Package no.hal.jex

Examples of no.hal.jex.JUnitTest


    String tests = jexAnnotation.tests();
    if (tests == null) {
      tests = testedMethodName;
    }
    JavaMethodTester javaMethodTester = (JavaMethodTester) ensureJavaElement(testMethodName, methodTesterParent.getMembers(), JexPackage.eINSTANCE.getJavaMethodTester());
    JUnitTest testReq = ensureJunitTest(javaMethodTester, tests, methodParent, reqParent);
    setAnnotationFeatures(testReq, jexAnnotation);
    return testReq;
  }
View Full Code Here


      }
      JavaRequirement req = (JavaRequirement)ensureRequirement(reqClass, member, reqParent.getRequirements());
      // must add to parent before searching hierarchy
      reqParent.getRequirements().add(req);
      if (req instanceof JUnitTest) {
        JUnitTest testReq = (JUnitTest) req;
        if (member instanceof TestRunnable) {
          String text = null;
          for (Member testElement : ((TestRunnable) member).getTestedElements()) {
            if (text == null) {
              text = "Test " + testElement.toString();
            } else {
              text += "; Test " + testElement.toString();
            }
          }
          testReq.setText(text != null ? text : "Test with " + javaElement.toString());
        }
      }
      if (javaElement instanceof JavaClass && depth != 0) {
        createRequirementsFromJavaModel(((JavaClass) javaElement).getMembers(), req, depth - 1);
      }
View Full Code Here

  }

  @Override
  public Boolean validateRequirement(AbstractRequirement req) {
    if (req instanceof JUnitTest) {
      JUnitTest junitTest = (JUnitTest) req;
      TestRunnable testRunnable = junitTest.getTestRunnable();
      for (Member jexMember : testRunnable.getTestedElements()) {
        if (jexMember != null) {
          if (validateJexMember(jexMember, false, true) == Boolean.FALSE) {
            return Boolean.FALSE;
          }
        }
      }
      Test test = createTest(testRunnable);
      if (test != null) {
        TestResult testResult = new TestResult();
        final Collection<String> messages = junitTest.getMessages();
        messages.clear();
        testResult.addListener(baseTestRunnerProvider.createBaseTestRunner(junitTest));
        test.run(testResult);
        ((JUnitTest) req).setSatisfied(testResult.wasSuccessful());
      }
View Full Code Here

    while (content.hasNext()) {
      Object o = content.next();
      if (o instanceof JavaElement) {
        content.prune();
      } else if (o instanceof JUnitTest) {
        JUnitTest test = (JUnitTest)o;
        TestRunnable testRun = test.getTestRunnable();
        if (testRun == null) {
          testRun = (TestRunnable) test.getJavaElement();
        }
        ITestElement.Result result = checkTestRunnable(testRun, testResults);
        if (result != ITestElement.Result.UNDEFINED) {
          validateTestRunRequirement(test, result);
        }
View Full Code Here

    String tests = (String) JdtHelper.getAnnotationValue(annotations, JEX_TESTS_ANNOTATION_KEY, IMemberValuePair.K_STRING);
    if (tests == null) {
      tests = testedMethodName;
    }
    JavaMethodTester javaMethodTester = (JavaMethodTester) ensureJavaElement(method.getElementName(), methodTesterParent.getMembers(), JexPackage.eINSTANCE.getJavaMethodTester());
    JUnitTest testReq = ensureJunitTest(javaMethodTester, tests, methodParent, reqParent);
    setAnnotationFeatures(testReq, annotations, parentAnnotations);
    return testReq;
  }
View Full Code Here

  };
 
  protected JUnitTest ensureJunitTest(JavaMethodTester javaMethodTester, String testsAnnotation, Iterable<Member> methodParents, AbstractRequirement reqParent) {

    // create and initialize JUnit test
    JUnitTest testReq = JexFactory.eINSTANCE.createJUnitTest();
    testReq.setText("Test");
    javaMethodTester.setReturnType("void");
    testReq.setJavaElement(javaMethodTester);
    testReq.setTestRunnable(javaMethodTester);
   
    reqParent.getRequirements().add(testReq);

    JavaClass methodParent = null;
    for (Member member : methodParents) {
      if (member instanceof JavaClass) {
        methodParent = (JavaClass) member;
        break;
      }
    }
    // add java elements and requirements for the tested elements
    String[] testedElements = testsAnnotation.split(";");
    for (int i = 0; i < testedElements.length; i++) {
      String testedElementName = testedElements[i].trim();
      String returnType = null, modifiers = null;
      for (int j = 0; j < visibilityPrefixes.length; j += 2) {
        String prefix = visibilityPrefixes[j];
        if (testedElementName.startsWith(prefix)) {
          modifiers = visibilityPrefixes[j + 1];
          testedElementName = testedElementName.substring(prefix.length());
          break;
        }
      }
      testReq.setText(testReq.getText() + (i == 0 ? " " : ", ") + testedElementName);
      int pos1 = testedElementName.indexOf('('), pos = testedElementName.lastIndexOf(' ', pos1 >= 0 ? pos1 : testedElementName.length());
      if (pos >= 0) {
        returnType = testedElementName.substring(0, pos);
        pos1 -= pos + 1;
        testedElementName = testedElementName.substring(pos + 1);
      }
      int pos2 = testedElementName.lastIndexOf(')');
      Member testedElement = null;
      if (pos1 >= 0 && pos2 >= 0) {
        String[] params = {}, exceptions = {};
        if (pos2 > pos1 + 2) {
          params = parseTypeList(testedElementName.substring(pos1 + 1, pos2));
        }
        String THROWS_KEYWORD = "throws ";
        int pos3 = testedElementName.indexOf(THROWS_KEYWORD, pos2);
        if (pos3 >= pos2) {
          exceptions = parseTypeList(testedElementName.substring(pos3 + THROWS_KEYWORD.length()));
        }
        testedElementName = testedElementName.substring(0, pos1);
        if (methodParent == null) {
          continue;
        }
        if (testedElementName != methodParent.getName() && returnType == null) {
          returnType = "void";
        }
        JavaMethod javaMethod = (JavaMethod) ensureJavaMethod(testedElementName, returnType, params, exceptions, methodParent.getMembers());
        testedElement = javaMethod;
      } else {
        JavaField javaField = (JavaField) ensureJavaElement(testedElementName, methodParent.getMembers(), JexPackage.eINSTANCE.getJavaField());
        javaField.setType(returnType);
        testedElement = javaField;
      }
      javaMethodTester.getTestedElements().add(testedElement);
      JavaRequirement javaReq = JexFactory.eINSTANCE.createJavaRequirement();
      javaReq.setText("Requires " + testedElements[i].trim());
      javaReq.setJavaElement(testedElement);

      if (modifiers != null) {
        testedElement.setModifiers((Integer) JexFactory.eINSTANCE.createFromString(JexPackage.eINSTANCE.getModifiers(), modifiers));
      } else {
        javaReq.setRequiredFeatures("!modifiers");
      }
      testReq.getRequirements().add(javaReq);
    }
    return testReq;
  }
View Full Code Here

    return AbstractRequirementChecker.satisfiedAnd(childrenSatisfied, satisified);
  }

  public static void computeRequirementPoints(AbstractRequirement req, int[] points) {
    if (req instanceof JUnitTest) {
      JUnitTest test = (JUnitTest)req;
      int reqPoints = test.getPoints();
      if (test.getSatisfied() == Boolean.TRUE) {
        points[0] += reqPoints;
      }
      points[1] += reqPoints;
    }
    for (AbstractRequirement childReq : req.getRequirements()) {
View Full Code Here

TOP

Related Classes of no.hal.jex.JUnitTest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.