ServiceDependencyBuilder { public static ServiceGraph buildGraph(java.util.Set<ServiceDefinition> sds, java.util.List<Situation> sits, String focusServiceType) { ServiceGraph ret=buildGraph(sds, sits); if (focusServiceType != null) { filter(ret, focusServiceType); } return (ret); } 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 testBuildGraph() { ServiceDefinition sd1=new ServiceDefinition(); sd1.setServiceType(SERVICE_TYPE1); InterfaceDefinition idef1=new InterfaceDefinition(); sd1.getInterfaces().add(idef1); idef1.setInterface(INTERFACE1); OperationDefinition op1=new OperationDefinition(); op1.setName(OP1); idef1.getOperations().add(op1); RequestResponseDefinition rrd1=new RequestResponseDefinition(); op1.setRequestResponse(rrd1); InvocationDefinition id1=new InvocationDefinition(); id1.setInterface(INTERFACE2); id1.setOperation(OP2); rrd1.getInvocations().add(id1); ServiceDefinition sd2=new ServiceDefinition(); sd2.setServiceType(SERVICE_TYPE2); InterfaceDefinition idef2=new InterfaceDefinition(); sd2.getInterfaces().add(idef2); idef2.setInterface(INTERFACE2); OperationDefinition op2=new OperationDefinition(); op2.setName(OP2); idef2.getOperations().add(op2); RequestResponseDefinition rrd2=new RequestResponseDefinition(); op2.setRequestResponse(rrd2); InvocationDefinition id2a=new InvocationDefinition(); id2a.setInterface(INTERFACE1); id2a.setOperation(OP1); rrd2.getInvocations().add(id2a); InvocationDefinition id2c=new InvocationDefinition(); id2c.setInterface(INTERFACE3); id2c.setOperation(OP3); rrd2.getInvocations().add(id2c); RequestFaultDefinition rfd2=new RequestFaultDefinition(); op2.getRequestFaults().add(rfd2); InvocationDefinition id2b=new InvocationDefinition(); id2b.setInterface(INTERFACE3); id2b.setOperation(OP3); rfd2.getInvocations().add(id2b); ServiceDefinition sd3=new ServiceDefinition(); sd3.setServiceType(SERVICE_TYPE3); InterfaceDefinition idef3=new InterfaceDefinition(); sd3.getInterfaces().add(idef3); idef3.setInterface(INTERFACE3); OperationDefinition op3=new OperationDefinition(); op3.setName(OP3); idef3.getOperations().add(op3); java.util.Set<ServiceDefinition> sds=new java.util.HashSet<ServiceDefinition>(); sds.add(sd1); sds.add(sd2); sds.add(sd3); java.util.List<Situation> sits=new java.util.ArrayList<Situation>(); Situation sit1=new Situation(); sit1.setSeverity(Situation.Severity.Critical); sit1.setSubject(Situation.createSubject(SERVICE_TYPE1)); sit1.setType("SLA Violation"); sit1.setDescription("Service exceeded SLA"); sits.add(sit1); Situation sit2=new Situation(); sit2.setSeverity(Situation.Severity.High); sit2.setSubject(Situation.createSubject(SERVICE_TYPE1)); sit2.setType("SLA Warning"); sit2.setDescription("Service close to violating SLA"); sits.add(sit2); Situation sit3=new Situation(); sit3.setSeverity(Situation.Severity.High); sit3.setSubject(Situation.createSubject(SERVICE_TYPE2, OP2, FAULT2)); sit3.setType("SLA Violation"); sit3.setDescription("Service exceeded SLA"); sits.add(sit3); ServiceGraph result= ServiceDependencyBuilder.buildGraph(sds, sits); if (result == null) { fail("Result null"); } if (result.getServiceNodes().size() != 3) { fail("Expecting 3 nodes: "+result.getServiceNodes().size()); } if (result.getUsageLinks().size() != 3) { fail("Expecting 3 usage links: "+result.getUsageLinks().size()); } if (result.getInvocationLinks().size() != 3) { fail("Expecting 3 invocation links: "+result.getInvocationLinks().size()); } ServiceNode sn1=result.getServiceNodeForInterface(INTERFACE1); OperationNode opn1=sn1.getOperation(OP1); ServiceNode sn2=result.getServiceNodeForInterface(INTERFACE2); OperationNode opn2=sn2.getOperation(OP2); ServiceNode sn3=result.getServiceNodeForInterface(INTERFACE3); OperationNode opn3=sn3.getOperation(OP3); if (result.getUsageLink(sn1, sn2) == null) { fail("UsageLink from s1 to s2 not present"); } if (result.getUsageLink(sn2, sn1) == null) { fail("UsageLink from s2 to s1 not present"); } if (result.getUsageLink(sn2, sn3) == null) { fail("UsageLink from s2 to s3 not present"); } if (result.getUsageLink(sn3, sn2) != null) { fail("UsageLink from s3 to s2 should not be present"); } int idcount=0; for (UsageLink ul : result.getUsageLinks()) { idcount += ul.getInvocations().size(); } if (idcount != 4) { fail("Expecting 4 invocation definitions: "+idcount); } if (result.getInvocationLink(opn1, opn2) == null) { fail("Link from op1 to op2 not present"); } if (result.getInvocationLink(opn2, opn1) == null) { fail("Link from op2 to op1 not present"); } if (result.getInvocationLink(opn2, opn3) == null) { fail("Link from op2 to op3 not present"); } if (result.getInvocationLink(opn3, opn2) != null) { fail("Link from op3 to op2 should not be present"); } idcount = 0; for (InvocationLink il : result.getInvocationLinks()) { idcount += il.getInvocations().size(); } if (idcount != 4) { fail("Expecting 4 invocation definitions: "+idcount); } if (sn1.getSituations().size() != 2) { fail("sn1 does not have 2 situation: "+sn1.getSituations().size()); } if (!sn1.getSituations().contains(sit1)) { fail("sn1 situation does not include sit1"); } if (!sn1.getSituations().contains(sit2)) { fail("sn1 situation does not include sit2"); } if (sn2.getSituations().size() != 0) { fail("sn2 should not have any situations: "+sn2.getSituations().size()); } if (opn2.getSituations().size() != 1) { fail("Opn2 does not have 1 situation: "+opn2.getSituations().size()); } if (opn2.getSituations().get(0) != sit3) { fail("Opn2 situation not sit3"); } }
@Test public void testMultiCastExample() { try { java.io.InputStream is=ServiceDependencyBuilderTest.class.getResourceAsStream("/activities/multicast.json"); byte[] b=new byte[is.available()]; is.read(b); ActivityUnit actUnit=ActivityUtil.deserializeActivityUnit(b); java.util.Collection<ServiceDefinition> sds=ServiceDefinitionUtil.derive(actUnit); java.util.Set<ServiceDefinition> defns=new java.util.HashSet<ServiceDefinition>(sds); ServiceGraph graph=ServiceDependencyBuilder.buildGraph(defns, Collections.<Situation> emptyList()); if (graph == null) { fail("Graph is null"); } java.util.Set<ServiceNode> nodes=graph.getServiceNodes(); if (nodes == null) { fail("Nodes list is null"); } if (nodes.size() != 3) { fail("Should be 3 nodes: "+nodes.size()); } ServiceNode initialNode=null; java.util.Iterator<ServiceNode> iter=nodes.iterator(); while (iter.hasNext()) { ServiceNode sn=iter.next(); if (sn.getProperties().get(ServiceNode.INITIAL_NODE) == Boolean.TRUE) { if (initialNode != null) { fail("Should only be a single initial node"); } initialNode = sn; } } ServiceGraphLayout layout=LayoutFactory.getServiceGraphLayout(); layout.layout(graph); iter = nodes.iterator(); while (iter.hasNext()) { ServiceNode sn=iter.next(); if (sn.getProperties().size() == 1) { fail("Service node '"+sn+"' does not have layout properties"); } } } catch (Exception e) { e.printStackTrace(); fail("Failed to test multicast example: "+e); } }