예제 #1
0
 public void testErrorSetIndexWithoutAttributeSet() {
   InstanceStack iStack = new InstanceStack();
   iStack.setConfigAdapter(mci);
   TestInstance ti = new TestInstance("instance");
   iStack.pushInstance(ti, ti.getDescriptor());
   try {
     iStack.setAttributeIndex(1);
     fail("Expected error when setting attribute index without setting attribute name first");
   } catch (Exception expected) {
     assertExceptionMessage(expected, AuraRuntimeException.class, "no name when index set");
   }
 }
예제 #2
0
 public void testErrorPushPopDifferentInstances() {
   InstanceStack iStack = new InstanceStack();
   iStack.setConfigAdapter(mci);
   TestInstance ti = new TestInstance("instance1");
   iStack.pushInstance(ti, ti.getDescriptor());
   try {
     iStack.popInstance(new TestInstance("instance2"));
     fail("Expected error when trying to pop different instance than previously pushed");
   } catch (Exception expected) {
     assertExceptionMessage(expected, AuraRuntimeException.class, "mismatched instance pop");
   }
 }
예제 #3
0
 public void testPopInstanceToTopIncrementsIndex() {
   InstanceStack iStack = new InstanceStack();
   iStack.setConfigAdapter(mci);
   assertEquals("InstanceStack constructor should set path to base", "/*[0]", iStack.getPath());
   TestInstance ti = new TestInstance();
   iStack.pushInstance(ti, ti.getDescriptor());
   iStack.popInstance(ti);
   assertEquals("Popping to top of stack should increment index", "/*[1]", iStack.getPath());
   iStack.pushInstance(ti, ti.getDescriptor());
   iStack.popInstance(ti);
   assertEquals("Popping to top of stack should increment index", "/*[2]", iStack.getPath());
 }
예제 #4
0
 public void testErrorSetAttributeNameWithoutClearing() {
   InstanceStack iStack = new InstanceStack();
   iStack.setConfigAdapter(mci);
   TestInstance ti = new TestInstance("instance");
   iStack.pushInstance(ti, ti.getDescriptor());
   iStack.setAttributeName("first");
   try {
     iStack.setAttributeName("second");
     fail("Expected error when setting second attribute without clearing first");
   } catch (Exception expected) {
     assertExceptionMessage(expected, AuraRuntimeException.class, "Setting name illegally");
   }
 }
예제 #5
0
 public void testErrorSetIndexWithoutClearingPreviousIndex() {
   InstanceStack iStack = new InstanceStack();
   iStack.setConfigAdapter(mci);
   TestInstance ti = new TestInstance();
   iStack.pushInstance(ti, ti.getDescriptor());
   iStack.setAttributeName("attribute");
   iStack.setAttributeIndex(42);
   try {
     iStack.setAttributeIndex(43);
     fail("Expected error when setting a new attribute index without clearing previous one");
   } catch (Exception expected) {
     assertExceptionMessage(expected, AuraRuntimeException.class, "missing clearAttributeIndex");
   }
 }
예제 #6
0
 public void testErrorClearIndexWithoutSettingIndex() {
   InstanceStack iStack = new InstanceStack();
   iStack.setConfigAdapter(mci);
   TestInstance ti = new TestInstance();
   iStack.pushInstance(ti, ti.getDescriptor());
   iStack.setAttributeName("attribute");
   try {
     iStack.clearAttributeIndex(1);
     fail("Expected error when clearing attribute index before setting an index");
   } catch (Exception expected) {
     assertExceptionMessage(
         expected, AuraRuntimeException.class, "mismatched clearAttributeIndex");
   }
 }
예제 #7
0
  public BodyDeclaration getTreeNode() {
    //        System.out.println("Building Method " + node.getName());

    String finalName = name + type.name() + Config.get().getTestMethodSuffix();
    MethodDeclaration result = new MethodDeclaration(ModifierSet.PUBLIC, new VoidType(), finalName);

    result.setComment(
        new BlockComment(
            "\n\t\tGenerated Unity test\n\t\t" + name + " - " + type.name() + " test." + "\n\t"));

    AnnotationExpr anno = new MarkerAnnotationExpr(new NameExpr("Test"));
    List<AnnotationExpr> annoList = new ArrayList<>();
    annoList.add(anno);
    result.setAnnotations(annoList);

    BlockStmt body = new BlockStmt();
    List<Statement> statements = new ArrayList<>();
    statements.add(instance.getStatement());

    body.setStmts(statements);
    result.setBody(body);

    // Set any mocks
    // Set instance
    // Set call parameters
    // Set call result
    // Set assertions
    return result;
  }
예제 #8
0
 public void testPrivileged() throws Exception {
   // setting up
   String namespace_Priv = "previlege";
   String namespace_UnPriv = "unprevilege";
   String name1 = "one";
   String name2 = "two";
   String name3 = "three";
   String name4 = "four";
   Mockito.when(mci.isPrivilegedNamespace(namespace_Priv)).thenReturn(true);
   Mockito.when(mci.isPrivilegedNamespace(namespace_UnPriv)).thenReturn(false);
   // create empty stack, sanity check
   InstanceStack iStack = new InstanceStack();
   iStack.setConfigAdapter(mci);
   assertFalse("stack should has topUnprivileged=null at the beginning", iStack.isUnprivileged());
   // start pushing
   TestInstance one = new TestInstance(namespace_Priv, name1);
   iStack.pushInstance(one, one.getDescriptor());
   assertFalse(
       "topUnprivileged is still null after pushing in one previleged instance:instance1",
       iStack.isUnprivileged());
   TestInstance two = new TestInstance(namespace_UnPriv, name2);
   iStack.pushInstance(two, two.getDescriptor());
   assertTrue(
       "topUnprivileged should become first unprivilege instance:instance2",
       iStack.isUnprivileged());
   TestInstance three = new TestInstance(namespace_Priv, name3);
   iStack.pushInstance(three, three.getDescriptor());
   assertTrue(
       "topUnprivileged should remain unchanged after pushing in a new privilege instance:instance3",
       iStack.isUnprivileged());
   TestInstance four = new TestInstance(namespace_UnPriv, name4);
   iStack.pushInstance(four, four.getDescriptor());
   assertTrue(
       "topUnprivileged should be unchanged after pushing in a new unprivilege instance:instance4",
       iStack.isUnprivileged());
   // start poping
   iStack.popInstance(four);
   assertTrue(
       "topUnprivileged should be unchanged after poping out unprivilege instance:instance4",
       iStack.isUnprivileged());
   iStack.popInstance(three);
   assertTrue(
       "topUnprivileged should be unchanged after poping out privilege instance:instance3",
       iStack.isUnprivileged());
   iStack.popInstance(two);
   assertFalse(
       "topUnprivileged should become null after poping out first unprivilege instance:instance2",
       iStack.isUnprivileged());
   iStack.popInstance(one);
   assertFalse(
       "topUnprivileged should be unchanged(null) after poping out instance1",
       iStack.isUnprivileged());
 }