org.apache.olingo.commons.api.data.ContextURL Java Examples
The following examples show how to use
org.apache.olingo.commons.api.data.ContextURL.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ODataXmlSerializerTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void entitySetTwoPrimNoMetadata() throws Exception { final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESTwoPrim"); final EntityCollection entitySet = data.readAll(edmEntitySet); InputStream result = new ODataJsonSerializer(ContentType.JSON_NO_METADATA) .entityCollection(metadata, edmEntitySet.getEntityType(), entitySet, EntityCollectionSerializerOptions.with() .contextURL(ContextURL.with().entitySet(edmEntitySet).build()).build()).getContent(); final String resultString = IOUtils.toString(result); final String expectedResult = "{\"value\":[" + "{\"PropertyInt16\":32766,\"PropertyString\":\"Test String1\"}," + "{\"PropertyInt16\":-365,\"PropertyString\":\"Test String2\"}," + "{\"PropertyInt16\":-32766,\"PropertyString\":null}," + "{\"PropertyInt16\":32767,\"PropertyString\":\"Test String4\"}]}"; Assert.assertEquals(expectedResult, resultString); }
Example #2
Source File: JsonDeltaSerializer.java From olingo-odata4 with Apache License 2.0 | 6 votes |
public void writeAddedUpdatedEntity(final ServiceMetadata metadata, final EdmEntityType entityType, final Entity entity, final ExpandOption expand, final SelectOption select, final ContextURL url, final boolean onlyReference, String name, final JsonGenerator json) throws IOException, SerializerException { json.writeStartObject(); if (entity.getId() != null && url != null) { String entityId = entity.getId().toString(); name = url.getEntitySetOrSingletonOrType(); if (!entityId.contains(name)) { String entityName = entityId.substring(0, entityId.indexOf("(")); if (!entityName.equals(name)) { json.writeStringField(Constants.JSON_CONTEXT, HASH + entityName + ENTITY); } } } json.writeStringField(Constants.JSON_ID, getEntityId(entity, entityType, name)); writeProperties(metadata, entityType, entity.getProperties(), select, json); json.writeEndObject(); }
Example #3
Source File: JsonDeltaSerializerTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test(expected = SerializerException.class) public void negativeLinkDeltaTest3() throws Exception { final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESDelta"); Delta delta = new Delta(); List<DeltaLink> addedLinks = new ArrayList<DeltaLink>(); DeltaLink link1 = new DeltaLink(); link1.setRelationship("NavPropertyETAllPrimOne"); link1.setSource(new URI("ESDelta(100)")); addedLinks.add(link1 ); delta.getAddedLinks().addAll(addedLinks ); ser.entityCollection(metadata, edmEntitySet.getEntityType(), delta , EntityCollectionSerializerOptions.with() .contextURL(ContextURL.with().entitySet(edmEntitySet).build()) .build()).getContent(); }
Example #4
Source File: ODataJsonSerializerv01Test.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void complexProperty() throws Exception { final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMixPrimCollComp"); final EdmProperty edmProperty = (EdmProperty) edmEntitySet.getEntityType().getProperty("PropertyComp"); final Property property = data.readAll(edmEntitySet).getEntities().get(0).getProperty("PropertyComp"); final String resultString = IOUtils.toString(serializer .complex(metadata, (EdmComplexType) edmProperty.getType(), property, ComplexSerializerOptions.with() .contextURL(ContextURL.with() .entitySet(edmEntitySet).keyPath("32767").navOrPropertyPath(edmProperty.getName()) .build()) .build()).getContent()); Assert.assertEquals("{" + "\"@context\":\"../$metadata#ESMixPrimCollComp(32767)/PropertyComp\"," + "\"@metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"PropertyInt16\":111,\"PropertyString\":\"TEST A\"}", resultString); }
Example #5
Source File: ODataJsonSerializerTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void entityCollectionReference() throws Exception { final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim"); final EntityCollection entityCollection = data.readAll(edmEntitySet); final SerializerResult serializerResult = serializer.referenceCollection(metadata, edmEntitySet, entityCollection, ReferenceCollectionSerializerOptions.with() .contextURL(ContextURL.with().asCollection().suffix(Suffix.REFERENCE).build()) .build()); final String resultString = IOUtils.toString(serializerResult.getContent()); Assert.assertEquals("{\"@odata.context\":\"../$metadata#Collection($ref)\"," + "\"value\":[{\"@odata.id\":\"ESAllPrim(32767)\"}," + "{\"@odata.id\":\"ESAllPrim(-32768)\"}," + "{\"@odata.id\":\"ESAllPrim(0)\"},{\"@odata.id\":\"ESAllPrim(10)\"}]}", resultString); }
Example #6
Source File: ODataJsonSerializerTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void primitiveCollectionPropertyIEEE754CompatibleInt64() throws Exception { final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESCollAllPrim"); final EdmProperty edmProperty = (EdmProperty) edmEntitySet.getEntityType().getProperty("CollPropertyInt64"); final Property property = data.readAll(edmEntitySet).getEntities().get(0).getProperty(edmProperty.getName()); final String resultString = IOUtils.toString(serializerIEEECompatible .primitiveCollection(metadata, (EdmPrimitiveType) edmProperty.getType(), property, PrimitiveSerializerOptions.with() .contextURL(ContextURL.with() .entitySet(edmEntitySet).keyPath("1").navOrPropertyPath(edmProperty.getName()).build()) .build()).getContent()); Assert.assertEquals("{" + "\"@odata.context\":\"../$metadata#ESCollAllPrim(1)/CollPropertyInt64\"," + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"value\":[\"929292929292\",\"333333333333\",\"444444444444\"]}", resultString); }
Example #7
Source File: ContextURLHelperTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void buildSelectComplex() throws Exception { final EdmEntitySet entitySet = entityContainer.getEntitySet("ESCompMixPrimCollComp"); final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList( ExpandSelectMock.mockSelectItem(entitySet, "PropertyMixedPrimCollComp", "PropertyComp", "PropertyString"), ExpandSelectMock.mockSelectItem(entitySet, "PropertyMixedPrimCollComp", "PropertyComp", "PropertyInt16"), ExpandSelectMock.mockSelectItem(entitySet, "PropertyMixedPrimCollComp", "CollPropertyString"), ExpandSelectMock.mockSelectItem(entitySet, "PropertyMixedPrimCollComp", "CollPropertyComp"), ExpandSelectMock.mockSelectItem(entitySet, "PropertyInt16"))); final ContextURL contextURL = ContextURL.with().entitySet(entitySet) .selectList(ContextURLHelper.buildSelectList(entitySet.getEntityType(), null, select)).build(); assertEquals("$metadata#ESCompMixPrimCollComp(" + "PropertyInt16," + "PropertyMixedPrimCollComp/CollPropertyString," + "PropertyMixedPrimCollComp/PropertyComp/PropertyInt16," + "PropertyMixedPrimCollComp/PropertyComp/PropertyString," + "PropertyMixedPrimCollComp/CollPropertyComp)", ContextURLBuilder.create(contextURL).toASCIIString()); }
Example #8
Source File: ODataJsonSerializerv01Test.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void entityWrongData() throws Exception { final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim"); Entity entity = data.readAll(edmEntitySet).getEntities().get(0); entity.getProperties().get(0).setValue(ValueType.PRIMITIVE, false); try { serializer.entity(metadata, edmEntitySet.getEntityType(), entity, EntitySerializerOptions.with() .contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build()) .build()); Assert.fail("Expected exception not thrown!"); } catch (final SerializerException e) { Assert.assertEquals(SerializerException.MessageKeys.WRONG_PROPERTY_VALUE, e.getMessageKey()); final String message = e.getLocalizedMessage(); Assert.assertThat(message, CoreMatchers.containsString("PropertyInt16")); Assert.assertThat(message, CoreMatchers.containsString("false")); } }
Example #9
Source File: ODataJsonSerializerTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void entityESKeyNavContFullMetadata() throws Exception { final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESKeyNavCont"); final Entity entity = data.readAll(edmEntitySet).getEntities().get(0); InputStream result = serializerFullMetadata.entity(metadata, edmEntitySet.getEntityType(), entity, EntitySerializerOptions.with() .contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build()) .build()).getContent(); final String resultString = IOUtils.toString(result); final String expected = "{\"@odata.context\":\"$metadata#ESKeyNavCont/$entity\"," + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\",\"@odata.type\":" + "\"#olingo.odata.test1.ETKeyNavCont\",\"@odata.id\":\"ESKeyNavCont(32766)\"," + "\"[email protected]\":\"#Int16\",\"PropertyInt16\":32766," + "\"PropertyString\":\"Test String1\",\"PropertyCompNavCont\":" + "{\"@odata.type\":\"#olingo.odata.test1.CTNavCont\"}}"; Assert.assertEquals(expected, resultString); }
Example #10
Source File: ODataJsonSerializerv01Test.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void primitiveCollectionProperty() throws Exception { final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESCollAllPrim"); final EdmProperty edmProperty = (EdmProperty) edmEntitySet.getEntityType().getProperty("CollPropertyString"); final Property property = data.readAll(edmEntitySet).getEntities().get(0).getProperty(edmProperty.getName()); final String resultString = IOUtils.toString(serializer .primitiveCollection(metadata, (EdmPrimitiveType) edmProperty.getType(), property, PrimitiveSerializerOptions.with() .contextURL(ContextURL.with() .entitySet(edmEntitySet).keyPath("1").navOrPropertyPath(edmProperty.getName()) .build()) .build()).getContent()); Assert.assertEquals("{" + "\"@context\":\"../$metadata#ESCollAllPrim(1)/CollPropertyString\"," + "\"@metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"value\":[\"[email protected]\",\"[email protected]\",\"[email protected]\"]}", resultString); }
Example #11
Source File: ODataJsonSerializerv01Test.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void primitivePropertyIEEE754CompatibleInt64() throws Exception { final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim"); final EdmProperty edmProperty = (EdmProperty) edmEntitySet.getEntityType().getProperty("PropertyInt64"); final Property property = data.readAll(edmEntitySet).getEntities().get(0).getProperty(edmProperty.getName()); final String resultString = IOUtils.toString(serializerIEEECompatible .primitive(metadata, (EdmPrimitiveType) edmProperty.getType(), property, PrimitiveSerializerOptions.with() .contextURL(ContextURL.with() .entitySet(edmEntitySet).keyPath("32767").navOrPropertyPath(edmProperty.getName()).build()) .build()).getContent()); Assert.assertEquals("{" + "\"@context\":\"../$metadata#ESAllPrim(32767)/PropertyInt64\"," + "\"@metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"value\":\"" + Long.MAX_VALUE + "\"}", resultString); }
Example #12
Source File: JsonDeltaSerializerWithNavigationsTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test(expected = SerializerException.class) public void negativeLinkDeltaTest1() throws Exception { final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESDelta"); Delta delta = new Delta(); List<DeltaLink> addedLinks = new ArrayList<DeltaLink>(); DeltaLink link1 = new DeltaLink(); link1.setSource(new URI("ESDelta(100)")); link1.setTarget(new URI("ESAllPrim(0)")); addedLinks.add(link1 ); delta.getAddedLinks().addAll(addedLinks ); ser.entityCollection(metadata, edmEntitySet.getEntityType(), delta , EntityCollectionSerializerOptions.with() .contextURL(ContextURL.with().entitySet(edmEntitySet).build()) .build()).getContent(); }
Example #13
Source File: ContextURLHelperTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void buildEntityTypeCastAndComplexTypeCastInSelect() throws Exception { final EdmEntitySet entitySet = entityContainer.getEntitySet("ESTwoKeyNav"); final EdmEntityType derivedEntityType = edm.getEntityType( new FullQualifiedName("olingo.odata.test1.ETBaseTwoKeyNav")); final EdmComplexType derivedComplexType = edm.getComplexType( new FullQualifiedName("olingo.odata.test1.CTBasePrimCompNav")); final SelectItem selectItem = ExpandSelectMock.mockSelectItemOnDerivedEntityAndComplexTypes( "CollPropertyComp", derivedEntityType, derivedComplexType, "NavPropertyETTwoKeyNavOne"); Mockito.when(selectItem.getStartTypeFilter()).thenReturn(derivedEntityType); final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(selectItem)); final ContextURL contextURL = ContextURL.with().entitySet(entitySet) .selectList(ContextURLHelper.buildSelectList(entitySet.getEntityType(), null, select)).build(); assertEquals("$metadata#ESTwoKeyNav(PropertyInt16,PropertyString," + "olingo.odata.test1.ETBaseTwoKeyNav/CollPropertyComp/" + "olingo.odata.test1.CTBasePrimCompNav/NavPropertyETTwoKeyNavOne)", ContextURLBuilder.create(contextURL).toASCIIString()); }
Example #14
Source File: ODataJsonSerializerv01Test.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void entityMedia() throws Exception { final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMedia"); final Entity entity = data.readAll(edmEntitySet).getEntities().get(0); final String resultString = IOUtils.toString(serializer.entity(metadata, edmEntitySet.getEntityType(), entity, EntitySerializerOptions.with() .contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build()) .build()).getContent()); final String expectedResult = "{\"@context\":\"$metadata#ESMedia/$entity\"," + "\"@metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"@mediaEtag\":\"W/\\\"1\\\"\"," + "\"@mediaContentType\":\"image/svg+xml\"," + "\"@mediaEditLink\":\"ESMedia(1)/$value\"," + "\"PropertyInt16\":1}"; Assert.assertEquals(expectedResult, resultString); }
Example #15
Source File: JsonDeltaSerializerTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void testDeltaForStream() throws Exception { final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESWithStream"); Delta delta = new Delta(); List<DeltaLink> addedLinks = new ArrayList<DeltaLink>(); DeltaLink link1 = new DeltaLink(); link1.setRelationship("NavPropertyETAllPrimOne"); link1.setSource(new URI("ESDelta(100)")); link1.setTarget(new URI("ESAllPrim(0)")); addedLinks.add(link1 ); delta.getAddedLinks().addAll(addedLinks ); InputStream stream = ser.entityCollection(metadata, edmEntitySet.getEntityType(), delta , EntityCollectionSerializerOptions.with() .contextURL(ContextURL.with().entitySet(edmEntitySet).build()) .build()).getContent(); String jsonString = IOUtils.toString(stream); final String expectedResult = "{" + "\"@odata.context\":\"$metadata#ESWithStream/$delta\"," + "\"value\":[{\"@odata.context\":\"#ESWithStream/$link\"," + "\"source\":\"ESDelta(100)\",\"relationship\":\"NavPropertyETAllPrimOne\"," + "\"target\":\"ESAllPrim(0)\"}]" + "}"; Assert.assertNotNull(jsonString); Assert.assertEquals(expectedResult, jsonString); }
Example #16
Source File: JsonDeltaSerializerTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void addedDeltaLink() throws Exception { final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESDelta"); Delta delta = new Delta(); List<DeltaLink> addedLinks = new ArrayList<DeltaLink>(); DeltaLink link1 = new DeltaLink(); link1.setRelationship("NavPropertyETAllPrimOne"); link1.setSource(new URI("ESDelta(100)")); link1.setTarget(new URI("ESAllPrim(0)")); addedLinks.add(link1 ); delta.getAddedLinks().addAll(addedLinks ); InputStream stream = ser.entityCollection(metadata, edmEntitySet.getEntityType(), delta , EntityCollectionSerializerOptions.with() .contextURL(ContextURL.with().entitySet(edmEntitySet).build()) .build()).getContent(); String jsonString = IOUtils.toString(stream); final String expectedResult = "{" + "\"@odata.context\":\"$metadata#ESDelta/$delta\",\"value\":[{" + "\"@odata.context\":\"#ESDelta/$link\",\"source\":\"ESDelta(100)\"," + "\"relationship\":\"NavPropertyETAllPrimOne\"," + "\"target\":\"ESAllPrim(0)\"}]" + "}"; Assert.assertNotNull(jsonString); Assert.assertEquals(expectedResult, jsonString); }
Example #17
Source File: ODataJsonSerializerTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void selectAll() throws Exception { final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESTwoPrim"); final Entity entity = data.readAll(edmEntitySet).getEntities().get(0); final SelectItem selectItem1 = ExpandSelectMock.mockSelectItem(edmEntitySet, "PropertyString"); SelectItem selectItem2 = Mockito.mock(SelectItem.class); Mockito.when(selectItem2.isStar()).thenReturn(true); final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(selectItem1, selectItem2)); InputStream result = serializer.entity(metadata, edmEntitySet.getEntityType(), entity, EntitySerializerOptions.with() .contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build()) .select(select) .build()).getContent(); final String resultString = IOUtils.toString(result); final String expectedResult = "{\"@odata.context\":\"$metadata#ESTwoPrim/$entity\"," + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"PropertyInt16\":32766,\"PropertyString\":\"Test String1\"}"; Assert.assertEquals(expectedResult, resultString); }
Example #18
Source File: ODataJsonSerializerTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void entityMediaWithMetadataFull() throws Exception { final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMedia"); final Entity entity = data.readAll(edmEntitySet).getEntities().get(0); entity.setMediaETag("W/\\\"08D25949E3BFB7AB\\\""); InputStream result = serializerFullMetadata .entity(metadata, edmEntitySet.getEntityType(), entity, EntitySerializerOptions.with().contextURL(ContextURL.with() .entitySet(edmEntitySet).suffix(Suffix.ENTITY).build()).build()) .getContent(); final String resultString = IOUtils.toString(result); final String expectedResult = "{\"@odata.context\":\"$metadata#ESMedia/$entity\"," + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"@odata.mediaEtag\":\"W/\\\\\\\"08D25949E3BFB7AB\\\\\\\"\",\"@odata.mediaContentType\":\"image/svg+xml\"," + "\"@odata.mediaEditLink\":\"ESMedia(1)/$value\"," + "\"@odata.type\":\"#olingo.odata.test1.ETMedia\",\"@odata.id\":\"ESMedia(1)\"," + "\"[email protected]\":\"#Int16\",\"PropertyInt16\":1}"; Assert.assertEquals(expectedResult, resultString); }
Example #19
Source File: ODataJsonSerializerTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void primitiveProperty() throws Exception { final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim"); final EdmProperty edmProperty = (EdmProperty) edmEntitySet.getEntityType().getProperty("PropertyString"); final Property property = data.readAll(edmEntitySet).getEntities().get(0).getProperty(edmProperty.getName()); final String resultString = IOUtils.toString(serializer .primitive(metadata, (EdmPrimitiveType) edmProperty.getType(), property, PrimitiveSerializerOptions.with() .contextURL(ContextURL.with() .entitySet(edmEntitySet).keyPath("32767").navOrPropertyPath(edmProperty.getName()) .build()) .build()).getContent()); Assert.assertEquals("{" + "\"@odata.context\":\"../$metadata#ESAllPrim(32767)/PropertyString\"," + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"value\":\"First Resource - positive values\"}", resultString); }
Example #20
Source File: AtomSerializer.java From olingo-odata4 with Apache License 2.0 | 6 votes |
private <T> void addContextInfo( final XMLStreamWriter writer, final ResWrap<T> container) throws XMLStreamException { if (container.getContextURL() != null) { final ContextURL contextURL = ContextURLParser.parse(container.getContextURL()); final URI base = contextURL.getServiceRoot(); if (container.getPayload() instanceof EntityCollection) { ((EntityCollection) container.getPayload()).setBaseURI(base); } if (container.getPayload() instanceof Entity) { ((Entity) container.getPayload()).setBaseURI(base); } writer.writeAttribute(Constants.NS_METADATA, Constants.CONTEXT, container.getContextURL().toASCIIString()); } if (container.getMetadataETag() != null) { writer.writeAttribute(Constants.NS_METADATA, Constants.ATOM_ATTR_METADATAETAG, container.getMetadataETag()); } }
Example #21
Source File: ODataJsonSerializerTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void expandStreamPropertyOnComplexWithNoMetadata() throws Exception { final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESStreamOnComplexProp"); final Entity entity = data.readAll(edmEntitySet).getEntities().get(1); final ExpandItem expandItem = ExpandSelectMock.mockExpandItem(edmEntitySet, "PropertyCompWithStream", "PropertyStream"); final ExpandOption expand = ExpandSelectMock.mockExpandOption(Arrays.asList(expandItem)); InputStream result = serializerNoMetadataV401.entity(metadata, edmEntitySet.getEntityType(), entity, EntitySerializerOptions.with() .contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build()) .expand(expand) .build()).getContent(); final String resultString = IOUtils.toString(result); final String expectedResult = "{\"PropertyInt16\":7,\"PropertyInt32\":10," + "\"PropertyCompWithStream\":{\"PropertyStream\":\"\ufffdioz\ufffd\\\"\ufffd\"," + "\"PropertyComp\":{\"PropertyInt16\":333,\"PropertyString\":\"TEST123\"}}}"; Assert.assertEquals(expectedResult, resultString); }
Example #22
Source File: ContextURLParserTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void complexOrPrimitiveType() { ContextURL contextURL = ContextURLParser.parse(URI.create("http://host/service/$metadata#Edm.String")); assertEquals("Edm.String", contextURL.getEntitySetOrSingletonOrType()); assertNull(contextURL.getDerivedEntity()); assertNull(contextURL.getSelectList()); assertNull(contextURL.getNavOrPropertyPath()); assertFalse(contextURL.isEntity()); contextURL = ContextURLParser.parse(URI.create("http://host/service/$metadata#ODataDemo.Address")); assertEquals("ODataDemo.Address", contextURL.getEntitySetOrSingletonOrType()); assertNull(contextURL.getDerivedEntity()); assertNull(contextURL.getSelectList()); assertNull(contextURL.getNavOrPropertyPath()); assertFalse(contextURL.isEntity()); }
Example #23
Source File: ODataXmlSerializerTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void primitiveCollectionProperty() throws Exception { final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESCollAllPrim"); final EdmProperty edmProperty = (EdmProperty) edmEntitySet.getEntityType().getProperty("CollPropertyString"); final Property property = data.readAll(edmEntitySet).getEntities().get(0).getProperty(edmProperty.getName()); final String resultString = IOUtils.toString(serializer .primitiveCollection(metadata, (EdmPrimitiveType) edmProperty.getType(), property, PrimitiveSerializerOptions.with() .contextURL(ContextURL.with() .entitySet(edmEntitySet).keyPath("1").navOrPropertyPath(edmProperty.getName()) .build()) .build()).getContent()); String expected = "<?xml version='1.0' encoding='UTF-8'?>" + "<m:value xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\" " + "m:context=\"../$metadata#ESCollAllPrim(1)/CollPropertyString\" " + "m:metadata-etag=\"metadataETag\" m:type=\"#Collection(String)\">" + "<m:element>[email protected]</m:element>" + "<m:element>[email protected]</m:element>" + "<m:element>[email protected]</m:element>" + "</m:value>"; checkXMLEqual(expected, resultString); }
Example #24
Source File: ODataJsonSerializerv01Test.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void entitySetTwoPrimNoMetadata() throws Exception { final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESTwoPrim"); final EntityCollection entitySet = data.readAll(edmEntitySet); final String resultString = IOUtils.toString(serializerNoMetadata .entityCollection(metadata, edmEntitySet.getEntityType(), entitySet, EntityCollectionSerializerOptions.with() .contextURL(ContextURL.with().entitySet(edmEntitySet).build()) .build()).getContent()); final String expectedResult = "{\"value\":[" + "{\"PropertyInt16\":32766,\"PropertyString\":\"Test String1\"}," + "{\"PropertyInt16\":-365,\"PropertyString\":\"Test String2\"}," + "{\"PropertyInt16\":-32766,\"PropertyString\":null}," + "{\"PropertyInt16\":32767,\"PropertyString\":\"Test String4\"}]}"; Assert.assertEquals(expectedResult, resultString); }
Example #25
Source File: ODataXmlSerializerTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void primitiveProperty() throws Exception { final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim"); final EdmProperty edmProperty = (EdmProperty) edmEntitySet.getEntityType().getProperty("PropertyString"); final Property property = data.readAll(edmEntitySet).getEntities().get(0).getProperty(edmProperty.getName()); final String resultString = IOUtils.toString(serializer .primitive(metadata, (EdmPrimitiveType) edmProperty.getType(), property, PrimitiveSerializerOptions.with() .contextURL(ContextURL.with() .entitySet(edmEntitySet).keyPath("32767").navOrPropertyPath(edmProperty.getName()) .build()) .build()).getContent()); String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<m:value xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\" " + "m:context=\"../$metadata#ESAllPrim(32767)/PropertyString\" " + "m:metadata-etag=\"metadataETag\">" + "First Resource - positive values</m:value>"; Assert.assertEquals(expected, resultString); }
Example #26
Source File: JsonDeltaSerializer.java From olingo-odata4 with Apache License 2.0 | 5 votes |
ContextURL checkContextURL(final ContextURL contextURL) throws SerializerException { if (isODataMetadataNone) { return null; } else if (contextURL == null) { throw new SerializerException("ContextURL null!", SerializerException.MessageKeys.NO_CONTEXT_URL); } return contextURL; }
Example #27
Source File: ODataJsonSerializerv01Test.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Test public void expandSelect() throws Exception { final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESTwoPrim"); final EdmEntityType entityType = edmEntitySet.getEntityType(); final Entity entity = data.readAll(edmEntitySet).getEntities().get(3); final SelectOption select = ExpandSelectMock.mockSelectOption(Collections.singletonList( ExpandSelectMock.mockSelectItem(entityContainer.getEntitySet("ESAllPrim"), "PropertyDate"))); ExpandItem expandItem = ExpandSelectMock.mockExpandItem(edmEntitySet, "NavPropertyETAllPrimOne"); Mockito.when(expandItem.getSelectOption()).thenReturn(select); final ExpandOption expand = ExpandSelectMock.mockExpandOption(Collections.singletonList(expandItem)); final String resultString = IOUtils.toString(serializer .entity(metadata, entityType, entity, EntitySerializerOptions.with() .contextURL(ContextURL.with().entitySet(edmEntitySet) .selectList(helper.buildContextURLSelectList(entityType, expand, select)) .suffix(Suffix.ENTITY).build()) .expand(expand) .build()).getContent()); Assert.assertEquals("{" + "\"@context\":\"$metadata#ESTwoPrim(PropertyInt16," + "NavPropertyETAllPrimOne(PropertyInt16,PropertyDate))/$entity\"," + "\"@metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"PropertyInt16\":32767,\"PropertyString\":\"Test String4\"," + "\"NavPropertyETAllPrimOne\":{\"@id\":\"ESAllPrim(32767)\"," + "\"PropertyInt16\":32767,\"PropertyDate\":\"2012-12-03\"}}", resultString); }
Example #28
Source File: ODataJsonSerializerTest.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Test public void deriveEntityESAllPrimDerivedOne() throws Exception { final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrimDerived"); final Entity entity = data.readAll(edmEntitySet).getEntities().get(0); final ExpandOption expand = ExpandSelectMock.mockExpandOption(Collections.singletonList( ExpandSelectMock.mockExpandItem(edmEntitySet, "NavPropertyETTwoPrimOne"))); InputStream result = serializer.entity(metadata, edmEntitySet.getEntityType(), entity, EntitySerializerOptions.with() .contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build()) .expand(expand) .build()).getContent(); final String resultString = IOUtils.toString(result); final String expectedResult = "{\"@odata.context\":\"$metadata#ESAllPrimDerived/$entity\"," + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"PropertyInt16\":32767,\"PropertyString\":\"First Resource - positive values\",\"PropertyBoolean\":true," + "\"PropertyByte\":255,\"PropertySByte\":127,\"PropertyInt32\":2147483647," + "\"PropertyInt64\":9223372036854775807," + "\"PropertySingle\":1.79E20,\"PropertyDouble\":-1.79E19," + "\"PropertyDecimal\":34,\"PropertyBinary\":\"ASNFZ4mrze8=\"," + "\"PropertyDate\":\"2012-12-03\",\"PropertyDateTimeOffset\":\"2012-12-03T07:16:23Z\"," + "\"PropertyDuration\":\"PT6S\"," + "\"PropertyGuid\":\"01234567-89ab-cdef-0123-456789abcdef\",\"PropertyTimeOfDay\":\"03:26:05\"," + "\"NavPropertyETTwoPrimOne\":{\"@odata.type\":\"#olingo.odata.test1.ETBase\",\"PropertyInt16\":32766," + "\"PropertyString\":\"Test String1\",\"AdditionalPropertyString_5\":\"Additional String1\"}}"; Assert.assertEquals(expectedResult, resultString); }
Example #29
Source File: DemoActionProcessor.java From olingo-odata4 with Apache License 2.0 | 5 votes |
private ContextURL getContextUrl(final EdmEntitySet entitySet, final EdmEntityType entityType, final boolean isSingleEntity) throws ODataLibraryException { Builder builder = ContextURL.with(); builder = entitySet == null ? isSingleEntity ? builder.type(entityType) : builder.asCollection().type(entityType) : builder.entitySet(entitySet); builder = builder.suffix(isSingleEntity && entitySet != null ? Suffix.ENTITY : null); return builder.build(); }
Example #30
Source File: ODataJsonSerializerTest.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Test public void expandSelect() throws Exception { final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESTwoPrim"); final EdmEntityType entityType = edmEntitySet.getEntityType(); final Entity entity = data.readAll(edmEntitySet).getEntities().get(3); final SelectOption select = ExpandSelectMock.mockSelectOption(Collections.singletonList( ExpandSelectMock.mockSelectItem(entityContainer.getEntitySet("ESAllPrim"), "PropertyDate"))); ExpandItem expandItem = ExpandSelectMock.mockExpandItem(edmEntitySet, "NavPropertyETAllPrimOne"); Mockito.when(expandItem.getSelectOption()).thenReturn(select); final ExpandOption expand = ExpandSelectMock.mockExpandOption(Collections.singletonList(expandItem)); final String resultString = IOUtils.toString(serializer .entity(metadata, entityType, entity, EntitySerializerOptions.with() .contextURL(ContextURL.with().entitySet(edmEntitySet) .selectList(helper.buildContextURLSelectList(entityType, expand, select)) .suffix(Suffix.ENTITY).build()) .expand(expand) .build()).getContent()); Assert.assertEquals("{" + "\"@odata.context\":\"$metadata#ESTwoPrim(PropertyInt16," + "NavPropertyETAllPrimOne(PropertyInt16,PropertyDate))/$entity\"," + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"PropertyInt16\":32767,\"PropertyString\":\"Test String4\"," + "\"NavPropertyETAllPrimOne\":{\"@odata.id\":\"ESAllPrim(32767)\"," + "\"PropertyInt16\":32767,\"PropertyDate\":\"2012-12-03\"}}", resultString); }