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 2015/01/27 20:24:59 UTC

[01/37] olingo-odata2 git commit: Added support for Spring

Repository: olingo-odata2
Updated Branches:
  refs/heads/Olingo-129_PocJpaDataStore 7224e855a -> 13b99eab0


Added support for Spring

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/5a93f4cc
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata2/tree/5a93f4cc
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata2/diff/5a93f4cc

Branch: refs/heads/Olingo-129_PocJpaDataStore
Commit: 5a93f4cc4e7c14759b1f3e8d1022c02978573646
Parents: 0c4bac5
Author: Lior Okman <li...@sap.com>
Authored: Wed Nov 12 20:25:43 2014 +0200
Committer: Michael Bolz <mi...@sap.com>
Committed: Thu Nov 13 06:35:57 2014 +0100

----------------------------------------------------------------------
 .../core/rest/spring/ODataRootLocator.java      | 141 +++++++++++++++++++
 odata2-lib/odata-spring/pom.xml                 |  39 +++++
 .../odata2/spring/OlingoNamespaceHandler.java   |  13 ++
 .../spring/OlingoServerDefinitionParser.java    |  73 ++++++++++
 .../src/main/resources/META-INF/spring.handlers |   1 +
 .../src/main/resources/META-INF/spring.schemas  |   1 +
 .../src/main/resources/schema/olingo.xsd        |  23 +++
 odata2-lib/pom.xml                              |   1 +
 pom.xml                                         |   2 +
 9 files changed, 294 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/5a93f4cc/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
new file mode 100755
index 0000000..295dc9d
--- /dev/null
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/rest/spring/ODataRootLocator.java
@@ -0,0 +1,141 @@
+/*******************************************************************************
+ * 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.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;
+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.rest.ODataRedirectLocator;
+import org.apache.olingo.odata2.core.rest.ODataSubLocator;
+import org.apache.olingo.odata2.core.rest.SubLocatorParameter;
+
+/**
+ * Default OData root locator responsible to handle the whole path and delegate all calls to a sub locator:<p>
+ * <code>/{odata path} e.g. http://host:port/webapp/odata.svc/$metadata</code><br>
+ * All path segments defined by a servlet mapping belong to the odata uri.
+ * </p>
+ * This behavior can be changed:<p>
+ * <code>/{custom path}{odata path} e.g. http://host:port/webapp/bmw/odata.svc/$metadata</code><br>
+ * The first segment defined by a servlet mapping belong to customer context and the following segments are OData
+ * specific.
+ * </p>
+ *
+ */
+@Path("/")
+public class 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;
+
+  // These next two members are exposed so that they can be injected with Spring
+  private ODataServiceFactory serviceFactory;
+  private int pathSplit = 0;
+
+  /**
+   * 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();
+    }
+
+    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);
+  }
+
+  private Object handleRedirect() {
+    return new ODataRedirectLocator();
+  }
+
+  public ODataServiceFactory getServiceFactory() {
+	return serviceFactory;
+  }
+
+  public void setServiceFactory(ODataServiceFactory serviceFactory) {
+	this.serviceFactory = serviceFactory;
+  }
+
+  public int getPathSplit() {
+	return pathSplit;
+  }
+
+  public void setPathSplit(int pathSplit) {
+	this.pathSplit = pathSplit;
+  }
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/5a93f4cc/odata2-lib/odata-spring/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-spring/pom.xml b/odata2-lib/odata-spring/pom.xml
new file mode 100755
index 0000000..8602fcc
--- /dev/null
+++ b/odata2-lib/odata-spring/pom.xml
@@ -0,0 +1,39 @@
+<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>
+	<artifactId>odata-spring</artifactId>
+	<name>${project.artifactId}</name>
+
+	<parent>
+		<groupId>org.apache.olingo</groupId>
+		<artifactId>olingo-odata2-lib</artifactId>
+		<version>2.0.2-SNAPSHOT</version>
+	</parent>
+
+	<dependencies>
+		<dependency>
+			<groupId>org.springframework</groupId>
+			<artifactId>spring-beans</artifactId>
+			<version>${spring.version}</version>
+			<exclusions>
+				<exclusion>
+					<groupId>commons-logging</groupId>
+					<artifactId>commons-logging</artifactId>
+				</exclusion>
+			</exclusions>
+			<optional>true</optional>
+		</dependency>
+
+		<dependency>
+			<groupId>${project.groupId}</groupId>
+			<version>${project.version}</version>
+			<artifactId>olingo-odata2-core</artifactId>
+		</dependency>
+
+		<dependency>
+			<groupId>org.apache.cxf</groupId>
+			<artifactId>cxf-rt-frontend-jaxrs</artifactId>
+			<version>${cxf.version}</version>
+		</dependency>
+	</dependencies>
+</project>

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/5a93f4cc/odata2-lib/odata-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoNamespaceHandler.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoNamespaceHandler.java b/odata2-lib/odata-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoNamespaceHandler.java
new file mode 100755
index 0000000..a141dde
--- /dev/null
+++ b/odata2-lib/odata-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoNamespaceHandler.java
@@ -0,0 +1,13 @@
+package org.apache.olingo.odata2.spring;
+
+import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
+
+
+public class OlingoNamespaceHandler extends NamespaceHandlerSupport {
+
+	@Override
+	public void init() {
+		registerBeanDefinitionParser("server", new OlingoServerDefinitionParser());
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/5a93f4cc/odata2-lib/odata-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoServerDefinitionParser.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoServerDefinitionParser.java b/odata2-lib/odata-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoServerDefinitionParser.java
new file mode 100755
index 0000000..849e7a8
--- /dev/null
+++ b/odata2-lib/odata-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoServerDefinitionParser.java
@@ -0,0 +1,73 @@
+package org.apache.olingo.odata2.spring;
+
+import org.apache.cxf.jaxrs.spring.JAXRSServerFactoryBeanDefinitionParser;
+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.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.beans.factory.config.BeanDefinitionHolder;
+import org.springframework.beans.factory.support.AbstractBeanDefinition;
+import org.springframework.beans.factory.support.BeanDefinitionBuilder;
+import org.springframework.beans.factory.support.ManagedList;
+import org.springframework.beans.factory.xml.ParserContext;
+import org.w3c.dom.Element;
+
+public class OlingoServerDefinitionParser extends JAXRSServerFactoryBeanDefinitionParser {
+
+	public OlingoServerDefinitionParser() {
+		super();
+		setBeanClass(SpringJAXRSServerFactoryBean.class);
+	}
+
+	@Override
+	protected void mapAttribute(BeanDefinitionBuilder bean, Element e,  String name, String val) {
+		if ("id".equals(name) || "address".equals(name)) {
+			mapToProperty(bean, name, val);
+		}
+	}
+
+	@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 = BeanDefinitionBuilder.genericBeanDefinition(ODataExceptionMapperImpl.class).getBeanDefinition();
+			definition.setScope(BeanDefinition.SCOPE_PROTOTYPE);
+			BeanDefinitionHolder holder = new BeanDefinitionHolder(definition, "OlingoODataExceptionHandler", new String[0]);
+			registerBeanDefinition(holder, parserContext.getRegistry());
+		}
+
+		if (!parserContext.getRegistry().containsBeanDefinition("OlingoODataProvider")) {
+			AbstractBeanDefinition definition = BeanDefinitionBuilder.genericBeanDefinition(ODataApplication.MyProvider.class).getBeanDefinition();
+			definition.setScope(BeanDefinition.SCOPE_PROTOTYPE);
+			BeanDefinitionHolder holder = new BeanDefinitionHolder(definition, "OlingoODataProvider", new String[0]);
+			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);
+
+		}
+
+		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/5a93f4cc/odata2-lib/odata-spring/src/main/resources/META-INF/spring.handlers
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-spring/src/main/resources/META-INF/spring.handlers b/odata2-lib/odata-spring/src/main/resources/META-INF/spring.handlers
new file mode 100755
index 0000000..6f63fc8
--- /dev/null
+++ b/odata2-lib/odata-spring/src/main/resources/META-INF/spring.handlers
@@ -0,0 +1 @@
+http\://www.apache.org/olingo/odata2/spring/namespace=org.apache.olingo.odata2.spring.OlingoNamespaceHandler

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/5a93f4cc/odata2-lib/odata-spring/src/main/resources/META-INF/spring.schemas
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-spring/src/main/resources/META-INF/spring.schemas b/odata2-lib/odata-spring/src/main/resources/META-INF/spring.schemas
new file mode 100755
index 0000000..85b9a6d
--- /dev/null
+++ b/odata2-lib/odata-spring/src/main/resources/META-INF/spring.schemas
@@ -0,0 +1 @@
+http\://www.apache.org/olingo/odata2/spring/namespace.xsd=schema/olingo.xsd

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/5a93f4cc/odata2-lib/odata-spring/src/main/resources/schema/olingo.xsd
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-spring/src/main/resources/schema/olingo.xsd b/odata2-lib/odata-spring/src/main/resources/schema/olingo.xsd
new file mode 100755
index 0000000..2b160e9
--- /dev/null
+++ b/odata2-lib/odata-spring/src/main/resources/schema/olingo.xsd
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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"
+	elementFormDefault="unqualified">
+
+	<xsd:import namespace="http://www.springframework.org/schema/beans"
+				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:extension>
+			</xsd:complexContent>
+		</xsd:complexType>
+	</xsd:element>
+</xsd:schema>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/5a93f4cc/odata2-lib/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-lib/pom.xml b/odata2-lib/pom.xml
index c646f3f..f510ec7 100644
--- a/odata2-lib/pom.xml
+++ b/odata2-lib/pom.xml
@@ -30,5 +30,6 @@
         <module>odata-fit</module>
         <module>odata-ref</module>
         <module>odata-web</module>
+        <module>odata-spring</module>
     </modules>
 </project>

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/5a93f4cc/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index fbe059e..67ae922 100644
--- a/pom.xml
+++ b/pom.xml
@@ -72,6 +72,8 @@
 
 		<version.eclipselink>2.5.1</version.eclipselink>
 		<version.javax.persistence>2.0.5</version.javax.persistence>
+
+		<spring.version>3.2.12.RELEASE</spring.version>
 	</properties>
 
 	<modules>


[17/37] olingo-odata2 git commit: [OLINGO-193] Moved all spring related into spring extension module

Posted by mi...@apache.org.
[OLINGO-193] Moved all spring related into spring extension module


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

Branch: refs/heads/Olingo-129_PocJpaDataStore
Commit: 986b1c4b4c45bfa0b156928108f2fe5ae6410236
Parents: 1ee1ff4
Author: Michael Bolz <mi...@sap.com>
Authored: Tue Dec 23 13:51:06 2014 +0100
Committer: Michael Bolz <mi...@sap.com>
Committed: Tue Dec 23 13:56:35 2014 +0100

----------------------------------------------------------------------
 .../odata2/core/rest/ODataRootLocator.java      |  98 +++++++++----
 .../core/rest/spring/ODataRootLocator.java      | 138 -------------------
 odata2-spring/pom.xml                           |   1 -
 .../olingo/odata2/spring/OlingoRootLocator.java | 134 ++++++++++++++++++
 .../spring/OlingoServerDefinitionParser.java    |  39 ++++--
 .../src/main/resources/schema/olingo.xsd        |   2 +-
 .../spring/SpringNamespaceHandlerTest.java      |  20 +--
 .../resources/spring/applicationContext.xml     |   2 +-
 8 files changed, 247 insertions(+), 187 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/986b1c4b/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 64f9d4f..3ff5984 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
@@ -6,9 +6,9 @@
  * 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
@@ -18,13 +18,24 @@
  ******************************************************************************/
 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;
 
@@ -38,40 +49,77 @@ import org.apache.olingo.odata2.core.rest.app.AbstractODataApplication;
  * The first segment defined by a servlet mapping belong to customer context and the following segments are OData
  * specific.
  * </p>
- * 
+ *
  */
 @Path("/")
-public class ODataRootLocator extends
-    org.apache.olingo.odata2.core.rest.spring.ODataRootLocator {
+public class ODataRootLocator {
 
   @Context
+  private HttpHeaders httpHeaders;
+  @Context
+  private UriInfo uriInfo;
+  @Context
+  private Request request;
+  @Context
   private ServletConfig servletConfig;
+  @Context
+  private HttpServletRequest servletRequest;
 
-  @Override
-  public ODataServiceFactory getServiceFactory() {
-    return createServiceFactoryFromContext(app, servletRequest,
-        servletConfig);
-  }
+  @Context
+  private Application app;
 
-  @Override
-  public void setServiceFactory(ODataServiceFactory serviceFactory) {
-    // Don't do anything
-  }
+  /**
+   * 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();
+    }
+
+    ODataServiceFactory serviceFactory = createServiceFactoryFromContext(app, servletRequest, servletConfig);
 
-  @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;
-  }
 
-  @Override
-  public void setPathSplit(int pathSplit) {
-    // Don't do anything
+    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);
   }
 
   public static ODataServiceFactory createServiceFactoryFromContext(final Application app,
@@ -100,4 +148,8 @@ public class ODataRootLocator extends
       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/986b1c4b/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
deleted file mode 100644
index ea143e7..0000000
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/rest/spring/ODataRootLocator.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*******************************************************************************
- * 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.core.rest.spring;
-
-import java.util.List;
-
-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.rest.ODataRedirectLocator;
-import org.apache.olingo.odata2.core.rest.ODataSubLocator;
-import org.apache.olingo.odata2.core.rest.SubLocatorParameter;
-
-/**
- * Default OData root locator responsible to handle the whole path and delegate all calls to a sub locator:<p>
- * <code>/{odata path} e.g. http://host:port/webapp/odata.svc/$metadata</code><br>
- * All path segments defined by a servlet mapping belong to the odata uri.
- * </p>
- * This behavior can be changed:<p>
- * <code>/{custom path}{odata path} e.g. http://host:port/webapp/bmw/odata.svc/$metadata</code><br>
- * The first segment defined by a servlet mapping belong to customer context and the following segments are OData
- * specific.
- * </p>
- *
- */
-@Path("/")
-public class ODataRootLocator {
-
-  @Context
-  private HttpHeaders httpHeaders;
-  @Context
-  private UriInfo uriInfo;
-  @Context
-  private Request request;
-  @Context
-  protected HttpServletRequest servletRequest;
-
-  @Context
-  protected Application app;
-
-  // These next two members are exposed so that they can be injected with Spring
-  private ODataServiceFactory serviceFactory;
-  private int pathSplit = 0;
-
-  /**
-   * 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();
-    }
-
-    final SubLocatorParameter param = new SubLocatorParameter();
-    param.setServiceFactory(getServiceFactory());
-    param.setPathSegments(pathSegments);
-    param.setHttpHeaders(httpHeaders);
-    param.setUriInfo(uriInfo);
-    param.setRequest(request);
-    param.setServletRequest(servletRequest);
-    param.setPathSplit(getPathSplit());
-
-    return ODataSubLocator.create(param);
-  }
-
-  private Object handleRedirect() {
-    return new ODataRedirectLocator();
-  }
-
-  public ODataServiceFactory getServiceFactory() {
-    return serviceFactory;
-  }
-
-  public void setServiceFactory(ODataServiceFactory serviceFactory) {
-    this.serviceFactory = serviceFactory;
-  }
-
-  public int getPathSplit() {
-    return pathSplit;
-  }
-
-  public void setPathSplit(int pathSplit) {
-    this.pathSplit = pathSplit;
-  }
-}

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/986b1c4b/odata2-spring/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-spring/pom.xml b/odata2-spring/pom.xml
index 5183719..ed1c7b3 100755
--- a/odata2-spring/pom.xml
+++ b/odata2-spring/pom.xml
@@ -75,7 +75,6 @@
 			<groupId>javax.servlet</groupId>
 			<artifactId>servlet-api</artifactId>
 			<version>2.5</version>
-			<scope>test</scope>
 		</dependency>
 		<dependency>
 			<groupId>commons-logging</groupId>

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/986b1c4b/odata2-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoRootLocator.java
----------------------------------------------------------------------
diff --git a/odata2-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoRootLocator.java b/odata2-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoRootLocator.java
new file mode 100644
index 0000000..bf60cb6
--- /dev/null
+++ b/odata2-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoRootLocator.java
@@ -0,0 +1,134 @@
+/*******************************************************************************
+ * 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.ODataServiceFactory;
+import org.apache.olingo.odata2.api.exception.ODataBadRequestException;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.core.rest.ODataRedirectLocator;
+import org.apache.olingo.odata2.core.rest.ODataSubLocator;
+import org.apache.olingo.odata2.core.rest.SubLocatorParameter;
+
+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 java.util.List;
+
+/**
+ * Default OData root locator responsible to handle the whole path and delegate all calls to a sub locator:<p>
+ * <code>/{odata path} e.g. http://host:port/webapp/odata.svc/$metadata</code><br>
+ * All path segments defined by a servlet mapping belong to the odata uri.
+ * </p>
+ * This behavior can be changed:<p>
+ * <code>/{custom path}{odata path} e.g. http://host:port/webapp/bmw/odata.svc/$metadata</code><br>
+ * The first segment defined by a servlet mapping belong to customer context and the following segments are OData
+ * specific.
+ * </p>
+ *
+ */
+@Path("/")
+public class OlingoRootLocator {
+
+  @Context
+  private HttpHeaders httpHeaders;
+  @Context
+  private UriInfo uriInfo;
+  @Context
+  private Request request;
+  @Context
+  private HttpServletRequest servletRequest;
+
+  // These next two members are exposed so that they can be injected with Spring
+  private ODataServiceFactory serviceFactory;
+  private int pathSplit = 0;
+
+  /**
+   * 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 org.apache.olingo.odata2.api.exception.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();
+    }
+
+    final SubLocatorParameter param = new SubLocatorParameter();
+    param.setServiceFactory(getServiceFactory());
+    param.setPathSegments(pathSegments);
+    param.setHttpHeaders(httpHeaders);
+    param.setUriInfo(uriInfo);
+    param.setRequest(request);
+    param.setServletRequest(servletRequest);
+    param.setPathSplit(getPathSplit());
+
+    return ODataSubLocator.create(param);
+  }
+
+  private Object handleRedirect() {
+    return new ODataRedirectLocator();
+  }
+
+  public ODataServiceFactory getServiceFactory() {
+    return serviceFactory;
+  }
+
+  public void setServiceFactory(ODataServiceFactory serviceFactory) {
+    this.serviceFactory = serviceFactory;
+  }
+
+  public int getPathSplit() {
+    return pathSplit;
+  }
+
+  public void setPathSplit(int pathSplit) {
+    this.pathSplit = pathSplit;
+  }
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/986b1c4b/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 a8e7f77..c517ad4 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
@@ -21,7 +21,6 @@ package org.apache.olingo.odata2.spring;
 import org.apache.cxf.jaxrs.spring.JAXRSServerFactoryBeanDefinitionParser;
 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.springframework.beans.factory.config.BeanDefinition;
 import org.springframework.beans.factory.config.BeanDefinitionHolder;
 import org.springframework.beans.factory.support.AbstractBeanDefinition;
@@ -30,8 +29,20 @@ import org.springframework.beans.factory.support.ManagedList;
 import org.springframework.beans.factory.xml.ParserContext;
 import org.w3c.dom.Element;
 
+/**
+ *
+ */
 public class OlingoServerDefinitionParser extends JAXRSServerFactoryBeanDefinitionParser {
 
+  protected static final String OLINGO_ROOT_LOCATOR = "OlingoRootLocator";
+  protected static final String OLINGO_ODATA_PROVIDER = "OlingoODataProvider";
+  protected static final String OLINGO_ODATA_EXCEPTION_HANDLER = "OlingoODataExceptionHandler";
+  protected static final String SERVICE_FACTORY = "serviceFactory";
+  protected static final String SERVICE_BEANS = "serviceBeans";
+  protected static final String ID = "id";
+  protected static final String FACTORY = "factory";
+  protected static final String PATH_SPLIT = "pathSplit";
+
   public OlingoServerDefinitionParser() {
     super();
     setBeanClass(SpringJAXRSServerFactoryBean.class);
@@ -39,7 +50,7 @@ public class OlingoServerDefinitionParser extends JAXRSServerFactoryBeanDefiniti
 
   @Override
   protected void mapAttribute(BeanDefinitionBuilder bean, Element e, String name, String val) {
-    if ("id".equals(name) || "address".equals(name)) {
+    if (ID.equals(name) || "address".equals(name)) {
       mapToProperty(bean, name, val);
     }
   }
@@ -48,38 +59,38 @@ public class OlingoServerDefinitionParser extends JAXRSServerFactoryBeanDefiniti
   protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder bean) {
     super.doParse(element, parserContext, bean);
 
-    if (!parserContext.getRegistry().containsBeanDefinition("OlingoODataExceptionHandler")) {
+    if (!parserContext.getRegistry().containsBeanDefinition(OLINGO_ODATA_EXCEPTION_HANDLER)) {
       AbstractBeanDefinition definition =
           BeanDefinitionBuilder.genericBeanDefinition(ODataExceptionMapperImpl.class).getBeanDefinition();
       definition.setScope(BeanDefinition.SCOPE_PROTOTYPE);
-      BeanDefinitionHolder holder = new BeanDefinitionHolder(definition, "OlingoODataExceptionHandler", new String[0]);
+      BeanDefinitionHolder holder = new BeanDefinitionHolder(definition, OLINGO_ODATA_EXCEPTION_HANDLER, new String[0]);
       registerBeanDefinition(holder, parserContext.getRegistry());
     }
 
-    if (!parserContext.getRegistry().containsBeanDefinition("OlingoODataProvider")) {
+    if (!parserContext.getRegistry().containsBeanDefinition(OLINGO_ODATA_PROVIDER)) {
       AbstractBeanDefinition definition =
           BeanDefinitionBuilder.genericBeanDefinition(ODataApplication.MyProvider.class).getBeanDefinition();
       definition.setScope(BeanDefinition.SCOPE_PROTOTYPE);
-      BeanDefinitionHolder holder = new BeanDefinitionHolder(definition, "OlingoODataProvider", new String[0]);
+      BeanDefinitionHolder holder = new BeanDefinitionHolder(definition, OLINGO_ODATA_PROVIDER, new String[0]);
       registerBeanDefinition(holder, parserContext.getRegistry());
     }
 
-    BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(ODataRootLocator.class);
+    BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(OlingoRootLocator.class);
     builder.setScope(BeanDefinition.SCOPE_PROTOTYPE);
-    builder.addPropertyReference("serviceFactory", element.getAttribute("factory"));
-    if (element.hasAttribute("pathsplit")) {
-      builder.addPropertyValue("pathSplit", element.getAttribute("pathsplit"));
+    builder.addPropertyReference(SERVICE_FACTORY, element.getAttribute(FACTORY));
+    if (element.hasAttribute(PATH_SPLIT)) {
+      builder.addPropertyValue(PATH_SPLIT, element.getAttribute(PATH_SPLIT));
     }
     AbstractBeanDefinition definition = builder.getBeanDefinition();
     BeanDefinitionHolder holder = new BeanDefinitionHolder(definition,
-        "OlingoODataRootLocator-" + element.getAttribute("id") + "-" + element.getAttribute("factory"), new String[0]);
+        OLINGO_ROOT_LOCATOR + "-" + element.getAttribute(ID) + "-" + element.getAttribute(FACTORY));
     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);
+    services.add(parserContext.getRegistry().getBeanDefinition(OLINGO_ODATA_EXCEPTION_HANDLER));
+    services.add(parserContext.getRegistry().getBeanDefinition(OLINGO_ODATA_PROVIDER));
+    bean.addPropertyValue(SERVICE_BEANS, services);
   }
 
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/986b1c4b/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 39424dd..436eb74 100755
--- a/odata2-spring/src/main/resources/schema/olingo.xsd
+++ b/odata2-spring/src/main/resources/schema/olingo.xsd
@@ -24,7 +24,7 @@
 				<xsd:extension base="beans:identifiedType">
 					<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: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/986b1c4b/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
index 81a2372..089cfe3 100755
--- 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
@@ -18,12 +18,9 @@
  ******************************************************************************/
 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;
@@ -32,6 +29,11 @@ import org.springframework.test.context.ContextConfiguration;
 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 import org.springframework.test.context.web.WebAppConfiguration;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
 @RunWith(SpringJUnit4ClassRunner.class)
 @ContextConfiguration("classpath:spring/applicationContext.xml")
 @WebAppConfiguration
@@ -44,15 +46,15 @@ public class SpringNamespaceHandlerTest {
   public void testSuccessfullyCreated() {
     assertTrue(appCtx.containsBean("testServer"));
 
-    assertTrue(appCtx.containsBean("OlingoODataExceptionHandler"));
-    assertTrue(appCtx.containsBean("OlingoODataProvider"));
+    assertTrue(appCtx.containsBean(OlingoServerDefinitionParser.OLINGO_ODATA_EXCEPTION_HANDLER));
+    assertTrue(appCtx.containsBean(OlingoServerDefinitionParser.OLINGO_ODATA_PROVIDER));
 
     assertEquals(ODataExceptionMapperImpl.class, appCtx.getType("OlingoODataExceptionHandler"));
     assertEquals(ODataApplication.MyProvider.class, appCtx.getType("OlingoODataProvider"));
 
-    String rootLocatorName = "OlingoODataRootLocator-testServer-serviceFactory";
+    String rootLocatorName = "OlingoRootLocator-testServer-serviceFactory";
     assertTrue(appCtx.containsBean(rootLocatorName));
-    assertEquals(ODataRootLocator.class, appCtx.getType(rootLocatorName));
+    assertEquals(OlingoRootLocator.class, appCtx.getType(rootLocatorName));
 
     SpringJAXRSServerFactoryBean server = appCtx.getBean("testServer", SpringJAXRSServerFactoryBean.class);
     assertEquals("/service.svc", server.getAddress());
@@ -60,8 +62,8 @@ public class SpringNamespaceHandlerTest {
 
   @Test
   public void testCorrectFactoryAndPathSplit() {
-    String rootLocatorName = "OlingoODataRootLocator-testServer-serviceFactory";
-    ODataRootLocator rootLocator = appCtx.getBean(rootLocatorName, ODataRootLocator.class);
+    String rootLocatorName = "OlingoRootLocator-testServer-serviceFactory";
+    OlingoRootLocator rootLocator = appCtx.getBean(rootLocatorName, OlingoRootLocator.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/986b1c4b/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
index 567c8da..31e9cd8 100755
--- a/odata2-spring/src/test/resources/spring/applicationContext.xml
+++ b/odata2-spring/src/test/resources/spring/applicationContext.xml
@@ -24,7 +24,7 @@
 	<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"/>
+	<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


[16/37] olingo-odata2 git commit: Minor fix in combination with Spring/CXFServlet

Posted by mi...@apache.org.
Minor fix in combination with Spring/CXFServlet


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

Branch: refs/heads/Olingo-129_PocJpaDataStore
Commit: 1ee1ff4334f5f3d993aa1e772c0e9b4e55c7dc82
Parents: a339d29
Author: Michael Bolz <mi...@sap.com>
Authored: Tue Dec 23 11:09:46 2014 +0100
Committer: Michael Bolz <mi...@sap.com>
Committed: Tue Dec 23 11:09:46 2014 +0100

----------------------------------------------------------------------
 .../java/org/apache/olingo/odata2/core/rest/RestUtil.java    | 8 +++++---
 pom.xml                                                      | 1 -
 2 files changed, 5 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/1ee1ff43/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/rest/RestUtil.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/rest/RestUtil.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/rest/RestUtil.java
index 8cb200d..b726f9b 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/rest/RestUtil.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/rest/RestUtil.java
@@ -37,6 +37,7 @@ import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.ResponseBuilder;
 import javax.ws.rs.core.UriBuilder;
+import javax.ws.rs.core.UriInfo;
 
 import org.apache.olingo.odata2.api.commons.HttpHeaders;
 import org.apache.olingo.odata2.api.exception.ODataBadRequestException;
@@ -180,7 +181,8 @@ public class RestUtil {
   public static PathInfoImpl buildODataPathInfo(final SubLocatorParameter param) throws ODataException {
     PathInfoImpl pathInfo = splitPath(param);
 
-    pathInfo.setServiceRoot(buildBaseUri(param.getServletRequest(), pathInfo.getPrecedingSegments()));
+    pathInfo.setServiceRoot(buildBaseUri(param.getUriInfo(),
+        param.getServletRequest(), pathInfo.getPrecedingSegments()));
     pathInfo.setRequestUri(buildRequestUri(param.getServletRequest()));
 
     return pathInfo;
@@ -224,10 +226,10 @@ public class RestUtil {
     return pathInfo;
   }
 
-  private static URI buildBaseUri(final HttpServletRequest request,
+  private static URI buildBaseUri(final UriInfo uriInfo, final HttpServletRequest request,
       final List<PathSegment> precedingPathSegments) throws ODataException {
     try {
-      String path = request.getContextPath() + request.getServletPath();
+      String path = uriInfo.getBaseUri().getPath();
       UriBuilder uriBuilder = UriBuilder.fromUri(path);
       for (final PathSegment ps : precedingPathSegments) {
         uriBuilder = uriBuilder.path(ps.getPath());

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/1ee1ff43/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 1c8875b..67ae922 100644
--- a/pom.xml
+++ b/pom.xml
@@ -82,7 +82,6 @@
 		<module>odata2-annotation-processor</module>
 		<module>odata2-dist</module>
 		<module>odata2-sample</module>
-        	<module>odata2-spring</module>
 	</modules>
 
 	<build>


[25/37] olingo-odata2 git commit: [OLINGO-476] Removed 'printStackTrace' in test

Posted by mi...@apache.org.
[OLINGO-476] Removed 'printStackTrace' in test


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

Branch: refs/heads/Olingo-129_PocJpaDataStore
Commit: f53eda472c0b0564cb018fab18830eebbecfeafe
Parents: 86576ce
Author: mibo <mi...@mirb.de>
Authored: Sat Jan 10 00:03:56 2015 +0100
Committer: mibo <mi...@mirb.de>
Committed: Sat Jan 10 00:03:56 2015 +0100

----------------------------------------------------------------------
 .../olingo/odata2/jpa/processor/core/access/data/JPAEntityTest.java | 1 -
 1 file changed, 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/f53eda47/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityTest.java
index 74edb70..46d967e 100644
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityTest.java
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityTest.java
@@ -86,7 +86,6 @@ public class JPAEntityTest {
       jpaEntity = new JPAEntity(edmEntityType, edmEntitySet, mockODataJPAContext());
       jpaEntity.create(ODataEntryMockUtil.mockODataEntry(JPATypeMock.ENTITY_NAME));
     } catch (ODataJPARuntimeException e) {
-      e.printStackTrace();
       fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
           + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
     } catch (EdmException e) {


[07/37] olingo-odata2 git commit: [OLINGO-521] Fix BatchResponseWriter

Posted by mi...@apache.org.
[OLINGO-521] Fix BatchResponseWriter

Signed-off-by: Christian Amend <ch...@apache.org>


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

Branch: refs/heads/Olingo-129_PocJpaDataStore
Commit: 14c534ee3bc265f6a9bc5b32ca87ad199371d627
Parents: 4bab6aa
Author: Christian Holzer <c....@sap.com>
Authored: Thu Dec 11 14:27:36 2014 +0100
Committer: Christian Amend <ch...@apache.org>
Committed: Mon Dec 15 14:55:08 2014 +0100

----------------------------------------------------------------------
 .../odata2/core/batch/BatchResponseWriter.java  |  31 +--
 .../core/batch/BatchRequestWriterITTest.java    | 243 +++++++++++++++++++
 .../core/batch/BatchResponseParserTest.java     |  57 ++++-
 .../odata2/core/batch/BatchResponseTest.java    |   2 +-
 .../core/batch/BatchResponseWriterITTest.java   | 179 ++++++++++++++
 5 files changed, 496 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/14c534ee/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/BatchResponseWriter.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/BatchResponseWriter.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/BatchResponseWriter.java
index be189d3..3840cdf 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/BatchResponseWriter.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/BatchResponseWriter.java
@@ -33,7 +33,7 @@ import org.apache.olingo.odata2.api.processor.ODataResponse;
 public class BatchResponseWriter {
   private static final String COLON = ":";
   private static final String SP = " ";
-  private static final String LF = "\r\n";
+  private static final String CRLF = "\r\n";
   private ResponseWriter writer = new ResponseWriter();
 
   public ODataResponse writeResponse(final List<BatchResponsePart> batchResponseParts) throws BatchException {
@@ -49,18 +49,18 @@ public class BatchResponseWriter {
   private void appendChangeSet(final BatchResponsePart batchResponsePart) throws BatchException {
     String boundary = BatchHelper.generateBoundary("changeset");
     writer.append(HttpHeaders.CONTENT_TYPE).append(COLON).append(SP)
-        .append("multipart/mixed; boundary=" + boundary).append(LF).append(LF);
+        .append("multipart/mixed; boundary=" + boundary).append(CRLF).append(CRLF);
     for (ODataResponse response : batchResponsePart.getResponses()) {
-      writer.append("--").append(boundary).append(LF);
+      writer.append("--").append(boundary).append(CRLF);
       appendResponsePartBody(response);
     }
-    writer.append("--").append(boundary).append("--").append(LF).append(LF);
+    writer.append("--").append(boundary).append("--").append(CRLF);
   }
 
   private void appendResponsePart(final List<BatchResponsePart> batchResponseParts, final String boundary)
       throws BatchException {
     for (BatchResponsePart batchResponsePart : batchResponseParts) {
-      writer.append("--").append(boundary).append(LF);
+      writer.append("--").append(boundary).append(CRLF);
       if (batchResponsePart.isChangeSet()) {
         appendChangeSet(batchResponsePart);
       } else {
@@ -73,16 +73,16 @@ public class BatchResponseWriter {
 
   private void appendResponsePartBody(final ODataResponse response) throws BatchException {
     writer.append(HttpHeaders.CONTENT_TYPE).append(COLON).append(SP)
-        .append(HttpContentType.APPLICATION_HTTP).append(LF);
+        .append(HttpContentType.APPLICATION_HTTP).append(CRLF);
     writer.append(BatchHelper.HTTP_CONTENT_TRANSFER_ENCODING).append(COLON).append(SP)
-        .append(BatchHelper.BINARY_ENCODING).append(LF);
+        .append(BatchHelper.BINARY_ENCODING).append(CRLF);
     if (response.getHeader(BatchHelper.MIME_HEADER_CONTENT_ID) != null) {
       writer.append(BatchHelper.HTTP_CONTENT_ID).append(COLON).append(SP)
-          .append(response.getHeader(BatchHelper.MIME_HEADER_CONTENT_ID)).append(LF);
+          .append(response.getHeader(BatchHelper.MIME_HEADER_CONTENT_ID)).append(CRLF);
     }
-    writer.append(LF);
+    writer.append(CRLF);
     writer.append("HTTP/1.1").append(SP).append(String.valueOf(response.getStatus().getStatusCode())).append(SP)
-        .append(response.getStatus().getInfo()).append(LF);
+        .append(response.getStatus().getInfo()).append(CRLF);
     appendHeader(response);
     if (!HttpStatusCodes.NO_CONTENT.equals(response.getStatus())) {
       String body;
@@ -93,20 +93,23 @@ public class BatchResponseWriter {
         body = response.getEntity().toString();
       }
       writer.append(HttpHeaders.CONTENT_LENGTH).append(COLON).append(SP)
-          .append(String.valueOf(BatchHelper.getBytes(body).length)).append(LF).append(LF);
+          .append(String.valueOf(BatchHelper.getBytes(body).length)).append(CRLF).append(CRLF);
       writer.append(body);
+    } else {
+      // No header if status code equals to 204 (No content)
+      writer.append(CRLF);
     }
-    writer.append(LF).append(LF);
+    writer.append(CRLF);
   }
 
   private void appendHeader(final ODataResponse response) {
     for (String name : response.getHeaderNames()) {
       if (!BatchHelper.MIME_HEADER_CONTENT_ID.equalsIgnoreCase(name)
           && !BatchHelper.REQUEST_HEADER_CONTENT_ID.equalsIgnoreCase(name)) {
-        writer.append(name).append(COLON).append(SP).append(response.getHeader(name)).append(LF);
+        writer.append(name).append(COLON).append(SP).append(response.getHeader(name)).append(CRLF);
       } else if (BatchHelper.REQUEST_HEADER_CONTENT_ID.equalsIgnoreCase(name)) {
         writer.append(BatchHelper.HTTP_CONTENT_ID).append(COLON).append(SP)
-            .append(response.getHeader(name)).append(LF);
+            .append(response.getHeader(name)).append(CRLF);
       }
     }
   }

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/14c534ee/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchRequestWriterITTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchRequestWriterITTest.java b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchRequestWriterITTest.java
new file mode 100644
index 0000000..b153596
--- /dev/null
+++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchRequestWriterITTest.java
@@ -0,0 +1,243 @@
+/*******************************************************************************
+ * 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.core.batch;
+
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.olingo.odata2.api.batch.BatchException;
+import org.apache.olingo.odata2.api.batch.BatchRequestPart;
+import org.apache.olingo.odata2.api.client.batch.BatchChangeSet;
+import org.apache.olingo.odata2.api.client.batch.BatchChangeSetPart;
+import org.apache.olingo.odata2.api.client.batch.BatchPart;
+import org.apache.olingo.odata2.api.client.batch.BatchQueryPart;
+import org.apache.olingo.odata2.api.commons.HttpHeaders;
+import org.apache.olingo.odata2.api.ep.EntityProviderBatchProperties;
+import org.apache.olingo.odata2.api.processor.ODataRequest;
+import org.apache.olingo.odata2.core.PathInfoImpl;
+import org.apache.olingo.odata2.core.batch.v2.BatchParser;
+import org.apache.olingo.odata2.core.batch.v2.BufferedReaderIncludingLineEndings;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class BatchRequestWriterITTest {
+  private static final String POST = "POST";
+  private static final String GET = "GET";
+  private static final String BOUNDARY = "batch_123";
+  private static final String CONTENT_TYPE = "multipart/mixed ;boundary=" + BOUNDARY;
+  private static final String SERVICE_ROOT = "http://localhost/odata/";
+  private static EntityProviderBatchProperties batchProperties;
+
+  @BeforeClass
+  public static void setProperties() throws URISyntaxException {
+    PathInfoImpl pathInfo = new PathInfoImpl();
+    pathInfo.setServiceRoot(new URI(SERVICE_ROOT));
+    batchProperties = EntityProviderBatchProperties.init().pathInfo(pathInfo).build();
+  }
+
+  @Test
+  public void testQueryPart() throws Exception {
+    List<BatchPart> batch = new ArrayList<BatchPart>();
+    Map<String, String> headers = new HashMap<String, String>();
+    headers.put("Accept", "application/json");
+    BatchPart request = BatchQueryPart.method(GET).uri("Employees").headers(headers).build();
+    batch.add(request);
+
+    BatchRequestWriter writer = new BatchRequestWriter();
+    InputStream stream = writer.writeBatchRequest(batch, BOUNDARY);
+
+    List<BatchRequestPart> parsedRequestParts = parseBatchRequest(stream);
+    assertEquals(1, parsedRequestParts.size());
+    BatchRequestPart part = parsedRequestParts.get(0);
+
+    assertFalse(part.isChangeSet());
+    assertEquals(1, part.getRequests().size());
+    ODataRequest oDataRequest = part.getRequests().get(0);
+    assertEquals("Employees", oDataRequest.getPathInfo().getODataSegments().get(0).getPath());
+    assertEquals("application/json", oDataRequest.getAcceptHeaders().get(0));
+  }
+
+  @Test
+  public void testChangeSet() throws Exception {
+    List<BatchPart> batch = new ArrayList<BatchPart>();
+    Map<String, String> headers = new HashMap<String, String>();
+    headers.put("Accept", "application/json");
+    BatchPart request = BatchQueryPart.method(GET).uri("Employees").headers(headers).contentId("000").build();
+    batch.add(request);
+
+    Map<String, String> changeSetHeaders = new HashMap<String, String>();
+    changeSetHeaders.put("content-type", "application/json");
+    String body = "/9j/4AAQSkZJRgABAQEBLAEsAAD/4RM0RXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEA";
+    BatchChangeSetPart changeRequest = BatchChangeSetPart.method(POST)
+        .uri("Employees")
+        .body(body)
+        .headers(changeSetHeaders)
+        .contentId("111")
+        .build();
+    BatchChangeSet changeSet = BatchChangeSet.newBuilder().build();
+    changeSet.add(changeRequest);
+    batch.add(changeSet);
+    BatchRequestWriter writer = new BatchRequestWriter();
+    InputStream stream = writer.writeBatchRequest(batch, BOUNDARY);
+
+    final List<BatchRequestPart> parsedRequestParts = parseBatchRequest(stream);
+    assertEquals(2, parsedRequestParts.size());
+
+    // Get Request
+    final BatchRequestPart partGet = parsedRequestParts.get(0);
+    assertFalse(partGet.isChangeSet());
+    assertEquals(1, partGet.getRequests().size());
+    final ODataRequest oDataRequestGet = partGet.getRequests().get(0);
+    assertEquals("Employees", oDataRequestGet.getPathInfo().getODataSegments().get(0).getPath());
+    assertEquals("application/json", oDataRequestGet.getAcceptHeaders().get(0));
+
+    // Change set
+    final BatchRequestPart partChangeSet = parsedRequestParts.get(1);
+    assertTrue(partChangeSet.isChangeSet());
+    assertEquals(1, partChangeSet.getRequests().size());
+    final ODataRequest oDataRequestPost = partChangeSet.getRequests().get(0);
+    assertEquals("Employees", oDataRequestGet.getPathInfo().getODataSegments().get(0).getPath());
+    assertEquals("111", oDataRequestPost.getRequestHeaderValue(BatchHelper.MIME_HEADER_CONTENT_ID));
+    assertEquals(body, streamToString(oDataRequestPost.getBody()));
+    assertEquals("application/json", oDataRequestPost.getRequestHeaderValue(HttpHeaders.CONTENT_TYPE));
+  }
+
+  @Test
+  public void testTwoChangeSets() throws Exception {
+    List<BatchPart> batch = new ArrayList<BatchPart>();
+
+    // Get request
+    Map<String, String> headers = new HashMap<String, String>();
+    headers.put("Accept", "application/json");
+    BatchPart request = BatchQueryPart.method(GET).uri("Employees").headers(headers).contentId("000").build();
+    batch.add(request);
+
+    Map<String, String> headerPostRequest = new HashMap<String, String>();
+    headerPostRequest.put("content-type", "application/json");
+
+    // Changeset 1
+    String bodyEmployee = "/9j/4AAQSkZJRgABAQEBLAEsAAD/4RM0RXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEA";
+    BatchChangeSetPart postRequest = BatchChangeSetPart.method(POST)
+        .uri("Employees")
+        .body(bodyEmployee)
+        .headers(headerPostRequest)
+        .contentId("111")
+        .build();
+
+    String bodyEmployee2 = "TestString\r\n";
+    BatchChangeSetPart postRequest2 = BatchChangeSetPart.method(POST)
+        .uri("Employees")
+        .body(bodyEmployee2)
+        .headers(headerPostRequest)
+        .contentId("222")
+        .build();
+    BatchChangeSet changeSet = BatchChangeSet.newBuilder().build();
+    changeSet.add(postRequest);
+    changeSet.add(postRequest2);
+    batch.add(changeSet);
+
+    // Changeset 2
+    BatchChangeSet changeSet2 = BatchChangeSet.newBuilder().build();
+    postRequest2 = BatchChangeSetPart.method(POST)
+        .uri("Employees")
+        .body(bodyEmployee2)
+        .headers(headerPostRequest)
+        .contentId("222")
+        .build();
+    changeSet2.add(postRequest2);
+    postRequest = BatchChangeSetPart.method(POST)
+        .uri("Employees")
+        .body(bodyEmployee)
+        .headers(headerPostRequest)
+        .contentId("111")
+        .build();
+    changeSet2.add(postRequest);
+    batch.add(changeSet2);
+
+    // Write requests
+    BatchRequestWriter writer = new BatchRequestWriter();
+    InputStream stream = writer.writeBatchRequest(batch, BOUNDARY);
+    // Read requests
+    final List<BatchRequestPart> parsedRequestParts = parseBatchRequest(stream);
+    assertEquals(3, parsedRequestParts.size());
+
+    // Get request
+    final BatchRequestPart partGet = parsedRequestParts.get(0);
+    assertFalse(partGet.isChangeSet());
+    assertEquals(1, partGet.getRequests().size());
+    final ODataRequest oDataRequestGet = partGet.getRequests().get(0);
+    assertEquals("Employees", oDataRequestGet.getPathInfo().getODataSegments().get(0).getPath());
+    assertEquals("application/json", oDataRequestGet.getAcceptHeaders().get(0));
+
+    // Changeset 1
+    BatchRequestPart parsedChangeSet1 = parsedRequestParts.get(1);
+    assertTrue(parsedChangeSet1.isChangeSet());
+    assertEquals(2, parsedChangeSet1.getRequests().size());
+    ODataRequest oDataRequestPost1 = parsedChangeSet1.getRequests().get(0);
+    assertEquals("111", oDataRequestPost1.getRequestHeaderValue(BatchHelper.MIME_HEADER_CONTENT_ID));
+    assertEquals(bodyEmployee, streamToString(oDataRequestPost1.getBody()));
+    assertEquals("application/json", oDataRequestPost1.getRequestHeaderValue(HttpHeaders.CONTENT_TYPE));
+
+    ODataRequest oDataRequestPost12 = parsedChangeSet1.getRequests().get(1);
+    assertEquals("222", oDataRequestPost12.getRequestHeaderValue(BatchHelper.MIME_HEADER_CONTENT_ID));
+    assertEquals(bodyEmployee2, streamToString(oDataRequestPost12.getBody()));
+    assertEquals("application/json", oDataRequestPost12.getRequestHeaderValue(HttpHeaders.CONTENT_TYPE));
+
+    // Changeset 2
+    BatchRequestPart parsedChangeSet2 = parsedRequestParts.get(2);
+    assertTrue(parsedChangeSet2.isChangeSet());
+    assertEquals(2, parsedChangeSet2.getRequests().size());
+    ODataRequest oDataRequestPost21 = parsedChangeSet2.getRequests().get(0);
+    assertEquals("222", oDataRequestPost21.getRequestHeaderValue(BatchHelper.MIME_HEADER_CONTENT_ID));
+    assertEquals(bodyEmployee2, streamToString(oDataRequestPost21.getBody()));
+    assertEquals("application/json", oDataRequestPost21.getRequestHeaderValue(HttpHeaders.CONTENT_TYPE));
+
+    ODataRequest oDataRequestPost22 = parsedChangeSet2.getRequests().get(1);
+    assertEquals("111", oDataRequestPost22.getRequestHeaderValue(BatchHelper.MIME_HEADER_CONTENT_ID));
+    assertEquals(bodyEmployee, streamToString(oDataRequestPost22.getBody()));
+    assertEquals("application/json", oDataRequestPost22.getRequestHeaderValue(HttpHeaders.CONTENT_TYPE));
+  }
+
+  private List<BatchRequestPart> parseBatchRequest(InputStream batchRequest) throws BatchException {
+    final BatchParser parser = new BatchParser(CONTENT_TYPE, batchProperties, true);
+    return parser.parseBatchRequest(batchRequest);
+  }
+
+  private String streamToString(final InputStream in) throws IOException {
+    final BufferedReaderIncludingLineEndings reader = new BufferedReaderIncludingLineEndings(new InputStreamReader(in));
+    final StringBuilder builder = new StringBuilder();
+    String line;
+
+    while ((line = reader.readLine()) != null) {
+      builder.append(line);
+    }
+
+    reader.close();
+    return builder.toString();
+  }
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/14c534ee/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchResponseParserTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchResponseParserTest.java b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchResponseParserTest.java
index feaa50d..e107db5 100644
--- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchResponseParserTest.java
+++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchResponseParserTest.java
@@ -64,6 +64,61 @@ public class BatchResponseParserTest {
       assertEquals("text/plain;charset=utf-8", response.getHeaders().get(HttpHeaders.CONTENT_TYPE));
       assertEquals("22", response.getHeaders().get("Content-length"));
       assertEquals("1", response.getContentId());
+      assertEquals("Frederic Fall MODIFIED", response.getBody());
+    }
+  }
+
+  @Test
+  public void testSimpleBatchResponseWithLinebreak() throws BatchException {
+    String getResponse = "--batch_123" + CRLF
+        + "Content-Type: application/http" + CRLF
+        + "Content-Transfer-Encoding: binary" + CRLF
+        + "Content-ID: 1" + CRLF
+        + CRLF
+        + "HTTP/1.1 200 OK" + CRLF
+        + "DataServiceVersion: 2.0" + CRLF
+        + "Content-Type: text/plain;charset=utf-8" + CRLF
+        + "Content-length: 24" + CRLF
+        + CRLF
+        + "Frederic Fall MODIFIED" + CRLF
+        + CRLF
+        + "--batch_123--";
+
+    InputStream in = new ByteArrayInputStream(getResponse.getBytes());
+    BatchParser parser = new BatchParser("multipart/mixed;boundary=batch_123", true);
+    List<BatchSingleResponse> responses = parser.parseBatchResponse(in);
+    for (BatchSingleResponse response : responses) {
+      assertEquals("200", response.getStatusCode());
+      assertEquals("OK", response.getStatusInfo());
+      assertEquals("text/plain;charset=utf-8", response.getHeaders().get(HttpHeaders.CONTENT_TYPE));
+      assertEquals("24", response.getHeaders().get("Content-length"));
+      assertEquals("1", response.getContentId());
+      assertEquals("Frederic Fall MODIFIED\r\n", response.getBody());
+    }
+  }
+
+  @Test
+  public void testNoContentResponse() throws Exception {
+    String responseContent =
+        "--ejjeeffe1\r\n" +
+            "Content-Type: application/http\r\n" +
+            "Content-Length: 96\r\n" +
+            "content-transfer-encoding: binary\r\n" +
+            "\r\n" +
+            "HTTP/1.1 204 No Content\r\n" +
+            "Content-Type: text/html\r\n" +
+            "dataserviceversion: 2.0\r\n" +
+            "\r\n" +
+            "\r\n" +
+            "--ejjeeffe1--\r\n";
+
+    InputStream in = new ByteArrayInputStream(responseContent.getBytes());
+    BatchParser parser = new BatchParser("multipart/mixed;boundary=ejjeeffe1", true);
+    List<BatchSingleResponse> responses = parser.parseBatchResponse(in);
+    for (BatchSingleResponse response : responses) {
+      assertEquals("204", response.getStatusCode());
+      assertEquals("No Content", response.getStatusInfo());
+      assertEquals("text/html", response.getHeaders().get(HttpHeaders.CONTENT_TYPE));
     }
   }
 
@@ -119,7 +174,7 @@ public class BatchResponseParserTest {
   @Test
   public void testResponseToChangeSetNoContentButContentLength() throws BatchException {
     String putResponse =
-            "--batch_123" + CRLF
+        "--batch_123" + CRLF
             + "Content-Type: " + HttpContentType.MULTIPART_MIXED + ";boundary=changeset_12ks93js84d" + CRLF
             + CRLF
             + "--changeset_12ks93js84d" + CRLF

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/14c534ee/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchResponseTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchResponseTest.java b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchResponseTest.java
index 2f8b7f8..4076a25 100644
--- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchResponseTest.java
+++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchResponseTest.java
@@ -140,6 +140,6 @@ public class BatchResponseTest {
     StringHelper.Stream content = StringHelper.toStream(body);
     List<BatchSingleResponse> result = parser.parseBatchResponse(content.asStream());
     assertEquals(2, result.size());
-    assertEquals("Failing content:\n" + content.asString(), 20, content.linesCount());
+    assertEquals("Failing content:\n" + content.asString(), 19, content.linesCount());
   }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/14c534ee/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchResponseWriterITTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchResponseWriterITTest.java b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchResponseWriterITTest.java
new file mode 100644
index 0000000..df84f39
--- /dev/null
+++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchResponseWriterITTest.java
@@ -0,0 +1,179 @@
+/*******************************************************************************
+ * 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.core.batch;
+
+import static org.junit.Assert.*;
+
+import java.io.ByteArrayInputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.batch.BatchResponsePart;
+import org.apache.olingo.odata2.api.client.batch.BatchSingleResponse;
+import org.apache.olingo.odata2.api.commons.HttpHeaders;
+import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
+import org.apache.olingo.odata2.api.processor.ODataResponse;
+import org.apache.olingo.odata2.core.batch.v2.BatchParser;
+import org.apache.olingo.odata2.core.commons.ContentType;
+import org.junit.Test;
+
+public class BatchResponseWriterITTest {
+
+  @Test
+  public void testSimpleRequest() throws Exception {
+    // Create batch response
+    List<BatchResponsePart> parts = new ArrayList<BatchResponsePart>();
+    ODataResponse response =
+        ODataResponse.entity("Walter Winter").status(HttpStatusCodes.OK).contentHeader("application/json").build();
+    List<ODataResponse> responses = new ArrayList<ODataResponse>(1);
+    responses.add(response);
+    parts.add(BatchResponsePart.responses(responses).changeSet(false).build());
+    BatchResponseWriter writer = new BatchResponseWriter();
+    ODataResponse batchResponse = writer.writeResponse(parts);
+
+    assertEquals(202, batchResponse.getStatus().getStatusCode());
+    assertNotNull(batchResponse.getEntity());
+    String body = (String) batchResponse.getEntity();
+    // Get boundary
+    int lineEndingIndex = body.indexOf("\r\n");
+    String boundary = body.substring(2, lineEndingIndex);
+
+    // Parse response and test outputs
+    final BatchParser parser = new BatchParser("multipart/mixed;boundary=" + boundary, true);
+    List<BatchSingleResponse> parserResponses = parser.parseBatchResponse(new ByteArrayInputStream(body.getBytes()));
+    for (BatchSingleResponse parserResponse : parserResponses) {
+      assertEquals("200", parserResponse.getStatusCode());
+      assertEquals("OK", parserResponse.getStatusInfo());
+      assertEquals("application/json", parserResponse.getHeaders().get(HttpHeaders.CONTENT_TYPE));
+      assertEquals("13", parserResponse.getHeaders().get(HttpHeaders.CONTENT_LENGTH));
+      assertEquals("Walter Winter", parserResponse.getBody());
+    }
+  }
+
+  @Test
+  public void testNoContent() throws Exception {
+    // Create batch response
+    List<BatchResponsePart> parts = new ArrayList<BatchResponsePart>();
+    ODataResponse response =
+        ODataResponse.status(HttpStatusCodes.NO_CONTENT).build();
+    List<ODataResponse> responses = new ArrayList<ODataResponse>(1);
+    responses.add(response);
+    parts.add(BatchResponsePart.responses(responses).changeSet(false).build());
+    BatchResponseWriter writer = new BatchResponseWriter();
+    ODataResponse batchResponse = writer.writeResponse(parts);
+
+    assertEquals(202, batchResponse.getStatus().getStatusCode());
+    assertNotNull(batchResponse.getEntity());
+    String body = (String) batchResponse.getEntity();
+    // Get boundary
+    int lineEndingIndex = body.indexOf("\r\n");
+    String boundary = body.substring(2, lineEndingIndex);
+
+    // Parse response and test outputs
+    final BatchParser parser = new BatchParser("multipart/mixed;boundary=" + boundary, true);
+    List<BatchSingleResponse> parserResponses = parser.parseBatchResponse(new ByteArrayInputStream(body.getBytes()));
+    for (BatchSingleResponse parserResponse : parserResponses) {
+      assertEquals("204", parserResponse.getStatusCode());
+      assertEquals("No Content", parserResponse.getStatusInfo());
+    }
+  }
+
+  @Test
+  public void testChangeSet() throws Exception {
+    List<BatchResponsePart> parts = new ArrayList<BatchResponsePart>();
+    ODataResponse response = ODataResponse.entity("Walter Winter")
+        .status(HttpStatusCodes.OK)
+        .contentHeader("application/json")
+        .build();
+    List<ODataResponse> responses = new ArrayList<ODataResponse>(1);
+    responses.add(response);
+    parts.add(BatchResponsePart.responses(responses).changeSet(false).build());
+
+    ODataResponse changeSetResponse =
+        ODataResponse.status(HttpStatusCodes.NO_CONTENT).header(BatchHelper.MIME_HEADER_CONTENT_ID, "1").build();
+    responses = new ArrayList<ODataResponse>(2);
+    ODataResponse changeSetResponseEntity =
+        ODataResponse.status(HttpStatusCodes.OK).contentHeader(ContentType.APPLICATION_JSON.toContentTypeString())
+            .header(BatchHelper.MIME_HEADER_CONTENT_ID, "2")
+            .entity("Test\r\n").build();
+    ODataResponse changeSetResponseEntity2 =
+        ODataResponse.status(HttpStatusCodes.OK).contentHeader(ContentType.APPLICATION_JSON.toContentTypeString())
+            .header(BatchHelper.MIME_HEADER_CONTENT_ID, "2")
+            .entity("Test\n").build();
+    ODataResponse changeSetResponseEntity3 =
+        ODataResponse.status(HttpStatusCodes.OK).contentHeader(ContentType.APPLICATION_JSON.toContentTypeString())
+            .header(BatchHelper.MIME_HEADER_CONTENT_ID, "2")
+            .entity("Test").build();
+    responses.add(changeSetResponse);
+    responses.add(changeSetResponseEntity);
+    responses.add(changeSetResponseEntity2);
+    responses.add(changeSetResponseEntity3);
+
+    parts.add(BatchResponsePart.responses(responses).changeSet(true).build());
+
+    BatchResponseWriter writer = new BatchResponseWriter();
+    ODataResponse batchResponse = writer.writeResponse(parts);
+
+    assertEquals(202, batchResponse.getStatus().getStatusCode());
+    assertNotNull(batchResponse.getEntity());
+    String body = (String) batchResponse.getEntity();
+
+    // Get boundary
+    int lineEndingIndex = body.indexOf("\r\n");
+    String boundary = body.substring(2, lineEndingIndex);
+
+    // Parse response and test outputs
+    final BatchParser parser = new BatchParser("multipart/mixed;boundary=" + boundary, true);
+    List<BatchSingleResponse> parserResponses = parser.parseBatchResponse(new ByteArrayInputStream(body.getBytes()));
+    assertEquals(5, parserResponses.size());
+
+    BatchSingleResponse parserResponse = parserResponses.get(0);
+    assertEquals("200", parserResponse.getStatusCode());
+    assertEquals("OK", parserResponse.getStatusInfo());
+    assertEquals("application/json", parserResponse.getHeaders().get(HttpHeaders.CONTENT_TYPE));
+    assertEquals("13", parserResponse.getHeaders().get(HttpHeaders.CONTENT_LENGTH));
+    assertEquals("Walter Winter", parserResponse.getBody());
+
+    parserResponse = parserResponses.get(1);
+    assertEquals("204", parserResponse.getStatusCode());
+    assertEquals("1", parserResponse.getContentId());
+    assertEquals("No Content", parserResponse.getStatusInfo());
+
+    parserResponse = parserResponses.get(2);
+    assertEquals("200", parserResponse.getStatusCode());
+    assertEquals("OK", parserResponse.getStatusInfo());
+    assertEquals("application/json", parserResponse.getHeaders().get(HttpHeaders.CONTENT_TYPE));
+    assertEquals("6", parserResponse.getHeaders().get(HttpHeaders.CONTENT_LENGTH));
+    assertEquals("Test\r\n", parserResponse.getBody());
+
+    parserResponse = parserResponses.get(3);
+    assertEquals("200", parserResponse.getStatusCode());
+    assertEquals("OK", parserResponse.getStatusInfo());
+    assertEquals("application/json", parserResponse.getHeaders().get(HttpHeaders.CONTENT_TYPE));
+    assertEquals("5", parserResponse.getHeaders().get(HttpHeaders.CONTENT_LENGTH));
+    assertEquals("Test\n", parserResponse.getBody());
+
+    parserResponse = parserResponses.get(4);
+    assertEquals("200", parserResponse.getStatusCode());
+    assertEquals("OK", parserResponse.getStatusInfo());
+    assertEquals("application/json", parserResponse.getHeaders().get(HttpHeaders.CONTENT_TYPE));
+    assertEquals("4", parserResponse.getHeaders().get(HttpHeaders.CONTENT_LENGTH));
+    assertEquals("Test", parserResponse.getBody());
+  }
+}


[18/37] olingo-odata2 git commit: [OLINGO-193] Adapted RAT check for odata2-spring module

Posted by mi...@apache.org.
[OLINGO-193] Adapted RAT check for odata2-spring module


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

Branch: refs/heads/Olingo-129_PocJpaDataStore
Commit: 7a596e207e0292419447f11b1df792f1824ca432
Parents: 986b1c4
Author: Michael Bolz <mi...@sap.com>
Authored: Tue Dec 23 14:10:33 2014 +0100
Committer: Michael Bolz <mi...@sap.com>
Committed: Tue Dec 23 14:10:33 2014 +0100

----------------------------------------------------------------------
 pom.xml | 2 ++
 1 file changed, 2 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/7a596e20/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 67ae922..9ffc517 100644
--- a/pom.xml
+++ b/pom.xml
@@ -350,6 +350,8 @@
 										<exclude>**/NOTICE</exclude>
 										<exclude>**/DEPENDENCIES</exclude>
 										<exclude>**/goal.txt</exclude>
+										<exclude>**/target/**</exclude>
+										<exclude>**/*.iml</exclude>
 									</excludes>
 								</configuration>
 							</execution>


[15/37] olingo-odata2 git commit: [OLINGO-516] Adding the missed licence header to files

Posted by mi...@apache.org.
[OLINGO-516] Adding the missed licence header to files

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

Branch: refs/heads/Olingo-129_PocJpaDataStore
Commit: 88d2335e806275c8d8ac7073e1634edce9c98d13
Parents: 2636dd5
Author: Chandan V A <ch...@sap.com>
Authored: Sun Dec 21 10:58:36 2014 +0530
Committer: Chandan V A <ch...@sap.com>
Committed: Sun Dec 21 10:58:36 2014 +0530

----------------------------------------------------------------------
 .../processor/ref/util/CustomerImageLoader.java   | 18 ++++++++++++++++++
 .../ref/extension/CustomerImageProcessor.java     | 18 ++++++++++++++++++
 2 files changed, 36 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/88d2335e/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/util/CustomerImageLoader.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/util/CustomerImageLoader.java b/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/util/CustomerImageLoader.java
index 59403a5..e0a4841 100644
--- a/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/util/CustomerImageLoader.java
+++ b/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/util/CustomerImageLoader.java
@@ -1,3 +1,21 @@
+/*******************************************************************************
+ * 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.jpa.processor.ref.util;
 
 import java.io.ByteArrayOutputStream;

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/88d2335e/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/CustomerImageProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/CustomerImageProcessor.java b/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/CustomerImageProcessor.java
index d341290..f930c80 100644
--- a/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/CustomerImageProcessor.java
+++ b/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/CustomerImageProcessor.java
@@ -1,3 +1,21 @@
+/*******************************************************************************
+ * 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.jpa.processor.ref.extension;
 
 import org.apache.olingo.odata2.api.annotation.edm.EdmFacets;


[12/37] olingo-odata2 git commit: Child elemnents in custom annotations will be read correctly

Posted by mi...@apache.org.
Child elemnents in custom annotations will be read correctly

Signed-off-by: Christian Amend <ch...@apache.org>


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

Branch: refs/heads/Olingo-129_PocJpaDataStore
Commit: 9f39956a3e0b239069ea65b4444f83032e73dfb4
Parents: f40ea94
Author: Christian Holzer <c....@sap.com>
Authored: Thu Dec 18 22:27:45 2014 +0100
Committer: Christian Amend <ch...@apache.org>
Committed: Fri Dec 19 14:03:36 2014 +0100

----------------------------------------------------------------------
 .../core/ep/consumer/XmlMetadataConsumer.java   |  25 +++-
 .../ep/consumer/XmlMetadataConsumerTest.java    | 116 ++++++++++++++++++-
 2 files changed, 135 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/9f39956a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlMetadataConsumer.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlMetadataConsumer.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlMetadataConsumer.java
index 0cc25e8..b2e62b5 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlMetadataConsumer.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlMetadataConsumer.java
@@ -104,7 +104,7 @@ public class XmlMetadataConsumer {
               .getLocalName())) {
             dataServices.setDataServiceVersion(reader.getAttributeValue(Edm.NAMESPACE_M_2007_08, "DataServiceVersion"));
           }
-        } 
+        }
       }
 
       if (!reader.isEndElement() || !XmlMetadataConstants.EDMX_TAG.equals(reader.getLocalName())) {
@@ -870,17 +870,32 @@ public class XmlMetadataConsumer {
     if (!annotationAttributes.isEmpty()) {
       aElement.setAttributes(annotationAttributes);
     }
-    while (reader.hasNext() && !(reader.isEndElement() && aElement.getName() != null
-        && aElement.getName().equals(reader.getLocalName()))) {
+
+    boolean justRead = false;
+    if (reader.hasNext()) {
       reader.next();
+      justRead = true;
+    }
+
+    while (justRead && !(reader.isEndElement() && aElement.getName() != null
+        && aElement.getName().equals(reader.getLocalName()))) {
+      justRead = false;
       if (reader.isStartElement()) {
         annotationElements.add(readAnnotationElement(reader));
+        if (reader.hasNext()) {
+          reader.next();
+          justRead = true;
+        }
       } else if (reader.isCharacters()) {
         String elementText = "";
         do {
+          justRead = false;
           elementText = elementText + reader.getText();
-          reader.next();
-        } while (reader.isCharacters());
+          if (reader.hasNext()) {
+            reader.next();
+            justRead = true;
+          }
+        } while (justRead && reader.isCharacters());
         aElement.setText(elementText);
       }
     }

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/9f39956a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/consumer/XmlMetadataConsumerTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/consumer/XmlMetadataConsumerTest.java b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/consumer/XmlMetadataConsumerTest.java
index bab3454..da58246 100644
--- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/consumer/XmlMetadataConsumerTest.java
+++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/consumer/XmlMetadataConsumerTest.java
@@ -176,7 +176,121 @@ public class XmlMetadataConsumerTest extends AbstractXmlConsumerTest {
       + "<EntityType Name= \"Photo\"><Key><PropertyRef Name=\"Id\"/></Key><Property Name=\"Id\" Type=\"Edm.Int32\" " +
       "Nullable=\"false\" MaxLength=\"Max\"/><Property Name=\"Name\" Type=\"Edm.Int32\" MaxLength=\"max\"/>"
       + "</EntityType></Schema></edmx:DataServices></edmx:Edmx>";
-
+  
+  @Test
+  public void testMetadataDokumentWithWhitepaces() throws Exception {
+    final String metadata = ""
+        + "<edmx:Edmx Version=\"1.0\" xmlns:edmx=\"" + Edm.NAMESPACE_EDMX_2007_06 + "\">"
+        + "   <edmx:DataServices m:DataServiceVersion=\"2.0\" xmlns:m=\"" + Edm.NAMESPACE_M_2007_08 + "\">"
+        + "       <Schema Namespace=\"" + NAMESPACE2 + "\" xmlns=\"" + Edm.NAMESPACE_EDM_2008_09 + "\">"
+        + "           <EntityType Name= \"Photo\">"
+        + "               <Key> "
+        + "                 <PropertyRef Name=\"Id\" />"
+        + "               </Key>"
+        + "               <Property Name=\"Id\" Type=\"Edm.Int16\" Nullable=\"false\" />"
+        + "               <MyAnnotation xmlns=\"http://company.com/odata\">   "
+        + "                 <child> value1</child>"
+        + "                 <child>value2</child>"
+        + "               </MyAnnotation>"
+        + "           </EntityType>"
+        + "       </Schema>"
+        + "  </edmx:DataServices>"
+        + "</edmx:Edmx>";
+    
+    XmlMetadataConsumer parser = new XmlMetadataConsumer();
+    XMLStreamReader reader = createStreamReader(metadata);
+    DataServices result = parser.readMetadata(reader, true);
+    
+    assertEquals(1, result.getSchemas().size());
+    List<EntityType> entityTypes = result.getSchemas().get(0).getEntityTypes();
+    assertEquals(1, entityTypes.size());
+    EntityType entityType = entityTypes.get(0);
+    List<AnnotationElement> annotationElements = entityType.getAnnotationElements();
+    assertEquals(1, annotationElements.size());
+    AnnotationElement annotationElement = annotationElements.get(0);
+    List<AnnotationElement> childElements = annotationElement.getChildElements();
+    assertEquals(2, childElements.size());
+    
+    assertEquals(" value1", childElements.get(0).getText());
+    assertEquals("value2", childElements.get(1).getText());
+  }
+  
+  @Test
+  public void testMetadataDokumentWithWhitepacesMultiline() throws Exception {
+    final String metadata = ""
+        + "<edmx:Edmx Version=\"1.0\" xmlns:edmx=\"" + Edm.NAMESPACE_EDMX_2007_06 + "\">"
+        + "   <edmx:DataServices m:DataServiceVersion=\"2.0\" xmlns:m=\"" + Edm.NAMESPACE_M_2007_08 + "\">"
+        + "       <Schema Namespace=\"" + NAMESPACE2 + "\" xmlns=\"" + Edm.NAMESPACE_EDM_2008_09 + "\">"
+        + "           <EntityType Name= \"Photo\">"
+        + "               <Key> "
+        + "                 <PropertyRef Name=\"Id\" />"
+        + "               </Key>"
+        + "               <Property Name=\"Id\" Type=\"Edm.Int16\" Nullable=\"false\" />"
+        + "               <MyAnnotation xmlns=\"http://company.com/odata\">   "
+        + "                 <child> value1\n"
+        + "                 long long long multiline attribute</child>"
+        + "                 <child>value2</child>"
+        + "               </MyAnnotation>"
+        + "           </EntityType>"
+        + "       </Schema>"
+        + "  </edmx:DataServices>"
+        + "</edmx:Edmx>";
+    
+    XmlMetadataConsumer parser = new XmlMetadataConsumer();
+    XMLStreamReader reader = createStreamReader(metadata);
+    DataServices result = parser.readMetadata(reader, true);
+    
+    assertEquals(1, result.getSchemas().size());
+    List<EntityType> entityTypes = result.getSchemas().get(0).getEntityTypes();
+    assertEquals(1, entityTypes.size());
+    EntityType entityType = entityTypes.get(0);
+    List<AnnotationElement> annotationElements = entityType.getAnnotationElements();
+    assertEquals(1, annotationElements.size());
+    AnnotationElement annotationElement = annotationElements.get(0);
+    List<AnnotationElement> childElements = annotationElement.getChildElements();
+    assertEquals(2, childElements.size());
+    
+    assertEquals(" value1\n" + 
+        "                 long long long multiline attribute", childElements.get(0).getText());
+    assertEquals("value2", childElements.get(1).getText());
+  }
+  
+  @Test
+  public void testMetadataDokumentWithWhitepaces2() throws Exception {
+    final String metadata = ""
+        + "<edmx:Edmx Version=\"1.0\" xmlns:edmx=\"" + Edm.NAMESPACE_EDMX_2007_06 + "\">"
+        + "   <edmx:DataServices m:DataServiceVersion=\"2.0\" xmlns:m=\"" + Edm.NAMESPACE_M_2007_08 + "\">"
+        + "       <Schema Namespace=\"" + NAMESPACE2 + "\" xmlns=\"" + Edm.NAMESPACE_EDM_2008_09 + "\">"
+        + "           <EntityType Name= \"Photo\">"
+        + "               <Key> "
+        + "                 <PropertyRef Name=\"Id\" />"
+        + "               </Key>"
+        + "               <Property Name=\"Id\" Type=\"Edm.Int16\" Nullable=\"false\" />"
+        + "               <MyAnnotation xmlns=\"http://company.com/odata\">   "
+        + "                 <child> value1"
+        + "</child></MyAnnotation>"
+        + "           </EntityType>"
+        + "       </Schema>"
+        + "  </edmx:DataServices>"
+        + "</edmx:Edmx>";
+    
+    XmlMetadataConsumer parser = new XmlMetadataConsumer();
+    XMLStreamReader reader = createStreamReader(metadata);
+    DataServices result = parser.readMetadata(reader, true);
+    
+    assertEquals(1, result.getSchemas().size());
+    List<EntityType> entityTypes = result.getSchemas().get(0).getEntityTypes();
+    assertEquals(1, entityTypes.size());
+    EntityType entityType = entityTypes.get(0);
+    List<AnnotationElement> annotationElements = entityType.getAnnotationElements();
+    assertEquals(1, annotationElements.size());
+    AnnotationElement annotationElement = annotationElements.get(0);
+    List<AnnotationElement> childElements = annotationElement.getChildElements();
+    assertEquals(1, childElements.size());
+    
+    assertEquals(" value1", childElements.get(0).getText());
+  }
+  
   @Test
   public void stringValueForMaxLegthFacet() throws Exception {
     XmlMetadataConsumer parser = new XmlMetadataConsumer();


[08/37] olingo-odata2 git commit: [OLINGO-521] BatchResponseWriterTests and BatchRequestWriterTests improved

Posted by mi...@apache.org.
[OLINGO-521] BatchResponseWriterTests and BatchRequestWriterTests improved

Signed-off-by: Christian Amend <ch...@apache.org>


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

Branch: refs/heads/Olingo-129_PocJpaDataStore
Commit: 2186daa3164d714f8c01129bb76f80e80b81ab6d
Parents: 14c534e
Author: Christian Holzer <c....@sap.com>
Authored: Mon Dec 15 15:28:10 2014 +0100
Committer: Christian Amend <ch...@apache.org>
Committed: Tue Dec 16 16:13:19 2014 +0100

----------------------------------------------------------------------
 .../odata2/core/batch/BatchRequestWriter.java   |   3 +-
 .../odata2/core/batch/BatchRequestTest.java     |   8 +-
 .../core/batch/BatchRequestWriterTest.java      | 214 +++++++++++++------
 .../core/batch/BatchResponseParserTest.java     |  63 ++++++
 .../core/batch/BatchResponseWriterTest.java     | 128 +++++++----
 5 files changed, 304 insertions(+), 112 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/2186daa3/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/BatchRequestWriter.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/BatchRequestWriter.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/BatchRequestWriter.java
index 9ec21cd..85242c6 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/BatchRequestWriter.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/BatchRequestWriter.java
@@ -59,7 +59,6 @@ public class BatchRequestWriter {
             request.getContentId());
       }
       
-      writer.append(CRLF);  // CRLF belongs to the boundary delimiter or boundary closing delimiter
     }
     writer.append("--").append(boundary).append("--");
     InputStream batchRequestBody;
@@ -109,6 +108,8 @@ public class BatchRequestWriter {
 
     if (body != null && !body.isEmpty()) {
       writer.append(body);
+    } else {
+      writer.append(CRLF);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/2186daa3/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchRequestTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchRequestTest.java b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchRequestTest.java
index f526920..7898a2c 100644
--- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchRequestTest.java
+++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchRequestTest.java
@@ -101,7 +101,7 @@ public class BatchRequestTest {
     headers.put("content-type", "application/json");
     BatchChangeSetPart request = BatchChangeSetPart.method(PUT)
         .uri("Employees('2')")
-        .body("{\"Возра�т\":40}")
+        .body("{\"Возраст\":40}")
         .headers(headers)
         .contentId("111")
         .build();
@@ -121,8 +121,8 @@ public class BatchRequestTest {
     assertTrue(requestBody.contains("--batch_"));
     assertTrue(requestBody.contains("--changeset_"));
     assertTrue(requestBody.contains("PUT Employees('2') HTTP/1.1"));
-    assertTrue(requestBody.contains("{\"Возра�т\":40}"));
-    assertEquals(16, batchRequestStream.linesCount());
+    assertTrue(requestBody.contains("{\"Возраст\":40}"));
+    assertEquals(15, batchRequestStream.linesCount());
 
     String contentType = "multipart/mixed; boundary=" + BOUNDARY;
     BatchParser parser = new BatchParser(contentType, parseProperties, true);
@@ -162,7 +162,7 @@ public class BatchRequestTest {
     assertTrue(requestBody.contains("GET Employees HTTP/1.1"));
     assertTrue(requestBody.contains("POST Employees HTTP/1.1"));
     assertTrue(requestBody.contains(body));
-    assertEquals(25, batchRequestStream.linesCount());
+    assertEquals(24, batchRequestStream.linesCount());
 
     String contentType = "multipart/mixed; boundary=" + BOUNDARY;
     BatchParser parser = new BatchParser(contentType, parseProperties, true);

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/2186daa3/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchRequestWriterTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchRequestWriterTest.java b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchRequestWriterTest.java
index e8f7cd4..395c2b8 100644
--- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchRequestWriterTest.java
+++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchRequestWriterTest.java
@@ -19,7 +19,6 @@
 package org.apache.olingo.odata2.core.batch;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
 import java.io.IOException;
@@ -37,7 +36,6 @@ import org.apache.olingo.odata2.api.client.batch.BatchPart;
 import org.apache.olingo.odata2.api.client.batch.BatchQueryPart;
 import org.apache.olingo.odata2.core.batch.v2.BufferedReaderIncludingLineEndings;
 import org.apache.olingo.odata2.core.batch.v2.BufferedReaderIncludingLineEndings.Line;
-import org.apache.olingo.odata2.testutil.helper.StringHelper;
 import org.junit.Test;
 
 public class BatchRequestWriterTest {
@@ -48,11 +46,6 @@ public class BatchRequestWriterTest {
   private static final String BOUNDARY = "batch_123";
   private static final Object CRLF = "\r\n";
 
-  private void checkMimeHeaders(final String requestBody) {
-    assertTrue(requestBody.contains("Content-Type: application/http"));
-    assertTrue(requestBody.contains("Content-Transfer-Encoding: binary"));
-  }
-
   @Test
   public void testBatchQueryPart() throws BatchException, IOException {
     List<BatchPart> batch = new ArrayList<BatchPart>();
@@ -63,15 +56,22 @@ public class BatchRequestWriterTest {
 
     BatchRequestWriter writer = new BatchRequestWriter();
     InputStream batchRequest = writer.writeBatchRequest(batch, BOUNDARY);
-
-    String requestBody = StringHelper.toStream(batchRequest).asString();
-    assertNotNull(batchRequest);
-    checkMimeHeaders(requestBody);
-
-    assertTrue(requestBody.contains("--batch_"));
-    assertTrue(requestBody.contains("GET Employees HTTP/1.1"));
-    checkHeaders(headers, requestBody);
-    assertEquals(9, StringHelper.countLines(requestBody));
+    
+    BufferedReaderIncludingLineEndings reader =
+        new BufferedReaderIncludingLineEndings(new InputStreamReader(batchRequest));
+    List<Line> lines = reader.toList();
+    reader.close();
+    int index = 0;
+    
+    assertTrue(lines.get(index++).toString().startsWith("--batch"));
+    assertEquals("Content-Type: application/http" + CRLF, lines.get(index++).toString());
+    assertEquals("Content-Transfer-Encoding: binary" + CRLF, lines.get(index++).toString());
+    assertEquals(CRLF, lines.get(index++).toString());
+    assertEquals("GET Employees HTTP/1.1" + CRLF, lines.get(index++).toString());
+    assertEquals("Accept: application/json" + CRLF, lines.get(index++).toString());
+    assertEquals(CRLF, lines.get(index++).toString());
+    assertEquals(CRLF, lines.get(index++).toString());
+    assertTrue(lines.get(index++).toString().startsWith("--batch"));
   }
 
   @Test
@@ -81,7 +81,7 @@ public class BatchRequestWriterTest {
     headers.put("content-type", "application/json");
     BatchChangeSetPart request = BatchChangeSetPart.method(PUT)
         .uri("Employees('2')")
-        .body("{\"Возраст\":40}")
+        .body("{\"Age\":40}")
         .headers(headers)
         .contentId("111")
         .build();
@@ -92,15 +92,27 @@ public class BatchRequestWriterTest {
     BatchRequestWriter writer = new BatchRequestWriter();
     InputStream batchRequest = writer.writeBatchRequest(batch, BOUNDARY);
 
-    String requestBody = StringHelper.inputStreamToString(batchRequest, true);
-    assertNotNull(batchRequest);
-    checkMimeHeaders(requestBody);
-    checkHeaders(headers, requestBody);
-
-    assertTrue(requestBody.contains("--batch_"));
-    assertTrue(requestBody.contains("--changeset_"));
-    assertTrue(requestBody.contains("PUT Employees('2') HTTP/1.1"));
-    assertTrue(requestBody.contains("{\"Возраст\":40}"));
+    BufferedReaderIncludingLineEndings reader =
+        new BufferedReaderIncludingLineEndings(new InputStreamReader(batchRequest));
+    List<Line> lines = reader.toList();
+    reader.close();
+    int index = 0;
+     
+    assertTrue(lines.get(index++).toString().startsWith("--batch"));
+    assertTrue(lines.get(index++).toString().startsWith("Content-Type: multipart/mixed; boundary=changeset_"));
+    assertEquals(CRLF, lines.get(index++).toString());
+    assertTrue(lines.get(index++).toString().startsWith("--changeset"));
+    assertEquals("Content-Type: application/http" + CRLF, lines.get(index++).toString());
+    assertEquals("Content-Transfer-Encoding: binary" + CRLF, lines.get(index++).toString());
+    assertEquals("Content-Id: 111" + CRLF, lines.get(index++).toString());
+    assertEquals(CRLF, lines.get(index++).toString());
+    assertEquals("PUT Employees('2') HTTP/1.1" + CRLF, lines.get(index++).toString());
+    assertEquals("Content-Length: 10" + CRLF, lines.get(index++).toString());
+    assertEquals("content-type: application/json" + CRLF, lines.get(index++).toString());
+    assertEquals(CRLF, lines.get(index++).toString());
+    assertEquals("{\"Age\":40}" + CRLF, lines.get(index++).toString());
+    assertTrue(lines.get(index++).toString().startsWith("--changeset"));
+    assertTrue(lines.get(index++).toString().startsWith("--batch"));
   }
 
   @Test
@@ -126,15 +138,37 @@ public class BatchRequestWriterTest {
     BatchRequestWriter writer = new BatchRequestWriter();
     InputStream batchRequest = writer.writeBatchRequest(batch, BOUNDARY);
 
-    String requestBody = StringHelper.inputStreamToString(batchRequest, true);
-    assertNotNull(batchRequest);
-    checkMimeHeaders(requestBody);
-
-    checkHeaders(headers, requestBody);
-    checkHeaders(changeSetHeaders, requestBody);
-    assertTrue(requestBody.contains("GET Employees HTTP/1.1"));
-    assertTrue(requestBody.contains("POST Employees HTTP/1.1"));
-    assertTrue(requestBody.contains(body));
+    BufferedReaderIncludingLineEndings reader =
+        new BufferedReaderIncludingLineEndings(new InputStreamReader(batchRequest));
+    List<Line> lines = reader.toList();
+    reader.close();
+    int index = 0;
+
+    assertTrue(lines.get(index++).toString().startsWith("--batch"));
+    assertEquals("Content-Type: application/http" + CRLF, lines.get(index++).toString());
+    assertEquals("Content-Transfer-Encoding: binary" + CRLF, lines.get(index++).toString());
+    assertEquals("Content-Id: 000" + CRLF, lines.get(index++).toString());
+    assertEquals(CRLF, lines.get(index++).toString());
+    assertEquals("GET Employees HTTP/1.1" + CRLF, lines.get(index++).toString());
+    assertEquals("Accept: application/json" + CRLF, lines.get(index++).toString());
+    assertEquals(CRLF, lines.get(index++).toString());
+    assertEquals(CRLF, lines.get(index++).toString());
+    
+    assertTrue(lines.get(index++).toString().startsWith("--batch"));
+    assertTrue(lines.get(index++).toString().startsWith("Content-Type: multipart/mixed; boundary=changeset_"));
+    assertEquals(CRLF, lines.get(index++).toString());
+    assertTrue(lines.get(index++).toString().startsWith("--changeset"));
+    assertEquals("Content-Type: application/http" + CRLF, lines.get(index++).toString());
+    assertEquals("Content-Transfer-Encoding: binary" + CRLF, lines.get(index++).toString());
+    assertEquals("Content-Id: 111" + CRLF, lines.get(index++).toString());
+    assertEquals(CRLF, lines.get(index++).toString());
+    assertEquals("POST Employees HTTP/1.1" + CRLF, lines.get(index++).toString());
+    assertEquals("Content-Length: 68" + CRLF, lines.get(index++).toString());
+    assertEquals("content-type: application/json" + CRLF, lines.get(index++).toString());
+    assertEquals(CRLF, lines.get(index++).toString());
+    assertEquals(body + CRLF, lines.get(index++).toString());
+    assertTrue(lines.get(index++).toString().startsWith("--changeset"));
+    assertTrue(lines.get(index++).toString().startsWith("--batch"));
   }
 
   @Test
@@ -150,12 +184,12 @@ public class BatchRequestWriterTest {
 
     BatchRequestWriter writer = new BatchRequestWriter();
     InputStream batchRequest = writer.writeBatchRequest(batch, BOUNDARY);
-    
+
     BufferedReaderIncludingLineEndings reader =
         new BufferedReaderIncludingLineEndings(new InputStreamReader(batchRequest));
     List<Line> lines = reader.toList();
     reader.close();
-    
+
     int line = 0;
     assertEquals("--" + BOUNDARY + CRLF, lines.get(line++).toString());
     assertEquals("Content-Type: application/http" + CRLF, lines.get(line++).toString());
@@ -164,9 +198,9 @@ public class BatchRequestWriterTest {
     assertEquals(CRLF, lines.get(line++).toString());
     assertEquals("GET Employees HTTP/1.1" + CRLF, lines.get(line++).toString());
     assertEquals("Accept: application/json" + CRLF, lines.get(line++).toString());
-    assertEquals(CRLF, lines.get(line++).toString());   // Belongs to the GET request [OData Protocol - 2.2.7.2.1]
-    
-    assertEquals(CRLF, lines.get(line++).toString());   // Belongs conceptually to the boundary [RFC 2046 - 5.1.1]
+    assertEquals(CRLF, lines.get(line++).toString()); // Belongs to the GET request [OData Protocol - 2.2.7.2.1]
+
+    assertEquals(CRLF, lines.get(line++).toString()); // Belongs conceptually to the boundary [RFC 2046 - 5.1.1]
     assertEquals("--" + BOUNDARY + CRLF, lines.get(line++).toString());
     assertEquals("Content-Type: application/http" + CRLF, lines.get(line++).toString());
     assertEquals("Content-Transfer-Encoding: binary" + CRLF, lines.get(line++).toString());
@@ -174,9 +208,9 @@ public class BatchRequestWriterTest {
     assertEquals(CRLF, lines.get(line++).toString());
     assertEquals("GET Employees HTTP/1.1" + CRLF, lines.get(line++).toString());
     assertEquals("Accept: application/json" + CRLF, lines.get(line++).toString());
-    assertEquals(CRLF, lines.get(line++).toString());   // Belongs to the GET request [OData Protocol - 2.2.7.2.1]
-    
-    assertEquals(CRLF, lines.get(line++).toString());   // Belongs conceptually to the boundary [RFC 2046 - 5.1.1]
+    assertEquals(CRLF, lines.get(line++).toString()); // Belongs to the GET request [OData Protocol - 2.2.7.2.1]
+
+    assertEquals(CRLF, lines.get(line++).toString()); // Belongs conceptually to the boundary [RFC 2046 - 5.1.1]
     assertEquals("--" + BOUNDARY + "--", lines.get(line++).toString());
     assertEquals(19, lines.size());
   }
@@ -200,7 +234,7 @@ public class BatchRequestWriterTest {
     changeSetHeaders = new HashMap<String, String>();
     changeSetHeaders.put("content-type", "application/json;odata=verbose");
     BatchChangeSetPart changeRequest2 = BatchChangeSetPart.method(PUT)
-        .uri("$/ManagerId")
+        .uri("$1/ManagerId")
         .body("{\"ManagerId\":1}")
         .headers(changeSetHeaders)
         .contentId("2")
@@ -211,16 +245,39 @@ public class BatchRequestWriterTest {
     BatchRequestWriter writer = new BatchRequestWriter();
     InputStream batchRequest = writer.writeBatchRequest(batch, BOUNDARY);
 
-    String requestBody = StringHelper.inputStreamToString(batchRequest);
-    assertNotNull(batchRequest);
-    checkMimeHeaders(requestBody);
-
-    assertTrue(requestBody.contains("POST Employees('2') HTTP/1.1"));
-    assertTrue(requestBody.contains("PUT $/ManagerId HTTP/1.1"));
-    assertTrue(requestBody.contains(BatchHelper.HTTP_CONTENT_ID + ": 1"));
-    assertTrue(requestBody.contains(BatchHelper.HTTP_CONTENT_ID + ": 2"));
-    assertTrue(requestBody.contains(body));
+    BufferedReaderIncludingLineEndings reader =
+        new BufferedReaderIncludingLineEndings(new InputStreamReader(batchRequest));
+    List<Line> lines = reader.toList();
+    reader.close();
 
+    int index = 0;
+    assertTrue(lines.get(index++).toString().startsWith("--batch"));
+    assertTrue(lines.get(index++).toString().startsWith("Content-Type: multipart/mixed; boundary=changeset_"));
+    assertEquals(CRLF, lines.get(index++).toString());
+    assertTrue(lines.get(index++).toString().startsWith("--changeset"));
+    assertEquals("Content-Type: application/http" + CRLF, lines.get(index++).toString());
+    assertEquals("Content-Transfer-Encoding: binary" + CRLF, lines.get(index++).toString());
+    assertEquals("Content-Id: 1" + CRLF, lines.get(index++).toString());
+    assertEquals(CRLF, lines.get(index++).toString());
+    assertEquals("POST Employees('2') HTTP/1.1" + CRLF, lines.get(index++).toString());
+    assertEquals("Content-Length: 68" + CRLF, lines.get(index++).toString());
+    assertEquals("content-type: application/json" + CRLF, lines.get(index++).toString());
+    assertEquals(CRLF, lines.get(index++).toString());
+    assertEquals(body + CRLF, lines.get(index++).toString());
+    
+    assertTrue(lines.get(index++).toString().startsWith("--changeset"));
+    assertEquals("Content-Type: application/http" + CRLF, lines.get(index++).toString());
+    assertEquals("Content-Transfer-Encoding: binary" + CRLF, lines.get(index++).toString());
+    assertEquals("Content-Id: 2" + CRLF, lines.get(index++).toString());
+    assertEquals(CRLF, lines.get(index++).toString());
+    assertEquals("PUT $1/ManagerId HTTP/1.1" + CRLF, lines.get(index++).toString());
+    assertEquals("Content-Length: 15" + CRLF, lines.get(index++).toString());
+    assertEquals("content-type: application/json;odata=verbose" + CRLF, lines.get(index++).toString());
+    assertEquals(CRLF, lines.get(index++).toString());
+    assertEquals("{\"ManagerId\":1}" + CRLF, lines.get(index++).toString());
+    
+    assertTrue(lines.get(index++).toString().startsWith("--changeset"));
+    assertTrue(lines.get(index++).toString().startsWith("--batch"));
   }
 
   @Test
@@ -254,22 +311,43 @@ public class BatchRequestWriterTest {
 
     BatchRequestWriter writer = new BatchRequestWriter();
     InputStream batchRequest = writer.writeBatchRequest(batch, BOUNDARY);
+    
+    BufferedReaderIncludingLineEndings reader =
+        new BufferedReaderIncludingLineEndings(new InputStreamReader(batchRequest));
+    List<Line> lines = reader.toList();
+    reader.close();
 
-    String requestBody = StringHelper.inputStreamToString(batchRequest);
-    assertNotNull(batchRequest);
-    checkMimeHeaders(requestBody);
-
-    assertTrue(requestBody.contains("POST Employees HTTP/1.1"));
-    assertTrue(requestBody.contains("PUT Employees('2')/ManagerId HTTP/1.1"));
-
-    assertTrue(requestBody.contains(body));
-
-  }
-
-  private void checkHeaders(final Map<String, String> headers, final String requestBody) {
-    for (Map.Entry<String, String> header : headers.entrySet()) {
-      assertTrue(requestBody.contains(header.getKey() + ": " + header.getValue()));
-    }
+    int index = 0;
+    assertTrue(lines.get(index++).toString().startsWith("--batch"));
+    assertTrue(lines.get(index++).toString().startsWith("Content-Type: multipart/mixed; boundary=changeset_"));
+    assertEquals(CRLF, lines.get(index++).toString());
+    assertTrue(lines.get(index++).toString().startsWith("--changeset"));
+    assertEquals("Content-Type: application/http" + CRLF, lines.get(index++).toString());
+    assertEquals("Content-Transfer-Encoding: binary" + CRLF, lines.get(index++).toString());
+    assertEquals(CRLF, lines.get(index++).toString());
+    assertEquals("POST Employees HTTP/1.1" + CRLF, lines.get(index++).toString());
+    assertEquals("Content-Length: 68" + CRLF, lines.get(index++).toString());
+    assertEquals("content-type: application/json" + CRLF, lines.get(index++).toString());
+    assertEquals("content-Id: 111" + CRLF, lines.get(index++).toString());
+    assertEquals(CRLF, lines.get(index++).toString());
+    assertEquals(body + CRLF, lines.get(index++).toString());
+    assertTrue(lines.get(index++).toString().startsWith("--changeset"));
+    
+    assertTrue(lines.get(index++).toString().startsWith("--batch"));
+    assertTrue(lines.get(index++).toString().startsWith("Content-Type: multipart/mixed; boundary=changeset_"));
+    assertEquals(CRLF, lines.get(index++).toString());
+    assertTrue(lines.get(index++).toString().startsWith("--changeset"));
+    assertEquals("Content-Type: application/http" + CRLF, lines.get(index++).toString());
+    assertEquals("Content-Transfer-Encoding: binary" + CRLF, lines.get(index++).toString());
+    assertEquals(CRLF, lines.get(index++).toString());
+    assertEquals("PUT Employees('2')/ManagerId HTTP/1.1" + CRLF, lines.get(index++).toString());
+    assertEquals("Content-Length: 15" + CRLF, lines.get(index++).toString());
+    assertEquals("content-type: application/json;odata=verbose" + CRLF, lines.get(index++).toString());
+    assertEquals("content-Id: 222" + CRLF, lines.get(index++).toString());
+    assertEquals(CRLF, lines.get(index++).toString());
+    assertEquals("{\"ManagerId\":1}" + CRLF, lines.get(index++).toString());
+    assertTrue(lines.get(index++).toString().startsWith("--changeset"));
+    assertTrue(lines.get(index++).toString().startsWith("--batch"));
   }
 
   @Test(expected = IllegalArgumentException.class)

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/2186daa3/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchResponseParserTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchResponseParserTest.java b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchResponseParserTest.java
index e107db5..dacdb5a 100644
--- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchResponseParserTest.java
+++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchResponseParserTest.java
@@ -170,7 +170,70 @@ public class BatchResponseParserTest {
       assertEquals("1", response.getContentId());
     }
   }
+  
+  @Test
+  public void testResponseChangeSetBodyWithoutCRLF() throws BatchException {
+    String putResponse = "--batch_123" + CRLF
+        + "Content-Type: " + HttpContentType.MULTIPART_MIXED + ";boundary=changeset_12ks93js84d" + CRLF
+        + CRLF
+        + "--changeset_12ks93js84d" + CRLF
+        + "Content-Type: application/http" + CRLF
+        + "Content-Transfer-Encoding: binary" + CRLF
+        + "Content-ID: 1" + CRLF
+        + CRLF
+        + "HTTP/1.1 200 Ok" + CRLF
+        + "DataServiceVersion: 2.0" + CRLF
+        + "Content-Length: 19" + CRLF
+        + CRLF
+        + "TestBodyWithoutCRLF" + CRLF
+        + "--changeset_12ks93js84d--" + CRLF
+        + CRLF
+        + "--batch_123--";
+
+    InputStream in = new ByteArrayInputStream(putResponse.getBytes());
+    BatchParser parser = new BatchParser("multipart/mixed;boundary=batch_123", true);
+    List<BatchSingleResponse> responses = parser.parseBatchResponse(in);
+    for (BatchSingleResponse response : responses) {
+      assertEquals("200", response.getStatusCode());
+      assertEquals("Ok", response.getStatusInfo());
+      assertEquals("19", response.getHeader(HttpHeaders.CONTENT_LENGTH));
+      assertEquals("TestBodyWithoutCRLF", response.getBody());
+      assertEquals("1", response.getContentId());
+    }
+  }
+  
+  @Test
+  public void testResponseChangeSetBodyWithCRLF() throws BatchException {
+    String putResponse = "--batch_123" + CRLF
+        + "Content-Type: " + HttpContentType.MULTIPART_MIXED + ";boundary=changeset_12ks93js84d" + CRLF
+        + CRLF
+        + "--changeset_12ks93js84d" + CRLF
+        + "Content-Type: application/http" + CRLF
+        + "Content-Transfer-Encoding: binary" + CRLF
+        + "Content-ID: 1" + CRLF
+        + CRLF
+        + "HTTP/1.1 200 Ok" + CRLF
+        + "DataServiceVersion: 2.0" + CRLF
+        + "Content-Length: 18" + CRLF
+        + CRLF
+        + "TestBodyWithCRLF" + CRLF
+        + CRLF
+        + "--changeset_12ks93js84d--" + CRLF
+        + CRLF
+        + "--batch_123--";
 
+    InputStream in = new ByteArrayInputStream(putResponse.getBytes());
+    BatchParser parser = new BatchParser("multipart/mixed;boundary=batch_123", true);
+    List<BatchSingleResponse> responses = parser.parseBatchResponse(in);
+    for (BatchSingleResponse response : responses) {
+      assertEquals("200", response.getStatusCode());
+      assertEquals("Ok", response.getStatusInfo());
+      assertEquals("18", response.getHeader(HttpHeaders.CONTENT_LENGTH));
+      assertEquals("TestBodyWithCRLF" + CRLF, response.getBody());
+      assertEquals("1", response.getContentId());
+    }
+  }
+  
   @Test
   public void testResponseToChangeSetNoContentButContentLength() throws BatchException {
     String putResponse =

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/2186daa3/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchResponseWriterTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchResponseWriterTest.java b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchResponseWriterTest.java
index cc58159..ecc5e93 100644
--- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchResponseWriterTest.java
+++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchResponseWriterTest.java
@@ -19,11 +19,12 @@
 package org.apache.olingo.odata2.core.batch;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
+import java.io.ByteArrayInputStream;
 import java.io.IOException;
+import java.io.InputStreamReader;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -31,10 +32,14 @@ import org.apache.olingo.odata2.api.batch.BatchException;
 import org.apache.olingo.odata2.api.batch.BatchResponsePart;
 import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
 import org.apache.olingo.odata2.api.processor.ODataResponse;
+import org.apache.olingo.odata2.core.batch.v2.BufferedReaderIncludingLineEndings;
+import org.apache.olingo.odata2.core.batch.v2.BufferedReaderIncludingLineEndings.Line;
 import org.junit.Test;
 
 public class BatchResponseWriterTest {
 
+  private static final String CRLF = "\r\n";
+
   @Test
   public void testBatchResponse() throws BatchException, IOException {
     List<BatchResponsePart> parts = new ArrayList<BatchResponsePart>();
@@ -57,16 +62,35 @@ public class BatchResponseWriterTest {
     assertEquals(202, batchResponse.getStatus().getStatusCode());
     assertNotNull(batchResponse.getEntity());
     String body = (String) batchResponse.getEntity();
-    
-    assertTrue(body.contains("--batch"));
-    assertTrue(body.contains("--changeset"));
-    assertTrue(body.contains("HTTP/1.1 200 OK"));
-    assertTrue(body.contains("Content-Type: application/http"));
-    assertTrue(body.contains("Content-Transfer-Encoding: binary"));
-    assertTrue(body.contains("Walter Winter"));
-    assertTrue(body.contains("multipart/mixed; boundary=changeset"));
-    assertTrue(body.contains("HTTP/1.1 204 No Content"));
 
+    BufferedReaderIncludingLineEndings reader =
+        new BufferedReaderIncludingLineEndings(new InputStreamReader(new ByteArrayInputStream(body.getBytes())));
+    List<Line> lines = reader.toList();
+    reader.close();
+    int index = 0;
+
+    assertTrue(lines.get(index++).toString().startsWith("--batch"));
+    assertEquals("Content-Type: application/http" + CRLF, lines.get(index++).toString());
+    assertEquals("Content-Transfer-Encoding: binary" + CRLF, lines.get(index++).toString());
+    assertEquals(CRLF, lines.get(index++).toString());
+    assertEquals("HTTP/1.1 200 OK" + CRLF, lines.get(index++).toString());
+    assertEquals("Content-Type: application/json" + CRLF, lines.get(index++).toString());
+    assertEquals("Content-Length: 13" + CRLF, lines.get(index++).toString());
+    assertEquals(CRLF, lines.get(index++).toString());
+    assertEquals("Walter Winter" + CRLF, lines.get(index++).toString());
+    
+    assertTrue(lines.get(index++).toString().startsWith("--batch"));
+    assertTrue(lines.get(index++).toString().startsWith("Content-Type: multipart/mixed; boundary=changeset_"));
+    assertEquals(CRLF, lines.get(index++).toString());
+    assertTrue(lines.get(index++).toString().startsWith("--changeset"));
+    assertEquals("Content-Type: application/http" + CRLF, lines.get(index++).toString());
+    assertEquals("Content-Transfer-Encoding: binary" + CRLF, lines.get(index++).toString());
+    assertEquals(CRLF, lines.get(index++).toString());
+    assertEquals("HTTP/1.1 204 No Content" + CRLF, lines.get(index++).toString());
+    assertEquals(CRLF, lines.get(index++).toString());
+    assertEquals(CRLF, lines.get(index++).toString());
+    assertTrue(lines.get(index++).toString().startsWith("--changeset"));
+    assertTrue(lines.get(index++).toString().startsWith("--batch"));
   }
 
   @Test
@@ -83,15 +107,23 @@ public class BatchResponseWriterTest {
     assertEquals(202, batchResponse.getStatus().getStatusCode());
     assertNotNull(batchResponse.getEntity());
     String body = (String) batchResponse.getEntity();
-
-    assertTrue(body.contains("--batch"));
-    assertFalse(body.contains("--changeset"));
-    assertTrue(body.contains("HTTP/1.1 200 OK" + "\r\n"));
-    assertTrue(body.contains("Content-Type: application/http" + "\r\n"));
-    assertTrue(body.contains("Content-Transfer-Encoding: binary" + "\r\n"));
-    assertTrue(body.contains("Walter Winter"));
-    assertFalse(body.contains("multipart/mixed; boundary=changeset"));
-
+    
+    BufferedReaderIncludingLineEndings reader =
+        new BufferedReaderIncludingLineEndings(new InputStreamReader(new ByteArrayInputStream(body.getBytes())));
+    List<Line> lines = reader.toList();
+    reader.close();
+    int index = 0;
+    
+    assertTrue(lines.get(index++).toString().startsWith("--batch"));
+    assertEquals("Content-Type: application/http" + CRLF, lines.get(index++).toString());
+    assertEquals("Content-Transfer-Encoding: binary" + CRLF, lines.get(index++).toString());
+    assertEquals(CRLF, lines.get(index++).toString());
+    assertEquals("HTTP/1.1 200 OK" + CRLF, lines.get(index++).toString());
+    assertEquals("Content-Type: application/json" + CRLF, lines.get(index++).toString());
+    assertEquals("Content-Length: 13" + CRLF, lines.get(index++).toString());
+    assertEquals(CRLF, lines.get(index++).toString());
+    assertEquals("Walter Winter" + CRLF, lines.get(index++).toString());
+    assertTrue(lines.get(index++).toString().startsWith("--batch"));
   }
 
   @Test
@@ -108,15 +140,25 @@ public class BatchResponseWriterTest {
     assertEquals(202, batchResponse.getStatus().getStatusCode());
     assertNotNull(batchResponse.getEntity());
     String body = (String) batchResponse.getEntity();
-    assertTrue(body.contains("--batch"));
-    assertTrue(body.contains("--changeset"));
-    assertTrue(body.indexOf("--changeset") != body.lastIndexOf("--changeset"));
-    assertFalse(body.contains("HTTP/1.1 200 OK" + "\r\n"));
-    assertTrue(body.contains("Content-Type: application/http" + "\r\n"));
-    assertTrue(body.contains("Content-Transfer-Encoding: binary" + "\r\n"));
-    assertTrue(body.contains("HTTP/1.1 204 No Content" + "\r\n"));
-    assertTrue(body.contains("Content-Type: multipart/mixed; boundary=changeset"));
-
+    
+    BufferedReaderIncludingLineEndings reader =
+        new BufferedReaderIncludingLineEndings(new InputStreamReader(new ByteArrayInputStream(body.getBytes())));
+    List<Line> lines = reader.toList();
+    reader.close();
+    int index = 0;
+    
+    assertTrue(lines.get(index++).toString().startsWith("--batch"));
+    assertTrue(lines.get(index++).toString().startsWith("Content-Type: multipart/mixed; boundary=changeset_"));
+    assertEquals(CRLF, lines.get(index++).toString());
+    assertTrue(lines.get(index++).toString().startsWith("--changeset"));
+    assertEquals("Content-Type: application/http" + CRLF, lines.get(index++).toString());
+    assertEquals("Content-Transfer-Encoding: binary" + CRLF, lines.get(index++).toString());
+    assertEquals(CRLF, lines.get(index++).toString());
+    assertEquals("HTTP/1.1 204 No Content" + CRLF, lines.get(index++).toString());
+    assertEquals(CRLF, lines.get(index++).toString());
+    assertEquals(CRLF, lines.get(index++).toString());
+    assertTrue(lines.get(index++).toString().startsWith("--changeset"));
+    assertTrue(lines.get(index++).toString().startsWith("--batch"));
   }
 
   @Test
@@ -137,17 +179,25 @@ public class BatchResponseWriterTest {
     assertEquals(202, batchResponse.getStatus().getStatusCode());
     assertNotNull(batchResponse.getEntity());
     String body = (String) batchResponse.getEntity();
-
-    String mimeHeader = "Content-Type: application/http" + "\r\n"
-        + "Content-Transfer-Encoding: binary" + "\r\n"
-        + "Content-Id: mimeHeaderContentId123" + "\r\n";
-
-    String requestHeader = "Content-Id: requestHeaderContentId123" + "\r\n"
-        + "Content-Type: application/json" + "\r\n"
-        + "Content-Length: 13" + "\r\n";
-
-    assertTrue(body.contains(mimeHeader));
-    assertTrue(body.contains(requestHeader));
+    
+    BufferedReaderIncludingLineEndings reader =
+        new BufferedReaderIncludingLineEndings(new InputStreamReader(new ByteArrayInputStream(body.getBytes())));
+    List<Line> lines = reader.toList();
+    reader.close();
+    int index = 0;
+
+    assertTrue(lines.get(index++).toString().startsWith("--batch"));
+    assertEquals("Content-Type: application/http" + CRLF, lines.get(index++).toString());
+    assertEquals("Content-Transfer-Encoding: binary" + CRLF, lines.get(index++).toString());
+    assertEquals("Content-Id: mimeHeaderContentId123" + CRLF, lines.get(index++).toString());
+    assertEquals(CRLF, lines.get(index++).toString());
+    assertEquals("HTTP/1.1 200 OK" + CRLF, lines.get(index++).toString());
+    assertEquals("Content-Id: requestHeaderContentId123" + CRLF, lines.get(index++).toString());
+    assertEquals("Content-Type: application/json" + CRLF, lines.get(index++).toString());
+    assertEquals("Content-Length: 13" + CRLF, lines.get(index++).toString());
+    assertEquals(CRLF, lines.get(index++).toString());
+    assertEquals("Walter Winter" + CRLF, lines.get(index++).toString());
+    assertTrue(lines.get(index++).toString().startsWith("--batch"));
   }
 
 }


[06/37] olingo-odata2 git commit: [OLINGO-508] Fixed OneToMany self reference

Posted by mi...@apache.org.
[OLINGO-508] Fixed OneToMany self reference


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

Branch: refs/heads/Olingo-129_PocJpaDataStore
Commit: 6f7b76f689e4a8c8889c59760715c80d4a4c17f2
Parents: 4bab6aa
Author: mibo <mi...@mirb.de>
Authored: Sat Dec 13 16:50:52 2014 +0100
Committer: mibo <mi...@mirb.de>
Committed: Sat Dec 13 16:50:52 2014 +0100

----------------------------------------------------------------------
 .../core/edm/AnnotationEdmProvider.java         |  39 +++--
 .../processor/core/util/AnnotationHelper.java   | 170 ++++++++++++++-----
 .../processor/core/util/ClassHelper.java        |  16 ++
 .../core/edm/AnnotationEdmProviderTest.java     |  36 ++--
 .../annotation/processor/core/model/Team.java   |   6 +
 .../core/util/AnnotationHelperTest.java         |  22 ++-
 .../ref/AnnotationRefServiceFactory.java        |   7 +-
 .../annotation/processor/ref/model/Team.java    |  10 ++
 .../annotation/processor/ref/MetadataTest.java  |  48 +++---
 9 files changed, 250 insertions(+), 104 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/6f7b76f6/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/edm/AnnotationEdmProvider.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/edm/AnnotationEdmProvider.java b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/edm/AnnotationEdmProvider.java
index 8b6e7f6..81546a7 100644
--- a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/edm/AnnotationEdmProvider.java
+++ b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/edm/AnnotationEdmProvider.java
@@ -374,9 +374,13 @@ public class AnnotationEdmProvider extends EdmProvider {
         }
         EdmNavigationProperty enp = field.getAnnotation(EdmNavigationProperty.class);
         if (enp != null) {
-          final NavigationProperty navProperty = createNavigationProperty(namespace, enp, field);
+          Class<?> fromClass = field.getDeclaringClass();
+          Class<?> toClass = ClassHelper.getFieldType(field);
+          AnnotationHelper.AnnotatedNavInfo info = ANNOTATION_HELPER.getCommonNavigationInfo(fromClass, toClass);
+
+          final NavigationProperty navProperty = createNavigationProperty(namespace, field, info);
           navProperties.add(navProperty);
-          Association association = createAssociation(field, navProperty);
+          Association association = createAssociation(info);
           associations.add(association);
         }
         EdmMediaResourceContent emrc = field.getAnnotation(EdmMediaResourceContent.class);
@@ -498,17 +502,15 @@ public class AnnotationEdmProvider extends EdmProvider {
       return cp;
     }
 
-    private NavigationProperty createNavigationProperty(final String namespace, final EdmNavigationProperty enp,
-        final Field field) {
+    private NavigationProperty createNavigationProperty(final String namespace, Field field,
+                                                        AnnotationHelper.AnnotatedNavInfo navInfo) {
       NavigationProperty navProp = new NavigationProperty();
       navProp.setName(ANNOTATION_HELPER.getPropertyName(field));
-      String fromRole = ANNOTATION_HELPER.extractFromRoleName(enp, field);
+      String fromRole = navInfo.getFromRoleName();
       navProp.setFromRole(fromRole);
+      navProp.setToRole(navInfo.getToRoleName());
 
-      String toRole = ANNOTATION_HELPER.extractToRoleName(enp, field);
-      navProp.setToRole(toRole);
-
-      String relationshipName = ANNOTATION_HELPER.extractRelationshipName(enp, field);
+      String relationshipName = navInfo.getRelationshipName();
       navProp.setRelationship(new FullQualifiedName(namespace, relationshipName));
 
       return navProp;
@@ -600,25 +602,22 @@ public class AnnotationEdmProvider extends EdmProvider {
       return ANNOTATION_HELPER.extractEntityTypeFqn(baseEntityClass);
     }
 
-    private Association createAssociation(final Field field, final NavigationProperty navProperty) {
+    private Association createAssociation(final AnnotationHelper.AnnotatedNavInfo info) {
       Association association = new Association();
-      EdmNavigationProperty navigation = field.getAnnotation(EdmNavigationProperty.class);
 
       AssociationEnd fromEnd = new AssociationEnd();
-      fromEnd.setRole(navProperty.getFromRole());
-      String typeName = ANNOTATION_HELPER.extractEntityTypeName(field.getDeclaringClass());
-      fromEnd.setType(new FullQualifiedName(namespace, typeName));
-      fromEnd.setMultiplicity(EdmMultiplicity.ONE);
+      fromEnd.setRole(info.getFromRoleName());
+      fromEnd.setType(new FullQualifiedName(namespace, info.getFromTypeName()));
+      fromEnd.setMultiplicity(info.getFromMultiplicity());
       association.setEnd1(fromEnd);
 
       AssociationEnd toEnd = new AssociationEnd();
-      toEnd.setRole(navProperty.getToRole());
-      String toTypeName = ANNOTATION_HELPER.extractEntitTypeName(navigation, field);
-      toEnd.setType(new FullQualifiedName(namespace, toTypeName));
-      toEnd.setMultiplicity(ANNOTATION_HELPER.getMultiplicity(navigation, field));
+      toEnd.setRole(info.getToRoleName());
+      toEnd.setType(new FullQualifiedName(namespace, info.getToTypeName()));
+      toEnd.setMultiplicity(info.getToMultiplicity());
       association.setEnd2(toEnd);
 
-      String associationName = navProperty.getRelationship().getName();
+      String associationName = info.getRelationshipName();
       association.setName(associationName);
       return association;
     }

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/6f7b76f6/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/util/AnnotationHelper.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/util/AnnotationHelper.java b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/util/AnnotationHelper.java
index 0d2ff11..d0f072a 100644
--- a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/util/AnnotationHelper.java
+++ b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/util/AnnotationHelper.java
@@ -103,22 +103,18 @@ public class AnnotationHelper {
 
   private boolean isEqual(final Object firstKey, final Object secondKey) {
     if (firstKey == null) {
-      if (secondKey == null) {
-        return true;
-      } else {
-        return secondKey.equals(firstKey);
-      }
+      return secondKey == null || secondKey.equals(firstKey);
     } else {
       return firstKey.equals(secondKey);
     }
   }
 
-  public String extractEntitTypeName(final EdmNavigationProperty enp, final Class<?> fallbackClass) {
+  public String extractEntityTypeName(final EdmNavigationProperty enp, final Class<?> fallbackClass) {
     Class<?> entityTypeClass = enp.toType();
     return extractEntityTypeName(entityTypeClass == Object.class ? fallbackClass : entityTypeClass);
   }
 
-  public String extractEntitTypeName(final EdmNavigationProperty enp, final Field field) {
+  public String extractEntityTypeName(final EdmNavigationProperty enp, final Field field) {
     Class<?> entityTypeClass = enp.toType();
     if (entityTypeClass == Object.class) {
       Class<?> toClass = field.getType();
@@ -199,8 +195,7 @@ public class AnnotationHelper {
   }
 
   public String generateNamespace(final Class<?> annotatedClass) {
-    String packageName = annotatedClass.getPackage().getName();
-    return packageName;
+    return annotatedClass.getPackage().getName();
   }
 
   /**
@@ -263,40 +258,53 @@ public class AnnotationHelper {
     return propertyName;
   }
 
-  public String extractFromRoleName(final EdmNavigationProperty enp, final Field field) {
-    return getCanonicalRole(field.getDeclaringClass());
-  }
-
   public String extractToRoleName(final EdmNavigationProperty enp, final Field field) {
     String role = enp.toRole();
     if (role.isEmpty()) {
-      role = getCanonicalRole(
-          field.getType().isArray() || Collection.class.isAssignableFrom(field.getType()) ?
-              (Class<?>) ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0] : field.getType());
+      role = getCanonicalRoleName(field.getName());
     }
     return role;
   }
 
-  public String getCanonicalRole(final Class<?> fallbackClass) {
-    String toRole = extractEntityTypeName(fallbackClass);
-    return "r_" + toRole;
+  public String extractFromRoleEntityName(final Field field) {
+    return extractEntityTypeName(field.getDeclaringClass());
+  }
+
+  public String extractToRoleEntityName(final EdmNavigationProperty enp, final Field field) {
+    Class<?> clazz = enp.toType();
+    if (clazz == Object.class) {
+      if(field.getType().isArray() || Collection.class.isAssignableFrom(field.getType())) {
+        clazz = (Class<?>) ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0];
+      } else {
+        clazz = field.getType();
+      }
+    }
+    return extractEntityTypeName(clazz);
+  }
+
+  public String getCanonicalRoleName(String name) {
+    return "r_" + name.substring(0, 1).toUpperCase(Locale.ENGLISH) + name.substring(1);
   }
 
   public String extractRelationshipName(final EdmNavigationProperty enp, final Field field) {
     String relationshipName = enp.association();
     if (relationshipName.isEmpty()) {
-      final String fromRole = extractFromRoleName(enp, field);
-      final String toRole = extractToRoleName(enp, field);
+      final String fromRole = extractFromRoleEntityName(field);
+      final String toRole = extractToRoleEntityName(enp, field);
+      return createCanonicalRelationshipName(fromRole, toRole);
+    }
+    return relationshipName;
+  }
+
+  public String createCanonicalRelationshipName(String fromRole, String toRole) {
       if (fromRole.compareTo(toRole) > 0) {
-        relationshipName = toRole + "-" + fromRole;
+        return toRole + "-" + fromRole;
       } else {
-        relationshipName = fromRole + "-" + toRole;
+        return fromRole + "-" + toRole;
       }
-    }
-    return relationshipName;
   }
 
-  public EdmMultiplicity getMultiplicity(final EdmNavigationProperty enp, final Field field) {
+  public EdmMultiplicity extractMultiplicity(final EdmNavigationProperty enp, final Field field) {
     EdmMultiplicity multiplicity = mapMultiplicity(enp.toMultiplicity());
     final boolean isCollectionType = field.getType().isArray() || Collection.class.isAssignableFrom(field.getType());
 
@@ -357,48 +365,131 @@ public class AnnotationHelper {
       return fromField;
     }
 
+    public String getFromRoleName() {
+      if(isBiDirectional()) {
+        return extractFromRoleEntityName(toField);
+      }
+      return extractToRoleName(toNavigation, toField);
+    }
+
     public Field getToField() {
       return toField;
     }
 
+    public String getToRoleName() {
+      if(isBiDirectional()) {
+        return extractToRoleName(toNavigation, toField);
+      }
+      return extractToRoleName(fromNavigation, fromField);
+    }
+
     public EdmMultiplicity getFromMultiplicity() {
-      return getMultiplicity(toNavigation, toField);
+      if(isBiDirectional()) {
+        return EdmMultiplicity.ONE;
+      }
+      return extractMultiplicity(toNavigation, toField);
     }
 
     public EdmMultiplicity getToMultiplicity() {
-      return getMultiplicity(fromNavigation, fromField);
+      if(isBiDirectional()) {
+        return extractMultiplicity(toNavigation, toField);
+      }
+      return extractMultiplicity(fromNavigation, fromField);
     }
 
     public boolean isBiDirectional() {
-      return toNavigation != null;
+      return fromNavigation == null;
+    }
+
+    public String getRelationshipName() {
+      String toAssociation = toNavigation.association();
+      String fromAssociation = "";
+      if(!isBiDirectional()) {
+        fromAssociation = fromNavigation.association();
+      }
+
+      if(fromAssociation.isEmpty() && fromAssociation.equals(toAssociation)) {
+        return createCanonicalRelationshipName(getFromRoleName(), getToRoleName());
+      } else if(toAssociation.isEmpty()) {
+        return fromAssociation;
+      } else if(!toAssociation.equals(fromAssociation)) {
+        throw new AnnotationRuntimeException("Invalid associations for navigation properties '" +
+            this.toString() + "'");
+      }
+      return toAssociation;
+    }
+
+    public String getFromTypeName() {
+      if(isBiDirectional()) {
+        return extractEntityTypeName(toField.getDeclaringClass());
+      }
+      return extractEntityTypeName(fromField.getDeclaringClass());
+    }
+
+    public String getToTypeName() {
+      if(isBiDirectional()) {
+        return extractEntityTypeName(ClassHelper.getFieldType(toField));
+      }
+      return extractEntityTypeName(toField.getDeclaringClass());
+    }
+
+    @Override
+    public String toString() {
+      if(isBiDirectional()) {
+        return "AnnotatedNavInfo{biDirectional = true" +
+            ", toField=" + toField.getName() +
+            ", toNavigation=" + toNavigation.name() + '}';
+      }
+      return "AnnotatedNavInfo{" +
+          "fromField=" + fromField.getName() +
+          ", toField=" + toField.getName() +
+          ", fromNavigation=" + fromNavigation.name() +
+          ", toNavigation=" + toNavigation.name() + '}';
     }
   }
 
+
   public AnnotatedNavInfo getCommonNavigationInfo(final Class<?> sourceClass, final Class<?> targetClass) {
     List<Field> sourceFields = getAnnotatedFields(sourceClass, EdmNavigationProperty.class);
     List<Field> targetFields = getAnnotatedFields(targetClass, EdmNavigationProperty.class);
 
+    if(sourceClass == targetClass) {
+      // special case, actual handled as bi-directional
+      return getCommonNavigationInfoBiDirectional(sourceClass, targetClass);
+    }
+
     // first try via association name to get full navigation information
     for (Field sourceField : sourceFields) {
-      final EdmNavigationProperty sourceNav = sourceField.getAnnotation(EdmNavigationProperty.class);
-      final String sourceAssociation = extractRelationshipName(sourceNav, sourceField);
-      for (Field targetField : targetFields) {
-        final EdmNavigationProperty targetNav = targetField.getAnnotation(EdmNavigationProperty.class);
-        final String targetAssociation = extractRelationshipName(targetNav, targetField);
-        if (sourceAssociation.equals(targetAssociation)) {
-          return new AnnotatedNavInfo(sourceField, targetField, sourceNav, targetNav);
+      if(ClassHelper.getFieldType(sourceField) == targetClass) {
+        final EdmNavigationProperty sourceNav = sourceField.getAnnotation(EdmNavigationProperty.class);
+        final String sourceAssociation = extractRelationshipName(sourceNav, sourceField);
+        for (Field targetField : targetFields) {
+          if(ClassHelper.getFieldType(targetField) == sourceClass) {
+            final EdmNavigationProperty targetNav = targetField.getAnnotation(EdmNavigationProperty.class);
+            final String targetAssociation = extractRelationshipName(targetNav, targetField);
+            if (sourceAssociation.equals(targetAssociation)) {
+              return new AnnotatedNavInfo(sourceField, targetField, sourceNav, targetNav);
+            }
+          }
         }
       }
     }
 
-    // if nothing was found assume none bi-directinal navigation
+    // if nothing was found assume/guess none bi-directional navigation
+    return getCommonNavigationInfoBiDirectional(sourceClass, targetClass);
+  }
+
+  private AnnotatedNavInfo getCommonNavigationInfoBiDirectional(final Class<?> sourceClass,
+                                                                final Class<?> targetClass) {
+    List<Field> sourceFields = getAnnotatedFields(sourceClass, EdmNavigationProperty.class);
+
     String targetEntityTypeName = extractEntityTypeName(targetClass);
     for (Field sourceField : sourceFields) {
       final EdmNavigationProperty sourceNav = sourceField.getAnnotation(EdmNavigationProperty.class);
-      final String navTargetEntityName = extractEntitTypeName(sourceNav, sourceField);
+      final String navTargetEntityName = extractEntityTypeName(sourceNav, sourceField);
 
       if (navTargetEntityName.equals(targetEntityTypeName)) {
-        return new AnnotatedNavInfo(sourceField, null, sourceNav, null);
+        return new AnnotatedNavInfo(null, sourceField, null, sourceNav);
       }
     }
 
@@ -576,7 +667,6 @@ public class AnnotationHelper {
 
   /**
    * 
-   * @param instance
    * @param resultClass
    * @param annotation
    * @param inherited

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/6f7b76f6/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/util/ClassHelper.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/util/ClassHelper.java b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/util/ClassHelper.java
index 24082ff..a5e9eb9 100644
--- a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/util/ClassHelper.java
+++ b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/util/ClassHelper.java
@@ -23,6 +23,7 @@ import java.io.FileFilter;
 import java.io.FilenameFilter;
 import java.io.IOException;
 import java.lang.reflect.Field;
+import java.lang.reflect.ParameterizedType;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
@@ -180,6 +181,21 @@ public class ClassHelper {
     }
   }
 
+  /**
+   * Get the type of the field. For arrays and collections the type of the array or collection is returned.
+   *
+   * @param field field for which the type is extracted
+   * @return type of the field (also for arrays or collections)
+   */
+  public static Class<?> getFieldType(Field field) {
+    if(field.getType().isArray() || Collection.class.isAssignableFrom(field.getType())) {
+      return (Class<?>) ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0];
+    } else {
+      return field.getType();
+    }
+  }
+
+
   public static Object getFieldValue(final Object instance, final Field field) {
     try {
       synchronized (field) {

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/6f7b76f6/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/edm/AnnotationEdmProviderTest.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/edm/AnnotationEdmProviderTest.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/edm/AnnotationEdmProviderTest.java
index 44187d4..50a1520 100644
--- a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/edm/AnnotationEdmProviderTest.java
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/edm/AnnotationEdmProviderTest.java
@@ -222,7 +222,7 @@ public class AnnotationEdmProviderTest {
     assertEquals("Buildings", asBuildingRooms.getEnd1().getEntitySet());
     assertEquals("r_Building", asBuildingRooms.getEnd1().getRole());
     assertEquals("Rooms", asBuildingRooms.getEnd2().getEntitySet());
-    assertEquals("r_Room", asBuildingRooms.getEnd2().getRole());
+    assertEquals("r_Rooms", asBuildingRooms.getEnd2().getRole());
   }
 
   @Test
@@ -252,7 +252,7 @@ public class AnnotationEdmProviderTest {
     assertEquals(6, entitySets.size());
 
     List<Association> associations = schema.getAssociations();
-    assertEquals(4, associations.size());
+    assertEquals(5, associations.size());
     for (Association association : associations) {
       assertNotNull(association.getName());
       validateAssociation(association);
@@ -265,22 +265,26 @@ public class AnnotationEdmProviderTest {
 
   private void validateAssociation(final Association association) {
     String name = association.getName();
-    if (name.equals("r_Employee-r_Room")) {
+    if (name.equals("r_Employees-r_Room")) {
       validateAssociation(association,
           "r_Room", EdmMultiplicity.ONE, defaultFqn("Room"),
-          "r_Employee", EdmMultiplicity.MANY, defaultFqn("Employee"));
+          "r_Employees", EdmMultiplicity.MANY, defaultFqn("Employee"));
     } else if (name.equals("BuildingRooms")) {
       validateAssociation(association,
           "r_Building", EdmMultiplicity.ONE, defaultFqn("Building"),
-          "r_Room", EdmMultiplicity.MANY, defaultFqn("Room"));
+          "r_Rooms", EdmMultiplicity.MANY, defaultFqn("Room"));
     } else if (name.equals("ManagerEmployees")) {
       validateAssociation(association,
           "r_Manager", EdmMultiplicity.ONE, defaultFqn("Manager"),
-          "r_Employee", EdmMultiplicity.MANY, defaultFqn("Employee"));
+          "r_Employees", EdmMultiplicity.MANY, defaultFqn("Employee"));
     } else if (name.equals("TeamEmployees")) {
       validateAssociation(association,
           "r_Team", EdmMultiplicity.ONE, defaultFqn("Team"),
-          "r_Employee", EdmMultiplicity.MANY, defaultFqn("Employee"));
+          "r_Employees", EdmMultiplicity.MANY, defaultFqn("Employee"));
+    } else if (name.equals("Team-r_SubTeam")) {
+      validateAssociation(association,
+          "Team", EdmMultiplicity.ONE, defaultFqn("Team"),
+          "r_SubTeam", EdmMultiplicity.ONE, defaultFqn("Team"));
     } else {
       fail("Got unknown association to validate with name '" + name + "'.");
     }
@@ -333,11 +337,11 @@ public class AnnotationEdmProviderTest {
 
     for (NavigationProperty navigationProperty : employee.getNavigationProperties()) {
       if (navigationProperty.getName().equals("ne_Manager")) {
-        validateNavProperty(navigationProperty, "ManagerEmployees", "r_Employee", "r_Manager");
+        validateNavProperty(navigationProperty, "ManagerEmployees", "r_Employees", "r_Manager");
       } else if (navigationProperty.getName().equals("ne_Team")) {
-        validateNavProperty(navigationProperty, "TeamEmployees", "r_Employee", "r_Team");
+        validateNavProperty(navigationProperty, "TeamEmployees", "r_Employees", "r_Team");
       } else if (navigationProperty.getName().equals("ne_Room")) {
-        validateNavProperty(navigationProperty, "r_Employee-r_Room", "r_Employee", "r_Room");
+        validateNavProperty(navigationProperty, "r_Employees-r_Room", "r_Employees", "r_Room");
       } else {
         fail("Got unexpected navigation property with name '" + navigationProperty.getName() + "'.");
       }
@@ -376,9 +380,11 @@ public class AnnotationEdmProviderTest {
     assertEquals(ModelSharedConstants.NAMESPACE_1, team.getBaseType().getNamespace());
 
     assertEquals(1, team.getProperties().size());
-    assertEquals(1, team.getNavigationProperties().size());
-    NavigationProperty navigationProperty = team.getNavigationProperties().get(0);
-    validateNavProperty(navigationProperty, "TeamEmployees", "r_Team", "r_Employee");
+    assertEquals(2, team.getNavigationProperties().size());
+    NavigationProperty navPropTeamEmployess = team.getNavigationProperties().get(0);
+    validateNavProperty(navPropTeamEmployess, "TeamEmployees", "r_Team", "r_Employees");
+    NavigationProperty navPropTeamTeam = team.getNavigationProperties().get(1);
+    validateNavProperty(navPropTeamTeam, "Team-r_SubTeam", "Team", "r_SubTeam");
   }
 
   @Test
@@ -459,9 +465,9 @@ public class AnnotationEdmProviderTest {
 
     for (NavigationProperty navigationProperty : navigationProperties) {
       if (navigationProperty.getName().equals("nr_Employees")) {
-        validateNavProperty(navigationProperty, "r_Employee-r_Room", "r_Room", "r_Employee");
+        validateNavProperty(navigationProperty, "r_Employees-r_Room", "r_Room", "r_Employees");
       } else if (navigationProperty.getName().equals("nr_Building")) {
-        validateNavProperty(navigationProperty, "BuildingRooms", "r_Room", "r_Building");
+        validateNavProperty(navigationProperty, "BuildingRooms", "r_Rooms", "r_Building");
       } else {
         fail("Got unexpected navigation property with name '" + navigationProperty.getName() + "'.");
       }

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/6f7b76f6/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Team.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Team.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Team.java
index 8e5e794..23371a6 100644
--- a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Team.java
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Team.java
@@ -38,6 +38,8 @@ public class Team extends RefBase {
   private Boolean isScrumTeam;
   @EdmNavigationProperty(name = "nt_Employees", association = "TeamEmployees", toMultiplicity = Multiplicity.MANY)
   private List<Employee> employees = new ArrayList<Employee>();
+  @EdmNavigationProperty
+  private Team subTeam;
 
   public Team() {
     super(-1, null);
@@ -63,6 +65,10 @@ public class Team extends RefBase {
     return employees;
   }
 
+  public Team getSubTeam() {
+    return subTeam;
+  }
+
   @Override
   public int hashCode() {
     return id;

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/6f7b76f6/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/util/AnnotationHelperTest.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/util/AnnotationHelperTest.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/util/AnnotationHelperTest.java
index 18d7df2..478a1b7 100644
--- a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/util/AnnotationHelperTest.java
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/util/AnnotationHelperTest.java
@@ -17,6 +17,7 @@ package org.apache.olingo.odata2.annotation.processor.core.util;
 
 import java.lang.reflect.Field;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import junit.framework.Assert;
@@ -160,26 +161,36 @@ public class AnnotationHelperTest {
   }
 
   @Test
-  public void extractEntitTypeNameViaNavigation() throws Exception {
+  public void extractEntityTypeNameViaNavigation() throws Exception {
     Field field = NavigationAnnotated.class.getDeclaredField("navigationPropertySimpleEntity");
     EdmNavigationProperty enp = field.getAnnotation(EdmNavigationProperty.class);
 
-    String name = annotationHelper.extractEntitTypeName(enp, SimpleEntity.class);
+    String name = annotationHelper.extractEntityTypeName(enp, SimpleEntity.class);
 
     Assert.assertEquals("SimpleEntity", name);
   }
 
   @Test
-  public void extractEntitTypeNameViaNavigationField() throws Exception {
+  public void extractEntityTypeNameViaNavigationField() throws Exception {
     Field field = NavigationAnnotated.class.getDeclaredField("navigationPropertyDefault");
     EdmNavigationProperty enp = field.getAnnotation(EdmNavigationProperty.class);
 
-    String name = annotationHelper.extractEntitTypeName(enp, field);
+    String name = annotationHelper.extractEntityTypeName(enp, field);
 
     Assert.assertEquals("SimpleEntity", name);
   }
 
   @Test
+  public void selfReferencedEntityTypeNameViaNavigationField() throws Exception {
+    Field field = NavigationAnnotated.class.getDeclaredField("selfReferencedNavigation");
+    EdmNavigationProperty enp = field.getAnnotation(EdmNavigationProperty.class);
+
+    String name = annotationHelper.extractToRoleName(enp, field);
+
+    Assert.assertEquals("r_SelfReferencedNavigation", name);
+  }
+
+  @Test
   public void getFieldTypeForPropertyNullInstance() throws Exception {
     Object result = annotationHelper.getFieldTypeForProperty(null, "");
     Assert.assertNull(result);
@@ -247,11 +258,14 @@ public class AnnotationHelperTest {
     }
   }
 
+  @EdmEntityType
   private class NavigationAnnotated {
     @EdmNavigationProperty(toType = SimpleEntity.class)
     SimpleEntity navigationPropertySimpleEntity;
     @EdmNavigationProperty
     SimpleEntity navigationPropertyDefault;
+    @EdmNavigationProperty
+    List<NavigationAnnotated> selfReferencedNavigation;
   }
 
   private class ConversionProperty {

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/6f7b76f6/odata2-annotation-processor/annotation-processor-ref/src/main/java/org/apache/olingo/odata2/annotation/processor/ref/AnnotationRefServiceFactory.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-ref/src/main/java/org/apache/olingo/odata2/annotation/processor/ref/AnnotationRefServiceFactory.java b/odata2-annotation-processor/annotation-processor-ref/src/main/java/org/apache/olingo/odata2/annotation/processor/ref/AnnotationRefServiceFactory.java
index 5a3766f..6bf3588 100644
--- a/odata2-annotation-processor/annotation-processor-ref/src/main/java/org/apache/olingo/odata2/annotation/processor/ref/AnnotationRefServiceFactory.java
+++ b/odata2-annotation-processor/annotation-processor-ref/src/main/java/org/apache/olingo/odata2/annotation/processor/ref/AnnotationRefServiceFactory.java
@@ -126,7 +126,7 @@ public class AnnotationRefServiceFactory extends ODataServiceFactory {
     teamDs.create(createTeam("Team Beta", false));
     teamDs.create(createTeam("Team Gamma", false));
     teamDs.create(createTeam("Team Omega", true));
-    teamDs.create(createTeam("Team Zeta", true));
+    teamDs.create(createTeam("Team Zeta", true, createTeam("SubTeamOne", false)));
 
     DataStore<Building> buildingsDs = getDataStore(Building.class);
     Building redBuilding = createBuilding("Red Building");
@@ -179,9 +179,14 @@ public class AnnotationRefServiceFactory extends ODataServiceFactory {
   }
 
   private static Team createTeam(final String teamName, final boolean isScrumTeam) {
+    return createTeam(teamName, isScrumTeam, null);
+  }
+
+  private static Team createTeam(final String teamName, final boolean isScrumTeam, Team subTeam) {
     Team team = new Team();
     team.setName(teamName);
     team.setScrumTeam(isScrumTeam);
+    subTeam.setSubTeam(subTeam);
     return team;
   }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/6f7b76f6/odata2-annotation-processor/annotation-processor-ref/src/main/java/org/apache/olingo/odata2/annotation/processor/ref/model/Team.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-ref/src/main/java/org/apache/olingo/odata2/annotation/processor/ref/model/Team.java b/odata2-annotation-processor/annotation-processor-ref/src/main/java/org/apache/olingo/odata2/annotation/processor/ref/model/Team.java
index 7f48f66..9e3d38c 100644
--- a/odata2-annotation-processor/annotation-processor-ref/src/main/java/org/apache/olingo/odata2/annotation/processor/ref/model/Team.java
+++ b/odata2-annotation-processor/annotation-processor-ref/src/main/java/org/apache/olingo/odata2/annotation/processor/ref/model/Team.java
@@ -38,6 +38,8 @@ public class Team extends RefBase {
   private Boolean isScrumTeam;
   @EdmNavigationProperty(name = "nt_Employees", association = "TeamEmployees", toMultiplicity = Multiplicity.MANY)
   private List<Employee> employees = new ArrayList<Employee>();
+  @EdmNavigationProperty
+  private Team subTeam;
 
   public Boolean isScrumTeam() {
     return isScrumTeam;
@@ -55,6 +57,14 @@ public class Team extends RefBase {
     return employees;
   }
 
+  public void setSubTeam(Team subTeam) {
+    this.subTeam = subTeam;
+  }
+
+  public Team getSubTeam() {
+    return subTeam;
+  }
+
   @Override
   public int hashCode() {
     return super.hashCode();

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/6f7b76f6/odata2-annotation-processor/annotation-processor-ref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/MetadataTest.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-ref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/MetadataTest.java b/odata2-annotation-processor/annotation-processor-ref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/MetadataTest.java
index 5114594..0068869 100644
--- a/odata2-annotation-processor/annotation-processor-ref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/MetadataTest.java
+++ b/odata2-annotation-processor/annotation-processor-ref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/MetadataTest.java
@@ -101,17 +101,17 @@ public class MetadataTest extends AbstractRefXmlTest {
     assertXpathExists(
         "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityType[@Name='Employee' and" +
             " @m:HasStream='true']/edm:NavigationProperty[@Name='ne_Manager' and " +
-            "@Relationship='RefScenario.ManagerEmployees' and @FromRole='r_Employee' and @ToRole='r_Manager']",
+            "@Relationship='RefScenario.ManagerEmployees' and @FromRole='r_Employees' and @ToRole='r_Manager']",
         payload);
     assertXpathExists(
         "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityType[@Name='Employee' and" +
             " @m:HasStream='true']/edm:NavigationProperty[@Name='ne_Team' and " +
-            "@Relationship='RefScenario.TeamEmployees' and @FromRole='r_Employee' and @ToRole='r_Team']",
+            "@Relationship='RefScenario.TeamEmployees' and @FromRole='r_Employees' and @ToRole='r_Team']",
         payload);
     assertXpathExists(
         "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityType[@Name='Employee' and " +
             "@m:HasStream='true']/edm:NavigationProperty[@Name='ne_Room' and " +
-            "@Relationship='RefScenario.r_Employee-r_Room' and @FromRole='r_Employee' and @ToRole='r_Room']",
+            "@Relationship='RefScenario.r_Employees-r_Room' and @FromRole='r_Employees' and @ToRole='r_Room']",
         payload);
 
     // Team
@@ -126,7 +126,7 @@ public class MetadataTest extends AbstractRefXmlTest {
     assertXpathExists(
         "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityType[@Name='Team' and " +
             "@BaseType='RefScenario.Base']/edm:NavigationProperty[@Name='nt_Employees' and " +
-            "@Relationship='RefScenario.TeamEmployees' and @FromRole='r_Team' and @ToRole='r_Employee']",
+            "@Relationship='RefScenario.TeamEmployees' and @FromRole='r_Team' and @ToRole='r_Employees']",
         payload);
 
     // Room
@@ -144,12 +144,12 @@ public class MetadataTest extends AbstractRefXmlTest {
     assertXpathExists(
         "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityType[@Name='Room' and" +
             " @BaseType='RefScenario.Base']/edm:NavigationProperty[@Name='nr_Employees' and " +
-            "@Relationship='RefScenario.r_Employee-r_Room' and @FromRole='r_Room' and @ToRole='r_Employee']",
+            "@Relationship='RefScenario.r_Employees-r_Room' and @FromRole='r_Room' and @ToRole='r_Employees']",
         payload);
     assertXpathExists(
         "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityType[@Name='Room' and " +
             "@BaseType='RefScenario.Base']/edm:NavigationProperty[@Name='nr_Building' and " +
-            "@Relationship='RefScenario.BuildingRooms' and @FromRole='r_Room' and @ToRole='r_Building']",
+            "@Relationship='RefScenario.BuildingRooms' and @FromRole='r_Rooms' and @ToRole='r_Building']",
         payload);
 
     // Manager
@@ -157,7 +157,7 @@ public class MetadataTest extends AbstractRefXmlTest {
             "@BaseType='RefScenario.Employee']", payload);
     assertXpathExists("/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityType[@Name='Manager' and " +
             "@BaseType='RefScenario.Employee']/edm:NavigationProperty[@Name='nm_Employees' and " +
-            "@Relationship='RefScenario.ManagerEmployees' and @FromRole='r_Manager' and @ToRole='r_Employee']",
+            "@Relationship='RefScenario.ManagerEmployees' and @FromRole='r_Manager' and @ToRole='r_Employees']",
         payload);
 
     // Building
@@ -174,7 +174,7 @@ public class MetadataTest extends AbstractRefXmlTest {
     assertXpathExists(
         "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityType[@Name='Building']" +
                 "/edm:NavigationProperty[@Name='nb_Rooms' and @Relationship='RefScenario.BuildingRooms' " +
-                "and @FromRole='r_Building' and @ToRole='r_Room']", payload);
+                "and @FromRole='r_Building' and @ToRole='r_Rooms']", payload);
 
     // Base
     assertXpathExists("/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityType[@Name='Base' and @Abstract='true']",
@@ -219,22 +219,22 @@ public class MetadataTest extends AbstractRefXmlTest {
     // ManagerEmployees
     assertXpathExists("/edmx:Edmx/edmx:DataServices/edm:Schema/edm:Association[@Name='ManagerEmployees']", payload);
     assertXpathExists("/edmx:Edmx/edmx:DataServices/edm:Schema/edm:Association[@Name='ManagerEmployees']" +
-            "/edm:End[@Type='RefScenario.Employee' and @Multiplicity='*' and @Role='r_Employee']", payload);
+            "/edm:End[@Type='RefScenario.Employee' and @Multiplicity='*' and @Role='r_Employees']", payload);
     assertXpathExists( "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:Association[@Name='ManagerEmployees']" +
             "/edm:End[@Type='RefScenario.Manager' and @Multiplicity='1' and @Role='r_Manager']", payload);
 
     // TeamEmployees
     assertXpathExists("/edmx:Edmx/edmx:DataServices/edm:Schema/edm:Association[@Name='TeamEmployees']", payload);
     assertXpathExists( "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:Association[@Name='TeamEmployees']" +
-            "/edm:End[@Type='RefScenario.Employee' and @Multiplicity='*' and @Role='r_Employee']", payload);
+            "/edm:End[@Type='RefScenario.Employee' and @Multiplicity='*' and @Role='r_Employees']", payload);
     assertXpathExists("/edmx:Edmx/edmx:DataServices/edm:Schema/edm:Association[@Name='TeamEmployees']" +
             "/edm:End[@Type='RefScenario.Team' and @Multiplicity='1' and @Role='r_Team']", payload);
 
     // RoomEmployees
-    assertXpathExists("/edmx:Edmx/edmx:DataServices/edm:Schema/edm:Association[@Name='r_Employee-r_Room']", payload);
-    assertXpathExists("/edmx:Edmx/edmx:DataServices/edm:Schema/edm:Association[@Name='r_Employee-r_Room']" +
-            "/edm:End[@Type='RefScenario.Employee' and @Multiplicity='*' and @Role='r_Employee']", payload);
-    assertXpathExists("/edmx:Edmx/edmx:DataServices/edm:Schema/edm:Association[@Name='r_Employee-r_Room']" +
+    assertXpathExists("/edmx:Edmx/edmx:DataServices/edm:Schema/edm:Association[@Name='r_Employees-r_Room']", payload);
+    assertXpathExists("/edmx:Edmx/edmx:DataServices/edm:Schema/edm:Association[@Name='r_Employees-r_Room']" +
+            "/edm:End[@Type='RefScenario.Employee' and @Multiplicity='*' and @Role='r_Employees']", payload);
+    assertXpathExists("/edmx:Edmx/edmx:DataServices/edm:Schema/edm:Association[@Name='r_Employees-r_Room']" +
             "/edm:End[@Type='RefScenario.Room' and @Multiplicity='1' and @Role='r_Room']", payload);
 
     // BuildingRooms
@@ -242,7 +242,7 @@ public class MetadataTest extends AbstractRefXmlTest {
     assertXpathExists("/edmx:Edmx/edmx:DataServices/edm:Schema/edm:Association[@Name='BuildingRooms']" +
             "/edm:End[@Type='RefScenario.Building' and @Multiplicity='1' and @Role='r_Building']", payload);
     assertXpathExists("/edmx:Edmx/edmx:DataServices/edm:Schema/edm:Association[@Name='BuildingRooms']" +
-            "/edm:End[@Type='RefScenario.Room' and @Multiplicity='*' and @Role='r_Room']", payload);
+            "/edm:End[@Type='RefScenario.Room' and @Multiplicity='*' and @Role='r_Rooms']", payload);
   }
 
   @Test
@@ -291,7 +291,7 @@ public class MetadataTest extends AbstractRefXmlTest {
     assertXpathExists(
         "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityContainer[@Name='DefaultContainer' and " +
             "@m:IsDefaultEntityContainer='true']/edm:AssociationSet[@Name='ManagerEmployees' and " +
-            "@Association='RefScenario.ManagerEmployees']/edm:End[@EntitySet='Employees' and @Role='r_Employee']",
+            "@Association='RefScenario.ManagerEmployees']/edm:End[@EntitySet='Employees' and @Role='r_Employees']",
         payload);
 
     assertXpathExists(
@@ -307,23 +307,23 @@ public class MetadataTest extends AbstractRefXmlTest {
     assertXpathExists(
         "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityContainer[@Name='DefaultContainer' and " +
             "@m:IsDefaultEntityContainer='true']/edm:AssociationSet[@Name='TeamEmployees' and " +
-            "@Association='RefScenario.TeamEmployees']/edm:End[@EntitySet='Employees' and @Role='r_Employee']",
+            "@Association='RefScenario.TeamEmployees']/edm:End[@EntitySet='Employees' and @Role='r_Employees']",
         payload);
 
     assertXpathExists(
         "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityContainer[@Name='DefaultContainer' and " +
-            "@m:IsDefaultEntityContainer='true']/edm:AssociationSet[@Name='r_Employee-r_Room' and " +
-            "@Association='RefScenario.r_Employee-r_Room']",
+            "@m:IsDefaultEntityContainer='true']/edm:AssociationSet[@Name='r_Employees-r_Room' and " +
+            "@Association='RefScenario.r_Employees-r_Room']",
         payload);
     assertXpathExists(
         "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityContainer[@Name='DefaultContainer' and " +
-            "@m:IsDefaultEntityContainer='true']/edm:AssociationSet[@Name='r_Employee-r_Room' and " +
-            "@Association='RefScenario.r_Employee-r_Room']/edm:End[@EntitySet='Rooms' and @Role='r_Room']",
+            "@m:IsDefaultEntityContainer='true']/edm:AssociationSet[@Name='r_Employees-r_Room' and " +
+            "@Association='RefScenario.r_Employees-r_Room']/edm:End[@EntitySet='Rooms' and @Role='r_Room']",
         payload);
     assertXpathExists(
         "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityContainer[@Name='DefaultContainer' and " +
-            "@m:IsDefaultEntityContainer='true']/edm:AssociationSet[@Name='r_Employee-r_Room' and " +
-            "@Association='RefScenario.r_Employee-r_Room']/edm:End[@EntitySet='Employees' and @Role='r_Employee']",
+            "@m:IsDefaultEntityContainer='true']/edm:AssociationSet[@Name='r_Employees-r_Room' and " +
+            "@Association='RefScenario.r_Employees-r_Room']/edm:End[@EntitySet='Employees' and @Role='r_Employees']",
         payload);
 
     assertXpathExists(
@@ -339,7 +339,7 @@ public class MetadataTest extends AbstractRefXmlTest {
     assertXpathExists(
         "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityContainer[@Name='DefaultContainer' and " +
             "@m:IsDefaultEntityContainer='true']/edm:AssociationSet[@Name='BuildingRooms' and " +
-            "@Association='RefScenario.BuildingRooms']/edm:End[@EntitySet='Rooms' and @Role='r_Room']",
+            "@Association='RefScenario.BuildingRooms']/edm:End[@EntitySet='Rooms' and @Role='r_Rooms']",
         payload);
   }
 }


[09/37] olingo-odata2 git commit: [OLINGO-508] Fixed readRelatedData for bi-directional

Posted by mi...@apache.org.
[OLINGO-508] Fixed readRelatedData for bi-directional


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

Branch: refs/heads/Olingo-129_PocJpaDataStore
Commit: c0e17eea1221392b3bad4de53339778dcbaad6d8
Parents: 6f7b76f
Author: mibo <mi...@mirb.de>
Authored: Tue Dec 16 21:26:29 2014 +0100
Committer: mibo <mi...@mirb.de>
Committed: Tue Dec 16 21:26:29 2014 +0100

----------------------------------------------------------------------
 .../core/datasource/AnnotationInMemoryDs.java   |  7 ++++++-
 .../ref/AnnotationRefServiceFactory.java        |  6 ++++--
 .../annotation/processor/ref/MetadataTest.java  | 22 ++++++++++++++++++++
 3 files changed, 32 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/c0e17eea/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/datasource/AnnotationInMemoryDs.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/datasource/AnnotationInMemoryDs.java b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/datasource/AnnotationInMemoryDs.java
index c1b121c..74b8d1e 100644
--- a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/datasource/AnnotationInMemoryDs.java
+++ b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/datasource/AnnotationInMemoryDs.java
@@ -144,7 +144,12 @@ public class AnnotationInMemoryDs implements DataSource {
 
     AnnotatedNavInfo navInfo = ANNOTATION_HELPER.getCommonNavigationInfo(
         sourceStore.getDataTypeClass(), targetStore.getDataTypeClass());
-    Field sourceField = navInfo.getFromField();
+    final Field sourceField;
+    if(navInfo.isBiDirectional()) {
+      sourceField = navInfo.getToField();
+    } else {
+      sourceField = navInfo.getFromField();
+    }
     if (sourceField == null) {
       throw new AnnotationRuntimeException("Missing source field for related data (sourceStore='" + sourceStore
           + "', targetStore='" + targetStore + "').");

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/c0e17eea/odata2-annotation-processor/annotation-processor-ref/src/main/java/org/apache/olingo/odata2/annotation/processor/ref/AnnotationRefServiceFactory.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-ref/src/main/java/org/apache/olingo/odata2/annotation/processor/ref/AnnotationRefServiceFactory.java b/odata2-annotation-processor/annotation-processor-ref/src/main/java/org/apache/olingo/odata2/annotation/processor/ref/AnnotationRefServiceFactory.java
index 6bf3588..9130a19 100644
--- a/odata2-annotation-processor/annotation-processor-ref/src/main/java/org/apache/olingo/odata2/annotation/processor/ref/AnnotationRefServiceFactory.java
+++ b/odata2-annotation-processor/annotation-processor-ref/src/main/java/org/apache/olingo/odata2/annotation/processor/ref/AnnotationRefServiceFactory.java
@@ -126,7 +126,9 @@ public class AnnotationRefServiceFactory extends ODataServiceFactory {
     teamDs.create(createTeam("Team Beta", false));
     teamDs.create(createTeam("Team Gamma", false));
     teamDs.create(createTeam("Team Omega", true));
-    teamDs.create(createTeam("Team Zeta", true, createTeam("SubTeamOne", false)));
+    Team subTeam = createTeam("SubTeamOne", false);
+    teamDs.create(subTeam);
+    teamDs.create(createTeam("Team Zeta", true, subTeam));
 
     DataStore<Building> buildingsDs = getDataStore(Building.class);
     Building redBuilding = createBuilding("Red Building");
@@ -186,7 +188,7 @@ public class AnnotationRefServiceFactory extends ODataServiceFactory {
     Team team = new Team();
     team.setName(teamName);
     team.setScrumTeam(isScrumTeam);
-    subTeam.setSubTeam(subTeam);
+    team.setSubTeam(subTeam);
     return team;
   }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/c0e17eea/odata2-annotation-processor/annotation-processor-ref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/MetadataTest.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-ref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/MetadataTest.java b/odata2-annotation-processor/annotation-processor-ref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/MetadataTest.java
index 0068869..4818327 100644
--- a/odata2-annotation-processor/annotation-processor-ref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/MetadataTest.java
+++ b/odata2-annotation-processor/annotation-processor-ref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/MetadataTest.java
@@ -128,6 +128,11 @@ public class MetadataTest extends AbstractRefXmlTest {
             "@BaseType='RefScenario.Base']/edm:NavigationProperty[@Name='nt_Employees' and " +
             "@Relationship='RefScenario.TeamEmployees' and @FromRole='r_Team' and @ToRole='r_Employees']",
         payload);
+    assertXpathExists(
+        "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityType[@Name='Team' and " +
+            "@BaseType='RefScenario.Base']/edm:NavigationProperty[@Name='SubTeam' and " +
+            "@Relationship='RefScenario.Team-r_SubTeam' and @FromRole='Team' and @ToRole='r_SubTeam']",
+        payload);
 
     // Room
     assertXpathExists(
@@ -230,6 +235,13 @@ public class MetadataTest extends AbstractRefXmlTest {
     assertXpathExists("/edmx:Edmx/edmx:DataServices/edm:Schema/edm:Association[@Name='TeamEmployees']" +
             "/edm:End[@Type='RefScenario.Team' and @Multiplicity='1' and @Role='r_Team']", payload);
 
+    // Team-r_SubTeam
+    assertXpathExists("/edmx:Edmx/edmx:DataServices/edm:Schema/edm:Association[@Name='Team-r_SubTeam']", payload);
+    assertXpathExists( "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:Association[@Name='Team-r_SubTeam']" +
+        "/edm:End[@Type='RefScenario.Team' and @Multiplicity='1' and @Role='Team']", payload);
+    assertXpathExists("/edmx:Edmx/edmx:DataServices/edm:Schema/edm:Association[@Name='Team-r_SubTeam']" +
+        "/edm:End[@Type='RefScenario.Team' and @Multiplicity='1' and @Role='r_SubTeam']", payload);
+
     // RoomEmployees
     assertXpathExists("/edmx:Edmx/edmx:DataServices/edm:Schema/edm:Association[@Name='r_Employees-r_Room']", payload);
     assertXpathExists("/edmx:Edmx/edmx:DataServices/edm:Schema/edm:Association[@Name='r_Employees-r_Room']" +
@@ -309,6 +321,16 @@ public class MetadataTest extends AbstractRefXmlTest {
             "@m:IsDefaultEntityContainer='true']/edm:AssociationSet[@Name='TeamEmployees' and " +
             "@Association='RefScenario.TeamEmployees']/edm:End[@EntitySet='Employees' and @Role='r_Employees']",
         payload);
+    assertXpathExists(
+        "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityContainer[@Name='DefaultContainer' and " +
+            "@m:IsDefaultEntityContainer='true']/edm:AssociationSet[@Name='Team-r_SubTeam' and " +
+            "@Association='RefScenario.Team-r_SubTeam']/edm:End[@EntitySet='Teams' and @Role='Team']",
+        payload);
+    assertXpathExists(
+        "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityContainer[@Name='DefaultContainer' and " +
+            "@m:IsDefaultEntityContainer='true']/edm:AssociationSet[@Name='Team-r_SubTeam' and " +
+            "@Association='RefScenario.Team-r_SubTeam']/edm:End[@EntitySet='Teams' and @Role='r_SubTeam']",
+        payload);
 
     assertXpathExists(
         "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityContainer[@Name='DefaultContainer' and " +


[19/37] olingo-odata2 git commit: [OLINGO-526] Fix for NPE in case referenced attribute is missing

Posted by mi...@apache.org.
[OLINGO-526] Fix for NPE in case referenced attribute is missing


Signed-off-by: Chandan V A <ch...@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/e80f0199
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata2/tree/e80f0199
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata2/diff/e80f0199

Branch: refs/heads/Olingo-129_PocJpaDataStore
Commit: e80f0199f57cd8e0eabc30f82f5226a5f6a920d2
Parents: 88d2335
Author: Chandan V A <ch...@sap.com>
Authored: Fri Dec 26 10:36:42 2014 +0530
Committer: Chandan V A <ch...@sap.com>
Committed: Fri Dec 26 10:36:42 2014 +0530

----------------------------------------------------------------------
 .../jpa/processor/api/exception/ODataJPAModelException.java      | 2 ++
 .../olingo/odata2/jpa/processor/core/model/JPAEdmProperty.java   | 4 ++++
 .../jpa-core/src/main/resources/jpaprocessor_msg.properties      | 2 +-
 3 files changed, 7 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/e80f0199/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/exception/ODataJPAModelException.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/exception/ODataJPAModelException.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/exception/ODataJPAModelException.java
index 9f18f37..0ddb284 100644
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/exception/ODataJPAModelException.java
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/exception/ODataJPAModelException.java
@@ -60,6 +60,8 @@ public class ODataJPAModelException extends ODataJPAException {
       "INNER_EXCEPTION");
   public static final MessageReference FUNC_PARAM_NAME_EXP = createMessageReference(ODataJPAModelException.class,
       "FUNC_PARAM_NAME_EXP");
+  public static final MessageReference REF_ATTRIBUTE_NOT_FOUND = createMessageReference(ODataJPAModelException.class,
+      "REF_ATTRIBUTE_NOT_FOUND");
 
   private ODataJPAModelException(final String localizedMessage, final Throwable e, final MessageReference msgRef) {
     super(localizedMessage, e, msgRef);

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/e80f0199/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmProperty.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmProperty.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmProperty.java
index 9bce9fc..369f6b9 100644
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmProperty.java
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmProperty.java
@@ -414,6 +414,10 @@ public class JPAEdmProperty extends JPAEdmBaseViewImpl implements
         }
       }
 
+      if (currentRefAttribute == null) {
+        throw ODataJPAModelException.throwException(ODataJPAModelException.REF_ATTRIBUTE_NOT_FOUND
+            .addContent(referencedEntityType.getName()), null);
+      }
       if (joinColumn.insertable() && joinColumn.updatable()) {
         currentSimpleProperty = new SimpleProperty();
         properties.add(buildSimpleProperty(currentRefAttribute, currentSimpleProperty, true));

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/e80f0199/odata2-jpa-processor/jpa-core/src/main/resources/jpaprocessor_msg.properties
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/resources/jpaprocessor_msg.properties b/odata2-jpa-processor/jpa-core/src/main/resources/jpaprocessor_msg.properties
index 29c1006..7b4bb95 100644
--- a/odata2-jpa-processor/jpa-core/src/main/resources/jpaprocessor_msg.properties
+++ b/odata2-jpa-processor/jpa-core/src/main/resources/jpaprocessor_msg.properties
@@ -34,7 +34,7 @@ org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException.FUNC
 org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException.FUNC_RETURN_TYPE_EXP="OData - JPA Model Processor: Return type expected. Class: [%1$s], Method: [%2$s]"
 org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException.FUNC_RETURN_TYPE_ENTITY_NOT_FOUND="OData - JPA Model Processor: Return type not found. Class: [%1$s], Method: [%2$s], Type: [%3$s]"
 org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException.FUNC_PARAM_NAME_EXP="OData - JPA Model Processor: Parameter Name for function import expected. Class: [%1$s]", Method: [%2$s]"
-
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException.REF_ATTRIBUTE_NOT_FOUND="OData - JPA Model Processor: Reference attribute not found in JPA entity [%1$s]"
 #JPA Type converter Errors
 org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException.TYPE_NOT_SUPPORTED="OData - JPA Type Converter: Type [%1$s] not supported"
 


[31/37] olingo-odata2 git commit: [OLINGO-536] Catcfh Exception in servlet

Posted by mi...@apache.org.
[OLINGO-536] Catcfh Exception in servlet


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

Branch: refs/heads/Olingo-129_PocJpaDataStore
Commit: 5c6af747ecab3cecf6b5b5ffd5012d3ccab8ad8a
Parents: b6a7d54
Author: Christian Amend <ch...@apache.org>
Authored: Thu Jan 15 12:58:15 2015 +0100
Committer: Christian Amend <ch...@apache.org>
Committed: Thu Jan 15 12:58:15 2015 +0100

----------------------------------------------------------------------
 .../java/org/apache/olingo/odata2/core/servlet/ODataServlet.java  | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/5c6af747/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/ODataServlet.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/ODataServlet.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/ODataServlet.java
index e1faeae..f0b5c6b 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/ODataServlet.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/ODataServlet.java
@@ -33,7 +33,6 @@ import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
 import org.apache.olingo.odata2.api.commons.ODataHttpMethod;
 import org.apache.olingo.odata2.api.exception.MessageReference;
 import org.apache.olingo.odata2.api.exception.ODataBadRequestException;
-import org.apache.olingo.odata2.api.exception.ODataException;
 import org.apache.olingo.odata2.api.exception.ODataHttpException;
 import org.apache.olingo.odata2.api.exception.ODataInternalServerErrorException;
 import org.apache.olingo.odata2.api.exception.ODataMethodNotAllowedException;
@@ -179,7 +178,7 @@ public class ODataServlet extends HttpServlet {
         final ODataResponse odataResponse = requestHandler.handle(odataRequest);
         createResponse(resp, odataResponse);
       }
-    } catch (ODataException e) {
+    } catch (Exception e) {
       ODataExceptionWrapper wrapper = new ODataExceptionWrapper(req, serviceFactory);
       createResponse(resp, wrapper.wrapInExceptionResponse(e));
     }


[21/37] olingo-odata2 git commit: [OLINGO-193] Renamed artifact and minor code clean up

Posted by mi...@apache.org.
[OLINGO-193] Renamed artifact and minor code clean up


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

Branch: refs/heads/Olingo-129_PocJpaDataStore
Commit: 92531140bb369a98a12c6a85f3f8aac08fb803bc
Parents: 5b63277
Author: Michael Bolz <mi...@sap.com>
Authored: Wed Jan 7 14:54:42 2015 +0100
Committer: Michael Bolz <mi...@sap.com>
Committed: Wed Jan 7 14:54:42 2015 +0100

----------------------------------------------------------------------
 .../olingo/odata2/core/rest/ODataRootLocator.java   |  3 +--
 odata2-spring/pom.xml                               |  2 +-
 .../olingo/odata2/spring/OlingoRootLocator.java     | 16 ----------------
 3 files changed, 2 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/92531140/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 e75ef5d..57a8bc8 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
@@ -151,8 +151,7 @@ public class ODataRootLocator {
           factoryClass = Class.forName(factoryClassName, true, cl);
         }
       }
-      ODataServiceFactory serviceFactory = (ODataServiceFactory) factoryClass.newInstance();
-      return serviceFactory;
+      return (ODataServiceFactory) factoryClass.newInstance();
     } catch (Exception e) {
       throw new ODataRuntimeException("Exception during ODataServiceFactory creation occured.", e);
     }

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/92531140/odata2-spring/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-spring/pom.xml b/odata2-spring/pom.xml
index ed1c7b3..1a10bb9 100755
--- a/odata2-spring/pom.xml
+++ b/odata2-spring/pom.xml
@@ -12,7 +12,7 @@
 <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>
-	<artifactId>odata2-spring</artifactId>
+	<artifactId>olingo-odata2-spring</artifactId>
 	<name>${project.artifactId}</name>
 
 	<parent>

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/92531140/odata2-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoRootLocator.java
----------------------------------------------------------------------
diff --git a/odata2-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoRootLocator.java b/odata2-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoRootLocator.java
index 4cfceea..82442d6 100644
--- a/odata2-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoRootLocator.java
+++ b/odata2-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoRootLocator.java
@@ -19,25 +19,9 @@
 package org.apache.olingo.odata2.spring;
 
 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.rest.ODataRedirectLocator;
-import org.apache.olingo.odata2.core.rest.ODataSubLocator;
-import org.apache.olingo.odata2.core.rest.SubLocatorParameter;
 import org.apache.olingo.odata2.core.rest.ODataRootLocator;
 
-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 java.util.List;
 
 /**
  * Default OData root locator responsible to handle the whole path and delegate all calls to a sub locator:<p>


[13/37] olingo-odata2 git commit: [OLINGO-526] Fix for Uni-Directional One to Many relationships

Posted by mi...@apache.org.
[OLINGO-526] Fix for Uni-Directional One to Many relationships

Signed-off-by: Chandan V A <ch...@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/bd0a1277
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata2/tree/bd0a1277
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata2/diff/bd0a1277

Branch: refs/heads/Olingo-129_PocJpaDataStore
Commit: bd0a12777286d180e182032230cf9f8a5ece6cf4
Parents: 9f39956
Author: Chandan V A <ch...@sap.com>
Authored: Sat Dec 20 09:51:05 2014 +0530
Committer: Chandan V A <ch...@sap.com>
Committed: Sat Dec 20 09:51:05 2014 +0530

----------------------------------------------------------------------
 .../odata2/jpa/processor/core/model/JPAEdmProperty.java     | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/bd0a1277/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmProperty.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmProperty.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmProperty.java
index 33f0c93..9bce9fc 100644
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmProperty.java
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmProperty.java
@@ -372,7 +372,14 @@ public class JPAEdmProperty extends JPAEdmBaseViewImpl implements
       String[] name = { null, null };
       name[0] = joinColumn.name().equals("") == true ? jpaAttribute.getName() : joinColumn.name();
 
-      EntityType<?> referencedEntityType = metaModel.entity(jpaAttribute.getJavaType());
+      EntityType<?> referencedEntityType = null;
+      if (jpaAttribute.isCollection()) {
+        referencedEntityType =
+            metaModel.entity(((PluralAttribute<?, ?, ?>) currentAttribute).getElementType().getJavaType());
+      } else {
+        referencedEntityType = metaModel.entity(jpaAttribute.getJavaType());
+      }
+
       if (joinColumn.referencedColumnName().equals("")) {
         for (Attribute<?, ?> referencedAttribute : referencedEntityType.getAttributes()) {
           if (referencedAttribute.getPersistentAttributeType() == PersistentAttributeType.BASIC &&


[11/37] olingo-odata2 git commit: [OLINGO-492] Call ODataCallback when using the servlet

Posted by mi...@apache.org.
[OLINGO-492] Call ODataCallback when using the servlet


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

Branch: refs/heads/Olingo-129_PocJpaDataStore
Commit: f40ea94c83f5e94fba8cdca98241a64735929222
Parents: fbfbff0
Author: Christian Amend <ch...@apache.org>
Authored: Wed Dec 17 17:46:10 2014 +0100
Committer: Christian Amend <ch...@apache.org>
Committed: Wed Dec 17 17:46:10 2014 +0100

----------------------------------------------------------------------
 .../core/servlet/ODataExceptionWrapper.java     | 29 +++++--
 .../odata2/core/servlet/ODataServlet.java       | 88 +++++++++++---------
 .../odata2/core/servlet/ODataServletTest.java   |  1 -
 .../odata2/fit/basic/NullServiceTest.java       |  2 +-
 .../odata2/testutil/fit/FitErrorCallback.java   |  1 -
 5 files changed, 71 insertions(+), 50 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/f40ea94c/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/ODataExceptionWrapper.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/ODataExceptionWrapper.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/ODataExceptionWrapper.java
index 7edd411..e2069d4 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/ODataExceptionWrapper.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/ODataExceptionWrapper.java
@@ -28,6 +28,7 @@ import java.util.Map.Entry;
 
 import javax.servlet.http.HttpServletRequest;
 
+import org.apache.olingo.odata2.api.ODataServiceFactory;
 import org.apache.olingo.odata2.api.batch.BatchException;
 import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
 import org.apache.olingo.odata2.api.ep.EntityProvider;
@@ -37,9 +38,11 @@ import org.apache.olingo.odata2.api.exception.ODataApplicationException;
 import org.apache.olingo.odata2.api.exception.ODataException;
 import org.apache.olingo.odata2.api.exception.ODataHttpException;
 import org.apache.olingo.odata2.api.exception.ODataMessageException;
+import org.apache.olingo.odata2.api.processor.ODataErrorCallback;
 import org.apache.olingo.odata2.api.processor.ODataErrorContext;
 import org.apache.olingo.odata2.api.processor.ODataResponse;
 import org.apache.olingo.odata2.core.commons.ContentType;
+import org.apache.olingo.odata2.core.ep.ProviderFacadeImpl;
 import org.apache.olingo.odata2.core.exception.MessageService;
 import org.apache.olingo.odata2.core.exception.MessageService.Message;
 import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
@@ -57,8 +60,9 @@ public class ODataExceptionWrapper {
   private final Locale messageLocale;
   private final URI requestUri;
   private final Map<String, List<String>> httpRequestHeaders;
+  private final ODataErrorCallback callback;
 
-  public ODataExceptionWrapper(final HttpServletRequest req) {
+  public ODataExceptionWrapper(final HttpServletRequest req, ODataServiceFactory serviceFactory) {
     try {
       requestUri = new URI(req.getRequestURI());
     } catch (URISyntaxException e) {
@@ -70,6 +74,7 @@ public class ODataExceptionWrapper {
     List<String> acceptHeaders = RestUtil.extractAcceptHeaders(req.getHeader("Accept"));
     contentType = getContentType(queryParameters, acceptHeaders).toContentTypeString();
     messageLocale = MessageService.getSupportedLocale(getLanguages(acceptableLanguages), DEFAULT_RESPONSE_LOCALE);
+    callback = serviceFactory.getCallback(ODataErrorCallback.class);
   }
 
   public ODataResponse wrapInExceptionResponse(final Exception exception) {
@@ -83,11 +88,11 @@ public class ODataExceptionWrapper {
       }
 
       ODataResponse oDataResponse;
-      // if (callback != null) {
-      // oDataResponse = handleErrorCallback(callback);
-      // } else {
-      oDataResponse = EntityProvider.writeErrorDocument(errorContext);
-      // }
+      if (callback != null) {
+        oDataResponse = handleErrorCallback(callback);
+      } else {
+        oDataResponse = EntityProvider.writeErrorDocument(errorContext);
+      }
       if (!oDataResponse.containsHeader(org.apache.olingo.odata2.api.commons.HttpHeaders.CONTENT_TYPE)) {
         oDataResponse = ODataResponse.fromResponse(oDataResponse).contentHeader(contentType).build();
       }
@@ -100,6 +105,18 @@ public class ODataExceptionWrapper {
     }
   }
 
+  private ODataResponse handleErrorCallback(final ODataErrorCallback callback) throws EntityProviderException {
+    ODataResponse oDataResponse;
+    try {
+      oDataResponse = callback.handleError(errorContext);
+    } catch (ODataApplicationException e) {
+      fillErrorContext(e);
+      enhanceContextWithApplicationException(e);
+      oDataResponse = new ProviderFacadeImpl().writeErrorDocument(errorContext);
+    }
+    return oDataResponse;
+  }
+
   private Exception extractException(final Exception exception) {
     if (exception instanceof ODataException) {
       ODataException odataException = (ODataException) exception;

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/f40ea94c/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/ODataServlet.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/ODataServlet.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/ODataServlet.java
index 465d52e..0973f33 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/ODataServlet.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/ODataServlet.java
@@ -62,84 +62,89 @@ public class ODataServlet extends HttpServlet {
     if (factoryClassName == null) {
       throw new ODataRuntimeException("config missing: org.apache.olingo.odata2.processor.factory");
     }
+
+    // We have to create the Service Factory here because otherwise we do not have access to the error callback
+    ODataServiceFactory serviceFactory = createServiceFactory(req);
+
     String xHttpMethod = req.getHeader("X-HTTP-Method");
     String xHttpMethodOverride = req.getHeader("X-HTTP-Method-Override");
     if (xHttpMethod != null && xHttpMethodOverride != null) {
       if (!xHttpMethod.equalsIgnoreCase(xHttpMethodOverride)) {
-        ODataExceptionWrapper wrapper = new ODataExceptionWrapper(req);
+        ODataExceptionWrapper wrapper = new ODataExceptionWrapper(req, serviceFactory);
         createResponse(resp, wrapper.wrapInExceptionResponse(
             new ODataBadRequestException(ODataBadRequestException.AMBIGUOUS_XMETHOD)));
       }
     }
 
     if (req.getPathInfo() != null) {
-      handle(req, resp, xHttpMethod, xHttpMethodOverride);
+      handle(req, resp, xHttpMethod, xHttpMethodOverride, serviceFactory);
     } else {
-      handleRedirect(req, resp);
+      handleRedirect(req, resp, serviceFactory);
     }
   }
 
   private void handle(final HttpServletRequest req, final HttpServletResponse resp, final String xHttpMethod,
-      final String xHttpMethodOverride) throws IOException {
+      final String xHttpMethodOverride, ODataServiceFactory serviceFactory) throws IOException {
     String method = req.getMethod();
     if (ODataHttpMethod.GET.name().equals(method)) {
-      handleRequest(req, ODataHttpMethod.GET, resp);
+      handleRequest(req, ODataHttpMethod.GET, resp, serviceFactory);
     } else if (ODataHttpMethod.POST.name().equals(method)) {
       if (xHttpMethod == null && xHttpMethodOverride == null) {
-        handleRequest(req, ODataHttpMethod.POST, resp);
+        handleRequest(req, ODataHttpMethod.POST, resp, serviceFactory);
       } else if (xHttpMethod == null) {
         /* tunneling */
-        boolean methodHandled = handleHttpTunneling(req, resp, xHttpMethodOverride);
+        boolean methodHandled = handleHttpTunneling(req, resp, xHttpMethodOverride, serviceFactory);
         if (!methodHandled) {
-          createMethodNotAllowedResponse(req, ODataHttpException.COMMON, resp);
+          createMethodNotAllowedResponse(req, ODataHttpException.COMMON, resp, serviceFactory);
         }
       } else {
         /* tunneling */
-        boolean methodHandled = handleHttpTunneling(req, resp, xHttpMethod);
+        boolean methodHandled = handleHttpTunneling(req, resp, xHttpMethod, serviceFactory);
         if (!methodHandled) {
-          createNotImplementedResponse(req, ODataNotImplementedException.TUNNELING, resp);
+          createNotImplementedResponse(req, ODataNotImplementedException.TUNNELING, resp, serviceFactory);
         }
       }
 
     } else if (ODataHttpMethod.PUT.name().equals(method)) {
-      handleRequest(req, ODataHttpMethod.PUT, resp);
+      handleRequest(req, ODataHttpMethod.PUT, resp, serviceFactory);
     } else if (ODataHttpMethod.DELETE.name().equals(method)) {
-      handleRequest(req, ODataHttpMethod.DELETE, resp);
+      handleRequest(req, ODataHttpMethod.DELETE, resp, serviceFactory);
     } else if (ODataHttpMethod.PATCH.name().equals(method)) {
-      handleRequest(req, ODataHttpMethod.PATCH, resp);
+      handleRequest(req, ODataHttpMethod.PATCH, resp, serviceFactory);
     } else if (ODataHttpMethod.MERGE.name().equals(method)) {
-      handleRequest(req, ODataHttpMethod.MERGE, resp);
+      handleRequest(req, ODataHttpMethod.MERGE, resp, serviceFactory);
     } else if (HTTP_METHOD_HEAD.equals(method) || HTTP_METHOD_OPTIONS.equals(method)) {
-      createNotImplementedResponse(req, ODataNotImplementedException.COMMON, resp);
+      createNotImplementedResponse(req, ODataNotImplementedException.COMMON, resp, serviceFactory);
     } else {
-      createNotImplementedResponse(req, ODataHttpException.COMMON, resp);
+      createNotImplementedResponse(req, ODataHttpException.COMMON, resp, serviceFactory);
     }
   }
 
   private boolean handleHttpTunneling(final HttpServletRequest req, final HttpServletResponse resp,
-      final String xHttpMethod) throws IOException {
+      final String xHttpMethod, ODataServiceFactory serviceFactory) throws IOException {
     if (ODataHttpMethod.MERGE.name().equals(xHttpMethod)) {
-      handleRequest(req, ODataHttpMethod.MERGE, resp);
+      handleRequest(req, ODataHttpMethod.MERGE, resp, serviceFactory);
     } else if (ODataHttpMethod.PATCH.name().equals(xHttpMethod)) {
-      handleRequest(req, ODataHttpMethod.PATCH, resp);
+      handleRequest(req, ODataHttpMethod.PATCH, resp, serviceFactory);
     } else if (ODataHttpMethod.DELETE.name().equals(xHttpMethod)) {
-      handleRequest(req, ODataHttpMethod.DELETE, resp);
+      handleRequest(req, ODataHttpMethod.DELETE, resp, serviceFactory);
     } else if (ODataHttpMethod.PUT.name().equals(xHttpMethod)) {
-      handleRequest(req, ODataHttpMethod.PUT, resp);
+      handleRequest(req, ODataHttpMethod.PUT, resp, serviceFactory);
     } else if (ODataHttpMethod.GET.name().equals(xHttpMethod)) {
-      handleRequest(req, ODataHttpMethod.GET, resp);
+      handleRequest(req, ODataHttpMethod.GET, resp, serviceFactory);
     } else if (ODataHttpMethod.POST.name().equals(xHttpMethod)) {
-      handleRequest(req, ODataHttpMethod.POST, resp);
+      handleRequest(req, ODataHttpMethod.POST, resp, serviceFactory);
     } else if (HTTP_METHOD_HEAD.equals(xHttpMethod) || HTTP_METHOD_OPTIONS.equals(xHttpMethod)) {
-      createNotImplementedResponse(req, ODataNotImplementedException.COMMON, resp);
+      createNotImplementedResponse(req, ODataNotImplementedException.COMMON, resp, serviceFactory);
     } else {
-      createNotImplementedResponse(req, ODataNotImplementedException.COMMON, resp);
+      createNotImplementedResponse(req, ODataNotImplementedException.COMMON, resp, serviceFactory);
     }
     return true;
   }
 
   private void
-      handleRequest(final HttpServletRequest req, final ODataHttpMethod method, final HttpServletResponse resp)
+      handleRequest(final HttpServletRequest req, final ODataHttpMethod method, final HttpServletResponse resp,
+          ODataServiceFactory serviceFactory)
           throws IOException {
     try {
       final String pathSplitAsString = getInitParameter(ODataServiceFactory.PATH_SPLIT_LABEL);
@@ -148,7 +153,7 @@ public class ODataServlet extends HttpServlet {
         pathSplit = Integer.parseInt(pathSplitAsString);
       }
       if (req.getHeader(HttpHeaders.ACCEPT) != null && req.getHeader(HttpHeaders.ACCEPT).isEmpty()) {
-        createNotAcceptableResponse(req, ODataNotAcceptableException.COMMON, resp);
+        createNotAcceptableResponse(req, ODataNotAcceptableException.COMMON, resp, serviceFactory);
       }
       ODataRequest odataRequest = ODataRequest.method(method)
           .contentType(RestUtil.extractRequestContentType(req.getContentType()).toContentTypeString())
@@ -159,13 +164,13 @@ public class ODataServlet extends HttpServlet {
           .requestHeaders(RestUtil.extractHeaders(req))
           .body(req.getInputStream())
           .build();
-      ODataServiceFactory serviceFactory = createServiceFactory(req);
+
       ODataContextImpl context = new ODataContextImpl(odataRequest, serviceFactory);
       context.setParameter(ODataContext.HTTP_SERVLET_REQUEST_OBJECT, req);
 
       ODataService service = serviceFactory.createService(context);
-      if(service == null){
-        createServiceUnavailableResponse(req, ODataInternalServerErrorException.NOSERVICE, resp);
+      if (service == null) {
+        createServiceUnavailableResponse(req, ODataInternalServerErrorException.NOSERVICE, resp, serviceFactory);
       } else {
         context.setService(service);
         service.getProcessor().setContext(context);
@@ -175,7 +180,7 @@ public class ODataServlet extends HttpServlet {
         createResponse(resp, odataResponse);
       }
     } catch (ODataException e) {
-      ODataExceptionWrapper wrapper = new ODataExceptionWrapper(req);
+      ODataExceptionWrapper wrapper = new ODataExceptionWrapper(req, serviceFactory);
       createResponse(resp, wrapper.wrapInExceptionResponse(e));
     }
   }
@@ -194,7 +199,8 @@ public class ODataServlet extends HttpServlet {
     }
   }
 
-  private void handleRedirect(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
+  private void handleRedirect(final HttpServletRequest req, final HttpServletResponse resp,
+      ODataServiceFactory serviceFactory) throws IOException {
     String method = req.getMethod();
     if (ODataHttpMethod.GET.name().equals(method) ||
         ODataHttpMethod.POST.name().equals(method) ||
@@ -209,7 +215,7 @@ public class ODataServlet extends HttpServlet {
           .build();
       createResponse(resp, odataResponse);
     } else {
-      createNotImplementedResponse(req, ODataHttpException.COMMON, resp);
+      createNotImplementedResponse(req, ODataHttpException.COMMON, resp, serviceFactory);
     }
 
   }
@@ -255,10 +261,10 @@ public class ODataServlet extends HttpServlet {
   }
 
   private void createNotImplementedResponse(final HttpServletRequest req, final MessageReference messageReference,
-      final HttpServletResponse resp) throws IOException {
+      final HttpServletResponse resp, ODataServiceFactory serviceFactory) throws IOException {
     // RFC 2616, 5.1.1: "An origin server SHOULD return the status code [...]
     // 501 (Not Implemented) if the method is unrecognized [...] by the origin server."
-    ODataExceptionWrapper exceptionWrapper = new ODataExceptionWrapper(req);
+    ODataExceptionWrapper exceptionWrapper = new ODataExceptionWrapper(req, serviceFactory);
     ODataResponse response =
         exceptionWrapper.wrapInExceptionResponse(new ODataNotImplementedException(messageReference));
 //    resp.setStatus(HttpStatusCodes.NOT_IMPLEMENTED.getStatusCode());
@@ -266,24 +272,24 @@ public class ODataServlet extends HttpServlet {
   }
 
   private void createMethodNotAllowedResponse(final HttpServletRequest req, final MessageReference messageReference,
-      final HttpServletResponse resp) throws IOException {
-    ODataExceptionWrapper exceptionWrapper = new ODataExceptionWrapper(req);
+      final HttpServletResponse resp, ODataServiceFactory serviceFactory) throws IOException {
+    ODataExceptionWrapper exceptionWrapper = new ODataExceptionWrapper(req, serviceFactory);
     ODataResponse response =
         exceptionWrapper.wrapInExceptionResponse(new ODataMethodNotAllowedException(messageReference));
     createResponse(resp, response);
   }
 
   private void createNotAcceptableResponse(final HttpServletRequest req, final MessageReference messageReference,
-      final HttpServletResponse resp) throws IOException {
-    ODataExceptionWrapper exceptionWrapper = new ODataExceptionWrapper(req);
+      final HttpServletResponse resp, ODataServiceFactory serviceFactory) throws IOException {
+    ODataExceptionWrapper exceptionWrapper = new ODataExceptionWrapper(req, serviceFactory);
     ODataResponse response =
         exceptionWrapper.wrapInExceptionResponse(new ODataNotAcceptableException(messageReference));
     createResponse(resp, response);
   }
 
   private void createServiceUnavailableResponse(HttpServletRequest req, MessageReference messageReference,
-      HttpServletResponse resp) throws IOException {
-    ODataExceptionWrapper exceptionWrapper = new ODataExceptionWrapper(req);
+      HttpServletResponse resp, ODataServiceFactory serviceFactory) throws IOException {
+    ODataExceptionWrapper exceptionWrapper = new ODataExceptionWrapper(req, serviceFactory);
     ODataResponse response =
         exceptionWrapper.wrapInExceptionResponse(new ODataInternalServerErrorException(messageReference));
     createResponse(resp, response);

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/f40ea94c/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/servlet/ODataServletTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/servlet/ODataServletTest.java b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/servlet/ODataServletTest.java
index 1c74fc0..2f877d2 100644
--- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/servlet/ODataServletTest.java
+++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/servlet/ODataServletTest.java
@@ -110,5 +110,4 @@ public class ODataServletTest {
     String factoryClassName = ODataServiceFactoryImpl.class.getName();
     Mockito.when(configMock.getInitParameter(ODataServiceFactory.FACTORY_LABEL)).thenReturn(factoryClassName);
   }
-
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/f40ea94c/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/NullServiceTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/NullServiceTest.java b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/NullServiceTest.java
index 58b9aba..9f7ac08 100644
--- a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/NullServiceTest.java
+++ b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/NullServiceTest.java
@@ -48,7 +48,7 @@ public class NullServiceTest extends AbstractFitTest {
 
   @Test
   public void nullServiceMustResultInODataResponse() throws Exception {
-    System.out.println("The following internal Server Error is wanted if this test doesnt fail!");
+    disableLogging();
     final HttpResponse response = executeGetRequest("$metadata");
     assertEquals(HttpStatusCodes.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusLine().getStatusCode());
 

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/f40ea94c/odata2-lib/odata-testutil/src/main/java/org/apache/olingo/odata2/testutil/fit/FitErrorCallback.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-testutil/src/main/java/org/apache/olingo/odata2/testutil/fit/FitErrorCallback.java b/odata2-lib/odata-testutil/src/main/java/org/apache/olingo/odata2/testutil/fit/FitErrorCallback.java
index fb8ff25..d63ff44 100644
--- a/odata2-lib/odata-testutil/src/main/java/org/apache/olingo/odata2/testutil/fit/FitErrorCallback.java
+++ b/odata2-lib/odata-testutil/src/main/java/org/apache/olingo/odata2/testutil/fit/FitErrorCallback.java
@@ -39,7 +39,6 @@ public class FitErrorCallback implements ODataErrorCallback {
     if (context.getHttpStatus() == HttpStatusCodes.INTERNAL_SERVER_ERROR) {
       LOG.error("Internal Server Error", context.getException());
     }
-
     return EntityProvider.writeErrorDocument(context);
   }
 


[34/37] olingo-odata2 git commit: [OLINGO-539] Fixed wrong exception message and javadoc

Posted by mi...@apache.org.
[OLINGO-539] Fixed wrong exception message and javadoc


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

Branch: refs/heads/Olingo-129_PocJpaDataStore
Commit: c9db4f5300b12dd98215bd501ca7bb06a65b77c1
Parents: 1ade40d
Author: Michael Bolz <mi...@sap.com>
Authored: Fri Jan 16 08:56:43 2015 +0100
Committer: Michael Bolz <mi...@sap.com>
Committed: Fri Jan 16 08:56:43 2015 +0100

----------------------------------------------------------------------
 .../olingo/odata2/jpa/processor/api/ODataJPAServiceFactory.java  | 4 ++--
 .../java/org/apache/olingo/odata2/core/servlet/ODataServlet.java | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/c9db4f53/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPAServiceFactory.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPAServiceFactory.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPAServiceFactory.java
index 82aa68d..709a048 100644
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPAServiceFactory.java
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPAServiceFactory.java
@@ -63,8 +63,8 @@ import org.apache.olingo.odata2.jpa.processor.api.factory.ODataJPAFactory;
  *    <param-value>org.apache.olingo.odata2.core.rest.ODataApplication</param-value>
  *  </init-param>
  *  <init-param>
- *    <param-name>org.apache.olingo.odata2.processor.factory</param-name>
- *    <param-value>foo.bar.sample.processor.SampleProcessorFactory</param-value>
+ *    <param-name>org.apache.olingo.odata2.service.factory</param-name>
+ *    <param-value>foo.bar.sample.service.SampleProcessorFactory</param-value>
  *  </init-param>
  *  <init-param>
  *    <param-name>org.apache.olingo.odata2.path.split</param-name>

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/c9db4f53/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/ODataServlet.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/ODataServlet.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/ODataServlet.java
index f0b5c6b..5607025 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/ODataServlet.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/ODataServlet.java
@@ -59,7 +59,7 @@ public class ODataServlet extends HttpServlet {
   protected void service(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
     final String factoryClassName = getInitParameter(ODataServiceFactory.FACTORY_LABEL);
     if (factoryClassName == null) {
-      throw new ODataRuntimeException("config missing: org.apache.olingo.odata2.processor.factory");
+      throw new ODataRuntimeException("config missing: " + ODataServiceFactory.FACTORY_LABEL);
     }
 
     // We have to create the Service Factory here because otherwise we do not have access to the error callback


[22/37] olingo-odata2 git commit: [OLINGO-476] Start with support for Java enum

Posted by mi...@apache.org.
[OLINGO-476] Start with support for Java enum


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

Branch: refs/heads/Olingo-129_PocJpaDataStore
Commit: 81bde4ff12f28f96cea0dadc59d728dab71780d6
Parents: e80f019
Author: mibo <mi...@mirb.de>
Authored: Fri Jan 9 20:39:50 2015 +0100
Committer: mibo <mi...@mirb.de>
Committed: Fri Jan 9 20:46:24 2015 +0100

----------------------------------------------------------------------
 .../core/access/model/JPATypeConvertor.java     |  3 +++
 .../core/access/model/JPATypeConvertorTest.java |  6 +++++
 .../jpa/processor/ref/model/Customer.java       | 20 +++++++++++------
 .../jpa/processor/ref/model/Importance.java     | 23 ++++++++++++++++++++
 .../resources/SQL_Insert_Customer.properties    | 10 ++++-----
 5 files changed, 50 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/81bde4ff/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPATypeConvertor.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPATypeConvertor.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPATypeConvertor.java
index 10a6d73..af8508f 100644
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPATypeConvertor.java
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPATypeConvertor.java
@@ -105,7 +105,10 @@ public class JPATypeConvertor {
       return EdmSimpleTypeKind.Binary;
     } else if (jpaType.equals(Clob.class) && isBlob(currentAttribute)) {
       return EdmSimpleTypeKind.String;
+    } else if (jpaType.isEnum()) {
+      return EdmSimpleTypeKind.String;
     }
+
     throw ODataJPAModelException.throwException(ODataJPAModelException.TYPE_NOT_SUPPORTED
         .addContent(jpaType.toString()), null);
   }

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/81bde4ff/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPATypeConvertorTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPATypeConvertorTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPATypeConvertorTest.java
index 29462c9..9325973 100644
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPATypeConvertorTest.java
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPATypeConvertorTest.java
@@ -42,6 +42,9 @@ public class JPATypeConvertorTest {
   private EdmSimpleTypeKind edmSimpleKindTypeByte;
   private EdmSimpleTypeKind edmSimpleKindTypeBoolean;
   private EdmSimpleTypeKind edmSimpleKindTypeUUID;
+  private EdmSimpleTypeKind edmSimpleKindTypeStringFromEnum;
+
+  enum SomeEnum {TEST}
 
   @Test
   public void testConvertToEdmSimpleType() {
@@ -56,6 +59,7 @@ public class JPATypeConvertorTest {
     Byte byteObj = new Byte((byte) 0);
     Boolean booleanObj = Boolean.TRUE;
     UUID uUID = new UUID(0, 0);
+    SomeEnum someEnum = SomeEnum.TEST;
 
     try {
       edmSimpleKindTypeString = JPATypeConvertor.convertToEdmSimpleType(str.getClass(), null);
@@ -68,6 +72,7 @@ public class JPATypeConvertorTest {
       edmSimpleKindTypeBigDecimal = JPATypeConvertor.convertToEdmSimpleType(bigDecimalObj.getClass(), null);
       edmSimpleKindTypeByte = JPATypeConvertor.convertToEdmSimpleType(byteObj.getClass(), null);
       edmSimpleKindTypeBoolean = JPATypeConvertor.convertToEdmSimpleType(booleanObj.getClass(), null);
+      edmSimpleKindTypeStringFromEnum = JPATypeConvertor.convertToEdmSimpleType(someEnum.getClass(), null);
       /*
        * edmSimpleKindTypeDate = JPATypeConvertor
        * .convertToEdmSimpleType(dateObj.getClass(),null);
@@ -89,6 +94,7 @@ public class JPATypeConvertorTest {
     assertEquals(EdmSimpleTypeKind.Boolean, edmSimpleKindTypeBoolean);
     // assertEquals(EdmSimpleTypeKind.DateTime, edmSimpleKindTypeDate);
     assertEquals(EdmSimpleTypeKind.Guid, edmSimpleKindTypeUUID);
+    assertEquals(EdmSimpleTypeKind.String, edmSimpleKindTypeStringFromEnum);
   }
 
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/81bde4ff/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/Customer.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/Customer.java b/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/Customer.java
index 12e38ac..3333b1f 100644
--- a/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/Customer.java
+++ b/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/Customer.java
@@ -23,6 +23,8 @@ import java.sql.Timestamp;
 import javax.persistence.Column;
 import javax.persistence.Embedded;
 import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
 import javax.persistence.FetchType;
 import javax.persistence.Id;
 import javax.persistence.JoinColumn;
@@ -40,6 +42,10 @@ public class Customer extends CustomerBase {
   @Column(name = "NAME")
   private String name;
 
+  @Enumerated(EnumType.STRING)
+  @Column(name = "IMPORTANCE")
+  private Importance importance;
+
   @Embedded
   private Address address;
 
@@ -77,13 +83,13 @@ public class Customer extends CustomerBase {
     this.name = name;
   }
 
-//  public List<SalesOrderHeader> getOrders() {
-//    return orders;
-//  }
-//
-//  public void setOrders(final List<SalesOrderHeader> orders) {
-//    this.orders = orders;
-//  }
+  public Importance getImportance() {
+    return importance;
+  }
+
+  public void setImportance(Importance importance) {
+    this.importance = importance;
+  }
 
   public Address getAddress() {
     return address;

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/81bde4ff/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/Importance.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/Importance.java b/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/Importance.java
new file mode 100644
index 0000000..6cd8057
--- /dev/null
+++ b/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/Importance.java
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * 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.jpa.processor.ref.model;
+
+public enum Importance {
+  LOW, MEDIUM, HIGH, VIP
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/81bde4ff/odata2-jpa-processor/jpa-web/src/main/resources/SQL_Insert_Customer.properties
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-web/src/main/resources/SQL_Insert_Customer.properties b/odata2-jpa-processor/jpa-web/src/main/resources/SQL_Insert_Customer.properties
index a42f23e..16e13bd 100644
--- a/odata2-jpa-processor/jpa-web/src/main/resources/SQL_Insert_Customer.properties
+++ b/odata2-jpa-processor/jpa-web/src/main/resources/SQL_Insert_Customer.properties
@@ -16,8 +16,8 @@
 #        specific language governing permissions and limitations
 #        under the License.
 #-------------------------------------------------------------------------------
-query_1 = INSERT INTO T_CUSTOMER (ID , NAME, HOUSE_NUMBER , STREET_NAME, CITY, COUNTRY, PINCODE,CREATED_AT) VALUES(100,'Bob Bryan',7,'5 cross Street', 'London', 'UK',  'E7','2012-11-01 00:01:00');
-query_2 = INSERT INTO T_CUSTOMER (ID , NAME, HOUSE_NUMBER , STREET_NAME, CITY, COUNTRY, PINCODE,CREATED_AT) VALUES(200,'Mike Bryan',7,'8 cross Street', 'New York', 'USA',  '10011','2012-11-01 00:01:00');
-query_3 = INSERT INTO T_CUSTOMER (ID , NAME, HOUSE_NUMBER , STREET_NAME, CITY, COUNTRY, PINCODE,CREATED_AT) VALUES(201,'Steve Roger',7,'9 cross Street', 'Mumbai', 'India', '200101','2012-11-01 00:01:00');
-query_4 = INSERT INTO T_CUSTOMER (ID , NAME, HOUSE_NUMBER , STREET_NAME, CITY, COUNTRY, PINCODE,CREATED_AT) VALUES(101,'Pac Man',7,'25 cross Street', 'Frankfurt', 'Germany',  '60001','2012-11-01 00:01:00');
-query_5 = INSERT INTO T_CUSTOMER (ID , NAME, HOUSE_NUMBER , STREET_NAME, CITY, COUNTRY, PINCODE,CREATED_AT) VALUES(202,'Bolt Man',7,'25 cross Street', 'Toronto', 'Canada',  'NE','2012-11-01 00:01:00');
\ No newline at end of file
+query_1 = INSERT INTO T_CUSTOMER (ID , NAME, IMPORTANCE, HOUSE_NUMBER , STREET_NAME, CITY, COUNTRY, PINCODE,CREATED_AT) VALUES(100,'Bob Bryan','VIP',7,'5 cross Street', 'London', 'UK',  'E7','2012-11-01 00:01:00');
+query_2 = INSERT INTO T_CUSTOMER (ID , NAME, IMPORTANCE, HOUSE_NUMBER , STREET_NAME, CITY, COUNTRY, PINCODE,CREATED_AT) VALUES(200,'Mike Bryan','LOW',7,'8 cross Street', 'New York', 'USA',  '10011','2012-11-01 00:01:00');
+query_3 = INSERT INTO T_CUSTOMER (ID , NAME, IMPORTANCE, HOUSE_NUMBER , STREET_NAME, CITY, COUNTRY, PINCODE,CREATED_AT) VALUES(201,'Steve Roger','LOW',7,'9 cross Street', 'Mumbai', 'India', '200101','2012-11-01 00:01:00');
+query_4 = INSERT INTO T_CUSTOMER (ID , NAME, IMPORTANCE, HOUSE_NUMBER , STREET_NAME, CITY, COUNTRY, PINCODE,CREATED_AT) VALUES(101,'Pac Man','LOW',7,'25 cross Street', 'Frankfurt', 'Germany',  '60001','2012-11-01 00:01:00');
+query_5 = INSERT INTO T_CUSTOMER (ID , NAME, IMPORTANCE, HOUSE_NUMBER , STREET_NAME, CITY, COUNTRY, PINCODE,CREATED_AT) VALUES(202,'Bolt Man','LOW',7,'25 cross Street', 'Toronto', 'Canada',  'NE','2012-11-01 00:01:00');
\ No newline at end of file


[36/37] olingo-odata2 git commit: [OLINGO-476] Merge branch 'OLINGO-476_SupportJavaEnums'

Posted by mi...@apache.org.
[OLINGO-476] Merge branch 'OLINGO-476_SupportJavaEnums'


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

Branch: refs/heads/Olingo-129_PocJpaDataStore
Commit: 5bb61bf2c9ae753958e18e0e51b1f8b33ec38ad4
Parents: f373225 f53eda4
Author: mibo <mi...@mirb.de>
Authored: Mon Jan 19 21:35:08 2015 +0100
Committer: mibo <mi...@mirb.de>
Committed: Mon Jan 19 21:35:08 2015 +0100

----------------------------------------------------------------------
 .../processor/core/access/data/JPAEntity.java   |  3 +++
 .../core/access/model/JPATypeConvertor.java     |  3 +++
 .../core/access/data/JPAEntityTest.java         |  2 ++
 .../core/access/model/JPATypeConvertorTest.java |  6 +++++
 .../processor/core/mock/data/EdmMockUtilV2.java |  8 +++++++
 .../processor/core/mock/data/JPATypeMock.java   | 12 ++++++++++
 .../core/mock/data/ODataEntryMockUtil.java      |  2 ++
 .../jpa/processor/ref/model/Customer.java       | 20 +++++++++++------
 .../jpa/processor/ref/model/Importance.java     | 23 ++++++++++++++++++++
 .../resources/SQL_Insert_Customer.properties    | 10 ++++-----
 10 files changed, 77 insertions(+), 12 deletions(-)
----------------------------------------------------------------------



[37/37] olingo-odata2 git commit: [OLINGO-129] Merge with master branch

Posted by mi...@apache.org.
[OLINGO-129] Merge with master branch


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

Branch: refs/heads/Olingo-129_PocJpaDataStore
Commit: 13b99eab05d6ec637c9b6cf118abe25b82a3e610
Parents: 7224e85 5bb61bf
Author: mibo <mi...@mirb.de>
Authored: Tue Jan 27 20:01:50 2015 +0100
Committer: mibo <mi...@mirb.de>
Committed: Tue Jan 27 20:01:50 2015 +0100

----------------------------------------------------------------------
 .../core/datasource/AnnotationDataSource.java   |   7 +-
 .../core/edm/AnnotationEdmProvider.java         |  39 ++-
 .../processor/core/util/AnnotationHelper.java   | 170 ++++++++++---
 .../processor/core/util/ClassHelper.java        |  16 ++
 .../core/edm/AnnotationEdmProviderTest.java     |  36 +--
 .../annotation/processor/core/model/Team.java   |   6 +
 .../core/util/AnnotationHelperTest.java         |  22 +-
 .../ref/AnnotationRefServiceFactory.java        |   9 +-
 .../annotation/processor/ref/model/Team.java    |  10 +
 .../annotation/processor/ref/MetadataTest.java  |  70 ++++--
 .../processor/api/ODataJPAServiceFactory.java   |   4 +-
 .../api/exception/ODataJPAModelException.java   |   2 +
 .../processor/api/factory/JPAAccessFactory.java |   7 +
 .../core/ODataJPAProcessorDefault.java          |  58 ++---
 .../core/ODataJPAResponseBuilderDefault.java    |   9 +-
 .../processor/core/access/data/JPAEntity.java   |   3 +
 .../core/access/model/JPAEdmNameBuilder.java    |  87 +++++--
 .../core/access/model/JPATypeConvertor.java     |   3 +
 .../core/factory/ODataJPAFactoryImpl.java       |   7 +
 .../processor/core/model/JPAEdmAssociation.java |   7 +-
 .../processor/core/model/JPAEdmEntityType.java  |  12 +-
 .../processor/core/model/JPAEdmProperty.java    |  33 ++-
 .../model/JPAEdmReferentialConstraintRole.java  |   8 +-
 .../main/resources/jpaprocessor_msg.properties  |   2 +-
 .../core/access/data/JPAEntityTest.java         |   2 +
 .../core/access/model/JPATypeConvertorTest.java |   6 +
 .../processor/core/mock/data/EdmMockUtilV2.java |   8 +
 .../processor/core/mock/data/JPATypeMock.java   |  12 +
 .../core/mock/data/ODataEntryMockUtil.java      |   2 +
 .../core/model/JPAEdmPropertyTest.java          | 226 +++++++++++++----
 .../jpa/processor/ref/model/Customer.java       |  20 +-
 .../jpa/processor/ref/model/Importance.java     |  23 ++
 .../processor/ref/util/CustomerImageLoader.java |  49 ++++
 .../jpa-ref/src/main/resources/Customer_1.png   | Bin 0 -> 8429 bytes
 .../jpa-ref/src/main/resources/Customer_2.png   | Bin 0 -> 12212 bytes
 .../ref/extension/CustomerImageProcessor.java   |  35 +++
 .../SalesOrderProcessingExtension.java          |   1 +
 .../resources/SQL_Insert_Customer.properties    |  10 +-
 .../odata2/core/batch/BatchRequestWriter.java   |   3 +-
 .../odata2/core/batch/BatchResponseWriter.java  |  31 +--
 .../core/ep/consumer/XmlMetadataConsumer.java   |  25 +-
 .../odata2/core/rest/ODataRootLocator.java      |  30 ++-
 .../olingo/odata2/core/rest/RestUtil.java       |   8 +-
 .../core/servlet/ODataExceptionWrapper.java     |  29 ++-
 .../odata2/core/servlet/ODataServlet.java       | 110 +++++----
 .../olingo/odata2/core/servlet/RestUtil.java    |  27 ++-
 .../odata2/core/batch/BatchRequestTest.java     |   8 +-
 .../core/batch/BatchRequestWriterITTest.java    | 243 +++++++++++++++++++
 .../core/batch/BatchRequestWriterTest.java      | 214 ++++++++++------
 .../core/batch/BatchResponseParserTest.java     | 120 ++++++++-
 .../odata2/core/batch/BatchResponseTest.java    |   2 +-
 .../core/batch/BatchResponseWriterITTest.java   | 179 ++++++++++++++
 .../core/batch/BatchResponseWriterTest.java     | 128 +++++++---
 .../ep/consumer/XmlMetadataConsumerTest.java    | 116 ++++++++-
 .../odata2/core/servlet/ODataServletTest.java   |  83 ++++++-
 .../odata2/fit/basic/NullServiceTest.java       |   2 +-
 .../odata2/testutil/fit/FitErrorCallback.java   |   1 -
 odata2-spring/.springBeans                      |  26 ++
 odata2-spring/pom.xml                           |  86 +++++++
 .../odata2/spring/OlingoNamespaceHandler.java   |  29 +++
 .../olingo/odata2/spring/OlingoRootLocator.java |  62 +++++
 .../spring/OlingoServerDefinitionParser.java    |  96 ++++++++
 .../src/main/resources/META-INF/spring.handlers |   8 +
 .../src/main/resources/META-INF/spring.schemas  |   8 +
 .../src/main/resources/schema/olingo.xsd        |  32 +++
 .../spring/SpringNamespaceHandlerTest.java      |  71 ++++++
 .../olingo/odata2/spring/TestFactory.java       |  39 +++
 .../resources/spring/applicationContext.xml     |  33 +++
 pom.xml                                         |   4 +
 69 files changed, 2417 insertions(+), 457 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/13b99eab/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/datasource/AnnotationDataSource.java
----------------------------------------------------------------------
diff --cc odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/datasource/AnnotationDataSource.java
index b2b44ba,0000000..eb22f81
mode 100644,000000..100644
--- a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/datasource/AnnotationDataSource.java
+++ b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/datasource/AnnotationDataSource.java
@@@ -1,438 -1,0 +1,443 @@@
 +/**
 + * *****************************************************************************
 + * 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.annotation.processor.core.datasource;
 +
 +import java.lang.reflect.Field;
 +import java.util.ArrayList;
 +import java.util.Collection;
 +import java.util.Collections;
 +import java.util.HashMap;
 +import java.util.List;
 +import java.util.Map;
 +
 +import org.apache.olingo.odata2.annotation.processor.core.util.AnnotationHelper;
 +import org.apache.olingo.odata2.annotation.processor.core.util.AnnotationHelper.AnnotatedNavInfo;
 +import org.apache.olingo.odata2.annotation.processor.core.util.AnnotationHelper.ODataAnnotationException;
 +import org.apache.olingo.odata2.annotation.processor.core.util.AnnotationRuntimeException;
 +import org.apache.olingo.odata2.annotation.processor.core.util.ClassHelper;
 +import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
 +import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceContent;
 +import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceMimeType;
 +import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
 +import org.apache.olingo.odata2.api.edm.EdmEntitySet;
 +import org.apache.olingo.odata2.api.edm.EdmException;
 +import org.apache.olingo.odata2.api.edm.EdmFunctionImport;
 +import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
 +import org.apache.olingo.odata2.api.exception.ODataApplicationException;
 +import org.apache.olingo.odata2.api.exception.ODataException;
 +import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
 +import org.apache.olingo.odata2.api.exception.ODataNotImplementedException;
 +
 +public class AnnotationDataSource implements DataSource {
 +
 +  private static final AnnotationHelper ANNOTATION_HELPER = new AnnotationHelper();
 +  private static final String DEFAULT_PERSISTENCE = Boolean.TRUE.toString();
 +
 +  private final Map<String, DataStore<Object>> dataStores = new HashMap<String, DataStore<Object>>();
 +  private final DataStoreFactory dataStoreFactory;
 +
 +  public AnnotationDataSource(final Collection<Class<?>> annotatedClasses) throws ODataException {
 +    this(annotatedClasses, new DualDataStoreFactory());
 +    dataStoreFactory.setDefaultProperty(DataStoreFactory.KEEP_PERSISTENT, DEFAULT_PERSISTENCE);
 +  }
 +
 +  public AnnotationDataSource(final Collection<Class<?>> annotatedClasses, final DataStoreFactory dataStoreFactory)
 +      throws ODataException {
 +    this.dataStoreFactory = dataStoreFactory;
 +    
 +    init(annotatedClasses);
 +  }
 +
 +  public AnnotationDataSource(final String packageToScan) throws ODataException {
 +    this(packageToScan, new DualDataStoreFactory());
 +    dataStoreFactory.setDefaultProperty(DataStoreFactory.KEEP_PERSISTENT, DEFAULT_PERSISTENCE);
 +  }
 +
 +  public AnnotationDataSource(final String packageToScan, final DataStoreFactory dataStoreFactory) 
 +          throws ODataException {
 +    this.dataStoreFactory = dataStoreFactory;
 +
 +    List<Class<?>> foundClasses = ClassHelper.loadClasses(packageToScan, new ClassHelper.ClassValidator() {
 +      @Override
 +      public boolean isClassValid(final Class<?> c) {
 +        return null != c.getAnnotation(org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet.class);
 +      }
 +    });
 +
 +    init(foundClasses);
 +  }
 +
 +  @SuppressWarnings("unchecked")
 +  private void init(final Collection<Class<?>> annotatedClasses) throws ODataException {
 +    try {
 +      for (Class<?> clz : annotatedClasses) {
 +        String entitySetName = ANNOTATION_HELPER.extractEntitySetName(clz);
 +        if(entitySetName != null) {
 +          DataStore<Object> dhs = (DataStore<Object>) dataStoreFactory.createDataStore(clz);
 +          dataStores.put(entitySetName, dhs);
 +        } else if (!ANNOTATION_HELPER.isEdmAnnotated(clz)) {
 +          throw new ODataException("Found not annotated class during DataStore initilization of type: "
 +              + clz.getName());
 +        }
 +      }
 +    } catch (DataStoreException e) {
 +      throw new ODataException("Error in DataStore initilization with message: " + e.getMessage(), e);
 +    }
 +  }
 +
 +  @SuppressWarnings("unchecked")
 +  public <T> DataStore<T> getDataStore(final Class<T> clazz) {
 +    String entitySetName = ANNOTATION_HELPER.extractEntitySetName(clazz);
 +    return (DataStore<T>) dataStores.get(entitySetName);
 +  }
 +
 +  @Override
 +  public List<?> readData(final EdmEntitySet entitySet) throws ODataNotImplementedException,
 +      ODataNotFoundException, EdmException, ODataApplicationException {
 +
 +    DataStore<Object> holder = getDataStore(entitySet);
 +    if (holder != null) {
 +      return new ArrayList<Object>(holder.read());
 +    }
 +
 +    throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
 +  }
 +
 +  @Override
 +  public Object readData(final EdmEntitySet entitySet, final Map<String, Object> keys)
 +      throws ODataNotFoundException, EdmException, ODataApplicationException {
 +
 +    DataStore<Object> store = getDataStore(entitySet);
 +    if (store != null) {
 +      Object keyInstance = store.createInstance();
 +      ANNOTATION_HELPER.setKeyFields(keyInstance, keys);
 +
 +      Object result = store.read(keyInstance);
 +      if (result != null) {
 +        return result;
 +      }
 +    }
 +
 +    throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
 +  }
 +
 +  @Override
 +  public Object readData(final EdmFunctionImport function, final Map<String, Object> parameters,
 +      final Map<String, Object> keys)
 +      throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
 +    throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
 +  }
 +
 +  @Override
 +  public Object readRelatedData(final EdmEntitySet sourceEntitySet, final Object sourceData,
 +      final EdmEntitySet targetEntitySet,
 +      final Map<String, Object> targetKeys)
 +      throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
 +
 +    DataStore<?> sourceStore = dataStores.get(sourceEntitySet.getName());
 +    DataStore<?> targetStore = dataStores.get(targetEntitySet.getName());
 +
 +    AnnotatedNavInfo navInfo = ANNOTATION_HELPER.getCommonNavigationInfo(
 +        sourceStore.getDataTypeClass(), targetStore.getDataTypeClass());
-     Field sourceField = navInfo.getFromField();
++    final Field sourceField;
++    if(navInfo.isBiDirectional()) {
++      sourceField = navInfo.getToField();
++    } else {
++      sourceField = navInfo.getFromField();
++    }
 +    if (sourceField == null) {
 +      throw new AnnotationRuntimeException("Missing source field for related data (sourceStore='" + sourceStore
 +          + "', targetStore='" + targetStore + "').");
 +    }
 +
 +    List<Object> resultData = readResultData(targetStore, sourceData, sourceField, navInfo);
 +    return extractResultData(targetStore, targetKeys, navInfo, resultData);
 +  }
 +
 +  /**
 +   * Read the result data from the target store based on <code>sourceData</code> and <code>sourceField</code>
 +   * 
 +   * @param targetStore
 +   * @param sourceData
 +   * @param sourceField
 +   * @return
 +   * @throws DataStoreException
 +   */
 +  private List<Object> readResultData(final DataStore<?> targetStore, final Object sourceData, 
 +          final Field sourceField, final AnnotatedNavInfo navInfo)
 +      throws DataStoreException {
 +    Object navigationInstance = getValue(sourceField, sourceData);
 +    if (navigationInstance == null) {
 +      return Collections.emptyList();
 +    }
 +    
 +    List<Object> resultData = new ArrayList<Object>();
 +    for (Object targetInstance : targetStore.read()) {
 +      if (navigationInstance instanceof Collection) {
 +        Map<String, Object> keyName2Value = 
 +                ANNOTATION_HELPER.getValueForAnnotatedFields(sourceData, EdmKey.class);
 +        Field toField = navInfo.getToField();
 +        Object backInstance = ClassHelper.getFieldValue(targetInstance, toField);
 +        boolean keyMatch = ANNOTATION_HELPER.keyMatch(backInstance, keyName2Value);
 +        if(keyMatch) {
 +          resultData.add(targetInstance);
 +        }
 +      } else if (targetStore.isKeyEqualChecked(targetInstance, navigationInstance)) {
 +        resultData.add(targetInstance);
 +      }
 +    }
 +    return resultData;
 +  }
 +
 +  /**
 +   * Extract the <code>result data</code> from the <code>resultData</code> list based on
 +   * <code>navigation information</code> and <code>targetKeys</code>.
 +   * 
 +   * @param targetStore
 +   * @param targetKeys
 +   * @param navInfo
 +   * @param resultData
 +   * @return
 +   * @throws DataStoreException
 +   */
 +  private Object extractResultData(final DataStore<?> targetStore, final Map<String, Object> targetKeys,
 +      final AnnotatedNavInfo navInfo, final List<Object> resultData) throws DataStoreException {
 +    if (navInfo.getToMultiplicity() == EdmMultiplicity.MANY) {
 +      if (targetKeys.isEmpty()) {
 +        return resultData;
 +      } else {
 +        Object keyInstance = targetStore.createInstance();
 +        ANNOTATION_HELPER.setKeyFields(keyInstance, targetKeys);
 +        for (Object result : resultData) {
 +          if (targetStore.isKeyEqualChecked(result, keyInstance)) {
 +            return result;
 +          }
 +        }
 +        return null;
 +      }
 +    } else {
 +      if (resultData.isEmpty()) {
 +        return null;
 +      }
 +      return resultData.get(0);
 +    }
 +  }
 +
 +  @Override
 +  public BinaryData readBinaryData(final EdmEntitySet entitySet, final Object mediaLinkEntryData)
 +      throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
 +
 +    Object data = ANNOTATION_HELPER.getValueForField(mediaLinkEntryData, EdmMediaResourceContent.class);
 +    Object mimeType = ANNOTATION_HELPER.getValueForField(mediaLinkEntryData, EdmMediaResourceMimeType.class);
 +
 +    if (data == null && mimeType == null) {
 +      DataStore<Object> dataStore = getDataStore(entitySet);
 +      Object readEntry = dataStore.read(mediaLinkEntryData);
 +      if (readEntry != null) {
 +        data = ANNOTATION_HELPER.getValueForField(readEntry, EdmMediaResourceContent.class);
 +        mimeType = ANNOTATION_HELPER.getValueForField(readEntry, EdmMediaResourceMimeType.class);
 +      }
 +    }
 +
 +    return new BinaryData((byte[]) data, String.valueOf(mimeType));
 +  }
 +
 +  @Override
 +  public Object newDataObject(final EdmEntitySet entitySet)
 +      throws ODataNotImplementedException, EdmException, ODataApplicationException {
 +
 +    DataStore<Object> dataStore = getDataStore(entitySet);
 +    if (dataStore != null) {
 +      return dataStore.createInstance();
 +    }
 +
 +    throw new AnnotationRuntimeException("No DataStore found for entitySet with name: " + entitySet.getName());
 +  }
 +
 +  @Override
 +  public void writeBinaryData(final EdmEntitySet entitySet, final Object mediaEntityInstance,
 +      final BinaryData binaryData)
 +      throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
 +
 +    try {
 +      DataStore<Object> dataStore = getDataStore(entitySet);
 +      Object readEntry = dataStore.read(mediaEntityInstance);
 +      if (readEntry == null) {
 +        throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
 +      } else {
 +        ANNOTATION_HELPER.setValueForAnnotatedField(
 +            mediaEntityInstance, EdmMediaResourceContent.class, binaryData.getData());
 +        ANNOTATION_HELPER.setValueForAnnotatedField(
 +            mediaEntityInstance, EdmMediaResourceMimeType.class, binaryData.getMimeType());
 +      }
 +    } catch (ODataAnnotationException e) {
 +      throw new AnnotationRuntimeException("Invalid media resource annotation at entity set '" + entitySet.getName()
 +          + "' with message '" + e.getMessage() + "'.", e);
 +    }
 +  }
 +
 +  /**
 +   * <p>Updates a single data object identified by the specified entity set and key fields of
 +   * the data object.</p>
 +   * @param entitySet the {@link EdmEntitySet} the object must correspond to
 +   * @param data the data object of the new entity
 +   * @return updated data object instance
 +   * @throws org.apache.olingo.odata2.api.exception.ODataNotImplementedException
 +   * @throws org.apache.olingo.odata2.api.edm.EdmException
 +   * @throws org.apache.olingo.odata2.api.exception.ODataApplicationException
 +   */
 +  public Object updateData(final EdmEntitySet entitySet, final Object data)
 +      throws ODataNotImplementedException, EdmException, ODataApplicationException {
 +
 +    DataStore<Object> dataStore = getDataStore(entitySet);
 +    return dataStore.update(data);
 +  }
 +
 +  @Override
 +  public void deleteData(final EdmEntitySet entitySet, final Map<String, Object> keys)
 +      throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
 +    DataStore<Object> dataStore = getDataStore(entitySet);
 +    Object keyInstance = dataStore.createInstance();
 +    ANNOTATION_HELPER.setKeyFields(keyInstance, keys);
 +    dataStore.delete(keyInstance);
 +  }
 +
 +  @Override
 +  public void createData(final EdmEntitySet entitySet, final Object data)
 +      throws ODataNotImplementedException, EdmException, ODataApplicationException {
 +
 +    DataStore<Object> dataStore = getDataStore(entitySet);
 +    dataStore.create(data);
 +  }
 +
 +  @Override
 +  public void deleteRelation(final EdmEntitySet sourceEntitySet, final Object sourceData,
 +      final EdmEntitySet targetEntitySet,
 +      final Map<String, Object> targetKeys)
 +      throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
 +    throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
 +  }
 +
 +  @Override
 +  public void writeRelation(final EdmEntitySet sourceEntitySet, final Object sourceEntity,
 +      final EdmEntitySet targetEntitySet,
 +      final Map<String, Object> targetEntityValues)
 +      throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
 +    // get common data
 +    DataStore<Object> sourceStore = dataStores.get(sourceEntitySet.getName());
 +    DataStore<Object> targetStore = dataStores.get(targetEntitySet.getName());
 +
 +    AnnotatedNavInfo commonNavInfo = ANNOTATION_HELPER.getCommonNavigationInfo(
 +        sourceStore.getDataTypeClass(), targetStore.getDataTypeClass());
 +
 +    // get and validate source fields
 +    Field sourceField = commonNavInfo.getFromField();
 +    if (sourceField == null) {
 +      throw new AnnotationRuntimeException("Missing source field for related data (sourceStore='" + sourceStore
 +          + "', targetStore='" + targetStore + "').");
 +    }
 +
 +    // get related target entity
 +    Object targetEntity = targetStore.createInstance();
 +    ANNOTATION_HELPER.setKeyFields(targetEntity, targetEntityValues);
 +    targetEntity = targetStore.read(targetEntity);
 +
 +    // set at source
 +    setValueAtNavigationField(sourceEntity, sourceField, targetEntity);
 +    // set at target
 +    Field targetField = commonNavInfo.getToField();
 +    if (targetField != null) {
 +      setValueAtNavigationField(targetEntity, targetField, sourceEntity);
 +    }
 +  }
 +
 +  /**
 +   * Set (Multiplicity != *) or add (Multiplicity == *) <code>value</code> at <code>field</code>
 +   * of <code>instance</code>.
 +   * 
 +   * @param instance
 +   * @param field
 +   * @param value
 +   * @throws EdmException
 +   */
 +  private void setValueAtNavigationField(final Object instance, final Field field, final Object value)
 +      throws EdmException {
 +    Class<?> fieldTypeClass = field.getType();
 +    if (Collection.class.isAssignableFrom(fieldTypeClass)) {
 +      @SuppressWarnings("unchecked")
 +      Collection<Object> collection = (Collection<Object>) ANNOTATION_HELPER.getValueForField(
 +          instance, field.getName(), EdmNavigationProperty.class);
 +      if (collection == null) {
 +        collection = new ArrayList<Object>();
 +        setValue(instance, field, collection);
 +      }
 +      collection.add(value);
 +    } else if (fieldTypeClass.isArray()) {
 +      throw new AnnotationRuntimeException("Write relations for internal used arrays is not supported.");
 +    } else {
 +      setValue(instance, field, value);
 +    }
 +  }
 +
 +  /**
 +   * Returns corresponding DataStore for EdmEntitySet or if no data store is registered an
 +   * AnnotationRuntimeException is thrown.
 +   * Never returns NULL.
 +   * 
 +   * @param entitySet for which the corresponding DataStore is returned
 +   * @return a DataStore object
 +   * @throws EdmException
 +   * @throws AnnotationRuntimeException if no DataStore is found
 +   */
 +  private DataStore<Object> getDataStore(final EdmEntitySet entitySet) throws EdmException {
 +    final String name = entitySet.getName();
 +    DataStore<Object> dataStore = dataStores.get(name);
 +    if (dataStore == null) {
 +      throw new AnnotationRuntimeException("No DataStore found for entity set '" + entitySet + "'.");
 +    }
 +    return dataStore;
 +  }
 +
 +  private Object getValue(final Field field, final Object instance) {
 +    try {
 +      boolean access = field.isAccessible();
 +      field.setAccessible(true);
 +      Object value = field.get(instance);
 +      field.setAccessible(access);
 +      return value;
 +    } catch (IllegalArgumentException e) {
 +      throw new AnnotationRuntimeException("Error for getting value of field '"
 +          + field + "' at instance '" + instance + "'.", e);
 +    } catch (IllegalAccessException e) {
 +      throw new AnnotationRuntimeException("Error for getting value of field '"
 +          + field + "' at instance '" + instance + "'.", e);
 +    }
 +  }
 +
 +  private void setValue(final Object instance, final Field field, final Object value) {
 +    try {
 +      boolean access = field.isAccessible();
 +      field.setAccessible(true);
 +      field.set(instance, value);
 +      field.setAccessible(access);
 +    } catch (IllegalArgumentException e) {
 +      throw new AnnotationRuntimeException("Error for setting value of field: '"
 +          + field + "' at instance: '" + instance + "'.", e);
 +    } catch (IllegalAccessException e) {
 +      throw new AnnotationRuntimeException("Error for setting value of field: '"
 +          + field + "' at instance: '" + instance + "'.", e);
 +    }
 +  }
 +}

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/13b99eab/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/edm/AnnotationEdmProvider.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/13b99eab/odata2-annotation-processor/annotation-processor-ref/src/main/java/org/apache/olingo/odata2/annotation/processor/ref/AnnotationRefServiceFactory.java
----------------------------------------------------------------------
diff --cc odata2-annotation-processor/annotation-processor-ref/src/main/java/org/apache/olingo/odata2/annotation/processor/ref/AnnotationRefServiceFactory.java
index 0977a83,9130a19..65f5585
--- a/odata2-annotation-processor/annotation-processor-ref/src/main/java/org/apache/olingo/odata2/annotation/processor/ref/AnnotationRefServiceFactory.java
+++ b/odata2-annotation-processor/annotation-processor-ref/src/main/java/org/apache/olingo/odata2/annotation/processor/ref/AnnotationRefServiceFactory.java
@@@ -145,9 -126,11 +145,11 @@@ public class AnnotationRefServiceFactor
      teamDs.create(createTeam("Team Beta", false));
      teamDs.create(createTeam("Team Gamma", false));
      teamDs.create(createTeam("Team Omega", true));
-     teamDs.create(createTeam("Team Zeta", true));
+     Team subTeam = createTeam("SubTeamOne", false);
+     teamDs.create(subTeam);
+     teamDs.create(createTeam("Team Zeta", true, subTeam));
  
 -    DataStore<Building> buildingsDs = getDataStore(Building.class);
 +    InMemoryDataStore<Building> buildingsDs = getDataStore(Building.class);
      Building redBuilding = createBuilding("Red Building");
      buildingsDs.create(redBuilding);
      Building greenBuilding = createBuilding("Green Building");


[05/37] 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-129_PocJpaDataStore
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);


[27/37] olingo-odata2 git commit: [OLINGO-531] Fix: ODataServlet response contains content-length header

Posted by mi...@apache.org.
[OLINGO-531] Fix: ODataServlet response contains content-length header

Signed-off-by: Christian Amend <ch...@apache.org>


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

Branch: refs/heads/Olingo-129_PocJpaDataStore
Commit: 297c3949222e50de4a6c266e4a221564ad2d9b08
Parents: b2b42b1
Author: Christian Holzer <c....@sap.com>
Authored: Tue Jan 13 09:31:52 2015 +0100
Committer: Christian Amend <ch...@apache.org>
Committed: Tue Jan 13 12:50:58 2015 +0100

----------------------------------------------------------------------
 .../odata2/core/servlet/ODataServlet.java       | 17 +++-
 .../odata2/core/servlet/ODataServletTest.java   | 82 ++++++++++++++++++++
 2 files changed, 98 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/297c3949/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/ODataServlet.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/ODataServlet.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/ODataServlet.java
index 0973f33..e1faeae 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/ODataServlet.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/ODataServlet.java
@@ -245,16 +245,31 @@ public class ODataServlet extends HttpServlet {
     if (entity != null) {
       ServletOutputStream out = resp.getOutputStream();
       int curByte;
+      int contentLength = 0;
+
       if (entity instanceof InputStream) {
         while ((curByte = ((InputStream) entity).read()) != -1) {
+          contentLength++;
           out.write((char) curByte);
         }
         ((InputStream) entity).close();
       } else if (entity instanceof String) {
         String body = (String) entity;
-        out.write(body.getBytes("utf-8"));
+        final byte[] entityBytes = body.getBytes("utf-8");
+        out.write(entityBytes);
+        contentLength = entityBytes.length;
+      }
+
+      if (response.getHeader(HttpHeaders.CONTENT_LENGTH) != null) {
+        // Override content length
+        try {
+          contentLength = Integer.parseInt(response.getHeader(HttpHeaders.CONTENT_LENGTH));
+        } catch (NumberFormatException e) {
+          // Ignore
+        }
       }
 
+      resp.setContentLength(contentLength);
       out.flush();
       out.close();
     }

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/297c3949/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/servlet/ODataServletTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/servlet/ODataServletTest.java b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/servlet/ODataServletTest.java
index 2f877d2..883ab96 100644
--- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/servlet/ODataServletTest.java
+++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/servlet/ODataServletTest.java
@@ -18,16 +18,22 @@
  ******************************************************************************/
 package org.apache.olingo.odata2.core.servlet;
 
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
 import java.lang.reflect.Field;
+import java.lang.reflect.Method;
 
 import javax.servlet.GenericServlet;
 import javax.servlet.ServletConfig;
+import javax.servlet.ServletOutputStream;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.olingo.odata2.api.ODataServiceFactory;
 import org.apache.olingo.odata2.api.commons.HttpHeaders;
 import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
+import org.apache.olingo.odata2.api.processor.ODataResponse;
+import org.apache.olingo.odata2.core.ODataResponseImpl;
 import org.apache.olingo.odata2.core.rest.ODataServiceFactoryImpl;
 import org.junit.Test;
 import org.mockito.Mockito;
@@ -91,6 +97,82 @@ public class ODataServletTest {
     Mockito.verify(respMock).setHeader(HttpHeaders.LOCATION, "/");
   }
 
+  @Test
+  public void contentLengthCalculatedString() throws Exception {
+    final Method createResponse =
+        ODataServlet.class.getDeclaredMethod("createResponse", HttpServletResponse.class, ODataResponse.class);
+    createResponse.setAccessible(true);
+
+    final ODataServlet servlet = new ODataServlet();
+    final String content = "Test\r\n";
+    final ODataResponse response = ODataResponseImpl.status(HttpStatusCodes.OK).entity(content).build();
+    prepareResponseMockToWrite(respMock);
+    prepareServlet(servlet);
+
+    createResponse.invoke(servlet, respMock, response);
+    Mockito.verify(respMock).setContentLength(content.getBytes("utf-8").length);
+  }
+
+  @Test
+  public void contentLengthCalculatedStream() throws Exception {
+    final Method createResponse =
+        ODataServlet.class.getDeclaredMethod("createResponse", HttpServletResponse.class, ODataResponse.class);
+    createResponse.setAccessible(true);
+
+    final ODataServlet servlet = new ODataServlet();
+    final String content = "Test\r\n";
+
+    final ODataResponse response =
+        ODataResponseImpl.status(HttpStatusCodes.OK).entity(new ByteArrayInputStream(content.getBytes("utf-8")))
+            .build();
+    prepareResponseMockToWrite(respMock);
+    prepareServlet(servlet);
+
+    createResponse.invoke(servlet, respMock, response);
+    Mockito.verify(respMock).setContentLength(content.getBytes("utf-8").length);
+  }
+
+  @Test
+  public void contentLengthHeader() throws Exception {
+    final Method createResponse =
+        ODataServlet.class.getDeclaredMethod("createResponse", HttpServletResponse.class, ODataResponse.class);
+    createResponse.setAccessible(true);
+    final ODataServlet servlet = new ODataServlet();
+    final ODataResponse response =
+        ODataResponseImpl.status(HttpStatusCodes.OK).header(HttpHeaders.CONTENT_LENGTH, "15").entity("").build();
+    prepareResponseMockToWrite(respMock);
+    prepareServlet(servlet);
+
+    createResponse.invoke(servlet, respMock, response);
+
+    Mockito.verify(respMock).setHeader(HttpHeaders.CONTENT_LENGTH, "15");
+    Mockito.verify(respMock).setContentLength(15);
+  }
+
+  @Test
+  public void contentLengthHeaderInvalid() throws Exception {
+    final Method createResponse =
+        ODataServlet.class.getDeclaredMethod("createResponse", HttpServletResponse.class, ODataResponse.class);
+    createResponse.setAccessible(true);
+    final ODataServlet servlet = new ODataServlet();
+    final ODataResponse response =
+        ODataResponseImpl.status(HttpStatusCodes.OK).header(HttpHeaders.CONTENT_LENGTH, "ab").entity("Test").build();
+    prepareResponseMockToWrite(respMock);
+    prepareServlet(servlet);
+
+    createResponse.invoke(servlet, respMock, response);
+
+    Mockito.verify(respMock).setHeader(HttpHeaders.CONTENT_LENGTH, "ab");
+    Mockito.verify(respMock).setContentLength(4); // ||"Test"|| = 4
+  }
+
+  private void prepareResponseMockToWrite(final HttpServletResponse response) throws IOException {
+    Mockito.when(response.getOutputStream()).thenReturn(new ServletOutputStream() {
+      @Override
+      public void write(int b) throws IOException {}
+    });
+  }
+
   private void prepareRequest(final HttpServletRequest req, final String contextPath, final String servletPath) {
     Mockito.when(req.getMethod()).thenReturn("GET");
     Mockito.when(req.getContextPath()).thenReturn(contextPath);


[28/37] olingo-odata2 git commit: [OLINGO-532] Expose JPAEdmMappingImpl via Factory

Posted by mi...@apache.org.
[OLINGO-532] Expose JPAEdmMappingImpl via Factory


Signed-off-by: Chandan V A <ch...@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/bdd755cb
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata2/tree/bdd755cb
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata2/diff/bdd755cb

Branch: refs/heads/Olingo-129_PocJpaDataStore
Commit: bdd755cb987feac46bb2148161ca5246b88d54a2
Parents: b2b42b1
Author: Chandan V A <ch...@sap.com>
Authored: Tue Jan 13 18:06:58 2015 +0530
Committer: Chandan V A <ch...@sap.com>
Committed: Tue Jan 13 18:06:58 2015 +0530

----------------------------------------------------------------------
 .../odata2/jpa/processor/api/factory/JPAAccessFactory.java    | 7 +++++++
 .../jpa/processor/core/factory/ODataJPAFactoryImpl.java       | 7 +++++++
 2 files changed, 14 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/bdd755cb/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/factory/JPAAccessFactory.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/factory/JPAAccessFactory.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/factory/JPAAccessFactory.java
index 20f965e..37e4bbb 100644
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/factory/JPAAccessFactory.java
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/factory/JPAAccessFactory.java
@@ -21,6 +21,7 @@ package org.apache.olingo.odata2.jpa.processor.api.factory;
 import org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext;
 import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmMappingModelAccess;
 import org.apache.olingo.odata2.jpa.processor.api.access.JPAProcessor;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmMapping;
 import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmModelView;
 
 /**
@@ -66,4 +67,10 @@ public interface JPAAccessFactory {
    * @return an instance of type {@link org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmMappingModelAccess}
    */
   public JPAEdmMappingModelAccess getJPAEdmMappingModelAccess(ODataJPAContext oDataJPAContext);
+
+  /**
+   * The method instantiates a JPAEdmMapping instance.
+   * @return an instance of type {@link org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmMapping}
+   */
+  public JPAEdmMapping getJPAEdmMappingInstance();
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/bdd755cb/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/factory/ODataJPAFactoryImpl.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/factory/ODataJPAFactoryImpl.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/factory/ODataJPAFactoryImpl.java
index 789afde..ce08757 100644
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/factory/ODataJPAFactoryImpl.java
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/factory/ODataJPAFactoryImpl.java
@@ -36,6 +36,7 @@ import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContext.JPQLContextBu
 import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContextType;
 import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContextView;
 import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLStatement.JPQLStatementBuilder;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmMapping;
 import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmModelView;
 import org.apache.olingo.odata2.jpa.processor.core.ODataJPAContextImpl;
 import org.apache.olingo.odata2.jpa.processor.core.ODataJPAProcessorDefault;
@@ -53,6 +54,7 @@ import org.apache.olingo.odata2.jpa.processor.core.jpql.JPQLSelectContext;
 import org.apache.olingo.odata2.jpa.processor.core.jpql.JPQLSelectSingleContext;
 import org.apache.olingo.odata2.jpa.processor.core.jpql.JPQLSelectSingleStatementBuilder;
 import org.apache.olingo.odata2.jpa.processor.core.jpql.JPQLSelectStatementBuilder;
+import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmMappingImpl;
 import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmModel;
 
 public class ODataJPAFactoryImpl extends ODataJPAFactory {
@@ -240,5 +242,10 @@ public class ODataJPAFactoryImpl extends ODataJPAFactory {
       return mappingModelAccess;
     }
 
+    @Override
+    public JPAEdmMapping getJPAEdmMappingInstance() {
+      return new JPAEdmMappingImpl();
+    }
+
   }
 }


[29/37] olingo-odata2 git commit: Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/olingo-odata2

Posted by mi...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/olingo-odata2


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

Branch: refs/heads/Olingo-129_PocJpaDataStore
Commit: b765c97235743864f1d457eef53b71b4e5af4db0
Parents: bdd755c 297c394
Author: Chandan V A <ch...@sap.com>
Authored: Tue Jan 13 18:07:49 2015 +0530
Committer: Chandan V A <ch...@sap.com>
Committed: Tue Jan 13 18:07:49 2015 +0530

----------------------------------------------------------------------
 .../odata2/core/servlet/ODataServlet.java       | 17 +++-
 .../odata2/core/servlet/ODataServletTest.java   | 82 ++++++++++++++++++++
 2 files changed, 98 insertions(+), 1 deletion(-)
----------------------------------------------------------------------



[14/37] olingo-odata2 git commit: [OLINGO-516] Support for $value in Function Import + Support for byte[] array return types in Function Imports.

Posted by mi...@apache.org.
[OLINGO-516] Support for $value in Function Import + Support for byte[]
array return types in Function Imports.

byte array returned from Function Imports will be serialized into HTTP
response with mime type as application/octect-stream. Currently there is
no means to override the mime type.

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

Branch: refs/heads/Olingo-129_PocJpaDataStore
Commit: 2636dd5f79186003b9d1087ed03586efd7687f24
Parents: bd0a127
Author: Chandan V A <ch...@sap.com>
Authored: Sat Dec 20 18:14:19 2014 +0530
Committer: Chandan V A <ch...@sap.com>
Committed: Sat Dec 20 18:14:19 2014 +0530

----------------------------------------------------------------------
 .../core/ODataJPAProcessorDefault.java          |  58 +++++++++----------
 .../core/ODataJPAResponseBuilderDefault.java    |   9 ++-
 .../processor/ref/util/CustomerImageLoader.java |  31 ++++++++++
 .../jpa-ref/src/main/resources/Customer_1.png   | Bin 0 -> 8429 bytes
 .../jpa-ref/src/main/resources/Customer_2.png   | Bin 0 -> 12212 bytes
 .../ref/extension/CustomerImageProcessor.java   |  17 ++++++
 .../SalesOrderProcessingExtension.java          |   1 +
 7 files changed, 84 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/2636dd5f/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefault.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefault.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefault.java
index 079aecc..6b1f40b 100644
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefault.java
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefault.java
@@ -58,9 +58,9 @@ public class ODataJPAProcessorDefault extends ODataJPAProcessor {
   @Override
   public ODataResponse readEntitySet(final GetEntitySetUriInfo uriParserResultView, final String contentType)
       throws ODataException {
-    
+
     oDataJPAContext.setODataContext(getContext());
-    
+
     List<Object> jpaEntities = jpaProcessor.process(uriParserResultView);
 
     ODataResponse oDataResponse =
@@ -74,9 +74,9 @@ public class ODataJPAProcessorDefault extends ODataJPAProcessor {
   @Override
   public ODataResponse readEntity(final GetEntityUriInfo uriParserResultView, final String contentType)
       throws ODataException {
-    
+
     oDataJPAContext.setODataContext(getContext());
-    
+
     Object jpaEntity = jpaProcessor.process(uriParserResultView);
 
     ODataResponse oDataResponse =
@@ -88,9 +88,9 @@ public class ODataJPAProcessorDefault extends ODataJPAProcessor {
   @Override
   public ODataResponse countEntitySet(final GetEntitySetCountUriInfo uriParserResultView, final String contentType)
       throws ODataException {
-    
+
     oDataJPAContext.setODataContext(getContext());
-    
+
     long jpaEntityCount = jpaProcessor.process(uriParserResultView);
 
     ODataResponse oDataResponse = responseBuilder.build(jpaEntityCount);
@@ -101,9 +101,9 @@ public class ODataJPAProcessorDefault extends ODataJPAProcessor {
   @Override
   public ODataResponse existsEntity(final GetEntityCountUriInfo uriInfo, final String contentType)
       throws ODataException {
-    
+
     oDataJPAContext.setODataContext(getContext());
-    
+
     long jpaEntityCount = jpaProcessor.process(uriInfo);
 
     ODataResponse oDataResponse = responseBuilder.build(jpaEntityCount);
@@ -114,9 +114,9 @@ public class ODataJPAProcessorDefault extends ODataJPAProcessor {
   @Override
   public ODataResponse createEntity(final PostUriInfo uriParserResultView, final InputStream content,
       final String requestContentType, final String contentType) throws ODataException {
-    
+
     oDataJPAContext.setODataContext(getContext());
-    
+
     Object createdJpaEntity = jpaProcessor.process(uriParserResultView, content, requestContentType);
 
     ODataResponse oDataResponse =
@@ -128,9 +128,9 @@ public class ODataJPAProcessorDefault extends ODataJPAProcessor {
   @Override
   public ODataResponse updateEntity(final PutMergePatchUriInfo uriParserResultView, final InputStream content,
       final String requestContentType, final boolean merge, final String contentType) throws ODataException {
-    
+
     oDataJPAContext.setODataContext(getContext());
-    
+
     Object jpaEntity = jpaProcessor.process(uriParserResultView, content, requestContentType);
 
     ODataResponse oDataResponse = responseBuilder.build(uriParserResultView, jpaEntity);
@@ -141,9 +141,9 @@ public class ODataJPAProcessorDefault extends ODataJPAProcessor {
   @Override
   public ODataResponse deleteEntity(final DeleteUriInfo uriParserResultView, final String contentType)
       throws ODataException {
-    
+
     oDataJPAContext.setODataContext(getContext());
-    
+
     Object deletedObj = jpaProcessor.process(uriParserResultView, contentType);
 
     ODataResponse oDataResponse = responseBuilder.build(uriParserResultView, deletedObj);
@@ -153,9 +153,9 @@ public class ODataJPAProcessorDefault extends ODataJPAProcessor {
   @Override
   public ODataResponse executeFunctionImport(final GetFunctionImportUriInfo uriParserResultView,
       final String contentType) throws ODataException {
-    
+
     oDataJPAContext.setODataContext(getContext());
-    
+
     List<Object> resultEntity = jpaProcessor.process(uriParserResultView);
 
     ODataResponse oDataResponse =
@@ -167,13 +167,13 @@ public class ODataJPAProcessorDefault extends ODataJPAProcessor {
   @Override
   public ODataResponse executeFunctionImportValue(final GetFunctionImportUriInfo uriParserResultView,
       final String contentType) throws ODataException {
-    
+
     oDataJPAContext.setODataContext(getContext());
-    
+
     List<Object> result = jpaProcessor.process(uriParserResultView);
 
     ODataResponse oDataResponse =
-        responseBuilder.build(uriParserResultView, result, contentType);
+        responseBuilder.build(uriParserResultView, result.get(0));
 
     return oDataResponse;
   }
@@ -181,9 +181,9 @@ public class ODataJPAProcessorDefault extends ODataJPAProcessor {
   @Override
   public ODataResponse readEntityLink(final GetEntityLinkUriInfo uriParserResultView, final String contentType)
       throws ODataException {
-    
+
     oDataJPAContext.setODataContext(getContext());
-    
+
     Object jpaEntity = jpaProcessor.process(uriParserResultView);
 
     ODataResponse oDataResponse =
@@ -197,7 +197,7 @@ public class ODataJPAProcessorDefault extends ODataJPAProcessor {
       throws ODataException {
 
     oDataJPAContext.setODataContext(getContext());
-    
+
     List<Object> jpaEntity = jpaProcessor.process(uriParserResultView);
 
     ODataResponse oDataResponse =
@@ -211,7 +211,7 @@ public class ODataJPAProcessorDefault extends ODataJPAProcessor {
       final String requestContentType, final String contentType) throws ODataException {
 
     oDataJPAContext.setODataContext(getContext());
-    
+
     jpaProcessor.process(uriParserResultView, content, requestContentType, contentType);
 
     return ODataResponse.newBuilder().build();
@@ -222,7 +222,7 @@ public class ODataJPAProcessorDefault extends ODataJPAProcessor {
       final String requestContentType, final String contentType) throws ODataException {
 
     oDataJPAContext.setODataContext(getContext());
-    
+
     jpaProcessor.process(uriParserResultView, content, requestContentType, contentType);
 
     return ODataResponse.newBuilder().build();
@@ -231,9 +231,9 @@ public class ODataJPAProcessorDefault extends ODataJPAProcessor {
   @Override
   public ODataResponse deleteEntityLink(final DeleteUriInfo uriParserResultView, final String contentType)
       throws ODataException {
-    
+
     oDataJPAContext.setODataContext(getContext());
-    
+
     jpaProcessor.process(uriParserResultView, contentType);
     return ODataResponse.newBuilder().build();
 
@@ -242,9 +242,9 @@ public class ODataJPAProcessorDefault extends ODataJPAProcessor {
   @Override
   public ODataResponse executeBatch(final BatchHandler handler, final String contentType, final InputStream content)
       throws ODataException {
-    
+
     oDataJPAContext.setODataContext(getContext());
-    
+
     ODataResponse batchResponse;
     List<BatchResponsePart> batchResponseParts = new ArrayList<BatchResponsePart>();
     PathInfo pathInfo = getContext().getPathInfo();
@@ -282,7 +282,7 @@ public class ODataJPAProcessorDefault extends ODataJPAProcessor {
 
       return BatchResponsePart.responses(responses).changeSet(true).build();
     } catch (Exception e) {
-      
+
       List<ODataResponse> errorResponses = new ArrayList<ODataResponse>(1);
       errorResponses.add(ODataResponse.entity(e).status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build());
       return BatchResponsePart.responses(errorResponses).changeSet(false).build();

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/2636dd5f/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilderDefault.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilderDefault.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilderDefault.java
index fc0653f..edec5fb 100644
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilderDefault.java
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilderDefault.java
@@ -267,9 +267,12 @@ public final class ODataJPAResponseBuilderDefault implements ODataJPAResponseBui
 
       if (result != null) {
         ODataResponse response = null;
-
-        final String value = type.valueToString(result, EdmLiteralKind.DEFAULT, null);
-        response = EntityProvider.writeText(value);
+        if (type.getDefaultType().equals(byte[].class)) {
+          response = EntityProvider.writeBinary("application/octet-stream", (byte[]) result);
+        } else {
+          final String value = type.valueToString(result, EdmLiteralKind.DEFAULT, null);
+          response = EntityProvider.writeText(value);
+        }
 
         return ODataResponse.fromResponse(response).build();
       } else {

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/2636dd5f/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/util/CustomerImageLoader.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/util/CustomerImageLoader.java b/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/util/CustomerImageLoader.java
new file mode 100644
index 0000000..59403a5
--- /dev/null
+++ b/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/util/CustomerImageLoader.java
@@ -0,0 +1,31 @@
+package org.apache.olingo.odata2.jpa.processor.ref.util;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+public class CustomerImageLoader {
+  public static byte[] loadImage(Long customerId) {
+    String name = null;
+    if (customerId == 1L) {
+      name = "/Customer_1.png";
+    } else if (customerId == 2L) {
+      name = "/Customer_2.png";
+    } else {
+      return null;
+    }
+
+    InputStream is = CustomerImageLoader.class.getResourceAsStream(name);
+    ByteArrayOutputStream os = new ByteArrayOutputStream();
+    int b = 0;
+    try {
+      while ((b = is.read()) != -1) {
+        os.write(b);
+      }
+    } catch (IOException e) {
+      return null;
+    }
+    return os.toByteArray();
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/2636dd5f/odata2-jpa-processor/jpa-ref/src/main/resources/Customer_1.png
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-ref/src/main/resources/Customer_1.png b/odata2-jpa-processor/jpa-ref/src/main/resources/Customer_1.png
new file mode 100644
index 0000000..f817682
Binary files /dev/null and b/odata2-jpa-processor/jpa-ref/src/main/resources/Customer_1.png differ

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/2636dd5f/odata2-jpa-processor/jpa-ref/src/main/resources/Customer_2.png
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-ref/src/main/resources/Customer_2.png b/odata2-jpa-processor/jpa-ref/src/main/resources/Customer_2.png
new file mode 100644
index 0000000..144ed93
Binary files /dev/null and b/odata2-jpa-processor/jpa-ref/src/main/resources/Customer_2.png differ

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/2636dd5f/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/CustomerImageProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/CustomerImageProcessor.java b/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/CustomerImageProcessor.java
new file mode 100644
index 0000000..d341290
--- /dev/null
+++ b/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/CustomerImageProcessor.java
@@ -0,0 +1,17 @@
+package org.apache.olingo.odata2.jpa.processor.ref.extension;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmFacets;
+import org.apache.olingo.odata2.api.annotation.edm.EdmFunctionImport;
+import org.apache.olingo.odata2.api.annotation.edm.EdmFunctionImport.ReturnType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmFunctionImport.ReturnType.Type;
+import org.apache.olingo.odata2.api.annotation.edm.EdmFunctionImportParameter;
+import org.apache.olingo.odata2.jpa.processor.ref.util.CustomerImageLoader;
+
+public class CustomerImageProcessor {
+
+  @EdmFunctionImport(returnType = @ReturnType(type = Type.SIMPLE))
+  public byte[] getImage(
+      @EdmFunctionImportParameter(name = "CustomerId", facets = @EdmFacets(nullable = false)) Long customerId) {
+    return CustomerImageLoader.loadImage(customerId);
+  }
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/2636dd5f/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/SalesOrderProcessingExtension.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/SalesOrderProcessingExtension.java b/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/SalesOrderProcessingExtension.java
index c3065ec..1553ba6 100644
--- a/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/SalesOrderProcessingExtension.java
+++ b/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/SalesOrderProcessingExtension.java
@@ -63,6 +63,7 @@ public class SalesOrderProcessingExtension implements JPAEdmExtension {
   @Override
   public void extendWithOperation(final JPAEdmSchemaView view) {
     view.registerOperations(SalesOrderHeaderProcessor.class, null);
+    view.registerOperations(CustomerImageProcessor.class, null);
 
   }
 


[26/37] olingo-odata2 git commit: [OLINGO-193] Merge branch 'OLINGO-193_SpringSupport'

Posted by mi...@apache.org.
[OLINGO-193] Merge branch 'OLINGO-193_SpringSupport'


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

Branch: refs/heads/Olingo-129_PocJpaDataStore
Commit: b2b42b1e4387c2b3c6e89521062c7ed4d6bf4feb
Parents: e80f019 9253114
Author: Michael Bolz <mi...@sap.com>
Authored: Tue Jan 13 09:02:25 2015 +0100
Committer: Michael Bolz <mi...@sap.com>
Committed: Tue Jan 13 09:02:25 2015 +0100

----------------------------------------------------------------------
 .../odata2/core/rest/ODataRootLocator.java      | 30 +++---
 .../olingo/odata2/core/rest/RestUtil.java       |  8 +-
 odata2-spring/.springBeans                      | 26 ++++++
 odata2-spring/pom.xml                           | 86 ++++++++++++++++++
 .../odata2/spring/OlingoNamespaceHandler.java   | 29 ++++++
 .../olingo/odata2/spring/OlingoRootLocator.java | 62 +++++++++++++
 .../spring/OlingoServerDefinitionParser.java    | 96 ++++++++++++++++++++
 .../src/main/resources/META-INF/spring.handlers |  8 ++
 .../src/main/resources/META-INF/spring.schemas  |  8 ++
 .../src/main/resources/schema/olingo.xsd        | 32 +++++++
 .../spring/SpringNamespaceHandlerTest.java      | 71 +++++++++++++++
 .../olingo/odata2/spring/TestFactory.java       | 39 ++++++++
 .../resources/spring/applicationContext.xml     | 33 +++++++
 pom.xml                                         |  4 +
 14 files changed, 518 insertions(+), 14 deletions(-)
----------------------------------------------------------------------



[33/37] olingo-odata2 git commit: [OLINGO-537] - Fix Type cast issue with generics

Posted by mi...@apache.org.
[OLINGO-537] - Fix Type cast issue with generics

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

Branch: refs/heads/Olingo-129_PocJpaDataStore
Commit: 1ade40dea19770091edcd12eae97013aa47cb9fa
Parents: 9d63ef4
Author: Chandan V A <ch...@sap.com>
Authored: Fri Jan 16 13:01:21 2015 +0530
Committer: Chandan V A <ch...@sap.com>
Committed: Fri Jan 16 13:01:21 2015 +0530

----------------------------------------------------------------------
 .../jpa/processor/core/model/JPAEdmEntityType.java    | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/1ade40de/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmEntityType.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmEntityType.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmEntityType.java
index 24878dc..fd18166 100644
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmEntityType.java
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmEntityType.java
@@ -113,13 +113,13 @@ public class JPAEdmEntityType extends JPAEdmBaseViewImpl implements JPAEdmEntity
         JPAEdmMapping jpaEdmMapping = (JPAEdmMapping) currentEdmEntityType.getMapping();
         EntityListeners entityListners = currentJPAEntityType.getJavaType().getAnnotation(EntityListeners.class);
         if (entityListners != null) {
-          for (Class<EntityListeners> entityListner : entityListners.value())
-          {
-              if (ODataJPATombstoneEntityListener.class.isAssignableFrom(entityListner)) {
-                jpaEdmMapping
-                    .setODataJPATombstoneEntityListener((Class<? extends ODataJPATombstoneEntityListener>) entityListner);
-                break;
-              }
+          for (Class<EntityListeners> entityListner : entityListners.value()) {
+            if (ODataJPATombstoneEntityListener.class.isAssignableFrom(entityListner)) {
+              jpaEdmMapping
+                  .setODataJPATombstoneEntityListener((Class<? extends ODataJPATombstoneEntityListener>)
+                  (Object) entityListner);
+              break;
+            }
           }
         }
         JPAEdmPropertyView propertyView = new JPAEdmProperty(schemaView);


[02/37] olingo-odata2 git commit: [OLINGO-193] Moved the Spring integration to the level above lib

Posted by mi...@apache.org.
[OLINGO-193] Moved the Spring integration to the level above lib

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/dd98b32d
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata2/tree/dd98b32d
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata2/diff/dd98b32d

Branch: refs/heads/Olingo-129_PocJpaDataStore
Commit: dd98b32d395f51da7ab0c1eac194cd2e25f9ad6a
Parents: 5a93f4c
Author: Lior Okman <li...@sap.com>
Authored: Thu Nov 13 09:22:08 2014 +0200
Committer: Michael Bolz <mi...@sap.com>
Committed: Fri Nov 14 08:38:55 2014 +0100

----------------------------------------------------------------------
 odata2-lib/odata-spring/pom.xml                 | 39 -----------
 .../odata2/spring/OlingoNamespaceHandler.java   | 13 ----
 .../spring/OlingoServerDefinitionParser.java    | 73 --------------------
 .../src/main/resources/META-INF/spring.handlers |  1 -
 .../src/main/resources/META-INF/spring.schemas  |  1 -
 .../src/main/resources/schema/olingo.xsd        | 23 ------
 odata2-lib/pom.xml                              |  1 -
 odata2-spring/pom.xml                           | 39 +++++++++++
 .../odata2/spring/OlingoNamespaceHandler.java   | 13 ++++
 .../spring/OlingoServerDefinitionParser.java    | 73 ++++++++++++++++++++
 .../src/main/resources/META-INF/spring.handlers |  1 +
 .../src/main/resources/META-INF/spring.schemas  |  1 +
 .../src/main/resources/schema/olingo.xsd        | 23 ++++++
 pom.xml                                         |  1 +
 14 files changed, 151 insertions(+), 151 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/dd98b32d/odata2-lib/odata-spring/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-spring/pom.xml b/odata2-lib/odata-spring/pom.xml
deleted file mode 100755
index 8602fcc..0000000
--- a/odata2-lib/odata-spring/pom.xml
+++ /dev/null
@@ -1,39 +0,0 @@
-<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>
-	<artifactId>odata-spring</artifactId>
-	<name>${project.artifactId}</name>
-
-	<parent>
-		<groupId>org.apache.olingo</groupId>
-		<artifactId>olingo-odata2-lib</artifactId>
-		<version>2.0.2-SNAPSHOT</version>
-	</parent>
-
-	<dependencies>
-		<dependency>
-			<groupId>org.springframework</groupId>
-			<artifactId>spring-beans</artifactId>
-			<version>${spring.version}</version>
-			<exclusions>
-				<exclusion>
-					<groupId>commons-logging</groupId>
-					<artifactId>commons-logging</artifactId>
-				</exclusion>
-			</exclusions>
-			<optional>true</optional>
-		</dependency>
-
-		<dependency>
-			<groupId>${project.groupId}</groupId>
-			<version>${project.version}</version>
-			<artifactId>olingo-odata2-core</artifactId>
-		</dependency>
-
-		<dependency>
-			<groupId>org.apache.cxf</groupId>
-			<artifactId>cxf-rt-frontend-jaxrs</artifactId>
-			<version>${cxf.version}</version>
-		</dependency>
-	</dependencies>
-</project>

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/dd98b32d/odata2-lib/odata-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoNamespaceHandler.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoNamespaceHandler.java b/odata2-lib/odata-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoNamespaceHandler.java
deleted file mode 100755
index a141dde..0000000
--- a/odata2-lib/odata-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoNamespaceHandler.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package org.apache.olingo.odata2.spring;
-
-import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
-
-
-public class OlingoNamespaceHandler extends NamespaceHandlerSupport {
-
-	@Override
-	public void init() {
-		registerBeanDefinitionParser("server", new OlingoServerDefinitionParser());
-	}
-
-}

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/dd98b32d/odata2-lib/odata-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoServerDefinitionParser.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoServerDefinitionParser.java b/odata2-lib/odata-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoServerDefinitionParser.java
deleted file mode 100755
index 849e7a8..0000000
--- a/odata2-lib/odata-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoServerDefinitionParser.java
+++ /dev/null
@@ -1,73 +0,0 @@
-package org.apache.olingo.odata2.spring;
-
-import org.apache.cxf.jaxrs.spring.JAXRSServerFactoryBeanDefinitionParser;
-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.springframework.beans.factory.config.BeanDefinition;
-import org.springframework.beans.factory.config.BeanDefinitionHolder;
-import org.springframework.beans.factory.support.AbstractBeanDefinition;
-import org.springframework.beans.factory.support.BeanDefinitionBuilder;
-import org.springframework.beans.factory.support.ManagedList;
-import org.springframework.beans.factory.xml.ParserContext;
-import org.w3c.dom.Element;
-
-public class OlingoServerDefinitionParser extends JAXRSServerFactoryBeanDefinitionParser {
-
-	public OlingoServerDefinitionParser() {
-		super();
-		setBeanClass(SpringJAXRSServerFactoryBean.class);
-	}
-
-	@Override
-	protected void mapAttribute(BeanDefinitionBuilder bean, Element e,  String name, String val) {
-		if ("id".equals(name) || "address".equals(name)) {
-			mapToProperty(bean, name, val);
-		}
-	}
-
-	@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 = BeanDefinitionBuilder.genericBeanDefinition(ODataExceptionMapperImpl.class).getBeanDefinition();
-			definition.setScope(BeanDefinition.SCOPE_PROTOTYPE);
-			BeanDefinitionHolder holder = new BeanDefinitionHolder(definition, "OlingoODataExceptionHandler", new String[0]);
-			registerBeanDefinition(holder, parserContext.getRegistry());
-		}
-
-		if (!parserContext.getRegistry().containsBeanDefinition("OlingoODataProvider")) {
-			AbstractBeanDefinition definition = BeanDefinitionBuilder.genericBeanDefinition(ODataApplication.MyProvider.class).getBeanDefinition();
-			definition.setScope(BeanDefinition.SCOPE_PROTOTYPE);
-			BeanDefinitionHolder holder = new BeanDefinitionHolder(definition, "OlingoODataProvider", new String[0]);
-			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);
-
-		}
-
-		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/dd98b32d/odata2-lib/odata-spring/src/main/resources/META-INF/spring.handlers
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-spring/src/main/resources/META-INF/spring.handlers b/odata2-lib/odata-spring/src/main/resources/META-INF/spring.handlers
deleted file mode 100755
index 6f63fc8..0000000
--- a/odata2-lib/odata-spring/src/main/resources/META-INF/spring.handlers
+++ /dev/null
@@ -1 +0,0 @@
-http\://www.apache.org/olingo/odata2/spring/namespace=org.apache.olingo.odata2.spring.OlingoNamespaceHandler

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/dd98b32d/odata2-lib/odata-spring/src/main/resources/META-INF/spring.schemas
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-spring/src/main/resources/META-INF/spring.schemas b/odata2-lib/odata-spring/src/main/resources/META-INF/spring.schemas
deleted file mode 100755
index 85b9a6d..0000000
--- a/odata2-lib/odata-spring/src/main/resources/META-INF/spring.schemas
+++ /dev/null
@@ -1 +0,0 @@
-http\://www.apache.org/olingo/odata2/spring/namespace.xsd=schema/olingo.xsd

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/dd98b32d/odata2-lib/odata-spring/src/main/resources/schema/olingo.xsd
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-spring/src/main/resources/schema/olingo.xsd b/odata2-lib/odata-spring/src/main/resources/schema/olingo.xsd
deleted file mode 100755
index 2b160e9..0000000
--- a/odata2-lib/odata-spring/src/main/resources/schema/olingo.xsd
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<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"
-	elementFormDefault="unqualified">
-
-	<xsd:import namespace="http://www.springframework.org/schema/beans"
-				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:extension>
-			</xsd:complexContent>
-		</xsd:complexType>
-	</xsd:element>
-</xsd:schema>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/dd98b32d/odata2-lib/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-lib/pom.xml b/odata2-lib/pom.xml
index f510ec7..c646f3f 100644
--- a/odata2-lib/pom.xml
+++ b/odata2-lib/pom.xml
@@ -30,6 +30,5 @@
         <module>odata-fit</module>
         <module>odata-ref</module>
         <module>odata-web</module>
-        <module>odata-spring</module>
     </modules>
 </project>

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/dd98b32d/odata2-spring/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-spring/pom.xml b/odata2-spring/pom.xml
new file mode 100755
index 0000000..75650d0
--- /dev/null
+++ b/odata2-spring/pom.xml
@@ -0,0 +1,39 @@
+<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>
+	<artifactId>odata2-spring</artifactId>
+	<name>${project.artifactId}</name>
+
+	<parent>
+		<groupId>org.apache.olingo</groupId>
+		<artifactId>olingo-odata2-parent</artifactId>
+		<version>2.0.2-SNAPSHOT</version>
+	</parent>
+
+	<dependencies>
+		<dependency>
+			<groupId>org.springframework</groupId>
+			<artifactId>spring-beans</artifactId>
+			<version>${spring.version}</version>
+			<exclusions>
+				<exclusion>
+					<groupId>commons-logging</groupId>
+					<artifactId>commons-logging</artifactId>
+				</exclusion>
+			</exclusions>
+			<optional>true</optional>
+		</dependency>
+
+		<dependency>
+			<groupId>${project.groupId}</groupId>
+			<version>${project.version}</version>
+			<artifactId>olingo-odata2-core</artifactId>
+		</dependency>
+
+		<dependency>
+			<groupId>org.apache.cxf</groupId>
+			<artifactId>cxf-rt-frontend-jaxrs</artifactId>
+			<version>${cxf.version}</version>
+		</dependency>
+	</dependencies>
+</project>

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/dd98b32d/odata2-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoNamespaceHandler.java
----------------------------------------------------------------------
diff --git a/odata2-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoNamespaceHandler.java b/odata2-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoNamespaceHandler.java
new file mode 100755
index 0000000..a141dde
--- /dev/null
+++ b/odata2-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoNamespaceHandler.java
@@ -0,0 +1,13 @@
+package org.apache.olingo.odata2.spring;
+
+import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
+
+
+public class OlingoNamespaceHandler extends NamespaceHandlerSupport {
+
+	@Override
+	public void init() {
+		registerBeanDefinitionParser("server", new OlingoServerDefinitionParser());
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/dd98b32d/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
new file mode 100755
index 0000000..849e7a8
--- /dev/null
+++ b/odata2-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoServerDefinitionParser.java
@@ -0,0 +1,73 @@
+package org.apache.olingo.odata2.spring;
+
+import org.apache.cxf.jaxrs.spring.JAXRSServerFactoryBeanDefinitionParser;
+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.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.beans.factory.config.BeanDefinitionHolder;
+import org.springframework.beans.factory.support.AbstractBeanDefinition;
+import org.springframework.beans.factory.support.BeanDefinitionBuilder;
+import org.springframework.beans.factory.support.ManagedList;
+import org.springframework.beans.factory.xml.ParserContext;
+import org.w3c.dom.Element;
+
+public class OlingoServerDefinitionParser extends JAXRSServerFactoryBeanDefinitionParser {
+
+	public OlingoServerDefinitionParser() {
+		super();
+		setBeanClass(SpringJAXRSServerFactoryBean.class);
+	}
+
+	@Override
+	protected void mapAttribute(BeanDefinitionBuilder bean, Element e,  String name, String val) {
+		if ("id".equals(name) || "address".equals(name)) {
+			mapToProperty(bean, name, val);
+		}
+	}
+
+	@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 = BeanDefinitionBuilder.genericBeanDefinition(ODataExceptionMapperImpl.class).getBeanDefinition();
+			definition.setScope(BeanDefinition.SCOPE_PROTOTYPE);
+			BeanDefinitionHolder holder = new BeanDefinitionHolder(definition, "OlingoODataExceptionHandler", new String[0]);
+			registerBeanDefinition(holder, parserContext.getRegistry());
+		}
+
+		if (!parserContext.getRegistry().containsBeanDefinition("OlingoODataProvider")) {
+			AbstractBeanDefinition definition = BeanDefinitionBuilder.genericBeanDefinition(ODataApplication.MyProvider.class).getBeanDefinition();
+			definition.setScope(BeanDefinition.SCOPE_PROTOTYPE);
+			BeanDefinitionHolder holder = new BeanDefinitionHolder(definition, "OlingoODataProvider", new String[0]);
+			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);
+
+		}
+
+		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/dd98b32d/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
new file mode 100755
index 0000000..6f63fc8
--- /dev/null
+++ b/odata2-spring/src/main/resources/META-INF/spring.handlers
@@ -0,0 +1 @@
+http\://www.apache.org/olingo/odata2/spring/namespace=org.apache.olingo.odata2.spring.OlingoNamespaceHandler

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/dd98b32d/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
new file mode 100755
index 0000000..85b9a6d
--- /dev/null
+++ b/odata2-spring/src/main/resources/META-INF/spring.schemas
@@ -0,0 +1 @@
+http\://www.apache.org/olingo/odata2/spring/namespace.xsd=schema/olingo.xsd

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/dd98b32d/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
new file mode 100755
index 0000000..2b160e9
--- /dev/null
+++ b/odata2-spring/src/main/resources/schema/olingo.xsd
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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"
+	elementFormDefault="unqualified">
+
+	<xsd:import namespace="http://www.springframework.org/schema/beans"
+				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:extension>
+			</xsd:complexContent>
+		</xsd:complexType>
+	</xsd:element>
+</xsd:schema>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/dd98b32d/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 67ae922..1c8875b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -82,6 +82,7 @@
 		<module>odata2-annotation-processor</module>
 		<module>odata2-dist</module>
 		<module>odata2-sample</module>
+        	<module>odata2-spring</module>
 	</modules>
 
 	<build>


[04/37] olingo-odata2 git commit: [OLINGO-193] Added unit tests

Posted by mi...@apache.org.
[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-129_PocJpaDataStore
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>


[10/37] olingo-odata2 git commit: [OLINGO-508] Merge branch 'OLINGO-508_FixAnnotationEdmProvider'

Posted by mi...@apache.org.
[OLINGO-508] Merge branch 'OLINGO-508_FixAnnotationEdmProvider'


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

Branch: refs/heads/Olingo-129_PocJpaDataStore
Commit: fbfbff0889aeaacdca287211952c1c7f63a74387
Parents: 2186daa c0e17ee
Author: mibo <mi...@mirb.de>
Authored: Tue Dec 16 21:36:28 2014 +0100
Committer: mibo <mi...@mirb.de>
Committed: Tue Dec 16 21:36:28 2014 +0100

----------------------------------------------------------------------
 .../core/datasource/AnnotationInMemoryDs.java   |   7 +-
 .../core/edm/AnnotationEdmProvider.java         |  39 +++--
 .../processor/core/util/AnnotationHelper.java   | 170 ++++++++++++++-----
 .../processor/core/util/ClassHelper.java        |  16 ++
 .../core/edm/AnnotationEdmProviderTest.java     |  36 ++--
 .../annotation/processor/core/model/Team.java   |   6 +
 .../core/util/AnnotationHelperTest.java         |  22 ++-
 .../ref/AnnotationRefServiceFactory.java        |   9 +-
 .../annotation/processor/ref/model/Team.java    |  10 ++
 .../annotation/processor/ref/MetadataTest.java  |  70 +++++---
 10 files changed, 280 insertions(+), 105 deletions(-)
----------------------------------------------------------------------



[30/37] olingo-odata2 git commit: [OLINGO-535] Fix splitPath method for servlet

Posted by mi...@apache.org.
[OLINGO-535] Fix splitPath method for servlet


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

Branch: refs/heads/Olingo-129_PocJpaDataStore
Commit: b6a7d54aefeb5527b0b8f34d6b232fe8c164f470
Parents: b765c97
Author: Christian Amend <ch...@apache.org>
Authored: Thu Jan 15 11:22:20 2015 +0100
Committer: Christian Amend <ch...@apache.org>
Committed: Thu Jan 15 11:22:20 2015 +0100

----------------------------------------------------------------------
 .../olingo/odata2/core/servlet/RestUtil.java    | 27 ++++++++++++--------
 1 file changed, 17 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/b6a7d54a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/RestUtil.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/RestUtil.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/RestUtil.java
index 22644ab..48d606c 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/RestUtil.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/RestUtil.java
@@ -107,33 +107,33 @@ public class RestUtil {
 
   public static Map<String, List<String>> extractAllQueryParameters(final String queryString) {
     Map<String, List<String>> allQueryParameterMap = new HashMap<String, List<String>>();
-    
+
     if (queryString != null) {
       // At first the queryString will be decoded.
       List<String> queryParameters = Arrays.asList(Decoder.decode(queryString).split("\\&"));
       for (String param : queryParameters) {
         int indexOfEqualSign = param.indexOf("=");
-        
+
         if (indexOfEqualSign < 0) {
-          final List<String> parameterList = allQueryParameterMap.containsKey(param) ? allQueryParameterMap.get(param) 
+          final List<String> parameterList = allQueryParameterMap.containsKey(param) ? allQueryParameterMap.get(param)
               : new LinkedList<String>();
-         allQueryParameterMap.put(param, parameterList);
-          
+          allQueryParameterMap.put(param, parameterList);
+
           parameterList.add("");
         } else {
           final String key = param.substring(0, indexOfEqualSign);
-          final List<String> parameterList = allQueryParameterMap.containsKey(key) ? allQueryParameterMap.get(key) 
+          final List<String> parameterList = allQueryParameterMap.containsKey(key) ? allQueryParameterMap.get(key)
               : new LinkedList<String>();
-          
+
           allQueryParameterMap.put(key, parameterList);
           parameterList.add(param.substring(indexOfEqualSign + 1));
         }
       }
     }
-    
+
     return allQueryParameterMap;
   }
-  
+
   /*
    * Parses Accept-Language header. Returns a list sorted by quality parameter
    */
@@ -273,7 +273,14 @@ public class RestUtil {
     while (pathInfoString.startsWith("/")) {
       pathInfoString = pathInfoString.substring(1);
     }
-    List<String> segments = Arrays.asList(pathInfoString.split("/", -1));
+    List<String> segments = null;
+    // EmptyStrings have to result in an empty list.
+    // Since split will always deliver an empty string back we have to do this manually
+    if (pathInfoString.isEmpty()) {
+      segments = new ArrayList<String>();
+    } else {
+      segments = Arrays.asList(pathInfoString.split("/", -1));
+    }
 
     if (pathSplit == 0) {
       precedingPathSegments = Collections.emptyList();


[03/37] olingo-odata2 git commit: [OLINGO-193] Minor code and license clean up

Posted by mi...@apache.org.
[OLINGO-193] Minor code and license clean up


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

Branch: refs/heads/Olingo-129_PocJpaDataStore
Commit: ee0798736eaff71a377d704067032c3add145567
Parents: dd98b32
Author: Michael Bolz <mi...@sap.com>
Authored: Fri Nov 14 08:46:52 2014 +0100
Committer: Michael Bolz <mi...@sap.com>
Committed: Fri Nov 14 08:46:52 2014 +0100

----------------------------------------------------------------------
 odata2-spring/pom.xml                           |   8 ++
 .../odata2/spring/OlingoNamespaceHandler.java   |  28 ++++-
 .../spring/OlingoServerDefinitionParser.java    | 118 +++++++++++--------
 .../src/main/resources/META-INF/spring.handlers |   7 ++
 .../src/main/resources/META-INF/spring.schemas  |   7 ++
 .../src/main/resources/schema/olingo.xsd        |   7 ++
 6 files changed, 121 insertions(+), 54 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/ee079873/odata2-spring/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-spring/pom.xml b/odata2-spring/pom.xml
index 75650d0..bf8f6a8 100755
--- a/odata2-spring/pom.xml
+++ b/odata2-spring/pom.xml
@@ -1,3 +1,11 @@
+<?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. -->
 <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>

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/ee079873/odata2-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoNamespaceHandler.java
----------------------------------------------------------------------
diff --git a/odata2-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoNamespaceHandler.java b/odata2-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoNamespaceHandler.java
index a141dde..9014733 100755
--- a/odata2-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoNamespaceHandler.java
+++ b/odata2-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoNamespaceHandler.java
@@ -1,13 +1,29 @@
+/*******************************************************************************
+ * 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.springframework.beans.factory.xml.NamespaceHandlerSupport;
 
-
 public class OlingoNamespaceHandler extends NamespaceHandlerSupport {
 
-	@Override
-	public void init() {
-		registerBeanDefinitionParser("server", new OlingoServerDefinitionParser());
-	}
-
+  @Override
+  public void init() {
+    registerBeanDefinitionParser("server", new OlingoServerDefinitionParser());
+  }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/ee079873/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 849e7a8..d4469a3 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
@@ -1,3 +1,21 @@
+/*******************************************************************************
+ * 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.cxf.jaxrs.spring.JAXRSServerFactoryBeanDefinitionParser;
@@ -14,60 +32,64 @@ import org.w3c.dom.Element;
 
 public class OlingoServerDefinitionParser extends JAXRSServerFactoryBeanDefinitionParser {
 
-	public OlingoServerDefinitionParser() {
-		super();
-		setBeanClass(SpringJAXRSServerFactoryBean.class);
-	}
+  public OlingoServerDefinitionParser() {
+    super();
+    setBeanClass(SpringJAXRSServerFactoryBean.class);
+  }
 
-	@Override
-	protected void mapAttribute(BeanDefinitionBuilder bean, Element e,  String name, String val) {
-		if ("id".equals(name) || "address".equals(name)) {
-			mapToProperty(bean, name, val);
-		}
-	}
+  @Override
+  protected void mapAttribute(BeanDefinitionBuilder bean, Element e, String name, String val) {
+    if ("id".equals(name) || "address".equals(name)) {
+      mapToProperty(bean, name, val);
+    }
+  }
 
-	@Override
-	protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder bean) {
-		super.doParse(element, parserContext, bean);
-		ManagedList<BeanDefinition> services = new ManagedList<BeanDefinition>(3);
+  @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 = BeanDefinitionBuilder.genericBeanDefinition(ODataExceptionMapperImpl.class).getBeanDefinition();
-			definition.setScope(BeanDefinition.SCOPE_PROTOTYPE);
-			BeanDefinitionHolder holder = new BeanDefinitionHolder(definition, "OlingoODataExceptionHandler", new String[0]);
-			registerBeanDefinition(holder, parserContext.getRegistry());
-		}
+    if (!parserContext.getRegistry().containsBeanDefinition("OlingoODataExceptionHandler")) {
+      AbstractBeanDefinition definition =
+          BeanDefinitionBuilder.genericBeanDefinition(ODataExceptionMapperImpl.class).getBeanDefinition();
+      definition.setScope(BeanDefinition.SCOPE_PROTOTYPE);
+      BeanDefinitionHolder holder = new BeanDefinitionHolder(definition, "OlingoODataExceptionHandler", new String[0]);
+      registerBeanDefinition(holder, parserContext.getRegistry());
+    }
 
-		if (!parserContext.getRegistry().containsBeanDefinition("OlingoODataProvider")) {
-			AbstractBeanDefinition definition = BeanDefinitionBuilder.genericBeanDefinition(ODataApplication.MyProvider.class).getBeanDefinition();
-			definition.setScope(BeanDefinition.SCOPE_PROTOTYPE);
-			BeanDefinitionHolder holder = new BeanDefinitionHolder(definition, "OlingoODataProvider", new String[0]);
-			registerBeanDefinition(holder, parserContext.getRegistry());
-		}
+    if (!parserContext.getRegistry().containsBeanDefinition("OlingoODataProvider")) {
+      AbstractBeanDefinition definition =
+          BeanDefinitionBuilder.genericBeanDefinition(ODataApplication.MyProvider.class).getBeanDefinition();
+      definition.setScope(BeanDefinition.SCOPE_PROTOTYPE);
+      BeanDefinitionHolder holder = new BeanDefinitionHolder(definition, "OlingoODataProvider", new String[0]);
+      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);
+    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);
 
-		}
+    }
 
-		services.add(parserContext.getRegistry().getBeanDefinition("OlingoODataExceptionHandler"));
-		services.add(parserContext.getRegistry().getBeanDefinition("OlingoODataProvider"));
-		bean.addPropertyValue("serviceBeans", services);
-	}
+    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/ee079873/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 6f63fc8..4b9c4c5 100755
--- a/odata2-spring/src/main/resources/META-INF/spring.handlers
+++ b/odata2-spring/src/main/resources/META-INF/spring.handlers
@@ -1 +1,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. -->
 http\://www.apache.org/olingo/odata2/spring/namespace=org.apache.olingo.odata2.spring.OlingoNamespaceHandler

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/ee079873/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 85b9a6d..f9ff528 100755
--- a/odata2-spring/src/main/resources/META-INF/spring.schemas
+++ b/odata2-spring/src/main/resources/META-INF/spring.schemas
@@ -1 +1,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. -->
 http\://www.apache.org/olingo/odata2/spring/namespace.xsd=schema/olingo.xsd

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/ee079873/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 2b160e9..6818687 100755
--- a/odata2-spring/src/main/resources/schema/olingo.xsd
+++ b/odata2-spring/src/main/resources/schema/olingo.xsd
@@ -1,4 +1,11 @@
 <?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"


[35/37] olingo-odata2 git commit: [OLINGO-411] Fix for handling JPA self joins

Posted by mi...@apache.org.
[OLINGO-411] Fix for handling JPA self joins

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

Branch: refs/heads/Olingo-129_PocJpaDataStore
Commit: f37322567aa2f83c7ee6b280fb7480e17e585c6b
Parents: c9db4f5
Author: Chandan V A <ch...@sap.com>
Authored: Sun Jan 18 14:18:10 2015 +0530
Committer: Chandan V A <ch...@sap.com>
Committed: Sun Jan 18 14:18:10 2015 +0530

----------------------------------------------------------------------
 .../core/access/model/JPAEdmNameBuilder.java    |  87 ++++---
 .../processor/core/model/JPAEdmAssociation.java |   7 +-
 .../processor/core/model/JPAEdmProperty.java    |  20 +-
 .../model/JPAEdmReferentialConstraintRole.java  |   8 +-
 .../core/model/JPAEdmPropertyTest.java          | 226 +++++++++++++++----
 5 files changed, 263 insertions(+), 85 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/f3732256/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmNameBuilder.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmNameBuilder.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmNameBuilder.java
index 939ca88..352016e 100644
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmNameBuilder.java
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmNameBuilder.java
@@ -26,6 +26,7 @@ import javax.persistence.metamodel.Attribute;
 import javax.persistence.metamodel.ManagedType;
 import javax.persistence.metamodel.PluralAttribute;
 
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
 import org.apache.olingo.odata2.api.edm.FullQualifiedName;
 import org.apache.olingo.odata2.api.edm.provider.Association;
 import org.apache.olingo.odata2.api.edm.provider.AssociationSet;
@@ -142,12 +143,15 @@ public class JPAEdmNameBuilder {
                 jpaAttributeName);
       }
     }
+    if (isForeignKey == true) {
+      joinColumnNames = view.getJPAJoinColumns().get(view.getJPAJoinColumns().size() - 1);
+    }
+
     if (skipDefaultNaming == false && propertyName == null) {
       propertyName = Character.toUpperCase(jpaAttributeName.charAt(0)) + jpaAttributeName.substring(1);
     } else if (propertyName == null) {
       propertyName = jpaAttributeName;
-      if (isForeignKey == true) {
-        joinColumnNames = view.getJPAJoinColumns().get(view.getJPAJoinColumns().size() - 1);
+      if (isForeignKey) {
         propertyName = mappingModelAccess.mapJPAAttribute(view.getJPAEdmEntityTypeView().getJPAEntityType().getName(),
             joinColumnNames[0]);
         if (propertyName == null) {
@@ -379,19 +383,6 @@ public class JPAEdmNameBuilder {
 
   }
 
-  private static String buildNamespace(final JPAEdmBaseView view) {
-    JPAEdmMappingModelAccess mappingModelAccess = view.getJPAEdmMappingModelAccess();
-    String namespace = null;
-    if (mappingModelAccess != null && mappingModelAccess.isMappingModelExists()) {
-      namespace = mappingModelAccess.mapJPAPersistenceUnit(view.getpUnitName());
-    }
-    if (namespace == null) {
-      namespace = view.getpUnitName();
-    }
-
-    return namespace;
-  }
-
   /*
    * ************************************************************************
    * EDM Association Name - RULES
@@ -408,16 +399,23 @@ public class JPAEdmNameBuilder {
     String end1Name = association.getEnd1().getType().getName();
     String end2Name = association.getEnd2().getType().getName();
 
-    if (end1Name.compareToIgnoreCase(end2Name) > 0) {
-      associationName = end2Name + UNDERSCORE + end1Name;
-    } else {
+    if (end1Name.equals(end2Name)) {
       associationName = end1Name + UNDERSCORE + end2Name;
+      associationName =
+          associationName + UNDERSCORE + multiplicityToString(association.getEnd1().getMultiplicity()) + UNDERSCORE
+              + multiplicityToString(association.getEnd2().getMultiplicity()) + Integer.toString(count);
+    } else {
+      if (end1Name.compareToIgnoreCase(end2Name) > 0) {
+        associationName = end2Name + UNDERSCORE + end1Name;
+      } else {
+        associationName = end1Name + UNDERSCORE + end2Name;
+      }
+      if (count > 1) {
+        associationName = associationName + Integer.toString(count - 1);
+      }
     }
-    if (count > 1) {
-      associationName = associationName + Integer.toString(count - 1);
-    }
-    association.setName(associationName);
 
+    association.setName(associationName);
   }
 
   /*
@@ -506,11 +504,21 @@ public class JPAEdmNameBuilder {
     // Condition for self join
     if (associationEndTypeOne.getName().equals(associationEndTypeTwo.getName())) {
       if (jpaAttribute.isCollection()) {
-        navProp.setFromRole(association.getEnd2().getRole());
-        navProp.setToRole(association.getEnd1().getRole());
+        if (association.getEnd2().getMultiplicity().equals(EdmMultiplicity.MANY)) {
+          navProp.setToRole(association.getEnd2().getRole());
+          navProp.setFromRole(association.getEnd1().getRole());
+        } else {
+          navProp.setToRole(association.getEnd1().getRole());
+          navProp.setFromRole(association.getEnd2().getRole());
+        }
       } else {
-        navProp.setToRole(association.getEnd2().getRole());
-        navProp.setFromRole(association.getEnd1().getRole());        
+        if (association.getEnd2().getMultiplicity().equals(EdmMultiplicity.ONE)) {
+          navProp.setToRole(association.getEnd2().getRole());
+          navProp.setFromRole(association.getEnd1().getRole());
+        } else {
+          navProp.setToRole(association.getEnd1().getRole());
+          navProp.setFromRole(association.getEnd2().getRole());
+        }
       }
     } else if (toName.equals(associationEndTypeOne.getName())) {
       navProp.setFromRole(association.getEnd2().getRole());
@@ -522,4 +530,31 @@ public class JPAEdmNameBuilder {
     }
   }
 
+  private static String multiplicityToString(EdmMultiplicity multiplicity) {
+    switch (multiplicity) {
+    case MANY:
+      return "Many";
+    case ONE:
+      return "One";
+    case ZERO_TO_ONE:
+      return "ZeroToOne";
+    default:
+      break;
+    }
+    return "";
+  }
+
+  private static String buildNamespace(final JPAEdmBaseView view) {
+    JPAEdmMappingModelAccess mappingModelAccess = view.getJPAEdmMappingModelAccess();
+    String namespace = null;
+    if (mappingModelAccess != null && mappingModelAccess.isMappingModelExists()) {
+      namespace = mappingModelAccess.mapJPAPersistenceUnit(view.getpUnitName());
+    }
+    if (namespace == null) {
+      namespace = view.getpUnitName();
+    }
+
+    return namespace;
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/f3732256/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmAssociation.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmAssociation.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmAssociation.java
index 9f35c3a..889047c 100644
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmAssociation.java
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmAssociation.java
@@ -217,8 +217,6 @@ public class JPAEdmAssociation extends JPAEdmBaseViewImpl implements JPAEdmAssoc
   @Override
   public int getNumberOfAssociationsWithSimilarEndPoints(final JPAEdmAssociationEndView view) {
     int count = 0;
-    AssociationEnd currentAssociationEnd1 = view.getEdmAssociationEnd1();
-    AssociationEnd currentAssociationEnd2 = view.getEdmAssociationEnd2();
     AssociationEnd end1 = null;
     AssociationEnd end2 = null;
     for (String key : associationMap.keySet()) {
@@ -226,10 +224,7 @@ public class JPAEdmAssociation extends JPAEdmBaseViewImpl implements JPAEdmAssoc
       if (association != null) {
         end1 = association.getEnd1();
         end2 = association.getEnd2();
-        if ((end1.getType().equals(currentAssociationEnd1.getType()) && end2.getType().equals(
-            currentAssociationEnd2.getType()))
-            || (end1.getType().equals(currentAssociationEnd2.getType()) && end2.getType().equals(
-                currentAssociationEnd1.getType()))) {
+        if (view.compare(end1, end2)) {
           count++;
         }
       }

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/f3732256/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmProperty.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmProperty.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmProperty.java
index 369f6b9..fbb8f96 100644
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmProperty.java
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmProperty.java
@@ -276,7 +276,10 @@ public class JPAEdmProperty extends JPAEdmBaseViewImpl implements
         case ONE_TO_ONE:
         case MANY_TO_ONE:
 
-          addForeignKey(currentAttribute);
+          if (attributeType.equals(PersistentAttributeType.MANY_TO_ONE)
+              || attributeType.equals(PersistentAttributeType.ONE_TO_ONE)) {
+            addForeignKey(currentAttribute);
+          }
 
           JPAEdmAssociationEndView associationEndView = new JPAEdmAssociationEnd(entityTypeView, JPAEdmProperty.this);
           associationEndView.getBuilder().build();
@@ -289,14 +292,17 @@ public class JPAEdmProperty extends JPAEdmBaseViewImpl implements
             associationView.addJPAEdmAssociationView(associationViewLocal, associationEndView);
           }
 
-          JPAEdmReferentialConstraintView refConstraintView = new JPAEdmReferentialConstraint(
-              associationView, entityTypeView, JPAEdmProperty.this);
-          refConstraintView.getBuilder().build();
+          if (attributeType.equals(PersistentAttributeType.MANY_TO_ONE)
+              || attributeType.equals(PersistentAttributeType.ONE_TO_ONE)) {
 
-          if (refConstraintView.isExists()) {
-            associationView.addJPAEdmRefConstraintView(refConstraintView);
-          }
+            JPAEdmReferentialConstraintView refConstraintView = new JPAEdmReferentialConstraint(
+                associationView, entityTypeView, JPAEdmProperty.this);
+            refConstraintView.getBuilder().build();
 
+            if (refConstraintView.isExists()) {
+              associationView.addJPAEdmRefConstraintView(refConstraintView);
+            }
+          }
           if (navigationPropertyView == null) {
             navigationPropertyView = new JPAEdmNavigationProperty(schemaView);
           }

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/f3732256/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmReferentialConstraintRole.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmReferentialConstraintRole.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmReferentialConstraintRole.java
index 2a5045a..9c3c89e 100644
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmReferentialConstraintRole.java
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmReferentialConstraintRole.java
@@ -141,6 +141,7 @@ public class JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implemen
 
     private void buildRole() throws SecurityException, NoSuchFieldException {
 
+      int index = 0;
       if (currentRole == null) {
         currentRole = new ReferentialConstraintRole();
         String jpaAttributeType = null;
@@ -157,6 +158,7 @@ public class JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implemen
             jpaAttributeType = type.toString().substring(lastIndexOfDot + 1);
           }
           edmEntityType = entityTypeView.searchEdmEntityType(jpaAttributeType);
+          index = 1;
         } else if (roleType == RoleType.DEPENDENT) {
           edmEntityType =
               entityTypeView.searchEdmEntityType(jpaAttribute.getDeclaringType().getJavaType().getSimpleName());
@@ -167,10 +169,8 @@ public class JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implemen
           for (String[] columnName : jpaColumnNames) {
             for (Property property : edmEntityType.getProperties()) {
               jpaColumnName = ((JPAEdmMapping) property.getMapping()).getJPAColumnName();
-              if (columnName[0].equals(jpaColumnName) ||
-                  columnName[0].equals(property.getName()) ||
-                  columnName[1].equals(jpaColumnName) ||
-                  columnName[1].equals(property.getName())) {
+              if (columnName[index].equals(jpaColumnName) ||
+                  columnName[index].equals(property.getName())) {
                 PropertyRef propertyRef = new PropertyRef();
                 propertyRef.setName(property.getName());
                 propertyRefs.add(propertyRef);

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/f3732256/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmPropertyTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmPropertyTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmPropertyTest.java
index c204d1f..f76a50f 100644
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmPropertyTest.java
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmPropertyTest.java
@@ -24,9 +24,13 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Member;
 import java.util.HashSet;
 import java.util.Set;
 
+import javax.persistence.Column;
+import javax.persistence.JoinColumn;
 import javax.persistence.metamodel.Attribute;
 import javax.persistence.metamodel.Attribute.PersistentAttributeType;
 import javax.persistence.metamodel.EmbeddableType;
@@ -34,9 +38,11 @@ import javax.persistence.metamodel.EntityType;
 import javax.persistence.metamodel.Metamodel;
 import javax.persistence.metamodel.Type;
 
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
 import org.apache.olingo.odata2.api.edm.FullQualifiedName;
 import org.apache.olingo.odata2.api.edm.provider.Association;
 import org.apache.olingo.odata2.api.edm.provider.AssociationEnd;
+import org.apache.olingo.odata2.api.edm.provider.NavigationProperty;
 import org.apache.olingo.odata2.api.edm.provider.Schema;
 import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmBuilder;
 import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
@@ -51,15 +57,18 @@ import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAEdmMockData.Com
 import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAEdmMockData.SimpleType;
 import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAEmbeddableTypeMock;
 import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAEntityTypeMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAJavaMemberMock;
 import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAMetaModelMock;
 import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAPluralAttributeMock;
 import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPASingularAttributeMock;
+import org.easymock.EasyMock;
 import org.junit.Test;
 
 public class JPAEdmPropertyTest extends JPAEdmTestModelView {
 
   private JPAEdmPropertyTest objJPAEdmPropertyTest;
   private JPAEdmProperty objJPAEdmProperty;
+  private static java.lang.String testCase = "Default";
 
   private static PersistentAttributeType ATTRIBUTE_TYPE = PersistentAttributeType.BASIC;
 
@@ -157,8 +166,30 @@ public class JPAEdmPropertyTest extends JPAEdmTestModelView {
   @Test
   public void testBuildManyToOne() {
     ATTRIBUTE_TYPE = PersistentAttributeType.MANY_TO_ONE;
+    testCase = "Default";
     objJPAEdmPropertyTest = new JPAEdmPropertyTest();
     objJPAEdmProperty = new JPAEdmProperty(objJPAEdmPropertyTest);
+
+    try {
+      objJPAEdmProperty.getBuilder().build();
+    } catch (ODataJPAModelException e) {
+      fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+    } catch (ODataJPARuntimeException e) {
+      fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+    }
+
+    NavigationProperty navigationProperty =
+        objJPAEdmProperty.getJPAEdmNavigationPropertyView().getEdmNavigationProperty();
+    assertNotNull(navigationProperty);
+  }
+
+  @Test
+  public void testBuildManyToOneNoJoinColumnNames() {
+    ATTRIBUTE_TYPE = PersistentAttributeType.MANY_TO_ONE;
+    testCase = "NoJoinColumnNames";
+    objJPAEdmPropertyTest = new JPAEdmPropertyTest();
+    objJPAEdmProperty = new JPAEdmProperty(objJPAEdmPropertyTest);
+
     try {
       objJPAEdmProperty.getBuilder().build();
     } catch (ODataJPAModelException e) {
@@ -167,7 +198,12 @@ public class JPAEdmPropertyTest extends JPAEdmTestModelView {
       fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
     }
 
-    assertNotNull(objJPAEdmProperty.getJPAEdmNavigationPropertyView().getEdmNavigationProperty());
+    NavigationProperty navigationProperty =
+        objJPAEdmProperty.getJPAEdmNavigationPropertyView().getEdmNavigationProperty();
+    assertNotNull(navigationProperty);
+    assertEquals("String", navigationProperty.getFromRole());
+    assertEquals("salesorderprocessing", navigationProperty.getToRole());
+    assertEquals("StringDetails", navigationProperty.getName());
   }
 
   @Override
@@ -227,9 +263,20 @@ public class JPAEdmPropertyTest extends JPAEdmTestModelView {
   @Override
   public Association getEdmAssociation() {
     Association association = new Association();
+    AssociationEnd end1 = new AssociationEnd();
+    end1.setType(new FullQualifiedName("salesorderprocessing", "SalesOrderHeader"));
+    end1.setMultiplicity(EdmMultiplicity.MANY);
+    end1.setRole("salesorderprocessing");
+
+    AssociationEnd end2 = new AssociationEnd();
+    end2.setType(new FullQualifiedName("String", "SalesOrderHeader"));
+    end2.setMultiplicity(EdmMultiplicity.ONE);
+    end2.setRole("String");
+
     association
-        .setEnd1(new AssociationEnd().setType(new FullQualifiedName("salesorderprocessing", "SalesOrderHeader")));
-    association.setEnd2(new AssociationEnd().setType(new FullQualifiedName("salesorderprocessing", "String")));
+        .setEnd1(end1);
+    association.setEnd2(end2);
+    association.setName("salesorderprocessing_String");
 
     return association;
   }
@@ -254,6 +301,58 @@ public class JPAEdmPropertyTest extends JPAEdmTestModelView {
     return this;
   }
 
+  @Override
+  public Attribute<?, ?> getJPAReferencedAttribute() {
+    JPAEdmAttribute<Object, String> refAttribute =
+        new JPAEdmAttribute<Object, String>(java.lang.String.class, "SOLITID");
+
+    return refAttribute;
+  }
+
+  @SuppressWarnings("hiding")
+  private static class JPAEdmAttribute<Object, String> extends JPASingularAttributeMock<Object, String> {
+
+    @Override
+    public PersistentAttributeType getPersistentAttributeType() {
+      if (attributeName.equals("SOLITID")) {
+        return PersistentAttributeType.BASIC;
+      }
+      return ATTRIBUTE_TYPE;
+    }
+
+    Class<String> clazz;
+    java.lang.String attributeName;
+
+    public JPAEdmAttribute(final Class<String> javaType, final java.lang.String name) {
+      this.clazz = javaType;
+      this.attributeName = name;
+
+    }
+
+    @Override
+    public Class<String> getJavaType() {
+      return clazz;
+    }
+
+    @Override
+    public java.lang.String getName() {
+      return this.attributeName;
+    }
+
+    @Override
+    public boolean isId() {
+      return true;
+    }
+
+    @Override
+    public Member getJavaMember() {
+      if (this.attributeName.equals("SOLITID")) {
+        return new JPAJavaMember();
+      }
+      return null;
+    }
+  }
+
   private class JPAEdmMetaModel extends JPAMetaModelMock {
     Set<EntityType<?>> entities;
     Set<EmbeddableType<?>> embeddableSet;
@@ -265,7 +364,7 @@ public class JPAEdmPropertyTest extends JPAEdmTestModelView {
 
     @Override
     public Set<EntityType<?>> getEntities() {
-      entities.add(new JPAEdmEntityType());
+      entities.add(new JPAEdmEntityType<String>());
       return entities;
     }
 
@@ -275,16 +374,39 @@ public class JPAEdmPropertyTest extends JPAEdmTestModelView {
       return embeddableSet;
     }
 
-    private class JPAEdmEntityType extends JPAEntityTypeMock<String> {
-      @Override
-      public String getName() {
-        return "SalesOrderHeader";
-      }
+    @SuppressWarnings("unchecked")
+    @Override
+    public <X> EntityType<X> entity(final Class<X> arg0) {
+      JPAEdmRefEntityType<String> refEntityType = new JPAEdmRefEntityType<String>();
+      return (EntityType<X>) refEntityType;
+
+    }
+  }
+
+  @SuppressWarnings("hiding")
+  private static class JPAEdmRefEntityType<String> extends JPAEntityTypeMock<String> {
+    Set<Attribute<? super String, ?>> attributeSet = new HashSet<Attribute<? super String, ?>>();
+
+    @SuppressWarnings({ "unchecked", "rawtypes" })
+    private void setValuesToSet() {
+      attributeSet.add((Attribute<? super String, String>) new JPAEdmAttribute(java.lang.String.class, "SOLITID"));
+      attributeSet.add((Attribute<? super String, String>) new JPAEdmAttribute(java.lang.String.class, "SONAME"));
+    }
+
+    @Override
+    public Set<Attribute<? super String, ?>> getAttributes() {
+      setValuesToSet();
+      return attributeSet;
+    }
+
+    @Override
+    public java.lang.String getName() {
+      return "salesorderitemdetails";
     }
   }
 
   @SuppressWarnings("hiding")
-  private class JPAEdmEntityType<String> extends JPAEntityTypeMock<String> {
+  private static class JPAEdmEntityType<String> extends JPAEntityTypeMock<String> {
     Set<Attribute<? super String, ?>> attributeSet = new HashSet<Attribute<? super String, ?>>();
 
     @SuppressWarnings({ "unchecked", "rawtypes" })
@@ -306,6 +428,16 @@ public class JPAEdmPropertyTest extends JPAEdmTestModelView {
     }
 
     private class JPAEdmPluralAttribute extends JPAPluralAttributeMock {
+
+      @Override
+      public Member getJavaMember() {
+        if (ATTRIBUTE_TYPE.equals(PersistentAttributeType.MANY_TO_ONE)) {
+          return new JPAJavaMember();
+        }
+        return null;
+
+      }
+
       @Override
       public java.lang.String getName() {
         return "salesorderheaderdetails";
@@ -338,38 +470,6 @@ public class JPAEdmPropertyTest extends JPAEdmTestModelView {
         };
       }
     }
-
-    private class JPAEdmAttribute<Object, String> extends JPASingularAttributeMock<Object, String> {
-
-      @Override
-      public PersistentAttributeType getPersistentAttributeType() {
-        return ATTRIBUTE_TYPE;
-      }
-
-      Class<String> clazz;
-      java.lang.String attributeName;
-
-      public JPAEdmAttribute(final Class<String> javaType, final java.lang.String name) {
-        this.clazz = javaType;
-        this.attributeName = name;
-
-      }
-
-      @Override
-      public Class<String> getJavaType() {
-        return clazz;
-      }
-
-      @Override
-      public java.lang.String getName() {
-        return this.attributeName;
-      }
-
-      @Override
-      public boolean isId() {
-        return true;
-      }
-    }
   }
 
   @SuppressWarnings("hiding")
@@ -435,4 +535,46 @@ public class JPAEdmPropertyTest extends JPAEdmTestModelView {
 
   }
 
+  private static class JPAJavaMember extends JPAJavaMemberMock {
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public <T extends Annotation> T getAnnotation(final Class<T> annotationClass) {
+
+      if (annotationClass.equals(JoinColumn.class)) {
+
+        if (testCase.equals("Default")) {
+          JoinColumn joinColumn = EasyMock.createMock(JoinColumn.class);
+          EasyMock.expect(joinColumn.name()).andReturn("FSOID").anyTimes();
+          EasyMock.expect(joinColumn.referencedColumnName()).andReturn("SOLITID").anyTimes();
+          EasyMock.expect(joinColumn.insertable()).andReturn(true).anyTimes();
+          EasyMock.expect(joinColumn.updatable()).andReturn(true).anyTimes();
+          EasyMock.replay(joinColumn);
+          return (T) joinColumn;
+        } else if (testCase.equals("NoJoinColumnNames")) {
+          JoinColumn joinColumn = EasyMock.createMock(JoinColumn.class);
+          EasyMock.expect(joinColumn.name()).andReturn("").anyTimes();
+          EasyMock.expect(joinColumn.referencedColumnName()).andReturn("").anyTimes();
+          EasyMock.expect(joinColumn.insertable()).andReturn(true).anyTimes();
+          EasyMock.expect(joinColumn.updatable()).andReturn(true).anyTimes();
+          EasyMock.replay(joinColumn);
+          return (T) joinColumn;
+        }
+
+      } else {
+
+        if (testCase.equals("Default")) {
+          Column column = EasyMock.createMock(Column.class);
+          EasyMock.expect(column.name()).andReturn("SOLITID").anyTimes();
+          EasyMock.expect(column.nullable()).andReturn(true).anyTimes();
+          EasyMock.expect(column.length()).andReturn(30).anyTimes();
+          EasyMock.replay(column);
+          return (T) column;
+        }
+
+      }
+      return null;
+    }
+  }
+
 }


[23/37] olingo-odata2 git commit: [OLINGO-476] Add missing write support (for java enums)

Posted by mi...@apache.org.
[OLINGO-476] Add missing write support (for java enums)


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

Branch: refs/heads/Olingo-129_PocJpaDataStore
Commit: bfb3c1888e3b5faf0b6fb2fb2ab32b3794de6407
Parents: 81bde4f
Author: mibo <mi...@mirb.de>
Authored: Fri Jan 9 23:23:45 2015 +0100
Committer: mibo <mi...@mirb.de>
Committed: Fri Jan 9 23:23:45 2015 +0100

----------------------------------------------------------------------
 .../olingo/odata2/jpa/processor/core/access/data/JPAEntity.java   | 3 +++
 1 file changed, 3 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/bfb3c188/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntity.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntity.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntity.java
index 847e171..e0135b2 100644
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntity.java
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntity.java
@@ -336,6 +336,9 @@ public class JPAEntity {
         } else if (parameterType.equals(Character.class)) {
           Character c = Character.valueOf(((String) entityPropertyValue).charAt(0));
           method.invoke(entity, c);
+        } else if (parameterType.isEnum()) {
+          Enum e = Enum.valueOf((Class<Enum>) parameterType, (String) entityPropertyValue);
+          method.invoke(entity, e);
         }
       } else if (parameterType.equals(Blob.class)) {
         if (onJPAWriteContent == null) {


[24/37] olingo-odata2 git commit: [OLINGO-476] Added test for Java enum

Posted by mi...@apache.org.
[OLINGO-476] Added test for Java enum


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

Branch: refs/heads/Olingo-129_PocJpaDataStore
Commit: 86576ce591a44d442f3a4818a45b0491cb10304a
Parents: bfb3c18
Author: mibo <mi...@mirb.de>
Authored: Fri Jan 9 23:56:43 2015 +0100
Committer: mibo <mi...@mirb.de>
Committed: Fri Jan 9 23:56:43 2015 +0100

----------------------------------------------------------------------
 .../jpa/processor/core/access/data/JPAEntityTest.java   |  3 +++
 .../jpa/processor/core/mock/data/EdmMockUtilV2.java     |  8 ++++++++
 .../jpa/processor/core/mock/data/JPATypeMock.java       | 12 ++++++++++++
 .../processor/core/mock/data/ODataEntryMockUtil.java    |  2 ++
 4 files changed, 25 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/86576ce5/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityTest.java
index e601bd8..74edb70 100644
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityTest.java
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityTest.java
@@ -86,6 +86,7 @@ public class JPAEntityTest {
       jpaEntity = new JPAEntity(edmEntityType, edmEntitySet, mockODataJPAContext());
       jpaEntity.create(ODataEntryMockUtil.mockODataEntry(JPATypeMock.ENTITY_NAME));
     } catch (ODataJPARuntimeException e) {
+      e.printStackTrace();
       fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
           + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
     } catch (EdmException e) {
@@ -101,6 +102,7 @@ public class JPAEntityTest {
     assertEquals(ODataEntryMockUtil.VALUE_C.charAt(0), jpaTypeMock.getMC());
     assertEquals(ODataEntryMockUtil.VALUE_CARRAY, new String(jpaTypeMock.getMCArray()));
     assertEquals(ODataEntryMockUtil.VALUE_CHAR, jpaTypeMock.getMChar().toString());
+    assertEquals(ODataEntryMockUtil.VALUE_ENUM, jpaTypeMock.getMSomeEnum());
     assertEquals(ODataEntryMockUtil.VALUE_CHARARRAY, JPAEntityParser.toString(jpaTypeMock.getMCharArray()));
     assertTrue(jpaTypeMock.getMDateTime().equals(ODataEntryMockUtil.VALUE_DATE_TIME));
   }
@@ -229,6 +231,7 @@ public class JPAEntityTest {
     JPATypeMock jpaTypeMock = (JPATypeMock) jpaEntity.getJPAEntity();
     assertEquals(jpaTypeMock.getMInt(), 0);// Key should not be changed
     assertEquals(jpaTypeMock.getMString(), ODataEntryMockUtil.VALUE_MSTRING);
+    assertEquals(ODataEntryMockUtil.VALUE_ENUM, jpaTypeMock.getMSomeEnum());
     assertTrue(jpaTypeMock.getMDateTime().equals(ODataEntryMockUtil.VALUE_DATE_TIME));
   }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/86576ce5/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/EdmMockUtilV2.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/EdmMockUtilV2.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/EdmMockUtilV2.java
index dc8fe8b..23208ac 100644
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/EdmMockUtilV2.java
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/EdmMockUtilV2.java
@@ -85,6 +85,8 @@ public class EdmMockUtilV2 {
     if (entityName.equals(JPATypeMock.ENTITY_NAME)) {
       EasyMock.expect(entityType.getProperty(JPATypeMock.PROPERTY_NAME_MINT)).andReturn(
           mockEdmProperty(entityName, JPATypeMock.PROPERTY_NAME_MINT)).anyTimes();
+      EasyMock.expect(entityType.getProperty(JPATypeMock.PROPERTY_NAME_ENUM)).andReturn(
+          mockEdmProperty(entityName, JPATypeMock.PROPERTY_NAME_ENUM)).anyTimes();
       EasyMock.expect(entityType.getProperty(JPATypeMock.PROPERTY_NAME_MSTRING)).andReturn(
           mockEdmProperty(entityName, JPATypeMock.PROPERTY_NAME_MSTRING)).anyTimes();
       EasyMock.expect(entityType.getProperty(JPATypeMock.PROPERTY_NAME_MDATETIME)).andReturn(
@@ -157,6 +159,7 @@ public class EdmMockUtilV2 {
       propertyNames.add(JPATypeMock.PROPERTY_NAME_MCARRAY);
       propertyNames.add(JPATypeMock.PROPERTY_NAME_MCHAR);
       propertyNames.add(JPATypeMock.PROPERTY_NAME_MCHARARRAY);
+      propertyNames.add(JPATypeMock.PROPERTY_NAME_ENUM);
     } else if (entityName.equals(JPARelatedTypeMock.ENTITY_NAME)) {
       propertyNames.add(JPARelatedTypeMock.PROPERTY_NAME_MLONG);
       propertyNames.add(JPARelatedTypeMock.PROPERTY_NAME_MBYTE);
@@ -246,6 +249,7 @@ public class EdmMockUtilV2 {
     EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class);
 
     if (propertyName.equals(JPATypeMock.PROPERTY_NAME_MINT) ||
+        propertyName.equals(JPATypeMock.PROPERTY_NAME_ENUM) ||
         propertyName.equals(JPATypeMock.PROPERTY_NAME_MSTRING) ||
         propertyName.equals(JPATypeMock.PROPERTY_NAME_MDATETIME) ||
         propertyName.equals(JPATypeMock.PROPERTY_NAME_MBLOB) ||
@@ -266,6 +270,7 @@ public class EdmMockUtilV2 {
       EasyMock.expect(edmProperty.getType()).andReturn(edmType).anyTimes();
       EasyMock.expect(edmType.getKind()).andReturn(EdmTypeKind.SIMPLE).anyTimes();
       if (propertyName.equals(JPATypeMock.PROPERTY_NAME_MSTRING) ||
+          propertyName.equals(JPATypeMock.PROPERTY_NAME_ENUM) ||
           propertyName.equals(JPATypeMock.PROPERTY_NAME_MCARRAY) ||
           propertyName.equals(JPATypeMock.PROPERTY_NAME_MC) ||
           propertyName.equals(JPATypeMock.PROPERTY_NAME_MCHAR) ||
@@ -351,6 +356,9 @@ public class EdmMockUtilV2 {
     } else if (propertyName.equals(JPATypeMock.PROPERTY_NAME_MSTRING)) {
       mapping.setJPAType(String.class);
       ((Mapping) mapping).setInternalName(JPATypeMock.PROPERTY_NAME_MSTRING);
+    } else if (propertyName.equals(JPATypeMock.PROPERTY_NAME_ENUM)) {
+      mapping.setJPAType(JPATypeMock.JPATypeMockEnum.class);
+      ((Mapping) mapping).setInternalName(JPATypeMock.PROPERTY_NAME_ENUM);
     } else if (propertyName.equals(JPATypeMock.PROPERTY_NAME_MBLOB)) {
       mapping.setJPAType(Blob.class);
       ((Mapping) mapping).setInternalName(JPATypeMock.PROPERTY_NAME_MBLOB);

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/86576ce5/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/JPATypeMock.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/JPATypeMock.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/JPATypeMock.java
index 59701fb..3d7ddcc 100644
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/JPATypeMock.java
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/JPATypeMock.java
@@ -28,6 +28,8 @@ import java.util.UUID;
 /* ========================================================================= */
 public class JPATypeMock {
 
+  enum JPATypeMockEnum {VALUE, MORE_VALUE}
+
   public static final String ENTITY_NAME = "JPATypeMock";
   public static final String PROPERTY_NAME_MINT = "mInt";
   public static final String PROPERTY_NAME_MSTRING = "mString";
@@ -40,6 +42,7 @@ public class JPATypeMock {
   public static final String PROPERTY_NAME_MCARRAY = "mCArray";
   public static final String PROPERTY_NAME_MKEY = "key";
   public static final String PROPERTY_NAME_MCOMPLEXTYPE = "complexType";
+  public static final String PROPERTY_NAME_ENUM = "mSomeEnum";
 
   public static final String NAVIGATION_PROPERTY_X = "mRelatedEntity";
   public static final String NAVIGATION_PROPERTY_XS = "mRelatedEntities";
@@ -55,6 +58,7 @@ public class JPATypeMock {
   private char[] mCArray;
   private Character mChar;
   private Character[] mCharArray;
+  private JPATypeMockEnum mSomeEnum;
 
   public Clob getMClob() {
     return mClob;
@@ -163,6 +167,14 @@ public class JPATypeMock {
     this.mBlob = mBlob;
   }
 
+  public JPATypeMockEnum getMSomeEnum() {
+    return mSomeEnum;
+  }
+
+  public void setMSomeEnum(JPATypeMockEnum mSomeEnum) {
+    this.mSomeEnum = mSomeEnum;
+  }
+
   /* ========================================================================= */
   public static class JPATypeEmbeddableMock {
 

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/86576ce5/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/ODataEntryMockUtil.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/ODataEntryMockUtil.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/ODataEntryMockUtil.java
index 4f95a0e..e5a081c 100644
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/ODataEntryMockUtil.java
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/ODataEntryMockUtil.java
@@ -52,6 +52,7 @@ public class ODataEntryMockUtil {
   public static final float VALUE_MFLOAT = 2.00F;
   public static final UUID VALUE_UUID = UUID.fromString("38400000-8cf0-11bd-b23e-10b96e4ef00d");
   public static final short VALUE_SHORT = 2;
+  public static final JPATypeMock.JPATypeMockEnum VALUE_ENUM = JPATypeMock.JPATypeMockEnum.VALUE;
 
   public static ODataEntry mockODataEntry(final String entityName) {
     ODataEntry oDataEntry = EasyMock.createMock(ODataEntry.class);
@@ -77,6 +78,7 @@ public class ODataEntryMockUtil {
 
     if (entityName.equals(JPATypeMock.ENTITY_NAME)) {
       propertyMap.put(JPATypeMock.PROPERTY_NAME_MINT, VALUE_MINT);
+      propertyMap.put(JPATypeMock.PROPERTY_NAME_ENUM, "VALUE");
 
       VALUE_DATE_TIME = Calendar.getInstance(TimeZone.getDefault());
       VALUE_DATE_TIME.set(2013, 1, 1, 1, 1, 1);


[32/37] olingo-odata2 git commit: [OLINGO-537] - Fix for ignoring EntityListeners getting added to JPAEdmMapping if it does not inherit from ODataJPATombstoneEntityListener

Posted by mi...@apache.org.
[OLINGO-537] - Fix for ignoring EntityListeners getting added to
JPAEdmMapping if it does not inherit from
ODataJPATombstoneEntityListener

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

Branch: refs/heads/Olingo-129_PocJpaDataStore
Commit: 9d63ef43219eeafc9ab2f2de8270333952258aa5
Parents: 5c6af74
Author: Chandan V A <ch...@sap.com>
Authored: Fri Jan 16 09:46:32 2015 +0530
Committer: Chandan V A <ch...@sap.com>
Committed: Fri Jan 16 09:46:32 2015 +0530

----------------------------------------------------------------------
 .../jpa/processor/core/model/JPAEdmEntityType.java    | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/9d63ef43/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmEntityType.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmEntityType.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmEntityType.java
index eea7254..24878dc 100644
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmEntityType.java
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmEntityType.java
@@ -113,15 +113,13 @@ public class JPAEdmEntityType extends JPAEdmBaseViewImpl implements JPAEdmEntity
         JPAEdmMapping jpaEdmMapping = (JPAEdmMapping) currentEdmEntityType.getMapping();
         EntityListeners entityListners = currentJPAEntityType.getJavaType().getAnnotation(EntityListeners.class);
         if (entityListners != null) {
-          for (Class<? extends ODataJPATombstoneEntityListener> entityListner : entityListners.value())
+          for (Class<EntityListeners> entityListner : entityListners.value())
           {
-            try {
-              jpaEdmMapping.setODataJPATombstoneEntityListener(entityListner);
-              break;
-            } catch (ClassCastException e) {
-              continue;
-            }
-
+              if (ODataJPATombstoneEntityListener.class.isAssignableFrom(entityListner)) {
+                jpaEdmMapping
+                    .setODataJPATombstoneEntityListener((Class<? extends ODataJPATombstoneEntityListener>) entityListner);
+                break;
+              }
           }
         }
         JPAEdmPropertyView propertyView = new JPAEdmProperty(schemaView);


[20/37] olingo-odata2 git commit: [OLINGO-193] Reuse as much code as possible in the spring extension (Extend the core ODataRootLocator and override the setters)

Posted by mi...@apache.org.
[OLINGO-193] Reuse as much code as possible in the spring extension (Extend the core ODataRootLocator and override the setters)

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/5b632779
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata2/tree/5b632779
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata2/diff/5b632779

Branch: refs/heads/Olingo-129_PocJpaDataStore
Commit: 5b632779b992c151478d8333c19489740c8255b9
Parents: 7a596e2
Author: Lior Okman <li...@gmail.com>
Authored: Wed Dec 24 20:43:44 2014 +0200
Committer: Michael Bolz <mi...@sap.com>
Committed: Wed Jan 7 14:52:24 2015 +0100

----------------------------------------------------------------------
 .../odata2/core/rest/ODataRootLocator.java      | 21 +++++--
 .../olingo/odata2/spring/OlingoRootLocator.java | 64 ++------------------
 2 files changed, 19 insertions(+), 66 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/5b632779/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 3ff5984..e75ef5d 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
@@ -102,13 +102,9 @@ public class ODataRootLocator {
       return handleRedirect();
     }
 
-    ODataServiceFactory serviceFactory = createServiceFactoryFromContext(app, servletRequest, servletConfig);
+    ODataServiceFactory serviceFactory = getServiceFactory();
 
-    int pathSplit = 0;
-    final String pathSplitAsString = servletConfig.getInitParameter(ODataServiceFactory.PATH_SPLIT_LABEL);
-    if (pathSplitAsString != null) {
-      pathSplit = Integer.parseInt(pathSplitAsString);
-    }
+    int pathSplit = getPathSplit();
 
     final SubLocatorParameter param = new SubLocatorParameter();
     param.setServiceFactory(serviceFactory);
@@ -122,6 +118,19 @@ public class ODataRootLocator {
     return ODataSubLocator.create(param);
   }
 
+  public ODataServiceFactory getServiceFactory() {
+    return createServiceFactoryFromContext(app, servletRequest, servletConfig);
+  }
+
+  public int getPathSplit() {
+    int pathSplit = 0;
+    final String pathSplitAsString = servletConfig.getInitParameter(ODataServiceFactory.PATH_SPLIT_LABEL);
+    if (pathSplitAsString != null) {
+      pathSplit = Integer.parseInt(pathSplitAsString);
+    }
+    return pathSplit;
+  }
+
   public static ODataServiceFactory createServiceFactoryFromContext(final Application app,
       final HttpServletRequest servletRequest,
       final ServletConfig servletConfig) {

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/5b632779/odata2-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoRootLocator.java
----------------------------------------------------------------------
diff --git a/odata2-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoRootLocator.java b/odata2-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoRootLocator.java
index bf60cb6..4cfceea 100644
--- a/odata2-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoRootLocator.java
+++ b/odata2-spring/src/main/java/org/apache/olingo/odata2/spring/OlingoRootLocator.java
@@ -24,6 +24,7 @@ import org.apache.olingo.odata2.api.exception.ODataException;
 import org.apache.olingo.odata2.core.rest.ODataRedirectLocator;
 import org.apache.olingo.odata2.core.rest.ODataSubLocator;
 import org.apache.olingo.odata2.core.rest.SubLocatorParameter;
+import org.apache.olingo.odata2.core.rest.ODataRootLocator;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.Encoded;
@@ -51,71 +52,13 @@ import java.util.List;
  *
  */
 @Path("/")
-public class OlingoRootLocator {
-
-  @Context
-  private HttpHeaders httpHeaders;
-  @Context
-  private UriInfo uriInfo;
-  @Context
-  private Request request;
-  @Context
-  private HttpServletRequest servletRequest;
+public class OlingoRootLocator extends ODataRootLocator {
 
   // These next two members are exposed so that they can be injected with Spring
   private ODataServiceFactory serviceFactory;
   private int pathSplit = 0;
 
-  /**
-   * 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 org.apache.olingo.odata2.api.exception.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();
-    }
-
-    final SubLocatorParameter param = new SubLocatorParameter();
-    param.setServiceFactory(getServiceFactory());
-    param.setPathSegments(pathSegments);
-    param.setHttpHeaders(httpHeaders);
-    param.setUriInfo(uriInfo);
-    param.setRequest(request);
-    param.setServletRequest(servletRequest);
-    param.setPathSplit(getPathSplit());
-
-    return ODataSubLocator.create(param);
-  }
-
-  private Object handleRedirect() {
-    return new ODataRedirectLocator();
-  }
-
+  @Override
   public ODataServiceFactory getServiceFactory() {
     return serviceFactory;
   }
@@ -124,6 +67,7 @@ public class OlingoRootLocator {
     this.serviceFactory = serviceFactory;
   }
 
+  @Override
   public int getPathSplit() {
     return pathSplit;
   }