You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by sk...@apache.org on 2013/10/22 13:58:17 UTC

git commit: [OLINGO-34] - additional JUnit tests

Updated Branches:
  refs/heads/master 625e7543a -> 08e11ce6d


[OLINGO-34] - additional JUnit tests


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

Branch: refs/heads/master
Commit: 08e11ce6d7a5090ca7ca3ad5f22b0fc748207de9
Parents: 625e754
Author: Stephan Klevenz <sk...@apache.org>
Authored: Mon Oct 21 08:55:16 2013 +0200
Committer: Stephan Klevenz <sk...@apache.org>
Committed: Tue Oct 22 13:58:09 2013 +0200

----------------------------------------------------------------------
 .../olingo/odata2/core/rest/RestUtil.java       |   3 +-
 .../fit/basic/issues/Service1Factory.java       |  76 ++++++++++++
 .../fit/basic/issues/Service2Factory.java       |  76 ++++++++++++
 .../basic/issues/TestCxfCacheUriInfoIssue.java  | 118 +++++++++++++++++++
 .../basic/issues/TestCxfCacheUriInfoIssue2.java |  75 ++++++++++++
 .../odata2/fit/basic/issues/TestIssue105.java   | 118 -------------------
 .../odata2/testutil/server/TestServer.java      |   5 +-
 7 files changed, 350 insertions(+), 121 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/08e11ce6/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 37703e7..e2982f0 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
@@ -217,7 +217,8 @@ public class RestUtil {
   private static URI buildBaseUri(final HttpServletRequest request,
       final List<PathSegment> precedingPathSegments) throws ODataException {
     try {
-      UriBuilder uriBuilder = UriBuilder.fromUri(request.getServletPath());
+      String path = request.getContextPath() + request.getServletPath();
+      UriBuilder uriBuilder = UriBuilder.fromUri(path);
       for (final PathSegment ps : precedingPathSegments) {
         uriBuilder = uriBuilder.path(ps.getPath());
         for (final String key : ps.getMatrixParameters().keySet()) {

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/08e11ce6/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/issues/Service1Factory.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/issues/Service1Factory.java b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/issues/Service1Factory.java
new file mode 100644
index 0000000..1abbee0
--- /dev/null
+++ b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/issues/Service1Factory.java
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * 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.fit.basic.issues;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.apache.olingo.odata2.api.ODataService;
+import org.apache.olingo.odata2.api.ODataServiceFactory;
+import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
+import org.apache.olingo.odata2.api.edm.provider.EdmProvider;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.processor.ODataContext;
+import org.apache.olingo.odata2.api.processor.ODataResponse;
+import org.apache.olingo.odata2.api.processor.ODataSingleProcessor;
+import org.apache.olingo.odata2.api.processor.part.MetadataProcessor;
+import org.apache.olingo.odata2.api.uri.info.GetMetadataUriInfo;
+import org.apache.olingo.odata2.core.processor.ODataSingleProcessorService;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+
+public class Service1Factory extends ODataServiceFactory {
+
+  public static ODataContext context;
+  public static ODataService service;
+  
+  public Service1Factory() {
+    super();
+   }
+
+  @Override
+  public ODataService createService(ODataContext ctx) throws ODataException {
+    final EdmProvider provider = mock(EdmProvider.class);
+    final ODataSingleProcessor processor = mock(ODataSingleProcessor.class);
+    when(((MetadataProcessor) processor).readMetadata(any(GetMetadataUriInfo.class), any(String.class))).thenReturn(
+        ODataResponse.entity("metadata").status(HttpStatusCodes.OK).build());
+
+    doAnswer(new Answer<Object>() {
+      @Override
+      public Object answer(final InvocationOnMock invocation) throws Throwable {
+        context = (ODataContext) invocation.getArguments()[0];
+        return null;
+      }
+    }).when(processor).setContext(any(ODataContext.class));
+
+    when(processor.getContext()).thenAnswer(new Answer<ODataContext>() {
+      @Override
+      public ODataContext answer(final InvocationOnMock invocation) throws Throwable {
+        return context;
+      }
+    });
+
+    service = new ODataSingleProcessorService(provider, processor) {};
+    return service;
+  }
+
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/08e11ce6/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/issues/Service2Factory.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/issues/Service2Factory.java b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/issues/Service2Factory.java
new file mode 100644
index 0000000..42b63fa
--- /dev/null
+++ b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/issues/Service2Factory.java
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * 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.fit.basic.issues;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.apache.olingo.odata2.api.ODataService;
+import org.apache.olingo.odata2.api.ODataServiceFactory;
+import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
+import org.apache.olingo.odata2.api.edm.provider.EdmProvider;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.processor.ODataContext;
+import org.apache.olingo.odata2.api.processor.ODataResponse;
+import org.apache.olingo.odata2.api.processor.ODataSingleProcessor;
+import org.apache.olingo.odata2.api.processor.part.MetadataProcessor;
+import org.apache.olingo.odata2.api.uri.info.GetMetadataUriInfo;
+import org.apache.olingo.odata2.core.processor.ODataSingleProcessorService;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+
+public class Service2Factory extends ODataServiceFactory {
+
+  public static ODataContext context;
+  public static ODataService service;
+  
+  public Service2Factory() {
+    super();
+   }
+
+  @Override
+  public ODataService createService(ODataContext ctx) throws ODataException {
+    final EdmProvider provider = mock(EdmProvider.class);
+    final ODataSingleProcessor processor = mock(ODataSingleProcessor.class);
+    when(((MetadataProcessor) processor).readMetadata(any(GetMetadataUriInfo.class), any(String.class))).thenReturn(
+        ODataResponse.entity("metadata").status(HttpStatusCodes.OK).build());
+
+    doAnswer(new Answer<Object>() {
+      @Override
+      public Object answer(final InvocationOnMock invocation) throws Throwable {
+        context = (ODataContext) invocation.getArguments()[0];
+        return null;
+      }
+    }).when(processor).setContext(any(ODataContext.class));
+
+    when(processor.getContext()).thenAnswer(new Answer<ODataContext>() {
+      @Override
+      public ODataContext answer(final InvocationOnMock invocation) throws Throwable {
+        return context;
+      }
+    });
+
+    service = new ODataSingleProcessorService(provider, processor) {};
+    return service;
+  }
+
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/08e11ce6/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/issues/TestCxfCacheUriInfoIssue.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/issues/TestCxfCacheUriInfoIssue.java b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/issues/TestCxfCacheUriInfoIssue.java
new file mode 100644
index 0000000..c8c188b
--- /dev/null
+++ b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/issues/TestCxfCacheUriInfoIssue.java
@@ -0,0 +1,118 @@
+/*******************************************************************************
+ * 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.fit.basic.issues;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.processor.ODataResponse;
+import org.apache.olingo.odata2.api.processor.ODataSingleProcessor;
+import org.apache.olingo.odata2.api.processor.part.MetadataProcessor;
+import org.apache.olingo.odata2.api.uri.info.GetMetadataUriInfo;
+import org.apache.olingo.odata2.fit.basic.AbstractBasicTest;
+import org.apache.olingo.odata2.testutil.fit.FitStaticServiceFactory;
+import org.junit.Test;
+
+/**
+ *  
+ */
+public class TestCxfCacheUriInfoIssue extends AbstractBasicTest {
+
+  @Override
+  protected ODataSingleProcessor createProcessor() throws ODataException {
+    final ODataSingleProcessor processor = mock(ODataSingleProcessor.class);
+    when(((MetadataProcessor) processor).readMetadata(any(GetMetadataUriInfo.class), any(String.class))).thenReturn(
+        ODataResponse.entity("metadata").status(HttpStatusCodes.OK).build());
+    return processor;
+  }
+
+  @Test
+  public void checkContextForDifferentHostNamesRequests() throws ClientProtocolException, IOException, ODataException,
+      URISyntaxException {
+    URI uri1 = URI.create(getEndpoint().toString() + "$metadata");
+
+    HttpGet get1 = new HttpGet(uri1);
+    HttpResponse response1 = getHttpClient().execute(get1);
+    assertNotNull(response1);
+
+    URI serviceRoot1 = getService().getProcessor().getContext().getPathInfo().getServiceRoot();
+    assertEquals(uri1.getHost(), serviceRoot1.getHost());
+
+    get1.reset();
+
+    URI uri2 =
+        new URI(uri1.getScheme(), uri1.getUserInfo(), "127.0.0.1", uri1.getPort(), uri1.getPath(), uri1.getQuery(),
+            uri1.getFragment());
+
+    HttpGet get2 = new HttpGet(uri2);
+    HttpResponse response2 = getHttpClient().execute(get2);
+    assertNotNull(response2);
+
+    URI serviceRoot2 = getService().getProcessor().getContext().getPathInfo().getServiceRoot();
+    assertEquals(uri2.getHost(), serviceRoot2.getHost());
+  }
+
+  @Test
+  public void checkContextForDifferentWithHostHeader() throws ClientProtocolException, IOException,
+      ODataException, URISyntaxException {
+    try {
+      FitStaticServiceFactory.bindService("123", getService());
+
+      // 1st request: cache uri
+      URI uri = URI.create(getEndpoint().toString() + "$metadata");
+      HttpGet get1 = new HttpGet(uri);
+      HttpResponse response1 = getHttpClient().execute(get1);
+      assertNotNull(response1);
+
+      URI serviceRoot1 = getService().getProcessor().getContext().getPathInfo().getServiceRoot();
+      assertEquals(uri.getHost(), serviceRoot1.getHost());
+
+      get1.reset();
+
+      HttpGet get2 = new HttpGet(uri);
+      get2.addHeader("Host", "bla:123");
+      HttpResponse response2 = getHttpClient().execute(get2);
+      assertNotNull(response2);
+
+      URI serviceRoot2 = getService().getProcessor().getContext().getPathInfo().getServiceRoot();
+      assertEquals("bla", serviceRoot2.getHost());
+      assertEquals(123, serviceRoot2.getPort());
+
+      URI requestUri = getService().getProcessor().getContext().getPathInfo().getRequestUri();
+      assertEquals("bla", requestUri.getHost());
+      assertEquals(123, requestUri.getPort());
+
+    } finally {
+      FitStaticServiceFactory.unbindService("123");
+    }
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/08e11ce6/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/issues/TestCxfCacheUriInfoIssue2.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/issues/TestCxfCacheUriInfoIssue2.java b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/issues/TestCxfCacheUriInfoIssue2.java
new file mode 100644
index 0000000..5085309
--- /dev/null
+++ b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/issues/TestCxfCacheUriInfoIssue2.java
@@ -0,0 +1,75 @@
+/*******************************************************************************
+ * 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.fit.basic.issues;
+
+import static org.junit.Assert.*;
+
+import java.net.URI;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.olingo.odata2.testutil.server.TestServer;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestCxfCacheUriInfoIssue2 {
+
+  private TestServer server1;
+  private TestServer server2;
+
+  @Before
+  public void before() {
+    server1 = new TestServer("/service1");
+    server2 = new TestServer("/service2");
+
+    server1.setPathSplit(0);
+    server2.setPathSplit(0);
+
+    server1.startServer(Service1Factory.class);
+    server2.startServer(Service2Factory.class);
+  }
+
+  @Test
+  public void testServletContextPath() throws Exception {
+    URI uri1 = URI.create(server1.getEndpoint().toASCIIString() + "$metadata");
+    final HttpGet get1 = new HttpGet(uri1);
+    HttpResponse r1 = new DefaultHttpClient().execute(get1);
+    assertNotNull(r1);
+    assertEquals(uri1, Service1Factory.service.getProcessor().getContext().getPathInfo().getRequestUri());
+    assertEquals(server1.getEndpoint(), Service1Factory.service.getProcessor().getContext().getPathInfo()
+        .getServiceRoot());
+
+    URI uri2 = URI.create(server2.getEndpoint().toASCIIString() + "$metadata");
+    final HttpGet get2 = new HttpGet(uri2);
+    HttpResponse r2 = new DefaultHttpClient().execute(get2);
+    assertNotNull(r2);
+    assertEquals(uri2, Service2Factory.service.getProcessor().getContext().getPathInfo().getRequestUri());
+    assertEquals(server2.getEndpoint(), Service2Factory.service.getProcessor().getContext().getPathInfo()
+        .getServiceRoot());
+  }
+
+  @After
+  public void after() {
+    server1.stopServer();
+    server2.stopServer();
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/08e11ce6/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/issues/TestIssue105.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/issues/TestIssue105.java b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/issues/TestIssue105.java
deleted file mode 100644
index 48db095..0000000
--- a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/issues/TestIssue105.java
+++ /dev/null
@@ -1,118 +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.fit.basic.issues;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-
-import org.apache.http.HttpResponse;
-import org.apache.http.client.ClientProtocolException;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.api.processor.ODataResponse;
-import org.apache.olingo.odata2.api.processor.ODataSingleProcessor;
-import org.apache.olingo.odata2.api.processor.part.MetadataProcessor;
-import org.apache.olingo.odata2.api.uri.info.GetMetadataUriInfo;
-import org.apache.olingo.odata2.fit.basic.AbstractBasicTest;
-import org.apache.olingo.odata2.testutil.fit.FitStaticServiceFactory;
-import org.junit.Test;
-
-/**
- *  
- */
-public class TestIssue105 extends AbstractBasicTest {
-
-  @Override
-  protected ODataSingleProcessor createProcessor() throws ODataException {
-    final ODataSingleProcessor processor = mock(ODataSingleProcessor.class);
-    when(((MetadataProcessor) processor).readMetadata(any(GetMetadataUriInfo.class), any(String.class))).thenReturn(
-        ODataResponse.entity("metadata").status(HttpStatusCodes.OK).build());
-    return processor;
-  }
-
-  @Test
-  public void checkContextForDifferentHostNamesRequests() throws ClientProtocolException, IOException, ODataException,
-      URISyntaxException {
-    URI uri1 = URI.create(getEndpoint().toString() + "$metadata");
-
-    HttpGet get1 = new HttpGet(uri1);
-    HttpResponse response1 = getHttpClient().execute(get1);
-    assertNotNull(response1);
-
-    URI serviceRoot1 = getService().getProcessor().getContext().getPathInfo().getServiceRoot();
-    assertEquals(uri1.getHost(), serviceRoot1.getHost());
-
-    get1.reset();
-
-    URI uri2 =
-        new URI(uri1.getScheme(), uri1.getUserInfo(), "127.0.0.1", uri1.getPort(), uri1.getPath(), uri1.getQuery(),
-            uri1.getFragment());
-
-    HttpGet get2 = new HttpGet(uri2);
-    HttpResponse response2 = getHttpClient().execute(get2);
-    assertNotNull(response2);
-
-    URI serviceRoot2 = getService().getProcessor().getContext().getPathInfo().getServiceRoot();
-    assertEquals(uri2.getHost(), serviceRoot2.getHost());
-  }
-
-  @Test
-  public void checkContextForDifferentWithHostHeader() throws ClientProtocolException, IOException,
-      ODataException, URISyntaxException {
-    try {
-      FitStaticServiceFactory.bindService("123", getService());
-
-      // 1st request: cache uri
-      URI uri = URI.create(getEndpoint().toString() + "$metadata");
-      HttpGet get1 = new HttpGet(uri);
-      HttpResponse response1 = getHttpClient().execute(get1);
-      assertNotNull(response1);
-
-      URI serviceRoot1 = getService().getProcessor().getContext().getPathInfo().getServiceRoot();
-      assertEquals(uri.getHost(), serviceRoot1.getHost());
-
-      get1.reset();
-
-      HttpGet get2 = new HttpGet(uri);
-      get2.addHeader("Host", "bla:123");
-      HttpResponse response2 = getHttpClient().execute(get2);
-      assertNotNull(response2);
-
-      URI serviceRoot2 = getService().getProcessor().getContext().getPathInfo().getServiceRoot();
-      assertEquals("bla", serviceRoot2.getHost());
-      assertEquals(123, serviceRoot2.getPort());
-
-      URI requestUri = getService().getProcessor().getContext().getPathInfo().getRequestUri();
-      assertEquals("bla", requestUri.getHost());
-      assertEquals(123, requestUri.getPort());
-
-    } finally {
-      FitStaticServiceFactory.unbindService("123");
-    }
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/08e11ce6/odata2-lib/odata-testutil/src/main/java/org/apache/olingo/odata2/testutil/server/TestServer.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-testutil/src/main/java/org/apache/olingo/odata2/testutil/server/TestServer.java b/odata2-lib/odata-testutil/src/main/java/org/apache/olingo/odata2/testutil/server/TestServer.java
index d7008be..039f11f 100644
--- a/odata2-lib/odata-testutil/src/main/java/org/apache/olingo/odata2/testutil/server/TestServer.java
+++ b/odata2-lib/odata-testutil/src/main/java/org/apache/olingo/odata2/testutil/server/TestServer.java
@@ -90,14 +90,15 @@ public class TestServer {
         }
 
         final ServletContextHandler contextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
-        contextHandler.addServlet(odataServletHolder, path + "/*");
+        contextHandler.setContextPath("/abc");
+       contextHandler.addServlet(odataServletHolder, path + "/*");
 
         try {
           final InetSocketAddress isa = new InetSocketAddress(DEFAULT_HOST, port);
           server = new Server(isa);
           server.setHandler(contextHandler);
           server.start();
-          endpoint = new URI(DEFAULT_SCHEME, null, DEFAULT_HOST, isa.getPort(), path, null, null);
+          endpoint = new URI(DEFAULT_SCHEME, null, DEFAULT_HOST, isa.getPort(), "/abc" + path, null, null);
           log.trace("Started server at endpoint " + endpoint.toASCIIString());
           break;
         } catch (final BindException e) {