Example #1
0
 @Test
 public void restore() throws RuleBaseException, TransformException {
   Node comp1 = content.query().single("/id('comp1')").node();
   Node comp2 = content.query().single("/id('comp2')").node();
   Node cname = content.query().single("/id('cname')").node();
   setModNearestAncestorImplementing(
       NodeTarget.class,
       new NodeTarget() {
         public ItemList targets() throws TransformException {
           return content.query().all("/id('comp1 comp2')");
         }
       });
   setModData("(<sort-siblings run-length='2'/>, <sort-siblings run-length='1'/>)");
   setModReferences(cname, comp2, cname);
   SortBySiblingBlock block = define("<sort before='sibling'>uml:name</sort>");
   SortBySiblingBlock.SortBySiblingSeg seg =
       (SortBySiblingBlock.SortBySiblingSeg) block.createSeg(mod);
   seg.restore();
   assertEquals(
       Arrays.asList(
           new Pair[] {
             Pair.of(comp1, Arrays.asList(cname, comp2)), Pair.of(comp2, Arrays.asList(cname))
           }),
       seg.siblingsByTarget);
 }
Example #2
0
 @SuppressWarnings("unchecked")
 @Test(expected = TransformException.class)
 public void verifyNotSibling() throws RuleBaseException, TransformException {
   Node uc1 = content.query().single("/id('uc1')").node();
   Node comp1 = content.query().single("/id('comp1')").node();
   Node um1 = content.query().single("/id('um1')").node();
   setModScope(uc1.query());
   SortBySiblingBlock block = define("<sort before='sibling'>.//uml:method</sort>");
   SortBySiblingBlock.SortBySiblingSeg seg =
       (SortBySiblingBlock.SortBySiblingSeg) block.createSeg(mod);
   seg.siblingsByTarget =
       Arrays.<Pair<Node, List<Node>>>asList(new Pair[] {Pair.of(comp1, Arrays.asList(um1))});
   seg.verify();
 }
Example #3
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);
    }
Example #4
0
 @SuppressWarnings("unchecked")
 @Test
 public void verify() throws RuleBaseException, TransformException {
   Node uc1 = content.query().single("/id('uc1')").node();
   Node comp1 = content.query().single("/id('comp1')").node();
   Node comp2 = content.query().single("/id('comp2')").node();
   Node cname = content.query().single("/id('cname')").node();
   setModScope(uc1.query());
   SortBySiblingBlock block = define("<sort before='sibling'>uml:name</sort>");
   SortBySiblingBlock.SortBySiblingSeg seg =
       (SortBySiblingBlock.SortBySiblingSeg) block.createSeg(mod);
   seg.siblingsByTarget =
       Arrays.<Pair<Node, List<Node>>>asList(
           new Pair[] {
             Pair.of(comp1, Arrays.asList(cname)), Pair.of(comp2, Arrays.asList(cname))
           });
   seg.verify();
 }
Example #5
0
 @SuppressWarnings("unchecked")
 @Test
 public void sortAfter() throws RuleBaseException {
   final Node comp1 = content.query().single("/id('comp1')").node();
   final Node comp2 = content.query().single("/id('comp2')").node();
   final Node cname = content.query().single("/id('cname')").node();
   SortBySiblingBlock block = define("<sort after='sibling'>uml:name</sort>");
   SortBySiblingBlock.SortBySiblingSeg seg1 =
       (SortBySiblingBlock.SortBySiblingSeg) block.createSeg(mod);
   SortBySiblingBlock.SortBySiblingSeg seg2 =
       (SortBySiblingBlock.SortBySiblingSeg) block.createSeg(mod);
   seg1.siblingsByTarget =
       Arrays.<Pair<Node, List<Node>>>asList(
           new Pair[] {
             Pair.of(comp1, Arrays.asList(cname, comp2)), Pair.of(comp2, Arrays.asList(cname))
           });
   seg2.siblingsByTarget =
       Arrays.<Pair<Node, List<Node>>>asList(new Pair[] {Pair.of(cname, Arrays.asList(comp2))});
   final OrderGraph graph = mockery.mock(OrderGraph.class);
   mockery.checking(
       new Expectations() {
         {
           one(graph).order(cname, comp1, 0);
           one(graph).order(comp2, comp1, 0);
           one(graph).order(cname, comp2, 0);
           one(graph).order(comp2, cname, 0);
         }
       });
   block.sort(Arrays.asList(seg1, seg2), graph);
 }
Example #6
0
 @Test
 public void sortDescending() throws RuleBaseException {
   SortByValueBlock block = define("<sort by='descending'>@name</sort>");
   SortByValueBlock.SortByValueSeg seg1 = (SortByValueBlock.SortByValueSeg) block.createSeg(mod);
   SortByValueBlock.SortByValueSeg seg2 = (SortByValueBlock.SortByValueSeg) block.createSeg(mod);
   seg1.values = new ArrayList<Pair<String, Item>>();
   seg1.values.add(Pair.of("m1", content.query().single("/id('m1')/@name").toAtomicItem()));
   seg2.values = new ArrayList<Pair<String, Item>>();
   seg2.values.add(Pair.of("m2", content.query().single("/id('m2')/@name").toAtomicItem()));
   final OrderGraph graph = mockery.mock(OrderGraph.class);
   mockery.checking(
       new Expectations() {
         {
           one(graph).order("m1", "m2", 0);
         }
       });
   block.sort(Arrays.asList(seg1, seg2), graph);
 }
Example #7
0
 @Test
 public void sort() throws RuleBaseException {
   SortByProxyBlock block = define("<sort as='corresponding'>$source</sort>");
   SortByProxyBlock.SortByProxySeg seg1 = (SortByProxyBlock.SortByProxySeg) block.createSeg(mod);
   SortByProxyBlock.SortByProxySeg seg2 = (SortByProxyBlock.SortByProxySeg) block.createSeg(mod);
   seg1.proxies = new ArrayList<Pair<String, Node>>();
   seg2.proxies = new ArrayList<Pair<String, Node>>();
   seg1.proxies.add(Pair.of("um1", content.query().single("/id('m1')").node()));
   seg2.proxies.add(Pair.of("uf1", content.query().single("/id('f1')").node()));
   seg1.proxies.add(Pair.of("um2", content.query().single("/id('m2')").node()));
   seg2.proxies.add(Pair.of("uf2", content.query().single("/id('f1')").node()));
   final OrderGraph graph = mockery.mock(OrderGraph.class);
   mockery.checking(
       new Expectations() {
         {
           one(graph).order("um1", "um2", 0);
         }
       });
   block.sort(Arrays.asList(seg1, seg2), graph);
 }
Example #8
0
 @Test
 public void restore() throws RuleBaseException, TransformException {
   setModNearestAncestorImplementing(
       NodeTarget.class,
       new NodeTarget() {
         public ItemList targets() throws TransformException {
           return content.query().all("/id('um1 um2')");
         }
       });
   setModData("(<sort-proxy position='1'/>, <sort-proxy position='2'/>)");
   setModReferences(
       content.query().single("/id('m1')").node(), content.query().single("/id('m2')").node());
   SortByProxyBlock block = define("<sort as='corresponding'>$source</sort>");
   SortByProxyBlock.SortByProxySeg seg = (SortByProxyBlock.SortByProxySeg) block.createSeg(mod);
   seg.restore();
   assertEquals(
       Arrays.asList(
           new Pair[] {
             Pair.of("um1", content.query().single("/id('m1')").node()),
             Pair.of("um2", content.query().single("/id('m2')").node())
           }),
       seg.proxies);
 }
Example #9
0
 @Test
 public void restore() throws RuleBaseException, TransformException {
   setModNearestAncestorImplementing(
       NodeTarget.class,
       new NodeTarget() {
         public ItemList targets() throws TransformException {
           return content.query().all("/id('m1 m2')");
         }
       });
   setModScope(
       content.query().single("/id('m1')").node().query(),
       content.query().single("/id('m2')").node().query());
   SortByValueBlock block = define("<sort by='ascending'>@name</sort>");
   SortByValueBlock.SortByValueSeg seg = (SortByValueBlock.SortByValueSeg) block.createSeg(mod);
   seg.restore();
   assertEquals(
       Arrays.asList(
           new Pair[] {
             Pair.of("m1", content.query().single("/id('m1')/@name").toAtomicItem()),
             Pair.of("m2", content.query().single("/id('m2')/@name").toAtomicItem())
           }),
       seg.values);
 }