[OLINGO-266] first client base FIT test (service document)

This commit is contained in:
Stephan Klevenz 2014-05-23 12:42:08 +02:00
parent 44e0c6495a
commit b40ae95b7f
2 changed files with 66 additions and 8 deletions

View File

@ -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);
}
}

View File

@ -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);
}
}