Ejemplo n.º 1
0
 @Test(expected = TransformException.class)
 public void resolveOrderBadQuery() throws RuleBaseException, TransformException {
   SortBlock block = define("<sort as='corresponding'>*</sort>");
   Node uc1 = content.query().single("/id('uc1')").node();
   setModBuilderCustomScope(uc1.query());
   block.resolveOrder(modBuilder, uc1);
 }
Ejemplo n.º 2
0
 @Test
 public void totalOrder() throws RuleBaseException {
   SortBlock block = define("<sort by='ascending' priority='5'>@foo</sort>");
   final OrderGraph graph = mockery.mock(OrderGraph.class);
   mockery.checking(
       new Expectations() {
         {
           one(graph).order("x2", "x1", 5);
           one(graph).order("x2", "x3", 5);
           one(graph).order("x2", "x4", 5);
           one(graph).order("x1", "x4", 5);
           one(graph).order("x3", "x4", 5);
         }
       });
   List<Pair<String, Integer>> list = new ArrayList<Pair<String, Integer>>();
   list.add(Pair.of("x1", 23));
   list.add(Pair.of("x2", 18));
   list.add(Pair.of("x3", 23));
   list.add(Pair.of("x4", 35));
   Comparator<Pair<String, Integer>> comparator =
       new Comparator<Pair<String, Integer>>() {
         public int compare(Pair<String, Integer> o1, Pair<String, Integer> o2) {
           return o1.second.compareTo(o2.second);
         }
       };
   block.totalOrder(list, comparator, graph);
 }
Ejemplo n.º 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);
    }
Ejemplo n.º 4
0
 @Test(expected = TransformException.class)
 public void resolveOrderNotSibling() throws RuleBaseException, TransformException {
   SortBlock block = define("<sort before='sibling'>.//uml:operation</sort>");
   Node cname = content.query().single("/id('cname')").node();
   Node uc1 = content.query().single("/id('uc1')").node();
   setModBuilderCustomScope(uc1.query());
   block.resolveOrder(modBuilder, cname);
 }
Ejemplo n.º 5
0
 @Test
 public void analyze() throws RuleBaseException, TransformException {
   SortBlock block = define("<sort as='corresponding'>$src</sort>");
   setModGlobalScope(content.query());
   Seg seg = block.createSeg(mod);
   seg.analyze();
   assertThat(block.requiredVariables, is(collection(new QName(null, "src", null))));
 }
Ejemplo n.º 6
0
 @Test
 public void resolveOrder() throws RuleBaseException, TransformException {
   SortBlock block = define("<sort by='ascending'>@name</sort>");
   Node m1 = content.query().single("/id('m1')").node();
   setModBuilderCustomScope(m1.query());
   supplement();
   block.resolveOrder(modBuilder, m1);
   checkSupplement("<sort-value refid='m1'>start</sort-value>");
 }
Ejemplo n.º 7
0
 @Test
 public void resolveOrderEmpty() throws RuleBaseException, TransformException {
   SortBlock block = define("<sort before='sibling'>()</sort>");
   Node cname = content.query().single("/id('cname')").node();
   Node uc1 = content.query().single("/id('uc1')").node();
   setModBuilderCustomScope(uc1.query());
   supplement();
   block.resolveOrder(modBuilder, cname);
   checkSupplement("<sort-siblings run-length='0'/>");
 }
Ejemplo n.º 8
0
 @Test
 public void resolveOrder1() throws RuleBaseException, TransformException {
   SortBlock block = define("<sort after='sibling'>uml:name</sort>");
   Node comp1 = content.query().single("/id('comp1')").node();
   Node uc1 = content.query().single("/id('uc1')").node();
   setModBuilderCustomScope(uc1.query());
   reference(content.query().single("/id('cname')").node());
   supplement();
   block.resolveOrder(modBuilder, comp1);
   checkSupplement("<sort-siblings run-length='1'/>");
 }
Ejemplo n.º 9
0
 @Test
 public void resolveOrder() throws RuleBaseException, TransformException {
   SortBlock block = define("<sort as='corresponding'>$source</sort>");
   Node um1 = content.query().single("/id('um1')").node();
   Node m1 = content.query().single("/id('m1')").node();
   setModBuilderCustomScope(um1.query().let("$source", m1));
   reference(m1);
   supplement();
   block.resolveOrder(modBuilder, um1);
   checkSupplement("<sort-proxy position='1'/>");
 }