Package org.infinispan.tree

Examples of org.infinispan.tree.Fqn


      child = Fqn.fromString("/a/b/c/d/e/f/g/h/e/r/e/r/t/tt/");
      assert child.isChildOf(parent);
   }

   public void testIsChildOf2() {
      Fqn child = Fqn.fromString("/a/b/c/d");
      assert "/b/c/d".equals(child.getSubFqn(1, child.size()).toString());
   }


      Fqn child = Fqn.fromString("/a/b/c/d");
      assert "/b/c/d".equals(child.getSubFqn(1, child.size()).toString());
   }

   public void testParentage() {
      Fqn fqnRoot = Fqn.ROOT;
      Fqn parent = fqnRoot.getParent();
      assert parent.equals(fqnRoot);

      Fqn fqnOne = Fqn.fromString("/one");
      parent = fqnOne.getParent();
      assert parent.equals(fqnRoot);
      assert fqnOne.isChildOf(parent);

      Fqn fqnTwo = Fqn.fromString("/one/two");
      parent = fqnTwo.getParent();
      assert parent.equals(fqnOne);
      assert fqnTwo.isChildOf(parent);

      Fqn fqnThree = Fqn.fromString("/one/two/three");
      parent = fqnThree.getParent();
      assert parent.equals(fqnTwo);
      assert fqnThree.isChildOf(parent);

   }

      assert fqnThree.isChildOf(parent);

   }

   public void testRoot() {
      Fqn fqn = Fqn.ROOT;
      assert fqn.isRoot();

      fqn = Fqn.fromString("/one/two");
      assert !fqn.isRoot();

      Fqn f = Fqn.fromString("/");

      assert f.isRoot();
      assert f.equals(Fqn.ROOT);
   }

      assert f.isRoot();
      assert f.equals(Fqn.ROOT);
   }

   public void testGetName() {
      Fqn integerFqn = Fqn.fromElements(1);
      assert "1".equals(integerFqn.getLastElementAsString());

      Object object = new Object();
      Fqn objectFqn = Fqn.fromElements(object);
      assert object.toString().equals(objectFqn.getLastElementAsString());
   }

   }

   // testing generics

   public void testSize() {
      Fqn f = Fqn.ROOT;
      assert f.size() == 0;
      assert f.isRoot();

      f = Fqn.fromString("/");
      assert f.size() == 0;
      assert f.isRoot();

      f = Fqn.fromString("/hello");
      assert f.size() == 1;
      assert !f.isRoot();
   }

      assert f.size() == 1;
      assert !f.isRoot();
   }

   public void testGenerations() {
      Fqn f = Fqn.fromElements(1, 2, 3, 4, 5, 6, 7);

      assert f.equals(f.getAncestor(f.size()));
      assert f.getParent().equals(f.getAncestor(f.size() - 1));
      assert Fqn.ROOT.equals(f.getAncestor(0));
      assert Fqn.fromElements(1).equals(f.getAncestor(1));
      assert Fqn.fromElements(1, 2).equals(f.getAncestor(2));
      assert Fqn.fromElements(1, 2, 3).equals(f.getAncestor(3));
      assert Fqn.fromElements(1, 2, 3, 4).equals(f.getAncestor(4));
      assert Fqn.fromElements(1, 2, 3, 4, 5).equals(f.getAncestor(5));

      try {
         f.getAncestor(-1);
         // should fail
         assert false;
      }
      catch (IllegalArgumentException good) {
         // expected
      }

      try {
         f.getAncestor(f.size() + 1);
         // should fail
         assert false;
      }
      catch (IndexOutOfBoundsException good) {
         // expected

         // expected
      }
   }

   public void testReplacingDirectAncestor() {
      Fqn fqn = Fqn.fromString("/a/b/c");
      Fqn newParent = Fqn.fromString("/hot/dog");
      Fqn expectedNewChild = Fqn.fromString("/hot/dog/c");

      assert expectedNewChild.equals(fqn.replaceAncestor(fqn.getParent(), newParent));
   }

      assert expectedNewChild.equals(fqn.replaceAncestor(fqn.getParent(), newParent));
   }

   public void testReplacingindirectAncestor() {
      Fqn fqn = Fqn.fromString("/a/b/c");
      Fqn newParent = Fqn.fromString("/hot/dog");
      Fqn expectedNewChild = Fqn.fromString("/hot/dog/b/c");

      Fqn replaced = fqn.replaceAncestor(fqn.getParent().getParent(), newParent);
      assert expectedNewChild.equals(replaced) : "Expected " + expectedNewChild + " but was " + replaced;
   }

   /**
    * Another convenience method that tests node removal
    */
   public void testNodeConvenienceNodeRemoval() {
      // this fqn is relative, but since it is from the root it may as well be absolute
      Fqn fqn = Fqn.fromString("/test/fqn");
      cache.getRoot().addChild(fqn);
      assertTrue(cache.getRoot().hasChild(fqn));

      assertEquals(true, cache.removeNode(fqn));
      assertFalse(cache.getRoot().hasChild(fqn));
      // remove should REALLY remove though and not just mark as deleted/invalid.
      Node n = cache.getNode(fqn);
      assert n == null;

      assertEquals(false, cache.removeNode(fqn));

      // remove should REALLY remove though and not just mark as deleted/invalid.
      n = cache.getNode(fqn);
      assert n == null;

      // Check that it's removed if it has a child
      Fqn child = Fqn.fromString("/test/fqn/child");
      log.error("TEST: Adding child " + child);
      cache.getRoot().addChild(child);
      assertStructure(cache, "/test/fqn/child");

      assertEquals(true, cache.removeNode(fqn));

   }

   private void assertStructure(TreeCache tc, String fqnStr) {
      // make sure structure nodes are properly built and maintained
      Cache c = tc.getCache();
      Fqn fqn = Fqn.fromString(fqnStr);
      // loop thru the Fqn, starting at its root, and make sure all of its children exist in proper NodeKeys
      for (int i = 0; i < fqn.size(); i++) {
         Fqn parent = fqn.getSubFqn(0, i);
         Object childName = fqn.get(i);
         // make sure a data key exists in the cache
         assert c.containsKey(new NodeKey(parent, NodeKey.Type.DATA)) : "Node [" + parent + "] does not have a Data atomic map!";
         assert c.containsKey(new NodeKey(parent, NodeKey.Type.STRUCTURE)) : "Node [" + parent + "] does not have a Structure atomic map!";
         AtomicMap<Object, Fqn> am = AtomicMapLookup.getAtomicMap(c, new NodeKey(parent, NodeKey.Type.STRUCTURE));

TOP

Related Classes of org.infinispan.tree.Fqn

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.