@Test public void testGetQueryWriterSetForNode() { Set<String> qs1 = new HashSet<String>(); Set<String> qs2 = new HashSet<String>(); Set<String> qs3 = new HashSet<String>(); Set<String> qs4 = new HashSet<String>(); Set<String> qs5 = new HashSet<String>(); Set<String> qs6 = new HashSet<String>(); Set<Activity> as1 = new HashSet<Activity>(); Set<Activity> as2 = new HashSet<Activity>(); Set<Activity> as3 = new HashSet<Activity>(); Set<Activity> as4 = new HashSet<Activity>(); Set<Activity> as5 = new HashSet<Activity>(); Set<Activity> as6 = new HashSet<Activity>(); Activity A = BPELFactory.eINSTANCE.createActivity(); Activity B = BPELFactory.eINSTANCE.createActivity(); Activity C = BPELFactory.eINSTANCE.createActivity(); Activity D = BPELFactory.eINSTANCE.createActivity(); Activity E = BPELFactory.eINSTANCE.createActivity(); Activity F = BPELFactory.eINSTANCE.createActivity(); A.setName("A"); B.setName("B"); C.setName("C"); D.setName("D"); E.setName("E"); F.setName("F"); qs1.add(".a"); qs2.add(".b"); qs3.add(".c"); qs4.add(".d"); qs5.add(".e"); qs6.add(".f"); as1.add(A); as1.add(D); as2.add(A); as2.add(E); as3.add(A); as4.add(B); as4.add(D); as5.add(B); as5.add(E); as6.add(C); Map<Set<String>, Set<Activity>> qs2wsMap = new HashMap<Set<String>, Set<Activity>>(); qs2wsMap.put(qs1, as1); qs2wsMap.put(qs2, as2); qs2wsMap.put(qs3, as3); qs2wsMap.put(qs4, as4); qs2wsMap.put(qs5, as5); qs2wsMap.put(qs6, as6); // now we have the tuples (query set: writer set) - {x.a}:{A,D}, // {x.b}:{A,E}, {x.c}:{A}, {x.d}:{B, D}, // {x.e}:{B,E}, {x.f}:{C} // create a queryWriterSet Activity a = BPELFactory.eINSTANCE.createActivity(); Variable x = BPELFactory.eINSTANCE.createVariable(); MyQueryWriterSet myqws = new MyQueryWriterSet(a, x, qs2wsMap); // now create a pwdg node PWDGNode node = new PWDGNode(); WDGNode wnode1 = new WDGNode(A); WDGNode wnode2 = new WDGNode(B); node.add(wnode1); node.add(wnode2); // now we try the getQuerywriterSetFor the pwdgNode QueryWriterSet qwsForNode = myqws.getQueryWriterSetFor(node); assertNotNull(qwsForNode); assertEquals(qwsForNode.getActivity(), myqws.getActivity()); assertEquals(qwsForNode.getVariable(), myqws.getVariable()); // the writer set now is {A, B} assertEquals(qwsForNode.getAllWriters().size(), 2); assertTrue(qwsForNode.getAllWriters().contains(A)); assertTrue(qwsForNode.getAllWriters().contains(B)); // the node filtered queryWriterSet should contain {x.a, x.b, x.c}:{A} Set<String> expectedQs = new HashSet<String>(); expectedQs.add(".a"); expectedQs.add(".b"); expectedQs.add(".c"); Set<Activity> expectedWs = new HashSet<Activity>(); expectedWs.add(A); Set<Activity> actualWs = qwsForNode.get(expectedQs); assertNotNull(actualWs); assertTrue(expectedWs.equals(actualWs)); // the node filtered queryWriterSet should contain {x.d, x.e}:{B} expectedQs.clear(); expectedQs.add(".d"); expectedQs.add(".e"); expectedWs.clear(); expectedWs.add(B); actualWs = qwsForNode.get(expectedQs); assertNotNull(actualWs); assertTrue(expectedWs.equals(actualWs)); // for pwdg node {F}, the query writer set is empty WDGNode wdgNodeF = new WDGNode(F); PWDGNode node2 = new PWDGNode(); node2.add(wdgNodeF); QueryWriterSet qwsForNodeF = myqws.getQueryWriterSetFor(node2); assertNotNull(qwsForNodeF); assertTrue(qwsForNodeF.isEmpty()); }
@Test public void testMergeQuerySet() { // create a queryWriterSet Set<String> qs1 = new HashSet<String>(); Set<String> qs2 = new HashSet<String>(); Set<String> qs3 = new HashSet<String>(); Set<String> qs4 = new HashSet<String>(); Set<String> qs5 = new HashSet<String>(); Set<String> qs6 = new HashSet<String>(); Set<Activity> as1 = new HashSet<Activity>(); Set<Activity> as2 = new HashSet<Activity>(); Set<Activity> as3 = new HashSet<Activity>(); Set<Activity> as4 = new HashSet<Activity>(); Set<Activity> as5 = new HashSet<Activity>(); Set<Activity> as6 = new HashSet<Activity>(); Activity A = BPELFactory.eINSTANCE.createActivity(); Activity B = BPELFactory.eINSTANCE.createActivity(); Activity C = BPELFactory.eINSTANCE.createActivity(); A.setName("A"); B.setName("B"); C.setName("C"); qs1.add(".a"); qs2.add(".b"); qs3.add(".c"); qs4.add(".d"); qs5.add(".e"); qs6.add(".f"); as1.add(A); as2.add(A); as3.add(A); as4.add(B); as5.add(B); as6.add(C); Map<Set<String>, Set<Activity>> qs2wsMap = new HashMap<Set<String>, Set<Activity>>(); qs2wsMap.put(qs1, as1); qs2wsMap.put(qs2, as2); qs2wsMap.put(qs3, as3); qs2wsMap.put(qs4, as4); qs2wsMap.put(qs5, as5); qs2wsMap.put(qs6, as6); // now try it Activity a = BPELFactory.eINSTANCE.createActivity(); Variable x = BPELFactory.eINSTANCE.createVariable(); Map<Set<String>, Set<Activity>> emptyMap = new HashMap<Set<String>, Set<Activity>>(); MyQueryWriterSet myqws = new MyQueryWriterSet(a, x, emptyMap); myqws.mergeQuerySet(qs2wsMap); // test assertNotNull(qs2wsMap); assertEquals(3, qs2wsMap.size()); // now there should be a {.a, .b, .c}:{A} entry Set<String> expectedQs = new HashSet<String>(); expectedQs.add(".a"); expectedQs.add(".b"); expectedQs.add(".c"); Set<Activity> expectedWs = new HashSet<Activity>(); expectedWs.add(A); Set<Activity> actualWs = qs2wsMap.get(expectedQs); assertNotNull(actualWs); assertTrue(expectedWs.equals(actualWs)); // {.d, .e}:{B} expectedQs.clear(); expectedQs.add(".d"); expectedQs.add(".e"); expectedWs.clear(); expectedWs.add(B); actualWs = qs2wsMap.get(expectedQs); assertNotNull(actualWs); assertTrue(expectedWs.equals(actualWs)); // now there should also be {x.f}:{C} entry expectedQs.clear(); expectedQs.add(".f"); expectedWs.clear(); expectedWs.add(C); actualWs = qs2wsMap.get(expectedQs); assertNotNull(actualWs); assertTrue(expectedWs.equals(actualWs)); }