001: package org.concern.controller;
002:
003: import junit.framework.TestCase;
004:
005: import org.concern.model.AsynchronousActivity;
006: import org.concern.model.EnvironmentEntry;
007: import org.concern.model.Loader;
008: import org.concern.model.Process;
009: import org.concern.model.SynchronousActivity;
010:
011: import java.util.*;
012:
013: public class ConfigurationTest extends TestCase {
014: protected Process process;
015:
016: public ConfigurationTest(String name) {
017: super (name);
018: }
019:
020: protected void setUp() throws Exception {
021: org.concern.model.Loader loaderModel = new org.concern.model.Loader(
022: "Loader", DummyLoader.class.getName());
023: org.concern.model.Actor actorModel = new org.concern.model.Actor(
024: "Actor", DummyActor.class.getName());
025: org.concern.model.Condition conditionModel = new org.concern.model.Condition(
026: "Condition", DummyCondition.class.getName());
027: org.concern.model.Activity synchronousActivityModel = new SynchronousActivity(
028: "SynchronousActivity", DummySynchronousActivity.class
029: .getName());
030: org.concern.model.Activity asynchronousActivityModel = new AsynchronousActivity(
031: "AsynchronousActivity", DummyAsynchronousActivity.class
032: .getName());
033: org.concern.model.Event eventModel = new org.concern.model.Event(
034: "Event", DummyEvent.class.getName());
035: org.concern.model.Listener listenerModel = new org.concern.model.Listener(
036: "Listener", DummyListener.class.getName());
037:
038: loaderModel.getEnvironment().add(
039: new EnvironmentEntry("name", "java.lang.String",
040: "value"));
041: loaderModel.getEnvironment().add(
042: new EnvironmentEntry("dummy", "java.lang.Integer",
043: "resource:blubber"));
044: actorModel.getEnvironment().add(
045: new EnvironmentEntry("name", "java.lang.String",
046: "value"));
047: actorModel.getEnvironment()
048: .add(
049: new EnvironmentEntry("dummy",
050: "java.lang.Integer", "10"));
051: conditionModel.getEnvironment().add(
052: new EnvironmentEntry("name", "java.lang.String",
053: "value"));
054: conditionModel.getEnvironment()
055: .add(
056: new EnvironmentEntry("dummy",
057: "java.lang.Integer", "10"));
058: synchronousActivityModel.getEnvironment().add(
059: new EnvironmentEntry("name", "java.lang.String",
060: "value"));
061: synchronousActivityModel.getEnvironment()
062: .add(
063: new EnvironmentEntry("dummy",
064: "java.lang.Integer", "10"));
065: asynchronousActivityModel.getEnvironment().add(
066: new EnvironmentEntry("name", "java.lang.String",
067: "value"));
068: asynchronousActivityModel.getEnvironment()
069: .add(
070: new EnvironmentEntry("dummy",
071: "java.lang.Integer", "10"));
072: eventModel.getEnvironment().add(
073: new EnvironmentEntry("name", "java.lang.String",
074: "value"));
075: eventModel.getEnvironment()
076: .add(
077: new EnvironmentEntry("dummy",
078: "java.lang.Integer", "10"));
079: listenerModel.getEnvironment().add(
080: new EnvironmentEntry("name", "java.lang.String",
081: "value"));
082: listenerModel.getEnvironment()
083: .add(
084: new EnvironmentEntry("dummy",
085: "java.lang.Integer", "10"));
086:
087: process = new Process("ControllerManagerTest");
088: process.getEnvironment().add(
089: new EnvironmentEntry("name", "java.lang.String",
090: "value"));
091: process.setLoader(loaderModel);
092: process.addActor(actorModel);
093: process.addCondition(conditionModel);
094: process.addActivity(synchronousActivityModel);
095: process.addActivity(asynchronousActivityModel);
096: process.addEvent(eventModel);
097: process.addListener(listenerModel);
098: }
099:
100: protected void tearDown() throws Exception {
101: }
102:
103: public void testDeployment() throws Exception {
104: Configuration configuration = new Configuration();
105: configuration.setProcess(process);
106: configuration.setClassLoader(getClass().getClassLoader());
107: DefaultResourceLocator resourceLocator = new DefaultResourceLocator();
108: resourceLocator.setResources(Collections.singletonMap(
109: "blubber", new Integer(11)));
110: configuration.setResourceLocator(resourceLocator);
111: Controller controller = configuration.buildController();
112:
113: DummyLoader loader = (DummyLoader) controller.getLoader();
114: DummyActor actor = (DummyActor) controller.getActors().get(0);
115: DummyCondition condition = (DummyCondition) controller
116: .getConditions().get(0);
117: DummySynchronousActivity synchronousActivity = null;
118: DummyAsynchronousActivity asynchronousActivity = null;
119: for (Iterator iterator = controller.getActivities().iterator(); iterator
120: .hasNext();) {
121: Activity activity = (Activity) iterator.next();
122: if (activity instanceof DummySynchronousActivity)
123: synchronousActivity = (DummySynchronousActivity) activity;
124: if (activity instanceof DummyAsynchronousActivity)
125: asynchronousActivity = (DummyAsynchronousActivity) activity;
126: }
127: DummyEvent event = (DummyEvent) controller.getEvents()
128: .iterator().next();
129: DummyListener listener = (DummyListener) controller
130: .getListeners().iterator().next();
131:
132: assertEquals("Loader", loader.getName());
133: assertEquals("Actor", actor.getName());
134: assertEquals("Condition", condition.getName());
135: assertEquals("SynchronousActivity", synchronousActivity
136: .getName());
137: assertEquals("AsynchronousActivity", asynchronousActivity
138: .getName());
139: assertEquals("Event", event.getName());
140: assertEquals("Listener", listener.getName());
141:
142: assertEquals("value", controller.environment.get("name"));
143: assertEquals("value", loader.environment.get("name"));
144: assertEquals("value", actor.environment.get("name"));
145: assertEquals("value", condition.environment.get("name"));
146: assertEquals("value", synchronousActivity.environment
147: .get("name"));
148: assertEquals("value", asynchronousActivity.environment
149: .get("name"));
150: assertEquals("value", event.environment.get("name"));
151: assertEquals("value", listener.environment.get("name"));
152:
153: assertEquals(new Integer(11), loader.getDummy());
154: assertEquals(new Integer(10), actor.getDummy());
155: assertEquals(new Integer(10), condition.getDummy());
156: assertEquals(new Integer(10), synchronousActivity.getDummy());
157: assertEquals(new Integer(10), asynchronousActivity.getDummy());
158: assertEquals(new Integer(10), event.getDummy());
159: assertEquals(new Integer(10), listener.getDummy());
160: }
161: }
|