コード例 #1
0
  @Test
  public void testSimSampleOnEventRequestOperationUnexpected() {
    SCARoleSimulator sim = new SCARoleSimulator();

    try {
      SimulationModel simmodel = new SimulationModel("simsample.composite", null);

      Object model = sim.getModel(simmodel);

      if (model == null) {
        fail("Model is null");
      }

      java.net.URL url = ClassLoader.getSystemResource("req.data");

      java.io.File f = new java.io.File(url.getFile());

      DefaultSimulationContext context = new DefaultSimulationContext(f);
      context.setModel(model);
      sim.initialize(context);

      TestSimulationHandler handler = new TestSimulationHandler();

      Parameter param = new Parameter();
      param.setValue("req.data");

      ReceiveEvent event1 = new ReceiveEvent();
      event1.setOperationName("callX");
      event1.getParameter().add(param);

      sim.onEvent(context, event1, handler);

      sim.close(context);

      if (handler.getErrorEvents().size() > 0) {
        fail("Should be no errors");
      }

      if (handler.getUnexpectedEvents().size() != 1) {
        fail("Should be 1 unexpected events");
      }

      if (handler.getNoSimulatorEvents().size() > 0) {
        fail("Should be no 'no simulator' events");
      }

      if (handler.getProcessedEvents().size() > 0) {
        fail("Should be 0 processed events");
      }

    } catch (Exception e) {
      fail("Exception occurred: " + e);
    }
  }
コード例 #2
0
  @Test
  public void testGetSupportedModel() {
    SCARoleSimulator sim = new SCARoleSimulator();

    try {
      SimulationModel simmodel = new SimulationModel("simsample.composite", null);

      Object model = sim.getModel(simmodel);

      if (model == null) {
        fail("Model is null");
      } else if ((model instanceof Node) == false) {
        fail("Model is not a Tuscany SCA node");
      }
    } catch (Exception e) {
      fail("Exception occurred: " + e);
    }
  }
コード例 #3
0
  @Test
  public void testGetModelRoles() {
    SCARoleSimulator sim = new SCARoleSimulator();

    try {
      SimulationModel simmodel = new SimulationModel("simsample.composite", null);

      Object model = sim.getModel(simmodel);

      if (model == null) {
        fail("Model is null");
      }

      java.util.List<Role> roles = sim.getModelRoles(model);

      if (roles.size() > 0) {
        fail("Should be no roles");
      }
    } catch (Exception e) {
      fail("Exception occurred: " + e);
    }
  }
コード例 #4
0
  @Test
  public void testStoreServiceOnEventAllProcessed() {
    SCARoleSimulator sim = new SCARoleSimulator();

    try {
      SimulationModel simmodel = new SimulationModel("store/Store.composite", null);

      Object model = sim.getModel(simmodel);

      if (model == null) {
        fail("Model is null");
      }

      java.net.URL url = ClassLoader.getSystemResource("store/BuyRequest.xml");

      java.io.File f = new java.io.File(url.getFile());

      DefaultSimulationContext context = new DefaultSimulationContext(f);
      context.setModel(model);
      sim.initialize(context);

      TestSimulationHandler handler = new TestSimulationHandler();

      Parameter param = new Parameter();
      param.setValue("BuyRequest.xml");

      ReceiveEvent event2 = new ReceiveEvent();
      event2.setOperationName("buy");
      event2.getParameter().add(param);

      sim.onEvent(context, event2, handler);

      Parameter resp = new Parameter();
      resp.setValue("BuyConfirmed.xml");

      SendEvent event3 = new SendEvent();
      event3.setOperationName("buy");
      event3.getParameter().add(resp);

      sim.onEvent(context, event3, handler);

      sim.close(context);

      if (handler.getErrorEvents().size() > 0) {
        fail("Should be no errors");
      }

      if (handler.getUnexpectedEvents().size() > 0) {
        fail("Should be no unexpected events");
      }

      if (handler.getNoSimulatorEvents().size() > 0) {
        fail("Should be no 'no simulator' events");
      }

      if (handler.getProcessedEvents().size() != 2) {
        fail("Should be 2 processed events");
      }

    } catch (Exception e) {
      e.printStackTrace();
      fail("Exception occurred: " + e);
    }
  }