001: package org.andromda.core.cartridge;
002:
003: import java.util.Collection;
004: import java.util.Iterator;
005: import java.util.Map;
006:
007: import junit.framework.TestCase;
008:
009: import org.andromda.core.cartridge.template.ModelElement;
010: import org.andromda.core.cartridge.template.Template;
011: import org.andromda.core.cartridge.template.Type;
012: import org.andromda.core.common.ComponentContainer;
013: import org.andromda.core.common.TemplateObject;
014: import org.andromda.core.namespace.NamespaceComponents;
015: import org.andromda.core.profile.Profile;
016:
017: /**
018: * Implements the JUnit test suit for
019: * {@link org.andromda.core.cartridge.Cartridge}
020: *
021: * @see org.andromda.core.cartridge.Cartridge
022: * @since 01.04.2003
023: * @author <a href="http://www.mbohlen.de">Matthias Bohlen </a>
024: * @author Chad Brandon
025: */
026: public class CartridgeTest extends TestCase {
027: private Cartridge cartridge;
028:
029: /**
030: * Constructor for AndroMDATestCartridgeTest.
031: *
032: * @param name
033: */
034: public CartridgeTest(String name) {
035: super (name);
036: }
037:
038: /**
039: * @see TestCase#setUp()
040: */
041: protected void setUp() throws Exception {
042: NamespaceComponents.instance().discover();
043: Collection cartridges = ComponentContainer.instance()
044: .findComponentsOfType(Cartridge.class);
045: assertNotNull(cartridges);
046: this .cartridge = (Cartridge) cartridges.iterator().next();
047: Profile.instance().setNamespace(this .cartridge.getNamespace());
048: this .cartridge.initialize();
049: }
050:
051: /**
052: * @see TestCase#tearDown()
053: */
054: protected void tearDown() throws Exception {
055: this .cartridge = null;
056: }
057:
058: public void testGetNamespace() {
059: assertEquals("test", this .cartridge.getNamespace());
060: }
061:
062: public void testGetResources() {
063: Collection resources = this .cartridge.getResources();
064: assertNotNull(resources);
065: assertEquals(3, resources.size());
066:
067: // first template
068: final Iterator templateIterator = resources.iterator();
069: Resource resource = (Resource) templateIterator.next();
070: assertTrue(resource.isLastModifiedCheck());
071:
072: Template template = (Template) templateIterator.next();
073: assertEquals("EntityBean.vsl", template.getPath());
074: assertEquals("{0}/{1}Bean.java", template.getOutputPattern());
075: assertEquals("beans", template.getOutlet());
076: assertTrue(template.isOverwrite());
077: assertNotNull(template.getSupportedModeElements());
078: assertEquals("entity", template.getSupportedModeElements()
079: .getVariable());
080: Collection modelElements = template.getSupportedModeElements()
081: .getModelElements();
082: assertNotNull(modelElements);
083: assertEquals(1, modelElements.size());
084: ModelElement element = (ModelElement) modelElements.iterator()
085: .next();
086: assertEquals("Entity", element.getStereotype());
087:
088: // second template
089: template = (Template) templateIterator.next();
090: assertEquals(
091: "templates/webservice/axis/server-config.wsdd.vsl",
092: template.getPath());
093: assertEquals("WEB-INF/server-config.wsdd", template
094: .getOutputPattern());
095: assertEquals("axis-configuration", template.getOutlet());
096: assertEquals("$viewType.equals('jsp')", template
097: .getOutputCondition());
098: assertTrue(template.isOverwrite());
099: assertTrue(template.isOutputToSingleFile());
100: assertFalse(template.isOutputOnEmptyElements());
101: assertNotNull(template.getSupportedModeElements());
102: assertEquals("services", template.getSupportedModeElements()
103: .getVariable());
104: modelElements = template.getSupportedModeElements()
105: .getModelElements();
106: assertNotNull(modelElements);
107: assertEquals(1, modelElements.size());
108: element = (ModelElement) modelElements.iterator().next();
109: assertNull(element.getVariable());
110: assertNull(element.getStereotype());
111:
112: final Collection types = element.getTypes();
113: assertNotNull(types);
114: assertEquals(1, types.size());
115: final Type type = (Type) types.iterator().next();
116: final Collection properties = type.getProperties();
117: assertEquals(2, properties.size());
118: final Iterator propertyIterator = properties.iterator();
119: Type.Property property1 = (Type.Property) propertyIterator
120: .next();
121: assertEquals("propertyOne", property1.getName());
122: assertEquals("", property1.getValue());
123: Type.Property property2 = (Type.Property) propertyIterator
124: .next();
125: assertEquals("propertyThree", property2.getName());
126: assertEquals("Contents", property2.getValue());
127:
128: final Map conditions = cartridge.getConditions();
129: assertEquals(1, conditions.size());
130: final String expressionName = (String) conditions.keySet()
131: .iterator().next();
132: assertEquals("viewTypeIsJsp", expressionName);
133: final String expressionValue = (String) conditions
134: .get(expressionName);
135: assertEquals("$viewType.equalsIgnoreCase('jsp')",
136: expressionValue);
137: }
138:
139: public void testGetPropertyReferences() {
140: String[] propertyRefs = this .cartridge.getPropertyReferences();
141: assertNotNull(propertyRefs);
142: assertEquals(2, propertyRefs.length);
143:
144: String propertyReferenceOne = "propertyReferenceOne";
145: String propertyReferenceTwo = "propertyReferenceTwo";
146:
147: assertEquals(propertyReferenceOne, propertyRefs[0]);
148: assertEquals(propertyReferenceTwo, propertyRefs[1]);
149: }
150:
151: public void testGetTemplateObjects() {
152: final Collection templateObjects = this .cartridge
153: .getTemplateObjects();
154: assertNotNull(templateObjects);
155: assertEquals(1, templateObjects.size());
156: TemplateObject templateObject = ((TemplateObject) templateObjects
157: .iterator().next());
158: assertEquals("utils", templateObject.getName());
159: assertEquals("test", templateObject.getNamespace());
160: CartridgeTemplateObject object = (CartridgeTemplateObject) templateObject
161: .getObject();
162: assertNotNull(object);
163: assertEquals("3", object.getDefinitionOne());
164:
165: }
166:
167: public void testGetContents() {
168: Collection contents = this .cartridge.getContents();
169: assertNotNull(contents);
170:
171: // make sure there's more than 0 contents listed
172: TestCase.assertNotSame(new Integer(0), new Integer(contents
173: .size()));
174: }
175: }
|