From b40ae95b7fffd570df88183a7d7a397964e7b5e6 Mon Sep 17 00:00:00 2001 From: Stephan Klevenz Date: Fri, 23 May 2014 12:42:08 +0200 Subject: [PATCH] [OLINGO-266] first client base FIT test (service document) --- .../apache/olingo/fit/tecsvc/BasicITCase.java | 60 +++++++++++++++++++ .../apache/olingo/fit/tecsvc/PingITCase.java | 14 ++--- 2 files changed, 66 insertions(+), 8 deletions(-) create mode 100644 fit/src/test/java/org/apache/olingo/fit/tecsvc/BasicITCase.java diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/BasicITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/BasicITCase.java new file mode 100644 index 000000000..8a610b50b --- /dev/null +++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/BasicITCase.java @@ -0,0 +1,60 @@ +/* + * 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.fit.tecsvc; + +import static org.junit.Assert.assertNotNull; + +import org.apache.olingo.client.api.communication.request.retrieve.EdmMetadataRequest; +import org.apache.olingo.client.api.communication.request.retrieve.ODataServiceDocumentRequest; +import org.apache.olingo.client.api.v4.ODataClient; +import org.apache.olingo.client.core.ODataClientFactory; +import org.apache.olingo.commons.api.domain.ODataServiceDocument; +import org.apache.olingo.commons.api.edm.Edm; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +public class BasicITCase { + + private static final String BASE_URI = "http://localhost:9080/tecsvc/odata.svc"; + + private ODataClient odata; + + @Before + public void before() { + odata = ODataClientFactory.getV4(); + } + + @Test + public void readServiceDocument() { + ODataServiceDocumentRequest request = odata.getRetrieveRequestFactory().getServiceDocumentRequest(BASE_URI + "/"); + assertNotNull(request); + ODataServiceDocument serviceDocument = request.execute().getBody(); + assertNotNull(serviceDocument); + } + + @Test + @Ignore + public void readMetadata() { + EdmMetadataRequest request = odata.getRetrieveRequestFactory().getMetadataRequest(BASE_URI + "/$metadata"); + assertNotNull(request); + Edm edm = request.execute().getBody(); + assertNotNull(edm); + } +} diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/PingITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/PingITCase.java index c13de43e4..3b9bbf45e 100644 --- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/PingITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/PingITCase.java @@ -23,14 +23,12 @@ import static org.junit.Assert.assertEquals; import java.net.HttpURLConnection; import java.net.URL; -import org.apache.olingo.commons.api.http.HttpHeader; -import org.apache.olingo.commons.api.http.HttpStatusCode; import org.junit.Test; public class PingITCase { - private static final String REF_SERVICE_REDIRECT = "http://localhost:9080/tecsvc/odata.svc"; - private static final String REF_SERVICE = REF_SERVICE_REDIRECT + "/"; + private static final String REF_SERVICE = "http://localhost:9080/tecsvc/odata.svc/"; + private static final String REDIRECT_URL = "http://localhost:9080/tecsvc/odata.svc"; @Test public void ping() throws Exception { @@ -46,15 +44,15 @@ public class PingITCase { @Test public void redirect() throws Exception { - URL url = new URL(REF_SERVICE_REDIRECT); + + URL url = new URL(REDIRECT_URL); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); connection.connect(); int code = connection.getResponseCode(); - - assertEquals(HttpStatusCode.TEMPORARY_REDIRECT, code); - assertEquals("/", connection.getHeaderField(HttpHeader.LOCATION)); + assertEquals(200, code); } + }