@Test public void testLoadSimulationContexts() { ScenarioSimulatorMain simulator=new ScenarioSimulatorMain(); Simulation simulation=new Simulation(); RoleDetails details=new RoleDetails(); details.setScenarioRole(STORE_ROLE); details.setModel("models/PurchaseGoods.cdm"); simulation.getRoles().add(details); simulation.setScenario("scenarios/SuccessfulPurchase.scn"); Scenario scenario=simulator.loadScenario(simulation); java.util.Map<Role, RoleSimulator> rsims=new java.util.HashMap<Role, RoleSimulator>(); rsims.put(scenario.getRole().get(1), new TestRoleSimulator()); java.util.Map<Role, SimulationContext> contexts=null; SimulationHandler handler=new TestSimulationHandler(); try { contexts = simulator.loadSimulationContexts(scenario, simulation, rsims, handler); } catch(Exception e) { e.printStackTrace(); fail("Failed to load simulation contexts: "+e); } if (contexts == null) { fail("No simulation contexts"); } SimulationContext context=contexts.get(scenario.getRole().get(1)); if (context == null) { fail("No simulation context for '"+STORE_ROLE+"'"); } if (context.getModel() == null) { fail("Model should not be null"); } }
protected java.util.Map<Role, SimulationContext> loadSimulationContexts(Scenario scenario, Simulation simulation, java.util.Map<Role, RoleSimulator> roleSimulators, SimulationHandler handler) { java.util.Map<Role, SimulationContext> ret=new java.util.HashMap<Role, SimulationContext>(); for (Role role : scenario.getRole()) { for (RoleDetails details : simulation.getRoles()) { if (details.getScenarioRole().equals(role.getName())) { RoleSimulator rsim=roleSimulators.get(role); try { java.io.InputStream is=ClassLoader.getSystemResourceAsStream(details.getModel()); if (is == null) { java.io.File f=new java.io.File(details.getModel()); if (f.exists()) { is = new java.io.FileInputStream(f); } } if (is != null) { SimulationContext context=loadContext(simulation, role, details, rsim); if (context != null) { logger.fine("Adding context for role '"+role.getName()+"'"); ret.put(role, context); } else { handler.roleStart(role); handler.roleFailed(role, "Failed to load context for role '"+role.getName()+"'"); } is.close(); } else { handler.roleStart(role); handler.roleFailed(role, "Failed to find model '"+details.getModel()+"'"); } } catch(Throwable e) { handler.roleStart(role); logger.log(Level.SEVERE, "Failed to load simulation model '"+details.getModel()+"'", e); handler.roleFailed(role, "Failed to load simulation model '"+details.getModel()+"': "+e); } } } } return(ret); }
ScenarioSimulatorMain { protected java.util.Map<Role, SimulationContext> loadSimulationContexts(Scenario scenario, Simulation simulation, java.util.Map<Role, RoleSimulator> roleSimulators, SimulationHandler handler) { java.util.Map<Role, SimulationContext> ret=new java.util.HashMap<Role, SimulationContext>(); for (Role role : scenario.getRole()) { for (RoleDetails details : simulation.getRoles()) { if (details.getScenarioRole().equals(role.getName())) { RoleSimulator rsim=roleSimulators.get(role); try { java.io.InputStream is=ClassLoader.getSystemResourceAsStream(details.getModel()); if (is == null) { java.io.File f=new java.io.File(details.getModel()); if (f.exists()) { is = new java.io.FileInputStream(f); } } if (is != null) { SimulationContext context=loadContext(simulation, role, details, rsim); if (context != null) { logger.fine("Adding context for role '"+role.getName()+"'"); ret.put(role, context); } else { handler.roleStart(role); handler.roleFailed(role, "Failed to load context for role '"+role.getName()+"'"); } is.close(); } else { handler.roleStart(role); handler.roleFailed(role, "Failed to find model '"+details.getModel()+"'"); } } catch(Throwable e) { handler.roleStart(role); logger.log(Level.SEVERE, "Failed to load simulation model '"+details.getModel()+"'", e); handler.roleFailed(role, "Failed to load simulation model '"+details.getModel()+"': "+e); } } } } return(ret); } }
ScenarioSimulatorMain { protected java.util.Map<Role, SimulationContext> loadSimulationContexts(Scenario scenario, Simulation simulation, java.util.Map<Role, RoleSimulator> roleSimulators, SimulationHandler handler) { java.util.Map<Role, SimulationContext> ret=new java.util.HashMap<Role, SimulationContext>(); for (Role role : scenario.getRole()) { for (RoleDetails details : simulation.getRoles()) { if (details.getScenarioRole().equals(role.getName())) { RoleSimulator rsim=roleSimulators.get(role); try { java.io.InputStream is=ClassLoader.getSystemResourceAsStream(details.getModel()); if (is == null) { java.io.File f=new java.io.File(details.getModel()); if (f.exists()) { is = new java.io.FileInputStream(f); } } if (is != null) { SimulationContext context=loadContext(simulation, role, details, rsim); if (context != null) { logger.fine("Adding context for role '"+role.getName()+"'"); ret.put(role, context); } else { handler.roleStart(role); handler.roleFailed(role, "Failed to load context for role '"+role.getName()+"'"); } is.close(); } else { handler.roleStart(role); handler.roleFailed(role, "Failed to find model '"+details.getModel()+"'"); } } catch(Throwable e) { handler.roleStart(role); logger.log(Level.SEVERE, "Failed to load simulation model '"+details.getModel()+"'", e); handler.roleFailed(role, "Failed to load simulation model '"+details.getModel()+"': "+e); } } } } return(ret); }  }
ScenarioSimulatorMain { protected java.util.Map<Role, SimulationContext> loadSimulationContexts(Scenario scenario, Simulation simulation, java.util.Map<Role, RoleSimulator> roleSimulators, SimulationHandler handler) { java.util.Map<Role, SimulationContext> ret=new java.util.HashMap<Role, SimulationContext>(); for (Role role : scenario.getRole()) { for (RoleDetails details : simulation.getRoles()) { if (details.getScenarioRole().equals(role.getName())) { RoleSimulator rsim=roleSimulators.get(role); try { java.io.InputStream is=ClassLoader.getSystemResourceAsStream(details.getModel()); if (is == null) { java.io.File f=new java.io.File(details.getModel()); if (f.exists()) { is = new java.io.FileInputStream(f); } } if (is != null) { SimulationContext context=loadContext(simulation, role, details, rsim); if (context != null) { logger.fine("Adding context for role '"+role.getName()+"'"); ret.put(role, context); } else { handler.roleStart(role); handler.roleFailed(role, "Failed to load context for role '"+role.getName()+"'"); } is.close(); } else { handler.roleStart(role); handler.roleFailed(role, "Failed to find model '"+details.getModel()+"'"); } } catch(Throwable e) { handler.roleStart(role); logger.log(Level.SEVERE, "Failed to load simulation model '"+details.getModel()+"'", e); handler.roleFailed(role, "Failed to load simulation model '"+details.getModel()+"': "+e); } } } } return(ret); }  static void main(String[] args); int simulate(Simulation simulation); int simulate(Simulation simulation, SimulationHandler handler); }
ScenarioSimulatorMain { protected java.util.Map<Role, SimulationContext> loadSimulationContexts(Scenario scenario, Simulation simulation, java.util.Map<Role, RoleSimulator> roleSimulators, SimulationHandler handler) { java.util.Map<Role, SimulationContext> ret=new java.util.HashMap<Role, SimulationContext>(); for (Role role : scenario.getRole()) { for (RoleDetails details : simulation.getRoles()) { if (details.getScenarioRole().equals(role.getName())) { RoleSimulator rsim=roleSimulators.get(role); try { java.io.InputStream is=ClassLoader.getSystemResourceAsStream(details.getModel()); if (is == null) { java.io.File f=new java.io.File(details.getModel()); if (f.exists()) { is = new java.io.FileInputStream(f); } } if (is != null) { SimulationContext context=loadContext(simulation, role, details, rsim); if (context != null) { logger.fine("Adding context for role '"+role.getName()+"'"); ret.put(role, context); } else { handler.roleStart(role); handler.roleFailed(role, "Failed to load context for role '"+role.getName()+"'"); } is.close(); } else { handler.roleStart(role); handler.roleFailed(role, "Failed to find model '"+details.getModel()+"'"); } } catch(Throwable e) { handler.roleStart(role); logger.log(Level.SEVERE, "Failed to load simulation model '"+details.getModel()+"'", e); handler.roleFailed(role, "Failed to load simulation model '"+details.getModel()+"': "+e); } } } } return(ret); }  static void main(String[] args); int simulate(Simulation simulation); int simulate(Simulation simulation, SimulationHandler handler);  }