params.put("baz", "baz value");
// create a new instance using the service
InstanceID instanceId = instanceService.newInstance(bpId, params);
Instance instance = instanceService.getInstanceByID(instanceId);
assertEquals("Instance id's are not equal", instanceId, instance.getInstanceID());
assertNotNull("Application parameter map is null", instance.getInstanceVariables());
assertEquals("There must be three parameters", 3, instance.getInstanceVariables().size());
assertNotNull(instance.getInstanceVariables().get("foo"));
assertEquals("foo value", instance.getInstanceVariables().get("foo").toString());
assertNotNull(instance.getInstanceVariables().get("bar"));
assertEquals("bar value", instance.getInstanceVariables().get("bar").toString());
assertNotNull(instance.getInstanceVariables().get("baz"));
assertEquals("baz value", instance.getInstanceVariables().get("baz").toString());
assertEquals("The graph must be named '"+ graphName +"'", graphName, instance.getGraphName());
assertEquals("Instance doesn't have a running status", Instance.STATUS_RUNNING, instance.getStatus());
// set a new name
instance.setGraphName("New_Graph_Name");
// create a new set of parameters and then set it
Map newParams = new HashMap();
newParams.put("aaa", "aaa value");
newParams.put("bbb", "bbb value");
newParams.put("ccc", "ccc value");
newParams.put("ddd", "ddd value");
instance.setInstanceVariables(newParams);
instance.setStatus(Instance.STATUS_COMPLETE);
// save it then retrieve the saved instance
instanceService.save(instance);
instance = instanceService.getInstanceByID(instanceId);
// it should still be the same instance, but with the modified values, as above
assertEquals("Instance id's are not equal", instanceId, instance.getInstanceID());
assertNotNull("Application parameter map is null", instance.getInstanceVariables());
assertEquals("There must be four parameters", 4, instance.getInstanceVariables().size());
assertNotNull(instance.getInstanceVariables().get("aaa"));
assertEquals("aaa value", instance.getInstanceVariables().get("aaa").toString());
assertNotNull(instance.getInstanceVariables().get("bbb"));
assertEquals("bbb value", instance.getInstanceVariables().get("bbb").toString());
assertNotNull(instance.getInstanceVariables().get("ccc"));
assertEquals("ccc value", instance.getInstanceVariables().get("ccc").toString());
assertNotNull(instance.getInstanceVariables().get("ddd"));
assertEquals("ddd value", instance.getInstanceVariables().get("ddd").toString());
assertEquals("The graph must be named 'New_Graph_Name'", "New_Graph_Name", instance.getGraphName());
assertEquals("Instance doesn't have a completed status", Instance.STATUS_COMPLETE, instance.getStatus());
}