コード例 #1
0
  public void parseAndPrintTest(Visitor[] visitors, AstPrinterInterface printer, boolean cmpInput)
      throws IOException, ParseException {
    System.out.println();
    System.out.println("Parser & Print test:");
    System.out.println("  Printer:    " + printer.getClass().getSimpleName());
    System.out.println();

    for (Test test : tests) {

      System.out.println("Testing: " + test.getName());

      ParserInterface p = new FullParser();
      p.addVisitors(Arrays.asList(visitors));

      AstNode r = p.parseArticle(test.getInput(), test.getName());

      StringWriter writer = new StringWriter();
      printer.print(r, writer);
      String result = writer.toString();

      if (cmpInput) {
        Assert.assertEquals(test.getInput(), result);
      } else {
        Assert.assertEquals(test.getResult(), result);
      }
    }

    System.out.println();
  }
コード例 #2
0
ファイル: TestSuite.java プロジェクト: Rick0/7510-TP2.3
 private boolean isValidName(Test test) {
   for (Test t : childTest) {
     if (t.getName().equals(test.getName())) {
       return false;
     }
   }
   return true;
 }
コード例 #3
0
ファイル: TestSuite.java プロジェクト: Rick0/7510-TP2.3
 public void addTest(Test test) {
   if (isValidName(test)) {
     childTest.add(test);
   } else {
     System.out.println("El test " + test.getName() + " ya existe en la suite " + getName());
   }
 }
コード例 #4
0
ファイル: TestHarness.java プロジェクト: kappamodeler/kappa
  public static void main(String[] args) {
    if (args.length < 1) {
      System.out.println("Please give the configuration file name as first argument");
      return;
    }

    Map<String, Long> executionTimes = new HashMap<String, Long>();

    InputSource inputSource = new InputSource(args[0]);

    List<Test> tests = getTests(inputSource);
    if (tests == null) return;

    Emailer emailer = parseEmailer(inputSource);
    if (emailer == null) return;

    List<List<String>> outputs = new ArrayList<List<String>>();

    for (Test test : tests) {
      try {
        System.out.println("Running test " + test.getName());
        long startTime = System.currentTimeMillis();
        BufferedReader bufferedReader = null;
        for (int i = 0; i < test.getNRuns(); i++) {
          Process process = Runtime.getRuntime().exec(test.getCommand());
          if (test.getOutput().equals("console")) {
            bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
          } else {
            bufferedReader = new BufferedReader(new FileReader(test.getOutput()));
          }
          process.waitFor();
        }
        executionTimes.put(test.getName(), System.currentTimeMillis() - startTime);
        outputs.add(getLines(bufferedReader));
        System.out.println("Test " + test.getName() + " executed");
      } catch (IOException e) {
        e.printStackTrace();
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    }

    String message = "";
    int size = tests.size();
    for (int i = 0; i < size; i++) {
      for (int j = 0; j < i; j++) {
        String differences = Diff.diff(outputs.get(i), outputs.get(j));
        if (!differences.isEmpty()) {
          message +=
              "Differences between "
                  + tests.get(j).getName()
                  + " and "
                  + tests.get(i).getName()
                  + " tests\n";
          message += differences;
        }
      }
    }

    System.out.println("Sending e-mails");

    if (!message.isEmpty()) {
      message = "Some tests failed:\n" + message;
    } else {
      message = "Tests run successfully\n";
    }
    message += "Time of execution:\n";
    for (String name : executionTimes.keySet()) {
      message += name + " : " + executionTimes.get(name) + "ms\n";
    }
    emailer.send(message);
    System.out.println("E-mails sent");
  }
コード例 #5
0
 @Transient
 public String getName() {
   return testDefinition.getName();
 }
コード例 #6
0
  @Override
  @Secured
  public TestExecution createTestExecution(TestExecution testExecution) throws ServiceException {
    // The test referred by test execution has to be an existing test
    Test test = testDAO.get(testExecution.getTest().getId());
    testExecution.setTest(test);
    TestExecution storedTestExecution = testExecutionDAO.create(testExecution);
    // execution params
    if (testExecution.getParameters() != null && testExecution.getParameters().size() > 0) {
      for (TestExecutionParameter param : testExecution.getParameters()) {
        param.setTestExecution(storedTestExecution);
        testExecutionParameterDAO.create(param);
      }
    }
    // tags
    if (testExecution.getTags() != null && testExecution.getTags().size() > 0) {
      for (Tag teg : testExecution.getTags()) {
        Tag tag = tagDAO.findByName(teg.getName());
        if (tag == null) {
          tag = tagDAO.create(teg);
        }

        Collection<TestExecution> tagTestExecutions = tag.getTestExecutions();
        if (tagTestExecutions == null) {
          tag.setTestExecutions(new ArrayList<>());
        }

        tag.getTestExecutions().add(storedTestExecution);
      }
    }
    // values
    if (testExecution.getValues() != null && !testExecution.getValues().isEmpty()) {
      for (Value value : testExecution.getValues()) {
        value.setTestExecution(storedTestExecution);
        if (value.getMetricName() == null) {
          throw new IllegalArgumentException("Metric name is mandatory");
        }
        Metric metric =
            test.getMetrics()
                .stream()
                .filter(m -> m.getName().equals(value.getMetricName()))
                .findFirst()
                .get();
        if (metric == null) {
          throw new ServiceException(
              "serviceException.metricNotInTest",
              test.getName(),
              test.getId().toString(),
              value.getMetricName());
        }
        value.setMetric(metric);
        valueDAO.create(value);
        if (value.getParameters() != null && value.getParameters().size() > 0) {
          for (ValueParameter vp : value.getParameters()) {
            vp.setValue(value);
            valueParameterDAO.create(vp);
          }
        }
      }
    }

    TestExecution clone = cloneAndFetch(storedTestExecution, true, true, true, true, true);
    log.debug("Created new test execution " + clone.getId());

    alertingService.processAlerts(clone);

    return clone;
  }
コード例 #7
0
ファイル: HelloWorldMain.java プロジェクト: kai-liki/Study
 /** @param args */
 public static void main(String[] args) {
   Test test = new MyTest().tryGetTests(1);
   System.out.println(test.getName());
 }