@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(); }
@Test(expected = TransformException.class) public void restoreBadQuery() throws RuleBaseException, TransformException { setModNearestAncestorImplementing( NodeTarget.class, new NodeTarget() { public ItemList targets() throws TransformException { return content.query().all("/id('c1')"); } }); setModScope(content.query().single("/id('c1')").node().query()); SortByValueBlock block = define("<sort by='ascending'>*</sort>"); SortByValueBlock.SortByValueSeg seg = (SortByValueBlock.SortByValueSeg) block.createSeg(mod); seg.restore(); }
@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(); }
private void runVerifyScenario(String proxyid, String modData) throws TransformException, RuleBaseException { Node um1 = content.query().single("/id('um1')").node(); Node m1 = content.query().single("/id('m1')").node(); setModNearestAncestorImplementing( NodeTarget.class, new NodeTarget() { public ItemList targets() throws TransformException { return content.query().all("/id('um1')"); } }); setModData(modData); setModReferences(content.query().single("/id($_1)", proxyid).node()); setModScope(um1.query().let("$source", m1)); SortByProxyBlock block = define("<sort as='corresponding'>$source</sort>"); SortByProxyBlock.SortByProxySeg seg = (SortByProxyBlock.SortByProxySeg) block.createSeg(mod); seg.proxies = new ArrayList<Pair<String, Node>>(); seg.proxies.add(Pair.of("um1", mod.references().get(0))); seg.verify(); }
@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); }