CQ-4081: Initial import
diff --git a/tests/org.eclipse.e4.core.deeplink.handler.test/.classpath b/tests/org.eclipse.e4.core.deeplink.handler.test/.classpath
new file mode 100644
index 0000000..8a8f166
--- /dev/null
+++ b/tests/org.eclipse.e4.core.deeplink.handler.test/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/tests/org.eclipse.e4.core.deeplink.handler.test/.project b/tests/org.eclipse.e4.core.deeplink.handler.test/.project
new file mode 100644
index 0000000..01de469
--- /dev/null
+++ b/tests/org.eclipse.e4.core.deeplink.handler.test/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.e4.core.deeplink.handler.test</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/tests/org.eclipse.e4.core.deeplink.handler.test/.settings/org.eclipse.jdt.core.prefs b/tests/org.eclipse.e4.core.deeplink.handler.test/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..5c8181c
--- /dev/null
+++ b/tests/org.eclipse.e4.core.deeplink.handler.test/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+#Wed Dec 23 16:10:44 GMT 2009
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/tests/org.eclipse.e4.core.deeplink.handler.test/META-INF/MANIFEST.MF b/tests/org.eclipse.e4.core.deeplink.handler.test/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..4e331a7
--- /dev/null
+++ b/tests/org.eclipse.e4.core.deeplink.handler.test/META-INF/MANIFEST.MF
@@ -0,0 +1,9 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Test Fragment
+Bundle-SymbolicName: org.eclipse.e4.core.deeplink.handler.test
+Bundle-Version: 4.6.0.qualifier
+Fragment-Host: org.eclipse.e4.core.deeplink.handler;bundle-version="1.0.0"
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Require-Bundle: org.junit,
+ org.easymock
diff --git a/tests/org.eclipse.e4.core.deeplink.handler.test/build.properties b/tests/org.eclipse.e4.core.deeplink.handler.test/build.properties
new file mode 100644
index 0000000..41eb6ad
--- /dev/null
+++ b/tests/org.eclipse.e4.core.deeplink.handler.test/build.properties
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
diff --git a/tests/org.eclipse.e4.core.deeplink.handler.test/src/org/eclipse/e4/core/deeplink/handler/DeepLinkHandlerIdentifierTest.java b/tests/org.eclipse.e4.core.deeplink.handler.test/src/org/eclipse/e4/core/deeplink/handler/DeepLinkHandlerIdentifierTest.java
new file mode 100644
index 0000000..07926e6
--- /dev/null
+++ b/tests/org.eclipse.e4.core.deeplink.handler.test/src/org/eclipse/e4/core/deeplink/handler/DeepLinkHandlerIdentifierTest.java
@@ -0,0 +1,84 @@
+/******************************************************************************
+ * Copyright (c) David Orme and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * David Orme - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.e4.core.deeplink.handler;
+
+import org.eclipse.e4.core.deeplink.api.URLPathInfoParser;
+
+import junit.framework.TestCase;
+
+public class DeepLinkHandlerIdentifierTest extends TestCase {
+
+ public void testDeepLinkHandlerIdentifier_nullInput_throwsRuntimeException() throws Exception {
+ try {
+ new URLPathInfoParser(null);
+ fail("Expected an IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // success
+ }
+ }
+
+ public void testDeepLinkHandlerIdentifier_nonNullInput_success() throws Exception {
+ try {
+ new URLPathInfoParser("/foo/bar");
+ // success
+ } catch (IllegalArgumentException e) {
+ fail("Did not expect an IllegalArgumentException");
+ }
+ }
+
+ public void testDeepLinkHandlerIdentifier_onlyForwardSlash_throwsRuntimeException() throws Exception {
+ try {
+ new URLPathInfoParser("/");
+ fail("Expected an IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // success
+ }
+ }
+
+ public void testDeepLinkHandlerIdentifier_fails_whenOnlyDeepLinkTypePresent() throws Exception {
+ final String DEEP_LINK_TYPE = "deepLinkType";
+ try {
+ new URLPathInfoParser("/" + DEEP_LINK_TYPE);
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ //success
+ }
+ }
+
+ public void testDeepLinkHandlerIdentifier_parses_whenDeepLinkTypeAndPartIDPresent() throws Exception {
+ final String DEEP_LINK_TYPE = "deepLinkType";
+ final String PART_ID = "partID";
+ URLPathInfoParser testee = new URLPathInfoParser("/" + DEEP_LINK_TYPE + "/" + PART_ID);
+ assertEquals(DEEP_LINK_TYPE, testee.handlerType);
+ assertEquals(PART_ID, testee.handlerId);
+ assertFalse(testee.action.hasValue());
+ }
+
+ public void testDeepLinkHandlerIdentifier_parses_whenDeepLinkTypeAndPartIDandHandlerPresent() throws Exception {
+ final String DEEP_LINK_TYPE = "deepLinkType";
+ final String PART_ID = "partID";
+ final String HANDLER = "handler";
+ URLPathInfoParser testee = new URLPathInfoParser("/" + DEEP_LINK_TYPE + "/" + PART_ID + "/" + HANDLER);
+ assertEquals(DEEP_LINK_TYPE, testee.handlerType);
+ assertEquals(PART_ID, testee.handlerId);
+ assertEquals(HANDLER, testee.action.get());
+ }
+
+ public void testDeepLinkHandlerIdentifier_parses_withInnumerableSlashes() throws Exception {
+ final String DEEP_LINK_TYPE = "deepLinkType";
+ final String PART_ID = "partID";
+ final String HANDLER = "handler";
+ URLPathInfoParser testee = new URLPathInfoParser("/" + DEEP_LINK_TYPE + "/" + PART_ID + "////////////////////////////////////////////////////////////////////////" + HANDLER);
+ assertEquals(DEEP_LINK_TYPE, testee.handlerType);
+ assertEquals(PART_ID, testee.handlerId);
+ assertEquals(HANDLER, testee.action.get());
+ }
+}
diff --git a/tests/org.eclipse.e4.core.deeplink.handler.test/src/org/eclipse/e4/core/deeplink/handler/DeepLinkTypeHandlerFactoryTest.java b/tests/org.eclipse.e4.core.deeplink.handler.test/src/org/eclipse/e4/core/deeplink/handler/DeepLinkTypeHandlerFactoryTest.java
new file mode 100644
index 0000000..b36278a
--- /dev/null
+++ b/tests/org.eclipse.e4.core.deeplink.handler.test/src/org/eclipse/e4/core/deeplink/handler/DeepLinkTypeHandlerFactoryTest.java
@@ -0,0 +1,90 @@
+/******************************************************************************
+ * Copyright (c) David Orme and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * David Orme - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.e4.core.deeplink.handler;
+
+import java.io.UnsupportedEncodingException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import junit.framework.TestCase;
+
+import org.easymock.EasyMock;
+//import org.easymock.classextension.EasyMock;
+import org.eclipse.e4.core.deeplink.api.AbstractDeepLinkTypeHandler;
+import org.eclipse.e4.core.deeplink.handler.DeepLinkTypeHandlerFactory;
+import org.eclipse.e4.core.functionalprog.optionmonad.Option;
+
+
+public class DeepLinkTypeHandlerFactoryTest extends TestCase {
+
+ private DeepLinkTypeHandlerFactory testee;
+ private Map<String, AbstractDeepLinkTypeHandler> typeHandlerMap;
+
+ public void setUp() {
+ typeHandlerMap = new HashMap<String, AbstractDeepLinkTypeHandler>();
+ testee = new DeepLinkTypeHandlerFactory(typeHandlerMap);
+ }
+
+ public void testNullInput_ExpectRuntimeException() throws Exception {
+ HttpServletRequest request = makeServletRequest(null);
+
+ try {
+ testee.createTypeHandler(request, null);
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ //success
+ }
+ }
+
+ public void testExtensionURL_ReturnsATypeHandler() throws Exception {
+ final String HANDLER_TYPE = "extensionType";
+
+ //dependencies
+ String urlPathInfo = "/" + HANDLER_TYPE + "/extensionId";
+ HttpServletRequest request = makeServletRequest(urlPathInfo);
+ HttpServletResponse response = makeServletResponse();
+
+ //expectations
+ DeepLinkTypeHandlerStub expectedTypeHandler = new DeepLinkTypeHandlerStub();
+ typeHandlerMap.put(HANDLER_TYPE, expectedTypeHandler);
+
+ Option<AbstractDeepLinkTypeHandler> result = testee.createTypeHandler(request, response);
+
+ assertTrue("Found expected type handler", result.get() == expectedTypeHandler);
+ }
+
+ public void testUnableToIdentifyTypeOfLink_returnsNone() throws Exception {
+ HttpServletRequest request = makeServletRequest("/noSuchThing/someId");
+ HttpServletResponse response = null;
+
+ Option<AbstractDeepLinkTypeHandler> result = testee.createTypeHandler(request, response);
+ assertTrue("Handler should have returned None", !result.hasValue());
+ }
+
+ private HttpServletResponse makeServletResponse() {
+ HttpServletResponse response = EasyMock.createNiceMock(HttpServletResponse.class);
+ response.setContentType("text/xml");
+ EasyMock.replay(response);
+ return response;
+ }
+
+ private HttpServletRequest makeServletRequest(String urlPathInfo)
+ throws UnsupportedEncodingException {
+ HttpServletRequest request = EasyMock.createNiceMock(HttpServletRequest.class);
+ request.setCharacterEncoding("UTF-8");
+ EasyMock.expect(request.getPathInfo()).andStubReturn(urlPathInfo);
+ EasyMock.replay(request);
+ return request;
+ }
+}
diff --git a/tests/org.eclipse.e4.core.deeplink.handler.test/src/org/eclipse/e4/core/deeplink/handler/DeepLinkTypeHandlerMapperTest.java b/tests/org.eclipse.e4.core.deeplink.handler.test/src/org/eclipse/e4/core/deeplink/handler/DeepLinkTypeHandlerMapperTest.java
new file mode 100644
index 0000000..dabe756
--- /dev/null
+++ b/tests/org.eclipse.e4.core.deeplink.handler.test/src/org/eclipse/e4/core/deeplink/handler/DeepLinkTypeHandlerMapperTest.java
@@ -0,0 +1,55 @@
+/******************************************************************************
+ * Copyright (c) David Orme and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * David Orme - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.e4.core.deeplink.handler;
+
+import junit.framework.TestCase;
+
+//import org.easymock.classextension.EasyMock;
+import org.easymock.EasyMock;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.e4.core.deeplink.api.Activator;
+import org.eclipse.e4.core.deeplink.handler.DeepLinkTypeHandlerMapper;
+
+
+public class DeepLinkTypeHandlerMapperTest extends TestCase {
+
+ private DeepLinkTypeHandlerMapper testee;
+ private IExtensionRegistry mockRegistry = EasyMock.createMock(IExtensionRegistry.class);;
+
+ public void setUp() {
+
+ }
+
+ // TODO: Should this fail-fast instead ???
+ public void testEmptyMapReturnedWhenNoExtensionsFound() {
+ EasyMock.expect(mockRegistry.getConfigurationElementsFor(Activator.PLUGIN_ID,
+ Activator.DEEP_LINK_EXT_PT_ID)).andReturn(new IConfigurationElement[]{});
+ EasyMock.replay(mockRegistry);
+
+ testee = new DeepLinkTypeHandlerMapper(mockRegistry);
+ assertEquals(0, testee.getMap().size());
+
+ EasyMock.verify(mockRegistry);
+ }
+
+ public void testRunTimeExceptionThrownWhenExtensionRegistryIsNull() {
+
+ try {
+ testee = new DeepLinkTypeHandlerMapper(null);
+ fail();
+ } catch (IllegalArgumentException e) {
+ //pass();
+ }
+
+ }
+
+}
diff --git a/tests/org.eclipse.e4.core.deeplink.handler.test/src/org/eclipse/e4/core/deeplink/handler/DeepLinkTypeHandlerStub.java b/tests/org.eclipse.e4.core.deeplink.handler.test/src/org/eclipse/e4/core/deeplink/handler/DeepLinkTypeHandlerStub.java
new file mode 100644
index 0000000..9e94d9c
--- /dev/null
+++ b/tests/org.eclipse.e4.core.deeplink.handler.test/src/org/eclipse/e4/core/deeplink/handler/DeepLinkTypeHandlerStub.java
@@ -0,0 +1,24 @@
+/******************************************************************************
+ * Copyright (c) David Orme and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * David Orme - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.e4.core.deeplink.handler;
+
+import java.io.IOException;
+
+import org.eclipse.e4.core.deeplink.api.AbstractDeepLinkTypeHandler;
+
+
+public class DeepLinkTypeHandlerStub extends AbstractDeepLinkTypeHandler {
+
+ @Override
+ public void processDeepLink() throws IOException {
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/tests/org.eclipse.e4.core.deeplink.handler.test/src/org/eclipse/e4/core/deeplink/handler/RequestHandlerTest.java b/tests/org.eclipse.e4.core.deeplink.handler.test/src/org/eclipse/e4/core/deeplink/handler/RequestHandlerTest.java
new file mode 100644
index 0000000..e062924
--- /dev/null
+++ b/tests/org.eclipse.e4.core.deeplink.handler.test/src/org/eclipse/e4/core/deeplink/handler/RequestHandlerTest.java
@@ -0,0 +1,54 @@
+/******************************************************************************
+ * Copyright (c) David Orme and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * David Orme - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.e4.core.deeplink.handler;
+
+import java.io.IOException;
+import java.util.HashMap;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import junit.framework.TestCase;
+
+import org.easymock.EasyMock;
+import org.eclipse.e4.core.deeplink.api.AbstractDeepLinkTypeHandler;
+import org.eclipse.e4.core.deeplink.handler.RequestHandler;
+
+public class RequestHandlerTest extends TestCase {
+
+ private RequestHandler testee;
+ private HttpServletRequest request;
+ private HttpServletResponse response;
+
+ public void setUp() throws Exception {
+ testee = new RequestHandler(new HashMap<String, AbstractDeepLinkTypeHandler>());
+
+ request = EasyMock.createMock(HttpServletRequest.class);
+ EasyMock.expect(request.getRemoteHost()).andReturn("thisIsNotLocalhost");
+ EasyMock.replay(request);
+
+ response = EasyMock.createMock(HttpServletResponse.class);
+ response.sendError(HttpServletResponse.SC_FORBIDDEN);
+ EasyMock.replay(response);
+ }
+
+ public void testRequestHandlerDoesNotProcessGetRequestsFromNonLocalMachines() throws ServletException, IOException {
+ testee.doGet(request, response);
+ EasyMock.verify(response);
+ }
+
+ public void testRequestHandlerDoesNotProcessPutRequestsFromNonLocalMachines() throws ServletException, IOException {
+ testee.doPost(request, response);
+ EasyMock.verify(response);
+ }
+
+}