[11/24] olingo-odata2 git commit: [OLINGO-1253]Client Module for Olingo v2
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/9e949e40/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/deserializer/XmlMetadataDeserializerTest.java -- diff --git a/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/deserializer/XmlMetadataDeserializerTest.java b/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/deserializer/XmlMetadataDeserializerTest.java new file mode 100644 index 000..daf7a5c --- /dev/null +++ b/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/deserializer/XmlMetadataDeserializerTest.java @@ -0,0 +1,1904 @@ +/*** + * 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.client.core.ep.deserializer; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.UnsupportedEncodingException; +import java.util.List; + +import javax.xml.stream.XMLStreamException; + +import org.apache.olingo.odata2.api.edm.Edm; +import org.apache.olingo.odata2.api.edm.EdmAction; +import org.apache.olingo.odata2.api.edm.EdmAnnotationAttribute; +import org.apache.olingo.odata2.api.edm.EdmAnnotationElement; +import org.apache.olingo.odata2.api.edm.EdmAnnotations; +import org.apache.olingo.odata2.api.edm.EdmAssociation; +import org.apache.olingo.odata2.api.edm.EdmAssociationSet; +import org.apache.olingo.odata2.api.edm.EdmAssociationSetEnd; +import org.apache.olingo.odata2.api.edm.EdmComplexType; +import org.apache.olingo.odata2.api.edm.EdmConcurrencyMode; +import org.apache.olingo.odata2.api.edm.EdmContentKind; +import org.apache.olingo.odata2.api.edm.EdmEntityContainer; +import org.apache.olingo.odata2.api.edm.EdmEntitySet; +import org.apache.olingo.odata2.api.edm.EdmEntityType; +import org.apache.olingo.odata2.api.edm.EdmException; +import org.apache.olingo.odata2.api.edm.EdmFacets; +import org.apache.olingo.odata2.api.edm.EdmMultiplicity; +import org.apache.olingo.odata2.api.edm.EdmNavigationProperty; +import org.apache.olingo.odata2.api.edm.EdmProperty; +import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind; +import org.apache.olingo.odata2.api.edm.provider.EdmProvider; +import org.apache.olingo.odata2.api.ep.EntityProvider; +import org.apache.olingo.odata2.api.ep.EntityProviderException; +import org.apache.olingo.odata2.api.processor.ODataResponse; +import org.apache.olingo.odata2.client.api.ODataClient; +import org.apache.olingo.odata2.client.api.edm.ClientEdm; +import org.apache.olingo.odata2.client.api.edm.EdmDataServices; +import org.apache.olingo.odata2.client.api.edm.EdmSchema; +import org.apache.olingo.odata2.client.api.edm.EdmUsing; +import org.apache.olingo.odata2.client.core.edm.EdmMetadataAssociationEnd; +import org.apache.olingo.odata2.testutil.helper.StringHelper; +import org.apache.olingo.odata2.testutil.mock.EdmTestProvider; +import org.junit.Test; + +public class XmlMetadataDeserializerTest extends AbstractXmlDeserializerTest { + + public XmlMetadataDeserializerTest(final StreamWriterImplType type) { +super(type); + } + + private static final String DEFAULT_VALUE = "Photo"; + private static final String FC_TARGET_PATH = "СодеÑжание"; + private static final String FC_NS_URI = "http://localhost;; + private static final String FC_NS_PREFIX = "ÑÑ"; + private static final Boolean FC_KEEP_IN_CONTENT = Boolean.FALSE; + private static final String NAMESPACE = "RefScenario"; + private static final String NAMESPACE2 = "RefScenario2"; + private static final String NAMESPACE3 = "RefScenario3"; + private static final String MIME_TYPE = "image/jpeg"; + private static final String ASSOCIATION = "ManagerEmployees"; + private static final int MAX_LENGTH = 4; + + private final String[]
[19/24] olingo-odata2 git commit: [OLINGO-1253]Client Module for Olingo v2
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/9e949e40/odata2-lib/odata-client-core/src/main/java/org/apache/olingo/odata2/client/core/ep/deserializer/XmlMetadataDeserializer.java -- diff --git a/odata2-lib/odata-client-core/src/main/java/org/apache/olingo/odata2/client/core/ep/deserializer/XmlMetadataDeserializer.java b/odata2-lib/odata-client-core/src/main/java/org/apache/olingo/odata2/client/core/ep/deserializer/XmlMetadataDeserializer.java new file mode 100644 index 000..73d62c1 --- /dev/null +++ b/odata2-lib/odata-client-core/src/main/java/org/apache/olingo/odata2/client/core/ep/deserializer/XmlMetadataDeserializer.java @@ -0,0 +1,1570 @@ +/*** + * 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.client.core.ep.deserializer; + +import java.io.InputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.olingo.odata2.api.edm.Edm; +import org.apache.olingo.odata2.api.edm.EdmAction; +import org.apache.olingo.odata2.api.edm.EdmAnnotationAttribute; +import org.apache.olingo.odata2.api.edm.EdmAnnotationElement; +import org.apache.olingo.odata2.api.edm.EdmAnnotations; +import org.apache.olingo.odata2.api.edm.EdmAssociation; +import org.apache.olingo.odata2.api.edm.EdmAssociationEnd; +import org.apache.olingo.odata2.api.edm.EdmAssociationSet; +import org.apache.olingo.odata2.api.edm.EdmAssociationSetEnd; +import org.apache.olingo.odata2.api.edm.EdmComplexType; +import org.apache.olingo.odata2.api.edm.EdmConcurrencyMode; +import org.apache.olingo.odata2.api.edm.EdmContentKind; +import org.apache.olingo.odata2.api.edm.EdmCustomizableFeedMappings; +import org.apache.olingo.odata2.api.edm.EdmEntityContainer; +import org.apache.olingo.odata2.api.edm.EdmEntitySet; +import org.apache.olingo.odata2.api.edm.EdmEntityType; +import org.apache.olingo.odata2.api.edm.EdmException; +import org.apache.olingo.odata2.api.edm.EdmFacets; +import org.apache.olingo.odata2.api.edm.EdmFunctionImport; +import org.apache.olingo.odata2.api.edm.EdmMultiplicity; +import org.apache.olingo.odata2.api.edm.EdmNavigationProperty; +import org.apache.olingo.odata2.api.edm.EdmParameter; +import org.apache.olingo.odata2.api.edm.EdmProperty; +import org.apache.olingo.odata2.api.edm.EdmReferentialConstraint; +import org.apache.olingo.odata2.api.edm.EdmReferentialConstraintRole; +import org.apache.olingo.odata2.api.edm.EdmSimpleType; +import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind; +import org.apache.olingo.odata2.api.edm.EdmTypeKind; +import org.apache.olingo.odata2.api.edm.FullQualifiedName; +import org.apache.olingo.odata2.api.edm.provider.Facets; +import org.apache.olingo.odata2.api.ep.EntityProviderException; +import org.apache.olingo.odata2.client.api.edm.EdmDataServices; +import org.apache.olingo.odata2.client.api.edm.EdmSchema; +import org.apache.olingo.odata2.client.api.edm.EdmUsing; +import org.apache.olingo.odata2.client.core.edm.EdmMetadataAssociationEnd; +import org.apache.olingo.odata2.client.core.edm.Impl.EdmAnnotationAttributeImpl; +import org.apache.olingo.odata2.client.core.edm.Impl.EdmAnnotationElementImpl; +import org.apache.olingo.odata2.client.core.edm.Impl.EdmAnnotationsImpl; +import org.apache.olingo.odata2.client.core.edm.Impl.EdmAssociationEndImpl; +import org.apache.olingo.odata2.client.core.edm.Impl.EdmAssociationImpl; +import org.apache.olingo.odata2.client.core.edm.Impl.EdmAssociationSetEndImpl; +import org.apache.olingo.odata2.client.core.edm.Impl.EdmAssociationSetImpl; +import org.apache.olingo.odata2.client.core.edm.Impl.EdmComplexPropertyImpl; +import org.apache.olingo.odata2.client.core.edm.Impl.EdmComplexTypeImpl; +import
[16/24] olingo-odata2 git commit: [OLINGO-1253]Client Module for Olingo v2
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/9e949e40/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/ProducerConsumerIntegrationTest.java -- diff --git a/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/ProducerConsumerIntegrationTest.java b/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/ProducerConsumerIntegrationTest.java new file mode 100644 index 000..9615caa --- /dev/null +++ b/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/ProducerConsumerIntegrationTest.java @@ -0,0 +1,811 @@ +/*** + * 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.client.core.ep; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.apache.olingo.odata2.api.batch.BatchException; +import org.apache.olingo.odata2.api.batch.BatchResponsePart; +import org.apache.olingo.odata2.api.client.batch.BatchChangeSet; +import org.apache.olingo.odata2.api.client.batch.BatchChangeSetPart; +import org.apache.olingo.odata2.api.client.batch.BatchPart; +import org.apache.olingo.odata2.api.client.batch.BatchSingleResponse; +import org.apache.olingo.odata2.api.commons.HttpStatusCodes; +import org.apache.olingo.odata2.api.edm.EdmEntitySet; +import org.apache.olingo.odata2.api.edm.EdmFunctionImport; +import org.apache.olingo.odata2.api.ep.EntityProviderException; +import org.apache.olingo.odata2.api.ep.entry.ODataEntry; +import org.apache.olingo.odata2.api.ep.feed.ODataDeltaFeed; +import org.apache.olingo.odata2.api.ep.feed.ODataFeed; +import org.apache.olingo.odata2.api.exception.ODataException; +import org.apache.olingo.odata2.api.processor.ODataResponse; +import org.apache.olingo.odata2.client.api.ODataClient; +import org.apache.olingo.odata2.client.api.ep.DeserializerProperties; +import org.apache.olingo.odata2.client.api.ep.Entity; +import org.apache.olingo.odata2.client.api.ep.EntityCollection; +import org.apache.olingo.odata2.client.api.ep.EntityCollectionSerializerProperties; +import org.apache.olingo.odata2.client.api.ep.EntitySerializerProperties; +import org.apache.olingo.odata2.client.api.ep.EntityStream; +import org.apache.olingo.odata2.core.batch.v2.BatchLineReader; +import org.apache.olingo.odata2.core.batch.v2.BatchParser; +import org.apache.olingo.odata2.core.batch.v2.Line; +import org.apache.olingo.odata2.testutil.mock.MockFacade; +import org.junit.Test; + +public class ProducerConsumerIntegrationTest { + protected static final URI BASE_URI; + private static final String PUT = "PUT"; + private static final String BOUNDARY = "batch_123"; + private static final Object CRLF = "\r\n"; + + static { +try { + BASE_URI = new URI("http://host:80/service/;); +} catch (URISyntaxException e) { + throw new RuntimeException(e); +} + } + private static final DeserializerProperties DEFAULT_READ_PROPERTIES + = DeserializerProperties.init() + .build(); + private static final EntitySerializerProperties DEFAULT_WRITE_PROPERTIES + = EntitySerializerProperties + .serviceRoot( + BASE_URI).build(); + private static final String XML = "application/xml"; + private static final String JSON = "application/json"; + + @Test + public void produceRoomAndThenConsumeIt() throws Exception { +EdmEntitySet roomSet = MockFacade.getMockEdm() +.getDefaultEntityContainer().getEntitySet("Rooms"); +Entity localRoomData = new Entity(); +localRoomData.addProperty("Id", "1"); +localRoomData.addProperty("Name", "Neu \n Schwansteinè´è¶"); + +Map
[17/24] olingo-odata2 git commit: [OLINGO-1253]Client Module for Olingo v2
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/9e949e40/odata2-lib/odata-client-core/src/main/java/org/apache/olingo/odata2/client/core/uri/EdmURIBuilderImpl.java -- diff --git a/odata2-lib/odata-client-core/src/main/java/org/apache/olingo/odata2/client/core/uri/EdmURIBuilderImpl.java b/odata2-lib/odata-client-core/src/main/java/org/apache/olingo/odata2/client/core/uri/EdmURIBuilderImpl.java new file mode 100644 index 000..567d3bc --- /dev/null +++ b/odata2-lib/odata-client-core/src/main/java/org/apache/olingo/odata2/client/core/uri/EdmURIBuilderImpl.java @@ -0,0 +1,491 @@ +package org.apache.olingo.odata2.client.core.uri; + +import java.net.URI; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import org.apache.olingo.odata2.api.edm.EdmEntitySet; +import org.apache.olingo.odata2.api.edm.EdmException; +import org.apache.olingo.odata2.api.edm.EdmFunctionImport; +import org.apache.olingo.odata2.api.edm.EdmLiteralKind; +import org.apache.olingo.odata2.api.edm.EdmMultiplicity; +import org.apache.olingo.odata2.api.edm.EdmNavigationProperty; +import org.apache.olingo.odata2.api.edm.EdmParameter; +import org.apache.olingo.odata2.api.edm.EdmProperty; +import org.apache.olingo.odata2.api.edm.EdmSimpleType; +import org.apache.olingo.odata2.api.edm.EdmSimpleTypeException; +import org.apache.olingo.odata2.api.edm.EdmTypeKind; +import org.apache.olingo.odata2.client.api.uri.EdmURIBuilder; +import org.apache.olingo.odata2.client.api.uri.QueryOption; +import org.apache.olingo.odata2.client.api.uri.SegmentType; +import org.apache.olingo.odata2.client.core.uri.util.UriUtil; +import org.apache.olingo.odata2.core.commons.Encoder; + +/** + * This is a builder class that constructs URI with edm validations + * + */ +public class EdmURIBuilderImpl implements EdmURIBuilder{ + protected final List segments = new ArrayList(); + private SegmentType state = SegmentType.INITIAL; + + /** + * Insertion-order map of query options. + */ + protected final MapqueryOptions = new LinkedHashMap (); + + /** + * Insertion-order map of custom query options. + */ + protected final Map customQueryOptions = new LinkedHashMap (); + + /** + * Insertion-order map of function import parameters. + */ + protected final Map functionImportParameters = new LinkedHashMap (); + + /** + * Constructor. + * + * @param serviceRoot absolute URL (schema, host and port included) representing the location of the root of the data + * service. + */ + public EdmURIBuilderImpl(final String serviceRoot) { +state = SegmentType.INITIAL; +segments.add(new Segment(SegmentType.INITIAL, serviceRoot)); + } + + @Override + public EdmURIBuilder appendCountSegment() { +switch (state) { +case INITIAL: +case SIMPLEPROPERTY: +case COMPLEXPROPERTY: +case NAVIGATION_TO_ONE: +case NAVIGATION_TO_MANY_WITH_KEY: +case FUNCTIONIMPORT_WITH_KEY: +case ENTITY: +throw new RuntimeException("Can't specify a key at this position");//NOSONAR +case ENTITYSET: +appendCount(); +break; +case NAVIGATION_TO_MANY: +appendCount(); +break; +case FUNCTIONIMPORT_MANY: + appendCount(); + break; +default: +throw new RuntimeException("Unkown state:" + state);//NOSONAR +} +return this; + } + + private void appendCount() { +segments.add(new Segment(SegmentType.COUNT, SegmentType.COUNT.getValue())); +state = SegmentType.COUNT; + } + + @Override + public EdmURIBuilder appendValueSegment() { +switch (state) { +case INITIAL: +case COMPLEXPROPERTY: +case ENTITYSET: +case NAVIGATION_TO_MANY: +case ENTITY: +case NAVIGATION_TO_MANY_WITH_KEY: +case NAVIGATION_TO_ONE: +throw new RuntimeException("Can't specify a navigation at this position");//NOSONAR +case SIMPLEPROPERTY: + addValueSegment(); + break; +default: +throw new RuntimeException("Unkown state:" + state);//NOSONAR +} +return this; + } + + private void addValueSegment() { +segments.add(new Segment(SegmentType.VALUE, SegmentType.VALUE.getValue())); + } + + @Override + public EdmURIBuilder appendMetadataSegment() { +segments.add(new Segment(SegmentType.METADATA, SegmentType.METADATA.getValue())); +return this; + } + + @Override + public EdmURIBuilder format(String format) { //NOSONAR +switch (state) { +case INITIAL: +case COUNT: +case VALUE: + throw new RuntimeException("Can't specify a format at this position");//NOSONAR +case NAVIGATION_TO_ONE: +case SIMPLEPROPERTY: +case COMPLEXPROPERTY: +case ENTITYSET: +case NAVIGATION_TO_MANY: +case ENTITY: +case NAVIGATION_TO_MANY_WITH_KEY: +
[12/24] olingo-odata2 git commit: [OLINGO-1253]Client Module for Olingo v2
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/9e949e40/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/deserializer/XmlErrorDocumentTest.java -- diff --git a/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/deserializer/XmlErrorDocumentTest.java b/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/deserializer/XmlErrorDocumentTest.java new file mode 100644 index 000..2a255f1 --- /dev/null +++ b/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/deserializer/XmlErrorDocumentTest.java @@ -0,0 +1,281 @@ +/*** + * 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.client.core.ep.deserializer; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.InputStream; +import java.util.Locale; + +import org.apache.olingo.odata2.api.ep.EntityProviderException; +import org.apache.olingo.odata2.api.processor.ODataErrorContext; +import org.apache.olingo.odata2.client.core.ep.deserializer.XmlErrorDocumentDeserializer; +import org.apache.olingo.odata2.testutil.helper.StringHelper; +import org.junit.Test; + +/** + * + */ +public class XmlErrorDocumentTest extends AbstractDeserializerTest { + + private static final String XML_ERROR_DOCUMENT_SIMPLE = + "\n" + + "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\;>\n" + + "\tErrorCode\n" + + "\tMessage\n" + + ""; + private static final String XML_ERROR_DOCUMENT_NULL_LOCALE = + "\n" + + "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\;>\n" + + "\tErrorCode\n" + + "\tMessage\n" + + ""; + private static final String XML_ERROR_DOCUMENT_INNER_ERROR = + "\n" + + "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\;>\n" + + "\tErrorCode\n" + + "\tMessage\n" + + "Some InnerError\n" + + ""; + private static final String XML_ERROR_DOCUMENT_INNER_ERROR_COMPLEX = + "\n" + + "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\;>\n" + + "\tErrorCode\n" + + "\tMessage\n" + + "" + + "More Inner Error" + + "\n" + + ""; + private static final String XML_ERROR_DOCUMENT_INVALID_XML = + "\n" + + "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\;>\n" + + "\tErrorCode\n" + + "\tMessage\n" + + ""; + /* error document with name 'locale' instead of 'lang' for message object */ + private static final String XML_ERROR_DOCUMENT_UNKNOWN_CONTENT = + "\n" + + "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\;>\n" + + "\tErrorCode\n" + + "\tMessage\n" + + "\tSecret\n" + + ""; + /* error document without value for message object */ + private static final String XML_ERROR_DOCUMENT_EMPTY_MESSAGE = + "\n" + + "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\;>\n" + + "\tErrorCode\n" + + "\t\n" + + ""; + private static final String XML_ERROR_DOCUMENT_MISSING_MESSAGE = + "\n" + + "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\;>\n" + + "\tErrorCode\n" + + ""; + private static final String XML_ERROR_DOCUMENT_MISSING_CODE = + "\n" + + "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\;>\n" + + "\tMessage\n" + + ""; + private static final String XML_ERROR_DOCUMENT_MISSING_ERROR = + "\n" + + "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\;>\n" + + "\tErrorCode\n" + + "\tMessage\n" + + ""; + private XmlErrorDocumentDeserializer xedc = new
[24/24] olingo-odata2 git commit: [OLINGO-1253]Client Module for Olingo v2
[OLINGO-1253]Client Module for Olingo v2 Project: http://git-wip-us.apache.org/repos/asf/olingo-odata2/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata2/commit/9e949e40 Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata2/tree/9e949e40 Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata2/diff/9e949e40 Branch: refs/heads/clientModule Commit: 9e949e40605f1528560e3bc9f1646b6686046005 Parents: 91bd4b8 Author: Archana RaiAuthored: Mon Apr 2 17:01:26 2018 +0530 Committer: Archana Rai Committed: Mon Apr 2 17:01:26 2018 +0530 -- .../olingo/odata2/api/edm/EdmException.java | 5 + .../odata2/api/ep/EntityProviderException.java | 9 +- odata2-lib/odata-client-api/pom.xml |71 + .../olingo/odata2/client/api/ODataClient.java | 119 + .../olingo/odata2/client/api/edm/ClientEdm.java |41 + .../odata2/client/api/edm/EdmDataServices.java |85 + .../odata2/client/api/edm/EdmDocumentation.java |58 + .../olingo/odata2/client/api/edm/EdmSchema.java |81 + .../olingo/odata2/client/api/edm/EdmUsing.java |57 + .../api/ep/ContentTypeBasedDeserializer.java|91 + .../api/ep/ContentTypeBasedSerializer.java |63 + .../DeserializerMetadataProviderInterface.java |30 + .../client/api/ep/DeserializerProperties.java | 170 + .../olingo/odata2/client/api/ep/Entity.java |97 + .../odata2/client/api/ep/EntityCollection.java |79 + .../EntityCollectionSerializerProperties.java | 119 + .../api/ep/EntitySerializerProperties.java | 159 + .../odata2/client/api/ep/EntityStream.java |55 + .../ep/callback/OnDeserializeInlineContent.java |47 + .../odata2/client/api/uri/EdmURIBuilder.java| 184 + .../odata2/client/api/uri/QueryOption.java |70 + .../odata2/client/api/uri/SegmentType.java |76 + .../odata2/client/api/uri/URIBuilder.java | 174 + odata2-lib/odata-client-core/pom.xml|90 + .../odata2/client/core/ODataClientImpl.java | 199 + .../core/edm/EdmMetadataAssociationEnd.java |38 + .../odata2/client/core/edm/EdmOnDelete.java |52 + .../edm/Impl/EdmAnnotationAttributeImpl.java|99 + .../core/edm/Impl/EdmAnnotationElementImpl.java |93 + .../core/edm/Impl/EdmAnnotationsImpl.java |82 + .../core/edm/Impl/EdmAssociationEndImpl.java| 106 + .../core/edm/Impl/EdmAssociationImpl.java | 149 + .../core/edm/Impl/EdmAssociationSetEndImpl.java |92 + .../core/edm/Impl/EdmAssociationSetImpl.java| 137 + .../core/edm/Impl/EdmComplexPropertyImpl.java |56 + .../core/edm/Impl/EdmComplexTypeImpl.java |75 + .../Impl/EdmCustomizableFeedMappingsImpl.java | 140 + .../core/edm/Impl/EdmDocumentationImpl.java | 110 + .../client/core/edm/Impl/EdmElementImpl.java|55 + .../core/edm/Impl/EdmEntityContainerImpl.java | 222 + .../client/core/edm/Impl/EdmEntitySetImpl.java | 136 + .../client/core/edm/Impl/EdmEntityTypeImpl.java | 133 + .../core/edm/Impl/EdmFunctionImportImpl.java| 179 + .../edm/Impl/EdmFunctionImportParameter.java| 140 + .../odata2/client/core/edm/Impl/EdmImpl.java| 207 + .../odata2/client/core/edm/Impl/EdmKeyImpl.java | 101 + .../client/core/edm/Impl/EdmMappingImpl.java|99 + .../client/core/edm/Impl/EdmNamedImpl.java |82 + .../edm/Impl/EdmNavigationPropertyImpl.java | 119 + .../client/core/edm/Impl/EdmOnDeleteImpl.java | 112 + .../client/core/edm/Impl/EdmParameterImpl.java |71 + .../client/core/edm/Impl/EdmPropertyImpl.java |91 + .../core/edm/Impl/EdmPropertyRefImpl.java |47 + .../edm/Impl/EdmReferentialConstraintImpl.java |72 + .../Impl/EdmReferentialConstraintRoleImpl.java |98 + .../client/core/edm/Impl/EdmSchemaImpl.java | 205 + .../core/edm/Impl/EdmSimplePropertyImpl.java|62 + .../core/edm/Impl/EdmStructuralTypeImpl.java| 154 + .../client/core/edm/Impl/EdmTypedImpl.java |84 + .../client/core/edm/Impl/EdmUsingImpl.java | 129 + .../core/ep/AtomSerializerDeserializer.java | 211 + .../core/ep/JsonSerializerDeserializer.java | 169 + .../ep/deserializer/JsonEntityDeserializer.java | 218 + .../ep/deserializer/JsonEntryDeserializer.java | 451 + .../JsonErrorDocumentDeserializer.java | 278 + .../ep/deserializer/JsonFeedDeserializer.java | 255 + .../deserializer/JsonPropertyDeserializer.java | 326 + .../ep/deserializer/XmlEntityDeserializer.java | 190 + .../ep/deserializer/XmlEntryDeserializer.java | 596 + .../XmlErrorDocumentDeserializer.java | 184 + .../ep/deserializer/XmlFeedDeserializer.java| 226 + .../deserializer/XmlMetadataDeserializer.java | 1570 +++ .../deserializer/XmlPropertyDeserializer.java | 199 +
[18/24] olingo-odata2 git commit: [OLINGO-1253]Client Module for Olingo v2
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/9e949e40/odata2-lib/odata-client-core/src/main/java/org/apache/olingo/odata2/client/core/ep/deserializer/XmlPropertyDeserializer.java -- diff --git a/odata2-lib/odata-client-core/src/main/java/org/apache/olingo/odata2/client/core/ep/deserializer/XmlPropertyDeserializer.java b/odata2-lib/odata-client-core/src/main/java/org/apache/olingo/odata2/client/core/ep/deserializer/XmlPropertyDeserializer.java new file mode 100644 index 000..53370bc --- /dev/null +++ b/odata2-lib/odata-client-core/src/main/java/org/apache/olingo/odata2/client/core/ep/deserializer/XmlPropertyDeserializer.java @@ -0,0 +1,199 @@ +/*** + * 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.client.core.ep.deserializer; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.olingo.odata2.api.edm.Edm; +import org.apache.olingo.odata2.api.edm.EdmException; +import org.apache.olingo.odata2.api.edm.EdmLiteralKind; +import org.apache.olingo.odata2.api.edm.EdmProperty; +import org.apache.olingo.odata2.api.edm.EdmSimpleType; +import org.apache.olingo.odata2.api.edm.EdmSimpleTypeException; +import org.apache.olingo.odata2.api.ep.EntityProviderException; +import org.apache.olingo.odata2.client.api.ep.DeserializerProperties; +import org.apache.olingo.odata2.core.ep.aggregator.EntityComplexPropertyInfo; +import org.apache.olingo.odata2.core.ep.aggregator.EntityInfoAggregator; +import org.apache.olingo.odata2.core.ep.aggregator.EntityPropertyInfo; +import org.apache.olingo.odata2.core.ep.aggregator.EntityTypeMapping; +import org.apache.olingo.odata2.core.ep.util.FormatXml; + +/** + * XML property consumer. + */ +public class XmlPropertyDeserializer { + + protected static final String TRUE = "true"; + protected static final String FALSE = "false"; + + /** + * Read property of every entry in a payload + * @param reader + * @param property + * @param readProperties + * @return Map+ * @throws EntityProviderException + */ + public Map readProperty(final XMLStreamReader reader, final EdmProperty property, + final DeserializerProperties readProperties) throws EntityProviderException { +return readProperty(reader, EntityInfoAggregator.create(property), readProperties); + } + + /** + * Read property of every entry in a payload + * @param reader + * @param propertyInfo + * @param readProperties + * @return Map + * @throws EntityProviderException + */ + public Map readProperty(final XMLStreamReader reader, final EntityPropertyInfo propertyInfo, + final DeserializerProperties readProperties) throws EntityProviderException { +final EntityTypeMapping typeMappings = +EntityTypeMapping.create(readProperties == null ? Collections. emptyMap() : + readProperties.getTypeMappings()); +try { + reader.next(); + + Object value = readStartedElement(reader, propertyInfo.getName(), propertyInfo, typeMappings, readProperties); + + Map result = new HashMap (); + result.put(propertyInfo.getName(), value); + return result; +} catch (XMLStreamException e) { + throw new EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass() + .getSimpleName()), e); +} catch (EdmException e) { + throw new EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass() + .getSimpleName()), e); +} + } + + + /** + * Deserializes a collection of entities + * @param reader + * @param info + * @param properties + * @return List + * @throws EntityProviderException + */ + public List
[21/24] olingo-odata2 git commit: [OLINGO-1253]Client Module for Olingo v2
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/9e949e40/odata2-lib/odata-client-core/src/main/java/org/apache/olingo/odata2/client/core/ep/JsonSerializerDeserializer.java -- diff --git a/odata2-lib/odata-client-core/src/main/java/org/apache/olingo/odata2/client/core/ep/JsonSerializerDeserializer.java b/odata2-lib/odata-client-core/src/main/java/org/apache/olingo/odata2/client/core/ep/JsonSerializerDeserializer.java new file mode 100644 index 000..aaba634 --- /dev/null +++ b/odata2-lib/odata-client-core/src/main/java/org/apache/olingo/odata2/client/core/ep/JsonSerializerDeserializer.java @@ -0,0 +1,169 @@ +/*** + * 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.client.core.ep; + +import java.io.BufferedWriter; +import java.io.InputStream; +import java.io.OutputStreamWriter; +import java.util.List; + +import org.apache.olingo.odata2.api.batch.BatchException; +import org.apache.olingo.odata2.api.batch.BatchResponsePart; +import org.apache.olingo.odata2.api.client.batch.BatchPart; +import org.apache.olingo.odata2.api.edm.EdmEntitySet; +import org.apache.olingo.odata2.api.edm.EdmException; +import org.apache.olingo.odata2.api.edm.EdmFunctionImport; +import org.apache.olingo.odata2.api.edm.EdmMultiplicity; +import org.apache.olingo.odata2.api.edm.EdmTypeKind; +import org.apache.olingo.odata2.api.ep.EntityProviderException; +import org.apache.olingo.odata2.api.ep.entry.ODataEntry; +import org.apache.olingo.odata2.api.ep.feed.ODataFeed; +import org.apache.olingo.odata2.api.processor.ODataErrorContext; +import org.apache.olingo.odata2.api.processor.ODataResponse; +import org.apache.olingo.odata2.client.api.ep.ContentTypeBasedDeserializer; +import org.apache.olingo.odata2.client.api.ep.ContentTypeBasedSerializer; +import org.apache.olingo.odata2.client.api.ep.Entity; +import org.apache.olingo.odata2.client.api.ep.EntityCollection; +import org.apache.olingo.odata2.client.api.ep.EntityCollectionSerializerProperties; +import org.apache.olingo.odata2.client.api.ep.EntitySerializerProperties; +import org.apache.olingo.odata2.client.api.ep.EntityStream; +import org.apache.olingo.odata2.client.core.ep.deserializer.JsonEntityDeserializer; +import org.apache.olingo.odata2.client.core.ep.serializer.JsonEntryEntitySerializer; +import org.apache.olingo.odata2.client.core.ep.serializer.JsonFeedEntitySerializer; +import org.apache.olingo.odata2.core.batch.BatchRequestWriter; +import org.apache.olingo.odata2.core.batch.BatchResponseWriter; +import org.apache.olingo.odata2.core.ep.EntityProviderProducerException; +import org.apache.olingo.odata2.core.ep.aggregator.EntityInfoAggregator; +import org.apache.olingo.odata2.core.ep.aggregator.EntityPropertyInfo; +import org.apache.olingo.odata2.core.ep.consumer.JsonErrorDocumentConsumer; +import org.apache.olingo.odata2.core.ep.util.CircleStreamBuffer; + +/** + * This class includes methods to serialize deserialize JSON Content type + */ +public class JsonSerializerDeserializer implements ContentTypeBasedSerializer, ContentTypeBasedDeserializer { + + private static final String DEFAULT_CHARSET = "UTF-8"; + + @Override + public ODataResponse writeEntry(EdmEntitySet entitySet, Entity data) + throws EntityProviderException { + +final EntitySerializerProperties properties = data == null ? +EntitySerializerProperties.serviceRoot(null).build() : data.getWriteProperties() == null ? +EntitySerializerProperties.serviceRoot(null).build() : data.getWriteProperties(); +final EntityInfoAggregator entityInfo = EntityInfoAggregator.create(entitySet, null); +CircleStreamBuffer buffer = new CircleStreamBuffer(); + +try { + BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(buffer.getOutputStream(), DEFAULT_CHARSET)); + JsonEntryEntitySerializer producer = new JsonEntryEntitySerializer(properties); + producer.append(writer, entityInfo, data); + writer.flush(); + buffer.closeWrite(); + +
[15/24] olingo-odata2 git commit: [OLINGO-1253]Client Module for Olingo v2
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/9e949e40/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/deserializer/JsonEntryDeserializerTest.java -- diff --git a/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/deserializer/JsonEntryDeserializerTest.java b/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/deserializer/JsonEntryDeserializerTest.java new file mode 100644 index 000..ac8d934 --- /dev/null +++ b/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/deserializer/JsonEntryDeserializerTest.java @@ -0,0 +1,539 @@ +/*** + * 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.client.core.ep.deserializer; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.InputStream; +import java.util.Calendar; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.TimeZone; + +import org.apache.olingo.odata2.api.edm.EdmEntitySet; +import org.apache.olingo.odata2.api.ep.EntityProviderException; +import org.apache.olingo.odata2.api.ep.entry.EntryMetadata; +import org.apache.olingo.odata2.api.ep.entry.MediaMetadata; +import org.apache.olingo.odata2.api.ep.entry.ODataEntry; +import org.apache.olingo.odata2.api.ep.feed.ODataFeed; +import org.apache.olingo.odata2.api.uri.ExpandSelectTreeNode; +import org.apache.olingo.odata2.client.api.ep.DeserializerProperties; +import org.apache.olingo.odata2.client.api.ep.EntityStream; +import org.apache.olingo.odata2.testutil.mock.MockFacade; +import org.junit.Test; + +/** + * + */ +public class JsonEntryDeserializerTest extends AbstractDeserializerTest { + + private static final String SIMPLE_ENTRY_BUILDING = "JsonBuilding.json"; + private static final String SIMPLE_ENTRY_ROOM = "JsonRoom.json"; + private static final String SIMPLE_ENTRY_EMPLOYEE = "JsonEmployee.json"; + private static final String SIMPLE_ENTRY_TEAM = "JsonTeam.json"; + private static final String INVALID_ENTRY_TEAM_DOUBLE_NAME_PROPERTY = "JsonInvalidTeamDoubleNameProperty.json"; + private static final String SIMPLE_ENTRY_BUILDING_WITHOUT_D = "JsonBuildingWithoutD.json"; + + // Negative Test jsonStart + private static final String negativeJsonStart_1 = "{ \"abc\": {"; + private static final String negativeJsonStart_2 = "{ \"d\": [a: 1, b: 2] }"; + + @Test + public void readContentOnlyEmployee() throws Exception { +// prepare +String content = readFile("JsonEmployeeContentOnly.json"); +EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees"); +InputStream contentBody = createContentAsStream(content); +EntityStream contentStream = new EntityStream(); +contentStream.setContent(contentBody); +contentStream.setReadProperties(DeserializerProperties.init().build()); + +// execute +JsonEntityDeserializer xec = new JsonEntityDeserializer(); +ODataEntry result = +xec.readEntry(entitySet, contentStream); + +// verify +assertEquals(9, result.getProperties().size()); + } + + @Test + public void readContentOnlyRoom() throws Exception { +// prepare +String content = readFile("JsonRoomContentOnly.json"); +EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms"); +InputStream contentBody = createContentAsStream(content); +EntityStream entityStream = new EntityStream(); +entityStream.setContent(contentBody); +entityStream.setReadProperties(DeserializerProperties.init().build()); + +// execute +JsonEntityDeserializer xec = new JsonEntityDeserializer(); +ODataEntry result = +xec.readEntry(entitySet, entityStream); + +// verify
[14/24] olingo-odata2 git commit: [OLINGO-1253]Client Module for Olingo v2
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/9e949e40/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/deserializer/JsonPropertyDeserializerTest.java -- diff --git a/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/deserializer/JsonPropertyDeserializerTest.java b/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/deserializer/JsonPropertyDeserializerTest.java new file mode 100644 index 000..3a89af0 --- /dev/null +++ b/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/deserializer/JsonPropertyDeserializerTest.java @@ -0,0 +1,834 @@ +/*** + * 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.client.core.ep.deserializer; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.UnsupportedEncodingException; +import java.math.BigDecimal; +import java.util.Arrays; +import java.util.Calendar; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.apache.olingo.odata2.api.edm.EdmFacets; +import org.apache.olingo.odata2.api.edm.EdmProperty; +import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind; +import org.apache.olingo.odata2.api.ep.EntityProviderException; +import org.apache.olingo.odata2.client.api.ep.DeserializerProperties; +import org.apache.olingo.odata2.core.ep.aggregator.EntityComplexPropertyInfo; +import org.apache.olingo.odata2.core.ep.aggregator.EntityInfoAggregator; +import org.apache.olingo.odata2.core.ep.aggregator.EntityPropertyInfo; +import org.apache.olingo.odata2.testutil.fit.BaseTest; +import org.apache.olingo.odata2.testutil.mock.MockFacade; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import com.google.gson.stream.JsonReader; + +/** + * + */ +public class JsonPropertyDeserializerTest extends BaseTest { + + @Rule + public ExpectedException expectedEx = ExpectedException.none(); + + @Test + public void booleanSimpleProperty() throws Exception { +EdmProperty property = mock(EdmProperty.class); +when(property.getName()).thenReturn("Boolean"); +when(property.isSimple()).thenReturn(true); + when(property.getType()).thenReturn(EdmSimpleTypeKind.Boolean.getEdmSimpleTypeInstance()); + +JsonReader reader = prepareReader("{\"Boolean\":true}"); +final MapresultMap = execute(property, reader); +assertEquals(Boolean.TRUE, resultMap.get("Boolean")); + } + + @Test + public void allNumberSimplePropertyKinds() throws Exception { +String simplePropertyJson = "{\"d\":{\"Age\":67}}"; +EdmProperty edmProperty = mock(EdmProperty.class); +when(edmProperty.getName()).thenReturn("Age"); +when(edmProperty.isSimple()).thenReturn(true); + +// Byte +JsonReader reader = prepareReader(simplePropertyJson); + when(edmProperty.getType()).thenReturn(EdmSimpleTypeKind.Byte.getEdmSimpleTypeInstance()); +Map resultMap = execute(edmProperty, reader); +assertEquals(Short.valueOf("67"), resultMap.get("Age")); + +// SByte +reader = prepareReader(simplePropertyJson); + when(edmProperty.getType()).thenReturn(EdmSimpleTypeKind.SByte.getEdmSimpleTypeInstance()); +resultMap = execute(edmProperty, reader); +assertEquals(Byte.valueOf("67"), resultMap.get("Age")); +// Int16 +reader = prepareReader(simplePropertyJson); + when(edmProperty.getType()).thenReturn(EdmSimpleTypeKind.Int16.getEdmSimpleTypeInstance()); +resultMap = execute(edmProperty, reader); +
[20/24] olingo-odata2 git commit: [OLINGO-1253]Client Module for Olingo v2
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/9e949e40/odata2-lib/odata-client-core/src/main/java/org/apache/olingo/odata2/client/core/ep/deserializer/XmlEntryDeserializer.java -- diff --git a/odata2-lib/odata-client-core/src/main/java/org/apache/olingo/odata2/client/core/ep/deserializer/XmlEntryDeserializer.java b/odata2-lib/odata-client-core/src/main/java/org/apache/olingo/odata2/client/core/ep/deserializer/XmlEntryDeserializer.java new file mode 100644 index 000..06bae41 --- /dev/null +++ b/odata2-lib/odata-client-core/src/main/java/org/apache/olingo/odata2/client/core/ep/deserializer/XmlEntryDeserializer.java @@ -0,0 +1,596 @@ +/*** + * 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.client.core.ep.deserializer; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.xml.namespace.NamespaceContext; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.olingo.odata2.api.edm.Edm; +import org.apache.olingo.odata2.api.edm.EdmEntitySet; +import org.apache.olingo.odata2.api.edm.EdmException; +import org.apache.olingo.odata2.api.edm.EdmLiteralKind; +import org.apache.olingo.odata2.api.edm.EdmMultiplicity; +import org.apache.olingo.odata2.api.edm.EdmNavigationProperty; +import org.apache.olingo.odata2.api.edm.EdmSimpleType; +import org.apache.olingo.odata2.api.ep.EntityProviderException; +import org.apache.olingo.odata2.api.ep.entry.ODataEntry; +import org.apache.olingo.odata2.api.exception.ODataApplicationException; +import org.apache.olingo.odata2.client.api.ep.DeserializerProperties; +import org.apache.olingo.odata2.client.api.ep.callback.OnDeserializeInlineContent; +import org.apache.olingo.odata2.core.commons.ContentType; +import org.apache.olingo.odata2.core.ep.aggregator.EntityInfoAggregator; +import org.apache.olingo.odata2.core.ep.aggregator.EntityPropertyInfo; +import org.apache.olingo.odata2.core.ep.aggregator.EntityTypeMapping; +import org.apache.olingo.odata2.core.ep.entry.EntryMetadataImpl; +import org.apache.olingo.odata2.core.ep.entry.MediaMetadataImpl; +import org.apache.olingo.odata2.core.ep.entry.ODataEntryImpl; +import org.apache.olingo.odata2.core.ep.feed.FeedMetadataImpl; +import org.apache.olingo.odata2.core.ep.feed.ODataDeltaFeedImpl; +import org.apache.olingo.odata2.core.ep.util.FormatXml; + +/** + * Atom/XML format reader/consumer for entries. + * + * {@link XmlEntryDeserializer} instance can be reused for several + * {@link #readEntry(XMLStreamReader, EntityInfoAggregator, EntityProviderReadProperties)} calls + * but be aware that the instance and their readEntry* methods are NOT THREAD SAFE. + * + */ +public class XmlEntryDeserializer { + + private ODataEntryImpl readEntryResult; + private Mapproperties; + private MediaMetadataImpl mediaMetadata; + private EntryMetadataImpl entryMetadata; + private EntityTypeMapping typeMappings; + private String currentHandledStartTagName; + + /** + * Deserializes payload entry + * @param reader + * @param eia + * @param readProperties + * @param isInline + * @return ODataEntry + * @throws EntityProviderException + */ + public ODataEntry readEntry(final XMLStreamReader reader, final EntityInfoAggregator eia, + final DeserializerProperties readProperties, final boolean isInline) throws EntityProviderException { +try { + initialize(readProperties); + + if (isInline) { +setETag(reader); + } + + while (reader.hasNext() && !isEntryEndTag(reader)) { +reader.nextTag(); +if (reader.isStartElement()) { + handleStartedTag(reader, eia, readProperties); +} + } + + return readEntryResult; +} catch (XMLStreamException e) { + throw new EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass() +
[07/24] olingo-odata2 git commit: [OLINGO-1253]Client Module for Olingo v2
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/9e949e40/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/serializer/JsonFeedEntitySerializerTest.java -- diff --git a/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/serializer/JsonFeedEntitySerializerTest.java b/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/serializer/JsonFeedEntitySerializerTest.java new file mode 100644 index 000..23f3310 --- /dev/null +++ b/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/serializer/JsonFeedEntitySerializerTest.java @@ -0,0 +1,919 @@ +/*** + * 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.client.core.ep.serializer; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.HashMap; +import java.util.Map; + +import org.apache.olingo.odata2.api.edm.Edm; +import org.apache.olingo.odata2.api.edm.EdmEntitySet; +import org.apache.olingo.odata2.api.edm.EdmFacets; +import org.apache.olingo.odata2.api.edm.EdmProperty; +import org.apache.olingo.odata2.api.edm.EdmTyped; +import org.apache.olingo.odata2.api.ep.EntityProviderException; +import org.apache.olingo.odata2.api.processor.ODataResponse; +import org.apache.olingo.odata2.client.api.ep.Entity; +import org.apache.olingo.odata2.client.api.ep.EntityCollection; +import org.apache.olingo.odata2.client.api.ep.EntityCollectionSerializerProperties; +import org.apache.olingo.odata2.client.api.ep.EntitySerializerProperties; +import org.apache.olingo.odata2.client.core.ep.JsonSerializerDeserializer; +import org.apache.olingo.odata2.testutil.fit.BaseTest; +import org.apache.olingo.odata2.testutil.helper.StringHelper; +import org.apache.olingo.odata2.testutil.mock.MockFacade; +import org.junit.Test; + +/** + * + */ +public class JsonFeedEntitySerializerTest extends BaseTest { + protected static final String BASE_URI = "http://host:80/service/;; + protected static final EntitySerializerProperties DEFAULT_PROPERTIES = + EntitySerializerProperties.serviceRoot(URI.create(BASE_URI)).build(); + protected static final String ERROR_MSG = "Entity or expanded entity cannot have null value."; + + @Test + public void unbalancedPropertyEntryWithInlineFeed() throws Exception { +Edm edm = MockFacade.getMockEdm(); +EdmTyped imageUrlProperty = edm.getEntityType("RefScenario", "Employee").getProperty("ImageUrl"); +EdmFacets facets = mock(EdmFacets.class); +when(facets.getMaxLength()).thenReturn(1); +when(((EdmProperty) imageUrlProperty).getFacets()).thenReturn(facets); + +Entity roomData = new Entity(); +roomData.addProperty("Id", "1"); +roomData.addProperty("Name", "Neu Schwanstein"); +roomData.addProperty("Seats", new Integer(20)); + + roomData.setWriteProperties(EntitySerializerProperties.serviceRoot(URI.create(BASE_URI)) +.build()); +EntityCollection innerData = new EntityCollection(); +Entity data = new Entity(); +data.addProperty("EmployeeId", "1"); +data.addProperty("EmployeeName", "EmpName1"); +data.addProperty("RoomId", "1"); +data.setWriteProperties(DEFAULT_PROPERTIES); +innerData.addEntity(data); + +data = new Entity(); +data.addProperty("EmployeeId", "1"); +data.addProperty("RoomId", "1"); +data.setWriteProperties(DEFAULT_PROPERTIES); +innerData.addEntity(data); +roomData.addNavigation("nr_Employees", innerData); + +EdmEntitySet entitySet = edm.getDefaultEntityContainer().getEntitySet("Rooms"); +final ODataResponse response = +new JsonSerializerDeserializer().writeEntry(entitySet, roomData); +assertNotNull(response); +
[06/24] olingo-odata2 git commit: [OLINGO-1253]Client Module for Olingo v2
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/9e949e40/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/uri/EdmUriBuilderTest.java -- diff --git a/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/uri/EdmUriBuilderTest.java b/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/uri/EdmUriBuilderTest.java new file mode 100644 index 000..4e4baf6 --- /dev/null +++ b/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/uri/EdmUriBuilderTest.java @@ -0,0 +1,988 @@ +package org.apache.olingo.odata2.client.core.uri; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.net.URI; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; + +import org.apache.olingo.odata2.api.edm.Edm; +import org.apache.olingo.odata2.api.edm.EdmComplexType; +import org.apache.olingo.odata2.api.edm.EdmEntitySet; +import org.apache.olingo.odata2.api.edm.EdmException; +import org.apache.olingo.odata2.api.edm.EdmFunctionImport; +import org.apache.olingo.odata2.api.edm.EdmNavigationProperty; +import org.apache.olingo.odata2.api.edm.EdmParameter; +import org.apache.olingo.odata2.api.edm.EdmProperty; +import org.apache.olingo.odata2.api.exception.ODataException; +import org.apache.olingo.odata2.client.api.uri.QueryOption; +import org.apache.olingo.odata2.testutil.mock.MockFacade; +import org.junit.Before; +import org.junit.Test; + +public class EdmUriBuilderTest { + + protected static final String SERVICE_ROOT_URI = "http://host:80/service/;; + protected static final String SERVICE_ROOT_URI_1 = "http://host:80/service;; + private Edm edm; + + @Before + public void getEdm() throws ODataException { +edm = MockFacade.getMockEdm(); + } + + @Test + public void testUriSimpleES() throws EdmException { +URI uri = new EdmURIBuilderImpl(SERVICE_ROOT_URI). + appendEntitySetSegment(edm.getDefaultEntityContainer().getEntitySet("Employees")). +build(); +assertNotNull(uri); +assertEquals("http://host:80/service/Employees;, uri.toASCIIString()); + } + + @Test + public void testSimpleESWithCountUri1() throws EdmException { +URI uri = new EdmURIBuilderImpl(SERVICE_ROOT_URI). + appendEntitySetSegment(edm.getDefaultEntityContainer().getEntitySet("Employees")). +appendCountSegment(). +build(); +assertNotNull(uri); +assertEquals("http://host:80/service/Employees/$count;, uri.toASCIIString()); + } + + @Test(expected=RuntimeException.class) + public void negTestWithCountAndFormat() throws EdmException { +new EdmURIBuilderImpl(SERVICE_ROOT_URI). + appendEntitySetSegment(edm.getDefaultEntityContainer().getEntitySet("Employees")). +appendCountSegment(). +format("application/json"). +build(); + } + + @Test + public void testSimpleESWithCountUri2() throws EdmException { +EdmEntitySet entitySet = edm.getDefaultEntityContainer().getEntitySet("Managers"); +URI uri = new EdmURIBuilderImpl(SERVICE_ROOT_URI). +appendEntitySetSegment(entitySet). + appendKeySegment((EdmProperty)entitySet.getEntityType().getProperty("EmployeeId"), "1"). + appendNavigationSegment((EdmNavigationProperty)entitySet.getEntityType().getProperty("nm_Employees")). +appendCountSegment(). +build(); +assertNotNull(uri); +assertEquals("http://host:80/service/Managers('1')/nm_Employees/$count", uri.toASCIIString()); + } + + @Test + public void testSimpleESWithCountAndFilter() throws EdmException { +EdmEntitySet entitySet = edm.getDefaultEntityContainer().getEntitySet("Managers"); +URI uri = new EdmURIBuilderImpl(SERVICE_ROOT_URI). +appendEntitySetSegment(entitySet). + appendKeySegment((EdmProperty)entitySet.getEntityType().getProperty("EmployeeId"), "1"). + appendNavigationSegment((EdmNavigationProperty)entitySet.getEntityType().getProperty("nm_Employees")). +appendCountSegment(). +addQueryOption(QueryOption.FILTER, "TeamId eq '1'"). +build(); +assertNotNull(uri); +assertEquals("http://host:80/service/Managers('1')/nm_Employees/" ++ "$count?$filter=TeamId%20eq%20'1'", uri.toASCIIString()); + } + + @Test(expected=RuntimeException.class) + public void negTestUriWithCountSegment1() throws EdmException { +EdmEntitySet entitySet = edm.getDefaultEntityContainer().getEntitySet("Managers"); +EdmEntitySet employeeEntitySet = edm.getDefaultEntityContainer().getEntitySet("Employees"); +new EdmURIBuilderImpl(SERVICE_ROOT_URI). +appendEntitySetSegment(entitySet). + appendKeySegment((EdmProperty)entitySet.getEntityType().getProperty("EmployeeId"), "1"). + appendNavigationSegment((EdmNavigationProperty)entitySet.getEntityType().getProperty("nm_Employees")). +
[22/24] olingo-odata2 git commit: [OLINGO-1253]Client Module for Olingo v2
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/9e949e40/odata2-lib/odata-client-core/src/main/java/org/apache/olingo/odata2/client/core/edm/Impl/EdmFunctionImportParameter.java -- diff --git a/odata2-lib/odata-client-core/src/main/java/org/apache/olingo/odata2/client/core/edm/Impl/EdmFunctionImportParameter.java b/odata2-lib/odata-client-core/src/main/java/org/apache/olingo/odata2/client/core/edm/Impl/EdmFunctionImportParameter.java new file mode 100644 index 000..7a0ca1f --- /dev/null +++ b/odata2-lib/odata-client-core/src/main/java/org/apache/olingo/odata2/client/core/edm/Impl/EdmFunctionImportParameter.java @@ -0,0 +1,140 @@ +/*** + * 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.client.core.edm.Impl; + +import org.apache.olingo.odata2.api.edm.EdmAnnotations; +import org.apache.olingo.odata2.api.edm.EdmFacets; +import org.apache.olingo.odata2.api.edm.EdmMapping; +import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind; +import org.apache.olingo.odata2.client.api.edm.EdmDocumentation; + +/** + * Objects of this class represent function import parameters + * + */ +public class EdmFunctionImportParameter { + + private String name; + private String mode; + private EdmSimpleTypeKind type; + private EdmFacets facets; + private EdmMapping mapping; + private EdmDocumentation documentation; + private EdmAnnotations annotations; + + /** + * @return String name of the parameter + */ + public String getName() { +return name; + } + + /** + * @return {@link EdmSimpleTypeKind} of this parameter + */ + public EdmSimpleTypeKind getType() { +return type; + } + + /** + * @return {@link EdmFacets} of this parameter + */ + public EdmFacets getFacets() { +return facets; + } + + /** + * @return {@link EdmMappingImpl} of this parameter + */ + public EdmMapping getMapping() { +return mapping; + } + + /** + * Sets the name of this {@link EdmFunctionImportParameter} + * @param name + * @return {@link EdmFunctionImportParameter} for method chaining + */ + public EdmFunctionImportParameter setName(final String name) { +this.name = name; +return this; + } + + /** + * Sets the mode of this {@link EdmFunctionImportParameter} + * @param mode + * @return {@link EdmFunctionImportParameter} for method chaining + */ + public EdmFunctionImportParameter setMode(final String mode) { +this.mode = mode; +return this; + } + + /** + * Sets the {@link EdmSimpleTypeKind} of this {@link EdmFunctionImportParameter} + * @param type + * @return {@link EdmFunctionImportParameter} for method chaining + */ + public EdmFunctionImportParameter setType(final EdmSimpleTypeKind type) { +this.type = type; +return this; + } + + /** + * Sets the {@link EdmFacets} of this {@link EdmFunctionImportParameter} + * @param facets + * @return {@link EdmFunctionImportParameter} for method chaining + */ + public EdmFunctionImportParameter setFacets(final EdmFacets facets) { +this.facets = facets; +return this; + } + + /** + * Sets the {@link EdmMappingImpl} of this {@link EdmFunctionImportParameter} + * @param mapping + * @return {@link EdmFunctionImportParameter} for method chaining + */ + public EdmFunctionImportParameter setMapping(final EdmMapping mapping) { +this.mapping = mapping; +return this; + } + + /** + * Sets the {@link Documentation} of this {@link EdmFunctionImportParameter} + * @param documentation + * @return {@link EdmFunctionImportParameter} for method chaining + */ + public EdmFunctionImportParameter setDocumentation(final EdmDocumentation documentation) { +this.documentation = documentation; +return this; + } + + public void setAnnotations(EdmAnnotationsImpl annotations) { +this.annotations = annotations; + } + + public EdmAnnotations getAnnotations() { +return this.annotations; + } + @Override + public String toString() { + return
[02/24] olingo-odata2 git commit: [OLINGO-1253]Client Module for Olingo v2
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/9e949e40/odata2-lib/odata-client-core/src/test/resources/ProductsFeed.xml -- diff --git a/odata2-lib/odata-client-core/src/test/resources/ProductsFeed.xml b/odata2-lib/odata-client-core/src/test/resources/ProductsFeed.xml new file mode 100644 index 000..23a4eb0 --- /dev/null +++ b/odata2-lib/odata-client-core/src/test/resources/ProductsFeed.xml @@ -0,0 +1,474 @@ + +http://services.odata.org/(S(tcjpjrwvrq5cbwf1yqulu1hc))/V2/OData/OData.svc/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices; xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata; xmlns="http://www.w3.org/2005/Atom;> + Products + http://services.odata.org/(S(tcjpjrwvrq5cbwf1yqulu1hc))/V2/OData/OData.svc/Products/ + 2017-04-07T05:44:22Z + + + http://services.odata.org/(S(tcjpjrwvrq5cbwf1yqulu1hc))/V2/OData/OData.svc/Products(0) +Bread +Whole grain bread +2017-04-07T05:44:22Z + + + + +http://schemas.microsoft.com/ado/2007/08/dataservices/related/Category; type="application/atom+xml;type=entry" title="Category" href="Products(0)/Category" /> +http://schemas.microsoft.com/ado/2007/08/dataservices/related/Supplier; type="application/atom+xml;type=entry" title="Supplier" href="Products(0)/Supplier"> + + + http://services.odata.org/(S(tcjpjrwvrq5cbwf1yqulu1hc))/V2/OData/OData.svc/Suppliers(1) + Tokyo Traders + 2017-04-07T05:44:22Z + + + + + http://schemas.microsoft.com/ado/2007/08/dataservices/related/Products; type="application/atom+xml;type=feed" title="Products" href="Suppliers(1)/Products" /> + http://schemas.microsoft.com/ado/2007/08/dataservices/scheme; /> + + + 1 + Tokyo Traders + 0 + +NE 40th +Redmond +WA +98052 +USA + + + + + + +http://schemas.microsoft.com/ado/2007/08/dataservices/scheme; /> + + +0 +1992-01-01T00:00:00 + +4 +2.5 + + + + + http://services.odata.org/(S(tcjpjrwvrq5cbwf1yqulu1hc))/V2/OData/OData.svc/Products(1) +Milk +Low fat milk +2017-04-07T05:44:22Z + + + + +http://schemas.microsoft.com/ado/2007/08/dataservices/related/Category; type="application/atom+xml;type=entry" title="Category" href="Products(1)/Category" /> +http://schemas.microsoft.com/ado/2007/08/dataservices/related/Supplier; type="application/atom+xml;type=entry" title="Supplier" href="Products(1)/Supplier"> + + + http://services.odata.org/(S(tcjpjrwvrq5cbwf1yqulu1hc))/V2/OData/OData.svc/Suppliers(0) + Exotic Liquids + 2017-04-07T05:44:22Z + + + + + http://schemas.microsoft.com/ado/2007/08/dataservices/related/Products; type="application/atom+xml;type=feed" title="Products" href="Suppliers(0)/Products" /> + http://schemas.microsoft.com/ado/2007/08/dataservices/scheme; /> + + + 0 + Exotic Liquids + 0 + +NE 228th +Sammamish +WA +98074 +USA + + + + + + +http://schemas.microsoft.com/ado/2007/08/dataservices/scheme; /> + + +1 +1995-10-01T00:00:00 + +3 +3.5 + + + + + http://services.odata.org/(S(tcjpjrwvrq5cbwf1yqulu1hc))/V2/OData/OData.svc/Products(2) +Vint soda +Americana Variety - Mix of 6 flavors +2017-04-07T05:44:22Z + + + + +http://schemas.microsoft.com/ado/2007/08/dataservices/related/Category; type="application/atom+xml;type=entry" title="Category" href="Products(2)/Category" /> +http://schemas.microsoft.com/ado/2007/08/dataservices/related/Supplier; type="application/atom+xml;type=entry" title="Supplier" href="Products(2)/Supplier"> + + + http://services.odata.org/(S(tcjpjrwvrq5cbwf1yqulu1hc))/V2/OData/OData.svc/Suppliers(0) + Exotic Liquids + 2017-04-07T05:44:22Z + + + + + http://schemas.microsoft.com/ado/2007/08/dataservices/related/Products; type="application/atom+xml;type=feed" title="Products" href="Suppliers(0)/Products" /> + http://schemas.microsoft.com/ado/2007/08/dataservices/scheme; /> + + + 0 + Exotic Liquids + 0 + +NE 228th +Sammamish +WA +98074 +
[03/24] olingo-odata2 git commit: [OLINGO-1253]Client Module for Olingo v2
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/9e949e40/odata2-lib/odata-client-core/src/test/resources/LargeEmployeeFeed.xml -- diff --git a/odata2-lib/odata-client-core/src/test/resources/LargeEmployeeFeed.xml b/odata2-lib/odata-client-core/src/test/resources/LargeEmployeeFeed.xml new file mode 100644 index 000..e9b58d9 --- /dev/null +++ b/odata2-lib/odata-client-core/src/test/resources/LargeEmployeeFeed.xml @@ -0,0 +1,12556 @@ + + +http://www.w3.org/2005/Atom; xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata; xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices; xml:base="https://olingoodata.neo.ondemand.com:443/com.sap.olingo.web/ReferenceScenario.svc/;> + https://olingoodata.neo.ondemand.com:443/com.sap.olingo.web/ReferenceScenario.svc/Employees + Employees + 2013-12-02T12:20:28.605Z + + + + + + https://olingoodata.neo.ondemand.com:443/com.sap.olingo.web/ReferenceScenario.svc/Employees('1') + Walter Winter + 1999-01-01T00:00:00Z + http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/> + + + http://schemas.microsoft.com/ado/2007/08/dataservices/related/ne_Manager; title="ne_Manager" type="application/atom+xml;type=entry"/> + http://schemas.microsoft.com/ado/2007/08/dataservices/related/ne_Team; title="ne_Team" type="application/atom+xml;type=entry"/> + http://schemas.microsoft.com/ado/2007/08/dataservices/related/ne_Room; title="ne_Room" type="application/atom+xml;type=entry"/> + + + 1 + Walter Winter + 1 + 1 + 1 + + + 69124 + Heidelberg + + Germany + + 52 + 1999-01-01T00:00:00 + Employees('1')/$value + + + + https://olingoodata.neo.ondemand.com:443/com.sap.olingo.web/ReferenceScenario.svc/Employees('2') + Frederic Fall + 2003-07-01T00:00:00Z + http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/> + + + http://schemas.microsoft.com/ado/2007/08/dataservices/related/ne_Manager; title="ne_Manager" type="application/atom+xml;type=entry"/> + http://schemas.microsoft.com/ado/2007/08/dataservices/related/ne_Team; title="ne_Team" type="application/atom+xml;type=entry"/> + http://schemas.microsoft.com/ado/2007/08/dataservices/related/ne_Room; title="ne_Room" type="application/atom+xml;type=entry"/> + + + 2 + Frederic Fall + 1 + 2 + 1 + + + 69190 + Walldorf + + Germany + + 32 + 2003-07-01T00:00:00 + Employees('2')/$value + + + + https://olingoodata.neo.ondemand.com:443/com.sap.olingo.web/ReferenceScenario.svc/Employees('3') + Jonathan Smith + 2013-12-02T12:20:28.622Z + http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/> + + + http://schemas.microsoft.com/ado/2007/08/dataservices/related/ne_Manager; title="ne_Manager" type="application/atom+xml;type=entry"/> + http://schemas.microsoft.com/ado/2007/08/dataservices/related/ne_Team; title="ne_Team" type="application/atom+xml;type=entry"/> + http://schemas.microsoft.com/ado/2007/08/dataservices/related/ne_Room; title="ne_Room" type="application/atom+xml;type=entry"/> + + + 3 + Jonathan Smith + 1 + 2 + 1 + + + 69190 + Walldorf + + Germany + + 56 + + Employees('3')/$value + + + +
[04/24] olingo-odata2 git commit: [OLINGO-1253]Client Module for Olingo v2
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/9e949e40/odata2-lib/odata-client-core/src/test/resources/JsonRoom_InlineEmployeesToTeam.json -- diff --git a/odata2-lib/odata-client-core/src/test/resources/JsonRoom_InlineEmployeesToTeam.json b/odata2-lib/odata-client-core/src/test/resources/JsonRoom_InlineEmployeesToTeam.json new file mode 100644 index 000..979e39a --- /dev/null +++ b/odata2-lib/odata-client-core/src/test/resources/JsonRoom_InlineEmployeesToTeam.json @@ -0,0 +1,79 @@ +{ + "d": { +"__metadata": { + "id": "http://localhost:8080/olingo-odata2-ref-web/ReferenceScenario.svc/Rooms('1')", + "uri": "http://localhost:8080/olingo-odata2-ref-web/ReferenceScenario.svc/Rooms('1')", + "type": "RefScenario.Room", + "etag": "W/\"1\"" +}, +"Id": "1", +"Name": "Room 1", +"Seats": 1, +"Version": 1, +"nr_Employees": { + "results": [ +{ + "__metadata": { +"id": "http://localhost:8080/olingo-odata2-ref-web/ReferenceScenario.svc/Employees('1')", +"uri": "http://localhost:8080/olingo-odata2-ref-web/ReferenceScenario.svc/Employees('1')", +"type": "RefScenario.Employee", +"content_type": "image/jpeg", +"media_src": "http://localhost:8080/olingo-odata2-ref-web/ReferenceScenario.svc/Employees('1')/$value", +"edit_media": "http://localhost:8080/olingo-odata2-ref-web/ReferenceScenario.svc/Employees('1')/$value" + }, + "EmployeeId": "1", + "EmployeeName": "Walter Winter", + "ManagerId": "1", + "RoomId": "1", + "TeamId": "1", + "Location": { +"__metadata": { + "type": "RefScenario.c_Location" +}, +"City": { + "__metadata": { +"type": "RefScenario.c_City" + }, + "PostalCode": "69124", + "CityName": "Heidelberg" +}, +"Country": "Germany" + }, + "Age": 52, + "EntryDate": "/Date(91514880)/", + "ImageUrl": "Employees('1')/$value", + "ne_Manager": { +"__deferred": { + "uri": "http://localhost:8080/olingo-odata2-ref-web/ReferenceScenario.svc/Employees('1')/ne_Manager" +} + }, + "ne_Team": { +"__metadata": { + "id": "http://localhost:8080/olingo-odata2-ref-web/ReferenceScenario.svc/Teams('1')", + "uri": "http://localhost:8080/olingo-odata2-ref-web/ReferenceScenario.svc/Teams('1')", + "type": "RefScenario.Team" +}, +"Id": "1", +"Name": "Team 1", +"isScrumTeam": false, +"nt_Employees": { + "__deferred": { +"uri": "http://localhost:8080/olingo-odata2-ref-web/ReferenceScenario.svc/Teams('1')/nt_Employees" + } +} + }, + "ne_Room": { +"__deferred": { + "uri": "http://localhost:8080/olingo-odata2-ref-web/ReferenceScenario.svc/Employees('1')/ne_Room" +} + } +} + ] +}, +"nr_Building": { + "__deferred": { +"uri": "http://localhost:8080/olingo-odata2-ref-web/ReferenceScenario.svc/Rooms('1')/nr_Building" + } +} + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/9e949e40/odata2-lib/odata-client-core/src/test/resources/JsonRoomsToEmployeesWithInlineTeams.json -- diff --git a/odata2-lib/odata-client-core/src/test/resources/JsonRoomsToEmployeesWithInlineTeams.json b/odata2-lib/odata-client-core/src/test/resources/JsonRoomsToEmployeesWithInlineTeams.json new file mode 100644 index 000..671dbb6 --- /dev/null +++ b/odata2-lib/odata-client-core/src/test/resources/JsonRoomsToEmployeesWithInlineTeams.json @@ -0,0 +1,118 @@ +{ + "d": { +"results": [ + { +"__metadata": { + "id": "http://localhost:8080/olingo-odata2-ref-web/ReferenceScenario.svc/Employees('2')", + "uri": "http://localhost:8080/olingo-odata2-ref-web/ReferenceScenario.svc/Employees('2')", + "type": "RefScenario.Employee", + "content_type": "image/jpeg", + "media_src": "http://localhost:8080/olingo-odata2-ref-web/ReferenceScenario.svc/Employees('2')/$value", + "edit_media": "http://localhost:8080/olingo-odata2-ref-web/ReferenceScenario.svc/Employees('2')/$value" +}, +"EmployeeId": "2", +"EmployeeName": "Frederic Fall", +"ManagerId": "1", +"RoomId": "2", +"TeamId": "1", +"Location": { + "__metadata": { +"type": "RefScenario.c_Location" + }, + "City": { +"__metadata": { +
[23/24] olingo-odata2 git commit: [OLINGO-1253]Client Module for Olingo v2
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/9e949e40/odata2-lib/odata-client-core/pom.xml -- diff --git a/odata2-lib/odata-client-core/pom.xml b/odata2-lib/odata-client-core/pom.xml new file mode 100644 index 000..e63401b --- /dev/null +++ b/odata2-lib/odata-client-core/pom.xml @@ -0,0 +1,90 @@ +http://maven.apache.org/POM/4.0.0; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance; + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd;> + 4.0.0 + + + org.apache.olingo + olingo-odata2-lib + 2.0.11-SNAPSHOT + .. + + + olingo-odata2-client-core + jar + ${project.artifactId} + + + + + junit + junit + ${junit.version} + + + org.apache.olingo + olingo-odata2-client-api + ${project.version} + + + org.apache.olingo + olingo-odata2-core + ${project.version} + + +org.apache.olingo +olingo-odata2-testutil +${project.version} +test + + +xmlunit +xmlunit +test + + + org.apache.httpcomponents + httpcore + ${httpcore.version} + + + + + + maven-jar-plugin + + + ${project.build.outputDirectory}/META-INF/MANIFEST.MF + + + + + org.apache.felix + maven-bundle-plugin + true + + + bundle-manifest + process-classes + + manifest + + + + + + + * + + + + ${project.url} + lazy + ${project.artifactId} + + + + + + + + http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/9e949e40/odata2-lib/odata-client-core/src/main/java/org/apache/olingo/odata2/client/core/ODataClientImpl.java -- diff --git a/odata2-lib/odata-client-core/src/main/java/org/apache/olingo/odata2/client/core/ODataClientImpl.java b/odata2-lib/odata-client-core/src/main/java/org/apache/olingo/odata2/client/core/ODataClientImpl.java new file mode 100644 index 000..1a51999 --- /dev/null +++ b/odata2-lib/odata-client-core/src/main/java/org/apache/olingo/odata2/client/core/ODataClientImpl.java @@ -0,0 +1,199 @@ +package org.apache.olingo.odata2.client.core; + +import java.io.InputStream; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import org.apache.olingo.odata2.api.edm.Edm; +import org.apache.olingo.odata2.api.edm.EdmException; +import org.apache.olingo.odata2.api.ep.EntityProviderException; +import org.apache.olingo.odata2.api.exception.ODataNotAcceptableException; +import org.apache.olingo.odata2.api.uri.PathSegment; +import org.apache.olingo.odata2.api.uri.UriInfo; +import org.apache.olingo.odata2.api.uri.UriNotMatchingException; +import org.apache.olingo.odata2.api.uri.UriSyntaxException; +import org.apache.olingo.odata2.client.api.ODataClient; +import org.apache.olingo.odata2.client.api.edm.EdmDataServices; +import org.apache.olingo.odata2.client.api.ep.ContentTypeBasedDeserializer; +import org.apache.olingo.odata2.client.api.ep.ContentTypeBasedSerializer; +import org.apache.olingo.odata2.client.api.ep.DeserializerMetadataProviderInterface; +import
[10/24] olingo-odata2 git commit: [OLINGO-1253]Client Module for Olingo v2
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/9e949e40/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/serializer/AtomEntrySerializerTest.java -- diff --git a/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/serializer/AtomEntrySerializerTest.java b/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/serializer/AtomEntrySerializerTest.java new file mode 100644 index 000..74cab47 --- /dev/null +++ b/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/serializer/AtomEntrySerializerTest.java @@ -0,0 +1,1814 @@ +/*** + * 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.client.core.ep.serializer; + +import static org.custommonkey.xmlunit.XMLAssert.assertXpathEvaluatesTo; +import static org.custommonkey.xmlunit.XMLAssert.assertXpathExists; +import static org.custommonkey.xmlunit.XMLAssert.assertXpathNotExists; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.UnsupportedEncodingException; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.TimeZone; + +import javax.xml.stream.FactoryConfigurationError; +import javax.xml.stream.XMLStreamException; + +import org.apache.olingo.odata2.api.edm.Edm; +import org.apache.olingo.odata2.api.edm.EdmConcurrencyMode; +import org.apache.olingo.odata2.api.edm.EdmCustomizableFeedMappings; +import org.apache.olingo.odata2.api.edm.EdmEntitySet; +import org.apache.olingo.odata2.api.edm.EdmEntityType; +import org.apache.olingo.odata2.api.edm.EdmFacets; +import org.apache.olingo.odata2.api.edm.EdmMapping; +import org.apache.olingo.odata2.api.edm.EdmProperty; +import org.apache.olingo.odata2.api.edm.EdmTargetPath; +import org.apache.olingo.odata2.api.edm.EdmTyped; +import org.apache.olingo.odata2.api.ep.EntityProviderException; +import org.apache.olingo.odata2.api.exception.ODataException; +import org.apache.olingo.odata2.api.exception.ODataMessageException; +import org.apache.olingo.odata2.api.processor.ODataResponse; +import org.apache.olingo.odata2.client.api.edm.ClientEdm; +import org.apache.olingo.odata2.client.api.edm.EdmDataServices; +import org.apache.olingo.odata2.client.api.ep.Entity; +import org.apache.olingo.odata2.client.api.ep.EntityCollection; +import org.apache.olingo.odata2.client.api.ep.EntitySerializerProperties; +import org.apache.olingo.odata2.client.core.ep.AbstractProviderTest; +import org.apache.olingo.odata2.client.core.ep.AtomSerializerDeserializer; +import org.apache.olingo.odata2.client.core.ep.deserializer.XmlMetadataDeserializer; +import org.apache.olingo.odata2.core.commons.ContentType; +import org.apache.olingo.odata2.core.ep.EntityProviderProducerException; +import org.apache.olingo.odata2.testutil.helper.StringHelper; +import org.apache.olingo.odata2.testutil.helper.XMLUnitHelper; +import org.apache.olingo.odata2.testutil.mock.MockFacade; +import org.custommonkey.xmlunit.SimpleNamespaceContext; +import org.custommonkey.xmlunit.XMLUnit; +import org.custommonkey.xmlunit.exceptions.XpathException; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.xml.sax.SAXException; + +import junit.framework.Assert; + +public class AtomEntrySerializerTest extends AbstractProviderTest { + + @Rule + public ExpectedException expectedEx = ExpectedException.none(); + + private String buildingXPathString = "/a:entry/a:link[@href=\"Rooms('1')/nr_Building\" and @title='nr_Building']"; +
[09/24] olingo-odata2 git commit: [OLINGO-1253]Client Module for Olingo v2
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/9e949e40/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/serializer/AtomFeedSerializerTest.java -- diff --git a/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/serializer/AtomFeedSerializerTest.java b/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/serializer/AtomFeedSerializerTest.java new file mode 100644 index 000..8ceead5 --- /dev/null +++ b/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/serializer/AtomFeedSerializerTest.java @@ -0,0 +1,1033 @@ +/*** + * 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.client.core.ep.serializer; + +import static org.custommonkey.xmlunit.XMLAssert.assertXpathExists; +import static org.custommonkey.xmlunit.XMLAssert.assertXpathNotExists; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.HashMap; +import java.util.Map; + +import org.apache.olingo.odata2.api.edm.Edm; +import org.apache.olingo.odata2.api.edm.EdmEntitySet; +import org.apache.olingo.odata2.api.edm.EdmFacets; +import org.apache.olingo.odata2.api.edm.EdmProperty; +import org.apache.olingo.odata2.api.edm.EdmTyped; +import org.apache.olingo.odata2.api.ep.EntityProviderException; +import org.apache.olingo.odata2.api.processor.ODataResponse; +import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo; +import org.apache.olingo.odata2.client.api.ep.Entity; +import org.apache.olingo.odata2.client.api.ep.EntityCollection; +import org.apache.olingo.odata2.client.api.ep.EntityCollectionSerializerProperties; +import org.apache.olingo.odata2.client.api.ep.EntitySerializerProperties; +import org.apache.olingo.odata2.client.core.ep.AbstractProviderTest; +import org.apache.olingo.odata2.client.core.ep.AtomSerializerDeserializer; +import org.apache.olingo.odata2.testutil.helper.StringHelper; +import org.apache.olingo.odata2.testutil.mock.MockFacade; +import org.custommonkey.xmlunit.exceptions.XpathException; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.xml.sax.SAXException; + +/** + * + */ +public class AtomFeedSerializerTest extends AbstractProviderTest { + @Rule + public ExpectedException expectedEx = ExpectedException.none(); + + private String employeeXPathString = "/a:entry/a:link[@href=\"Rooms('1')/nr_Employees\" and @title='nr_Employees']"; + + private static final String EXP_MSG = "Write properties are mandatory for XML."; + private static final String ERROR_MSG = "Entity or expanded entity cannot have null value."; + + public AtomFeedSerializerTest(final StreamWriterImplType type) { +super(type); + } + + private GetEntitySetUriInfo view; + + @Before + public void before() throws Exception { +initializeRoomData(1); + +view = mock(GetEntitySetUriInfo.class); + +EdmEntitySet set = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms"); +when(view.getTargetEntitySet()).thenReturn(set); + } + + @Test + public void entityWithInlineFeed() throws Exception { +Entity roomData = new Entity(); +roomData.addProperty("Id", "1"); +roomData.addProperty("Name", "Neu Schwanstein"); +roomData.addProperty("Seats", new Integer(20)); +EntityCollection listData = new EntityCollection(); +EntitySerializerProperties properties = +EntitySerializerProperties.serviceRoot(BASE_URI) +.includeMetadata(true).build(); +Entity data = new Entity(); +data.addProperty("EmployeeId", "1"); +data.addProperty("EmployeeName", "EmpName1"); +
[08/24] olingo-odata2 git commit: [OLINGO-1253]Client Module for Olingo v2
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/9e949e40/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/serializer/JsonEntryEntitySerializerTest.java -- diff --git a/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/serializer/JsonEntryEntitySerializerTest.java b/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/serializer/JsonEntryEntitySerializerTest.java new file mode 100644 index 000..f7e0433 --- /dev/null +++ b/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/serializer/JsonEntryEntitySerializerTest.java @@ -0,0 +1,1027 @@ +/*** + * 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.client.core.ep.serializer; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.UnsupportedEncodingException; +import java.net.URI; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.TimeZone; + +import javax.xml.stream.XMLStreamException; + +import org.apache.olingo.odata2.api.edm.Edm; +import org.apache.olingo.odata2.api.edm.EdmConcurrencyMode; +import org.apache.olingo.odata2.api.edm.EdmEntitySet; +import org.apache.olingo.odata2.api.edm.EdmEntityType; +import org.apache.olingo.odata2.api.edm.EdmFacets; +import org.apache.olingo.odata2.api.edm.EdmMapping; +import org.apache.olingo.odata2.api.edm.EdmProperty; +import org.apache.olingo.odata2.api.edm.EdmSimpleTypeException; +import org.apache.olingo.odata2.api.edm.EdmTyped; +import org.apache.olingo.odata2.api.ep.EntityProviderException; +import org.apache.olingo.odata2.api.processor.ODataResponse; +import org.apache.olingo.odata2.client.api.edm.ClientEdm; +import org.apache.olingo.odata2.client.api.edm.EdmDataServices; +import org.apache.olingo.odata2.client.api.ep.Entity; +import org.apache.olingo.odata2.client.api.ep.EntityCollection; +import org.apache.olingo.odata2.client.api.ep.EntitySerializerProperties; +import org.apache.olingo.odata2.client.core.ep.JsonSerializerDeserializer; +import org.apache.olingo.odata2.client.core.ep.deserializer.XmlMetadataDeserializer; +import org.apache.olingo.odata2.core.ep.EntityProviderProducerException; +import org.apache.olingo.odata2.testutil.fit.BaseTest; +import org.apache.olingo.odata2.testutil.helper.StringHelper; +import org.apache.olingo.odata2.testutil.mock.MockFacade; +import org.junit.Test; + +import com.google.gson.Gson; +import com.google.gson.internal.LinkedTreeMap; + +/** + * + */ +public class JsonEntryEntitySerializerTest extends BaseTest { + protected static final String BASE_URI = "http://host:80/service/;; + protected static final EntitySerializerProperties DEFAULT_PROPERTIES = + EntitySerializerProperties.serviceRoot(URI.create(BASE_URI)).build(); + protected static final String ERROR_MSG = "Entity or expanded entity cannot have null value."; + protected static final String ERROR_MSG1 = "Navigation has to be either an Entity or a Map."; + + + @Test + public void entry() throws Exception { +final EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Teams"); +Entity entity = new Entity(); +entity.addProperty("Id", "1"); +entity.addProperty("isScrumTeam", true); +entity.setWriteProperties(DEFAULT_PROPERTIES); + +final ODataResponse response = new JsonSerializerDeserializer().writeEntry(entitySet, entity); +final String json = verifyResponse(response); +assertEquals("{\"Id\":\"1\",\"isScrumTeam\":true}", json); + } + +
[01/24] olingo-odata2 git commit: [OLINGO-1253]Client Module for Olingo v2
Repository: olingo-odata2 Updated Branches: refs/heads/clientModule 91bd4b897 -> 9e949e406 http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/9e949e40/odata2-lib/odata-client-core/src/test/resources/feed_with_deleted_entries.xml -- diff --git a/odata2-lib/odata-client-core/src/test/resources/feed_with_deleted_entries.xml b/odata2-lib/odata-client-core/src/test/resources/feed_with_deleted_entries.xml new file mode 100644 index 000..78c187e --- /dev/null +++ b/odata2-lib/odata-client-core/src/test/resources/feed_with_deleted_entries.xml @@ -0,0 +1,40 @@ + + +http://www.w3.org/2005/Atom; xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata; +xmlns:at="http://purl.org/atompub/tombstones/1.0; xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices; + xml:base="https://olingoodata.neo.ondemand.com:443/com.sap.olingo.web/ReferenceScenario.svc/;> + https://olingoodata.neo.ondemand.com:443/com.sap.olingo.web/ReferenceScenario.svc/Rooms +Rooms +2014-01-21T09:15:52.473Z + + + + + +http://host:123/odata/Rooms('1') +Room 1 +2014-01-21T09:15:52.474Z +http://schemas.microsoft.com/ado/2007/08/dataservices/scheme; /> + +http://schemas.microsoft.com/ado/2007/08/dataservices/related/nr_Employees; +title="nr_Employees" type="application/atom+xml;type=feed" /> +http://schemas.microsoft.com/ado/2007/08/dataservices/related/nr_Building; +title="nr_Building" type="application/atom+xml;type=entry" /> + + +1 +Room 1 +1 +1 + + + +http://host:123/odata/Rooms('2')" when="2014-01-14T18:11:06.682+01:00" /> +http://host:123/odata/Rooms?$skiptoken=97; rel="delta" /> + http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/9e949e40/odata2-lib/odata-client-core/src/test/resources/feed_with_delta_link.xml -- diff --git a/odata2-lib/odata-client-core/src/test/resources/feed_with_delta_link.xml b/odata2-lib/odata-client-core/src/test/resources/feed_with_delta_link.xml new file mode 100644 index 000..bb73341 --- /dev/null +++ b/odata2-lib/odata-client-core/src/test/resources/feed_with_delta_link.xml @@ -0,0 +1,69 @@ + + +http://www.w3.org/2005/Atom; + xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata; + xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices; + xmlns:at="http://purl.org/atompub/tombstones/1.0; + xml:base="http://some.host.com/service.root/ReferenceScenario.svc/;> + http://some.host.com/service.root/ReferenceScenario.svc/Employees + Employees + 2013-04-23T11:46:14.926Z + + + + + + http://some.host.com/service.root/ReferenceScenario.svc/Employees('1') + Walter Winter + 1999-01-01T00:00:00Z + http://schemas.microsoft.com/ado/2007/08/dataservices/scheme; /> + + + http://schemas.microsoft.com/ado/2007/08/dataservices/related/ne_Manager; + title="ne_Manager" type="application/atom+xml; type=entry" /> + http://schemas.microsoft.com/ado/2007/08/dataservices/related/ne_Team; + title="ne_Team" type="application/atom+xml; type=entry" /> + http://schemas.microsoft.com/ado/2007/08/dataservices/related/ne_Room; + title="ne_Room" type="application/atom+xml; type=entry" /> + + + 1 + Walter Winter + 1 + 1 + 1 + + + 69124 + Heidelberg + + Germany + + 52 + 1999-01-01T00:00:00 + Employees('1')/$value + + + http://thisisadeltalink; rel="delta"/> + http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/9e949e40/odata2-lib/odata-client-core/src/test/resources/metadataForDeepInsert.xml -- diff --git a/odata2-lib/odata-client-core/src/test/resources/metadataForDeepInsert.xml b/odata2-lib/odata-client-core/src/test/resources/metadataForDeepInsert.xml new file mode 100644 index 000..a718bf5 --- /dev/null +++ b/odata2-lib/odata-client-core/src/test/resources/metadataForDeepInsert.xml @@ -0,0 +1,53 @@ + +http://schemas.microsoft.com/ado/2007/06/edmx;
[13/24] olingo-odata2 git commit: [OLINGO-1253]Client Module for Olingo v2
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/9e949e40/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/deserializer/XmlEntityDeserializerTest.java -- diff --git a/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/deserializer/XmlEntityDeserializerTest.java b/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/deserializer/XmlEntityDeserializerTest.java new file mode 100644 index 000..caf05da --- /dev/null +++ b/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/deserializer/XmlEntityDeserializerTest.java @@ -0,0 +1,2461 @@ +/*** + * 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.client.core.ep.deserializer; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.io.InputStream; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.TimeZone; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.apache.olingo.odata2.api.commons.HttpContentType; +import org.apache.olingo.odata2.api.edm.EdmEntitySet; +import org.apache.olingo.odata2.api.edm.EdmFacets; +import org.apache.olingo.odata2.api.edm.EdmProperty; +import org.apache.olingo.odata2.api.ep.EntityProviderException; +import org.apache.olingo.odata2.api.ep.entry.EntryMetadata; +import org.apache.olingo.odata2.api.ep.entry.MediaMetadata; +import org.apache.olingo.odata2.api.ep.entry.ODataEntry; +import org.apache.olingo.odata2.api.ep.feed.FeedMetadata; +import org.apache.olingo.odata2.api.ep.feed.ODataFeed; +import org.apache.olingo.odata2.api.exception.MessageReference; +import org.apache.olingo.odata2.api.exception.ODataMessageException; +import org.apache.olingo.odata2.client.api.ep.DeserializerProperties; +import org.apache.olingo.odata2.client.api.ep.EntityStream; +import org.apache.olingo.odata2.client.api.ep.callback.OnDeserializeInlineContent; +import org.apache.olingo.odata2.testutil.helper.StringHelper; +import org.apache.olingo.odata2.testutil.mock.MockFacade; +import org.junit.Assert; +import org.junit.Test; +import org.mockito.Mockito; + +/** + * + */ +public class XmlEntityDeserializerTest extends AbstractXmlDeserializerTest { + + public XmlEntityDeserializerTest(final StreamWriterImplType type) { +super(type); + } + + private static final Logger LOG = Logger.getLogger(XmlEntityDeserializerTest.class.getName()); + static { +LOG.setLevel(Level.OFF); + } + + public static final String EMPLOYEE_1_XML = + "" + + + "http://www.w3.org/2005/Atom\; " + + "xmlns:m=\"http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\; " + + "xmlns:d=\"http://schemas.microsoft.com/ado/2007/08/dataservices\; xml:base=\"http://localhost:19000/\; " + + "m:etag=\"W/1\">" + + + " http://localhost:19000/Employees('1')" + + + " Walter Winter" + + + " 1999-01-01T00:00:00Z" + + + " http://schemas.microsoft.com/ado/2007/08/dataservices/scheme\"/>" + + + " " + + + " " + + + " http://schemas.microsoft.com/ado/2007/08/dataservices/related/ne_Room\; " + + "type=\"application/atom+xml; type=entry\" title=\"ne_Room\"/>" + + + " http://schemas.microsoft.com/ado/2007/08/dataservices/related/ne_Manager\; " + + "type=\"application/atom+xml; type=entry\" title=\"ne_Manager\"/>" + + + " http://schemas.microsoft.com/ado/2007/08/dataservices/related/ne_Team\; " + + "type=\"application/atom+xml; type=entry\" title=\"ne_Team\"/>" + + + " " + + " " + + "1"
[05/24] olingo-odata2 git commit: [OLINGO-1253]Client Module for Olingo v2
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/9e949e40/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/uri/UriParserTest.java -- diff --git a/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/uri/UriParserTest.java b/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/uri/UriParserTest.java new file mode 100644 index 000..50d0c5e --- /dev/null +++ b/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/uri/UriParserTest.java @@ -0,0 +1,1132 @@ +package org.apache.olingo.odata2.client.core.uri; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Mockito.when; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import org.apache.olingo.odata2.api.commons.InlineCount; +import org.apache.olingo.odata2.api.edm.Edm; +import org.apache.olingo.odata2.api.edm.EdmEntitySet; +import org.apache.olingo.odata2.api.edm.EdmException; +import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind; +import org.apache.olingo.odata2.api.edm.EdmTypeKind; +import org.apache.olingo.odata2.api.exception.MessageReference; +import org.apache.olingo.odata2.api.exception.ODataException; +import org.apache.olingo.odata2.api.exception.ODataMessageException; +import org.apache.olingo.odata2.api.uri.KeyPredicate; +import org.apache.olingo.odata2.api.uri.PathSegment; +import org.apache.olingo.odata2.api.uri.UriInfo; +import org.apache.olingo.odata2.api.uri.UriNotMatchingException; +import org.apache.olingo.odata2.api.uri.UriParser; +import org.apache.olingo.odata2.api.uri.UriSyntaxException; +import org.apache.olingo.odata2.client.api.ODataClient; +import org.apache.olingo.odata2.core.uri.UriInfoImpl; +import org.apache.olingo.odata2.core.uri.UriParserImpl; +import org.apache.olingo.odata2.core.uri.UriType; +import org.apache.olingo.odata2.testutil.mock.MockFacade; +import org.junit.Before; +import org.junit.Test; + +public class UriParserTest { + + private Edm edm; + + @Before + public void getEdm() throws ODataException { +edm = MockFacade.getMockEdm(); + } + + @Test + public void copyPathSegmentsTest() throws Exception { +List pathSegments = new ArrayList(); +pathSegments.add(UriParser.createPathSegment("$metadata", null)); +UriInfo result = new UriParserImpl(edm).parse(pathSegments, Collections.emptyMap()); +assertNotNull(result); +assertEquals(1, pathSegments.size()); +assertEquals("$metadata", pathSegments.get(0).getPath()); + } + + @Test + public void copyPathSegmentsTestEncoded() throws Exception { +List pathSegments = new ArrayList(); +pathSegments.add(UriParser.createPathSegment("%24metadata", null)); +UriInfoImpl result = (UriInfoImpl) new UriParserImpl(edm).parse(pathSegments, +Collections. emptyMap()); +assertNotNull(result); +assertEquals(UriType.URI8, result.getUriType()); + } + + @Test + public void parseNonsense() throws Exception { +parseWrongUri("/bla", UriNotMatchingException.NOTFOUND); + } + + @Test + public void parseServiceDocument() throws Exception { +UriInfoImpl result = parse("/"); +assertEquals(UriType.URI0, result.getUriType()); + +result = parse(""); +assertEquals(UriType.URI0, result.getUriType()); + +result = +(UriInfoImpl) new UriParserImpl(edm).parse(Collections. emptyList(), Collections +. emptyMap()); +assertEquals(UriType.URI0, result.getUriType()); + } + + @Test + public void parseMetadata() throws Exception { +UriInfoImpl result = parse("/$metadata"); +assertEquals(UriType.URI8, result.getUriType()); + } + + @Test + public void parseMetadataError() throws Exception { +parseWrongUri("/$metadata/somethingwrong", UriSyntaxException.MUSTBELASTSEGMENT); + } + + @Test + public void parseBatch() throws Exception { +UriInfoImpl result = parse("/$batch"); +assertEquals(UriType.URI9, result.getUriType()); + } + + @Test + public void parseBatchError() throws Exception { +parseWrongUri("/$batch/somethingwrong", UriSyntaxException.MUSTBELASTSEGMENT); + } + + @Test + public void parseSomethingEntitySet() throws Exception { +parseWrongUri("/somethingwrong", UriNotMatchingException.NOTFOUND); + } + + @Test + public void parseContainerWithoutEntitySet() throws Exception { +parseWrongUri("Container1.", UriNotMatchingException.MATCHPROBLEM); + } + + @Test +
[olingo-odata2] Git Push Summary
Repository: olingo-odata2 Updated Branches: refs/heads/clientModule [created] 91bd4b897