@Override
 public boolean shouldRun(Description description) {
   if (description.getMethodName() == null || description.getTestClass() == null) {
     return shouldRun(description, null, null);
   } else {
     Class<?> testClass = description.getTestClass();
     return shouldRun(description, createSuiteDescription(testClass), testClass);
   }
 }
 @Override
 protected void starting(Description description) {
   // Before each test method, ensure a new session is created.
   String webAppUrl = SeleniumUtil.getWebAppUrl();
   if (description.getTestClass().isAnnotationPresent(UrlParams.class)) {
     String urlParams = description.getTestClass().getAnnotation(UrlParams.class).value();
     if (!StringUtility.isNullOrEmpty(urlParams)) {
       webAppUrl = webAppUrl + "?" + urlParams;
     }
   }
   m_driver.get(webAppUrl);
 }
 private String url(Description description) {
   //noinspection StringEquality
   if (this.testUrl == NOT_SPECIFIED) {
     return EndToEndTestUtils.classNameToTestFileUrl(description.getTestClass());
   }
   return this.testUrl;
 }
    @Override
    public void setup(JenkinsRule jenkinsRule, EndToEndTfs recipe) throws Exception {
      final Description testDescription = jenkinsRule.getTestDescription();
      final Class clazz = testDescription.getTestClass();
      testClassName = clazz.getSimpleName();
      testCaseName = testDescription.getMethodName();
      final String hostName = IntegrationTestHelper.tryToDetermineHostName();
      final File currentFolder = new File("").getAbsoluteFile();
      final File workspaces = new File(currentFolder, "workspaces");
      // TODO: Consider NOT using the Server class
      server = new Server(null, null, serverUrl, helper.getUserName(), helper.getUserPassword());

      final MockableVersionControlClient vcc = server.getVersionControlClient();

      // workspaceName MUST be unique across computers hitting the same server
      workspaceName = hostName + "-" + testCaseName;
      workspace = createWorkspace(vcc, workspaceName);

      pathInTfvc = IntegrationTestHelper.determinePathInTfvcForTestCase(testDescription);
      final File localTestClassFolder = new File(workspaces, testClassName);
      localBaseFolderFile = new File(localTestClassFolder, testCaseName);
      //noinspection ResultOfMethodCallIgnored
      localBaseFolderFile.mkdirs();
      final String localBaseFolder = localBaseFolderFile.getAbsolutePath();
      final WorkingFolder workingFolder = new WorkingFolder(pathInTfvc, localBaseFolder);
      workspace.createWorkingFolder(workingFolder);

      // TODO: Is this necessary if we're about to delete it, anyway?
      workspace.get(GetOptions.NONE);

      // Delete the folder associated with this test in TFVC
      workspace.pendDelete(
          new String[] {pathInTfvc},
          RecursionType.FULL,
          LockLevel.UNCHANGED,
          GetOptions.NONE,
          PendChangesOptions.NONE);
      checkIn("Cleaning up for the " + testCaseName + " test.");
      // we don't need to verify this check-in, because a first run on a server will be a no-op

      // create the folder in TFVC
      workspace.pendAdd(
          new String[] {localBaseFolder},
          false,
          null,
          LockLevel.UNCHANGED,
          GetOptions.NONE,
          PendChangesOptions.NONE);
      final int changeSet = checkIn("Setting up for the " + testCaseName + " test.");
      Assert.assertTrue(changeSet >= 0);

      final Class<? extends StubRunner> runnerClass = recipe.value();
      if (runnerClass != null) {
        runner = runnerClass.newInstance();
        runner.setParent(this);
        runner.setHelper(this.helper);
        runner.setup(jenkinsRule, recipe);
      }
    }
 public Statement apply(final Statement base, Description description) {
   Class<?> testClass = description.getTestClass();
   init(description.getMethodName(), testClass.getSimpleName());
   boolean leaksHandles =
       testClass.getAnnotation(LeaksFileHandles.class) != null
           || description.getAnnotation(LeaksFileHandles.class) != null;
   return new TestDirectoryCleaningStatement(base, getTestDirectory(), leaksHandles);
 }
 private void dump(Description description) {
   final String methodName = description.getMethodName();
   System.out.println("***************************************************");
   System.out.println(" - isSuite: " + description.isSuite());
   System.out.println(" - isTest: " + description.isTest());
   System.out.println(" - annotations: " + description.getAnnotations());
   System.out.println(" - TestClass: " + description.getTestClass());
   System.out.println(" - class name: " + description.getClassName());
   System.out.println(" - method name: " + description.getMethodName());
   System.out.println("###################################################");
 }
示例#7
0
 static Optional<JavaSource> toJavaSource(Description description) {
   Class<?> testClass = description.getTestClass();
   if (testClass != null) {
     String methodName = description.getMethodName();
     if (methodName != null) {
       return Optional.of(toJavaMethodSource(testClass, methodName));
     }
     return Optional.of(new JavaSource(testClass));
   }
   return Optional.empty();
 }
  public void closeApplicationContext(Description description) {
    Class<?> testClass = description.getTestClass();
    applicationContexts.computeIfPresent(
        testClass,
        (k, v) -> {
          if (v.isActive()) {
            v.close();
          }

          return v;
        });
  }
  public Statement apply(final Statement base, Description description) {
    Class<?> testClass = description.getTestClass();
    init(description.getMethodName(), testClass.getSimpleName());

    suppressCleanupErrors =
        testClass.getAnnotation(LeaksFileHandles.class) != null
            || description.getAnnotation(LeaksFileHandles.class) != null
            // For now, assume that all tests run with the daemon executer leak file handles
            // This seems to be true for any test that uses
            // `GradleExecuter.requireOwnGradleUserHomeDir`
            || "daemon".equals(System.getProperty("org.gradle.integtest.executer"));

    return new TestDirectoryCleaningStatement(base, description.getDisplayName());
  }
  private boolean shouldRun(Description description, Description parent, Class<?> parentClass) {
    if (matcher == null) {
      return true;
    } else {
      Set<Class<?>> cats = new HashSet<Class<?>>();
      Category cat = description.getAnnotation(Category.class);
      if (cat != null) {
        addAll(cats, cat.value());
      }

      if (parent != null) {
        cat = parent.getAnnotation(Category.class);
        if (cat != null) {
          addAll(cats, cat.value());
        }
      }

      if (parentClass != null) {
        findSuperclassCategories(cats, parentClass);
      }

      Class<?> testClass = description.getTestClass();
      if (testClass != null) {
        cat = testClass.getAnnotation(Category.class);
        if (cat != null) {
          addAll(cats, cat.value());
        }
      }

      cats.remove(null);

      boolean result = matcher.enabled(cats.toArray(new Class<?>[cats.size()]));

      if (!result) {
        ArrayList<Description> children = description.getChildren();
        if (children != null) {
          for (Description child : children) {
            if (shouldRun(child, description, null)) {
              result = true;
              break;
            }
          }
        }
      }

      return result;
    }
  }
  private boolean verifyTestMethodsInJUnit38TestClassThatShouldRun(JUnit38ClassRunner runner) {
    Description testClassDescription = runner.getDescription();
    Class<?> testClass = testClassDescription.getTestClass();
    Iterator<Description> itr = testClassDescription.getChildren().iterator();

    while (itr.hasNext()) {
      Description testDescription = itr.next();
      String testMethodName = testDescription.getMethodName();
      testMethod = findPublicVoidMethod(testClass, testMethodName);

      Boolean shouldRun = shouldRunTestInCurrentTestRun(null, testMethod);

      if (shouldRun != null && !shouldRun) {
        itr.remove();
      }
    }

    return testClassDescription.getChildren().isEmpty();
  }
示例#12
0
 private Runner buildRunner(Description each) {
   if (each.toString().equals("TestSuite with 0 tests")) {
     return Suite.emptySuite();
   }
   if (each.toString().startsWith(MALFORMED_JUNIT_3_TEST_CLASS_PREFIX)) {
     // This is cheating, because it runs the whole class
     // to get the warning for this method, but we can't do better,
     // because JUnit 3.8's
     // thrown away which method the warning is for.
     return new JUnit38ClassRunner(new TestSuite(getMalformedTestClass(each)));
   }
   Class<?> type = each.getTestClass();
   if (type == null) {
     throw new RuntimeException("Can't build a runner from description [" + each + "]");
   }
   String methodName = each.getMethodName();
   if (methodName == null) {
     return Request.aClass(type).getRunner();
   }
   return Request.method(type, methodName).getRunner();
 }
示例#13
0
  /**
   * {@inheritDoc}
   *
   * @see org.junit.rules.TestWatcher#starting(org.junit.runner.Description)
   */
  @Override
  protected void starting(Description d) {
    testClass = d.getTestClass();
    className = testClass.getName();
    methodName = d.getMethodName();
    displayName = d.getDisplayName();

    log(
        "\n\t>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n\tRunning Test [%s.%s]\n\t>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n",
        testClass.getSimpleName(), methodName);
    if (!preparedClasses.contains(testClass)) {
      log("Preparing Test Class [%s]", className);
      preparedClasses.add(testClass);
      UnsafeAdapterConfigurator.setConfiguration(testClass);
      Assert.assertFalse(
          "UnsafeAdapter is not in expected state",
          UnsafeAdapterConfigurator.requiresReset(testClass));
      log(
          "Prepared Test Class [%s], Unsafe Adapter Config: %s",
          className, UnsafeAdapterConfigurator.printActualConfiguration());
    }
  }
示例#14
0
 private void setDataSetFromAnnotation(Description description) {
   Class<?> testClass = description.getTestClass();
   Fixture fixture = findFixtureAnnotation(description);
   if (fixture == null) return;
   Fixture.Type type = fixture.type();
   String[] resources = fixture.resources();
   if (resources == null || resources.length == 0) return;
   try {
     if (resources.length == 1) {
       setDataSet(loadDataSet(type, resources[0], testClass));
     } else {
       IDataSet[] dataSets = new IDataSet[resources.length];
       for (int i = 0; i < resources.length; i++) {
         dataSets[i] = loadDataSet(type, resources[i], testClass);
       }
       setDataSet(new CompositeDataSet(dataSets));
     }
   } catch (YAMLException e) {
     throw new YAMLException("Cant load fixture: " + Arrays.toString(resources), e);
   } catch (DataSetException | URISyntaxException e) {
     throw new AssertionError(e);
   }
 }
 protected void starting(Description description) {
   toString = description.getTestClass().getSimpleName() + "." + description.getMethodName();
 }
示例#16
0
 Report(Description description) {
   this.name = description.getTestClass().getSimpleName() + "." + description.getMethodName();
 }
示例#17
0
 private Fixture findFixtureAnnotation(Description description) {
   Fixture fixture = description.getAnnotation(Fixture.class);
   if (fixture != null) return fixture;
   return description.getTestClass().getAnnotation(Fixture.class);
 }
示例#18
0
 private Description parentDescription(Description description) {
   // TODO: how heavy are we cringing?
   return Description.createSuiteDescription(description.getTestClass());
 }
 /**
  * Creates a string representing a path in TFVC where the specified {@param testDescription} will
  * perform its work.
  *
  * @param testDescription metadata about the currently executing test method.
  * @return a string that looks like <code>$/FunctionalTests/TestClass/testMethod</code>
  */
 public static String determinePathInTfvcForTestCase(Description testDescription) {
   final Class clazz = testDescription.getTestClass();
   final String testClassName = clazz.getSimpleName();
   final String testCaseName = testDescription.getMethodName();
   return "$/FunctionalTests" + "/" + testClassName + "/" + testCaseName;
 }