1 package org.andromda.core.cartridge;
2
3 import java.util.Collection;
4 import java.util.Iterator;
5 import java.util.Map;
6 import junit.framework.TestCase;
7 import org.andromda.core.cartridge.template.ModelElement;
8 import org.andromda.core.cartridge.template.Template;
9 import org.andromda.core.cartridge.template.Type;
10 import org.andromda.core.cartridge.template.Type.Property;
11 import org.andromda.core.common.ComponentContainer;
12 import org.andromda.core.common.TemplateObject;
13 import org.andromda.core.namespace.NamespaceComponents;
14 import org.andromda.core.profile.Profile;
15
16
17
18
19
20
21
22
23
24
25 public class CartridgeTest
26 extends TestCase
27 {
28 private Cartridge cartridge;
29
30
31
32
33
34
35 public CartridgeTest(String name)
36 {
37 super(name);
38 }
39
40
41
42
43 protected void setUp()
44 throws Exception
45 {
46 NamespaceComponents.instance().discover();
47 Collection<Cartridge> cartridges = ComponentContainer.instance().findComponentsOfType(Cartridge.class);
48 assertNotNull(cartridges);
49 this.cartridge = cartridges.iterator().next();
50 Profile.instance().setNamespace(this.cartridge.getNamespace());
51 this.cartridge.initialize();
52 }
53
54
55
56
57 protected void tearDown()
58 throws Exception
59 {
60 this.cartridge = null;
61 }
62
63
64
65
66 public void testGetNamespace()
67 {
68 assertEquals(
69 "test",
70 this.cartridge.getNamespace());
71 }
72
73
74
75
76 public void testGetResources()
77 {
78 Collection<Resource> resources = this.cartridge.getResources();
79 assertNotNull(resources);
80 assertEquals(
81 3,
82 resources.size());
83
84
85 final Iterator<Resource> templateIterator = resources.iterator();
86 Resource resource = templateIterator.next();
87 assertTrue(resource.isLastModifiedCheck());
88
89 Template template = (Template)templateIterator.next();
90 assertEquals(
91 "EntityBean.vsl",
92 template.getPath());
93 assertEquals(
94 "{0}/{1}Bean.java",
95 template.getOutputPattern());
96 assertEquals(
97 "beans",
98 template.getOutlet());
99 assertTrue(template.isOverwrite());
100 assertNotNull(template.getSupportedModeElements());
101 assertEquals(
102 "entity",
103 template.getSupportedModeElements().getVariable());
104 Collection<ModelElement> modelElements = template.getSupportedModeElements().getModelElements();
105 assertNotNull(modelElements);
106 assertEquals(
107 1,
108 modelElements.size());
109 ModelElement element = modelElements.iterator().next();
110 assertEquals(
111 "Entity",
112 element.getStereotype());
113
114
115 template = (Template)templateIterator.next();
116 assertEquals(
117 "templates/webservice/axis/server-config.wsdd.vsl",
118 template.getPath());
119 assertEquals(
120 "WEB-INF/server-config.wsdd",
121 template.getOutputPattern());
122 assertEquals(
123 "axis-configuration",
124 template.getOutlet());
125 assertEquals("$viewType.equals('jsp')", template.getOutputCondition());
126 assertTrue(template.isOverwrite());
127 assertTrue(template.isOutputToSingleFile());
128 assertFalse(template.isOutputOnEmptyElements());
129 assertNotNull(template.getSupportedModeElements());
130 assertEquals(
131 "services",
132 template.getSupportedModeElements().getVariable());
133 modelElements = template.getSupportedModeElements().getModelElements();
134 assertNotNull(modelElements);
135 assertEquals(
136 1,
137 modelElements.size());
138 element = modelElements.iterator().next();
139 assertNull(element.getVariable());
140 assertNull(element.getStereotype());
141
142 final Collection<Type> types = element.getTypes();
143 assertNotNull(types);
144 assertEquals(1, types.size());
145 final Type type = types.iterator().next();
146 final Collection<Property> properties = type.getProperties();
147 assertEquals(2, properties.size());
148 final Iterator propertyIterator = properties.iterator();
149 Type.Property property1 = (Type.Property)propertyIterator.next();
150 assertEquals("propertyOne", property1.getName());
151 assertEquals("", property1.getValue());
152 Type.Property property2 = (Type.Property)propertyIterator.next();
153 assertEquals("propertyThree", property2.getName());
154 assertEquals("Contents", property2.getValue());
155
156 final Map<String, String> conditions = cartridge.getConditions();
157 assertEquals(1, conditions.size());
158 final String expressionName = conditions.keySet().iterator().next();
159 assertEquals("viewTypeIsJsp", expressionName);
160 final String expressionValue = conditions.get(expressionName);
161 assertEquals("$viewType.equalsIgnoreCase('jsp')", expressionValue);
162 }
163
164
165
166
167 public void testGetPropertyReferences()
168 {
169 String[] propertyRefs = this.cartridge.getPropertyReferences();
170 assertNotNull(propertyRefs);
171 assertEquals(
172 2,
173 propertyRefs.length);
174
175 String propertyReferenceOne = "propertyReferenceOne";
176 String propertyReferenceTwo = "propertyReferenceTwo";
177
178 assertEquals(propertyReferenceOne, propertyRefs[0]);
179 assertEquals(propertyReferenceTwo, propertyRefs[1]);
180 }
181
182
183
184
185 public void testGetTemplateObjects()
186 {
187 final Collection<TemplateObject> templateObjects = this.cartridge.getTemplateObjects();
188 assertNotNull(templateObjects);
189 assertEquals(
190 1,
191 templateObjects.size());
192 TemplateObject templateObject = templateObjects.iterator().next();
193 assertEquals("utils", templateObject.getName());
194 assertEquals("test",templateObject.getNamespace());
195 CartridgeTemplateObject object = (CartridgeTemplateObject)templateObject.getObject();
196 assertNotNull(object);
197 assertEquals("3", object.getDefinitionOne());
198
199 }
200
201
202
203
204 public void testGetContents()
205 {
206 Collection<String> contents = this.cartridge.getContents();
207 assertNotNull(contents);
208
209
210
211
212
213
214 }
215 }