Ejemplo n.º 1
0
 public void testPeekAtStackWithOneReturnsTop() throws Exception {
   InstanceStack iStack = new InstanceStack();
   iStack.setConfigAdapter(mci);
   Instance<?> ti = new TestInstance();
   iStack.pushInstance(ti, ti.getDescriptor());
   assertEquals("Expecting top of stack", ti, iStack.peek());
 }
Ejemplo n.º 2
0
 public void testGetAccessReturnsPushedAccess() throws Exception {
   InstanceStack iStack = new InstanceStack();
   iStack.setConfigAdapter(mci);
   Instance<?> ti1 = new TestInstance("path1");
   iStack.pushAccess(ti1);
   assertEquals(ti1, iStack.getAccess());
 }
Ejemplo n.º 3
0
 public void testNextId() {
   InstanceStack iStack = new InstanceStack();
   iStack.setConfigAdapter(mci);
   assertEquals("nextId should be initialized to 1", 1, iStack.getNextId());
   assertEquals("nextId should increment", 2, iStack.getNextId());
   assertEquals("nextId should increment again", 3, iStack.getNextId());
 }
Ejemplo n.º 4
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());
 }
Ejemplo n.º 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());
  }
Ejemplo n.º 6
0
 /** Verify nothing serialized if no registered components */
 public void testSerializeAsPartNoComponents() throws Exception {
   InstanceStack iStack = new InstanceStack();
   iStack.setConfigAdapter(mci);
   JsonEncoder jsonMock = Mockito.mock(JsonEncoder.class);
   iStack.serializeAsPart(jsonMock);
   assertEquals(
       "Components should empty when no registered components", 0, iStack.getComponents().size());
   verifyZeroInteractions(jsonMock);
 }
Ejemplo n.º 7
0
 public void testPushThenPopAccessSuccess() throws Exception {
   InstanceStack iStack = new InstanceStack();
   iStack.setConfigAdapter(mci);
   Instance<?> ti1 = new TestInstance("path1");
   Instance<?> ti2 = new TestInstance("path2");
   iStack.pushAccess(ti1);
   iStack.pushAccess(ti2);
   iStack.popAccess(ti2);
   iStack.popAccess(ti1);
   assertNull("Stack should return null after popping only instance", iStack.getAccess());
 }
Ejemplo n.º 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");
   }
 }
Ejemplo n.º 9
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());
 }
Ejemplo n.º 10
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());
 }
Ejemplo n.º 11
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");
   }
 }
Ejemplo n.º 12
0
 public void testMarkParentNoCurrentInstance() {
   InstanceStack iStack = new InstanceStack();
   iStack.setConfigAdapter(mci);
   assertEquals("InstanceStack constructor should set path to base", "/*[0]", iStack.getPath());
   TestInstance parent = new TestInstance("parentBase");
   iStack.markParent(parent);
   assertEquals(
       "Marking parent should set path to the parent's path", "parentBase", iStack.getPath());
   iStack.clearParent(parent);
   assertEquals(
       "Clearing parent should reset path to original base path", "/*[0]", iStack.getPath());
 }
Ejemplo n.º 13
0
 public void testPopAccessPastEmptyThrowsError() throws Exception {
   InstanceStack iStack = new InstanceStack();
   iStack.setConfigAdapter(mci);
   Instance<?> ti1 = new TestInstance("path1");
   try {
     iStack.pushAccess(ti1);
     iStack.popAccess(ti1);
     iStack.popAccess(ti1);
     fail("Expected exception when popping access twice but only pushed instance once");
   } catch (Exception e) {
     assertExceptionMessage(e, AuraRuntimeException.class, "mismatched access pop");
   }
 }
Ejemplo n.º 14
0
 public void testPopAccessWithDifferentInstanceThrowsError() throws Exception {
   InstanceStack iStack = new InstanceStack();
   iStack.setConfigAdapter(mci);
   Instance<?> ti1 = new TestInstance("path1");
   Instance<?> ti2 = new TestInstance("path2");
   try {
     iStack.pushAccess(ti1);
     iStack.popAccess(ti2);
     fail("Expected exception when popping access with mismatched instances");
   } catch (Exception e) {
     assertExceptionMessage(e, AuraRuntimeException.class, "mismatched access pop");
   }
 }
Ejemplo n.º 15
0
  public void testPeekAtStackAfterPopReturnsTop() 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);

    assertEquals("Expecting top of stack", ti1, iStack.peek());
  }
Ejemplo n.º 16
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");
   }
 }
Ejemplo n.º 17
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");
   }
 }
Ejemplo n.º 18
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());
  }
Ejemplo n.º 19
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");
   }
 }
Ejemplo n.º 20
0
 public void testMarkParentMultipleTimes() {
   InstanceStack iStack = new InstanceStack();
   iStack.setConfigAdapter(mci);
   assertEquals("InstanceStack constructor should set path to base", "/*[0]", iStack.getPath());
   TestInstance parent = new TestInstance("parent");
   iStack.markParent(parent);
   assertEquals("Marking parent should set path to the parent's path", "parent", iStack.getPath());
   iStack.markParent(parent);
   assertEquals("Marking additional parent should not update path", "parent", iStack.getPath());
   iStack.clearParent(parent);
   assertEquals("parent", iStack.getPath());
   iStack.clearParent(parent);
   assertEquals(
       "Clearing both parents should reset path to original base path", "/*[0]", iStack.getPath());
 }
Ejemplo n.º 21
0
  public void testErrorWrongParent() {
    // Mark a new parent without clearing the first
    InstanceStack iStack = new InstanceStack();
    iStack.setConfigAdapter(mci);
    iStack.markParent(new TestInstance("parent"));
    try {
      iStack.markParent(new TestInstance("different parent"));
      fail("Expected error when marking parent that's different than the current instance");
    } catch (Exception expected) {
      assertExceptionMessage(
          expected, AuraRuntimeException.class, "Don't know how to handle setAttribute here");
    }

    // Clear an instance that hasn't been marked as a parent
    iStack = new InstanceStack();
    iStack.setConfigAdapter(mci);
    iStack.markParent(new TestInstance("parent"));
    try {
      iStack.clearParent(new TestInstance("different parent"));
      fail("Expected error when clearing parent that's different than the current instance");
    } catch (Exception expected) {
      assertExceptionMessage(expected, AuraRuntimeException.class, "mismatched clear parent");
    }
  }
Ejemplo n.º 22
0
  /** Verify registered components are serialized in alphabetical order */
  public void testSerializeAsPart() throws Exception {
    InstanceStack iStack = new InstanceStack();
    iStack.setConfigAdapter(mci);
    JsonEncoder jsonMock = Mockito.mock(JsonEncoder.class);
    BaseComponent<?, ?> a = getComponentWithPath("a");
    BaseComponent<?, ?> b = getComponentWithPath("b");
    BaseComponent<?, ?> c = getComponentWithPath("c");
    iStack.registerComponent(b);
    iStack.registerComponent(c);
    iStack.registerComponent(a);
    iStack.serializeAsPart(jsonMock);

    List<BaseComponent<?, ?>> sorted = Lists.newArrayList();
    sorted.add(a);
    sorted.add(b);
    sorted.add(c);
    verify(jsonMock).writeMapKey("components");
    verify(jsonMock).writeArray(sorted);
  }
Ejemplo n.º 23
0
  public void testComponents() {
    InstanceStack iStack = new InstanceStack();
    iStack.setConfigAdapter(mci);
    Map<String, BaseComponent<?, ?>> comps = iStack.getComponents();
    assertNotNull("Components should never be null", comps);
    assertEquals("Components should empty", 0, comps.size());

    BaseComponent<?, ?> x = getComponentWithPath("a");
    iStack.registerComponent(x);
    comps = iStack.getComponents();
    assertNotNull("Components should never be null", comps);
    assertEquals("Components should have one component", 1, comps.size());
    assertEquals("Components should have x", x, comps.get("a"));

    BaseComponent<?, ?> y = getComponentWithPath("b");
    iStack.registerComponent(y);
    comps = iStack.getComponents();
    assertNotNull("Components should never be null", comps);
    assertEquals("Components should have two components", 2, comps.size());
    assertEquals("Components should have x", x, comps.get("a"));
    assertEquals("Components should have y", y, comps.get("b"));
  }
Ejemplo n.º 24
0
 public void testPeekAtEmptyStackReturnsNull() throws Exception {
   InstanceStack iStack = new InstanceStack();
   iStack.setConfigAdapter(mci);
   assertEquals("Expecting null at top of empty stack", null, iStack.peek());
 }