Exemple #1
0
  public void testPeekAtStackWithTwoReturnsTop() throws Exception {
    InstanceStack iStack = new InstanceStack();
    iStack.setConfigAdapter(mci);
    Instance<?> ti1 = new TestInstance();
    iStack.pushInstance(ti1, ti1.getDescriptor());

    Instance<?> ti2 = new TestInstance();
    iStack.pushInstance(ti2, ti2.getDescriptor());

    assertEquals("Expecting top of stack", ti2, iStack.peek());
  }
Exemple #2
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());
 }
Exemple #3
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());
 }
Exemple #4
0
  public void testPeekAtEmptiedStackReturnsNull() throws Exception {
    InstanceStack iStack = new InstanceStack();
    iStack.setConfigAdapter(mci);
    Instance<?> ti1 = new TestInstance();
    iStack.pushInstance(ti1, ti1.getDescriptor());

    Instance<?> ti2 = new TestInstance();
    iStack.pushInstance(ti2, ti2.getDescriptor());

    iStack.popInstance(ti2);
    iStack.popInstance(ti1);

    assertEquals("Expecting null at top of empty stack", null, iStack.peek());
  }
Exemple #5
0
  public void testPath() {
    InstanceStack iStack = new InstanceStack();
    iStack.setConfigAdapter(mci);
    assertEquals("InstanceStack constructor should set path to base", "/*[0]", iStack.getPath());

    Instance<?> ti = new TestInstance();
    iStack.pushInstance(ti, ti.getDescriptor());

    // Set and clear attributes
    iStack.setAttributeName("attr1");
    assertEquals(
        "Setting attribute name should append name to path", "/*[0]/attr1", iStack.getPath());
    iStack.clearAttributeName("attr1");
    assertEquals("Clearing attribute name should remove name from path", "/*[0]", iStack.getPath());
    iStack.setAttributeName("body");
    assertEquals(
        "Setting attribute name as body should append '*' to path", "/*[0]/*", iStack.getPath());
    iStack.clearAttributeName("body");
    assertEquals("/*[0]", iStack.getPath());
    iStack.setAttributeName("realbody");
    assertEquals(
        "Setting attribute name as realbody should append '+' to path",
        "/*[0]/+",
        iStack.getPath());
    iStack.clearAttributeName("realbody");
    assertEquals("/*[0]", iStack.getPath());

    // Set and clear indexes
    iStack.setAttributeName("attr2");
    iStack.setAttributeIndex(42);
    assertEquals("/*[0]/attr2[42]", iStack.getPath());
    iStack.clearAttributeIndex(42);
    assertEquals("/*[0]/attr2", iStack.getPath());
  }
Exemple #6
0
 public void testGetAccessReturnsInstanceWhenNoAccessStack() throws Exception {
   InstanceStack iStack = new InstanceStack();
   iStack.setConfigAdapter(mci);
   Instance<?> ti1 = new TestInstance("path1");
   iStack.pushInstance(ti1, ti1.getDescriptor());
   assertEquals(ti1, iStack.getAccess());
 }
Exemple #7
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");
   }
 }
Exemple #8
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");
   }
 }
Exemple #9
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");
   }
 }
Exemple #10
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");
   }
 }
Exemple #11
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");
   }
 }