01: package org.andromda.translation.ocl;
02:
03: import java.io.FileReader;
04: import java.io.PushbackReader;
05: import java.net.URL;
06:
07: import junit.framework.Test;
08: import junit.framework.TestCase;
09: import junit.framework.TestSuite;
10:
11: import org.andromda.core.common.AndroMDALogger;
12: import org.andromda.core.common.ClassUtils;
13: import org.andromda.core.common.ResourceUtils;
14: import org.andromda.translation.ocl.analysis.DepthFirstAdapter;
15: import org.andromda.translation.ocl.lexer.Lexer;
16: import org.andromda.translation.ocl.node.Start;
17: import org.andromda.translation.ocl.parser.OclParser;
18:
19: /**
20: * Implements the JUnit test suite for {@link org.andromda.translation.ocl.parser.OclParser}
21: *
22: * @author Chad Brandon
23: */
24: public class OclParserTest extends TestCase {
25:
26: private String PACKAGE_DIR = ClassUtils.getPackageName(
27: OclParserTest.class).replace('.', '/');
28:
29: /**
30: * Location of a file containing valid OCL syntax.
31: */
32: private String VALID_SYNTAX = PACKAGE_DIR + "/valid-syntax.ocl";
33:
34: /**
35: * Constructor for ModelFacadeTest.
36: *
37: * @param testName
38: */
39: public OclParserTest(String testName) {
40: super (testName);
41: }
42:
43: public void setUp() throws Exception {
44: super .setUp();
45: AndroMDALogger.initialize();
46: }
47:
48: /**
49: * Assembles test suite of all known tests
50: *
51: * @return non-null test suite
52: */
53: public static Test suite() {
54: TestSuite suite = new TestSuite();
55: suite.addTestSuite(OclParserTest.class);
56: return suite;
57: }
58:
59: public void testValidExpressions() {
60: try {
61: URL url = ResourceUtils.getResource(VALID_SYNTAX);
62: if (url == null) {
63: TestCase.fail("Could not load resource '"
64: + VALID_SYNTAX + "'");
65: }
66: DepthFirstAdapter adapter = new DepthFirstAdapter();
67: Lexer lexer = new Lexer(new PushbackReader(new FileReader(
68: url.getFile())));
69: OclParser parser = new OclParser(lexer);
70: Start startNode = parser.parse();
71: startNode.apply(adapter);
72: } catch (Throwable th) {
73: th.printStackTrace();
74: TestCase.fail(th.toString());
75: }
76: }
77:
78: /**
79: * Runs the test suite
80: */
81: public static void main(String[] args) {
82: junit.textui.TestRunner.run(suite());
83: }
84: }
|