public InternalRemoteRunner(
      Class<?> testClass, String endpoint, Class<? extends Runner> remoteRunnerClass)
      throws InitializationError {
    super(testClass);
    this.testClass = testClass;
    this.remoteRunnerClass = remoteRunnerClass;
    TestClass tc = new TestClass(testClass);

    description = Description.createTestDescription(testClass, tc.getName(), tc.getAnnotations());

    for (FrameworkMethod method : tc.getAnnotatedMethods(Test.class)) {
      String methodName = method.getName();
      Description child =
          Description.createTestDescription(testClass, methodName, method.getAnnotations());

      methodNames.put(child, methodName);
      description.addChild(child);
    }

    if (executorService == null) {
      String ep = System.getProperty("junit.remote.endpoint");
      if (ep == null) {
        ep = endpoint;
      }

      for (String e : ep.split(",")) {
        if (e.trim().equals("")) {
          continue;
        }
        endpoints.add(e.trim());
      }
      executorService = Executors.newFixedThreadPool(endpoints.size());
    }

    setScheduler(
        new RunnerScheduler() {
          @Override
          public void schedule(final Runnable childStatement) {
            SEMAPHORE.reducePermits(1);
            executorService.submit(new SemaphoreDelegate(childStatement));
          }

          @Override
          public void finished() {
            try {
              SEMAPHORE.acquire();
              SEMAPHORE.release();
            } catch (InterruptedException ignore) {
              Thread.currentThread().interrupt();
            }
          }
        });
  }
Exemplo n.º 2
0
 private Description asDescription(Test test) {
   if (test instanceof Describable) {
     Describable facade = (Describable) test;
     return facade.getDescription();
   }
   return Description.createTestDescription(getEffectiveClass(test), getName(test));
 }
Exemplo n.º 3
0
 /* 109:    */
 /* 110:    */ private static Description makeDescription(Test test) /* 111:    */ {
   /* 112: 96 */ if ((test instanceof TestCase))
   /* 113:    */ {
     /* 114: 97 */ TestCase tc = (TestCase) test;
     /* 115: 98 */ return Description.createTestDescription(tc.getClass(), tc.getName());
     /* 116:    */ }
   /* 117: 99 */ if ((test instanceof TestSuite))
   /* 118:    */ {
     /* 119:100 */ TestSuite ts = (TestSuite) test;
     /* 120:101 */ String name = ts.getName() == null ? createSuiteDescription(ts) : ts.getName();
     /* 121:102 */ Description description =
         Description.createSuiteDescription(name, new Annotation[0]);
     /* 122:103 */ int n = ts.testCount();
     /* 123:104 */ for (int i = 0; i < n; i++)
     /* 124:    */ {
       /* 125:105 */ Description made = makeDescription(ts.testAt(i));
       /* 126:106 */ description.addChild(made);
       /* 127:    */ }
     /* 128:108 */ return description;
     /* 129:    */ }
   /* 130:109 */ if ((test instanceof Describable))
   /* 131:    */ {
     /* 132:110 */ Describable adapter = (Describable) test;
     /* 133:111 */ return adapter.getDescription();
     /* 134:    */ }
   /* 135:112 */ if ((test instanceof TestDecorator))
   /* 136:    */ {
     /* 137:113 */ TestDecorator decorator = (TestDecorator) test;
     /* 138:114 */ return makeDescription(decorator.getTest());
     /* 139:    */ }
   /* 140:117 */ return Description.createSuiteDescription(test.getClass());
   /* 141:    */ }
Exemplo n.º 4
0
 public PropertyTestRunner(Class<?> clas) {
   this.clas = clas;
   this.allTests =
       Check.properties(clas)
           .map(p -> P.p(p._1(), p._3(), Description.createTestDescription(clas, p._2())));
   this.filteredTests = allTests;
 }
Exemplo n.º 5
0
 private static Description makeDescription(Test test) {
   if (test instanceof TestCase) {
     TestCase tc = (TestCase) test;
     return Description.createTestDescription(tc.getClass(), tc.getName(), getAnnotations(tc));
   } else if (test instanceof TestSuite) {
     TestSuite ts = (TestSuite) test;
     String name = ts.getName() == null ? createSuiteDescription(ts) : ts.getName();
     Description description = Description.createSuiteDescription(name);
     int n = ts.testCount();
     for (int i = 0; i < n; i++) {
       Description made = makeDescription(ts.testAt(i));
       description.addChild(made);
     }
     return description;
   } else if (test instanceof Describable) {
     Describable adapter = (Describable) test;
     return adapter.getDescription();
   } else if (test instanceof TestDecorator) {
     TestDecorator decorator = (TestDecorator) test;
     return makeDescription(decorator.getTest());
   } else {
     // This is the best we can do in this case
     return Description.createSuiteDescription(test.getClass());
   }
 }
Exemplo n.º 6
0
 /*  53:    */
 /*  54:    */ private Description asDescription(Test test) /*  55:    */ {
   /*  56: 45 */ if ((test instanceof Describable))
   /*  57:    */ {
     /*  58: 46 */ Describable facade = (Describable) test;
     /*  59: 47 */ return facade.getDescription();
     /*  60:    */ }
   /*  61: 49 */ return Description.createTestDescription(
       getEffectiveClass(test), getName(test));
   /*  62:    */ }
Exemplo n.º 7
0
  private void runScenario(RunNotifier notifier, Scenario scenario) {
    Description childDescription =
        Description.createTestDescription(getClass(), scenario.getName());
    descr.addChild(childDescription);
    EachTestNotifier eachNotifier = new EachTestNotifier(notifier, childDescription);
    try {
      eachNotifier.fireTestStarted();

      // If a KieSession is not available, fail fast
      if (ksessions == null || ksessions.values().isEmpty()) {
        eachNotifier.addFailure(
            new NullKieSessionException(
                "Unable to get a Session to run tests. Check the project for build errors."));
      } else {

        KieSession ksession = getKSession(scenario.getKSessions());

        if (ksession == null) {
          String ksessionName = getKSessionName(scenario.getKSessions());
          if (ksessionName == null) {
            eachNotifier.addFailure(
                new NullPointerException(
                    "Test scenario runner could not find the default knowledge session."));
          } else {
            eachNotifier.addFailure(
                new NullPointerException(
                    "Test scenario runner could not find a stateful knowledge session with the name \'"
                        + ksessionName
                        + "\'."));
          }
        } else {
          final ScenarioRunner runner = new ScenarioRunner(ksession, maxRuleFirings);
          runner.run(scenario);
          if (!scenario.wasSuccessful()) {
            StringBuilder builder = new StringBuilder();
            for (String message : scenario.getFailureMessages()) {
              builder.append(message).append("\n");
            }
            eachNotifier.addFailedAssumption(new AssumptionViolatedException(builder.toString()));
          }

          // FLUSSSSSH!
          for (FactHandle factHandle : ksession.getFactHandles()) {
            ksession.delete(factHandle);
          }
        }
      }
    } catch (Throwable t) {
      eachNotifier.addFailure(t);
    } finally {
      // has to always be called as per junit docs
      eachNotifier.fireTestFinished();
    }
  }
Exemplo n.º 8
0
 @Override
 public Statement apply(Statement base, FrameworkMethod method, Object fixtureTarget) {
   final Repeat actual = method.getAnnotation(Repeat.class);
   if (actual == null) {
     return base;
   }
   Class<?> fixtureType = fixtureTarget.getClass();
   Description description =
       Description.createTestDescription(fixtureType, method.getName(), method.getAnnotations());
   return statement = onRepeat(actual, notifier, base, description);
 }
 @Override
 public void run(final RunNotifier notifier) {
   if (System.getProperty(IGNORE_SYS_PROP) != null) {
     notifier.fireTestIgnored(
         Description.createTestDescription(
             getTestClass().getJavaClass(),
             "System property to ignore integration tests is set."));
   } else {
     super.run(notifier);
   }
 }
  /** {@inheritDoc} */
  @Override
  public void filter(final Filter filter) throws NoTestsRemainException {
    computeTestMethods();

    for (final ListIterator<FrameworkMethod> iter = testMethods_.listIterator(); iter.hasNext(); ) {
      final FrameworkMethod method = iter.next();
      // compute 2 descriptions to verify if it is the intended test:
      // - one "normal", this is what Eclipse's filter awaits when typing Ctrl+X T
      //   when cursor is located on a test method
      // - one with browser nickname, this is what is needed when re-running a test from
      //   the JUnit view
      // as the list of methods is cached, this is what will be returned when computeTestMethods()
      // is called
      final Description description =
          Description.createTestDescription(getTestClass().getJavaClass(), method.getName());
      final Description description2 =
          Description.createTestDescription(getTestClass().getJavaClass(), testName(method));
      if (!filter.shouldRun(description) && !filter.shouldRun(description2)) {
        iter.remove();
      }
    }
  }
Exemplo n.º 11
0
 protected TestCase(
     Class<?> testClass,
     String baseName,
     String sourceName,
     Path path,
     String testInput,
     String expectedOutput) {
   this.name = Description.createTestDescription(testClass, baseName);
   this.sourceName = sourceName;
   this.path = path;
   this.testInput = testInput;
   this.expectedOutput = expectedOutput;
 }
 Description describeMethod() {
   Object[] params = paramsFromAnnotation();
   Description parametrised = Description.createSuiteDescription(method.name());
   for (int i = 0; i < params.length; i++) {
     /*
     Object paramSet = params[i];
     parametrised.addChild(Description.createTestDescription(method.frameworkMethod.getMethod().getDeclaringClass(),
             Utils.stringify(paramSet, i) + " (" + method.name() + ")", method.frameworkMethod.getAnnotations()));
             */
     parametrised.addChild(
         Description.createTestDescription(
             method.frameworkMethod.getMethod().getDeclaringClass(),
             method.name() + " [" + i + "]",
             method.frameworkMethod.getAnnotations()));
   }
   return parametrised;
 }
  // Mostly taken from Junit4Provider.java
  public RunResult invokeJunit4(Class<?> clazz, String requestedTestMethod)
      throws TestSetFailedException {

    final ReporterFactory reporterFactory = providerParameters.getReporterFactory();

    RunListener reporter = reporterFactory.createReporter();

    ConsoleOutputCapture.startCapture((ConsoleOutputReceiver) reporter);

    JUnit4RunListener jUnit4TestSetReporter = new JUnit4RunListener(reporter);

    Result result = new Result();
    RunNotifier listeners = getRunNotifier(jUnit4TestSetReporter, result, customRunListeners);

    listeners.fireTestRunStarted(Description.createTestDescription(clazz, requestedTestMethod));

    final ReportEntry report =
        new SimpleReportEntry(
            getClass().getName() + "." + requestedTestMethod,
            clazz.getName() + "." + requestedTestMethod);
    reporter.testSetStarting(report);
    try {
      for (final Method method : clazz.getMethods()) {
        if (method.getParameterTypes().length == 0
            && requestedTestMethod.equals(method.getName())) {
          Request.method(clazz, method.getName()).getRunner().run(listeners);
        }
      }
    } catch (Throwable e) {
      reporter.testError(
          SimpleReportEntry.withException(
              report.getSourceName(),
              report.getName(),
              new PojoStackTraceWriter(report.getSourceName(), report.getName(), e)));
    } finally {
      reporter.testSetCompleted(report);
    }
    listeners.fireTestRunFinished(result);
    JUnit4RunListener.rethrowAnyTestMechanismFailures(result);

    closeRunNotifier(jUnit4TestSetReporter, customRunListeners);
    return reporterFactory.close();
  }
Exemplo n.º 14
0
 @Override
 protected Description describeChild(Interaction interaction) {
   return Description.createTestDescription(
       pactToVerify.consumer().name(), interaction.description());
 }
Exemplo n.º 15
0
 @Override
 public Description getDescription() {
   return Description.createTestDescription(this.getClass(), ScriptUtils.getFullName(script));
 }
 protected Description methodDescription(JUnit4TestMethod method) {
   return Description.createTestDescription(
       getTestClass().getJavaClass(), testName(method), testAnnotations(method.getTestMethod()));
 }
  private void reportTestAsNotApplicableInCurrentTestRun(Method method) {
    Class<?> testClass = method.getDeclaringClass();
    Description testDescription = Description.createTestDescription(testClass, method.getName());

    runNotifier.fireTestAssumptionFailed(new Failure(testDescription, NOT_APPLICABLE));
  }
Exemplo n.º 18
0
 private Description describeCause(Throwable child) {
   return Description.createTestDescription(
       runner.getTestClass().getJavaClass(), "initializationError");
 }
Exemplo n.º 19
0
 @Override
 protected Description describeChild(String child) {
   return Description.createTestDescription(suiteClass, child);
 }
Exemplo n.º 20
0
 /** @see org.junit.runners.ParentRunner#describeChild(java.lang.Object) */
 @Override
 protected Description describeChild(TestInfo child) {
   return Description.createTestDescription(getTestClass().getJavaClass(), child.name);
 }
Exemplo n.º 21
0
 @Override
 protected Description describeChild(ProcessorTestCase child) {
   return Description.createTestDescription(
       getTestClass().getJavaClass(), child.processor.name().toLowerCase());
 }
 private Description descriptionFor(WikiTestPage test) {
   return Description.createTestDescription(mainClass, test.getFullPath());
 }