ServiceDependencyBuilder { protected static void filter(ServiceGraph sg, String focusServiceType) { ServiceNode focus=sg.getServiceNode(focusServiceType); if (focus != null) { java.util.Set<ServiceNode> serviceProviders=new java.util.HashSet<ServiceNode>(); java.util.Iterator<ServiceNode> serviceNodeIter=sg.getServiceNodes().iterator(); while (serviceNodeIter.hasNext()) { ServiceNode node=serviceNodeIter.next(); if (node == focus || serviceProviders.contains(node)) { continue; } if (sg.getUsageLink(node, focus) != null) { continue; } java.util.Set<ServiceNode> visited=new java.util.HashSet<ServiceNode>(); if (!isServiceProvider(sg, node, focus, visited)) { java.util.Iterator<InvocationLink> ilIter=sg.getInvocationLinks().iterator(); while (ilIter.hasNext()) { InvocationLink il=ilIter.next(); if (node.getOperations().contains(il.getSource()) || node.getOperations().contains(il.getTarget())) { ilIter.remove(); } } java.util.Iterator<UsageLink> ulIter=sg.getUsageLinks().iterator(); while (ulIter.hasNext()) { UsageLink ul=ulIter.next(); if (ul.getSource() == node || ul.getTarget() == node) { ulIter.remove(); } } serviceNodeIter.remove(); } else { serviceProviders.addAll(visited); } } } } private  ServiceDependencyBuilder(); static java.util.Set<ServiceDefinition> getInitialServices(java.util.Collection<ServiceDefinition> sds); static java.util.Set<ServiceDefinition> getServiceClients(ServiceDefinition mainsd,
                        java.util.Collection<ServiceDefinition> sds); static ServiceGraph buildGraph(java.util.Set<ServiceDefinition> sds,
                        java.util.List<Situation> sits, String focusServiceType); static ServiceGraph buildGraph(java.util.Set<ServiceDefinition> sds,
                        java.util.List<Situation> sits); static InvocationMetric getMergedMetrics(java.util.List<InvocationDefinition> invocations);  }
@Test public void testFilterGraphFocusSN1() { ServiceGraph sg=getServiceGraph(); ServiceDependencyBuilder.filter(sg, SERVICE_TYPE1); verifyFullServiceGraph(sg); }
@Test public void testFilterGraphFocusSN2() { ServiceGraph sg=getServiceGraph(); ServiceDependencyBuilder.filter(sg, SERVICE_TYPE2); if (sg == null) { fail("Result null"); } if (sg.getServiceNodes().size() != 3) { fail("Expecting 3 nodes: "+sg.getServiceNodes().size()); } if (sg.getUsageLinks().size() != 2) { fail("Expecting 2 usage links: "+sg.getUsageLinks().size()); } if (sg.getInvocationLinks().size() != 2) { fail("Expecting 2 invocation links: "+sg.getInvocationLinks().size()); } ServiceNode sn1=sg.getServiceNodeForInterface(INTERFACE1); OperationNode opn1=sn1.getOperation(OP1); ServiceNode sn2=sg.getServiceNodeForInterface(INTERFACE2); OperationNode opn2=sn2.getOperation(OP2); ServiceNode sn3=sg.getServiceNodeForInterface(INTERFACE3); OperationNode opn3=sn3.getOperation(OP3); ServiceNode sn4=sg.getServiceNodeForInterface(INTERFACE4); if (sg.getUsageLink(sn1, sn2) == null) { fail("UsageLink from s1 to s2 not present"); } if (sg.getUsageLink(sn2, sn3) == null) { fail("UsageLink from s2 to s3 not present"); } if (sg.getInvocationLink(opn1, opn2) == null) { fail("Link from op1 to op2 not present"); } if (sg.getInvocationLink(opn2, opn3) == null) { fail("Link from op2 to op3 not present"); } if (sn4 != null) { fail("Service node with interface4 should not be present"); } }
@Test public void testFilterGraphFocusSN3() { ServiceGraph sg=getServiceGraph(); ServiceDependencyBuilder.filter(sg, SERVICE_TYPE3); if (sg == null) { fail("Result null"); } if (sg.getServiceNodes().size() != 2) { fail("Expecting 2 nodes: "+sg.getServiceNodes().size()); } if (sg.getUsageLinks().size() != 1) { fail("Expecting 1 usage links: "+sg.getUsageLinks().size()); } if (sg.getInvocationLinks().size() != 1) { fail("Expecting 1 invocation links: "+sg.getInvocationLinks().size()); } ServiceNode sn1=sg.getServiceNodeForInterface(INTERFACE1); ServiceNode sn2=sg.getServiceNodeForInterface(INTERFACE2); OperationNode opn2=sn2.getOperation(OP2); ServiceNode sn3=sg.getServiceNodeForInterface(INTERFACE3); OperationNode opn3=sn3.getOperation(OP3); ServiceNode sn4=sg.getServiceNodeForInterface(INTERFACE4); if (sg.getUsageLink(sn2, sn3) == null) { fail("UsageLink from s2 to s3 not present"); } if (sg.getInvocationLink(opn2, opn3) == null) { fail("Link from op2 to op3 not present"); } if (sn1 != null) { fail("Service node with interface1 should not be present"); } if (sn4 != null) { fail("Service node with interface4 should not be present"); } }