Exemplo n.º 1
0
  @Override
  // @Secured TODO: we need to handle this property, since getTestByRelation will not work as metric
  // is associated with more tests
  public void removeMetric(Metric metric, Test test) throws ServiceException {
    Metric freshMetric = metricDAO.get(metric.getId());
    Test freshTest = testDAO.get(test.getId());

    // List<Test> newTests = freshMetric.getTests().stream().filter(o ->
    // !o.equals(freshTest)).collect(Collectors.toList());
    // freshMetric.setTests(newTests);

    // List<Metric> newMetrics = freshTest.getMetrics().stream().filter(o ->
    // !o.equals(freshMetric)).collect(Collectors.toList());
    // freshTest.setMetrics(newMetrics);

    freshMetric.getTests().remove(freshTest);
    freshTest.getMetrics().remove(freshMetric);

    metricDAO.update(freshMetric);
    testDAO.update(freshTest);

    if (freshMetric.getTests() == null || freshMetric.getTests().isEmpty()) {
      metricDAO.remove(freshMetric);
    }
  }
Exemplo n.º 2
0
  public static void main(String[] args) throws Exception {
    System.out.println("input file path");
    // path:文件绝对路径
    String path = "D:\\develop\\texdata\\积分表.tex";
    // 初始化输入
    PreMath prm = new PreMath();
    // 将预处理的字符串写入临时文件$path.tmp
    prm.process(path);

    System.out.println("input file path over");

    MathNode mn = new MathNode("=");
    MathNode mnl = new MathNode("x");
    MathNode mnr = new MathNode("1");
    mn.LNode = mnl;
    mn.RNode = mnr;
    mn.pnode();
    Test ts = new Test();
    ts.strcmp("asd", "d");
    /*
    //	Scanner scanner = new Scanner(ipts);
    	// create a CharStream that reads from standard input
    	ANTLRInputStream input = new ANTLRInputStream(System.in);
    	// create a lexer that feeds off of input CharStream
    	antlrtLexer lexer = new antlrtLexer(input);
    	// create a buffer of tokens pulled from the lexer
    	CommonTokenStream tokens = new CommonTokenStream(lexer);
    	// create a parser that feeds off the tokens buffer
    	antlrtParser parser = new antlrtParser(tokens);
    	// begin parsing at rule rule
    	parser.prog();
    	*/
  }
Exemplo n.º 3
0
 @org.junit.Test
 public void testExcludes() {
   assertSame(test, test.exclude(TEST_PATTERN_1, TEST_PATTERN_2));
   assertEquals(WrapUtil.toList(TEST_PATTERN_1, TEST_PATTERN_2), test.getExcludes());
   test.exclude(TEST_PATTERN_3);
   assertEquals(
       WrapUtil.toList(TEST_PATTERN_1, TEST_PATTERN_2, TEST_PATTERN_3), test.getExcludes());
 }
Exemplo n.º 4
0
 @Override
 public List<Test> getAllFullTests() {
   List<Test> r = testDAO.getAll();
   List<Test> rcopy = new ArrayList<Test>(r.size());
   for (Test t : r) {
     rcopy.add(getFullTest(t.getId()));
   }
   return rcopy;
 }
Exemplo n.º 5
0
 public static void main(String[] args) {
   Test test = new Test();
   test.printAreas();
   //    Rectangle r = new Rectangle(3, 2, 5, 6);
   //    r.show();
   //    Shape c = new Circle(5, 4, 5);
   //    c.show();
   //    System.out.println("Circle area is: " + c.getArea());
 }
Exemplo n.º 6
0
 @org.junit.Test
 public void testUnmanagedClasspath() {
   List<Object> list1 = WrapUtil.toList("a", new Object());
   assertSame(test, test.unmanagedClasspath(list1.toArray(new Object[list1.size()])));
   assertEquals(list1, test.getUnmanagedClasspath());
   List list2 = WrapUtil.toList(WrapUtil.toList("b", "c"));
   test.unmanagedClasspath(list2.toArray(new Object[list2.size()]));
   assertEquals(GUtil.addLists(list1, GUtil.flatten(list2)), test.getUnmanagedClasspath());
 }
Exemplo n.º 7
0
 public boolean process(Set<? extends TypeElement> annos, RoundEnvironment rEnv) {
   Trees trees = Trees.instance(processingEnv);
   Test test = new Test();
   for (Element e : rEnv.getRootElements()) {
     Tree t = trees.getTree(e);
     test.scan(t, null);
   }
   return true;
 }
Exemplo n.º 8
0
  @Override
  public List<Metric> getAllMetrics(Long testId) {
    Test freshTest = testDAO.get(testId);
    if (freshTest.getMetrics() == null) {
      return new ArrayList<>();
    }

    List<Metric> metrics = freshTest.getMetrics().stream().collect(Collectors.toList());
    return metrics;
  }
Exemplo n.º 9
0
 public void testExecuteWithUnspecifiedTestResultsDir() {
   setUpMocks(test);
   test.setTestResultsDir(null);
   try {
     test.execute();
     fail();
   } catch (Exception e) {
     assertThat(e.getCause(), Matchers.instanceOf(InvalidUserDataException.class));
   }
 }
 public void store() {
   Test.deleteAllInstances(new Atom());
   Test.deleteAllInstances(this);
   CascadeToExistingVectorMember cev = new CascadeToExistingVectorMember();
   cev.vec = new Vector();
   Atom atom = new Atom("one");
   Test.store(atom);
   cev.vec.addElement(atom);
   Test.store(cev);
 }
Exemplo n.º 11
0
 static void test01() {
   Map<String, String> ref = new HashMap<>();
   Test test = new Test();
   test.test01(ref);
   if (ref.containsKey("test")) {
     System.out.println("passed reference");
     System.out.println(ref.get("test"));
   } else {
     System.out.println("passed value");
   }
 }
Exemplo n.º 12
0
 @Override
 public List<String> getTestsByPrefix(String prefix) {
   List<Test> tests = testDAO.findByUIDPrefix(prefix);
   List<String> testuids = new ArrayList<String>();
   for (Test test : tests) {
     if (userService.isLoggedUserInGroup(test.getGroupId())) {
       testuids.add(test.getUid());
     }
   }
   return testuids;
 }
Exemplo n.º 13
0
  @Override
  public boolean isUserSubscribed(User user, Test test) {
    Test freshTest = testDAO.get(test.getId());
    Collection<User> testSubscribers = freshTest.getSubscribers();
    for (User testSubscriber : testSubscribers) {
      if (testSubscriber.getId().equals(user.getId())) {
        return true;
      }
    }

    return false;
  }
Exemplo n.º 14
0
  @Override
  public void addSubscriber(User user, Test test) {
    Test freshTest = testDAO.get(test.getId());
    User freshUser = userDAO.get(user.getId());

    Collection<User> testSubscribers = freshTest.getSubscribers();
    if (testSubscribers.contains(freshUser)) {
      return;
    }

    testSubscribers.add(freshUser);
    testDAO.update(freshTest);
  }
Exemplo n.º 15
0
  @Override
  @Secured
  public void removeTest(Test test) throws ServiceException {
    Test freshTest = testDAO.get(test.getId());
    try {
      for (TestExecution testExecution : freshTest.getTestExecutions()) {
        removeTestExecution(testExecution);
      }
    } catch (ServiceException ex) {
      throw new ServiceException("serviceException.removeTest.cannotRemoveAllTestExecutions", ex);
    }

    testDAO.remove(freshTest);
  }
Exemplo n.º 16
0
 private Test mapTest(
     PuzzleTestDto puzzleTest, Runner runner, Map<String, ByteArrayOutputStream> testFiles)
     throws IOException {
   Test test = new Test();
   test.setIndex(Integer.parseInt(puzzleTest.getIndex()));
   test.setRunner(runner);
   test = testRepository.save(test);
   String inputFileName = test.getId() + "/" + puzzleTest.getIndex() + ".txt";
   if (testFiles == null) {
     storage.uploadPublic(
         testsBucket,
         inputFileName,
         new ByteArrayInputStream(puzzleTest.getData().getBytes()),
         "text/plain");
   } else {
     storage.uploadPublic(
         testsBucket,
         inputFileName,
         new ByteArrayInputStream(testFiles.get(puzzleTest.getData()).toByteArray()),
         "text/plain");
   }
   storage.upload(
       testsBucket,
       test.getId() + "/output.txt",
       new ByteArrayInputStream(puzzleTest.getSolution().getBytes()),
       "text/plain");
   Map<String, String> testParams = new HashMap<>();
   testParams.put("test", testsBucket + "/" + test.getId() + "/output.txt");
   testParams.put("stdin", testsBucket + "/" + inputFileName);
   test.setParams(testParams);
   test = testRepository.save(test);
   test.setRunner(runner);
   return test;
 }
Exemplo n.º 17
0
  @Override
  public void removeSubscriber(User user, Test test) {
    Test freshTest = testDAO.get(test.getId());

    Collection<User> testSubscribers = new ArrayList<>(freshTest.getSubscribers());
    for (User testSubscriber : freshTest.getSubscribers()) {
      if (testSubscriber.getId().equals(user.getId())) {
        testSubscribers.remove(testSubscriber);
      }
    }

    test.setSubscribers(testSubscribers);
    testDAO.update(test);
  }
Exemplo n.º 18
0
  @Before
  public void setUp() {
    super.setUp();
    test = new Test(getProject(), AbstractTaskTest.TEST_TASK_NAME);
    ((AbstractProject) test.getProject()).setProjectDir(TEST_ROOT_DIR);
    context.checking(
        new Expectations() {
          {
            one(testFrameworkMock).initialize(getProject(), test);
          }
        });
    test.useTestFramework(testFrameworkMock);

    if (!TEST_TEST_CLASSES_DIR.exists()) assertTrue(TEST_TEST_CLASSES_DIR.mkdirs());
  }
Exemplo n.º 19
0
  @org.junit.Test
  public void testExecuteWithNonExistingCompiledTestsDir() {
    setUpMocks(test);
    test.setUnmanagedClasspath(null);
    context.checking(
        new Expectations() {
          {
            allowing(existentDirsFilterMock)
                .checkExistenceAndThrowStopActionIfNot(TEST_TEST_CLASSES_DIR);
            will(throwException(new StopActionException()));
          }
        });
    test.existingDirsFilter = existentDirsFilterMock;

    test.execute();
  }
Exemplo n.º 20
0
 // Run the tests for this container:
 public void timedTest() {
   displayHeader();
   for (TestParam param : paramList) {
     System.out.format(sizeField, param.size);
     for (Test<C> test : tests) {
       C kontainer = initialize(param.size);
       long start = System.nanoTime();
       // Call the overriden method:
       int reps = test.test(kontainer, param);
       long duration = System.nanoTime() - start;
       long timePerRep = duration / reps; // Nanoseconds
       System.out.format(numberField(), timePerRep);
     }
     System.out.println();
   }
 }
Exemplo n.º 21
0
 @org.junit.Test
 public void testInit() {
   assertNotNull(test.getTestFramework());
   assertNotNull(test.existingDirsFilter);
   assertNotNull(test.classpathConverter);
   assertNull(test.getTestClassesDir());
   assertNull(test.getConfiguration());
   assertNull(test.getTestResultsDir());
   assertNull(test.getTestReportDir());
   assertNull(test.getIncludes());
   assertNull(test.getExcludes());
   assertNull(test.getUnmanagedClasspath());
   assert test.isStopAtFailuresOrErrors();
 }
  public boolean runTest(String filename) throws Exception {
    Test test = new Test();
    test.file = new File(filename);
    runTest(test);

    // Print the DOM node
    if (this.resultsWriter != null) {
      this.resultsWriter.write("<html><head>");
      this.resultsWriter.write("<title>" + test.name + "</title>");
      this.resultsWriter.write("<style>");
      this.resultsWriter.write(".ran { background-color: #eeffee; }");
      this.resultsWriter.write(".passed { background-color: #ccffcc; }");
      this.resultsWriter.write(".failed { background-color: #ffcccc; }");
      this.resultsWriter.write(".error { background-color: #ffeeee; }");
      this.resultsWriter.write("</style>");
      this.resultsWriter.write("</head><body>");
      this.resultsWriter.write("<div>\n");
      this.resultsWriter.write(
          "<h3><a name=\"" + test.label + "\">" + test.file.getName() + "</a></h3>\n");
      this.resultsWriter.write("<table border=\"1\">\n");
      this.resultsWriter.write(
          "<tr class=\""
              + (test.result ? "passed" : "failed")
              + "\"><td colspan=\"3\">"
              + test.name
              + "</td></tr>\n");
      for (Command command : test.commands) {
        boolean result = command.result.startsWith("OK");
        this.resultsWriter.write("<tr class=\"" + (result ? "passed" : "failed") + "\"><td>");
        this.resultsWriter.write(command.cmd);
        this.resultsWriter.write("</td><td>");
        if (command.args != null) {
          this.resultsWriter.write(Arrays.asList(command.args).toString());
        }
        this.resultsWriter.write("</td><td>");
        this.resultsWriter.write(command.result);
        this.resultsWriter.write("</td></tr>\n");
        if (command.failure) break;
      }
      this.resultsWriter.write("</table>\n");
      this.resultsWriter.write("</body></html>");
      // outputDocument(this.resultsWriter);
    }
    return test.result;
  }
Exemplo n.º 23
0
 /** @return TestCase.getName() or Test.toString() or "nullTest" */
 public static String safeTestName(Test test) {
   if (test instanceof TestCase) {
     return ((TestCase) test).getName();
   } else if (null != test) {
     return test.toString();
   } else {
     return "nullTest";
   }
 }
Exemplo n.º 24
0
 @org.junit.Test
 public void testExecuteWithTestFailuresAndContinueWithFailures() {
   setUpMocks(test);
   setExistingDirsFilter();
   test.setStopAtFailuresOrErrors(false);
   context.checking(
       new Expectations() {
         {
           one(testFrameworkMock).prepare(getProject(), test);
           one(testFrameworkMock).getTestClassNames();
           will(returnValue(okTestClassNames));
           one(testFrameworkMock)
               .execute(getProject(), test, okTestClassNames, new ArrayList<String>());
           one(testFrameworkMock).report(getProject(), test);
         }
       });
   test.execute();
 }
Exemplo n.º 25
0
 private void setExistingDirsFilter() {
   context.checking(
       new Expectations() {
         {
           allowing(existentDirsFilterMock)
               .checkExistenceAndThrowStopActionIfNot(TEST_TEST_CLASSES_DIR);
         }
       });
   test.existingDirsFilter = existentDirsFilterMock;
 }
  protected static String getMethodName(Test test) {
    String className;
    String desc = test.toString();
    Matcher matcher = methodpattern.matcher(desc);
    if (matcher.matches()) {
      className = matcher.group(1);

    } else {
      className = desc;
    }

    return className;
  }
 public void addFailure(Test test, AssertionFailedError t) {
   StringBuffer sb = new StringBuffer();
   sb.append(test.toString());
   sb.append("\n");
   StringWriter sw = new StringWriter();
   t.printStackTrace(new PrintWriter(sw, true));
   sb.append(sw.toString());
   Log.getLogWriter().severe("zzzzzFAILURE IN " + test, t);
   // reportFailure(test, sb.toString());
   lastFailClass = getClassName(test);
   lastFailMethod = getMethodName(test);
   lastThrowable = t;
 }
Exemplo n.º 28
0
 @org.junit.Test(expected = GradleException.class)
 public void testExecuteWithTestFailuresAndStopAtFailures() {
   setUpMocks(test);
   setExistingDirsFilter();
   context.checking(
       new Expectations() {
         {
           one(testFrameworkMock).prepare(getProject(), test);
           one(testFrameworkMock).getTestClassNames();
           will(returnValue(okTestClassNames));
           one(testFrameworkMock)
               .execute(getProject(), test, okTestClassNames, new ArrayList<String>());
         }
       });
   test.execute();
 }
Exemplo n.º 29
0
  @Override
  public Test getFullTest(Long id) {
    Test test = testDAO.get(id);
    if (test == null) {
      return null;
    }
    test = test.clone();
    // TODO: return by named query, with optimized fetching
    Collection<Metric> metrics = test.getMetrics();
    if (metrics != null) {
      List<Metric> clonedMetrics = new ArrayList<Metric>();
      for (Metric metric : metrics) {
        clonedMetrics.add(metric);
      }
      test.setMetrics(clonedMetrics);
    }

    Collection<User> subscribers = test.getSubscribers();
    if (subscribers != null) {
      List<User> subscribersClone = new ArrayList<>();
      for (User subscriber : subscribers) {
        subscribersClone.add(subscriber.clone());
      }
      test.setSubscribers(subscribersClone);
    }

    Collection<Alert> alerts = test.getAlerts();
    if (alerts != null) {
      List<Alert> alertsClone = new ArrayList<>();
      for (Alert alert : alerts) {
        List<Tag> tagsClone = new ArrayList<>();
        for (Tag tag : alert.getTags()) {
          tagsClone.add(tag.clone());
        }
        Alert alertClone = alert.clone();
        alertClone.setTags(tagsClone);
        alertsClone.add(alertClone);
      }
      test.setAlerts(alertsClone);
    }

    return test;
  }
  public void test() {
    Test.forEach(
        new CascadeToExistingVectorMember(),
        new Visitor4() {
          public void visit(Object obj) {
            CascadeToExistingVectorMember cev = (CascadeToExistingVectorMember) obj;
            Atom atom = (Atom) cev.vec.elementAt(0);
            atom.name = "two";
            Test.store(cev);
            atom.name = "three";
            Test.store(cev);
          }
        });

    Test.reOpen();

    Test.forEach(
        new CascadeToExistingVectorMember(),
        new Visitor4() {
          public void visit(Object obj) {
            CascadeToExistingVectorMember cev = (CascadeToExistingVectorMember) obj;
            Atom atom = (Atom) cev.vec.elementAt(0);
            Test.ensure(atom.name.equals("three"));
            Test.ensureOccurrences(atom, 1);
          }
        });

    Test.forEach(
        new CascadeToExistingVectorMember(),
        new Visitor4() {
          public void visit(Object obj) {
            CascadeToExistingVectorMember cev = (CascadeToExistingVectorMember) obj;
            Atom atom = (Atom) cev.vec.elementAt(0);
            atom.name = "four";
            Test.store(cev);
          }
        });

    Test.reOpen();

    Test.forEach(
        new CascadeToExistingVectorMember(),
        new Visitor4() {
          public void visit(Object obj) {
            CascadeToExistingVectorMember cev = (CascadeToExistingVectorMember) obj;
            Atom atom = (Atom) cev.vec.elementAt(0);
            Test.ensure(atom.name.equals("four"));
            Test.ensureOccurrences(atom, 1);
          }
        });
  }