Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2007-05-01 15:49:13 -0400
committerpelder2007-05-01 15:49:13 -0400
commit18f216e3b3e1418b2bfd73d09e72ada567d852ef (patch)
tree13401385241bb67adc25055f1cdce3ce1d7da469 /tests/org.eclipse.jet.tests
parent87cd27e970a034a8234ba0e65739ac577bb709a4 (diff)
downloadorg.eclipse.jet-18f216e3b3e1418b2bfd73d09e72ada567d852ef.tar.gz
org.eclipse.jet-18f216e3b3e1418b2bfd73d09e72ada567d852ef.tar.xz
org.eclipse.jet-18f216e3b3e1418b2bfd73d09e72ada567d852ef.zip
[184846] The constructor URI(String) expects special characters to be encoded. Other URI constructors will encode as appropriate. Change to these constructors, and avoid other URI methods the use this constructor (resolve(String) and create(String)). Also, platform URL handlers don't correctly decode encoded URLs. Switch from URI.toURL() to new URL(String, int, String, String)
Diffstat (limited to 'tests/org.eclipse.jet.tests')
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/AllTests.java1
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/parser/resources/AllTests.java19
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/parser/resources/ResourceTemplateInputTest.java136
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/parser/resources/WorkspaceTemplateResolverBuilderTest.java114
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/parser/resources/WorkspaceTemplateResolverHelperFactoryTest.java126
5 files changed, 396 insertions, 0 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 fd2efbb..6445e93 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
@@ -18,6 +18,7 @@ public class AllTests {
suite.addTest(org.eclipse.jet.tests.taglib.java.AllTests.suite());
suite.addTest(org.eclipse.jet.tests.taglib.format.AllTests.suite());
suite.addTest(org.eclipse.jet.tests.runtime.AllTests.suite());
+ suite.addTest(org.eclipse.jet.tests.parser.resources.AllTests.suite());
//$JUnit-BEGIN$
//$JUnit-END$
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/parser/resources/AllTests.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/parser/resources/AllTests.java
new file mode 100644
index 0000000..515e2c8
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/parser/resources/AllTests.java
@@ -0,0 +1,19 @@
+package org.eclipse.jet.tests.parser.resources;
+
+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.parser.resources");
+ //$JUnit-BEGIN$
+ suite.addTest(ResourceTemplateInputTest.suite());
+ suite.addTest(WorkspaceTemplateResolverBuilderTest.suite());
+ suite.addTest(WorkspaceTemplateResolverHelperFactoryTest.suite());
+ //$JUnit-END$
+ return suite;
+ }
+
+}
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/parser/resources/ResourceTemplateInputTest.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/parser/resources/ResourceTemplateInputTest.java
new file mode 100644
index 0000000..6b84bd2
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/parser/resources/ResourceTemplateInputTest.java
@@ -0,0 +1,136 @@
+/**
+ *
+ */
+package org.eclipse.jet.tests.parser.resources;
+
+import java.io.Reader;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import junit.extensions.TestSetup;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IWorkspaceRunnable;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jet.JET2Platform;
+import org.eclipse.jet.core.parser.ITemplateInput;
+import org.eclipse.jet.core.parser.TemplateInputException;
+import org.eclipse.jet.internal.parser.resources.ResourceTemplateInput;
+
+/**
+ * @author pelder
+ *
+ */
+public class ResourceTemplateInputTest extends TestCase {
+
+ protected static IProject project;
+
+ public static Test suite() {
+ TestSetup setup = new TestSetup(new TestSuite(ResourceTemplateInputTest.class)) {
+ protected void setUp() throws Exception {
+ setUpAllTests();
+ }
+
+ protected void tearDown() throws Exception {
+ tearDownAllTests();
+ }
+ };
+
+ return setup;
+ }
+
+ protected static void setUpAllTests() {
+ String newProjectModel = "<newProjectModel>" +
+ "<project" +
+ " name=\"" + TEST_PROJECT_NAME + "\"" +
+ "/>" +
+ "</newProjectModel>";
+
+ IStatus status = JET2Platform.runTransformOnString("org.eclipse.jet.transforms.newproject", newProjectModel, new NullProgressMonitor());
+ assertTrue("setUpAllTests", status.isOK());
+ try {
+ ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
+
+ public void run(IProgressMonitor monitor) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }}, new NullProgressMonitor());
+ } catch (CoreException e) {
+ fail(e.getMessage());
+ }
+
+ project = ResourcesPlugin.getWorkspace().getRoot().getProject(TEST_PROJECT_NAME);
+ assertTrue("Test project exists", project.exists());
+
+ }
+
+ protected static void tearDownAllTests() {
+ // TODO Auto-generated method stub
+
+ }
+
+ protected ITemplateInput templateInput;
+ private static final String TEST_PROJECT_NAME = "org.eclipse.jet.tests.resources.ResourceTemplateInput Tests";
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ IFile templateFile = project.getFile("templates/main.jet");
+ templateInput = new ResourceTemplateInput(templateFile);
+ }
+ /**
+ * Test method for {@link org.eclipse.jet.internal.parser.resources.ResourceTemplateInput#ResourceTemplateInput(org.eclipse.core.resources.IFile)}.
+ */
+ public void testResourceTemplateInput() {
+
+ assertNotNull(templateInput);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.parser.resources.ResourceTemplateInput#getBaseLocation()}.
+ * @throws URISyntaxException
+ */
+ public void testGetBaseLocation() throws URISyntaxException {
+ URI baseLocation = templateInput.getBaseLocation();
+
+ assertEquals(new URI("platform", "/resource/" + TEST_PROJECT_NAME + "/", null), baseLocation);
+
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.parser.resources.ResourceTemplateInput#getReader()}.
+ * @throws TemplateInputException
+ */
+ public void testGetReader() throws TemplateInputException {
+ Reader reader = templateInput.getReader();
+ assertNotNull(reader);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.parser.resources.ResourceTemplateInput#getTemplatePath()}.
+ */
+ public void testGetTemplatePath() {
+ String templatePath = templateInput.getTemplatePath();
+
+ assertEquals("templates/main.jet", templatePath);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.parser.resources.ResourceTemplateInput#getEncoding()}.
+ * @throws TemplateInputException
+ * @throws CoreException
+ */
+ public void testGetEncoding() throws TemplateInputException, CoreException {
+ String encoding = templateInput.getEncoding();
+ assertEquals(project.getFile(templateInput.getTemplatePath()).getCharset(), encoding);
+ }
+
+}
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/parser/resources/WorkspaceTemplateResolverBuilderTest.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/parser/resources/WorkspaceTemplateResolverBuilderTest.java
new file mode 100644
index 0000000..ac609f1
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/parser/resources/WorkspaceTemplateResolverBuilderTest.java
@@ -0,0 +1,114 @@
+/**
+ *
+ */
+package org.eclipse.jet.tests.parser.resources;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import junit.extensions.TestSetup;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IWorkspaceRunnable;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jet.JET2Platform;
+import org.eclipse.jet.core.parser.ITemplateResolver;
+import org.eclipse.jet.internal.parser.resources.WorkspaceTemplateResolverBuilder;
+
+/**
+ * @author pelder
+ *
+ */
+public class WorkspaceTemplateResolverBuilderTest extends TestCase {
+
+ private static final String TEST_PROJECT_NAME = "org.eclipse.jet.tests.parser.Workspace Template Resover Builder Test";
+ protected static IProject project;
+
+ public static Test suite() {
+ TestSetup setup = new TestSetup(new TestSuite(WorkspaceTemplateResolverBuilderTest.class)) {
+ protected void setUp() throws Exception {
+ setUpAllTests();
+ }
+
+ protected void tearDown() throws Exception {
+ tearDownAllTests();
+ }
+ };
+
+ return setup;
+ }
+
+ protected static void tearDownAllTests() {
+ // TODO Auto-generated method stub
+
+ }
+
+ protected static void setUpAllTests() {
+ String newProjectModel = "<newProjectModel>" +
+ "<project" +
+ " name=\"" + TEST_PROJECT_NAME + "\"" +
+ "/>" +
+ "</newProjectModel>";
+
+ IStatus status = JET2Platform.runTransformOnString("org.eclipse.jet.transforms.newproject", newProjectModel, new NullProgressMonitor());
+ assertTrue("setUpAllTests", status.isOK());
+ try {
+ ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
+
+ public void run(IProgressMonitor monitor) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }}, new NullProgressMonitor());
+ } catch (CoreException e) {
+ fail(e.getMessage());
+ }
+
+ project = ResourcesPlugin.getWorkspace().getRoot().getProject(TEST_PROJECT_NAME);
+ assertTrue("Test project exists", project.exists());
+
+ }
+
+ private WorkspaceTemplateResolverBuilder builder;
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ builder = new WorkspaceTemplateResolverBuilder(project);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.parser.resources.WorkspaceTemplateResolverBuilder#WorkspaceTemplateResolverBuilder(org.eclipse.core.resources.IProject)}.
+ * @throws URISyntaxException
+ */
+ public void testWorkspaceTemplateResolverBuilder() throws URISyntaxException {
+ assertNotNull(builder);
+ ITemplateResolver templateResolver = builder.build();
+
+ URI[] baseLocations = templateResolver.getBaseLocations();
+ assertEquals(1, baseLocations.length);
+ assertEquals(new URI("platform", "/resource/" + TEST_PROJECT_NAME + "/", null), baseLocations[0]);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.parser.resources.WorkspaceTemplateResolverBuilder#addAltBaseLocations(java.net.URI[])}.
+ * @throws URISyntaxException
+ */
+ public void testAddAltBaseLocations() throws URISyntaxException {
+ builder.addAltBaseLocations(new URI[] {
+ new URI("file", "/c:/usr/altLocation/", null), });
+
+ ITemplateResolver templateResolver = builder.build();
+
+ URI[] baseLocations = templateResolver.getBaseLocations();
+ assertEquals(2, baseLocations.length);
+ assertEquals(new URI("file", "/c:/usr/altLocation/", null), baseLocations[1]);
+
+ }
+
+}
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/parser/resources/WorkspaceTemplateResolverHelperFactoryTest.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/parser/resources/WorkspaceTemplateResolverHelperFactoryTest.java
new file mode 100644
index 0000000..8ac4153
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/parser/resources/WorkspaceTemplateResolverHelperFactoryTest.java
@@ -0,0 +1,126 @@
+/**
+ *
+ */
+package org.eclipse.jet.tests.parser.resources;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import junit.extensions.TestSetup;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IWorkspaceRunnable;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jet.JET2Platform;
+import org.eclipse.jet.core.parser.ITemplateResolverHelper;
+import org.eclipse.jet.internal.parser.resources.WorkspaceTemplateResolverHelperFactory;
+
+/**
+ * @author pelder
+ *
+ */
+public class WorkspaceTemplateResolverHelperFactoryTest extends TestCase {
+
+ private static final String TEST_PROJECT_NAME = "org.eclipse.jet.tests.parser.Workspace Template Resover Helper Factory Test";
+ protected static IProject project;
+
+ public static Test suite() {
+ TestSetup setup = new TestSetup(new TestSuite(WorkspaceTemplateResolverHelperFactoryTest.class)) {
+ protected void setUp() throws Exception {
+ setUpAllTests();
+ }
+
+ protected void tearDown() throws Exception {
+ tearDownAllTests();
+ }
+ };
+
+ return setup;
+ }
+
+ protected static void tearDownAllTests() {
+ // TODO Auto-generated method stub
+
+ }
+
+ protected static void setUpAllTests() {
+ String newProjectModel = "<newProjectModel>" +
+ "<project" +
+ " name=\"" + TEST_PROJECT_NAME + "\"" +
+ "/>" +
+ "</newProjectModel>";
+
+ IStatus status = JET2Platform.runTransformOnString("org.eclipse.jet.transforms.newproject", newProjectModel, new NullProgressMonitor());
+ assertTrue("setUpAllTests", status.isOK());
+ try {
+ ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
+
+ public void run(IProgressMonitor monitor) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }}, new NullProgressMonitor());
+ } catch (CoreException e) {
+ fail(e.getMessage());
+ }
+
+ project = ResourcesPlugin.getWorkspace().getRoot().getProject(TEST_PROJECT_NAME);
+ assertTrue("Test project exists", project.exists());
+
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.parser.resources.WorkspaceTemplateResolverHelperFactory#getTemplateResolverHelper(java.net.URI)}.
+ * @throws URISyntaxException
+ */
+ public void testGetTemplateResolverHelper_project_platformURI() throws URISyntaxException {
+
+ URI baseLocation = new URI("platform", "/resource/" + project.getName() + "/", null);
+ ITemplateResolverHelper templateResolverHelper = WorkspaceTemplateResolverHelperFactory.getInstance().getTemplateResolverHelper(baseLocation);
+ String templatePath = "templates/main.jet";
+ assertTrue("template Exists", templateResolverHelper.inputExists(templatePath));
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.parser.resources.WorkspaceTemplateResolverHelperFactory#getTemplateResolverHelper(java.net.URI)}.
+ * @throws URISyntaxException
+ */
+ public void testGetTemplateResolverHelper_folder_platformURI() throws URISyntaxException {
+
+ URI baseLocation = new URI("platform", "/resource/" + project.getName() + "/templates/", null);
+ ITemplateResolverHelper templateResolverHelper = WorkspaceTemplateResolverHelperFactory.getInstance().getTemplateResolverHelper(baseLocation);
+ String templatePath = "main.jet";
+ assertTrue("template Exists", templateResolverHelper.inputExists(templatePath));
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.parser.resources.WorkspaceTemplateResolverHelperFactory#getTemplateResolverHelper(java.net.URI)}.
+ * @throws URISyntaxException
+ */
+ public void testGetTemplateResolverHelper_project_fileURI() throws URISyntaxException {
+
+ URI baseLocation = project.getLocationURI();
+ ITemplateResolverHelper templateResolverHelper = WorkspaceTemplateResolverHelperFactory.getInstance().getTemplateResolverHelper(baseLocation);
+ String templatePath = "templates/main.jet";
+ assertTrue("template Exists", templateResolverHelper.inputExists(templatePath));
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.parser.resources.WorkspaceTemplateResolverHelperFactory#getTemplateResolverHelper(java.net.URI)}.
+ * @throws URISyntaxException
+ */
+ public void testGetTemplateResolverHelper_folder_fileURI() throws URISyntaxException {
+
+ URI baseLocation = project.getFolder("templates").getLocationURI();
+ ITemplateResolverHelper templateResolverHelper = WorkspaceTemplateResolverHelperFactory.getInstance().getTemplateResolverHelper(baseLocation);
+ String templatePath = "main.jet";
+ assertTrue("template Exists", templateResolverHelper.inputExists(templatePath));
+ }
+
+}

Back to the top