예제 #1
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);
    }
  }
  @Test
  public void testTidyServiceDescriptions() {
    Object expression = null;

    try {
      java.io.InputStream is =
          Thread.currentThread().getContextClassLoader().getResourceAsStream(SCRIPT);

      if (is == null) {
        fail("Unable to locate '" + SCRIPT + "'");
      } else {
        byte[] b = new byte[is.available()];
        is.read(b);
        is.close();

        // Compile expression
        expression = MVEL.compileExpression(new String(b));
      }
    } catch (Exception e) {
      fail("Failed to test script: " + e);
    }

    java.util.Map<String, Object> vars = new java.util.HashMap<String, Object>();

    java.util.Map<String, Object> internalVariables = new java.util.HashMap<String, Object>();

    ActiveCollectionSource acs = new ActiveCollectionSource();

    acs.getProperties().put("maxSnapshots", 3);

    ActiveMap map = new ActiveMap("TestMap");

    acs.setActiveCollection(map);

    // Add some service definitions
    ServiceDefinition sd1 = new ServiceDefinition();
    sd1.setServiceType("sd1");
    acs.insert(sd1.getServiceType(), sd1);

    ServiceDefinition sd2 = new ServiceDefinition();
    sd2.setServiceType("sd2");
    acs.insert(sd2.getServiceType(), sd2);

    vars.put("acs", acs);
    vars.put("variables", internalVariables);

    MVEL.executeExpression(expression, vars);

    @SuppressWarnings("unchecked")
    java.util.List<Object> snapshots = (List<Object>) internalVariables.get("snapshots");

    if (snapshots == null) {
      fail("No snapshots recorded");
    }

    if (snapshots.size() != 1) {
      fail("Expecting 1 snapshot: " + snapshots.size());
    }

    MVEL.executeExpression(expression, vars);

    if (snapshots.size() != 2) {
      fail("Expecting 2 snapshot: " + snapshots.size());
    }

    MVEL.executeExpression(expression, vars);

    if (snapshots.size() != 3) {
      fail("Expecting 3 snapshot: " + snapshots.size());
    }

    // Need to check that only three snapshots (as defined
    // by the cleanup cycle) will be retained
    MVEL.executeExpression(expression, vars);

    if (snapshots.size() != 3) {
      fail("Expecting 3 snapshot: " + snapshots.size());
    }
  }