@Test public void testGetModelRoles() { String filename="monitor/models/PurchaseGoods.spr"; java.io.InputStream is= ClassLoader.getSystemResourceAsStream(filename); try { SimulationModel sm=new SimulationModel(filename, is); ProtocolRoleSimulator sim=new ProtocolRoleSimulator(); Object model=sim.getModel(sm, null); java.util.List<Role> roles=sim.getModelRoles(model); if (roles.size() != 4) { fail("Incorrect number of roles, expecting 4, but got: "+roles.size()); } Role r1=new Role(); r1.setName("Buyer"); Role r2=new Role(); r2.setName("CreditAgency"); Role r3=new Role(); r3.setName("Store"); Role r4=new Role(); r4.setName("Logistics"); if (roles.get(0).getName().equals(r1.getName()) == false) { fail("Role '"+r1.getName()+"' not found"); } if (roles.get(1).getName().equals(r2.getName()) == false) { fail("Role '"+r2.getName()+"' not found"); } if (roles.get(2).getName().equals(r3.getName()) == false) { fail("Role '"+r3.getName()+"' not found"); } if (roles.get(3).getName().equals(r4.getName()) == false) { fail("Role '"+r4.getName()+"' not found"); } } catch(Exception e) { e.printStackTrace(); fail("Failed to get model roles: "+e); } }
public List<Role> getModelRoles(Object model) { if (model instanceof ProtocolModel) { java.util.List<Role> ret=new java.util.Vector<Role>(); if (((ProtocolModel)model).isLocated()) { Role role=new Role(); role.setName(((ProtocolModel)model).getProtocol().getLocatedRole().getName()); ret.add(role); } else { for (org.scribble.protocol.model.Role r : ((ProtocolModel)model).getRoles()) { Role role=new Role(); role.setName(r.getName()); ret.add(role); } } return (ret); } return (Collections.emptyList()); }
ProtocolRoleSimulator implements RoleSimulator { public List<Role> getModelRoles(Object model) { if (model instanceof ProtocolModel) { java.util.List<Role> ret=new java.util.Vector<Role>(); if (((ProtocolModel)model).isLocated()) { Role role=new Role(); role.setName(((ProtocolModel)model).getProtocol().getLocatedRole().getName()); ret.add(role); } else { for (org.scribble.protocol.model.Role r : ((ProtocolModel)model).getRoles()) { Role role=new Role(); role.setName(r.getName()); ret.add(role); } } return (ret); } return (Collections.emptyList()); } }
ProtocolRoleSimulator implements RoleSimulator { public List<Role> getModelRoles(Object model) { if (model instanceof ProtocolModel) { java.util.List<Role> ret=new java.util.Vector<Role>(); if (((ProtocolModel)model).isLocated()) { Role role=new Role(); role.setName(((ProtocolModel)model).getProtocol().getLocatedRole().getName()); ret.add(role); } else { for (org.scribble.protocol.model.Role r : ((ProtocolModel)model).getRoles()) { Role role=new Role(); role.setName(r.getName()); ret.add(role); } } return (ret); } return (Collections.emptyList()); }  }
ProtocolRoleSimulator implements RoleSimulator { public List<Role> getModelRoles(Object model) { if (model instanceof ProtocolModel) { java.util.List<Role> ret=new java.util.Vector<Role>(); if (((ProtocolModel)model).isLocated()) { Role role=new Role(); role.setName(((ProtocolModel)model).getProtocol().getLocatedRole().getName()); ret.add(role); } else { for (org.scribble.protocol.model.Role r : ((ProtocolModel)model).getRoles()) { Role role=new Role(); role.setName(r.getName()); ret.add(role); } } return (ret); } return (Collections.emptyList()); }  String getName(); void initialize(SimulationContext context); boolean isSupported(SimulationModel model); Object getModel(SimulationModel model, final ResourceLocator locator); List<Role> getModelRoles(Object model); Object getModelForRole(Object model, Role role, final ResourceLocator locator); void onEvent(SimulationContext context, Event event,
							SimulationHandler handler); void close(SimulationContext context); }
ProtocolRoleSimulator implements RoleSimulator { public List<Role> getModelRoles(Object model) { if (model instanceof ProtocolModel) { java.util.List<Role> ret=new java.util.Vector<Role>(); if (((ProtocolModel)model).isLocated()) { Role role=new Role(); role.setName(((ProtocolModel)model).getProtocol().getLocatedRole().getName()); ret.add(role); } else { for (org.scribble.protocol.model.Role r : ((ProtocolModel)model).getRoles()) { Role role=new Role(); role.setName(r.getName()); ret.add(role); } } return (ret); } return (Collections.emptyList()); }  String getName(); void initialize(SimulationContext context); boolean isSupported(SimulationModel model); Object getModel(SimulationModel model, final ResourceLocator locator); List<Role> getModelRoles(Object model); Object getModelForRole(Object model, Role role, final ResourceLocator locator); void onEvent(SimulationContext context, Event event,
							SimulationHandler handler); void close(SimulationContext context); static final String PROTOCOL_SIMULATOR; }