You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by il...@apache.org on 2014/04/29 11:51:50 UTC
[06/11] [OLINGO-236] Refactor complete
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/v4/QueryOptionsTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/QueryOptionsTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/QueryOptionsTestITCase.java
new file mode 100644
index 0000000..baa2bd4
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/v4/QueryOptionsTestITCase.java
@@ -0,0 +1,215 @@
+/*
+ * 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.v4;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetRequest;
+import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
+import org.apache.olingo.client.api.uri.v4.URIBuilder;
+import static org.apache.olingo.fit.v4.AbstractTestITCase.client;
+import org.apache.olingo.commons.api.domain.ODataInlineEntitySet;
+import org.apache.olingo.commons.api.domain.v4.ODataEntity;
+import org.apache.olingo.commons.api.domain.v4.ODataEntitySet;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
+import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.junit.Test;
+
+/**
+ * This is the unit test class to check for query options.
+ */
+public class QueryOptionsTestITCase extends AbstractTestITCase {
+
+ /**
+ * Test <tt>$expand</tt>.
+ */
+ public void expand() {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Customers").appendKeySegment(1).expand("Orders");
+
+ final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
+ req.setFormat(ODataPubFormat.JSON_FULL_METADATA);
+
+ final ODataEntity customer = req.execute().getBody();
+ assertTrue(customer.getNavigationLink("Orders") instanceof ODataInlineEntitySet);
+ }
+
+ /**
+ * Test <tt>$filter</tt> and <tt>$orderby</tt>.
+ *
+ * @see org.apache.olingo.client.core.v3.FilterFactoryTest for more tests.
+ */
+ @Test
+ public void filterOrderby() throws EdmPrimitiveTypeException {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("People").filter("(PersonID lt 3)");
+
+ // 1. check that filtered entity set looks as expected
+ ODataEntitySetRequest<ODataEntitySet> req =
+ client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.build());
+ req.setFormat(ODataPubFormat.JSON);
+
+ ODataEntitySet feed = req.execute().getBody();
+ assertNotNull(feed);
+ assertEquals(2, feed.getEntities().size());
+
+ // 2. extract PersonID values - sorted ASC by default
+ final List<Integer> former = new ArrayList<Integer>(2);
+ for (ODataEntity entity : feed.getEntities()) {
+ final Integer personID = entity.getProperty("PersonID").getPrimitiveValue().toCastValue(Integer.class);
+ assertTrue(personID < 3);
+ former.add(personID);
+ }
+
+ // 3. add orderby clause to filter above
+ req = client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.orderBy("PersonID desc").build());
+ req.setFormat(ODataPubFormat.JSON);
+ feed = req.execute().getBody();
+ assertNotNull(feed);
+ assertEquals(2, feed.getEntities().size());
+
+ // 4. extract again VIN value - now they were required to be sorted DESC
+ final List<Integer> latter = new ArrayList<Integer>(2);
+ for (ODataEntity entity : feed.getEntities()) {
+ final Integer personID = entity.getProperty("PersonID").getPrimitiveValue().toCastValue(Integer.class);
+ assertTrue(personID < 3);
+ latter.add(personID);
+ }
+
+ // 5. reverse latter and expect to be equal to former
+ Collections.reverse(latter);
+ assertEquals(former, latter);
+ }
+
+ /**
+ * Test <tt>$format</tt>.
+ */
+ @Test
+ public void format() {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Customers").appendKeySegment(1).format("json");
+
+ final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
+ req.setFormat(ODataPubFormat.ATOM);
+
+ final ODataRetrieveResponse<ODataEntity> res = req.execute();
+ assertNotNull(res);
+ assertTrue(res.getContentType().replaceAll(" ", "").
+ startsWith(ODataPubFormat.JSON.toString(client.getServiceVersion())));
+ }
+
+ /**
+ * Test <tt>$skip</tt>.
+ */
+ public void skip() {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("People");
+
+ // 1. check that filtered entity set looks as expected
+ ODataEntitySetRequest<ODataEntitySet> req =
+ client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.skip(2).build());
+ ODataEntitySet feed = req.execute().getBody();
+ assertEquals(3, feed.getEntities().size());
+ }
+
+ /**
+ * Test <tt>$top</tt>.
+ */
+ public void top() {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("People");
+
+ // 1. check that filtered entity set looks as expected
+ ODataEntitySetRequest<ODataEntitySet> req = client.getRetrieveRequestFactory().
+ getEntitySetRequest(uriBuilder.top(2).build());
+ ODataEntitySet feed = req.execute().getBody();
+ assertEquals(2, feed.getEntities().size());
+ }
+
+ /**
+ * Test <tt>$skiptoken</tt>.
+ */
+ @Test
+ public void skiptoken() throws EdmPrimitiveTypeException {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL);
+ uriBuilder.appendEntitySetSegment("People").skipToken("5");
+
+ final ODataEntitySetRequest<ODataEntitySet> req =
+ client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.build());
+ req.setFormat(ODataPubFormat.JSON);
+
+ final ODataEntitySet feed = req.execute().getBody();
+ assertNotNull(feed);
+ assertEquals(1, feed.getEntities().size());
+
+ for (ODataEntity entity : feed.getEntities()) {
+ assertTrue(entity.getProperty("PersonID").getPrimitiveValue().toCastValue(Integer.class) > 5);
+ }
+ }
+
+ /**
+ * Test <tt>$inlinecount</tt>.
+ */
+ @Test
+ public void inlinecount() {
+ final URIBuilder uriBuilder =
+ client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Customers").count(true);
+
+ final ODataEntitySetRequest<ODataEntitySet> req =
+ client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.build());
+ req.setFormat(ODataPubFormat.JSON);
+ final ODataEntitySet feed = req.execute().getBody();
+ assertNotNull(feed);
+ assertEquals(feed.getEntities().size(), feed.getCount());
+ }
+
+ /**
+ * Test <tt>$select</tt>.
+ */
+ @Test
+ public void select() {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Customers").appendKeySegment(1).select("PersonID,Orders").expand("Orders");
+
+ final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
+ req.setFormat(ODataPubFormat.JSON_FULL_METADATA);
+
+ final ODataEntity customer = req.execute().getBody();
+ assertEquals(1, customer.getProperties().size());
+ assertEquals(1, customer.getNavigationLinks().size());
+ assertTrue((customer.getNavigationLinks().get(0) instanceof ODataInlineEntitySet));
+ }
+
+ @Test
+ public void issue253() {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("relatedEntitySelect").appendEntitySetSegment("Customers").appendKeySegment(1).
+ expandWithSelect("Orders", "OrderID", "OrderDetails");
+
+ final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
+ req.setFormat(ODataPubFormat.JSON_FULL_METADATA);
+
+ final ODataRetrieveResponse<ODataEntity> res = req.execute();
+ assertEquals(200, res.getStatusCode());
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/v4/ServiceDocumentTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/ServiceDocumentTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/ServiceDocumentTestITCase.java
new file mode 100644
index 0000000..5c01b65
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/v4/ServiceDocumentTestITCase.java
@@ -0,0 +1,62 @@
+/*
+ * 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.v4;
+
+import static org.junit.Assert.assertEquals;
+
+import java.net.URI;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataServiceDocumentRequest;
+import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
+import org.apache.olingo.commons.api.domain.ODataServiceDocument;
+import org.apache.olingo.commons.api.format.ODataFormat;
+import org.junit.Test;
+
+public class ServiceDocumentTestITCase extends AbstractTestITCase {
+
+ private void retrieveServiceDocument(final ODataFormat format) {
+ final ODataServiceDocumentRequest req =
+ client.getRetrieveRequestFactory().getServiceDocumentRequest(testStaticServiceRootURL);
+ req.setFormat(format);
+
+ final ODataRetrieveResponse<ODataServiceDocument> res = req.execute();
+ assertEquals(200, res.getStatusCode());
+
+ final ODataServiceDocument serviceDocument = res.getBody();
+ assertEquals(12, serviceDocument.getEntitySets().size());
+ assertEquals(6, serviceDocument.getSingletons().size());
+ assertEquals(6, serviceDocument.getFunctionImports().size());
+
+ assertEquals(URI.create(testStaticServiceRootURL + "/ProductDetails"),
+ serviceDocument.getEntitySetURI("ProductDetails"));
+ assertEquals(URI.create(testStaticServiceRootURL + "/Boss"),
+ serviceDocument.getSingletonURI("Boss"));
+ assertEquals(URI.create(testStaticServiceRootURL + "/GetPerson"),
+ serviceDocument.getFunctionImportURI("GetPerson"));
+ }
+
+ @Test
+ public void retrieveServiceDocumentAsXML() {
+ retrieveServiceDocument(ODataFormat.XML);
+ }
+
+ @Test
+ public void retrieveServiceDocumentAsJSON() {
+ retrieveServiceDocument(ODataFormat.JSON);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/resources/sample.png
----------------------------------------------------------------------
diff --git a/fit/src/test/resources/sample.png b/fit/src/test/resources/sample.png
new file mode 100644
index 0000000..399ee46
Binary files /dev/null and b/fit/src/test/resources/sample.png differ
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/pom.xml
----------------------------------------------------------------------
diff --git a/lib/client-core/pom.xml b/lib/client-core/pom.xml
index 58025ee..f4206d1 100644
--- a/lib/client-core/pom.xml
+++ b/lib/client-core/pom.xml
@@ -62,14 +62,6 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</dependency>
-
- <dependency>
- <groupId>org.apache.olingo</groupId>
- <artifactId>olingo-fit</artifactId>
- <version>${project.version}</version>
- <type>war</type>
- <scope>test</scope>
- </dependency>
</dependencies>
<build>
@@ -85,39 +77,6 @@
</systemPropertyVariables>
</configuration>
</plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-failsafe-plugin</artifactId>
- <inherited>true</inherited>
- <configuration>
- <systemPropertyVariables>
- <propertyName>org.slf4j.simpleLogger.defaultLogLevel</propertyName>
- <org.slf4j.simpleLogger.defaultLogLevel>DEBUG</org.slf4j.simpleLogger.defaultLogLevel>
- </systemPropertyVariables>
- </configuration>
- </plugin>
-
- <plugin>
- <groupId>org.codehaus.cargo</groupId>
- <artifactId>cargo-maven2-plugin</artifactId>
- <inherited>true</inherited>
- <executions>
- <execution>
- <id>start-container</id>
- <phase>pre-integration-test</phase>
- <goals>
- <goal>start</goal>
- </goals>
- </execution>
- <execution>
- <id>stop-container</id>
- <phase>post-integration-test</phase>
- <goals>
- <goal>stop</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
</plugins>
<resources>
@@ -131,10 +90,6 @@
<directory>src/test/resources</directory>
<filtering>false</filtering>
</testResource>
- <testResource>
- <directory>${basedir}/../../fit/src/main/resources</directory>
- <filtering>true</filtering>
- </testResource>
</testResources>
</build>
</project>
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/AbstractBaseTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/AbstractBaseTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/AbstractBaseTestITCase.java
deleted file mode 100644
index 33c27a6..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/AbstractBaseTestITCase.java
+++ /dev/null
@@ -1,98 +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.client.core.it;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.StringWriter;
-import org.apache.commons.io.IOUtils;
-import org.apache.olingo.client.api.CommonODataClient;
-import org.apache.olingo.commons.api.data.Entity;
-import org.apache.olingo.commons.api.data.EntitySet;
-import org.apache.olingo.commons.api.domain.CommonODataEntity;
-import org.apache.olingo.commons.api.domain.CommonODataProperty;
-import org.apache.olingo.commons.api.domain.ODataValue;
-import org.apache.olingo.commons.core.data.AtomEntityImpl;
-import org.apache.olingo.commons.core.data.JSONEntityImpl;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public abstract class AbstractBaseTestITCase {
-
- /**
- * Logger.
- */
- protected static final Logger LOG = LoggerFactory.getLogger(AbstractBaseTestITCase.class);
-
- @SuppressWarnings("rawtypes")
- protected abstract CommonODataClient getClient();
-
- protected void debugEntity(final Entity entity, final String message) {
- if (LOG.isDebugEnabled()) {
- final StringWriter writer = new StringWriter();
- getClient().getSerializer().entity(entity, writer);
- writer.flush();
- LOG.debug(message + "\n{}", writer.toString());
- }
- }
-
- protected void debugEntitySet(final EntitySet entitySet, final String message) {
- if (LOG.isDebugEnabled()) {
- final StringWriter writer = new StringWriter();
- getClient().getSerializer().entitySet(entitySet, writer);
- writer.flush();
- LOG.debug(message + "\n{}", writer.toString());
- }
- }
-
- protected void debugODataProperty(final CommonODataProperty property, final String message) {
- LOG.debug(message + "\n{}", property.toString());
- }
-
- protected void debugODataValue(final ODataValue value, final String message) {
- LOG.debug(message + "\n{}", value.toString());
- }
-
- protected void debugODataEntity(final CommonODataEntity entity, final String message) {
- if (LOG.isDebugEnabled()) {
- StringWriter writer = new StringWriter();
- getClient().getSerializer().entity(getClient().getBinder().getEntity(entity, AtomEntityImpl.class), writer);
- writer.flush();
- LOG.debug(message + " (Atom)\n{}", writer.toString());
-
- writer = new StringWriter();
- getClient().getSerializer().entity(getClient().getBinder().getEntity(entity, JSONEntityImpl.class), writer);
- writer.flush();
- LOG.debug(message + " (JSON)\n{}", writer.toString());
- }
- }
-
- protected void debugInputStream(final InputStream input, final String message) {
- if (LOG.isDebugEnabled()) {
- try {
- LOG.debug(message + "\n{}", IOUtils.toString(input));
- } catch (IOException e) {
- LOG.error("Error writing stream", e);
- } finally {
- IOUtils.closeQuietly(input);
- }
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/AbstractMetadataTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/AbstractMetadataTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/AbstractMetadataTestITCase.java
deleted file mode 100644
index 623eca8..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/AbstractMetadataTestITCase.java
+++ /dev/null
@@ -1,35 +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.client.core.it;
-
-import org.apache.olingo.client.api.CommonODataClient;
-
-public abstract class AbstractMetadataTestITCase {
-
- @SuppressWarnings("rawtypes")
- protected abstract CommonODataClient getClient();
-
- protected String getTestServiceRoot() {
- return "http://localhost:9080/StaticService/" + getClient().getServiceVersion().name() + "/Static.svc";
- }
-
- protected String getNorthwindServiceRoot() {
- return "http://localhost:9080/StaticService/" + getClient().getServiceVersion().name() + "/NorthWind.svc";
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/AbstractTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/AbstractTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/AbstractTestITCase.java
deleted file mode 100644
index 9f06dc4..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/AbstractTestITCase.java
+++ /dev/null
@@ -1,516 +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.client.core.it.v3;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.io.IOException;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.olingo.client.api.communication.ODataClientErrorException;
-import org.apache.olingo.client.api.communication.request.cud.ODataDeleteRequest;
-import org.apache.olingo.client.api.communication.request.cud.ODataEntityCreateRequest;
-import org.apache.olingo.client.api.communication.request.cud.ODataEntityUpdateRequest;
-import org.apache.olingo.client.api.communication.request.cud.v3.UpdateType;
-import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
-import org.apache.olingo.client.api.communication.response.ODataDeleteResponse;
-import org.apache.olingo.client.api.communication.response.ODataEntityCreateResponse;
-import org.apache.olingo.client.api.communication.response.ODataEntityUpdateResponse;
-import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
-import org.apache.olingo.client.api.http.HttpMethod;
-import org.apache.olingo.client.api.uri.v3.URIBuilder;
-import org.apache.olingo.client.api.v3.ODataClient;
-import org.apache.olingo.client.core.ODataClientFactory;
-import org.apache.olingo.client.core.it.AbstractBaseTestITCase;
-import org.apache.olingo.client.core.uri.URIUtils;
-import org.apache.olingo.commons.api.domain.CommonODataEntity;
-import org.apache.olingo.commons.api.domain.CommonODataEntitySet;
-import org.apache.olingo.commons.api.domain.CommonODataProperty;
-import org.apache.olingo.commons.api.domain.ODataCollectionValue;
-import org.apache.olingo.commons.api.domain.ODataComplexValue;
-import org.apache.olingo.commons.api.domain.ODataInlineEntity;
-import org.apache.olingo.commons.api.domain.ODataInlineEntitySet;
-import org.apache.olingo.commons.api.domain.ODataLink;
-import org.apache.olingo.commons.api.domain.ODataValue;
-import org.apache.olingo.commons.api.domain.v3.ODataEntity;
-import org.apache.olingo.commons.api.domain.v3.ODataProperty;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.format.ODataPubFormat;
-import org.junit.BeforeClass;
-
-public abstract class AbstractTestITCase extends AbstractBaseTestITCase {
-
- protected static final FullQualifiedName TEST_PRODUCT_TYPE =
- new FullQualifiedName("Microsoft.Test.OData.Services.AstoriaDefaultService.Product");
-
- protected static ODataClient client;
-
- protected static String testStaticServiceRootURL;
-
- protected static String testKeyAsSegmentServiceRootURL;
-
- protected static String testActionOverloadingServiceRootURL;
-
- protected static String testOpenTypeServiceRootURL;
-
- protected static String testLargeModelServiceRootURL;
-
- protected static String testAuthServiceRootURL;
-
- @BeforeClass
- public static void setUpODataServiceRoot() throws IOException {
- testStaticServiceRootURL = "http://localhost:9080/StaticService/V30/Static.svc";
- testKeyAsSegmentServiceRootURL = "http://localhost:9080/StaticService/V30/KeyAsSegment.svc";
- testActionOverloadingServiceRootURL = "http://localhost:9080/StaticService/V30/ActionOverloading.svc";
- testOpenTypeServiceRootURL = "http://localhost:9080/StaticService/V30/OpenType.svc";
- testLargeModelServiceRootURL = "http://localhost:9080/StaticService/V30/Static.svc/large";
- testAuthServiceRootURL = "http://localhost:9080/DefaultService.svc";
- }
-
- @BeforeClass
- public static void setClientInstance() {
- client = ODataClientFactory.getV3();
- }
-
- @Override
- protected ODataClient getClient() {
- return client;
- }
-
- protected void checkLinks(final Collection<ODataLink> original, final Collection<ODataLink> actual) {
- assertTrue(original.size() <= actual.size());
-
- for (ODataLink originalLink : original) {
- ODataLink foundOriginal = null;
- ODataLink foundActual = null;
-
- for (ODataLink actualLink : actual) {
-
- if (actualLink.getType() == originalLink.getType()
- && (originalLink.getLink() == null
- || actualLink.getLink().toASCIIString().endsWith(originalLink.getLink().toASCIIString()))
- && actualLink.getName().equals(originalLink.getName())) {
-
- foundOriginal = originalLink;
- foundActual = actualLink;
- }
- }
-
- assertNotNull(foundOriginal);
- assertNotNull(foundActual);
-
- if (foundOriginal instanceof ODataInlineEntity && foundActual instanceof ODataInlineEntity) {
- final CommonODataEntity originalInline = ((ODataInlineEntity) foundOriginal).getEntity();
- assertNotNull(originalInline);
-
- final CommonODataEntity actualInline = ((ODataInlineEntity) foundActual).getEntity();
- assertNotNull(actualInline);
-
- checkProperties(originalInline.getProperties(), actualInline.getProperties());
- }
- }
- }
-
- protected void checkProperties(final Collection<? extends CommonODataProperty> original,
- final Collection<? extends CommonODataProperty> actual) {
-
- assertTrue(original.size() <= actual.size());
-
- // re-organize actual properties into a Map<String, ODataProperty>
- final Map<String, CommonODataProperty> actualProps = new HashMap<String, CommonODataProperty>(actual.size());
-
- for (CommonODataProperty prop : actual) {
- assertFalse(actualProps.containsKey(prop.getName()));
- actualProps.put(prop.getName(), prop);
- }
-
- assertTrue(actual.size() <= actualProps.size());
-
- for (CommonODataProperty prop : original) {
- assertNotNull(prop);
- if (actualProps.containsKey(prop.getName())) {
- final CommonODataProperty actualProp = actualProps.get(prop.getName());
- assertNotNull(actualProp);
-
- if (prop.getValue() != null && actualProp.getValue() != null) {
- checkPropertyValue(prop.getName(), prop.getValue(), actualProp.getValue());
- }
- } else {
- // nothing ... maybe :FC_KeepInContent="false"
- // ..... no assert can be done ....
- }
- }
- }
-
- protected void checkPropertyValue(final String propertyName,
- final ODataValue original, final ODataValue actual) {
-
- assertNotNull("Null original value for " + propertyName, original);
- assertNotNull("Null actual value for " + propertyName, actual);
-
- assertEquals("Type mismatch for '" + propertyName + "': "
- + original.getClass().getSimpleName() + "-" + actual.getClass().getSimpleName(),
- original.getClass().getSimpleName(), actual.getClass().getSimpleName());
-
- if (original.isComplex()) {
- final List<ODataProperty> originalFileds = new ArrayList<ODataProperty>();
- for (ODataProperty prop : original.<ODataProperty>asComplex()) {
- originalFileds.add(prop);
- }
-
- final List<ODataProperty> actualFileds = new ArrayList<ODataProperty>();
- for (ODataProperty prop : actual.<ODataProperty>asComplex()) {
- actualFileds.add(prop);
- }
-
- checkProperties(originalFileds, actualFileds);
- } else if (original.isCollection()) {
- assertTrue(original.asCollection().size() <= actual.asCollection().size());
-
- boolean found = original.asCollection().isEmpty();
-
- for (ODataValue originalValue : original.asCollection()) {
- for (ODataValue actualValue : actual.asCollection()) {
- try {
- checkPropertyValue(propertyName, originalValue, actualValue);
- found = true;
- } catch (AssertionError ignore) {
- // ignore
- }
- }
- }
-
- assertTrue("Found " + actual + " but expected " + original, found);
- } else {
- assertTrue("Primitive value for '" + propertyName + "' type mismatch: " + original.asPrimitive().
- getTypeKind() + "-" + actual.asPrimitive().getTypeKind(),
- original.asPrimitive().getTypeKind().equals(actual.asPrimitive().getTypeKind()));
-
- assertEquals("Primitive value for '" + propertyName + "' mismatch: " + original.asPrimitive().toString()
- + "-" + actual.asPrimitive().toString(),
- original.asPrimitive().toString(), actual.asPrimitive().toString());
- }
- }
-
- protected ODataEntity getSampleCustomerInfo(final int id, final String sampleinfo) {
- final ODataEntity entity = getClient().getObjectFactory().newEntity(new FullQualifiedName(
- "Microsoft.Test.OData.Services.AstoriaDefaultService.CustomerInfo"));
- entity.setMediaEntity(true);
-
- getClient().getBinder().add(entity,
- getClient().getObjectFactory().newPrimitiveProperty("Information",
- getClient().getObjectFactory().newPrimitiveValueBuilder().buildString(sampleinfo)));
-
- return entity;
- }
-
- protected ODataEntity getSampleCustomerProfile(
- final int id, final String sampleName, final boolean withInlineInfo) {
-
- final ODataEntity entity = getClient().getObjectFactory().
- newEntity(new FullQualifiedName("Microsoft.Test.OData.Services.AstoriaDefaultService.Customer"));
-
- // add name attribute
- getClient().getBinder().add(entity,
- getClient().getObjectFactory().newPrimitiveProperty("Name",
- getClient().getObjectFactory().newPrimitiveValueBuilder().buildString(sampleName)));
-
- // add key attribute
- getClient().getBinder().add(entity,
- getClient().getObjectFactory().newPrimitiveProperty("CustomerId",
- getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(id)));
-
- // add BackupContactInfo attribute (collection)
- final ODataCollectionValue<ODataValue> backupContactInfoValue = getClient().getObjectFactory().newCollectionValue(
- "Collection(Microsoft.Test.OData.Services.AstoriaDefaultService.ContactDetails)");
- getClient().getBinder().add(entity,
- getClient().getObjectFactory().newCollectionProperty("BackupContactInfo", backupContactInfoValue));
-
- // add BackupContactInfo.ContactDetails attribute (complex)
- final ODataComplexValue<ODataProperty> contactDetails = getClient().getObjectFactory().newComplexValue(
- "Microsoft.Test.OData.Services.AstoriaDefaultService.ContactDetails");
- backupContactInfoValue.add(contactDetails);
-
- // add BackupContactInfo.ContactDetails.AlternativeNames attribute (collection)
- final ODataCollectionValue<ODataValue> altNamesValue = getClient().getObjectFactory().
- newCollectionValue("Collection(Edm.String)");
- altNamesValue.add(getClient().getObjectFactory().newPrimitiveValueBuilder().buildString("myname"));
- contactDetails.add(getClient().getObjectFactory().newCollectionProperty("AlternativeNames", altNamesValue));
-
- // add BackupContactInfo.ContactDetails.EmailBag attribute (collection)
- final ODataCollectionValue<ODataValue> emailBagValue = getClient().getObjectFactory().
- newCollectionValue("Collection(Edm.String)");
- emailBagValue.add(getClient().getObjectFactory().newPrimitiveValueBuilder().buildString("myname@mydomain.com"));
- contactDetails.add(getClient().getObjectFactory().newCollectionProperty("EmailBag", emailBagValue));
-
- // add BackupContactInfo.ContactDetails.ContactAlias attribute (complex)
- final ODataComplexValue<ODataProperty> contactAliasValue = getClient().getObjectFactory().newComplexValue(
- "Microsoft.Test.OData.Services.AstoriaDefaultService.Aliases");
- contactDetails.add(getClient().getObjectFactory().newComplexProperty("ContactAlias", contactAliasValue));
-
- // add BackupContactInfo.ContactDetails.ContactAlias.AlternativeNames attribute (collection)
- final ODataCollectionValue<ODataValue> aliasAltNamesValue = getClient().getObjectFactory().
- newCollectionValue("Collection(Edm.String)");
- aliasAltNamesValue.add(getClient().getObjectFactory().newPrimitiveValueBuilder().buildString("myAlternativeName"));
- contactAliasValue.add(getClient().getObjectFactory().newCollectionProperty("AlternativeNames", aliasAltNamesValue));
-
- if (withInlineInfo) {
- final ODataInlineEntity inlineInfo = getClient().getObjectFactory().newDeepInsertEntity(
- "Info",
- getSampleCustomerInfo(id, sampleName + "_Info"));
- inlineInfo.getEntity().setMediaEntity(true);
- entity.addLink(inlineInfo);
- }
-
- return entity;
- }
-
- protected String getETag(final URI uri) {
- final ODataRetrieveResponse<ODataEntity> res = getClient().getRetrieveRequestFactory().
- getEntityRequest(uri).execute();
- try {
- return res.getETag();
- } finally {
- res.close();
- }
- }
-
- protected ODataEntity read(final ODataPubFormat format, final URI editLink) {
- final ODataEntityRequest<ODataEntity> req = getClient().getRetrieveRequestFactory().
- getEntityRequest(editLink);
- req.setFormat(format);
-
- final ODataRetrieveResponse<ODataEntity> res = req.execute();
- final ODataEntity entity = res.getBody();
-
- assertNotNull(entity);
-
- if (ODataPubFormat.JSON_FULL_METADATA == format || ODataPubFormat.ATOM == format) {
- assertEquals(req.getURI(), entity.getEditLink());
- }
-
- return entity;
- }
-
- protected ODataEntity createEntity(
- final String serviceRootURL,
- final ODataPubFormat format,
- final ODataEntity original,
- final String entitySetName) {
-
- final URIBuilder uriBuilder = getClient().getURIBuilder(serviceRootURL).
- appendEntitySetSegment(entitySetName);
-
- debugODataEntity(original, "About to create");
-
- final ODataEntityCreateRequest<ODataEntity> createReq =
- getClient().getCUDRequestFactory().getEntityCreateRequest(uriBuilder.build(), original);
- createReq.setFormat(format);
-
- final ODataEntityCreateResponse<ODataEntity> createRes = createReq.execute();
- assertEquals(201, createRes.getStatusCode());
- assertEquals("Created", createRes.getStatusMessage());
-
- final ODataEntity created = createRes.getBody();
- assertNotNull(created);
-
- debugODataEntity(created, "Just created");
-
- return created;
- }
-
- protected ODataEntity compareEntities(final String serviceRootURL,
- final ODataPubFormat format,
- final ODataEntity original,
- final int actualObjectId,
- final Collection<String> expands) {
-
- final URIBuilder uriBuilder = getClient().getURIBuilder(serviceRootURL).
- appendEntitySetSegment("Customer").appendKeySegment(actualObjectId);
-
- // search expanded
- if (expands != null) {
- for (String expand : expands) {
- uriBuilder.expand(expand);
- }
- }
-
- final ODataEntityRequest<ODataEntity> req = getClient().getRetrieveRequestFactory().
- getEntityRequest(uriBuilder.build());
- req.setFormat(format);
-
- final ODataRetrieveResponse<ODataEntity> res = req.execute();
- assertEquals(200, res.getStatusCode());
-
- final ODataEntity actual = res.getBody();
- assertNotNull(actual);
-
- // check defined links
- checkLinks(original.getAssociationLinks(), actual.getAssociationLinks());
- checkLinks(original.getEditMediaLinks(), actual.getEditMediaLinks());
- checkLinks(original.getNavigationLinks(), actual.getNavigationLinks());
-
- // check defined properties equality
- checkProperties(original.getProperties(), actual.getProperties());
-
- return actual;
- }
-
- protected void cleanAfterCreate(
- final ODataPubFormat format,
- final ODataEntity created,
- final boolean includeInline,
- final String baseUri) {
-
- final Set<URI> toBeDeleted = new HashSet<URI>();
- toBeDeleted.add(created.getEditLink());
-
- if (includeInline) {
- for (ODataLink link : created.getNavigationLinks()) {
- if (link instanceof ODataInlineEntity) {
- final CommonODataEntity inline = ((ODataInlineEntity) link).getEntity();
- if (inline.getEditLink() != null) {
- toBeDeleted.add(URIUtils.getURI(baseUri, inline.getEditLink().toASCIIString()));
- }
- }
-
- if (link instanceof ODataInlineEntitySet) {
- final CommonODataEntitySet inline = ((ODataInlineEntitySet) link).getEntitySet();
- for (CommonODataEntity entity : inline.getEntities()) {
- if (entity.getEditLink() != null) {
- toBeDeleted.add(URIUtils.getURI(baseUri, entity.getEditLink().toASCIIString()));
- }
- }
- }
- }
- }
-
- assertFalse(toBeDeleted.isEmpty());
-
- for (URI link : toBeDeleted) {
- final ODataDeleteRequest deleteReq = getClient().getCUDRequestFactory().getDeleteRequest(link);
- final ODataDeleteResponse deleteRes = deleteReq.execute();
-
- assertEquals(204, deleteRes.getStatusCode());
- assertEquals("No Content", deleteRes.getStatusMessage());
-
- deleteRes.close();
-
- final ODataEntityRequest<ODataEntity> retrieveReq = getClient().getRetrieveRequestFactory().
- getEntityRequest(link);
- // bug that needs to be fixed on the SampleService - cannot get entity not found with header
- // Accept: application/json;odata=minimalmetadata
- retrieveReq.setFormat(format == ODataPubFormat.JSON_FULL_METADATA ? ODataPubFormat.JSON : format);
-
- Exception exception = null;
- try {
- retrieveReq.execute();
- fail();
- } catch (ODataClientErrorException e) {
- exception = e;
- assertEquals(404, e.getStatusLine().getStatusCode());
- }
- assertNotNull(exception);
- }
- }
-
- protected void updateEntityDescription(
- final ODataPubFormat format, final ODataEntity changes, final UpdateType type) {
-
- updateEntityDescription(format, changes, type, null);
- }
-
- protected void updateEntityDescription(
- final ODataPubFormat format, final ODataEntity changes, final UpdateType type, final String etag) {
-
- updateEntityStringProperty("Description", format, changes, type, etag);
- }
-
- protected void updateEntityStringProperty(final String propertyName,
- final ODataPubFormat format, final ODataEntity changes, final UpdateType type, final String etag) {
-
- final URI editLink = changes.getEditLink();
-
- final String newm = "New " + propertyName + "(" + System.currentTimeMillis() + ")";
-
- ODataProperty propertyValue = changes.getProperty(propertyName);
-
- final String oldm;
- if (propertyValue == null) {
- oldm = null;
- } else {
- oldm = propertyValue.getValue().toString();
- changes.getProperties().remove(propertyValue);
- }
-
- assertNotEquals(newm, oldm);
-
- getClient().getBinder().add(changes,
- getClient().getObjectFactory().newPrimitiveProperty(propertyName,
- getClient().getObjectFactory().newPrimitiveValueBuilder().buildString(newm)));
-
- update(type, changes, format, etag);
-
- final ODataEntity actual = read(format, editLink);
-
- propertyValue = null;
-
- for (ODataProperty prop : actual.getProperties()) {
- if (prop.getName().equals(propertyName)) {
- propertyValue = prop;
- }
- }
-
- assertNotNull(propertyValue);
- assertEquals(newm, propertyValue.getValue().toString());
- }
-
- protected void update(
- final UpdateType type, final ODataEntity changes, final ODataPubFormat format, final String etag) {
-
- final ODataEntityUpdateRequest<ODataEntity> req =
- getClient().getCUDRequestFactory().getEntityUpdateRequest(type, changes);
-
- if (getClient().getConfiguration().isUseXHTTPMethod()) {
- assertEquals(HttpMethod.POST, req.getMethod());
- } else {
- assertEquals(type.getMethod(), req.getMethod());
- }
- req.setFormat(format);
-
- if (StringUtils.isNotBlank(etag)) {
- req.setIfMatch(etag); // Product include ETag header into the response .....
- }
-
- final ODataEntityUpdateResponse<ODataEntity> res = req.execute();
- assertEquals(204, res.getStatusCode());
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/ActionOverloadingTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/ActionOverloadingTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/ActionOverloadingTestITCase.java
deleted file mode 100644
index 4273a9c..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/ActionOverloadingTestITCase.java
+++ /dev/null
@@ -1,181 +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.client.core.it.v3;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
-import java.util.LinkedHashMap;
-import java.util.Map;
-import org.apache.olingo.client.api.communication.request.invoke.ODataNoContent;
-import org.apache.olingo.client.api.communication.response.ODataInvokeResponse;
-import org.apache.olingo.client.api.uri.v3.URIBuilder;
-import org.apache.olingo.client.core.uri.URIUtils;
-import org.apache.olingo.commons.api.domain.ODataValue;
-import org.apache.olingo.commons.api.domain.v3.ODataEntity;
-import org.apache.olingo.commons.api.domain.v3.ODataEntitySet;
-import org.apache.olingo.commons.api.domain.v3.ODataProperty;
-import org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.EdmAction;
-import org.apache.olingo.commons.api.edm.EdmActionImport;
-import org.apache.olingo.commons.api.edm.EdmEntityContainer;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.core.edm.primitivetype.EdmInt32;
-import org.junit.Test;
-
-public class ActionOverloadingTestITCase extends AbstractTestITCase {
-
- @Test
- public void retrieveProduct() throws EdmPrimitiveTypeException {
- final Edm edm = getClient().getRetrieveRequestFactory().
- getMetadataRequest(testActionOverloadingServiceRootURL).execute().getBody();
- assertNotNull(edm);
-
- final EdmEntityContainer container = edm.getSchemas().get(0).getEntityContainer();
- assertNotNull(container);
-
- int execs = 0;
- for (EdmActionImport actImp : container.getActionImports()) {
- if ("RetrieveProduct".equals(actImp.getName())) {
- // 1. unbound
- final EdmAction unbound = actImp.getUnboundAction();
- assertNotNull(unbound);
- assertEquals(EdmInt32.getInstance(), unbound.getReturnType().getType());
-
- final URIBuilder unboundBuilder = getClient().getURIBuilder(testActionOverloadingServiceRootURL).
- appendOperationCallSegment(URIUtils.operationImportURISegment(container, actImp.getName()));
- final ODataInvokeResponse<ODataProperty> unboundRes = getClient().getInvokeRequestFactory().
- <ODataProperty>getInvokeRequest(unboundBuilder.build(), unbound).execute();
- assertNotNull(unboundRes);
- assertEquals(200, unboundRes.getStatusCode());
- assertEquals(Integer.valueOf(-10), unboundRes.getBody().getPrimitiveValue().toCastValue(Integer.class));
- execs++;
-
- // 2. bound to Product
- final EdmAction productBound = edm.getBoundAction(
- new FullQualifiedName(container.getNamespace(), actImp.getName()),
- new FullQualifiedName(container.getNamespace(), "Product"), false);
- assertNotNull(productBound);
- assertEquals(EdmInt32.getInstance(), productBound.getReturnType().getType());
-
- final ODataEntity product = getClient().getRetrieveRequestFactory().getEntityRequest(
- getClient().getURIBuilder(testActionOverloadingServiceRootURL).
- appendEntitySetSegment("Product").appendKeySegment(-10).build()).
- execute().getBody();
- assertNotNull(product);
-
- final ODataInvokeResponse<ODataProperty> productBoundRes = getClient().getInvokeRequestFactory().
- <ODataProperty>getInvokeRequest(product.getOperation(actImp.getName()).getTarget(), unbound).
- execute();
- assertNotNull(productBoundRes);
- assertEquals(200, productBoundRes.getStatusCode());
- assertEquals(Integer.valueOf(-10), productBoundRes.getBody().getPrimitiveValue().toCastValue(Integer.class));
- execs++;
-
- // 3. bound to OrderLine
- final EdmAction orderLineBound = edm.getBoundAction(
- new FullQualifiedName(container.getNamespace(), actImp.getName()),
- new FullQualifiedName(container.getNamespace(), "OrderLine"), false);
- assertNotNull(orderLineBound);
- assertEquals(EdmInt32.getInstance(), orderLineBound.getReturnType().getType());
-
- final Map<String, Object> key = new LinkedHashMap<String, Object>(2);
- key.put("OrderId", -10);
- key.put("ProductId", -10);
- final ODataEntity orderLine = getClient().getRetrieveRequestFactory().getEntityRequest(
- getClient().getURIBuilder(testActionOverloadingServiceRootURL).
- appendEntitySetSegment("OrderLine").appendKeySegment(key).build()).
- execute().getBody();
- assertNotNull(orderLine);
-
- final ODataInvokeResponse<ODataProperty> orderLineBoundRes = getClient().getInvokeRequestFactory().
- <ODataProperty>getInvokeRequest(orderLine.getOperation(actImp.getName()).getTarget(), unbound).
- execute();
- assertNotNull(orderLineBoundRes);
- assertEquals(200, orderLineBoundRes.getStatusCode());
- assertEquals(Integer.valueOf(-10), orderLineBoundRes.getBody().getPrimitiveValue().toCastValue(Integer.class));
- execs++;
- }
- }
- assertEquals(3, execs);
- }
-
- @Test
- public void increaseSalaries() {
- final Edm edm = getClient().getRetrieveRequestFactory().
- getMetadataRequest(testActionOverloadingServiceRootURL).execute().getBody();
- assertNotNull(edm);
-
- final EdmEntityContainer container = edm.getSchemas().get(0).getEntityContainer();
- assertNotNull(container);
-
- int execs = 0;
- for (EdmActionImport actImp : container.getActionImports()) {
- if ("IncreaseSalaries".equals(actImp.getName())) {
- final Map<String, ODataValue> parameters = new LinkedHashMap<String, ODataValue>(1);
- parameters.put("n", getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(5));
-
- // 1. bound to employees
- final EdmAction employeeBound = edm.getBoundAction(
- new FullQualifiedName(container.getNamespace(), actImp.getName()),
- new FullQualifiedName(container.getNamespace(), "Employee"), true);
- assertNotNull(employeeBound);
- assertNull(employeeBound.getReturnType());
-
- final URIBuilder employeeBuilder = getClient().getURIBuilder(testActionOverloadingServiceRootURL).
- appendEntitySetSegment("Person").
- appendDerivedEntityTypeSegment("Microsoft.Test.OData.Services.AstoriaDefaultService.Employee");
- final ODataEntitySet employees = getClient().getRetrieveRequestFactory().getEntitySetRequest(
- employeeBuilder.build()).execute().getBody();
- assertNotNull(employees);
-
- final ODataInvokeResponse<ODataNoContent> employeeRes = getClient().getInvokeRequestFactory().
- <ODataNoContent>getInvokeRequest(employeeBuilder.appendOperationCallSegment(actImp.getName()).build(),
- employeeBound, parameters).execute();
- assertNotNull(employeeRes);
- assertEquals(204, employeeRes.getStatusCode());
- execs++;
-
- // 1. bound to special employees
- final EdmAction specEmpBound = edm.getBoundAction(
- new FullQualifiedName(container.getNamespace(), actImp.getName()),
- new FullQualifiedName(container.getNamespace(), "SpecialEmployee"), true);
- assertNotNull(specEmpBound);
- assertNull(specEmpBound.getReturnType());
-
- final URIBuilder specEmpBuilder = getClient().getURIBuilder(testActionOverloadingServiceRootURL).
- appendEntitySetSegment("Person").
- appendDerivedEntityTypeSegment("Microsoft.Test.OData.Services.AstoriaDefaultService.SpecialEmployee");
- final ODataEntitySet specEmps = getClient().getRetrieveRequestFactory().getEntitySetRequest(
- specEmpBuilder.build()).execute().getBody();
- assertNotNull(specEmps);
-
- final ODataInvokeResponse<ODataNoContent> specEmpsRes = getClient().getInvokeRequestFactory().
- <ODataNoContent>getInvokeRequest(specEmpBuilder.appendOperationCallSegment(actImp.getName()).build(),
- specEmpBound, parameters).execute();
- assertNotNull(specEmpsRes);
- assertEquals(204, specEmpsRes.getStatusCode());
- execs++;
- }
- }
- assertEquals(2, execs);
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/AsyncTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/AsyncTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/AsyncTestITCase.java
deleted file mode 100644
index 9b9ba9c..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/AsyncTestITCase.java
+++ /dev/null
@@ -1,134 +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.client.core.it.v3;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-
-import java.io.InputStream;
-import java.net.URI;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
-import org.apache.commons.io.IOUtils;
-import org.apache.olingo.client.api.communication.request.cud.ODataEntityUpdateRequest;
-import org.apache.olingo.client.api.communication.request.cud.v3.UpdateType;
-import org.apache.olingo.client.api.communication.request.retrieve.ODataMediaRequest;
-import org.apache.olingo.client.api.communication.request.streamed.MediaEntityCreateStreamManager;
-import org.apache.olingo.client.api.communication.request.streamed.ODataMediaEntityCreateRequest;
-import org.apache.olingo.client.api.communication.response.ODataEntityUpdateResponse;
-import org.apache.olingo.client.api.communication.response.ODataMediaEntityCreateResponse;
-import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
-import org.apache.olingo.client.api.uri.v3.URIBuilder;
-import org.apache.olingo.commons.api.domain.v3.ODataEntity;
-import org.apache.olingo.commons.api.domain.v3.ODataEntitySet;
-import org.junit.Test;
-
-public class AsyncTestITCase extends AbstractTestITCase {
-
- @Test
- public void retrieveEntitySet() throws InterruptedException, ExecutionException {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Product");
- final Future<ODataRetrieveResponse<ODataEntitySet>> futureRes =
- client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.build()).asyncExecute();
- assertNotNull(futureRes);
-
- while (!futureRes.isDone()) {
- Thread.sleep(1000L);
- }
-
- final ODataRetrieveResponse<ODataEntitySet> res = futureRes.get();
- assertNotNull(res);
- assertEquals(200, res.getStatusCode());
- assertFalse(res.getBody().getEntities().isEmpty());
- }
-
- @Test
- public void updateEntity() throws InterruptedException, ExecutionException {
- final URI uri = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Product").appendKeySegment(-10).build();
-
- final ODataRetrieveResponse<ODataEntity> entityRes = client.getRetrieveRequestFactory().
- getEntityRequest(uri).execute();
- final ODataEntity entity = entityRes.getBody();
- entity.getAssociationLinks().clear();
- entity.getNavigationLinks().clear();
- entity.getEditMediaLinks().clear();
-
- entity.getProperties().remove(entity.getProperty("Description"));
- getClient().getBinder().add(entity,
- client.getObjectFactory().newPrimitiveProperty("Description",
- client.getObjectFactory().newPrimitiveValueBuilder().setText("AsyncTest#updateEntity").build()));
-
- final ODataEntityUpdateRequest<ODataEntity> updateReq =
- client.getCUDRequestFactory().getEntityUpdateRequest(uri, UpdateType.MERGE, entity);
- updateReq.setIfMatch(entityRes.getETag());
- final Future<ODataEntityUpdateResponse<ODataEntity>> futureRes = updateReq.asyncExecute();
-
- while (!futureRes.isDone()) {
- Thread.sleep(1000L);
- }
-
- final ODataEntityUpdateResponse<ODataEntity> res = futureRes.get();
- assertNotNull(res);
- assertEquals(204, res.getStatusCode());
- }
-
- /**
- * @see MediaEntityTest#createMediaEntity(com.msopentech.odatajclient.engine.format.ODataPubFormat)
- */
- @Test
- public void createMediaEntity() throws Exception {
- URIBuilder builder = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Car");
-
- final String TO_BE_UPDATED = "async buffered stream sample";
- final InputStream input = IOUtils.toInputStream(TO_BE_UPDATED);
-
- final ODataMediaEntityCreateRequest<ODataEntity> createReq =
- client.getStreamedRequestFactory().getMediaEntityCreateRequest(builder.build(), input);
-
- final MediaEntityCreateStreamManager<ODataEntity> streamManager = createReq.execute();
- final Future<ODataMediaEntityCreateResponse<ODataEntity>> futureCreateRes = streamManager.getAsyncResponse();
-
- while (!futureCreateRes.isDone()) {
- Thread.sleep(1000L);
- }
-
- final ODataMediaEntityCreateResponse<ODataEntity> createRes = futureCreateRes.get();
- assertEquals(201, createRes.getStatusCode());
-
- final ODataEntity created = createRes.getBody();
- assertNotNull(created);
- assertEquals(2, created.getProperties().size());
-
- final int id = "VIN".equals(created.getProperties().get(0).getName())
- ? created.getProperties().get(0).getPrimitiveValue().toCastValue(Integer.class)
- : created.getProperties().get(1).getPrimitiveValue().toCastValue(Integer.class);
-
- builder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Car").appendKeySegment(id).appendValueSegment();
-
- final ODataMediaRequest retrieveReq = client.getRetrieveRequestFactory().getMediaRequest(builder.build());
-
- final ODataRetrieveResponse<InputStream> retrieveRes = retrieveReq.execute();
- assertEquals(200, retrieveRes.getStatusCode());
- assertEquals(TO_BE_UPDATED, IOUtils.toString(retrieveRes.getBody()));
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/AuthEntityRetrieveTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/AuthEntityRetrieveTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/AuthEntityRetrieveTestITCase.java
deleted file mode 100644
index 686e5ca..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/AuthEntityRetrieveTestITCase.java
+++ /dev/null
@@ -1,42 +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.client.core.it.v3;
-
-import org.apache.olingo.client.core.http.BasicAuthHttpClientFactory;
-import org.apache.olingo.client.core.http.DefaultHttpClientFactory;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-
-public class AuthEntityRetrieveTestITCase extends EntityRetrieveTestITCase {
-
- @BeforeClass
- public static void enableBasicAuth() {
- client.getConfiguration().setHttpClientFactory(new BasicAuthHttpClientFactory("odatajclient", "odatajclient"));
- }
-
- @AfterClass
- public static void disableBasicAuth() {
- client.getConfiguration().setHttpClientFactory(new DefaultHttpClientFactory());
- }
-
- @Override
- protected String getServiceRoot() {
- return testAuthServiceRootURL;
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/BatchTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/BatchTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/BatchTestITCase.java
deleted file mode 100644
index 0e67a07..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/BatchTestITCase.java
+++ /dev/null
@@ -1,444 +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.client.core.it.v3;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.fail;
-
-import java.io.IOException;
-import java.net.URI;
-import java.util.Iterator;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-import org.apache.http.HttpResponse;
-import org.apache.olingo.client.api.ODataBatchConstants;
-import org.apache.olingo.client.api.communication.request.ODataStreamManager;
-import org.apache.olingo.client.api.communication.request.batch.BatchStreamManager;
-import org.apache.olingo.client.api.communication.request.batch.ODataBatchResponseItem;
-import org.apache.olingo.client.api.communication.request.batch.ODataChangeset;
-import org.apache.olingo.client.api.communication.request.batch.ODataRetrieve;
-import org.apache.olingo.client.api.communication.request.batch.v3.ODataBatchRequest;
-import org.apache.olingo.client.api.communication.request.cud.ODataEntityCreateRequest;
-import org.apache.olingo.client.api.communication.request.cud.ODataEntityUpdateRequest;
-import org.apache.olingo.client.api.communication.request.cud.v3.UpdateType;
-import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
-import org.apache.olingo.client.api.communication.response.ODataBatchResponse;
-import org.apache.olingo.client.api.communication.response.ODataEntityCreateResponse;
-import org.apache.olingo.client.api.communication.response.ODataEntityUpdateResponse;
-import org.apache.olingo.client.api.communication.response.ODataResponse;
-import org.apache.olingo.client.api.uri.v3.URIBuilder;
-import org.apache.olingo.client.core.communication.request.AbstractODataStreamManager;
-import org.apache.olingo.client.core.communication.request.Wrapper;
-import org.apache.olingo.client.core.communication.request.batch.ODataChangesetResponseItem;
-import org.apache.olingo.client.core.communication.request.batch.ODataRetrieveResponseItem;
-import org.apache.olingo.client.core.communication.request.retrieve.ODataEntityRequestImpl;
-import org.apache.olingo.client.core.communication.request.retrieve.ODataEntityRequestImpl.ODataEntityResponseImpl;
-import org.apache.olingo.client.core.uri.URIUtils;
-import org.apache.olingo.commons.api.domain.v3.ODataEntity;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
-import org.apache.olingo.commons.api.format.ODataPubFormat;
-import org.junit.Test;
-
-public class BatchTestITCase extends AbstractTestITCase {
-
- private static final String PREFIX = "!!PREFIX!!";
-
- private static final String SUFFIX = "!!SUFFIX!!";
-
- private static final int MAX = 10000;
-
- @Test
- public void stringStreaming() {
- final TestStreamManager streaming = new TestStreamManager();
-
- new StreamingThread(streaming).start();
-
- streaming.addObject((PREFIX + "\n").getBytes());
-
- for (int i = 0; i <= MAX; i++) {
- streaming.addObject((i + ") send info\n").getBytes());
- }
-
- streaming.addObject(SUFFIX.getBytes());
- streaming.finalizeBody();
- }
-
- @Test
- public void emptyBatchRequest() {
- // create your request
- final ODataBatchRequest request = client.getBatchRequestFactory().getBatchRequest(testStaticServiceRootURL);
-
- final BatchStreamManager payload = request.execute();
- final ODataBatchResponse response = payload.getResponse();
-
- assertEquals(202, response.getStatusCode());
- assertEquals("Accepted", response.getStatusMessage());
-
- final Iterator<ODataBatchResponseItem> iter = response.getBody();
- assertFalse(iter.hasNext());
- }
-
- @Test
- public void changesetWithError() {
- // create your request
- final ODataBatchRequest request = client.getBatchRequestFactory().getBatchRequest(testStaticServiceRootURL);
-
- final BatchStreamManager payload = request.execute();
- final ODataChangeset changeset = payload.addChangeset();
-
- URIBuilder targetURI;
- ODataEntityCreateRequest<ODataEntity> createReq;
-
- targetURI = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Customer");
- for (int i = 1; i <= 2; i++) {
- // Create Customer into the changeset
- createReq = client.getCUDRequestFactory().getEntityCreateRequest(
- targetURI.build(),
- getSampleCustomerProfile(100 + i, "Sample customer", false));
- createReq.setFormat(ODataPubFormat.JSON);
- changeset.addRequest(createReq);
- }
-
- targetURI = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("WrongEntitySet");
- createReq = client.getCUDRequestFactory().getEntityCreateRequest(
- targetURI.build(),
- getSampleCustomerProfile(105, "Sample customer", false));
- createReq.setFormat(ODataPubFormat.JSON);
- changeset.addRequest(createReq);
-
- targetURI = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Customer");
- for (int i = 3; i <= 4; i++) {
- // Create Customer into the changeset
- createReq = client.getCUDRequestFactory().getEntityCreateRequest(
- targetURI.build(),
- getSampleCustomerProfile(100 + i, "Sample customer", false));
- createReq.setFormat(ODataPubFormat.ATOM);
- changeset.addRequest(createReq);
- }
-
- final ODataBatchResponse response = payload.getResponse();
- assertEquals(202, response.getStatusCode());
- assertEquals("Accepted", response.getStatusMessage());
-
- final Iterator<ODataBatchResponseItem> iter = response.getBody();
- final ODataChangesetResponseItem chgResponseItem = (ODataChangesetResponseItem) iter.next();
-
- final ODataResponse res = chgResponseItem.next();
- assertEquals(404, res.getStatusCode());
- assertEquals("Not Found", res.getStatusMessage());
- assertEquals(Integer.valueOf(3), Integer.valueOf(
- res.getHeader(ODataBatchConstants.CHANGESET_CONTENT_ID_NAME).iterator().next()));
- assertFalse(chgResponseItem.hasNext());
- }
-
- @Test
- @SuppressWarnings("unchecked")
- public void changesetWithReference() throws EdmPrimitiveTypeException {
- // create your request
- final ODataBatchRequest request = client.getBatchRequestFactory().getBatchRequest(testStaticServiceRootURL);
- final BatchStreamManager streamManager = request.execute();
-
- final ODataChangeset changeset = streamManager.addChangeset();
- ODataEntity customer = getSampleCustomerProfile(20, "sample customer", false);
-
- URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Customer");
-
- // add create request
- final ODataEntityCreateRequest<ODataEntity> createReq =
- client.getCUDRequestFactory().getEntityCreateRequest(uriBuilder.build(), customer);
-
- changeset.addRequest(createReq);
-
- // retrieve request reference
- int createRequestRef = changeset.getLastContentId();
-
- // add update request: link CustomerInfo(17) to the new customer
- final ODataEntity customerChanges = client.getObjectFactory().newEntity(customer.getTypeName());
- customerChanges.addLink(client.getObjectFactory().newEntityNavigationLink(
- "Info",
- client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("CustomerInfo").
- appendKeySegment(17).build()));
-
- final ODataEntityUpdateRequest<ODataEntity> updateReq = client.getCUDRequestFactory().getEntityUpdateRequest(
- URI.create("$" + createRequestRef), UpdateType.PATCH, customerChanges);
-
- changeset.addRequest(updateReq);
-
- final ODataBatchResponse response = streamManager.getResponse();
- assertEquals(202, response.getStatusCode());
- assertEquals("Accepted", response.getStatusMessage());
-
- // verify response payload ...
- final Iterator<ODataBatchResponseItem> iter = response.getBody();
-
- final ODataBatchResponseItem item = iter.next();
- assertTrue(item instanceof ODataChangesetResponseItem);
-
- final ODataChangesetResponseItem chgitem = (ODataChangesetResponseItem) item;
-
- ODataResponse res = chgitem.next();
- assertEquals(201, res.getStatusCode());
- assertTrue(res instanceof ODataEntityCreateResponse);
-
- customer = ((ODataEntityCreateResponse<ODataEntity>) res).getBody();
-
- ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(
- URIUtils.getURI(testStaticServiceRootURL, customer.getEditLink().toASCIIString() + "/Info"));
-
- assertEquals(Integer.valueOf(17),
- req.execute().getBody().getProperty("CustomerInfoId").getPrimitiveValue().toCastValue(Integer.class));
-
- res = chgitem.next();
- assertEquals(204, res.getStatusCode());
- assertTrue(res instanceof ODataEntityUpdateResponse);
-
- // clean ...
- assertEquals(204, client.getCUDRequestFactory().getDeleteRequest(
- URIUtils.getURI(testStaticServiceRootURL, customer.getEditLink().toASCIIString())).execute().
- getStatusCode());
-
- try {
- client.getRetrieveRequestFactory().getEntityRequest(
- URIUtils.getURI(testStaticServiceRootURL, customer.getEditLink().toASCIIString())).
- execute().getBody();
- fail();
- } catch (Exception e) {
- // ignore
- }
- }
-
- @Test
- @SuppressWarnings("unchecked")
- public void batchRequest() throws EdmPrimitiveTypeException {
- // create your request
- final ODataBatchRequest request = client.getBatchRequestFactory().getBatchRequest(testStaticServiceRootURL);
-
- final BatchStreamManager streamManager = request.execute();
-
- // -------------------------------------------
- // Add retrieve item
- // -------------------------------------------
- ODataRetrieve retrieve = streamManager.addRetrieve();
-
- // prepare URI
- URIBuilder targetURI = client.getURIBuilder(testStaticServiceRootURL);
- targetURI.appendEntitySetSegment("Customer").appendKeySegment(-10).
- expand("Logins").select("CustomerId,Logins/Username");
-
- // create new request
- ODataEntityRequest<ODataEntity> queryReq = client.getRetrieveRequestFactory().getEntityRequest(targetURI.build());
- queryReq.setFormat(ODataPubFormat.ATOM);
-
- retrieve.setRequest(queryReq);
- // -------------------------------------------
-
- // -------------------------------------------
- // Add changeset item
- // -------------------------------------------
- final ODataChangeset changeset = streamManager.addChangeset();
-
- // Update Product into the changeset
- targetURI = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Product").appendKeySegment(-10);
- final URI editLink = targetURI.build();
-
- final ODataEntity merge = client.getObjectFactory().newEntity(TEST_PRODUCT_TYPE);
- merge.setEditLink(editLink);
-
- merge.getProperties().add(client.getObjectFactory().newPrimitiveProperty(
- "Description",
- client.getObjectFactory().newPrimitiveValueBuilder().buildString("new description from batch")));
-
- final ODataEntityUpdateRequest changeReq =
- client.getCUDRequestFactory().getEntityUpdateRequest(UpdateType.MERGE, merge);
- changeReq.setFormat(ODataPubFormat.JSON_FULL_METADATA);
- changeReq.setIfMatch(getETag(editLink));
-
- changeset.addRequest(changeReq);
-
- // Create Customer into the changeset
- targetURI = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Customer");
- final ODataEntity original = getSampleCustomerProfile(1000, "Sample customer", false);
- final ODataEntityCreateRequest<ODataEntity> createReq =
- client.getCUDRequestFactory().getEntityCreateRequest(targetURI.build(), original);
- createReq.setFormat(ODataPubFormat.ATOM);
- changeset.addRequest(createReq);
- // -------------------------------------------
-
- // -------------------------------------------
- // Add retrieve item
- // -------------------------------------------
- retrieve = streamManager.addRetrieve();
-
- // prepare URI
- targetURI = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Product").appendKeySegment(-10);
-
- // create new request
- queryReq = client.getRetrieveRequestFactory().getEntityRequest(targetURI.build());
-
- retrieve.setRequest(queryReq);
- // -------------------------------------------
-
- final ODataBatchResponse response = streamManager.getResponse();
- assertEquals(202, response.getStatusCode());
- assertEquals("Accepted", response.getStatusMessage());
- final Iterator<ODataBatchResponseItem> iter = response.getBody();
-
- // retrive the first item (ODataRetrieve)
- ODataBatchResponseItem item = iter.next();
- assertTrue(item instanceof ODataRetrieveResponseItem);
-
- ODataRetrieveResponseItem retitem = (ODataRetrieveResponseItem) item;
- ODataResponse res = retitem.next();
- assertTrue(res instanceof ODataEntityResponseImpl);
- assertEquals(200, res.getStatusCode());
- assertEquals("OK", res.getStatusMessage());
-
- ODataEntityRequestImpl<ODataEntity>.ODataEntityResponseImpl entres =
- (ODataEntityRequestImpl.ODataEntityResponseImpl) res;
-
- ODataEntity entity = entres.getBody();
- assertEquals(-10, entity.getProperty("CustomerId").getPrimitiveValue().toCastValue(Integer.class), 0);
-
- // retrieve the second item (ODataChangeset)
- item = iter.next();
- assertTrue(item instanceof ODataChangesetResponseItem);
-
- final ODataChangesetResponseItem chgitem = (ODataChangesetResponseItem) item;
- res = chgitem.next();
- assertTrue(res instanceof ODataEntityUpdateResponse);
- assertEquals(204, res.getStatusCode());
- assertEquals("No Content", res.getStatusMessage());
-
- res = chgitem.next();
- assertTrue(res instanceof ODataEntityCreateResponse);
- assertEquals(201, res.getStatusCode());
- assertEquals("Created", res.getStatusMessage());
-
- final ODataEntityCreateResponse<ODataEntity> createres = (ODataEntityCreateResponse<ODataEntity>) res;
- entity = createres.getBody();
- assertEquals(new Integer(1000), entity.getProperty("CustomerId").getPrimitiveValue().toCastValue(Integer.class));
-
- // retrive the third item (ODataRetrieve)
- item = iter.next();
- assertTrue(item instanceof ODataRetrieveResponseItem);
-
- retitem = (ODataRetrieveResponseItem) item;
- res = retitem.next();
- assertTrue(res instanceof ODataEntityResponseImpl);
- assertEquals(200, res.getStatusCode());
- assertEquals("OK", res.getStatusMessage());
-
- entres = (ODataEntityRequestImpl.ODataEntityResponseImpl) res;
- entity = entres.getBody();
- assertEquals("new description from batch",
- entity.getProperty("Description").getPrimitiveValue().toCastValue(String.class));
-
- assertFalse(iter.hasNext());
- }
-
- private static class TestStreamManager extends AbstractODataStreamManager<ODataBatchResponse> {
-
- public TestStreamManager() {
- super(new Wrapper<Future<HttpResponse>>());
- }
-
- public ODataStreamManager<ODataBatchResponse> addObject(byte[] src) {
- stream(src);
- return this;
- }
-
- @Override
- protected ODataBatchResponse getResponse(long timeout, TimeUnit unit) {
- throw new UnsupportedOperationException("Not supported yet.");
- }
- };
-
- /**
- * To be used for debug purposes.
- */
- private static class StreamingThread extends Thread {
-
- private final TestStreamManager streaming;
-
- public StreamingThread(final TestStreamManager streaming) {
- this.streaming = streaming;
- }
-
- @Override
- public void run() {
- try {
- final StringBuilder builder = new StringBuilder();
-
- byte[] buff = new byte[1024];
-
- int len;
-
- while ((len = streaming.getBody().read(buff)) >= 0) {
- builder.append(new String(buff, 0, len));
- }
-
- assertTrue(builder.toString().startsWith(PREFIX));
- assertTrue(builder.toString().contains((MAX / 2) + ") send info"));
- assertTrue(builder.toString().contains((MAX / 3) + ") send info"));
- assertTrue(builder.toString().contains((MAX / 20) + ") send info"));
- assertTrue(builder.toString().contains((MAX / 30) + ") send info"));
- assertTrue(builder.toString().contains(MAX + ") send info"));
- assertTrue(builder.toString().endsWith(SUFFIX));
-
- } catch (IOException e) {
- fail();
- }
- }
- }
-
- private static class BatchStreamingThread extends Thread {
-
- private final BatchStreamManager streaming;
-
- public BatchStreamingThread(final BatchStreamManager streaming) {
- this.streaming = streaming;
- }
-
- @Override
- public void run() {
- try {
- final StringBuilder builder = new StringBuilder();
-
- byte[] buff = new byte[1024];
-
- int len;
-
- while ((len = streaming.getBody().read(buff)) >= 0) {
- builder.append(new String(buff, 0, len));
- }
-
- LOG.debug("Batch request {}", builder.toString());
-
- assertTrue(builder.toString().contains("Content-Id:2"));
- assertTrue(builder.toString().contains("GET " + testStaticServiceRootURL));
- } catch (IOException e) {
- fail();
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/CountTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/CountTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/CountTestITCase.java
deleted file mode 100644
index f004c26..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/CountTestITCase.java
+++ /dev/null
@@ -1,60 +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.client.core.it.v3;
-
-import static org.junit.Assert.*;
-import org.junit.Test;
-
-import org.apache.olingo.client.api.communication.ODataClientErrorException;
-import org.apache.olingo.client.api.communication.request.retrieve.ODataValueRequest;
-import org.apache.olingo.commons.api.domain.ODataValue;
-import org.apache.olingo.commons.api.format.ODataValueFormat;
-import org.apache.olingo.client.api.uri.CommonURIBuilder;
-
-public class CountTestITCase extends AbstractTestITCase {
-
- @Test
- public void entityCount() {
- CommonURIBuilder<?> uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Customer").count();
- final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
- req.setFormat(ODataValueFormat.TEXT);
- try {
- final ODataValue value = req.execute().getBody();
- assertTrue(10 <= Integer.parseInt(value.toString()));
- } catch (ODataClientErrorException e) {
- LOG.error("Error code: {}", e.getStatusLine().getStatusCode(), e);
- }
- }
-
- @Test
- public void invalidAccept() {
- final CommonURIBuilder<?> uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Customer").count();
- final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
- req.setFormat(ODataValueFormat.TEXT);
- req.setAccept("application/json;odata=fullmetadata");
- try {
- final ODataValue value = req.execute().getBody();
- fail();
- } catch (ODataClientErrorException e) {
- assertEquals(415, e.getStatusLine().getStatusCode());
- }
- }
-}