You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by mi...@apache.org on 2014/11/26 09:52:12 UTC

[1/2] olingo-odata2 git commit: [OLINGO-193] Added unit tests

Repository: olingo-odata2
Updated Branches:
  refs/heads/OLINGO-193_SpringSupport ee0798736 -> a339d2956


[OLINGO-193] Added unit tests

Signed-off-by: Michael Bolz <mi...@sap.com>


Project: http://git-wip-us.apache.org/repos/asf/olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata2/commit/fe1be5e9
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata2/tree/fe1be5e9
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata2/diff/fe1be5e9

Branch: refs/heads/OLINGO-193_SpringSupport
Commit: fe1be5e92ff3575b4192ae3b827cce1116ee3b71
Parents: ee07987
Author: Lior Okman <li...@sap.com>
Authored: Sun Nov 16 12:08:50 2014 +0200
Committer: Michael Bolz <mi...@sap.com>
Committed: Wed Nov 26 08:51:19 2014 +0100

----------------------------------------------------------------------
 odata2-spring/.springBeans                      | 26 ++++++++
 odata2-spring/pom.xml                           | 54 +++++++++++++--
 .../spring/OlingoServerDefinitionParser.java    | 33 ++++------
 .../src/main/resources/META-INF/spring.handlers |  2 +-
 .../src/main/resources/META-INF/spring.schemas  |  2 +-
 .../src/main/resources/schema/olingo.xsd        | 34 +++++-----
 .../spring/SpringNamespaceHandlerTest.java      | 69 ++++++++++++++++++++
 .../olingo/odata2/spring/TestFactory.java       | 39 +++++++++++
 .../resources/spring/applicationContext.xml     | 33 ++++++++++
 9 files changed, 246 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/fe1be5e9/odata2-spring/.springBeans
----------------------------------------------------------------------
diff --git a/odata2-spring/.springBeans b/odata2-spring/.springBeans
new file mode 100755
index 0000000..f95fac8
--- /dev/null
+++ b/odata2-spring/.springBeans
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor
+     	license agreements. See the NOTICE file distributed with this work for additional
+	information regarding copyright ownership. The ASF licenses this file to
+	you under the Apache License, Version 2.0 (the "License"); you may not use
+	this file except in compliance with the License. You may obtain a copy of
+	the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
+	by applicable law or agreed to in writing, software distributed under the
+	License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
+	OF ANY KIND, either express or implied. See the License for the specific
+	language governing permissions and limitations under the License. -->
+<beansProjectDescription>
+	<version>1</version>
+	<pluginVersion><![CDATA[3.6.2.201410090854-RELEASE]]></pluginVersion>
+	<configSuffixes>
+		<configSuffix><![CDATA[xml]]></configSuffix>
+	</configSuffixes>
+	<enableImports><![CDATA[false]]></enableImports>
+	<configs>
+		<config>src/test/resources/spring/applicationContext.xml</config>
+	</configs>
+	<autoconfigs>
+	</autoconfigs>
+	<configSets>
+	</configSets>
+</beansProjectDescription>

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/fe1be5e9/odata2-spring/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-spring/pom.xml b/odata2-spring/pom.xml
index bf8f6a8..5183719 100755
--- a/odata2-spring/pom.xml
+++ b/odata2-spring/pom.xml
@@ -1,11 +1,14 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file
-    distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under
-    the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may
-    obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to
-    in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
-    ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under
-    the License. -->
+<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor
+	license agreements. See the NOTICE file distributed with this work for additional
+	information regarding copyright ownership. The ASF licenses this file to
+	you under the Apache License, Version 2.0 (the "License"); you may not use
+	this file except in compliance with the License. You may obtain a copy of
+	the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
+	by applicable law or agreed to in writing, software distributed under the
+	License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
+	OF ANY KIND, either express or implied. See the License for the specific
+	language governing permissions and limitations under the License. -->
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 	<modelVersion>4.0.0</modelVersion>
@@ -43,5 +46,42 @@
 			<artifactId>cxf-rt-frontend-jaxrs</artifactId>
 			<version>${cxf.version}</version>
 		</dependency>
+
+		<!-- Test dependencies -->
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.springframework</groupId>
+			<artifactId>spring-context</artifactId>
+			<version>${spring.version}</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.springframework</groupId>
+			<artifactId>spring-web</artifactId>
+			<version>${spring.version}</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.springframework</groupId>
+			<artifactId>spring-test</artifactId>
+			<version>${spring.version}</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>javax.servlet</groupId>
+			<artifactId>servlet-api</artifactId>
+			<version>2.5</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>commons-logging</groupId>
+			<artifactId>commons-logging</artifactId>
+			<version>1.1.3</version>
+			<scope>test</scope>
+		</dependency>
 	</dependencies>
 </project>

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/fe1be5e9/odata2-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoServerDefinitionParser.java
----------------------------------------------------------------------
diff --git a/odata2-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoServerDefinitionParser.java b/odata2-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoServerDefinitionParser.java
index d4469a3..fdb6e18 100755
--- a/odata2-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoServerDefinitionParser.java
+++ b/odata2-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoServerDefinitionParser.java
@@ -47,7 +47,6 @@ public class OlingoServerDefinitionParser extends JAXRSServerFactoryBeanDefiniti
   @Override
   protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder bean) {
     super.doParse(element, parserContext, bean);
-    ManagedList<BeanDefinition> services = new ManagedList<BeanDefinition>(3);
 
     if (!parserContext.getRegistry().containsBeanDefinition("OlingoODataExceptionHandler")) {
       AbstractBeanDefinition definition =
@@ -65,28 +64,20 @@ public class OlingoServerDefinitionParser extends JAXRSServerFactoryBeanDefiniti
       registerBeanDefinition(holder, parserContext.getRegistry());
     }
 
-    if (!element.hasAttribute("factory")) {
-      if (!parserContext.getRegistry().containsBeanDefinition("OlingoODataRootLocator")) {
-        AbstractBeanDefinition definition =
-            BeanDefinitionBuilder.genericBeanDefinition(ODataRootLocator.class).getBeanDefinition();
-        definition.setScope(BeanDefinition.SCOPE_PROTOTYPE);
-        BeanDefinitionHolder holder = new BeanDefinitionHolder(definition, "OlingoODataRootLocator", new String[0]);
-        registerBeanDefinition(holder, parserContext.getRegistry());
-      }
-      services.add(parserContext.getRegistry().getBeanDefinition("OlingoODataRootLocator"));
-    } else {
-      BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(ODataRootLocator.class);
-      builder.setScope(BeanDefinition.SCOPE_PROTOTYPE);
-      builder.addPropertyReference("serviceFactory", element.getAttribute("factory"));
-      AbstractBeanDefinition definition = builder.getBeanDefinition();
-      BeanDefinitionHolder holder =
-          new BeanDefinitionHolder(definition, "OlingoODataRootLocator-" + element.getAttribute("factory"),
-              new String[0]);
-      registerBeanDefinition(holder, parserContext.getRegistry());
-      services.add(definition);
-
+    BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(ODataRootLocator.class);
+    builder.setScope(BeanDefinition.SCOPE_PROTOTYPE);
+    builder.addPropertyReference("serviceFactory", element.getAttribute("factory"));
+    if (element.hasAttribute("pathsplit")) {
+      builder.addPropertyValue("pathSplit", element.getAttribute("pathsplit"));
     }
+    AbstractBeanDefinition definition = builder.getBeanDefinition();
+    BeanDefinitionHolder holder =
+        new BeanDefinitionHolder(definition, "OlingoODataRootLocator-" + element.getAttribute("id") + "-" + element.getAttribute("factory"),
+            new String[0]);
+    registerBeanDefinition(holder, parserContext.getRegistry());
 
+    ManagedList<BeanDefinition> services = new ManagedList<BeanDefinition>(3);
+    services.add(definition);
     services.add(parserContext.getRegistry().getBeanDefinition("OlingoODataExceptionHandler"));
     services.add(parserContext.getRegistry().getBeanDefinition("OlingoODataProvider"));
     bean.addPropertyValue("serviceBeans", services);

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/fe1be5e9/odata2-spring/src/main/resources/META-INF/spring.handlers
----------------------------------------------------------------------
diff --git a/odata2-spring/src/main/resources/META-INF/spring.handlers b/odata2-spring/src/main/resources/META-INF/spring.handlers
index 4b9c4c5..dadb52f 100755
--- a/odata2-spring/src/main/resources/META-INF/spring.handlers
+++ b/odata2-spring/src/main/resources/META-INF/spring.handlers
@@ -5,4 +5,4 @@
     in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
     ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under
     the License. -->
-http\://www.apache.org/olingo/odata2/spring/namespace=org.apache.olingo.odata2.spring.OlingoNamespaceHandler
+http\://www.apache.org/olingo/odata2/spring/odata=org.apache.olingo.odata2.spring.OlingoNamespaceHandler

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/fe1be5e9/odata2-spring/src/main/resources/META-INF/spring.schemas
----------------------------------------------------------------------
diff --git a/odata2-spring/src/main/resources/META-INF/spring.schemas b/odata2-spring/src/main/resources/META-INF/spring.schemas
index f9ff528..1a2a280 100755
--- a/odata2-spring/src/main/resources/META-INF/spring.schemas
+++ b/odata2-spring/src/main/resources/META-INF/spring.schemas
@@ -5,4 +5,4 @@
     in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
     ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under
     the License. -->
-http\://www.apache.org/olingo/odata2/spring/namespace.xsd=schema/olingo.xsd
+http\://www.apache.org/olingo/odata2/spring/odata.xsd=schema/olingo.xsd

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/fe1be5e9/odata2-spring/src/main/resources/schema/olingo.xsd
----------------------------------------------------------------------
diff --git a/odata2-spring/src/main/resources/schema/olingo.xsd b/odata2-spring/src/main/resources/schema/olingo.xsd
index 6818687..39424dd 100755
--- a/odata2-spring/src/main/resources/schema/olingo.xsd
+++ b/odata2-spring/src/main/resources/schema/olingo.xsd
@@ -1,28 +1,30 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file
-    distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under
-    the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may
-    obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to
-    in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
-    ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under
-    the License. -->
-<xsd:schema xmlns="http://www.apache.org/olingo/odata2/spring/namespace"
-	xmlns:xsd="http://www.w3.org/2001/XMLSchema"
-	xmlns:beans="http://www.springframework.org/schema/beans"
-	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-	xmlns:jaxrs="http://cxf.apache.org/jaxrs"
-	targetNamespace="http://www.apache.org/olingo/odata2/spring/namespace"
+<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor
+	license agreements. See the NOTICE file distributed with this work for additional
+	information regarding copyright ownership. The ASF licenses this file to
+	you under the Apache License, Version 2.0 (the "License"); you may not use
+	this file except in compliance with the License. You may obtain a copy of
+	the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
+	by applicable law or agreed to in writing, software distributed under the
+	License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
+	OF ANY KIND, either express or implied. See the License for the specific
+	language governing permissions and limitations under the License. -->
+<xsd:schema xmlns="http://www.apache.org/olingo/odata2/spring/odata"
+	xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:beans="http://www.springframework.org/schema/beans"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxrs="http://cxf.apache.org/jaxrs"
+	targetNamespace="http://www.apache.org/olingo/odata2/spring/odata"
 	elementFormDefault="unqualified">
 
 	<xsd:import namespace="http://www.springframework.org/schema/beans"
-				schemaLocation="http://www.springframework.org/schema/beans/spring-beans.xsd"/>
+		schemaLocation="http://www.springframework.org/schema/beans/spring-beans.xsd" />
 
 	<xsd:element name="server">
 		<xsd:complexType>
 			<xsd:complexContent>
 				<xsd:extension base="beans:identifiedType">
-					<xsd:attribute name="address" type="xsd:string" use="required"/>
-					<xsd:attribute name="factory" type="xsd:string" use="optional"/>
+					<xsd:attribute name="address" type="xsd:string" use="required" />
+					<xsd:attribute name="factory" type="xsd:string" use="required" />
+					<xsd:attribute name="pathsplit" type="xsd:int" use="optional" />
 				</xsd:extension>
 			</xsd:complexContent>
 		</xsd:complexType>

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/fe1be5e9/odata2-spring/src/test/java/org/apache/olingo/odata2/spring/SpringNamespaceHandlerTest.java
----------------------------------------------------------------------
diff --git a/odata2-spring/src/test/java/org/apache/olingo/odata2/spring/SpringNamespaceHandlerTest.java b/odata2-spring/src/test/java/org/apache/olingo/odata2/spring/SpringNamespaceHandlerTest.java
new file mode 100755
index 0000000..81a2372
--- /dev/null
+++ b/odata2-spring/src/test/java/org/apache/olingo/odata2/spring/SpringNamespaceHandlerTest.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ******************************************************************************/
+package org.apache.olingo.odata2.spring;
+
+import static org.junit.Assert.*;
+
+import org.apache.cxf.jaxrs.spring.JAXRSServerFactoryBeanDefinitionParser.SpringJAXRSServerFactoryBean;
+import org.apache.olingo.odata2.core.rest.ODataExceptionMapperImpl;
+import org.apache.olingo.odata2.core.rest.app.ODataApplication;
+import org.apache.olingo.odata2.core.rest.spring.ODataRootLocator;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.web.WebAppConfiguration;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration("classpath:spring/applicationContext.xml")
+@WebAppConfiguration
+public class SpringNamespaceHandlerTest {
+
+  @Autowired
+  private ApplicationContext appCtx;
+
+  @Test
+  public void testSuccessfullyCreated() {
+    assertTrue(appCtx.containsBean("testServer"));
+
+    assertTrue(appCtx.containsBean("OlingoODataExceptionHandler"));
+    assertTrue(appCtx.containsBean("OlingoODataProvider"));
+
+    assertEquals(ODataExceptionMapperImpl.class, appCtx.getType("OlingoODataExceptionHandler"));
+    assertEquals(ODataApplication.MyProvider.class, appCtx.getType("OlingoODataProvider"));
+
+    String rootLocatorName = "OlingoODataRootLocator-testServer-serviceFactory";
+    assertTrue(appCtx.containsBean(rootLocatorName));
+    assertEquals(ODataRootLocator.class, appCtx.getType(rootLocatorName));
+
+    SpringJAXRSServerFactoryBean server = appCtx.getBean("testServer", SpringJAXRSServerFactoryBean.class);
+    assertEquals("/service.svc", server.getAddress());
+  }
+
+  @Test
+  public void testCorrectFactoryAndPathSplit() {
+    String rootLocatorName = "OlingoODataRootLocator-testServer-serviceFactory";
+    ODataRootLocator rootLocator = appCtx.getBean(rootLocatorName, ODataRootLocator.class);
+    assertNotNull(rootLocator.getServiceFactory());
+    assertSame(appCtx.getBean("serviceFactory"), rootLocator.getServiceFactory());
+    assertEquals(3, rootLocator.getPathSplit());
+  }
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/fe1be5e9/odata2-spring/src/test/java/org/apache/olingo/odata2/spring/TestFactory.java
----------------------------------------------------------------------
diff --git a/odata2-spring/src/test/java/org/apache/olingo/odata2/spring/TestFactory.java b/odata2-spring/src/test/java/org/apache/olingo/odata2/spring/TestFactory.java
new file mode 100755
index 0000000..746a03b
--- /dev/null
+++ b/odata2-spring/src/test/java/org/apache/olingo/odata2/spring/TestFactory.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ******************************************************************************/
+package org.apache.olingo.odata2.spring;
+
+import org.apache.olingo.odata2.api.ODataService;
+import org.apache.olingo.odata2.api.ODataServiceFactory;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.processor.ODataContext;
+
+/**
+ * Empty service factory, to be used for testing that the namespace handler and server definition
+ * parser work correctly.
+ *
+ * @author Lior Okman <li...@sap.com>
+ */
+public class TestFactory extends ODataServiceFactory {
+
+  @Override
+  public ODataService createService(ODataContext ctx) throws ODataException {
+    return null;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/fe1be5e9/odata2-spring/src/test/resources/spring/applicationContext.xml
----------------------------------------------------------------------
diff --git a/odata2-spring/src/test/resources/spring/applicationContext.xml b/odata2-spring/src/test/resources/spring/applicationContext.xml
new file mode 100755
index 0000000..567c8da
--- /dev/null
+++ b/odata2-spring/src/test/resources/spring/applicationContext.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor
+	license agreements. See the NOTICE file distributed with this work for additional
+	information regarding copyright ownership. The ASF licenses this file to
+	you under the Apache License, Version 2.0 (the "License"); you may not use
+	this file except in compliance with the License. You may obtain a copy of
+	the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
+	by applicable law or agreed to in writing, software distributed under the
+	License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
+	OF ANY KIND, either express or implied. See the License for the specific
+	language governing permissions and limitations under the License. -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xmlns:odata="http://www.apache.org/olingo/odata2/spring/odata"
+	xmlns:context="http://www.springframework.org/schema/context"
+	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+		http://www.apache.org/olingo/odata2/spring/odata http://www.apache.org/olingo/odata2/spring/odata.xsd
+		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
+
+	<!-- Make @Autowire work -->
+	<context:annotation-config />
+
+	<!-- Register the test factory -->
+	<bean id="serviceFactory" class="org.apache.olingo.odata2.spring.TestFactory" />
+
+	<!-- This is what is actually being tested -->
+	<odata:server id="testServer" address="/service.svc" factory="serviceFactory" pathsplit="3"/>
+
+	<!-- In order to be useful in a real environment, Apache CXF needs to be configured correctly as well.
+	     This context file doesn't handle this, since the unit test only tests that the namespace handler
+	     works
+	-->
+</beans>


[2/2] olingo-odata2 git commit: [OLINGO-193] Reuse as much code as possible between the spring and non-spring root locators.

Posted by mi...@apache.org.
[OLINGO-193] Reuse as much code as possible between the spring and non-spring root locators.


Project: http://git-wip-us.apache.org/repos/asf/olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata2/commit/a339d295
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata2/tree/a339d295
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata2/diff/a339d295

Branch: refs/heads/OLINGO-193_SpringSupport
Commit: a339d2956d7dd892acd2f67893c1a608e796ad0e
Parents: fe1be5e
Author: Michael Bolz <mi...@sap.com>
Authored: Wed Nov 26 09:08:21 2014 +0100
Committer: Michael Bolz <mi...@sap.com>
Committed: Wed Nov 26 09:19:59 2014 +0100

----------------------------------------------------------------------
 .../odata2/core/rest/ODataRootLocator.java      | 92 +++++---------------
 .../core/rest/spring/ODataRootLocator.java      | 19 ++--
 .../spring/OlingoServerDefinitionParser.java    |  5 +-
 3 files changed, 30 insertions(+), 86 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/a339d295/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/rest/ODataRootLocator.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/rest/ODataRootLocator.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/rest/ODataRootLocator.java
index d9a91cc..64f9d4f 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/rest/ODataRootLocator.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/rest/ODataRootLocator.java
@@ -18,24 +18,13 @@
  ******************************************************************************/
 package org.apache.olingo.odata2.core.rest;
 
-import java.util.List;
-
 import javax.servlet.ServletConfig;
 import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.Encoded;
-import javax.ws.rs.HeaderParam;
 import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
 import javax.ws.rs.core.Application;
 import javax.ws.rs.core.Context;
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.PathSegment;
-import javax.ws.rs.core.Request;
-import javax.ws.rs.core.UriInfo;
 
 import org.apache.olingo.odata2.api.ODataServiceFactory;
-import org.apache.olingo.odata2.api.exception.ODataBadRequestException;
-import org.apache.olingo.odata2.api.exception.ODataException;
 import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
 import org.apache.olingo.odata2.core.rest.app.AbstractODataApplication;
 
@@ -52,74 +41,37 @@ import org.apache.olingo.odata2.core.rest.app.AbstractODataApplication;
  * 
  */
 @Path("/")
-public class ODataRootLocator {
+public class ODataRootLocator extends
+    org.apache.olingo.odata2.core.rest.spring.ODataRootLocator {
 
   @Context
-  private HttpHeaders httpHeaders;
-  @Context
-  private UriInfo uriInfo;
-  @Context
-  private Request request;
-  @Context
   private ServletConfig servletConfig;
-  @Context
-  private HttpServletRequest servletRequest;
-
-  @Context
-  private Application app;
-
-  /**
-   * Default root behavior which will delegate all paths to a ODataLocator.
-   * @param pathSegments URI path segments - all segments have to be OData
-   * @param xHttpMethod HTTP Header X-HTTP-Method for tunneling through POST
-   * @param xHttpMethodOverride HTTP Header X-HTTP-Method-Override for tunneling through POST
-   * @return a locator handling OData protocol
-   * @throws ODataException
-   * @throws ClassNotFoundException
-   * @throws IllegalAccessException
-   * @throws InstantiationException
-   */
-  @Path("/{pathSegments: .*}")
-  public Object handleRequest(
-      @Encoded @PathParam("pathSegments") final List<PathSegment> pathSegments,
-      @HeaderParam("X-HTTP-Method") final String xHttpMethod,
-      @HeaderParam("X-HTTP-Method-Override") final String xHttpMethodOverride)
-      throws ODataException, ClassNotFoundException, InstantiationException, IllegalAccessException {
-
-    if (xHttpMethod != null && xHttpMethodOverride != null) {
-
-      /*
-       * X-HTTP-Method-Override : implemented by CXF
-       * X-HTTP-Method : implemented in ODataSubLocator:handlePost
-       */
 
-      if (!xHttpMethod.equalsIgnoreCase(xHttpMethodOverride)) {
-        throw new ODataBadRequestException(ODataBadRequestException.AMBIGUOUS_XMETHOD);
-      }
-    }
-
-    if (servletRequest.getPathInfo() == null) {
-      return handleRedirect();
-    }
+  @Override
+  public ODataServiceFactory getServiceFactory() {
+    return createServiceFactoryFromContext(app, servletRequest,
+        servletConfig);
+  }
 
-    ODataServiceFactory serviceFactory = createServiceFactoryFromContext(app, servletRequest, servletConfig);
+  @Override
+  public void setServiceFactory(ODataServiceFactory serviceFactory) {
+    // Don't do anything
+  }
 
+  @Override
+  public int getPathSplit() {
     int pathSplit = 0;
-    final String pathSplitAsString = servletConfig.getInitParameter(ODataServiceFactory.PATH_SPLIT_LABEL);
+    final String pathSplitAsString = servletConfig
+        .getInitParameter(ODataServiceFactory.PATH_SPLIT_LABEL);
     if (pathSplitAsString != null) {
       pathSplit = Integer.parseInt(pathSplitAsString);
     }
+    return pathSplit;
+  }
 
-    final SubLocatorParameter param = new SubLocatorParameter();
-    param.setServiceFactory(serviceFactory);
-    param.setPathSegments(pathSegments);
-    param.setHttpHeaders(httpHeaders);
-    param.setUriInfo(uriInfo);
-    param.setRequest(request);
-    param.setServletRequest(servletRequest);
-    param.setPathSplit(pathSplit);
-
-    return ODataSubLocator.create(param);
+  @Override
+  public void setPathSplit(int pathSplit) {
+    // Don't do anything
   }
 
   public static ODataServiceFactory createServiceFactoryFromContext(final Application app,
@@ -148,8 +100,4 @@ public class ODataRootLocator {
       throw new ODataRuntimeException("Exception during ODataServiceFactory creation occured.", e);
     }
   }
-
-  private Object handleRedirect() {
-    return new ODataRedirectLocator();
-  }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/a339d295/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/rest/spring/ODataRootLocator.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/rest/spring/ODataRootLocator.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/rest/spring/ODataRootLocator.java
old mode 100755
new mode 100644
index 295dc9d..ea143e7
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/rest/spring/ODataRootLocator.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/rest/spring/ODataRootLocator.java
@@ -20,7 +20,6 @@ package org.apache.olingo.odata2.core.rest.spring;
 
 import java.util.List;
 
-import javax.servlet.ServletConfig;
 import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.Encoded;
 import javax.ws.rs.HeaderParam;
@@ -62,12 +61,10 @@ public class ODataRootLocator {
   @Context
   private Request request;
   @Context
-  private ServletConfig servletConfig;
-  @Context
-  private HttpServletRequest servletRequest;
+  protected HttpServletRequest servletRequest;
 
   @Context
-  private Application app;
+  protected Application app;
 
   // These next two members are exposed so that they can be injected with Spring
   private ODataServiceFactory serviceFactory;
@@ -108,13 +105,13 @@ public class ODataRootLocator {
     }
 
     final SubLocatorParameter param = new SubLocatorParameter();
-    param.setServiceFactory(serviceFactory);
+    param.setServiceFactory(getServiceFactory());
     param.setPathSegments(pathSegments);
     param.setHttpHeaders(httpHeaders);
     param.setUriInfo(uriInfo);
     param.setRequest(request);
     param.setServletRequest(servletRequest);
-    param.setPathSplit(pathSplit);
+    param.setPathSplit(getPathSplit());
 
     return ODataSubLocator.create(param);
   }
@@ -124,18 +121,18 @@ public class ODataRootLocator {
   }
 
   public ODataServiceFactory getServiceFactory() {
-	return serviceFactory;
+    return serviceFactory;
   }
 
   public void setServiceFactory(ODataServiceFactory serviceFactory) {
-	this.serviceFactory = serviceFactory;
+    this.serviceFactory = serviceFactory;
   }
 
   public int getPathSplit() {
-	return pathSplit;
+    return pathSplit;
   }
 
   public void setPathSplit(int pathSplit) {
-	this.pathSplit = pathSplit;
+    this.pathSplit = pathSplit;
   }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/a339d295/odata2-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoServerDefinitionParser.java
----------------------------------------------------------------------
diff --git a/odata2-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoServerDefinitionParser.java b/odata2-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoServerDefinitionParser.java
index fdb6e18..a8e7f77 100755
--- a/odata2-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoServerDefinitionParser.java
+++ b/odata2-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoServerDefinitionParser.java
@@ -71,9 +71,8 @@ public class OlingoServerDefinitionParser extends JAXRSServerFactoryBeanDefiniti
       builder.addPropertyValue("pathSplit", element.getAttribute("pathsplit"));
     }
     AbstractBeanDefinition definition = builder.getBeanDefinition();
-    BeanDefinitionHolder holder =
-        new BeanDefinitionHolder(definition, "OlingoODataRootLocator-" + element.getAttribute("id") + "-" + element.getAttribute("factory"),
-            new String[0]);
+    BeanDefinitionHolder holder = new BeanDefinitionHolder(definition,
+        "OlingoODataRootLocator-" + element.getAttribute("id") + "-" + element.getAttribute("factory"), new String[0]);
     registerBeanDefinition(holder, parserContext.getRegistry());
 
     ManagedList<BeanDefinition> services = new ManagedList<BeanDefinition>(3);