Java Code Examples for org.apache.olingo.odata2.api.ep.entry.ODataEntry#getProperties()
The following examples show how to use
org.apache.olingo.odata2.api.ep.entry.ODataEntry#getProperties() .
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: JsonEntryConsumerTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void readSimpleRoomEntry() throws Exception { ODataEntry roomEntry = prepareAndExecuteEntry(SIMPLE_ENTRY_ROOM, "Rooms", DEFAULT_PROPERTIES); // verify Map<String, Object> properties = roomEntry.getProperties(); assertEquals(4, properties.size()); assertEquals("1", properties.get("Id")); assertEquals("Room 1", properties.get("Name")); assertEquals((short) 1, properties.get("Seats")); assertEquals((short) 1, properties.get("Version")); List<String> associationUris = roomEntry.getMetadata().getAssociationUris("nr_Employees"); assertEquals(1, associationUris.size()); assertEquals("http://localhost:8080/ReferenceScenario.svc/Rooms('1')/nr_Employees", associationUris.get(0)); associationUris = roomEntry.getMetadata().getAssociationUris("nr_Building"); assertEquals(1, associationUris.size()); assertEquals("http://localhost:8080/ReferenceScenario.svc/Rooms('1')/nr_Building", associationUris.get(0)); EntryMetadata metadata = roomEntry.getMetadata(); assertEquals("W/\"1\"", metadata.getEtag()); }
Example 2
Source File: JsonEntryConsumerTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void readSimpleBuildingEntryWithoutD() throws Exception { ODataEntry result = prepareAndExecuteEntry(SIMPLE_ENTRY_BUILDING_WITHOUT_D, "Buildings", DEFAULT_PROPERTIES); // verify Map<String, Object> properties = result.getProperties(); assertNotNull(properties); assertEquals("1", properties.get("Id")); assertEquals("Building 1", properties.get("Name")); assertNull(properties.get("Image")); assertNull(properties.get("nb_Rooms")); List<String> associationUris = result.getMetadata().getAssociationUris("nb_Rooms"); assertEquals(1, associationUris.size()); assertEquals("http://localhost:8080/ReferenceScenario.svc/Buildings('1')/nb_Rooms", associationUris.get(0)); checkMediaDataInitial(result.getMediaMetadata()); }
Example 3
Source File: XmlEntityConsumerTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
/** * Reads an employee with inlined but <code>NULL</code> room navigation property * (which has {@link com.sap.core.odata.api.edm.EdmMultiplicity#ONE EdmMultiplicity#ONE}). */ @Test public void readWithInlineContentEmployeeNullRoomEntry() throws Exception { EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees"); InputStream reqContent = createContentAsStream(EMPLOYEE_1_NULL_ROOM_XML); // execute XmlEntityConsumer xec = new XmlEntityConsumer(); ODataEntry entry = xec.readEntry(entitySet, reqContent, EntityProviderReadProperties.init().mergeSemantic(true).build()); // validate assertNotNull(entry); Map<String, Object> properties = entry.getProperties(); assertEquals("1", properties.get("EmployeeId")); assertEquals("Walter Winter", properties.get("EmployeeName")); ODataEntry room = (ODataEntry) properties.get("ne_Room"); assertNull(room); }
Example 4
Source File: XmlEntityDeserializerTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
/** * Reads an employee with inlined but <code>NULL</code> room navigation property * (which has {@link com.sap.core.odata.api.edm.EdmMultiplicity#ONE EdmMultiplicity#ONE}). */ @Test public void readWithInlineContentEmployeeNullRoomEntry() throws Exception { EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees"); InputStream reqContent = createContentAsStream(EMPLOYEE_1_NULL_ROOM_XML); EntityStream stream = new EntityStream(); stream.setContent(reqContent); stream.setReadProperties(DeserializerProperties.init().build()); // execute XmlEntityDeserializer xec = new XmlEntityDeserializer(); ODataEntry entry = xec.readEntry(entitySet, stream); // validate assertNotNull(entry); Map<String, Object> properties = entry.getProperties(); assertEquals("1", properties.get("EmployeeId")); assertEquals("Walter Winter", properties.get("EmployeeName")); ODataEntry room = (ODataEntry) properties.get("ne_Room"); assertNull(room); }
Example 5
Source File: JsonEntryDeserializerTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void readMinimalEntry() throws Exception { final EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Teams"); EntityStream entityStream = new EntityStream(); entityStream.setContent(createContentAsStream("{\"Id\":\"99\"}")); entityStream.setReadProperties(DEFAULT_PROPERTIES); final ODataEntry result = new JsonEntityDeserializer().readEntry(entitySet, entityStream); final Map<String, Object> properties = result.getProperties(); assertNotNull(properties); assertEquals(1, properties.size()); assertEquals("99", properties.get("Id")); assertTrue(result.getMetadata().getAssociationUris("nt_Employees").isEmpty()); checkMediaDataInitial(result.getMediaMetadata()); }
Example 6
Source File: JsonEntryConsumerTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void readEntryWithNullProperty() throws Exception { final EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms"); final String content = "{\"Id\":\"99\",\"Seats\":null}"; for (final boolean merge : new boolean[] { false, true }) { final ODataEntry result = new JsonEntityConsumer().readEntry(entitySet, createContentAsStream(content), EntityProviderReadProperties.init().mergeSemantic(merge).build()); final Map<String, Object> properties = result.getProperties(); assertNotNull(properties); assertEquals(2, properties.size()); assertEquals("99", properties.get("Id")); assertTrue(properties.containsKey("Seats")); assertNull(properties.get("Seats")); assertTrue(result.getMetadata().getAssociationUris("nr_Employees").isEmpty()); checkMediaDataInitial(result.getMediaMetadata()); } }
Example 7
Source File: XmlEntityConsumerTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Test public void testReadEntryRequestNullMapping() throws Exception { XmlEntityConsumer xec = new XmlEntityConsumer(); EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees"); InputStream content = createContentAsStream(EMPLOYEE_1_XML); ODataEntry result = xec.readEntry(entitySet, content, EntityProviderReadProperties.init().mergeSemantic(true).build()); // verify Map<String, Object> properties = result.getProperties(); assertEquals(9, properties.size()); assertEquals("1", properties.get("EmployeeId")); assertEquals("Walter Winter", properties.get("EmployeeName")); assertEquals("1", properties.get("ManagerId")); assertEquals("1", properties.get("RoomId")); assertEquals("1", properties.get("TeamId")); Map<String, Object> location = (Map<String, Object>) properties.get("Location"); assertEquals(2, location.size()); assertEquals("Germany", location.get("Country")); Map<String, Object> city = (Map<String, Object>) location.get("City"); assertEquals(2, city.size()); assertEquals("69124", city.get("PostalCode")); assertEquals("Heidelberg", city.get("CityName")); assertEquals(Integer.valueOf(52), properties.get("Age")); Calendar entryDate = (Calendar) properties.get("EntryDate"); assertEquals(915148800000L, entryDate.getTimeInMillis()); assertEquals(TimeZone.getTimeZone("GMT"), entryDate.getTimeZone()); assertEquals("/SAP/PUBLIC/BC/NWDEMO_MODEL/IMAGES/Employee_1.png", properties.get("ImageUrl")); }
Example 8
Source File: JsonEntryDeepInsertFeedTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Test public void innerFeedNoMediaResourceWithCallback() throws Exception { FeedCallback callback = new FeedCallback(); EntityProviderReadProperties readProperties = EntityProviderReadProperties.init().mergeSemantic(false).callback(callback).build(); ODataEntry outerEntry = prepareAndExecuteEntry(BUILDING_WITH_INLINE_ROOMS, "Buildings", readProperties); ODataFeed innerRoomFeed = (ODataFeed) outerEntry.getProperties().get("nb_Rooms"); assertNull(innerRoomFeed); innerRoomFeed = callback.getFeed(); List<ODataEntry> rooms = innerRoomFeed.getEntries(); assertNotNull(rooms); assertEquals(1, rooms.size()); ODataEntry room = rooms.get(0); Map<String, Object> roomProperties = room.getProperties(); assertEquals(4, roomProperties.size()); assertEquals("1", roomProperties.get("Id")); assertEquals("Room 1", roomProperties.get("Name")); assertEquals(Short.valueOf("1"), roomProperties.get("Version")); assertEquals(Short.valueOf("1"), roomProperties.get("Seats")); List<String> associationUris = room.getMetadata().getAssociationUris("nr_Employees"); assertEquals(1, associationUris.size()); assertEquals("http://localhost:8080/ReferenceScenario.svc/Rooms('1')/nr_Employees", associationUris.get(0)); associationUris = room.getMetadata().getAssociationUris("nr_Building"); assertEquals(1, associationUris.size()); assertEquals("http://localhost:8080/ReferenceScenario.svc/Rooms('1')/nr_Building", associationUris.get(0)); }
Example 9
Source File: XmlEntityConsumerTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
/** * Missing 'key' properties are allowed for validation against Edm model. * @throws Exception */ @Test @SuppressWarnings("unchecked") public void testReadEntryMissingKeyProperty() throws Exception { // prepare final EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees"); InputStream contentBody = createContentAsStream(EMPLOYEE_1_XML.replace("<d:EmployeeId>1</d:EmployeeId>", "")); // execute XmlEntityConsumer xec = new XmlEntityConsumer(); ODataEntry result = xec.readEntry(entitySet, contentBody, EntityProviderReadProperties.init().mergeSemantic(false).build()); // verify Map<String, Object> properties = result.getProperties(); assertEquals(8, properties.size()); assertNull(properties.get("EmployeeId")); assertEquals("Walter Winter", properties.get("EmployeeName")); assertEquals("1", properties.get("ManagerId")); assertEquals("1", properties.get("RoomId")); assertEquals("1", properties.get("TeamId")); Map<String, Object> location = (Map<String, Object>) properties.get("Location"); assertEquals(2, location.size()); assertEquals("Germany", location.get("Country")); Map<String, Object> city = (Map<String, Object>) location.get("City"); assertEquals(2, city.size()); assertEquals("69124", city.get("PostalCode")); assertEquals("Heidelberg", city.get("CityName")); assertEquals(Integer.valueOf(52), properties.get("Age")); Calendar entryDate = (Calendar) properties.get("EntryDate"); assertEquals(915148800000L, entryDate.getTimeInMillis()); assertEquals(TimeZone.getTimeZone("GMT"), entryDate.getTimeZone()); assertEquals("/SAP/PUBLIC/BC/NWDEMO_MODEL/IMAGES/Employee_1.png", properties.get("ImageUrl")); }
Example 10
Source File: XmlEntityDeserializerTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Test public void testReadEntryRequest() throws Exception { XmlEntityDeserializer xec = new XmlEntityDeserializer(); EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees"); EntityStream stream = new EntityStream(); InputStream content = createContentAsStream(EMPLOYEE_1_XML); stream.setContent(content); stream.setReadProperties(DeserializerProperties.init().build()); // execute ODataEntry result = xec.readEntry(entitySet, stream); // verify Map<String, Object> properties = result.getProperties(); assertEquals(9, properties.size()); assertEquals("1", properties.get("EmployeeId")); assertEquals("Walter Winter", properties.get("EmployeeName")); assertEquals("1", properties.get("ManagerId")); assertEquals("1", properties.get("RoomId")); assertEquals("1", properties.get("TeamId")); Map<String, Object> location = (Map<String, Object>) properties.get("Location"); assertEquals(2, location.size()); assertEquals("Germany", location.get("Country")); Map<String, Object> city = (Map<String, Object>) location.get("City"); assertEquals(2, city.size()); assertEquals("69124", city.get("PostalCode")); assertEquals("Heidelberg", city.get("CityName")); assertEquals(Integer.valueOf(52), properties.get("Age")); Calendar entryDate = (Calendar) properties.get("EntryDate"); assertEquals(915148800000L, entryDate.getTimeInMillis()); assertEquals(TimeZone.getTimeZone("GMT"), entryDate.getTimeZone()); assertEquals("/SAP/PUBLIC/BC/NWDEMO_MODEL/IMAGES/Employee_1.png", properties.get("ImageUrl")); }
Example 11
Source File: ProducerConsumerIntegrationTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
private Map<String, Object> execute(final Map<String, Object> localRoomData, final EdmEntitySet roomSet, final String contentType) throws EntityProviderException { ODataResponse response = EntityProvider.writeEntry(contentType, roomSet, localRoomData, DEFAULT_WRITE_PROPERTIES); InputStream content = (InputStream) response.getEntity(); ODataEntry entry = EntityProvider.readEntry(contentType, roomSet, content, DEFAULT_READ_PROPERTIES); Map<String, Object> properties = entry.getProperties(); return properties; }
Example 12
Source File: XmlEntityConsumerTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Test public void testReadEntryWithLargeProperty() throws Exception { // prepare EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees"); String newName = StringHelper.generateData(81920); InputStream contentBody = createContentAsStream(EMPLOYEE_1_XML.replaceAll("Walter Winter", newName)); // execute XmlEntityConsumer xec = new XmlEntityConsumer(); ODataEntry result = xec.readEntry(entitySet, contentBody, EntityProviderReadProperties.init().mergeSemantic(false).build()); // verify Map<String, Object> properties = result.getProperties(); assertEquals(9, properties.size()); assertEquals("1", properties.get("EmployeeId")); assertEquals(newName, properties.get("EmployeeName")); assertEquals("1", properties.get("ManagerId")); assertEquals("1", properties.get("RoomId")); assertEquals("1", properties.get("TeamId")); Map<String, Object> location = (Map<String, Object>) properties.get("Location"); assertEquals(2, location.size()); assertEquals("Germany", location.get("Country")); Map<String, Object> city = (Map<String, Object>) location.get("City"); assertEquals(2, city.size()); assertEquals("69124", city.get("PostalCode")); assertEquals("Heidelberg", city.get("CityName")); assertEquals(Integer.valueOf(52), properties.get("Age")); Calendar entryDate = (Calendar) properties.get("EntryDate"); assertEquals(915148800000L, entryDate.getTimeInMillis()); assertEquals(TimeZone.getTimeZone("GMT"), entryDate.getTimeZone()); assertEquals("/SAP/PUBLIC/BC/NWDEMO_MODEL/IMAGES/Employee_1.png", properties.get("ImageUrl")); }
Example 13
Source File: JsonEntryDeepInsertEntryTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Test public void innerEntryWithOptionalNavigationProperty() throws Exception { // prepare DeserializerProperties readProperties = DeserializerProperties.init().build(); EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees"); // modify edm for test case (change multiplicity to ZERO_TO_ONE) EdmType navigationType = mock(EdmType.class); when(navigationType.getKind()).thenReturn(EdmTypeKind.ENTITY); EdmNavigationProperty navigationProperty = mock(EdmNavigationProperty.class); when(navigationProperty.getName()).thenReturn("ne_Team"); when(navigationProperty.getType()).thenReturn(navigationType); when(navigationProperty.getMultiplicity()).thenReturn(EdmMultiplicity.ZERO_TO_ONE); when(entitySet.getEntityType().getProperty("ne_Team")).thenReturn(navigationProperty); EdmEntitySet targetEntitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Teams"); when(entitySet.getRelatedEntitySet(navigationProperty)).thenReturn(targetEntitySet); // execute JsonEntityDeserializer xec = new JsonEntityDeserializer(); InputStream contentBody = getFileAsStream(EMPLOYEE_WITH_INLINE_TEAM); EntityStream entityStream = new EntityStream(); entityStream.setContent(contentBody); entityStream.setReadProperties(readProperties); ODataEntry outerEntry = xec.readEntry(entitySet, entityStream); ODataEntry innerTeam = (ODataEntry) outerEntry.getProperties().get("ne_Team"); Map<String, Object> innerTeamProperties = innerTeam.getProperties(); assertEquals("1", innerTeamProperties.get("Id")); assertEquals("Team 1", innerTeamProperties.get("Name")); assertEquals(Boolean.FALSE, innerTeamProperties.get("isScrumTeam")); assertNull(innerTeamProperties.get("nt_Employees")); List<String> associationUris = innerTeam.getMetadata().getAssociationUris("nt_Employees"); assertEquals(1, associationUris.size()); assertEquals("http://localhost:8080/ReferenceScenario.svc/Teams('1')/nt_Employees", associationUris.get(0)); }
Example 14
Source File: XmlEntityConsumerTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Test public void readIncompleteEntryMerge() throws Exception { XmlEntityConsumer xec = new XmlEntityConsumer(); EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms"); InputStream reqContent = createContentAsStream(ROOM_1_XML); ODataEntry result = xec.readEntry(entitySet, reqContent, EntityProviderReadProperties.init().mergeSemantic(true).build()); // verify EntryMetadata entryMetadata = result.getMetadata(); assertEquals("http://localhost:19000/test/Rooms('1')", entryMetadata.getId()); assertEquals("W/\"1\"", entryMetadata.getEtag()); assertEquals(null, entryMetadata.getUri()); MediaMetadata mediaMetadata = result.getMediaMetadata(); assertEquals("application/xml", mediaMetadata.getContentType()); assertEquals(null, mediaMetadata.getSourceLink()); assertEquals(null, mediaMetadata.getEditLink()); assertEquals(null, mediaMetadata.getEtag()); Map<String, Object> properties = result.getProperties(); assertEquals(1, properties.size()); assertEquals("1", properties.get("Id")); assertEquals("Rooms('1')/nr_Building", result.getMetadata().getAssociationUris("nr_Building").get(0)); assertEquals("Rooms('1')/nr_Employees", result.getMetadata().getAssociationUris("nr_Employees").get(0)); }
Example 15
Source File: XmlEntityDeserializerTest.java From olingo-odata2 with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") @Test public void testReadEntryWithMergeAndMappings() throws Exception { // prepare EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees"); String content = EMPLOYEE_1_XML.replace("<d:Age>52</d:Age>", ""); InputStream contentBody = createContentAsStream(content); EntityStream stream = new EntityStream(); stream.setContent(contentBody); OnDeserializeInlineContent callback = new Callback(); DeserializerProperties consumerProperties = DeserializerProperties.init().addTypeMappings( createTypeMappings("Age", Long.class, // test unused type mapping "EntryDate", Date.class)).callback(callback).build(); stream.setReadProperties(consumerProperties); // execute XmlEntityDeserializer xec = new XmlEntityDeserializer(); ODataEntry result = xec.readEntry(entitySet, stream); // verify Map<String, Object> properties = result.getProperties(); assertEquals(8, properties.size()); // removed property assertNull(properties.get("Age")); // available properties assertEquals("1", properties.get("EmployeeId")); assertEquals("Walter Winter", properties.get("EmployeeName")); assertEquals("1", properties.get("ManagerId")); assertEquals("1", properties.get("RoomId")); assertEquals("1", properties.get("TeamId")); Map<String, Object> location = (Map<String, Object>) properties.get("Location"); assertEquals(2, location.size()); assertEquals("Germany", location.get("Country")); Map<String, Object> city = (Map<String, Object>) location.get("City"); assertEquals(2, city.size()); assertEquals("69124", city.get("PostalCode")); assertEquals("Heidelberg", city.get("CityName")); assertEquals(new Date(915148800000l), properties.get("EntryDate")); assertEquals("/SAP/PUBLIC/BC/NWDEMO_MODEL/IMAGES/Employee_1.png", properties.get("ImageUrl")); }
Example 16
Source File: XmlEntityConsumerTest.java From olingo-odata2 with Apache License 2.0 | 4 votes |
/** Teams('1')?$expand=nt_Employees,nt_Employees/ne_Team */ @Test public void readWithDoubleInlineContent() throws Exception { // prepare String content = readFile("double_expanded_team.xml"); assertNotNull(content); EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Teams"); InputStream reqContent = createContentAsStream(content); // execute XmlEntityConsumer xec = new XmlEntityConsumer(); EntityProviderReadProperties consumerProperties = EntityProviderReadProperties.init().mergeSemantic(false).build(); ODataEntry entry = xec.readEntry(entitySet, reqContent, consumerProperties); // validate assertNotNull(entry); Map<String, Object> properties = entry.getProperties(); assertEquals("1", properties.get("Id")); assertEquals("Team 1", properties.get("Name")); assertEquals(Boolean.FALSE, properties.get("isScrumTeam")); // ODataFeed employeesFeed = (ODataFeed) properties.get("nt_Employees"); List<ODataEntry> employees = employeesFeed.getEntries(); assertEquals(3, employees.size()); // ODataEntry employeeNo2 = employees.get(1); Map<String, Object> employessNo2Props = employeeNo2.getProperties(); assertEquals("Frederic Fall", employessNo2Props.get("EmployeeName")); assertEquals("2", employessNo2Props.get("RoomId")); assertEquals(32, employessNo2Props.get("Age")); @SuppressWarnings("unchecked") Map<String, Object> emp2Location = (Map<String, Object>) employessNo2Props.get("Location"); @SuppressWarnings("unchecked") Map<String, Object> emp2City = (Map<String, Object>) emp2Location.get("City"); assertEquals("69190", emp2City.get("PostalCode")); assertEquals("Walldorf", emp2City.get("CityName")); ODataEntry inlinedTeam = (ODataEntry) employessNo2Props.get("ne_Team"); assertEquals("1", inlinedTeam.getProperties().get("Id")); assertEquals("Team 1", inlinedTeam.getProperties().get("Name")); }
Example 17
Source File: XmlEntityDeserializerTest.java From olingo-odata2 with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") @Test public void testReadFeedWithInlineCountAndNextLink() throws Exception { // prepare EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees"); String content = readFile("feed_employees_full.xml"); InputStream contentAsStream = createContentAsStream(content); EntityStream stream = new EntityStream(); stream.setContent(contentAsStream); stream.setReadProperties(DeserializerProperties.init().build()); // execute XmlEntityDeserializer xec = new XmlEntityDeserializer(); ODataFeed feedResult = xec.readFeed(entitySet, stream); // verify feed result // metadata FeedMetadata metadata = feedResult.getFeedMetadata(); assertEquals(Integer.valueOf(6), metadata.getInlineCount()); assertEquals("http://thisisanextlink", metadata.getNextLink()); assertNull(metadata.getDeltaLink()); // entries List<ODataEntry> entries = feedResult.getEntries(); assertEquals(6, entries.size()); // verify first employee ODataEntry firstEmployee = entries.get(0); Map<String, Object> properties = firstEmployee.getProperties(); assertEquals(9, properties.size()); assertEquals("1", properties.get("EmployeeId")); assertEquals("Walter Winter", properties.get("EmployeeName")); assertEquals("1", properties.get("ManagerId")); assertEquals("1", properties.get("RoomId")); assertEquals("1", properties.get("TeamId")); Map<String, Object> location = (Map<String, Object>) properties.get("Location"); assertEquals(2, location.size()); assertEquals("Germany", location.get("Country")); Map<String, Object> city = (Map<String, Object>) location.get("City"); assertEquals(2, city.size()); assertEquals("69124", city.get("PostalCode")); assertEquals("Heidelberg", city.get("CityName")); assertEquals(Integer.valueOf(52), properties.get("Age")); Calendar entryDate = (Calendar) properties.get("EntryDate"); assertEquals(915148800000L, entryDate.getTimeInMillis()); assertEquals(TimeZone.getTimeZone("GMT"), entryDate.getTimeZone()); assertEquals("Employees('1')/$value", properties.get("ImageUrl")); }
Example 18
Source File: XmlEntityDeserializerTest.java From olingo-odata2 with Apache License 2.0 | 4 votes |
/** Teams('1')?$expand=nt_Employees */ @SuppressWarnings("unchecked") @Test public void readWithInlineContent() throws Exception { // prepare String content = readFile("expanded_team.xml"); assertNotNull(content); EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Teams"); InputStream reqContent = createContentAsStream(content); // execute XmlEntityDeserializer xec = new XmlEntityDeserializer(); DeserializerProperties consumerProperties = DeserializerProperties.init() .build(); EntityStream stream = new EntityStream(); stream.setContent(reqContent); stream.setReadProperties(consumerProperties); ODataEntry entry = xec.readEntry(entitySet, stream); // validate assertNotNull(entry); Map<String, Object> properties = entry.getProperties(); assertEquals("1", properties.get("Id")); assertEquals("Team 1", properties.get("Name")); assertEquals(Boolean.FALSE, properties.get("isScrumTeam")); ODataFeed employeesFeed = (ODataFeed) properties.get("nt_Employees"); List<ODataEntry> employees = employeesFeed.getEntries(); assertEquals(3, employees.size()); // ODataEntry employeeNo2 = employees.get(1); Map<String, Object> employessNo2Props = employeeNo2.getProperties(); assertEquals("Frederic Fall", employessNo2Props.get("EmployeeName")); assertEquals("2", employessNo2Props.get("RoomId")); assertEquals(32, employessNo2Props.get("Age")); Map<String, Object> emp2Location = (Map<String, Object>) employessNo2Props.get("Location"); Map<String, Object> emp2City = (Map<String, Object>) emp2Location.get("City"); assertEquals("69190", emp2City.get("PostalCode")); assertEquals("Walldorf", emp2City.get("CityName")); }
Example 19
Source File: JsonEntryDeepInsertFeedTest.java From olingo-odata2 with Apache License 2.0 | 4 votes |
@Test public void innerFeedWithCallback() throws Exception { FeedCallback callback = new FeedCallback(); EntityProviderReadProperties readProperties = EntityProviderReadProperties.init().mergeSemantic(false).callback(callback).build(); EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Buildings"); String content = readFile("JsonBuildingWithInlineRoomsFeedToEmployees.json"); assertNotNull(content); InputStream contentBody = createContentAsStream(content); // execute JsonEntityConsumer xec = new JsonEntityConsumer(); ODataEntry result = xec.readEntry(entitySet, contentBody, readProperties); assertNotNull(result); ODataFeed innerRoomFeed = (ODataFeed) result.getProperties().get("nb_Rooms"); assertNull(innerRoomFeed); innerRoomFeed = callback.getFeed(); List<ODataEntry> rooms = innerRoomFeed.getEntries(); assertNotNull(rooms); assertEquals(1, rooms.size()); ODataEntry room = rooms.get(0); Map<String, Object> roomProperties = room.getProperties(); assertEquals(5, roomProperties.size()); assertEquals("1", roomProperties.get("Id")); assertEquals("Room 1", roomProperties.get("Name")); assertEquals(Short.valueOf("1"), roomProperties.get("Version")); assertEquals(Short.valueOf("1"), roomProperties.get("Seats")); Map<String, Object> inlineEntries = callback.getNavigationProperties(); getExpandedData(inlineEntries, result, entitySet.getEntityType()); List<ODataEntry> roomsFeed = ((ODataFeed)result.getProperties().get("nb_Rooms")).getEntries(); List<ODataEntry> employeesFeed = ((ODataFeed)roomsFeed.get(0).getProperties(). get("nr_Employees")).getEntries(); assertEquals(1, employeesFeed.size()); assertEquals(10, employeesFeed.get(0).getProperties().size()); assertEquals(3, ((ODataEntry)employeesFeed.get(0).getProperties().get("ne_Team")). getProperties().size()); }
Example 20
Source File: JsonFeedConsumerTest.java From olingo-odata2 with Apache License 2.0 | 4 votes |
@Test public void teamsFeed() throws Exception { ODataFeed feed = prepareAndExecuteFeed("JsonTeams.json", "Teams", DEFAULT_PROPERTIES); List<ODataEntry> entries = feed.getEntries(); assertNotNull(entries); assertEquals(2, entries.size()); // Team1 ODataEntry entry = entries.get(0); Map<String, Object> properties = entry.getProperties(); assertNotNull(properties); assertEquals("1", properties.get("Id")); assertEquals("Team 1", properties.get("Name")); assertEquals(Boolean.FALSE, properties.get("isScrumTeam")); assertNull(properties.get("nt_Employees")); List<String> associationUris = entry.getMetadata().getAssociationUris("nt_Employees"); assertEquals(1, associationUris.size()); assertEquals("http://localhost:8080/ReferenceScenario.svc/Teams('1')/nt_Employees", associationUris.get(0)); checkMediaDataInitial(entry.getMediaMetadata()); // Team2 entry = entries.get(1); properties = entry.getProperties(); assertNotNull(properties); assertEquals("2", properties.get("Id")); assertEquals("Team 2", properties.get("Name")); assertEquals(Boolean.TRUE, properties.get("isScrumTeam")); assertNull(properties.get("nt_Employees")); associationUris = entry.getMetadata().getAssociationUris("nt_Employees"); assertEquals(1, associationUris.size()); assertEquals("http://localhost:8080/ReferenceScenario.svc/Teams('2')/nt_Employees", associationUris.get(0)); checkMediaDataInitial(entry.getMediaMetadata()); // Check FeedMetadata FeedMetadata feedMetadata = feed.getFeedMetadata(); assertNotNull(feedMetadata); assertNull(feedMetadata.getInlineCount()); assertNull(feedMetadata.getNextLink()); }