示例#1
0
 @Test
 public void convertToSequence() {
   Folder c = db.createFolder("/top");
   c.documents().build(Name.create(db, "one")).elem("test").end("test").commit();
   XMLDocument doc = c.documents().build(Name.create(db, "two")).elem("test").end("test").commit();
   assertEquals(2, c.query().all("/test").size());
   assertEquals(1, c.query().all("$_1/test", new Object[] {doc}).size());
 }
示例#2
0
 @Test
 public void query4() {
   Folder c1 = db.createFolder("/c1");
   XMLDocument doc =
       c1.documents().build(Name.create(db, "original")).elem("test").end("test").commit();
   c1.documents().build(Name.create(db, "another")).elem("test").end("test").commit();
   doc.query().single("/test");
   assertEquals(2, c1.query().all("/test").size());
 }
示例#3
0
 @Test
 public void copy1() {
   Folder c1 = db.createFolder("/c1"), c2 = db.createFolder("/c2");
   XMLDocument original =
       c1.documents().build(Name.create(db, "original")).elem("test").end("test").commit();
   XMLDocument copy = original.copy(c2, Name.keepCreate(db));
   assertEquals(1, c1.documents().size());
   c1.query().single("/test");
   assertEquals(1, c2.documents().size());
   c2.query().single("/test");
   copy.query().single("/test");
 }
示例#4
0
 @Test
 public void move1() {
   Folder c1 = db.createFolder("/c1"), c2 = db.createFolder("/c2");
   XMLDocument doc =
       c1.documents().build(Name.create(db, "original")).elem("test").end("test").commit();
   doc.move(c2, Name.keepCreate(db));
   assertEquals(0, c1.documents().size());
   assertFalse(c1.query().exists("/test"));
   assertEquals(1, c2.documents().size());
   c2.query().single("/test");
   doc.query().single("/test");
   assertEquals("/c2/original", doc.path());
 }
示例#5
0
 @Test
 public void query2() {
   Folder c1 = db.createFolder("/c1");
   c1.documents().build(Name.create(db, "original")).elem("test").end("test").commit();
   XMLDocument doc = c1.documents().get("original").xml();
   doc.query().single("/test");
 }
示例#6
0
 @Test
 public void nameAndPathFromLoad() {
   XMLDocument doc =
       db.createFolder("/top").documents().load(Name.create(db, "foo"), Source.xml("<root/>"));
   assertEquals("foo", doc.name());
   assertEquals("/top/foo", doc.path());
 }
示例#7
0
    @Test
    public void resolve() throws RuleBaseException, TransformException {
      final Node m1 = content.query().single("/id('m1')").node();
      final Node m2 = content.query().single("/id('m2')").node();
      final SortBlock mockBlock = mockery.mock(SortBlock.class);
      SortBlock block =
          new SortBlock(
              db.getFolder("/")
                  .documents()
                  .load(
                      Name.create("rule"),
                      Source.xml("<rule><sort by='ascending'>@foo</sort></rule>"))
                  .root()
                  .query()
                  .single("*")
                  .node()) {
            @Override
            void resolveOrder(Builder aModBuilder, Node node) throws TransformException {
              mockBlock.resolveOrder(aModBuilder, node);
            }

            @Override
            public Seg createSeg(Mod unused) {
              fail();
              return null;
            }
          };
      modBuilder = mockery.mock(Mod.Builder.class);
      mockery.checking(
          new Expectations() {
            {
              one(modBuilder).dependOn(m1.document());
              one(modBuilder).dependOn(m2.document());
              Sequence seq1 = mockery.sequence("pre-commit resolveOrder 1");
              Sequence seq2 = mockery.sequence("pre-commit resolveOrder 2");
              one(mockBlock).resolveOrder(modBuilder, m1);
              inSequence(seq1);
              one(mockBlock).resolveOrder(modBuilder, m2);
              inSequence(seq2);
              modBuilderPriors.add(seq1);
              modBuilderPriors.add(seq2);
            }
          });
      block.requiredVariables =
          Arrays.asList(new QName[] {new QName(null, "a", null), new QName(null, "b", null)});
      dependOnNearest(
          NodeTarget.class,
          false,
          new NodeTarget() {
            public ItemList targets() throws TransformException {
              return content.query().all("/id('m1 m2')");
            }
          });
      order("m1");
      order("m2");
      dependOnVariables(new QName(null, "a", null), new QName(null, "b", null));
      thenCommit();
      block.resolve(modBuilder);
    }
示例#8
0
 @Test
 public void delete1() {
   Folder c1 = db.createFolder("/c1");
   XMLDocument doc =
       c1.documents().build(Name.create(db, "original")).elem("test").end("test").commit();
   doc.delete();
   assertEquals(0, c1.documents().size());
 }
示例#9
0
 @Test
 public void writeToOutputStream() throws IOException {
   XMLDocument doc =
       db.createFolder("/top").documents().load(Name.create(db, "foo"), Source.xml("<root/>"));
   ByteArrayOutputStream out = new ByteArrayOutputStream();
   doc.write(out);
   out.close();
   assertEquals("<root/>", out.toString());
 }
示例#10
0
 @Test
 public void lengthFromCreate() {
   XMLDocument doc =
       db.createFolder("/top")
           .documents()
           .build(Name.create(db, "foo"))
           .elem("root")
           .end("root")
           .commit();
   assertThat(doc.length(), Matchers.greaterThan(0L));
 }
示例#11
0
 @Test
 public void contentsAsStringFromCreate() {
   XMLDocument doc =
       db.createFolder("/top")
           .documents()
           .build(Name.create(db, "foo"))
           .elem("root")
           .end("root")
           .commit();
   assertEquals("<root/>", doc.contentsAsString());
 }
示例#12
0
 @Test
 public void delete2() {
   Folder c1 = db.createFolder("/c1");
   XMLDocument doc1 =
       c1.documents()
           .build(Name.create(db, "doc1"))
           .elem("test")
           .attr("xml:id", "a")
           .end("test")
           .commit();
   XMLDocument doc2 =
       c1.documents()
           .build(Name.create(db, "doc2"))
           .elem("test2")
           .attr("xml:id", "b")
           .end("test2")
           .commit();
   doc1.delete();
   doc2.delete();
   assertEquals(0, c1.documents().size());
 }
示例#13
0
 @Test
 public void nameAndPathFromCreate() {
   XMLDocument doc =
       db.createFolder("/top")
           .documents()
           .build(Name.create(db, "foo"))
           .elem("root")
           .end("root")
           .commit();
   assertEquals("foo", doc.name());
   assertEquals("/top/foo", doc.path());
 }
示例#14
0
 @Test
 public void lengthFromLoad() {
   XMLDocument doc =
       db.createFolder("/top").documents().load(Name.create(db, "foo"), Source.xml("<root/>"));
   assertThat(doc.length(), Matchers.greaterThan(0L));
 }
示例#15
0
 @Test
 public void contentsAsStringFromLoad() {
   XMLDocument doc =
       db.createFolder("/top").documents().load(Name.create(db, "foo"), Source.xml("<root/>"));
   assertEquals("<root/>", doc.contentsAsString());
 }