org.apache.olingo.odata2.api.edm.EdmProperty Java Examples
The following examples show how to use
org.apache.olingo.odata2.api.edm.EdmProperty.
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: EntityInfoAggregator.java From olingo-odata2 with Apache License 2.0 | 6 votes |
private Map<String, EntityPropertyInfo> createPropertyInfoObjects(final EdmStructuralType type, final List<String> propertyNames) throws EntityProviderException { try { Map<String, EntityPropertyInfo> infos = new HashMap<String, EntityPropertyInfo>(); for (String propertyName : propertyNames) { EdmProperty property = (EdmProperty) type.getProperty(propertyName); checkETagRelevant(property); EntityPropertyInfo info = createEntityPropertyInfo(property); infos.put(info.getName(), info); checkTargetPathInfo(property, info); } return infos; } catch (EdmException e) { throw new EntityProviderException(EntityProviderException.COMMON, e); } }
Example #2
Source File: JsonPropertyDeserializerTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void simplePropertyWithStringToLongMappingStandalone() throws Exception { String simplePropertyJson = "{\"d\":{\"Age\":67}}"; JsonReader reader = prepareReader(simplePropertyJson); final EdmProperty edmProperty = (EdmProperty) MockFacade.getMockEdm().getEntityType("RefScenario", "Employee").getProperty("Age"); DeserializerProperties readProperties = mock(DeserializerProperties.class); Map<String, Object> typeMappings = new HashMap<String, Object>(); typeMappings.put("Age", Integer.class); when(readProperties.getTypeMappings()).thenReturn(typeMappings); Map<String, Object> resultMap = new JsonPropertyDeserializer().readPropertyStandalone(reader, edmProperty, readProperties); assertEquals(Integer.valueOf(67), resultMap.get("Age")); }
Example #3
Source File: JPQLBuilderFactoryTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
private GetEntityUriInfo getEntityUriInfo() throws EdmException { GetEntityUriInfo getEntityView = EasyMock.createMock(GetEntityUriInfo.class); EdmEntitySet edmEntitySet = EasyMock.createMock(EdmEntitySet.class); EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class); EasyMock.expect(edmEntityType.getKeyProperties()).andStubReturn(new ArrayList<EdmProperty>()); EasyMock.expect(edmEntityType.getMapping()).andStubReturn(null); EasyMock.expect(edmEntityType.getName()).andStubReturn(""); EasyMock.expect(edmEntitySet.getEntityType()).andStubReturn(edmEntityType); EasyMock.expect(getEntityView.getSelect()).andStubReturn(null); EasyMock.expect(getEntityView.getTargetEntitySet()).andStubReturn(edmEntitySet); EdmEntitySet startEdmEntitySet = EasyMock.createMock(EdmEntitySet.class); EdmEntityType startEdmEntityType = EasyMock.createMock(EdmEntityType.class); EasyMock.expect(startEdmEntityType.getMapping()).andStubReturn(null); EasyMock.expect(startEdmEntityType.getName()).andStubReturn("SOHeader"); EasyMock.expect(startEdmEntitySet.getEntityType()).andStubReturn(startEdmEntityType); EasyMock.expect(getEntityView.getStartEntitySet()).andStubReturn(startEdmEntitySet); EasyMock.replay(startEdmEntityType, startEdmEntitySet); EasyMock.replay(edmEntityType, edmEntitySet); EasyMock.expect(getEntityView.getKeyPredicates()).andStubReturn(new ArrayList<KeyPredicate>()); List<NavigationSegment> navigationSegments = new ArrayList<NavigationSegment>(); EasyMock.expect(getEntityView.getNavigationSegments()).andStubReturn(navigationSegments); EasyMock.replay(getEntityView); return getEntityView; }
Example #4
Source File: EdmURIBuilderImpl.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Override public EdmURIBuilder appendPropertySegment(EdmProperty property, String segmentValue) { switch (state) { case INITIAL: case SIMPLEPROPERTY: case NAVIGATION_TO_ONE: case ENTITYSET: case NAVIGATION_TO_MANY: case FUNCTIONIMPORT_MANY: throw new RuntimeException("Can't specify a property at this position");//NOSONAR case COMPLEXPROPERTY: appendProperty(property, segmentValue); break; case ENTITY: appendProperty(property, segmentValue); break; case NAVIGATION_TO_MANY_WITH_KEY: case FUNCTIONIMPORT_WITH_KEY: case FUNCTIONIMPORT: appendProperty(property, segmentValue); break; default: throw new RuntimeException("Unkown state:" + state);//NOSONAR } return this; }
Example #5
Source File: JsonPropertyConsumerTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void veryLongStringStandalone() throws Exception { char[] chars = new char[32768]; Arrays.fill(chars, 0, 32768, 'a'); String propertyValue = new String(chars); String simplePropertyJson = "{\"d\":{\"Name\":\"" + propertyValue + "\"}}"; JsonReader reader = prepareReader(simplePropertyJson); final EdmProperty edmProperty = (EdmProperty) MockFacade.getMockEdm().getEntityType("RefScenario", "Room").getProperty("Name"); EntityProviderReadProperties readProperties = mock(EntityProviderReadProperties.class); when(readProperties.getTypeMappings()).thenReturn(null); Map<String, Object> resultMap = new JsonPropertyConsumer().readPropertyStandalone(reader, edmProperty, readProperties); assertEquals(propertyValue, resultMap.get("Name")); }
Example #6
Source File: JsonPropertyConsumerTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void deepComplexPropertyOnOpenReader() throws Exception { final String complexPropertyJson = "{\"__metadata\":{\"type\":\"RefScenario.c_Location\"}," + "\"City\":{\"__metadata\":{\"type\":\"RefScenario.c_City\"},\"PostalCode\":\"69124\"," + "\"CityName\":\"Heidelberg\"},\"Country\":\"Germany\"}"; JsonReader reader = prepareReader(complexPropertyJson); EdmProperty edmProperty = (EdmProperty) MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees").getEntityType() .getProperty("Location"); EntityComplexPropertyInfo entityPropertyInfo = (EntityComplexPropertyInfo) EntityInfoAggregator.create(edmProperty); JsonPropertyConsumer jpc = new JsonPropertyConsumer(); @SuppressWarnings("unchecked") Map<String, Object> result = (Map<String, Object>) jpc.readPropertyValue(reader, entityPropertyInfo, null, null); assertEquals(2, result.size()); assertEquals("Germany", result.get("Country")); @SuppressWarnings("unchecked") Map<String, Object> innerResult = (Map<String, Object>) result.get("City"); assertEquals(2, innerResult.size()); assertEquals("Heidelberg", innerResult.get("CityName")); assertEquals("69124", innerResult.get("PostalCode")); }
Example #7
Source File: EdmUriBuilderTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test(expected = RuntimeException.class) public void negTestUriWithFormat() throws EdmException { EdmEntitySet entitySet = edm.getDefaultEntityContainer().getEntitySet("Employees"); EdmComplexType complexType = edm.getComplexType("RefScenario", "c_Location"); EdmProperty property = (EdmProperty) complexType.getProperty("City"); EdmComplexType complexType1 = (EdmComplexType) property.getType(); EdmProperty property1 = (EdmProperty) complexType1.getProperty("CityName"); new EdmURIBuilderImpl(SERVICE_ROOT_URI). appendEntitySetSegment(entitySet). appendKeySegment((EdmProperty)entitySet.getEntityType().getProperty("EmployeeId"), "1"). appendPropertySegment((EdmProperty)entitySet.getEntityType().getProperty("Location"), "Location"). appendPropertySegment(property, "City"). appendPropertySegment(property1, "CityName"). appendValueSegment(). format("application/json"). build(); }
Example #8
Source File: EdmUriBuilderTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void testFunctionImportWithMultipleParamsWithCount() throws Exception { EdmFunctionImport functionImport = edm.getDefaultEntityContainer().getFunctionImport("BuildingSearch"); EdmEntitySet entitySet = edm.getDefaultEntityContainer().getEntitySet("Buildings"); EdmProperty property = (EdmProperty) entitySet.getEntityType().getProperty("Id"); EdmNavigationProperty navProperty = (EdmNavigationProperty) entitySet.getEntityType().getProperty("nb_Rooms"); Map<EdmParameter, Object> functionImportParams = new LinkedHashMap<EdmParameter, Object>(); EdmParameter param1 = edm.getDefaultEntityContainer().getFunctionImport("BuildingSearch").getParameter("q"); functionImportParams.put(param1, "1"); EdmParameter param2 = edm.getDefaultEntityContainer().getFunctionImport("BuildingSearch").getParameter("r"); functionImportParams.put(param2, 1); URI uri = new EdmURIBuilderImpl(SERVICE_ROOT_URI). appendFunctionImportSegment(functionImport).appendKeySegment(property, "1"). appendNavigationSegment(navProperty). appendCountSegment(). appendFunctionImportParameters(functionImportParams).build(); assertNotNull(uri); assertEquals("http://host:80/service/BuildingSearch('1')/nb_Rooms/$count?q='1'&r=1", uri.toASCIIString()); }
Example #9
Source File: ODataJPAResponseBuilderTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
private List<EdmProperty> getKeyProperties() { List<EdmProperty> edmProperties = new ArrayList<EdmProperty>(); EdmType edmType = EasyMock.createMock(EdmType.class); EasyMock.expect(edmType.getKind()).andStubReturn(EdmTypeKind.SIMPLE); EasyMock.replay(edmType); EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class); EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class); EasyMock.expect(edmMapping.getInternalName()).andStubReturn("soId"); EasyMock.replay(edmMapping); try { EasyMock.expect(edmProperty.getName()).andStubReturn("ID"); EasyMock.expect(edmProperty.getType()).andStubReturn(edmType); EasyMock.expect(edmProperty.getMapping()).andStubReturn(edmMapping); EasyMock.replay(edmProperty); } catch (EdmException e) { fail("There is an exception is mocking some object " + e.getMessage()); } edmProperties.add(edmProperty); return edmProperties; }
Example #10
Source File: EdmMock.java From olingo-odata2 with Apache License 2.0 | 6 votes |
private static EdmEntityType createEntityTypeMock(final String name, final EdmSimpleTypeKind kind, final String keyPropertyId) throws EdmException { EdmEntityType entityType = mock(EdmEntityType.class); when(entityType.getName()).thenReturn(name); when(entityType.getNamespace()).thenReturn("RefScenario"); final EdmProperty keyProperty = createProperty(keyPropertyId, kind, entityType); EdmFacets facets = mock(EdmFacets.class); when(facets.getMaxLength()).thenReturn(null); when(facets.isNullable()).thenReturn(false); when(keyProperty.getFacets()).thenReturn(facets); when(entityType.getKind()).thenReturn(EdmTypeKind.ENTITY); when(entityType.getPropertyNames()).thenReturn(Arrays.asList(keyPropertyId)); when(entityType.getKeyPropertyNames()).thenReturn(Arrays.asList(keyPropertyId)); when(entityType.getKeyProperties()).thenReturn(Arrays.asList(keyProperty)); return entityType; }
Example #11
Source File: XmlPropertyProducerTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void serializeAge() throws Exception { AtomEntityProvider s = createAtomEntityProvider(); EdmTyped edmTyped = MockFacade.getMockEdm().getEntityType("RefScenario", "Employee").getProperty("Age"); EdmProperty edmProperty = (EdmProperty) edmTyped; ODataResponse response = s.writeProperty(edmProperty, employeeData.get("Age")); assertNotNull(response); assertNotNull(response.getEntity()); String xml = StringHelper.inputStreamToString((InputStream) response.getEntity()); assertNotNull(xml); assertXpathExists("/d:Age", xml); assertXpathEvaluatesTo("52", "/d:Age/text()", xml); }
Example #12
Source File: JsonPropertyConsumerTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void simplePropertyWithStringToNullMappingStandalone() throws Exception { String simplePropertyJson = "{\"d\":{\"Age\":67}}"; JsonReader reader = prepareReader(simplePropertyJson); final EdmProperty edmProperty = (EdmProperty) MockFacade.getMockEdm().getEntityType("RefScenario", "Employee").getProperty("Age"); EntityProviderReadProperties readProperties = mock(EntityProviderReadProperties.class); Map<String, Object> typeMappings = new HashMap<String, Object>(); typeMappings.put("Age", null); when(readProperties.getTypeMappings()).thenReturn(typeMappings); Map<String, Object> resultMap = new JsonPropertyConsumer().readPropertyStandalone(reader, edmProperty, readProperties); assertEquals(Integer.valueOf(67), resultMap.get("Age")); }
Example #13
Source File: EdmUriBuilderTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void testFunctionImportWithPathSegmentsAndParams() throws Exception { EdmFunctionImport functionImport = edm.getDefaultEntityContainer().getFunctionImport("EmployeeSearch"); Map<EdmParameter, Object> functionImportParams = new HashMap<EdmParameter, Object>(); EdmParameter param = edm.getDefaultEntityContainer().getFunctionImport("EmployeeSearch").getParameter("q"); functionImportParams.put(param, "Emp1"); EdmEntitySet entitySet = edm.getDefaultEntityContainer().getEntitySet("Employees"); EdmProperty property = (EdmProperty) entitySet.getEntityType().getProperty("Location"); try { new EdmURIBuilderImpl(SERVICE_ROOT_URI). appendFunctionImportSegment(functionImport).appendPropertySegment(property, "Location"). appendFunctionImportParameters(functionImportParams).build(); } catch (RuntimeException e) { assertEquals("Can't specify a property at this position", e.getMessage()); } }
Example #14
Source File: ListsProcessor.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Override public ODataResponse readEntitySimplePropertyValue(final GetSimplePropertyUriInfo uriInfo, final String contentType) throws ODataException { Object data = retrieveData( uriInfo.getStartEntitySet(), uriInfo.getKeyPredicates(), uriInfo.getFunctionImport(), mapFunctionParameters(uriInfo.getFunctionImportParameters()), uriInfo.getNavigationSegments()); if (data == null) { throw new ODataNotFoundException(ODataNotFoundException.ENTITY); } final List<EdmProperty> propertyPath = uriInfo.getPropertyPath(); final EdmProperty property = propertyPath.get(propertyPath.size() - 1); final Object value = property.getMapping() == null || property.getMapping().getMediaResourceMimeTypeKey() == null ? getPropertyValue(data, propertyPath) : getSimpleTypeValueMap(data, propertyPath); return ODataResponse.fromResponse(EntityProvider.writePropertyValue(property, value)).eTag( constructETag(uriInfo.getTargetEntitySet(), data)).build(); }
Example #15
Source File: EdmEntityTypeImplProv.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Override public List<EdmProperty> getKeyProperties() throws EdmException { if (edmKeyProperties == null) { if (edmBaseType != null) { return ((EdmEntityType) edmBaseType).getKeyProperties(); } if (keyProperties == null) { keyProperties = new HashMap<String, EdmProperty>(); edmKeyProperties = new ArrayList<EdmProperty>(); for (String keyPropertyName : getKeyPropertyNames()) { final EdmTyped edmProperty = getProperty(keyPropertyName); if (edmProperty != null && edmProperty instanceof EdmProperty) { keyProperties.put(keyPropertyName, (EdmProperty) edmProperty); edmKeyProperties.add((EdmProperty) edmProperty); } else { throw new EdmException(EdmException.COMMON); } } } } return edmKeyProperties; }
Example #16
Source File: AtomEntryProducerTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void testExceptionWithNonNullablePropertyIsNull2() throws Exception { EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Organizations"); EdmProperty kindProperty = (EdmProperty) entitySet.getEntityType().getProperty("Kind"); EdmFacets facets = kindProperty.getFacets(); when(facets.isNullable()).thenReturn(new Boolean(false)); EdmProperty nameProperty = (EdmProperty) entitySet.getEntityType().getProperty("Name"); EdmFacets facets1 = nameProperty.getFacets(); when(facets1.isNullable()).thenReturn(new Boolean(false)); final EntityProviderWriteProperties properties = EntityProviderWriteProperties.serviceRoot(BASE_URI).omitETag(true). isDataBasedPropertySerialization(true).build(); AtomEntityProvider ser = createAtomEntityProvider(); Map<String, Object> orgData = new HashMap<String, Object>(); orgData.put("Id", "1"); orgData.put("Name", "Org1"); try { ser.writeEntry(entitySet, orgData, properties); } catch (EntityProviderProducerException e) { assertTrue(e.getMessage().contains("do not allow to format the value 'Org1' for property 'Name'.")); } }
Example #17
Source File: EdmxProviderTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void annotationsAtSimpleProperty() throws Exception { Edm edm = createEdm(); assertNotNull(edm); EdmProperty property = (EdmProperty) edm.getEntityType("Self", "Employee").getProperty("EmployeeName"); assertNotNull(property); EdmAnnotations annotations = property.getAnnotations(); assertNotNull(annotations); List<EdmAnnotationAttribute> annotationAttributes = annotations.getAnnotationAttributes(); assertNotNull(annotationAttributes); List<EdmAnnotationElement> annotationElements = annotations.getAnnotationElements(); assertNotNull(annotationElements); assertEquals(2, annotationElements.size()); assertNull(annotationElements.get(0).getChildElements()); }
Example #18
Source File: AtomEntryProducerTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void testKeepInContentNull() throws Exception { AtomEntityProvider ser = createAtomEntityProvider(); EdmEntitySet entitySet = MockFacade.getMockEdm().getEntityContainer("Container2").getEntitySet("Photos"); EdmProperty customProperty = (EdmProperty) entitySet.getEntityType().getProperty("CustomProperty"); when(customProperty.getCustomizableFeedMappings().isFcKeepInContent()).thenReturn(null); ODataResponse response = ser.writeEntry(entitySet, photoData, DEFAULT_PROPERTIES); String xmlString = verifyResponse(response); assertXpathExists("/a:entry", xmlString); assertXpathExists("/a:entry/custom:CustomProperty", xmlString); assertXpathNotExists("/a:entry/custom:CustomProperty/text()", xmlString); assertXpathEvaluatesTo("true", "/a:entry/custom:CustomProperty/@m:null", xmlString); assertXpathExists("/a:entry/m:properties/d:CustomProperty", xmlString); verifyTagOrdering(xmlString, "category", "Содержание", "CustomProperty", "content", "properties"); }
Example #19
Source File: JsonPropertyConsumerTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void complexPropertyOnOpenReader() throws Exception { final String complexPropertyJson = "{\"__metadata\":{\"type\":\"RefScenario.c_City\"},\"PostalCode\":\"69124\",\"CityName\":\"Heidelberg\"}"; JsonReader reader = prepareReader(complexPropertyJson); final EdmProperty property = (EdmProperty) MockFacade.getMockEdm().getComplexType("RefScenario", "c_Location").getProperty("City"); EntityComplexPropertyInfo entityPropertyInfo = (EntityComplexPropertyInfo) EntityInfoAggregator.create(property); JsonPropertyConsumer jpc = new JsonPropertyConsumer(); @SuppressWarnings("unchecked") Map<String, Object> result = (Map<String, Object>) jpc.readPropertyValue(reader, entityPropertyInfo, null, null); assertEquals(2, result.size()); assertEquals("Heidelberg", result.get("CityName")); assertEquals("69124", result.get("PostalCode")); }
Example #20
Source File: XmlPropertyConsumerTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test(expected = EntityProviderException.class) public void readComplexPropertyWithInvalidName() throws Exception { String xml = "<Invalid xmlns=\"" + Edm.NAMESPACE_D_2007_08 + "\"" + " xmlns:m=\"" + Edm.NAMESPACE_M_2007_08 + "\" m:type=\"RefScenario.c_Location\">" + "<Country>Germany</Country>" + "<City m:type=\"RefScenario.c_City\">" + "<PostalCode>69124</PostalCode>" + "<CityName>Heidelberg</CityName>" + "</City>" + "</Invalid>"; XMLStreamReader reader = createReaderForTest(xml, true); final EdmProperty property = (EdmProperty) MockFacade.getMockEdm().getEntityType("RefScenario", "Employee").getProperty("Location"); new XmlPropertyConsumer().readProperty(reader, property, null); }
Example #21
Source File: JsonPropertyConsumerTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void complexPropertyWithStringToStringMappingStandalone() throws Exception { final String complexPropertyJson = "{\"d\":{\"City\":{\"__metadata\":{\"type\":\"RefScenario.c_City\"}," + "\"PostalCode\":\"69124\",\"CityName\":\"Heidelberg\"}}}"; JsonReader reader = prepareReader(complexPropertyJson); final EdmProperty property = (EdmProperty) MockFacade.getMockEdm().getComplexType("RefScenario", "c_Location").getProperty("City"); EntityProviderReadProperties readProperties = mock(EntityProviderReadProperties.class); Map<String, Object> innerMappings = new HashMap<String, Object>(); innerMappings.put("PostalCode", String.class); Map<String, Object> typeMappings = new HashMap<String, Object>(); typeMappings.put("City", innerMappings); when(readProperties.getTypeMappings()).thenReturn(typeMappings); Map<String, Object> result = new JsonPropertyConsumer().readPropertyStandalone(reader, property, readProperties); assertEquals(1, result.size()); @SuppressWarnings("unchecked") Map<String, Object> innerResult = (Map<String, Object>) result.get("City"); assertEquals("Heidelberg", innerResult.get("CityName")); assertEquals("69124", innerResult.get("PostalCode")); }
Example #22
Source File: ODataExpressionParser.java From olingo-odata2 with Apache License 2.0 | 6 votes |
private static String getPropertyName(final CommonExpression whereExpression) throws EdmException, ODataJPARuntimeException { EdmTyped edmProperty = ((PropertyExpression) whereExpression).getEdmProperty(); EdmMapping mapping; if (edmProperty instanceof EdmNavigationProperty) { EdmNavigationProperty edmNavigationProperty = (EdmNavigationProperty) edmProperty; mapping = edmNavigationProperty.getMapping(); } else if(edmProperty instanceof EdmProperty) { EdmProperty property = (EdmProperty) edmProperty; mapping = property.getMapping(); } else { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL, null); } return mapping != null ? mapping.getInternalName() : edmProperty.getName(); }
Example #23
Source File: XmlPropertyConsumerTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void complexPropertyNullValueNotAllowedButNotValidated() throws Exception { final String xml = "<Location xmlns=\"" + Edm.NAMESPACE_D_2007_08 + "\" m:null=\"true\" xmlns:m=\"" + Edm.NAMESPACE_M_2007_08 + "\" />"; EdmProperty property = (EdmProperty) MockFacade.getMockEdm().getEntityType("RefScenario", "Employee") .getProperty("Location"); EdmFacets facets = mock(EdmFacets.class); when(facets.isNullable()).thenReturn(false); when(property.getFacets()).thenReturn(facets); final EntityProviderReadProperties readProperties = mock(EntityProviderReadProperties.class); final Map<String, Object> resultMap = new XmlPropertyConsumer() .readProperty(createReaderForTest(xml, true), property, readProperties); assertFalse(resultMap.isEmpty()); assertNull(resultMap.get("Location")); }
Example #24
Source File: JsonEntryEntitySerializerTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void testExceptionWithNonNullablePropertyIsNull2() throws Exception { EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Organizations"); EdmProperty kindProperty = (EdmProperty) entitySet.getEntityType().getProperty("Kind"); EdmFacets facets = kindProperty.getFacets(); when(facets.isNullable()).thenReturn(new Boolean(false)); EdmProperty nameProperty = (EdmProperty) entitySet.getEntityType().getProperty("Name"); EdmFacets facets1 = nameProperty.getFacets(); when(facets1.isNullable()).thenReturn(new Boolean(false)); Entity orgData = new Entity(); orgData.addProperty("Id", "1"); orgData.addProperty("Name", "Org1"); orgData.setWriteProperties( EntitySerializerProperties.serviceRoot(URI.create(BASE_URI)).build()); try { new JsonSerializerDeserializer().writeEntry(entitySet, orgData); } catch (EntityProviderProducerException e) { assertTrue(e.getMessage().contains("do not allow to format the value 'Org1' for property 'Name'.")); } }
Example #25
Source File: JsonEntryEntitySerializerTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Test(expected = EntityProviderException.class) public void entryWithExpandedEntryWithFacets() 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.addProperty("Version", new Integer(3)); Entity employeeData = new Entity(); employeeData.addProperty("EmployeeId", "1"); employeeData.addProperty("ImageUrl", "hhtp://url"); employeeData.setWriteProperties(EntitySerializerProperties.serviceRoot(URI.create(BASE_URI)) .validatingFacets(true).build()); roomData.addNavigation("nr_Employees", employeeData); roomData.setWriteProperties(EntitySerializerProperties.serviceRoot(URI.create(BASE_URI)) .build()); EdmEntitySet entitySet = edm.getDefaultEntityContainer().getEntitySet("Rooms"); final ODataResponse response = new JsonSerializerDeserializer().writeEntry(entitySet, roomData); assertNotNull(response); }
Example #26
Source File: BasicProviderTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Test public void writePropertyValue() throws Exception { EdmTyped edmTyped = MockFacade.getMockEdm().getEntityType("RefScenario", "Employee").getProperty("Age"); EdmProperty edmProperty = (EdmProperty) edmTyped; ODataResponse response = provider.writePropertyValue(edmProperty, employeeData.get("Age")); assertNotNull(response); assertNotNull(response.getEntity()); assertNull("BasicProvider should not set content header", response.getContentHeader()); String value = StringHelper.inputStreamToString((InputStream) response.getEntity()); assertEquals(employeeData.get("Age").toString(), value); }
Example #27
Source File: EdmUriBuilderTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Test(expected=RuntimeException.class) public void testUriWithSelectOnEntityWithTop() throws EdmException { EdmEntitySet entitySet = edm.getDefaultEntityContainer().getEntitySet("Managers"); new EdmURIBuilderImpl(SERVICE_ROOT_URI). appendEntitySetSegment(entitySet). appendKeySegment((EdmProperty)entitySet.getEntityType().getProperty("EmployeeId"), "1"). select("EmployeeId", "EmployeeName", "RoomId", "TeamId"). top(2). build(); }
Example #28
Source File: BeanPropertyAccessTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Test public void getPropertyType() throws ODataException { SimpleEntity data = new SimpleEntity(); data.name = "A Name"; EdmProperty property = mockProperty("Name"); Class<?> type = ava.getPropertyType(data, property); Assert.assertEquals(String.class, type); }
Example #29
Source File: EdmUriBuilderTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Test(expected=RuntimeException.class) public void negTest1UriWithNavigationSegment() 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")). appendNavigationSegment((EdmNavigationProperty)employeeEntitySet.getEntityType().getProperty("ne_Team")). build(); }
Example #30
Source File: JsonFeedEntitySerializerTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Test public void unbalancedPropertyEntryWithoutKeyWithInlineFeed() 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("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", "2"); 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); final String json = verifyResponse(response); assertEquals("{\"Name\":\"Neu Schwanstein\",\"Seats\":20,\"nr_Employees\":" + "[{\"EmployeeId\":\"1\",\"EmployeeName\":\"EmpName1\",\"RoomId\":\"1\"}," + "{\"EmployeeId\":\"2\",\"RoomId\":\"1\"}]}", json); }