You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by sk...@apache.org on 2013/08/28 15:34:07 UTC
[03/43] source distribution
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c5b266a6/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/testutil/mock/EdmMock.java
----------------------------------------------------------------------
diff --git a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/testutil/mock/EdmMock.java b/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/testutil/mock/EdmMock.java
new file mode 100644
index 0000000..9ffe44a
--- /dev/null
+++ b/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/testutil/mock/EdmMock.java
@@ -0,0 +1,339 @@
+/*******************************************************************************
+ * 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.testutil.mock;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.Arrays;
+
+import org.mockito.Mockito;
+
+import org.apache.olingo.odata2.api.commons.ODataHttpMethod;
+import org.apache.olingo.odata2.api.edm.Edm;
+import org.apache.olingo.odata2.api.edm.EdmComplexType;
+import org.apache.olingo.odata2.api.edm.EdmConcurrencyMode;
+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.EdmMapping;
+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.EdmServiceMetadata;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+import org.apache.olingo.odata2.api.edm.EdmStructuralType;
+import org.apache.olingo.odata2.api.edm.EdmTargetPath;
+import org.apache.olingo.odata2.api.edm.EdmType;
+import org.apache.olingo.odata2.api.edm.EdmTypeKind;
+import org.apache.olingo.odata2.api.edm.EdmTyped;
+import org.apache.olingo.odata2.api.edm.provider.CustomizableFeedMappings;
+import org.apache.olingo.odata2.api.exception.ODataException;
+
+/**
+ * Mocked Entity Data Model, more or less aligned to the Reference Scenario.
+ *
+ */
+class EdmMock {
+
+ public static Edm createMockEdm() throws ODataException {
+ EdmEntityContainer defaultContainer = mock(EdmEntityContainer.class);
+ when(defaultContainer.isDefaultEntityContainer()).thenReturn(true);
+
+ final EdmEntitySet employeeEntitySet = createEntitySetMock(defaultContainer, "Employees", EdmSimpleTypeKind.String, "EmployeeId");
+ final EdmEntitySet teamEntitySet = createEntitySetMock(defaultContainer, "Teams", EdmSimpleTypeKind.String, "Id");
+ final EdmEntitySet roomEntitySet = createEntitySetMock(defaultContainer, "Rooms", EdmSimpleTypeKind.String, "Id");
+ final EdmEntitySet managerEntitySet = createEntitySetMock(defaultContainer, "Managers", EdmSimpleTypeKind.String, "EmployeeId");
+ final EdmEntitySet buildingEntitySet = createEntitySetMock(defaultContainer, "Buildings", EdmSimpleTypeKind.String, "Id");
+
+ EdmEntityType employeeType = employeeEntitySet.getEntityType();
+ when(employeeType.hasStream()).thenReturn(true);
+ EdmMapping employeeTypeMapping = Mockito.mock(EdmMapping.class);
+ when(employeeTypeMapping.getMimeType()).thenReturn("getImageType");
+ when(employeeType.getMapping()).thenReturn(employeeTypeMapping);
+ when(employeeType.getPropertyNames()).thenReturn(Arrays.asList(
+ "EmployeeId", "EmployeeName", "ManagerId", "RoomId", "TeamId",
+ "Location", "Age", "EntryDate", "ImageUrl"));
+ when(employeeType.getNavigationPropertyNames()).thenReturn(Arrays.asList("ne_Manager", "ne_Team", "ne_Room"));
+
+ EdmProperty employeeNameProperty = createProperty("EmployeeName", EdmSimpleTypeKind.String, employeeType);
+ EdmCustomizableFeedMappings employeeTitleMappings = mock(EdmCustomizableFeedMappings.class);
+ when(employeeTitleMappings.getFcTargetPath()).thenReturn(EdmTargetPath.SYNDICATION_TITLE);
+ when(employeeTitleMappings.isFcKeepInContent()).thenReturn(true);
+ when(employeeNameProperty.getCustomizableFeedMappings()).thenReturn(employeeTitleMappings);
+
+ createProperty("ManagerId", EdmSimpleTypeKind.String, employeeType);
+ createProperty("RoomId", EdmSimpleTypeKind.String, employeeType);
+ createProperty("TeamId", EdmSimpleTypeKind.String, employeeType);
+ createProperty("Age", EdmSimpleTypeKind.Int32, employeeType);
+
+ EdmProperty employeeEntryDateProperty = createProperty("EntryDate", EdmSimpleTypeKind.DateTime, employeeType);
+ EdmCustomizableFeedMappings employeeUpdatedMappings = mock(EdmCustomizableFeedMappings.class);
+ when(employeeUpdatedMappings.getFcTargetPath()).thenReturn(EdmTargetPath.SYNDICATION_UPDATED);
+ when(employeeUpdatedMappings.isFcKeepInContent()).thenReturn(true);
+ when(employeeEntryDateProperty.getCustomizableFeedMappings()).thenReturn(employeeUpdatedMappings);
+ EdmFacets employeeEntryDateFacets = mock(EdmFacets.class);
+ when(employeeEntryDateFacets.getMaxLength()).thenReturn(null);
+ when(employeeEntryDateFacets.isNullable()).thenReturn(Boolean.TRUE);
+ when(employeeEntryDateProperty.getFacets()).thenReturn(employeeEntryDateFacets);
+
+ createProperty("ImageUrl", EdmSimpleTypeKind.String, employeeType);
+
+ final EdmComplexType locationComplexType = mock(EdmComplexType.class);
+ when(locationComplexType.getKind()).thenReturn(EdmTypeKind.COMPLEX);
+ when(locationComplexType.getName()).thenReturn("c_Location");
+ when(locationComplexType.getNamespace()).thenReturn("RefScenario");
+ when(locationComplexType.getPropertyNames()).thenReturn(Arrays.asList("City", "Country"));
+
+ final EdmProperty locationComplexProperty = mock(EdmProperty.class);
+ when(locationComplexProperty.getType()).thenReturn(locationComplexType);
+ when(locationComplexProperty.getName()).thenReturn("Location");
+ when(employeeType.getProperty("Location")).thenReturn(locationComplexProperty);
+ createProperty("Country", EdmSimpleTypeKind.String, locationComplexType);
+
+ final EdmComplexType cityComplexType = mock(EdmComplexType.class);
+ when(cityComplexType.getKind()).thenReturn(EdmTypeKind.COMPLEX);
+ when(cityComplexType.getName()).thenReturn("c_City");
+ when(cityComplexType.getNamespace()).thenReturn("RefScenario");
+ when(cityComplexType.getPropertyNames()).thenReturn(Arrays.asList("PostalCode", "CityName"));
+
+ EdmProperty cityProperty = mock(EdmProperty.class);
+ when(cityProperty.getType()).thenReturn(cityComplexType);
+ when(cityProperty.getName()).thenReturn("City");
+ when(locationComplexType.getProperty("City")).thenReturn(cityProperty);
+
+ createProperty("PostalCode", EdmSimpleTypeKind.String, cityComplexType);
+ createProperty("CityName", EdmSimpleTypeKind.String, cityComplexType);
+
+ createNavigationProperty("ne_Manager", EdmMultiplicity.ONE, employeeEntitySet, managerEntitySet);
+ createNavigationProperty("ne_Team", EdmMultiplicity.ONE, employeeEntitySet, teamEntitySet);
+ createNavigationProperty("ne_Room", EdmMultiplicity.ONE, employeeEntitySet, roomEntitySet);
+
+ EdmEntityType teamType = teamEntitySet.getEntityType();
+ when(teamType.getPropertyNames()).thenReturn(Arrays.asList("Id", "Name", "isScrumTeam"));
+ createProperty("Name", EdmSimpleTypeKind.String, teamType);
+ createProperty("isScrumTeam", EdmSimpleTypeKind.Boolean, teamType);
+ when(teamType.getNavigationPropertyNames()).thenReturn(Arrays.asList("nt_Employees"));
+ createNavigationProperty("nt_Employees", EdmMultiplicity.MANY, teamEntitySet, employeeEntitySet);
+
+ EdmEntityType roomType = roomEntitySet.getEntityType();
+ when(roomType.getPropertyNames()).thenReturn(Arrays.asList("Id", "Name", "Seats", "Version"));
+ EdmProperty roomId = roomEntitySet.getEntityType().getKeyProperties().get(0);
+ EdmFacets roomIdFacets = mock(EdmFacets.class);
+ when(roomIdFacets.getMaxLength()).thenReturn(100);
+ when(roomId.getFacets()).thenReturn(roomIdFacets);
+ createProperty("Name", EdmSimpleTypeKind.String, roomType);
+ createProperty("Seats", EdmSimpleTypeKind.Int16, roomType);
+ EdmProperty roomVersion = createProperty("Version", EdmSimpleTypeKind.Int16, roomType);
+ EdmFacets roomVersionFacets = mock(EdmFacets.class);
+ when(roomVersionFacets.getConcurrencyMode()).thenReturn(EdmConcurrencyMode.Fixed);
+ when(roomVersionFacets.isNullable()).thenReturn(null);
+ when(roomVersion.getFacets()).thenReturn(roomVersionFacets);
+ when(roomType.getNavigationPropertyNames()).thenReturn(Arrays.asList("nr_Employees", "nr_Building"));
+ createNavigationProperty("nr_Employees", EdmMultiplicity.MANY, roomEntitySet, employeeEntitySet);
+ createNavigationProperty("nr_Building", EdmMultiplicity.ONE, roomEntitySet, buildingEntitySet);
+
+ createNavigationProperty("ne_Manager", EdmMultiplicity.ONE, managerEntitySet, managerEntitySet);
+ createNavigationProperty("ne_Team", EdmMultiplicity.ONE, managerEntitySet, teamEntitySet);
+ createNavigationProperty("ne_Room", EdmMultiplicity.ONE, managerEntitySet, roomEntitySet);
+ createNavigationProperty("nm_Employees", EdmMultiplicity.MANY, managerEntitySet, employeeEntitySet);
+
+ EdmEntityType buildingType = buildingEntitySet.getEntityType();
+ when(buildingType.getPropertyNames()).thenReturn(Arrays.asList("Id", "Name", "Image"));
+ createProperty("Name", EdmSimpleTypeKind.String, buildingType);
+ createProperty("Image", EdmSimpleTypeKind.Binary, buildingType);
+ when(buildingType.getNavigationPropertyNames()).thenReturn(Arrays.asList("nb_Rooms"));
+ createNavigationProperty("nb_Rooms", EdmMultiplicity.MANY, buildingEntitySet, roomEntitySet);
+
+ EdmFunctionImport employeeSearchFunctionImport = createFunctionImportMock(defaultContainer, "EmployeeSearch", employeeType, EdmMultiplicity.MANY);
+ when(employeeSearchFunctionImport.getEntitySet()).thenReturn(employeeEntitySet);
+ EdmParameter employeeSearchParameter = mock(EdmParameter.class);
+ when(employeeSearchParameter.getType()).thenReturn(EdmSimpleTypeKind.String.getEdmSimpleTypeInstance());
+ when(employeeSearchFunctionImport.getParameterNames()).thenReturn(Arrays.asList("q"));
+ when(employeeSearchFunctionImport.getParameter("q")).thenReturn(employeeSearchParameter);
+ createFunctionImportMock(defaultContainer, "AllLocations", locationComplexType, EdmMultiplicity.MANY);
+ createFunctionImportMock(defaultContainer, "AllUsedRoomIds", EdmSimpleTypeKind.String.getEdmSimpleTypeInstance(), EdmMultiplicity.MANY);
+ createFunctionImportMock(defaultContainer, "MaximalAge", EdmSimpleTypeKind.Int16.getEdmSimpleTypeInstance(), EdmMultiplicity.ONE);
+ createFunctionImportMock(defaultContainer, "MostCommonLocation", locationComplexType, EdmMultiplicity.ONE);
+ EdmFunctionImport managerPhotoFunctionImport = createFunctionImportMock(defaultContainer, "ManagerPhoto", EdmSimpleTypeKind.Binary.getEdmSimpleTypeInstance(), EdmMultiplicity.ONE);
+ EdmParameter managerPhotoParameter = mock(EdmParameter.class);
+ when(managerPhotoParameter.getType()).thenReturn(EdmSimpleTypeKind.String.getEdmSimpleTypeInstance());
+ EdmFacets managerPhotoParameterFacets = mock(EdmFacets.class);
+ when(managerPhotoParameterFacets.isNullable()).thenReturn(false);
+ when(managerPhotoParameter.getFacets()).thenReturn(managerPhotoParameterFacets);
+ when(managerPhotoFunctionImport.getParameterNames()).thenReturn(Arrays.asList("Id"));
+ when(managerPhotoFunctionImport.getParameter("Id")).thenReturn(managerPhotoParameter);
+ EdmFunctionImport oldestEmployeeFunctionImport = createFunctionImportMock(defaultContainer, "OldestEmployee", employeeType, EdmMultiplicity.ONE);
+ when(oldestEmployeeFunctionImport.getEntitySet()).thenReturn(employeeEntitySet);
+
+ EdmEntityContainer specificContainer = mock(EdmEntityContainer.class);
+ when(specificContainer.getEntitySet("Employees")).thenReturn(employeeEntitySet);
+ when(specificContainer.getName()).thenReturn("Container1");
+
+ EdmEntityType photoEntityType = mock(EdmEntityType.class);
+ when(photoEntityType.getName()).thenReturn("Photo");
+ when(photoEntityType.getNamespace()).thenReturn("RefScenario2");
+ when(photoEntityType.getPropertyNames()).thenReturn(Arrays.asList(
+ "Id", "Name", "Type", "Image", "BinaryData", "Содержание", "CustomProperty"));
+ when(photoEntityType.getKeyPropertyNames()).thenReturn(Arrays.asList("Id", "Type"));
+ when(photoEntityType.hasStream()).thenReturn(true);
+ EdmMapping photoEntityTypeMapping = Mockito.mock(EdmMapping.class);
+ when(photoEntityTypeMapping.getMimeType()).thenReturn("getType");
+ when(photoEntityType.getMapping()).thenReturn(photoEntityTypeMapping);
+ EdmProperty photoIdProperty = createProperty("Id", EdmSimpleTypeKind.Int32, photoEntityType);
+ EdmFacets photoIdFacet = mock(EdmFacets.class);
+ when(photoIdFacet.getConcurrencyMode()).thenReturn(EdmConcurrencyMode.Fixed);
+ when(photoIdProperty.getFacets()).thenReturn(photoIdFacet);
+
+ createProperty("Name", EdmSimpleTypeKind.String, photoEntityType);
+ final EdmProperty photoTypeProperty = createProperty("Type", EdmSimpleTypeKind.String, photoEntityType);
+ when(photoEntityType.getKeyProperties()).thenReturn(Arrays.asList(photoIdProperty, photoTypeProperty));
+
+ EdmProperty photoImageProperty = createProperty("Image", EdmSimpleTypeKind.Binary, photoEntityType);
+ EdmMapping imageMapping = mock(EdmMapping.class);
+ when(imageMapping.getMimeType()).thenReturn("getImageType");
+ when(photoImageProperty.getMapping()).thenReturn(imageMapping);
+
+ EdmProperty binaryDataProperty = createProperty("BinaryData", EdmSimpleTypeKind.Binary, photoEntityType);
+ when(binaryDataProperty.getMimeType()).thenReturn("image/jpeg");
+
+ EdmProperty photoRussianProperty = createProperty("Содержание", EdmSimpleTypeKind.String, photoEntityType);
+ EdmFacets photoRussianFacets = mock(EdmFacets.class);
+ when(photoRussianFacets.isNullable()).thenReturn(true);
+ when(photoRussianFacets.isUnicode()).thenReturn(true);
+ when(photoRussianFacets.getMaxLength()).thenReturn(Integer.MAX_VALUE);
+ when(photoRussianProperty.getFacets()).thenReturn(photoRussianFacets);
+ CustomizableFeedMappings photoRussianMapping = mock(CustomizableFeedMappings.class);
+ when(photoRussianMapping.getFcKeepInContent()).thenReturn(false);
+ when(photoRussianMapping.getFcNsPrefix()).thenReturn("ру");
+ when(photoRussianMapping.getFcNsUri()).thenReturn("http://localhost");
+ when(photoRussianMapping.getFcTargetPath()).thenReturn("Содержание");
+ when(photoRussianProperty.getCustomizableFeedMappings()).thenReturn(photoRussianMapping);
+
+ EdmProperty customProperty = createProperty("CustomProperty", EdmSimpleTypeKind.String, photoEntityType);
+ CustomizableFeedMappings customFeedMapping = mock(CustomizableFeedMappings.class);
+ when(customFeedMapping.getFcKeepInContent()).thenReturn(false);
+ when(customFeedMapping.getFcNsPrefix()).thenReturn("custom");
+ when(customFeedMapping.getFcNsUri()).thenReturn("http://localhost");
+ when(customFeedMapping.getFcTargetPath()).thenReturn("TarPath");
+ when(customProperty.getCustomizableFeedMappings()).thenReturn(customFeedMapping);
+
+ EdmEntitySet photoEntitySet = mock(EdmEntitySet.class);
+ when(photoEntitySet.getName()).thenReturn("Photos");
+ when(photoEntitySet.getEntityType()).thenReturn(photoEntityType);
+ EdmEntityContainer photoContainer = mock(EdmEntityContainer.class);
+ when(photoContainer.isDefaultEntityContainer()).thenReturn(false);
+ when(photoContainer.getEntitySet("Photos")).thenReturn(photoEntitySet);
+ when(photoContainer.getName()).thenReturn("Container2");
+
+ when(photoEntitySet.getEntityContainer()).thenReturn(photoContainer);
+
+ Edm edm = mock(Edm.class);
+ EdmServiceMetadata serviceMetadata = mock(EdmServiceMetadata.class);
+ when(serviceMetadata.getDataServiceVersion()).thenReturn("MockEdm");
+ when(edm.getServiceMetadata()).thenReturn(serviceMetadata);
+ when(edm.getDefaultEntityContainer()).thenReturn(defaultContainer);
+ when(edm.getEntityContainer("Container1")).thenReturn(specificContainer);
+ when(edm.getEntityContainer("Container2")).thenReturn(photoContainer);
+ when(edm.getEntityType("RefScenario", "Employee")).thenReturn(employeeType);
+ when(edm.getEntityType("RefScenario", "Team")).thenReturn(teamType);
+ when(edm.getEntityType("RefScenario", "Room")).thenReturn(roomType);
+ when(edm.getEntityType("RefScenario", "Building")).thenReturn(buildingType);
+ when(edm.getComplexType("RefScenario", "c_Location")).thenReturn(locationComplexType);
+ when(edm.getEntityType("RefScenario2", "Photo")).thenReturn(photoEntityType);
+
+ return edm;
+ }
+
+ private static EdmNavigationProperty createNavigationProperty(final String name, final EdmMultiplicity multiplicity, final EdmEntitySet entitySet, final EdmEntitySet targetEntitySet) throws EdmException {
+ EdmType navigationType = mock(EdmType.class);
+ when(navigationType.getKind()).thenReturn(EdmTypeKind.ENTITY);
+
+ EdmNavigationProperty navigationProperty = mock(EdmNavigationProperty.class);
+ when(navigationProperty.getName()).thenReturn(name);
+ when(navigationProperty.getType()).thenReturn(navigationType);
+ when(navigationProperty.getMultiplicity()).thenReturn(multiplicity);
+
+ when(entitySet.getEntityType().getProperty(name)).thenReturn(navigationProperty);
+ when(entitySet.getRelatedEntitySet(navigationProperty)).thenReturn(targetEntitySet);
+
+ return navigationProperty;
+ }
+
+ private static EdmProperty createProperty(final String name, final EdmSimpleTypeKind kind, final EdmStructuralType entityType) throws EdmException {
+ EdmProperty property = mock(EdmProperty.class);
+ when(property.getType()).thenReturn(kind.getEdmSimpleTypeInstance());
+ when(property.getName()).thenReturn(name);
+ when(entityType.getProperty(name)).thenReturn(property);
+ return property;
+ }
+
+ private static EdmEntitySet createEntitySetMock(final EdmEntityContainer container, final String name, final EdmSimpleTypeKind kind, final String keyPropertyId) throws EdmException {
+ final EdmEntityType entityType = createEntityTypeMock(name.substring(0, name.length() - 1), kind, keyPropertyId);
+
+ EdmEntitySet entitySet = mock(EdmEntitySet.class);
+ when(entitySet.getName()).thenReturn(name);
+ when(entitySet.getEntityType()).thenReturn(entityType);
+
+ when(entitySet.getEntityContainer()).thenReturn(container);
+
+ when(container.getEntitySet(name)).thenReturn(entitySet);
+
+ return entitySet;
+ }
+
+ 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;
+ }
+
+ private static EdmFunctionImport createFunctionImportMock(final EdmEntityContainer container, final String name, final EdmType type, final EdmMultiplicity multiplicity) throws EdmException {
+ EdmTyped returnType = mock(EdmTyped.class);
+ when(returnType.getType()).thenReturn(type);
+ when(returnType.getMultiplicity()).thenReturn(multiplicity);
+
+ EdmFunctionImport functionImport = mock(EdmFunctionImport.class);
+ when(functionImport.getName()).thenReturn(name);
+ when(functionImport.getReturnType()).thenReturn(returnType);
+ when(functionImport.getHttpMethod()).thenReturn(ODataHttpMethod.GET.name());
+
+ when(container.getFunctionImport(name)).thenReturn(functionImport);
+
+ return functionImport;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c5b266a6/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/testutil/mock/EdmTestProvider.java
----------------------------------------------------------------------
diff --git a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/testutil/mock/EdmTestProvider.java b/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/testutil/mock/EdmTestProvider.java
new file mode 100644
index 0000000..5a4a82d
--- /dev/null
+++ b/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/testutil/mock/EdmTestProvider.java
@@ -0,0 +1,522 @@
+/*******************************************************************************
+ * 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.testutil.mock;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.edm.EdmConcurrencyMode;
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+import org.apache.olingo.odata2.api.edm.EdmTargetPath;
+import org.apache.olingo.odata2.api.edm.FullQualifiedName;
+import org.apache.olingo.odata2.api.edm.provider.AnnotationAttribute;
+import org.apache.olingo.odata2.api.edm.provider.AnnotationElement;
+import org.apache.olingo.odata2.api.edm.provider.Association;
+import org.apache.olingo.odata2.api.edm.provider.AssociationEnd;
+import org.apache.olingo.odata2.api.edm.provider.AssociationSet;
+import org.apache.olingo.odata2.api.edm.provider.AssociationSetEnd;
+import org.apache.olingo.odata2.api.edm.provider.ComplexProperty;
+import org.apache.olingo.odata2.api.edm.provider.ComplexType;
+import org.apache.olingo.odata2.api.edm.provider.CustomizableFeedMappings;
+import org.apache.olingo.odata2.api.edm.provider.EdmProvider;
+import org.apache.olingo.odata2.api.edm.provider.EntityContainer;
+import org.apache.olingo.odata2.api.edm.provider.EntityContainerInfo;
+import org.apache.olingo.odata2.api.edm.provider.EntitySet;
+import org.apache.olingo.odata2.api.edm.provider.EntityType;
+import org.apache.olingo.odata2.api.edm.provider.Facets;
+import org.apache.olingo.odata2.api.edm.provider.FunctionImport;
+import org.apache.olingo.odata2.api.edm.provider.FunctionImportParameter;
+import org.apache.olingo.odata2.api.edm.provider.Key;
+import org.apache.olingo.odata2.api.edm.provider.Mapping;
+import org.apache.olingo.odata2.api.edm.provider.NavigationProperty;
+import org.apache.olingo.odata2.api.edm.provider.Property;
+import org.apache.olingo.odata2.api.edm.provider.PropertyRef;
+import org.apache.olingo.odata2.api.edm.provider.ReferentialConstraint;
+import org.apache.olingo.odata2.api.edm.provider.ReferentialConstraintRole;
+import org.apache.olingo.odata2.api.edm.provider.ReturnType;
+import org.apache.olingo.odata2.api.edm.provider.Schema;
+import org.apache.olingo.odata2.api.edm.provider.SimpleProperty;
+import org.apache.olingo.odata2.api.exception.ODataException;
+
+public class EdmTestProvider extends EdmProvider {
+
+ public static final String NAMESPACE_1 = "RefScenario";
+ public static final String NAMESPACE_2 = "RefScenario2";
+
+ private static final FullQualifiedName ENTITY_TYPE_1_1 = new FullQualifiedName(NAMESPACE_1, "Employee");
+ private static final FullQualifiedName ENTITY_TYPE_1_BASE = new FullQualifiedName(NAMESPACE_1, "Base");
+ private static final FullQualifiedName ENTITY_TYPE_1_2 = new FullQualifiedName(NAMESPACE_1, "Team");
+ private static final FullQualifiedName ENTITY_TYPE_1_3 = new FullQualifiedName(NAMESPACE_1, "Room");
+ private static final FullQualifiedName ENTITY_TYPE_1_4 = new FullQualifiedName(NAMESPACE_1, "Manager");
+ private static final FullQualifiedName ENTITY_TYPE_1_5 = new FullQualifiedName(NAMESPACE_1, "Building");
+ private static final FullQualifiedName ENTITY_TYPE_2_1 = new FullQualifiedName(NAMESPACE_2, "Photo");
+
+ private static final FullQualifiedName COMPLEX_TYPE_1 = new FullQualifiedName(NAMESPACE_1, "c_Location");
+ private static final FullQualifiedName COMPLEX_TYPE_2 = new FullQualifiedName(NAMESPACE_1, "c_City");
+
+ private static final FullQualifiedName ASSOCIATION_1_1 = new FullQualifiedName(NAMESPACE_1, "ManagerEmployees");
+ private static final FullQualifiedName ASSOCIATION_1_2 = new FullQualifiedName(NAMESPACE_1, "TeamEmployees");
+ private static final FullQualifiedName ASSOCIATION_1_3 = new FullQualifiedName(NAMESPACE_1, "RoomEmployees");
+ private static final FullQualifiedName ASSOCIATION_1_4 = new FullQualifiedName(NAMESPACE_1, "BuildingRooms");
+
+ private static final String ROLE_1_1 = "r_Employees";
+ private static final String ROLE_1_2 = "r_Team";
+ private static final String ROLE_1_3 = "r_Room";
+ private static final String ROLE_1_4 = "r_Manager";
+ private static final String ROLE_1_5 = "r_Building";
+
+ private static final String ENTITY_CONTAINER_1 = "Container1";
+ private static final String ENTITY_CONTAINER_2 = "Container2";
+
+ private static final String ENTITY_SET_1_1 = "Employees";
+ private static final String ENTITY_SET_1_2 = "Teams";
+ private static final String ENTITY_SET_1_3 = "Rooms";
+ private static final String ENTITY_SET_1_4 = "Managers";
+ private static final String ENTITY_SET_1_5 = "Buildings";
+ private static final String ENTITY_SET_2_1 = "Photos";
+
+ private static final String FUNCTION_IMPORT_1 = "EmployeeSearch";
+ private static final String FUNCTION_IMPORT_2 = "AllLocations";
+ private static final String FUNCTION_IMPORT_3 = "AllUsedRoomIds";
+ private static final String FUNCTION_IMPORT_4 = "MaximalAge";
+ private static final String FUNCTION_IMPORT_5 = "MostCommonLocation";
+ private static final String FUNCTION_IMPORT_6 = "ManagerPhoto";
+ private static final String FUNCTION_IMPORT_7 = "OldestEmployee";
+
+ @Override
+ public List<Schema> getSchemas() throws ODataException {
+ final List<Schema> schemas = new ArrayList<Schema>();
+
+ Schema schema = new Schema();
+ schema.setNamespace(NAMESPACE_1);
+
+ final List<EntityType> entityTypes = new ArrayList<EntityType>();
+ entityTypes.add(getEntityType(ENTITY_TYPE_1_1));
+ entityTypes.add(getEntityType(ENTITY_TYPE_1_2));
+ entityTypes.add(getEntityType(ENTITY_TYPE_1_3));
+ entityTypes.add(getEntityType(ENTITY_TYPE_1_4));
+ entityTypes.add(getEntityType(ENTITY_TYPE_1_5));
+ entityTypes.add(getEntityType(ENTITY_TYPE_1_BASE));
+ schema.setEntityTypes(entityTypes);
+
+ final List<ComplexType> complexTypes = new ArrayList<ComplexType>();
+ complexTypes.add(getComplexType(COMPLEX_TYPE_1));
+ complexTypes.add(getComplexType(COMPLEX_TYPE_2));
+ schema.setComplexTypes(complexTypes);
+
+ final List<Association> associations = new ArrayList<Association>();
+ associations.add(getAssociation(ASSOCIATION_1_1));
+ associations.add(getAssociation(ASSOCIATION_1_2));
+ associations.add(getAssociation(ASSOCIATION_1_3));
+ associations.add(getAssociation(ASSOCIATION_1_4));
+ schema.setAssociations(associations);
+
+ EntityContainer entityContainer = new EntityContainer();
+ entityContainer.setName(ENTITY_CONTAINER_1).setDefaultEntityContainer(true);
+
+ final List<EntitySet> entitySets = new ArrayList<EntitySet>();
+ entitySets.add(getEntitySet(ENTITY_CONTAINER_1, ENTITY_SET_1_1));
+ entitySets.add(getEntitySet(ENTITY_CONTAINER_1, ENTITY_SET_1_2));
+ entitySets.add(getEntitySet(ENTITY_CONTAINER_1, ENTITY_SET_1_3));
+ entitySets.add(getEntitySet(ENTITY_CONTAINER_1, ENTITY_SET_1_4));
+ entitySets.add(getEntitySet(ENTITY_CONTAINER_1, ENTITY_SET_1_5));
+ entityContainer.setEntitySets(entitySets);
+
+ final List<AssociationSet> associationSets = new ArrayList<AssociationSet>();
+ associationSets.add(getAssociationSet(ENTITY_CONTAINER_1, ASSOCIATION_1_1, ENTITY_SET_1_4, ROLE_1_4));
+ associationSets.add(getAssociationSet(ENTITY_CONTAINER_1, ASSOCIATION_1_2, ENTITY_SET_1_2, ROLE_1_2));
+ associationSets.add(getAssociationSet(ENTITY_CONTAINER_1, ASSOCIATION_1_3, ENTITY_SET_1_3, ROLE_1_3));
+ associationSets.add(getAssociationSet(ENTITY_CONTAINER_1, ASSOCIATION_1_4, ENTITY_SET_1_5, ROLE_1_5));
+ entityContainer.setAssociationSets(associationSets);
+
+ final List<FunctionImport> functionImports = new ArrayList<FunctionImport>();
+ functionImports.add(getFunctionImport(ENTITY_CONTAINER_1, FUNCTION_IMPORT_1));
+ functionImports.add(getFunctionImport(ENTITY_CONTAINER_1, FUNCTION_IMPORT_2));
+ functionImports.add(getFunctionImport(ENTITY_CONTAINER_1, FUNCTION_IMPORT_3));
+ functionImports.add(getFunctionImport(ENTITY_CONTAINER_1, FUNCTION_IMPORT_4));
+ functionImports.add(getFunctionImport(ENTITY_CONTAINER_1, FUNCTION_IMPORT_5));
+ functionImports.add(getFunctionImport(ENTITY_CONTAINER_1, FUNCTION_IMPORT_6));
+ functionImports.add(getFunctionImport(ENTITY_CONTAINER_1, FUNCTION_IMPORT_7));
+ entityContainer.setFunctionImports(functionImports);
+
+ schema.setEntityContainers(Arrays.asList(entityContainer));
+
+ final List<AnnotationElement> childElements = new ArrayList<AnnotationElement>();
+ childElements.add(new AnnotationElement().setName("schemaElementTest2").setText("text2").setNamespace(NAMESPACE_1));
+ childElements.add(new AnnotationElement().setName("schemaElementTest3").setText("text3").setPrefix("prefix").setNamespace("namespace"));
+ final List<AnnotationAttribute> elementAttributes = new ArrayList<AnnotationAttribute>();
+ elementAttributes.add(new AnnotationAttribute().setName("rel").setText("self"));
+ elementAttributes.add(new AnnotationAttribute().setName("href").setText("http://google.com").setPrefix("pre").setNamespace("namespaceForAnno"));
+ childElements.add(new AnnotationElement().setName("schemaElementTest4").setText("text4").setAttributes(elementAttributes));
+
+ final List<AnnotationElement> schemaElements = new ArrayList<AnnotationElement>();
+ schemaElements.add(new AnnotationElement().setName("schemaElementTest1").setText("text1").setChildElements(childElements));
+
+ schema.setAnnotationElements(schemaElements);
+ schemas.add(schema);
+
+ schema = new Schema();
+ schema.setNamespace(NAMESPACE_2);
+
+ schema.setEntityTypes(Arrays.asList(getEntityType(ENTITY_TYPE_2_1)));
+
+ entityContainer = new EntityContainer();
+ entityContainer.setName(ENTITY_CONTAINER_2);
+ entityContainer.setEntitySets(Arrays.asList(getEntitySet(ENTITY_CONTAINER_2, ENTITY_SET_2_1)));
+ schema.setEntityContainers(Arrays.asList(entityContainer));
+
+ schemas.add(schema);
+
+ return schemas;
+ }
+
+ @Override
+ public EntityType getEntityType(final FullQualifiedName edmFQName) throws ODataException {
+ if (NAMESPACE_1.equals(edmFQName.getNamespace())) {
+ if (ENTITY_TYPE_1_1.getName().equals(edmFQName.getName())) {
+ final List<Property> properties = new ArrayList<Property>();
+ final ArrayList<AnnotationAttribute> annoList = new ArrayList<AnnotationAttribute>();
+ annoList.add(new AnnotationAttribute().setName("annoName").setNamespace("http://annoNamespace").setPrefix("annoPrefix").setText("annoText"));
+ annoList.add(new AnnotationAttribute().setName("annoName2").setNamespace("http://annoNamespace").setPrefix("annoPrefix").setText("annoText2"));
+ properties.add(new SimpleProperty().setName("EmployeeId").setType(EdmSimpleTypeKind.String)
+ .setFacets(new Facets().setNullable(false))
+ .setMapping(new Mapping().setInternalName("getId")).setAnnotationAttributes(annoList));
+ final ArrayList<AnnotationAttribute> annoList2 = new ArrayList<AnnotationAttribute>();
+ annoList2.add(new AnnotationAttribute().setName("annoName").setNamespace("http://annoNamespace").setPrefix("annoPrefix").setText("annoText"));
+
+ final List<AnnotationElement> annoElementsForSimpleProp = new ArrayList<AnnotationElement>();
+ annoElementsForSimpleProp.add(new AnnotationElement().setName("propertyAnnoElement").setText("text"));
+ annoElementsForSimpleProp.add(new AnnotationElement().setName("propertyAnnoElement2"));
+ final SimpleProperty simpleProp = new SimpleProperty().setName("EmployeeName").setType(EdmSimpleTypeKind.String)
+ .setCustomizableFeedMappings(new CustomizableFeedMappings()
+ .setFcTargetPath(EdmTargetPath.SYNDICATION_TITLE)).setAnnotationAttributes(annoList2).setAnnotationElements(annoElementsForSimpleProp);
+
+ properties.add(simpleProp);
+ final ArrayList<AnnotationAttribute> annoList3 = new ArrayList<AnnotationAttribute>();
+ annoList3.add(new AnnotationAttribute().setName("annoName").setNamespace("http://annoNamespaceNew").setPrefix("annoPrefix").setText("annoTextNew"));
+ properties.add(new SimpleProperty().setName("ManagerId").setType(EdmSimpleTypeKind.String)
+ .setMapping(new Mapping().setInternalName("getManager.getId")).setAnnotationAttributes(annoList3));
+ properties.add(new SimpleProperty().setName("RoomId").setType(EdmSimpleTypeKind.String)
+ .setMapping(new Mapping().setInternalName("getRoom.getId")));
+ properties.add(new SimpleProperty().setName("TeamId").setType(EdmSimpleTypeKind.String)
+ .setFacets(new Facets().setMaxLength(2))
+ .setMapping(new Mapping().setInternalName("getTeam.getId")));
+ properties.add(new ComplexProperty().setName("Location").setType(COMPLEX_TYPE_1));
+ properties.add(new SimpleProperty().setName("Age").setType(EdmSimpleTypeKind.Int16));
+ properties.add(new SimpleProperty().setName("EntryDate").setType(EdmSimpleTypeKind.DateTime)
+ .setFacets(new Facets().setNullable(true))
+ .setCustomizableFeedMappings(new CustomizableFeedMappings().setFcTargetPath(EdmTargetPath.SYNDICATION_UPDATED)));
+ properties.add(new SimpleProperty().setName("ImageUrl").setType(EdmSimpleTypeKind.String)
+ .setMapping(new Mapping().setInternalName("getImageUri")));
+ final List<NavigationProperty> navigationProperties = new ArrayList<NavigationProperty>();
+ navigationProperties.add(new NavigationProperty().setName("ne_Manager")
+ .setRelationship(ASSOCIATION_1_1).setFromRole(ROLE_1_1).setToRole(ROLE_1_4));
+ navigationProperties.add(new NavigationProperty().setName("ne_Team")
+ .setRelationship(ASSOCIATION_1_2).setFromRole(ROLE_1_1).setToRole(ROLE_1_2));
+ navigationProperties.add(new NavigationProperty().setName("ne_Room")
+ .setRelationship(ASSOCIATION_1_3).setFromRole(ROLE_1_1).setToRole(ROLE_1_3));
+ return new EntityType().setName(ENTITY_TYPE_1_1.getName())
+ .setProperties(properties)
+ .setHasStream(true)
+ .setKey(getKey("EmployeeId"))
+ .setNavigationProperties(navigationProperties)
+ .setMapping(new Mapping().setMimeType("getImageType"));
+
+ } else if (ENTITY_TYPE_1_BASE.getName().equals(edmFQName.getName())) {
+ final List<Property> properties = new ArrayList<Property>();
+ properties.add(new SimpleProperty().setName("Id").setType(EdmSimpleTypeKind.String)
+ .setFacets(new Facets().setNullable(false).setDefaultValue("1")));
+ properties.add(new SimpleProperty().setName("Name").setType(EdmSimpleTypeKind.String)
+ .setCustomizableFeedMappings(new CustomizableFeedMappings().setFcTargetPath(EdmTargetPath.SYNDICATION_TITLE)));
+ return new EntityType().setName(ENTITY_TYPE_1_BASE.getName())
+ .setAbstract(true)
+ .setProperties(properties)
+ .setKey(getKey("Id"));
+
+ } else if (ENTITY_TYPE_1_2.getName().equals(edmFQName.getName())) {
+ final List<Property> properties = new ArrayList<Property>();
+ properties.add(new SimpleProperty().setName("isScrumTeam").setType(EdmSimpleTypeKind.Boolean)
+ .setFacets(new Facets().setNullable(true))
+ .setMapping(new Mapping().setInternalName("isScrumTeam")));
+ final List<NavigationProperty> navigationProperties = new ArrayList<NavigationProperty>();
+ navigationProperties.add(new NavigationProperty().setName("nt_Employees")
+ .setRelationship(ASSOCIATION_1_2).setFromRole(ROLE_1_2).setToRole(ROLE_1_1));
+ return new EntityType().setName(ENTITY_TYPE_1_2.getName())
+ .setBaseType(ENTITY_TYPE_1_BASE)
+ .setProperties(properties)
+ .setNavigationProperties(navigationProperties);
+
+ } else if (ENTITY_TYPE_1_3.getName().equals(edmFQName.getName())) {
+ final List<Property> properties = new ArrayList<Property>();
+ properties.add(new SimpleProperty().setName("Seats").setType(EdmSimpleTypeKind.Int16));
+ properties.add(new SimpleProperty().setName("Version").setType(EdmSimpleTypeKind.Int16)
+ .setFacets(new Facets().setConcurrencyMode(EdmConcurrencyMode.Fixed)));
+ final List<NavigationProperty> navigationProperties = new ArrayList<NavigationProperty>();
+ navigationProperties.add(new NavigationProperty().setName("nr_Employees")
+ .setRelationship(ASSOCIATION_1_3).setFromRole(ROLE_1_3).setToRole(ROLE_1_1));
+ navigationProperties.add(new NavigationProperty().setName("nr_Building")
+ .setRelationship(ASSOCIATION_1_4).setFromRole(ROLE_1_3).setToRole(ROLE_1_5));
+ return new EntityType().setName(ENTITY_TYPE_1_3.getName())
+ .setBaseType(ENTITY_TYPE_1_BASE)
+ .setProperties(properties)
+ .setNavigationProperties(navigationProperties);
+
+ } else if (ENTITY_TYPE_1_4.getName().equals(edmFQName.getName())) {
+ final List<NavigationProperty> navigationProperties = new ArrayList<NavigationProperty>();
+ navigationProperties.add(new NavigationProperty().setName("nm_Employees")
+ .setRelationship(ASSOCIATION_1_1).setFromRole(ROLE_1_4).setToRole(ROLE_1_1));
+ return new EntityType().setName(ENTITY_TYPE_1_4.getName())
+ .setBaseType(ENTITY_TYPE_1_1)
+ .setHasStream(true)
+ .setNavigationProperties(navigationProperties)
+ .setMapping(new Mapping().setMimeType("getImageType"));
+
+ } else if (ENTITY_TYPE_1_5.getName().equals(edmFQName.getName())) {
+ final List<Property> properties = new ArrayList<Property>();
+ properties.add(new SimpleProperty().setName("Id").setType(EdmSimpleTypeKind.String)
+ .setFacets(new Facets().setNullable(false)));
+ properties.add(new SimpleProperty().setName("Name").setType(EdmSimpleTypeKind.String)
+ .setCustomizableFeedMappings(new CustomizableFeedMappings()
+ .setFcTargetPath(EdmTargetPath.SYNDICATION_AUTHORNAME)));
+ properties.add(new SimpleProperty().setName("Image").setType(EdmSimpleTypeKind.Binary));
+ final List<NavigationProperty> navigationProperties = new ArrayList<NavigationProperty>();
+ navigationProperties.add(new NavigationProperty().setName("nb_Rooms")
+ .setRelationship(ASSOCIATION_1_4).setFromRole(ROLE_1_5).setToRole(ROLE_1_3));
+ return new EntityType().setName(ENTITY_TYPE_1_5.getName())
+ .setProperties(properties)
+ .setKey(getKey("Id"))
+ .setNavigationProperties(navigationProperties);
+ }
+
+ } else if (NAMESPACE_2.equals(edmFQName.getNamespace())) {
+ if (ENTITY_TYPE_2_1.getName().equals(edmFQName.getName())) {
+ final List<Property> properties = new ArrayList<Property>();
+ properties.add(new SimpleProperty().setName("Id").setType(EdmSimpleTypeKind.Int32)
+ .setFacets(new Facets().setNullable(false).setConcurrencyMode(EdmConcurrencyMode.Fixed)));
+ properties.add(new SimpleProperty().setName("Name").setType(EdmSimpleTypeKind.String)
+ .setCustomizableFeedMappings(new CustomizableFeedMappings().setFcTargetPath(EdmTargetPath.SYNDICATION_TITLE)));
+ properties.add(new SimpleProperty().setName("Type").setType(EdmSimpleTypeKind.String)
+ .setFacets(new Facets().setNullable(false)));
+ properties.add(new SimpleProperty().setName("ImageUrl").setType(EdmSimpleTypeKind.String)
+ .setCustomizableFeedMappings(new CustomizableFeedMappings().setFcTargetPath(EdmTargetPath.SYNDICATION_AUTHORURI))
+ .setMapping(new Mapping().setInternalName("getImageUri")));
+ properties.add(new SimpleProperty().setName("Image").setType(EdmSimpleTypeKind.Binary)
+ .setMapping(new Mapping().setMimeType("getType")));
+ properties.add(new SimpleProperty().setName("BinaryData").setType(EdmSimpleTypeKind.Binary)
+ .setFacets(new Facets().setNullable(true))
+ .setMimeType("image/jpeg"));
+ properties.add(new SimpleProperty().setName("Содержание").setType(EdmSimpleTypeKind.String)
+ .setFacets(new Facets().setNullable(true))
+ .setCustomizableFeedMappings(new CustomizableFeedMappings()
+ .setFcKeepInContent(false)
+ .setFcNsPrefix("ру") // CYRILLIC SMALL LETTER ER + CYRILLIC SMALL LETTER U
+ .setFcNsUri("http://localhost")
+ .setFcTargetPath("Содержание"))
+ .setMapping(new Mapping().setInternalName("getContent")));
+ return new EntityType().setName(ENTITY_TYPE_2_1.getName())
+ .setProperties(properties)
+ .setHasStream(true)
+ .setKey(getKey("Id", "Type"))
+ .setMapping(new Mapping().setMimeType("getType"));
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public ComplexType getComplexType(final FullQualifiedName edmFQName) throws ODataException {
+ if (NAMESPACE_1.equals(edmFQName.getNamespace())) {
+ if (COMPLEX_TYPE_1.getName().equals(edmFQName.getName())) {
+ final List<Property> properties = new ArrayList<Property>();
+ properties.add(new ComplexProperty().setName("City").setType(COMPLEX_TYPE_2));
+ properties.add(new SimpleProperty().setName("Country").setType(EdmSimpleTypeKind.String));
+ return new ComplexType().setName(COMPLEX_TYPE_1.getName()).setProperties(properties);
+
+ } else if (COMPLEX_TYPE_2.getName().equals(edmFQName.getName())) {
+ final List<Property> properties = new ArrayList<Property>();
+ properties.add(new SimpleProperty().setName("PostalCode").setType(EdmSimpleTypeKind.String));
+ properties.add(new SimpleProperty().setName("CityName").setType(EdmSimpleTypeKind.String));
+ return new ComplexType().setName(COMPLEX_TYPE_2.getName()).setProperties(properties);
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public Association getAssociation(final FullQualifiedName edmFQName) throws ODataException {
+ if (NAMESPACE_1.equals(edmFQName.getNamespace())) {
+ if (ASSOCIATION_1_1.getName().equals(edmFQName.getName())) {
+ return new Association().setName(ASSOCIATION_1_1.getName())
+ .setEnd1(new AssociationEnd().setType(ENTITY_TYPE_1_1).setRole(ROLE_1_1).setMultiplicity(EdmMultiplicity.MANY))
+ .setEnd2(new AssociationEnd().setType(ENTITY_TYPE_1_4).setRole(ROLE_1_4).setMultiplicity(EdmMultiplicity.ONE));
+ } else if (ASSOCIATION_1_2.getName().equals(edmFQName.getName())) {
+ return new Association().setName(ASSOCIATION_1_2.getName())
+ .setEnd1(new AssociationEnd().setType(ENTITY_TYPE_1_1).setRole(ROLE_1_1).setMultiplicity(EdmMultiplicity.MANY))
+ .setEnd2(new AssociationEnd().setType(ENTITY_TYPE_1_2).setRole(ROLE_1_2).setMultiplicity(EdmMultiplicity.ONE));
+ } else if (ASSOCIATION_1_3.getName().equals(edmFQName.getName())) {
+ return new Association().setName(ASSOCIATION_1_3.getName())
+ .setEnd1(new AssociationEnd().setType(ENTITY_TYPE_1_1).setRole(ROLE_1_1).setMultiplicity(EdmMultiplicity.MANY))
+ .setEnd2(new AssociationEnd().setType(ENTITY_TYPE_1_3).setRole(ROLE_1_3).setMultiplicity(EdmMultiplicity.ONE));
+ } else if (ASSOCIATION_1_4.getName().equals(edmFQName.getName())) {
+ final List<PropertyRef> propertyRefsPrincipal = new ArrayList<PropertyRef>();
+ propertyRefsPrincipal.add(new PropertyRef().setName("Id"));
+ propertyRefsPrincipal.add(new PropertyRef().setName("Id2"));
+ final List<PropertyRef> propertyRefsDependent = new ArrayList<PropertyRef>();
+ propertyRefsDependent.add(new PropertyRef().setName("Id"));
+ propertyRefsDependent.add(new PropertyRef().setName("Id2"));
+ return new Association().setName(ASSOCIATION_1_4.getName())
+ .setEnd1(new AssociationEnd().setType(ENTITY_TYPE_1_5).setRole(ROLE_1_5).setMultiplicity(EdmMultiplicity.ONE))
+ .setEnd2(new AssociationEnd().setType(ENTITY_TYPE_1_3).setRole(ROLE_1_3).setMultiplicity(EdmMultiplicity.MANY))
+ .setReferentialConstraint(new ReferentialConstraint().setPrincipal(new ReferentialConstraintRole().setRole("BuildingToRoom").setPropertyRefs(propertyRefsPrincipal))
+ .setDependent(new ReferentialConstraintRole().setRole("RoomToBuilding").setPropertyRefs(propertyRefsDependent)));
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public EntityContainerInfo getEntityContainerInfo(final String name) throws ODataException {
+ if ((name == null) || ENTITY_CONTAINER_1.equals(name)) {
+ return new EntityContainerInfo().setName(ENTITY_CONTAINER_1).setDefaultEntityContainer(true);
+ } else if (ENTITY_CONTAINER_2.equals(name)) {
+ return new EntityContainerInfo().setName(name).setDefaultEntityContainer(false);
+ }
+
+ return null;
+ }
+
+ @Override
+ public EntitySet getEntitySet(final String entityContainer, final String name) throws ODataException {
+ if (ENTITY_CONTAINER_1.equals(entityContainer)) {
+ if (ENTITY_SET_1_1.equals(name)) {
+ return new EntitySet().setName(name).setEntityType(ENTITY_TYPE_1_1);
+ } else if (ENTITY_SET_1_2.equals(name)) {
+ return new EntitySet().setName(name).setEntityType(ENTITY_TYPE_1_2);
+ } else if (ENTITY_SET_1_3.equals(name)) {
+ return new EntitySet().setName(name).setEntityType(ENTITY_TYPE_1_3);
+ } else if (ENTITY_SET_1_4.equals(name)) {
+ return new EntitySet().setName(name).setEntityType(ENTITY_TYPE_1_4);
+ } else if (ENTITY_SET_1_5.equals(name)) {
+ return new EntitySet().setName(name).setEntityType(ENTITY_TYPE_1_5);
+ }
+
+ } else if (ENTITY_CONTAINER_2.equals(entityContainer)) {
+ if (ENTITY_SET_2_1.equals(name)) {
+ return new EntitySet().setName(name).setEntityType(ENTITY_TYPE_2_1);
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public FunctionImport getFunctionImport(final String entityContainer, final String name) throws ODataException {
+ if (ENTITY_CONTAINER_1.equals(entityContainer)) {
+ if (FUNCTION_IMPORT_1.equals(name)) {
+ final List<FunctionImportParameter> parameters = new ArrayList<FunctionImportParameter>();
+ parameters.add(new FunctionImportParameter().setName("q").setType(EdmSimpleTypeKind.String)
+ .setFacets(new Facets().setNullable(true)));
+ return new FunctionImport().setName(name)
+ .setReturnType(new ReturnType().setTypeName(ENTITY_TYPE_1_1).setMultiplicity(EdmMultiplicity.MANY))
+ .setEntitySet(ENTITY_SET_1_1)
+ .setHttpMethod("GET")
+ .setParameters(parameters);
+
+ } else if (FUNCTION_IMPORT_2.equals(name)) {
+ return new FunctionImport().setName(name)
+ .setReturnType(new ReturnType().setTypeName(COMPLEX_TYPE_1).setMultiplicity(EdmMultiplicity.MANY))
+ .setHttpMethod("GET");
+
+ } else if (FUNCTION_IMPORT_3.equals(name)) {
+ return new FunctionImport().setName(name)
+ .setReturnType(new ReturnType().setTypeName(EdmSimpleTypeKind.String.getFullQualifiedName()).setMultiplicity(EdmMultiplicity.MANY))
+ .setHttpMethod("GET");
+
+ } else if (FUNCTION_IMPORT_4.equals(name)) {
+ return new FunctionImport().setName(name)
+ .setReturnType(new ReturnType().setTypeName(EdmSimpleTypeKind.Int16.getFullQualifiedName()).setMultiplicity(EdmMultiplicity.ONE))
+ .setHttpMethod("GET");
+
+ } else if (FUNCTION_IMPORT_5.equals(name)) {
+ return new FunctionImport().setName(name)
+ .setReturnType(new ReturnType().setTypeName(COMPLEX_TYPE_1).setMultiplicity(EdmMultiplicity.ONE))
+ .setHttpMethod("GET");
+
+ } else if (FUNCTION_IMPORT_6.equals(name)) {
+ final List<FunctionImportParameter> parameters = new ArrayList<FunctionImportParameter>();
+ parameters.add(new FunctionImportParameter().setName("Id").setType(EdmSimpleTypeKind.String)
+ .setFacets(new Facets().setNullable(false)));
+ return new FunctionImport().setName(name)
+ .setReturnType(new ReturnType().setTypeName(EdmSimpleTypeKind.Binary.getFullQualifiedName()).setMultiplicity(EdmMultiplicity.ONE))
+ .setHttpMethod("GET")
+ .setParameters(parameters);
+
+ } else if (FUNCTION_IMPORT_7.equals(name)) {
+ return new FunctionImport().setName(name)
+ .setReturnType(new ReturnType().setTypeName(new FullQualifiedName(NAMESPACE_1, "Employee")).setMultiplicity(EdmMultiplicity.ZERO_TO_ONE))
+ .setEntitySet(ENTITY_SET_1_1)
+ .setHttpMethod("GET");
+
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public AssociationSet getAssociationSet(final String entityContainer, final FullQualifiedName association, final String sourceEntitySetName, final String sourceEntitySetRole) throws ODataException {
+ if (ENTITY_CONTAINER_1.equals(entityContainer)) {
+ if (ASSOCIATION_1_1.equals(association)) {
+ return new AssociationSet().setName(ASSOCIATION_1_1.getName())
+ .setAssociation(ASSOCIATION_1_1)
+ .setEnd1(new AssociationSetEnd().setRole(ROLE_1_4).setEntitySet(ENTITY_SET_1_4))
+ .setEnd2(new AssociationSetEnd().setRole(ROLE_1_1).setEntitySet(ENTITY_SET_1_1));
+ } else if (ASSOCIATION_1_2.equals(association)) {
+ return new AssociationSet().setName(ASSOCIATION_1_2.getName())
+ .setAssociation(ASSOCIATION_1_2)
+ .setEnd1(new AssociationSetEnd().setRole(ROLE_1_2).setEntitySet(ENTITY_SET_1_2))
+ .setEnd2(new AssociationSetEnd().setRole(ROLE_1_1).setEntitySet(ENTITY_SET_1_1));
+ } else if (ASSOCIATION_1_3.equals(association)) {
+ return new AssociationSet().setName(ASSOCIATION_1_3.getName())
+ .setAssociation(ASSOCIATION_1_3)
+ .setEnd1(new AssociationSetEnd().setRole(ROLE_1_3).setEntitySet(ENTITY_SET_1_3))
+ .setEnd2(new AssociationSetEnd().setRole(ROLE_1_1).setEntitySet(ENTITY_SET_1_1));
+ } else if (ASSOCIATION_1_4.equals(association)) {
+ return new AssociationSet().setName(ASSOCIATION_1_4.getName())
+ .setAssociation(ASSOCIATION_1_4)
+ .setEnd1(new AssociationSetEnd().setRole(ROLE_1_5).setEntitySet(ENTITY_SET_1_5))
+ .setEnd2(new AssociationSetEnd().setRole(ROLE_1_3).setEntitySet(ENTITY_SET_1_3));
+ }
+ }
+
+ return null;
+ }
+
+ private Key getKey(final String... keyNames) {
+ final List<PropertyRef> keyProperties = new ArrayList<PropertyRef>();
+ for (final String keyName : keyNames) {
+ keyProperties.add(new PropertyRef().setName(keyName));
+ }
+ return new Key().setKeys(keyProperties);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c5b266a6/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/testutil/mock/MockFacade.java
----------------------------------------------------------------------
diff --git a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/testutil/mock/MockFacade.java b/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/testutil/mock/MockFacade.java
new file mode 100644
index 0000000..10085c0
--- /dev/null
+++ b/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/testutil/mock/MockFacade.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * 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.testutil.mock;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.mockito.Mockito;
+
+import org.apache.olingo.odata2.api.edm.Edm;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.uri.PathSegment;
+
+/**
+ * Mocked Entity Data Model, more or less aligned to the Reference Scenario.
+ *
+ */
+public class MockFacade {
+
+ public static Edm getMockEdm() throws ODataException {
+ return EdmMock.createMockEdm();
+ }
+
+ public static List<PathSegment> getPathSegmentsAsODataPathSegmentMock(final List<String> segments) {
+ final List<PathSegment> pathSegmentsMock = new ArrayList<PathSegment>();
+ for (final String segment : segments) {
+ PathSegment pathSegment = Mockito.mock(PathSegment.class);
+ Mockito.when(pathSegment.getPath()).thenReturn(segment);
+ pathSegmentsMock.add(pathSegment);
+ }
+ return pathSegmentsMock;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c5b266a6/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/testutil/mock/SampleClassForInvalidMessageReferences.java
----------------------------------------------------------------------
diff --git a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/testutil/mock/SampleClassForInvalidMessageReferences.java b/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/testutil/mock/SampleClassForInvalidMessageReferences.java
new file mode 100644
index 0000000..420c7b1
--- /dev/null
+++ b/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/testutil/mock/SampleClassForInvalidMessageReferences.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * 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.testutil.mock;
+
+import org.apache.olingo.odata2.api.exception.MessageReference;
+import org.apache.olingo.odata2.api.exception.ODataMessageException;
+
+/**
+ *
+ */
+public class SampleClassForInvalidMessageReferences extends ODataMessageException
+{
+ private static final long serialVersionUID = 1L;
+
+ public SampleClassForInvalidMessageReferences(final MessageReference messageReference) {
+ super(messageReference);
+ }
+
+ public SampleClassForInvalidMessageReferences(final MessageReference messageReference, final String errorCode) {
+ super(messageReference, errorCode);
+ }
+
+ public static final MessageReference EXIST = createMessageReference(SampleClassForInvalidMessageReferences.class, "EXIST");
+ public static final MessageReference DOES_NOT_EXIST = createMessageReference(SampleClassForInvalidMessageReferences.class, "DOES_NOT_EXIST");
+ public static final MessageReference EXITS_BUT_EMPTY = createMessageReference(SampleClassForInvalidMessageReferences.class, "EXITS_BUT_EMPTY");
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c5b266a6/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/testutil/mock/TecEdmInfo.java
----------------------------------------------------------------------
diff --git a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/testutil/mock/TecEdmInfo.java b/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/testutil/mock/TecEdmInfo.java
new file mode 100644
index 0000000..92733af
--- /dev/null
+++ b/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/testutil/mock/TecEdmInfo.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * 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.testutil.mock;
+
+import static org.junit.Assert.fail;
+
+import org.apache.olingo.odata2.api.edm.Edm;
+import org.apache.olingo.odata2.api.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.edm.EdmException;
+
+/**
+ * Helper for the entity data model used as technical reference scenario.
+ *
+ */
+public class TecEdmInfo {
+ private final Edm edm;
+
+ public TecEdmInfo(final Edm edm) {
+ this.edm = edm;
+ }
+
+ public EdmEntityType getTypeEtAllTypes() {
+ try {
+ return edm
+ .getEntityContainer(TechnicalScenarioEdmProvider.ENTITY_CONTAINER_1)
+ .getEntitySet(TechnicalScenarioEdmProvider.ES_ALL_TYPES)
+ .getEntityType();
+ } catch (final EdmException e) {
+ fail("Error in test setup" + e.getLocalizedMessage());
+ }
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c5b266a6/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/testutil/mock/TechnicalScenarioEdmProvider.java
----------------------------------------------------------------------
diff --git a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/testutil/mock/TechnicalScenarioEdmProvider.java b/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/testutil/mock/TechnicalScenarioEdmProvider.java
new file mode 100644
index 0000000..703a068
--- /dev/null
+++ b/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/testutil/mock/TechnicalScenarioEdmProvider.java
@@ -0,0 +1,287 @@
+/*******************************************************************************
+ * 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.testutil.mock;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+import org.apache.olingo.odata2.api.edm.FullQualifiedName;
+import org.apache.olingo.odata2.api.edm.provider.Association;
+import org.apache.olingo.odata2.api.edm.provider.AssociationEnd;
+import org.apache.olingo.odata2.api.edm.provider.AssociationSet;
+import org.apache.olingo.odata2.api.edm.provider.AssociationSetEnd;
+import org.apache.olingo.odata2.api.edm.provider.ComplexProperty;
+import org.apache.olingo.odata2.api.edm.provider.ComplexType;
+import org.apache.olingo.odata2.api.edm.provider.EdmProvider;
+import org.apache.olingo.odata2.api.edm.provider.EntityContainer;
+import org.apache.olingo.odata2.api.edm.provider.EntityContainerInfo;
+import org.apache.olingo.odata2.api.edm.provider.EntitySet;
+import org.apache.olingo.odata2.api.edm.provider.EntityType;
+import org.apache.olingo.odata2.api.edm.provider.Facets;
+import org.apache.olingo.odata2.api.edm.provider.FunctionImport;
+import org.apache.olingo.odata2.api.edm.provider.Key;
+import org.apache.olingo.odata2.api.edm.provider.NavigationProperty;
+import org.apache.olingo.odata2.api.edm.provider.Property;
+import org.apache.olingo.odata2.api.edm.provider.PropertyRef;
+import org.apache.olingo.odata2.api.edm.provider.Schema;
+import org.apache.olingo.odata2.api.edm.provider.SimpleProperty;
+import org.apache.olingo.odata2.api.exception.ODataMessageException;
+
+/**
+ * Provider for the entity data model used as technical reference scenario
+ *
+ */
+public class TechnicalScenarioEdmProvider extends EdmProvider {
+
+ public static final String NAMESPACE_1 = "TecRefScenario";
+
+ public static final FullQualifiedName ET_KEY_IS_STRING = new FullQualifiedName(NAMESPACE_1, "EtKeyTypeString");
+ public static final FullQualifiedName ET_KEY_IS_INTEGER = new FullQualifiedName(NAMESPACE_1, "EtKeyTypeInteger");
+ public static final FullQualifiedName ET_COMPLEX_KEY = new FullQualifiedName(NAMESPACE_1, "EtComplexKey");
+ public static final FullQualifiedName ET_ALL_TYPES = new FullQualifiedName(NAMESPACE_1, "EtAllTypes");
+ public static final FullQualifiedName ET_STRING_FACETS = new FullQualifiedName(NAMESPACE_1, "EtStringFacets");
+
+ public static final FullQualifiedName CT_ADDRESS = new FullQualifiedName(NAMESPACE_1, "CtAdress");
+ public static final FullQualifiedName CT_ALL_TYPES = new FullQualifiedName(NAMESPACE_1, "CtAllTypes");
+
+ public static final FullQualifiedName ASSOCIATION_ET1_ET2 = new FullQualifiedName(NAMESPACE_1, "Association");
+ public static final String ROLE_1 = "Role1";
+ public static final String ROLE_2 = "Role2";
+
+ public static final String ENTITY_CONTAINER_1 = "Container1";
+
+ public static final String ES_KEY_IS_STRING = "KeyTypeString";
+ public static final String ES_KEY_IS_INTEGER = "KeyTypeInteger";
+ public static final String ES_COMPLEX_KEY = "ComplexKey";
+ public static final String ES_ALL_TYPES = "AllTypes";
+ public static final String ES_STRING_FACETS = "StringFacets";
+
+ @Override
+ public List<Schema> getSchemas() throws ODataMessageException {
+ final Schema schema = new Schema();
+ schema.setNamespace(NAMESPACE_1);
+
+ schema.setEntityTypes(Arrays.asList(
+ getEntityType(ET_KEY_IS_STRING),
+ getEntityType(ET_KEY_IS_INTEGER),
+ getEntityType(ET_COMPLEX_KEY),
+ getEntityType(ET_ALL_TYPES)));
+
+ schema.setComplexTypes(Arrays.asList(getComplexType(CT_ALL_TYPES)));
+
+ final EntityContainer entityContainer = new EntityContainer();
+ entityContainer.setName(ENTITY_CONTAINER_1).setDefaultEntityContainer(true);
+ entityContainer.setEntitySets(Arrays.asList(
+ getEntitySet(ENTITY_CONTAINER_1, ES_KEY_IS_STRING),
+ getEntitySet(ENTITY_CONTAINER_1, ES_KEY_IS_INTEGER),
+ getEntitySet(ENTITY_CONTAINER_1, ES_COMPLEX_KEY),
+ getEntitySet(ENTITY_CONTAINER_1, ES_ALL_TYPES),
+ getEntitySet(ENTITY_CONTAINER_1, ES_STRING_FACETS)));
+
+ schema.setEntityContainers(Arrays.asList(entityContainer));
+
+ return Arrays.asList(schema);
+ }
+
+ @Override
+ public EntityType getEntityType(final FullQualifiedName edmFQName) throws ODataMessageException {
+ if (NAMESPACE_1.equals(edmFQName.getNamespace())) {
+ if (ET_KEY_IS_STRING.getName().equals(edmFQName.getName())) {
+ final List<Property> properties = new ArrayList<Property>();
+ properties.add(new SimpleProperty().setName("KeyString")
+ .setType(EdmSimpleTypeKind.String)
+ .setFacets(new Facets().setNullable(false)));
+
+ final List<NavigationProperty> navigationProperties = new ArrayList<NavigationProperty>();
+
+ navigationProperties.add(new NavigationProperty().setName("navProperty").setFromRole(ROLE_1).setToRole(ROLE_2).setRelationship(ASSOCIATION_ET1_ET2));
+
+ return new EntityType().setName(ET_KEY_IS_STRING.getName()).setProperties(properties).setNavigationProperties(navigationProperties).setKey(createKey("KeyString"));
+ } else if (ET_KEY_IS_INTEGER.getName().equals(edmFQName.getName())) {
+ final List<Property> properties = new ArrayList<Property>();
+ properties.add(new SimpleProperty().setName("KeyInteger")
+ .setType(EdmSimpleTypeKind.String)
+ .setFacets(new Facets().setNullable(false)));
+
+ final List<NavigationProperty> navigationProperties = new ArrayList<NavigationProperty>();
+ navigationProperties.add(new NavigationProperty().setName("navProperty").setFromRole(ROLE_2).setToRole(ROLE_1).setRelationship(ASSOCIATION_ET1_ET2));
+
+ return new EntityType().setName(ET_KEY_IS_INTEGER.getName()).setProperties(properties).setNavigationProperties(navigationProperties).setKey(createKey("KeyInteger"));
+
+ } else if (ET_COMPLEX_KEY.getName().equals(edmFQName.getName())) {
+ final List<Property> properties = new ArrayList<Property>();
+ properties.add(new SimpleProperty().setName("KeyString")
+ .setType(EdmSimpleTypeKind.String)
+ .setFacets(new Facets().setNullable(false)));
+ properties.add(new SimpleProperty().setName("KeyInteger")
+ .setType(EdmSimpleTypeKind.String)
+ .setFacets(new Facets().setNullable(false)));
+
+ return new EntityType().setName(ET_COMPLEX_KEY.getName()).setProperties(properties).setKey(createKey("KeyInteger", "KeyString"));
+ } else if (ET_ALL_TYPES.getName().equals(edmFQName.getName())) {
+ final List<Property> properties = new ArrayList<Property>();
+ properties.add(new SimpleProperty().setName("Boolean").setType(EdmSimpleTypeKind.Boolean));
+ properties.add(new SimpleProperty().setName("Binary").setType(EdmSimpleTypeKind.Binary));
+ properties.add(new SimpleProperty().setName("Byte").setType(EdmSimpleTypeKind.Byte));
+ properties.add(new SimpleProperty().setName("DateTime").setType(EdmSimpleTypeKind.DateTime));
+ properties.add(new SimpleProperty().setName("DateTimeOffset").setType(EdmSimpleTypeKind.DateTimeOffset));
+ properties.add(new SimpleProperty().setName("Decimal").setType(EdmSimpleTypeKind.Decimal));
+ properties.add(new SimpleProperty().setName("Double").setType(EdmSimpleTypeKind.Double));
+ properties.add(new SimpleProperty().setName("Guid").setType(EdmSimpleTypeKind.Guid));
+ properties.add(new SimpleProperty().setName("Int16").setType(EdmSimpleTypeKind.Int16));
+ properties.add(new SimpleProperty().setName("Int32").setType(EdmSimpleTypeKind.Int32));
+ properties.add(new SimpleProperty().setName("Int64").setType(EdmSimpleTypeKind.Int64));
+ properties.add(new SimpleProperty().setName("SByte").setType(EdmSimpleTypeKind.SByte));
+ properties.add(new SimpleProperty().setName("Single").setType(EdmSimpleTypeKind.Single));
+ properties.add(new SimpleProperty().setName("String").setType(EdmSimpleTypeKind.String));
+ properties.add(new SimpleProperty().setName("Time").setType(EdmSimpleTypeKind.Time));
+ properties.add(new ComplexProperty().setName("Complex").setType(CT_ALL_TYPES));
+ return new EntityType().setName(ET_ALL_TYPES.getName()).setProperties(properties);
+ } else if (ET_STRING_FACETS.getName().equals(edmFQName.getName())) {
+ final List<Property> properties = new ArrayList<Property>();
+
+ properties.add(new SimpleProperty().setName("StringDefaultValue").setType(EdmSimpleTypeKind.String)
+ .setFacets(new Facets().setDefaultValue("defaultValue")));
+
+ properties.add(new SimpleProperty().setName("StringFixedLength").setType(EdmSimpleTypeKind.String)
+ .setFacets(new Facets().setFixedLength(true)));
+
+ properties.add(new SimpleProperty().setName("StringMaxLength").setType(EdmSimpleTypeKind.String)
+ .setFacets(new Facets().setMaxLength(15)));
+
+ properties.add(new SimpleProperty().setName("StringLength").setType(EdmSimpleTypeKind.String)
+ .setFacets(new Facets().setMaxLength(15).setFixedLength(true)));
+
+ properties.add(new SimpleProperty().setName("StringNullable").setType(EdmSimpleTypeKind.String)
+ .setFacets(new Facets().setNullable(false)));
+
+ properties.add(new SimpleProperty().setName("StringUnicode").setType(EdmSimpleTypeKind.String)
+ .setFacets(new Facets().setUnicode(false)));
+
+ return new EntityType().setName(ET_STRING_FACETS.getName()).setProperties(properties);
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public ComplexType getComplexType(final FullQualifiedName edmFQName) throws ODataMessageException {
+ if (NAMESPACE_1.equals(edmFQName.getNamespace())) {
+ if (CT_ADDRESS.getName().equals(edmFQName.getName())) {
+ final List<Property> properties = new ArrayList<Property>();
+ properties.add(new SimpleProperty().setName("Street").setType(EdmSimpleTypeKind.String));
+ properties.add(new SimpleProperty().setName("City").setType(EdmSimpleTypeKind.String));
+ return new ComplexType().setName(CT_ADDRESS.getName()).setAbstract(false).setProperties(properties);
+ } else if (CT_ALL_TYPES.getName().equals(edmFQName.getName())) {
+ final List<Property> properties = new ArrayList<Property>();
+ properties.add(new SimpleProperty().setName("Boolean").setType(EdmSimpleTypeKind.Boolean));
+ properties.add(new SimpleProperty().setName("Binary").setType(EdmSimpleTypeKind.Binary));
+ properties.add(new SimpleProperty().setName("Byte").setType(EdmSimpleTypeKind.Byte));
+ properties.add(new SimpleProperty().setName("DateTime").setType(EdmSimpleTypeKind.DateTime));
+ properties.add(new SimpleProperty().setName("DateTimeOffset").setType(EdmSimpleTypeKind.DateTimeOffset));
+ properties.add(new SimpleProperty().setName("Decimal").setType(EdmSimpleTypeKind.Decimal));
+ properties.add(new SimpleProperty().setName("Double").setType(EdmSimpleTypeKind.Double));
+ properties.add(new SimpleProperty().setName("Guid").setType(EdmSimpleTypeKind.Guid));
+ properties.add(new SimpleProperty().setName("Int16").setType(EdmSimpleTypeKind.Int16));
+ properties.add(new SimpleProperty().setName("Int32").setType(EdmSimpleTypeKind.Int32));
+ properties.add(new SimpleProperty().setName("Int64").setType(EdmSimpleTypeKind.Int64));
+ properties.add(new SimpleProperty().setName("SByte").setType(EdmSimpleTypeKind.SByte));
+ properties.add(new SimpleProperty().setName("Single").setType(EdmSimpleTypeKind.Single));
+ properties.add(new SimpleProperty().setName("String").setType(EdmSimpleTypeKind.String));
+ properties.add(new SimpleProperty().setName("Time").setType(EdmSimpleTypeKind.Time));
+ properties.add(new ComplexProperty().setName("Address").setType(CT_ADDRESS));
+ return new ComplexType().setName(CT_ALL_TYPES.getName()).setAbstract(false).setProperties(properties);
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public Association getAssociation(final FullQualifiedName edmFQName) throws ODataMessageException {
+ if (NAMESPACE_1.equals(edmFQName.getNamespace())) {
+ if (ASSOCIATION_ET1_ET2.getName().equals(edmFQName.getName())) {
+ final AssociationEnd end1 = new AssociationEnd().setMultiplicity(EdmMultiplicity.ONE).setRole(ROLE_1).setType(ET_KEY_IS_STRING);
+ final AssociationEnd end2 = new AssociationEnd().setMultiplicity(EdmMultiplicity.ONE).setRole(ROLE_2).setType(ET_KEY_IS_INTEGER);
+ return new Association().setName("Association").setEnd1(end1).setEnd2(end2);
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public EntityContainerInfo getEntityContainerInfo(final String name) throws ODataMessageException {
+ if ((name == null) || ENTITY_CONTAINER_1.equals(name)) {
+ return new EntityContainerInfo().setName(ENTITY_CONTAINER_1).setDefaultEntityContainer(true);
+ }
+
+ return null;
+ }
+
+ @Override
+ public EntitySet getEntitySet(final String entityContainer, final String name) throws ODataMessageException {
+ if (ENTITY_CONTAINER_1.equals(entityContainer)) {
+ if (ES_KEY_IS_STRING.equals(name)) {
+ return new EntitySet().setName(name).setEntityType(ET_KEY_IS_STRING);
+ } else if (ES_KEY_IS_INTEGER.equals(name)) {
+ return new EntitySet().setName(name).setEntityType(ET_KEY_IS_INTEGER);
+ } else if (ES_COMPLEX_KEY.equals(name)) {
+ return new EntitySet().setName(name).setEntityType(ET_COMPLEX_KEY);
+ } else if (ES_ALL_TYPES.equals(name)) {
+ return new EntitySet().setName(name).setEntityType(ET_ALL_TYPES);
+ } else if (ES_STRING_FACETS.equals(name)) {
+ return new EntitySet().setName(name).setEntityType(ET_STRING_FACETS);
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public FunctionImport getFunctionImport(final String entityContainer, final String name) throws ODataMessageException {
+ return null;
+ }
+
+ @Override
+ public AssociationSet getAssociationSet(final String entityContainer, final FullQualifiedName association, final String sourceEntitySetName, final String sourceEntitySetRole) throws ODataMessageException {
+ if (ENTITY_CONTAINER_1.equals(entityContainer)) {
+ if (ASSOCIATION_ET1_ET2.equals(association)) {
+ final AssociationSetEnd end1 = new AssociationSetEnd().setRole(ROLE_1).setEntitySet(ES_KEY_IS_STRING);
+ final AssociationSetEnd end2 = new AssociationSetEnd().setRole(ROLE_2).setEntitySet(ES_KEY_IS_INTEGER);
+
+ return new AssociationSet().setName("AssociationSet").setEnd1(end1).setEnd2(end2);
+ }
+ }
+ return null;
+ }
+
+ private Key createKey(final String... keyNames) {
+ final List<PropertyRef> keyProperties = new ArrayList<PropertyRef>();
+ for (final String keyName : keyNames) {
+ keyProperties.add(new PropertyRef().setName(keyName));
+ }
+ return new Key().setKeys(keyProperties);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c5b266a6/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/testutil/server/ServerRuntimeException.java
----------------------------------------------------------------------
diff --git a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/testutil/server/ServerRuntimeException.java b/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/testutil/server/ServerRuntimeException.java
new file mode 100644
index 0000000..aa43be4
--- /dev/null
+++ b/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/testutil/server/ServerRuntimeException.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * 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.testutil.server;
+
+/**
+ *
+ */
+public class ServerRuntimeException extends RuntimeException {
+
+ public ServerRuntimeException(final Exception e) {
+ super(e);
+ }
+
+ private static final long serialVersionUID = 1L;
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c5b266a6/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/testutil/server/TestServer.java
----------------------------------------------------------------------
diff --git a/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/testutil/server/TestServer.java b/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/testutil/server/TestServer.java
new file mode 100644
index 0000000..4243551
--- /dev/null
+++ b/aggregated-sources/org.apache.olingo.odata2-parent-sources/org/apache/olingo/odata2/testutil/server/TestServer.java
@@ -0,0 +1,137 @@
+/*******************************************************************************
+ * 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.testutil.server;
+
+import java.net.BindException;
+import java.net.InetSocketAddress;
+import java.net.URI;
+
+import org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet;
+import org.apache.log4j.Logger;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.servlet.ServletContextHandler;
+import org.eclipse.jetty.servlet.ServletHolder;
+
+import org.apache.olingo.odata2.api.ODataService;
+import org.apache.olingo.odata2.api.ODataServiceFactory;
+import org.apache.olingo.odata2.testutil.fit.FitStaticServiceFactory;
+
+/**
+ *
+ */
+public class TestServer {
+ private static final Logger log = Logger.getLogger(TestServer.class);
+
+ private static final int PORT_MIN = 19000;
+ private static final int PORT_MAX = 19200;
+ private static final int PORT_INC = 1;
+
+ private static final String DEFAULT_SCHEME = "http";
+ private static final String DEFAULT_HOST = "localhost";
+ private static final String DEFAULT_PATH = "/test";
+
+ private URI endpoint; //= URI.create("http://localhost:19080/test"); // no slash at the end !!!
+ private final String path;
+
+ private int pathSplit = 0;
+
+ public TestServer() {
+ this(DEFAULT_PATH);
+ }
+
+ public TestServer(final String path) {
+ if (path.startsWith("/")) {
+ this.path = path;
+ } else {
+ this.path = "/" + path;
+ }
+ }
+
+ public int getPathSplit() {
+ return pathSplit;
+ }
+
+ public void setPathSplit(final int pathSplit) {
+ this.pathSplit = pathSplit;
+ }
+
+ public URI getEndpoint() {
+ return URI.create(endpoint + "/");
+ }
+
+ private Server server;
+
+ public void startServer(final Class<? extends ODataServiceFactory> factoryClass) {
+ try {
+ for (int port = PORT_MIN; port <= PORT_MAX; port += PORT_INC) {
+ final CXFNonSpringJaxrsServlet odataServlet = new CXFNonSpringJaxrsServlet();
+ final ServletHolder odataServletHolder = new ServletHolder(odataServlet);
+ odataServletHolder.setInitParameter("javax.ws.rs.Application", "org.apache.olingo.odata2.core.rest.app.ODataApplication");
+ odataServletHolder.setInitParameter(ODataServiceFactory.FACTORY_LABEL, factoryClass.getCanonicalName());
+
+ if (pathSplit > 0) {
+ odataServletHolder.setInitParameter(ODataServiceFactory.PATH_SPLIT_LABEL, Integer.toString(pathSplit));
+ }
+
+ final ServletContextHandler contextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
+ contextHandler.addServlet(odataServletHolder, path + "/*");
+
+ try {
+ final InetSocketAddress isa = new InetSocketAddress(DEFAULT_HOST, port);
+ server = new Server(isa);
+ server.setHandler(contextHandler);
+ server.start();
+ endpoint = new URI(DEFAULT_SCHEME, null, DEFAULT_HOST, isa.getPort(), path, null, null);
+ log.trace("Started server at endpoint " + endpoint.toASCIIString());
+ break;
+ } catch (final BindException e) {
+ log.trace("port is busy... " + port + " [" + e.getMessage() + "]");
+ }
+ }
+
+ if (!server.isStarted()) {
+ throw new BindException("no free port in range of [" + PORT_MIN + ".." + PORT_MAX + "]");
+ }
+
+ } catch (final Exception e) {
+ log.error(e);
+ throw new ServerRuntimeException(e);
+ }
+ }
+
+ public void startServer(final ODataService service) {
+ startServer(FitStaticServiceFactory.class);
+
+ if ((server != null) && server.isStarted()) {
+ FitStaticServiceFactory.bindService(this, service);
+ }
+ }
+
+ public void stopServer() {
+ try {
+ if (server != null) {
+ FitStaticServiceFactory.unbindService(this);
+ server.stop();
+ log.trace("Stopped server at endpoint " + getEndpoint().toASCIIString());
+ }
+ } catch (final Exception e) {
+ throw new ServerRuntimeException(e);
+ }
+ }
+}