summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2006-03-10 15:36:38 (EST)
committerpelder2006-03-10 15:36:38 (EST)
commitaf4ae64f0a132ba5240e97f3fba16545648e5dcb (patch)
treed51ffb866cc21411f175b316178c442898823f0e
parent141027d9b9750b3d423c8647db779e3f15815293 (diff)
downloadorg.eclipse.jet-af4ae64f0a132ba5240e97f3fba16545648e5dcb.zip
org.eclipse.jet-af4ae64f0a132ba5240e97f3fba16545648e5dcb.tar.gz
org.eclipse.jet-af4ae64f0a132ba5240e97f3fba16545648e5dcb.tar.bz2
[131381] Add JUnits for the java:importsLocation tag.
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/AllTests.java3
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/taglib/java/AllTests.java17
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/taglib/java/TestImportsLocationTag.java133
3 files changed, 152 insertions, 1 deletions
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/AllTests.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/AllTests.java
index 5ef908c..49684c7 100644
--- a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/AllTests.java
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/AllTests.java
@@ -9,10 +9,11 @@ public class AllTests {
TestSuite suite = new TestSuite("Test for org.eclipse.jet.tests");
suite.addTest(org.eclipse.jet.tests.compiler.AllTests.suite());
suite.addTest(org.eclipse.jet.tests.runtime.AllTests.suite());
- suite.addTest(org.eclipse.jet.tests.taglib.AllTests.suite());
suite.addTest(org.eclipse.jet.tests.xpath.AllTests.suite());
suite.addTest(org.eclipse.jet.tests.model.load.AllTests.suite());
+ suite.addTest(org.eclipse.jet.tests.taglib.AllTests.suite());
suite.addTest(org.eclipse.jet.tests.taglib.control.AllTests.suite());
+ suite.addTest(org.eclipse.jet.tests.taglib.java.AllTests.suite());
//$JUnit-BEGIN$
//$JUnit-END$
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/taglib/java/AllTests.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/taglib/java/AllTests.java
new file mode 100644
index 0000000..7cf8f7e
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/taglib/java/AllTests.java
@@ -0,0 +1,17 @@
+package org.eclipse.jet.tests.taglib.java;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class AllTests {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(
+ "Test for org.eclipse.jet.tests.taglib.java");
+ //$JUnit-BEGIN$
+ suite.addTestSuite(TestImportsLocationTag.class);
+ //$JUnit-END$
+ return suite;
+ }
+
+}
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/taglib/java/TestImportsLocationTag.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/taglib/java/TestImportsLocationTag.java
new file mode 100644
index 0000000..1253af2
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/taglib/java/TestImportsLocationTag.java
@@ -0,0 +1,133 @@
+package org.eclipse.jet.tests.taglib.java;
+
+import junit.framework.TestCase;
+
+import org.eclipse.emf.codegen.util.ImportManager;
+import org.eclipse.jet.BodyContentWriter;
+import org.eclipse.jet.JET2Context;
+import org.eclipse.jet.JET2Writer;
+import org.eclipse.jet.internal.taglib.java.ImportsLocationTag;
+import org.eclipse.jet.taglib.JET2TagException;
+import org.eclipse.jet.taglib.TagInfo;
+import org.eclipse.jet.taglib.java.JavaImportsUtil;
+import org.eclipse.jface.text.BadPositionCategoryException;
+import org.eclipse.jface.text.Position;
+
+public class TestImportsLocationTag extends TestCase {
+
+ /*
+ * Test method for 'org.eclipse.jet.internal.taglib.java.ImportsLocationTag.doAction(TagInfo, JET2Context, JET2Writer)'
+ */
+ public void testDoAction() throws JET2TagException, BadPositionCategoryException {
+ JET2Context context = new JET2Context(null);
+ JET2Writer writer = new BodyContentWriter();
+
+ TagInfo td = new TagInfo("java:importsLocation", 1, 1,
+ new String[] {"package"},
+ new String[] {"foo.bar.test"});
+
+ ImportsLocationTag tag = createImportsLocationTag(context, writer, td);
+
+ tag.doAction(td, context, writer);
+
+ verifyImportManagerInstalled(writer);
+ }
+
+ /**
+ * @param context
+ * @param writer
+ * @param td
+ * @return
+ */
+ private ImportsLocationTag createImportsLocationTag(JET2Context context, JET2Writer writer, TagInfo td) {
+ ImportsLocationTag tag = new ImportsLocationTag();
+
+ tag.setContext(context);
+ tag.setParent(null);
+ tag.setTagInfo(td);
+ tag.setOut(writer);
+ return tag;
+ }
+
+ /*
+ * Test method for 'org.eclipse.jet.internal.taglib.java.ImportsLocationTag.doAction(TagInfo, JET2Context, JET2Writer)'
+ */
+ public void testDoAction_multipleTimes() throws JET2TagException, BadPositionCategoryException {
+ JET2Context context = new JET2Context(null);
+ JET2Writer writer = new BodyContentWriter();
+
+ TagInfo td = new TagInfo("java:importsLocation", 1, 1,
+ new String[] {"package"},
+ new String[] {"foo.bar.test"});
+
+ TagInfo td2 = new TagInfo("java:importsLocation", 2, 1,
+ new String[] {"package"},
+ new String[] {"foo.bar.test2"});
+
+ ImportsLocationTag tag = createImportsLocationTag(context, writer, td);
+
+ ImportsLocationTag tag2 = createImportsLocationTag(context, writer, td2);
+
+ tag.doAction(td, context, writer);
+
+ try {
+ tag2.doAction(td2, context, writer);
+ fail("Second doAction on same file should have thrown JET2TagException");
+ } catch(JET2TagException e) {
+ // success
+ }
+
+ verifyImportManagerInstalled(writer);
+ }
+
+ /**
+ * @param writer
+ * @throws BadPositionCategoryException
+ */
+ private ImportManager verifyImportManagerInstalled(JET2Writer writer) throws BadPositionCategoryException {
+ final Position[] positions = writer.getDocument().getPositions(ImportsLocationTag.IMPORTS_POSITION_CATEGORY);
+ assertTrue("positions.length == 1", positions.length == 1);
+ assertTrue("positions[0] instanceof ImportsLocationTag.ImportsPosition", positions[0] instanceof ImportsLocationTag.ImportsPosition);
+
+ ImportManager mgr = ((ImportsLocationTag.ImportsPosition)positions[0]).getImportManager();
+
+ assertNotNull(mgr);
+ return mgr;
+ }
+
+ public void testJavaImportsUtil() throws JET2TagException, BadPositionCategoryException {
+ // setup an imports tag...
+ JET2Context context = new JET2Context(null);
+ JET2Writer writer = new BodyContentWriter();
+
+ TagInfo td = new TagInfo("java:importsLocation", 1, 1,
+ new String[] {"package"},
+ new String[] {"foo.bar.test"});
+
+ final ImportsLocationTag tag = createImportsLocationTag(context, writer, td);
+ tag.doAction(td, context, writer);
+ final ImportManager tagInstalledMananger = verifyImportManagerInstalled(writer);
+
+ // Test: get the installed imports tag the public way...
+ final ImportManager importManager = JavaImportsUtil.getImportManager(writer);
+
+ // Verify
+ assertEquals(tagInstalledMananger, importManager);
+
+
+ }
+
+ public void testJavaImportsUtil_NotInstalled() {
+ // setup empty writer...
+ JET2Writer writer = new BodyContentWriter();
+
+ // Test: get the installed imports tag the public way...
+ try {
+ JavaImportsUtil.getImportManager(writer);
+ fail("Expected thrown JET2TagException");
+ } catch(JET2TagException e) {
+ // success
+ }
+ }
+
+}