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 2014/04/04 07:26:50 UTC
[46/51] [abbrv] git commit: [OLINGO-168] Tests for metadata
serialization
[OLINGO-168] Tests for metadata serialization
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/809519f9
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/809519f9
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/809519f9
Branch: refs/heads/olingo-206-validator
Commit: 809519f9d8baa8522d73dfcb7a590c4373480f93
Parents: 1e8eaec
Author: Christian Amend <ch...@apache.org>
Authored: Wed Apr 2 17:21:18 2014 +0200
Committer: Christian Amend <ch...@apache.org>
Committed: Wed Apr 2 17:21:48 2014 +0200
----------------------------------------------------------------------
.../core/edm/AbstractEdmComplexType.java | 63 +++---
.../commons/core/edm/AbstractEdmEntityType.java | 16 +-
.../core/edm/AbstractEdmNavigationProperty.java | 17 +-
.../core/edm/AbstractEdmStructuredType.java | 194 +++++++++---------
.../olingo/commons/core/edm/EdmTypeImpl.java | 45 +++--
.../core/edm/provider/EdmComplexTypeImpl.java | 2 -
.../core/edm/provider/EdmEntityTypeImpl.java | 45 +++--
.../edm/provider/EdmComplexTypeImplTest.java | 12 +-
.../edm/provider/EdmEntityTypeImplTest.java | 11 +-
.../core/edm/provider/EdmSchemaImplTest.java | 6 +-
.../serializer/xml/MetadataDocumentTest.java | 197 ++++++++++++++++++-
11 files changed, 416 insertions(+), 192 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/809519f9/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmComplexType.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmComplexType.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmComplexType.java
index 732f29f..5410582 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmComplexType.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmComplexType.java
@@ -1,18 +1,18 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
+ * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
+ * 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
- *
+ * 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
+ * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
@@ -27,29 +27,36 @@ import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
public abstract class AbstractEdmComplexType extends AbstractEdmStructuredType implements EdmComplexType {
- public AbstractEdmComplexType(
- final Edm edm,
- final FullQualifiedName fqn,
- final FullQualifiedName baseTypeName) {
- super(edm, fqn, EdmTypeKind.COMPLEX, baseTypeName);
- }
+ public AbstractEdmComplexType(
+ final Edm edm,
+ final FullQualifiedName typeName,
+ final FullQualifiedName baseTypeName) {
+ super(edm, typeName, EdmTypeKind.COMPLEX, baseTypeName);
+ }
- @Override
- protected EdmStructuredType buildBaseType(final FullQualifiedName baseTypeName) {
- // TODO: check for comment
- EdmComplexType baseType = null;
- if (baseTypeName != null) {
- baseType = edm.getComplexType(baseTypeName);
- if (baseType == null) {
- throw new EdmException("Can't find base type with name: " + baseTypeName + " for complex type: "
- + getName());
- }
- }
- return baseType;
+ @Override
+ protected EdmStructuredType buildBaseType(final FullQualifiedName baseTypeName) {
+ EdmComplexType baseType = null;
+ if (baseTypeName != null) {
+ baseType = edm.getComplexType(baseTypeName);
+ if (baseType == null) {
+ throw new EdmException("Can't find base type with name: " + baseTypeName + " for complex type: "
+ + getName());
+ }
}
+ return baseType;
+ }
+
+ @Override
+ public EdmComplexType getBaseType() {
+ checkBaseType();
+ return (EdmComplexType) baseType;
+ }
- @Override
- public EdmComplexType getBaseType() {
- return (EdmComplexType) baseType;
+ @Override
+ protected void checkBaseType() {
+ if (baseTypeName != null && baseType == null) {
+ baseType = buildBaseType(baseTypeName);
}
+ }
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/809519f9/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmEntityType.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmEntityType.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmEntityType.java
index eb9d170..60af07a 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmEntityType.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmEntityType.java
@@ -34,19 +34,15 @@ import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
public abstract class AbstractEdmEntityType extends AbstractEdmStructuredType implements EdmEntityType {
private final boolean hasStream;
-
protected EdmEntityType entityBaseType;
-
private final List<String> keyPredicateNames = new ArrayList<String>();
-
private final Map<String, EdmKeyPropertyRef> keyPropertyRefs = new LinkedHashMap<String, EdmKeyPropertyRef>();
-
private List<EdmKeyPropertyRef> keyPropertyRefsList;
- protected AbstractEdmEntityType(final Edm edm, final FullQualifiedName fqn, final FullQualifiedName baseTypeName,
+ protected AbstractEdmEntityType(final Edm edm, final FullQualifiedName typeName, final FullQualifiedName baseTypeName,
final boolean hashStream) {
- super(edm, fqn, EdmTypeKind.ENTITY, baseTypeName);
+ super(edm, typeName, EdmTypeKind.ENTITY, baseTypeName);
this.hasStream = hashStream;
}
@@ -76,11 +72,13 @@ public abstract class AbstractEdmEntityType extends AbstractEdmStructuredType im
@Override
public EdmEntityType getBaseType() {
+ checkBaseType();
return entityBaseType;
}
@Override
public List<String> getKeyPredicateNames() {
+ checkBaseType();
if (keyPredicateNames.isEmpty() && baseType != null) {
return entityBaseType.getKeyPredicateNames();
}
@@ -89,6 +87,7 @@ public abstract class AbstractEdmEntityType extends AbstractEdmStructuredType im
@Override
public List<EdmKeyPropertyRef> getKeyPropertyRefs() {
+ checkBaseType();
if (keyPropertyRefsList == null) {
keyPropertyRefsList = new ArrayList<EdmKeyPropertyRef>(keyPropertyRefs.values());
}
@@ -100,6 +99,7 @@ public abstract class AbstractEdmEntityType extends AbstractEdmStructuredType im
@Override
public EdmKeyPropertyRef getKeyPropertyRef(final String keyPredicateName) {
+ checkBaseType();
final EdmKeyPropertyRef edmKeyPropertyRef = keyPropertyRefs.get(keyPredicateName);
if (edmKeyPropertyRef == null && entityBaseType != null) {
return entityBaseType.getKeyPropertyRef(keyPredicateName);
@@ -111,4 +111,8 @@ public abstract class AbstractEdmEntityType extends AbstractEdmStructuredType im
public boolean hasStream() {
return hasStream;
}
+
+ protected void checkBaseType() {
+ //Current Client implementation doesn`t need this so I implemented an empty body here.
+ }
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/809519f9/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmNavigationProperty.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmNavigationProperty.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmNavigationProperty.java
index dca80bd..0d97ba6 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmNavigationProperty.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmNavigationProperty.java
@@ -1,18 +1,18 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
+ * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
+ * 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
- *
+ * 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
+ * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
@@ -62,7 +62,8 @@ public abstract class AbstractEdmNavigationProperty extends EdmElementImpl imple
for (String element : split) {
property = type.getNavigationProperty(element);
if (property == null) {
- throw new EdmException("Cannot find property with name: " + element + " at type " + type.getName());
+ throw new EdmException("Cannot find navigation property with name: " + element
+ + " at type " + type.getName());
}
type = (EdmStructuredType) property.getType();
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/809519f9/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmStructuredType.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmStructuredType.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmStructuredType.java
index a807052..a4cd47d 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmStructuredType.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmStructuredType.java
@@ -1,18 +1,18 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
+ * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
+ * 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
- *
+ * 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
+ * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
@@ -34,99 +34,105 @@ import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
public abstract class AbstractEdmStructuredType extends EdmTypeImpl implements EdmStructuredType {
- protected EdmStructuredType baseType;
-
- private List<String> propertyNames;
-
- private List<String> navigationPropertyNames;
-
- public AbstractEdmStructuredType(
- final Edm edm,
- final FullQualifiedName fqn,
- final EdmTypeKind kind,
- final FullQualifiedName baseTypeName) {
-
- super(edm, fqn, kind);
+ protected EdmStructuredType baseType;
+ protected FullQualifiedName baseTypeName;
+ private List<String> propertyNames;
+ private List<String> navigationPropertyNames;
+
+ public AbstractEdmStructuredType(
+ final Edm edm,
+ final FullQualifiedName typeName,
+ final EdmTypeKind kind,
+ final FullQualifiedName baseTypeName) {
+
+ super(edm, typeName, kind);
+ this.baseTypeName = baseTypeName;
+ }
+
+ protected abstract EdmStructuredType buildBaseType(FullQualifiedName baseTypeName);
+
+ protected abstract Map<String, EdmProperty> getProperties();
+
+ protected abstract Map<String, EdmNavigationProperty> getNavigationProperties();
+
+ protected abstract void checkBaseType();
+
+ @Override
+ public List<String> getPropertyNames() {
+ if (propertyNames == null) {
+ propertyNames = new ArrayList<String>();
+ checkBaseType();
+ if (baseType != null) {
+ propertyNames.addAll(baseType.getPropertyNames());
+ }
+ propertyNames.addAll(getProperties().keySet());
}
-
- protected abstract EdmStructuredType buildBaseType(FullQualifiedName baseTypeName);
-
- protected abstract Map<String, EdmProperty> getProperties();
-
- protected abstract Map<String, EdmNavigationProperty> getNavigationProperties();
-
- @Override
- public List<String> getPropertyNames() {
- if (propertyNames == null) {
- propertyNames = new ArrayList<String>();
- if (baseType != null) {
- propertyNames.addAll(baseType.getPropertyNames());
- }
- propertyNames.addAll(getProperties().keySet());
- }
- return propertyNames;
+ return propertyNames;
+ }
+
+ @Override
+ public List<String> getNavigationPropertyNames() {
+ if (navigationPropertyNames == null) {
+ navigationPropertyNames = new ArrayList<String>();
+ checkBaseType();
+ if (baseType != null) {
+ navigationPropertyNames.addAll(baseType.getNavigationPropertyNames());
+ }
+ navigationPropertyNames.addAll(getNavigationProperties().keySet());
}
-
- @Override
- public List<String> getNavigationPropertyNames() {
- if (navigationPropertyNames == null) {
- navigationPropertyNames = new ArrayList<String>();
- if (baseType != null) {
- navigationPropertyNames.addAll(baseType.getNavigationPropertyNames());
- }
- navigationPropertyNames.addAll(getNavigationProperties().keySet());
- }
- return navigationPropertyNames;
+ return navigationPropertyNames;
+ }
+
+ @Override
+ public EdmElement getProperty(final String name) {
+ EdmElement property = getStructuralProperty(name);
+ if (property == null) {
+ property = getNavigationProperty(name);
}
-
- @Override
- public EdmElement getProperty(final String name) {
- EdmElement property = getStructuralProperty(name);
- if (property == null) {
- property = getNavigationProperty(name);
- }
- return property;
+ return property;
+ }
+
+ @Override
+ public EdmProperty getStructuralProperty(final String name) {
+ EdmProperty property = null;
+ checkBaseType();
+ if (baseType != null) {
+ property = baseType.getStructuralProperty(name);
}
-
- @Override
- public EdmProperty getStructuralProperty(final String name) {
- EdmProperty property = null;
- if (baseType != null) {
- property = baseType.getStructuralProperty(name);
- }
- if (property == null) {
- property = getProperties().get(name);
- }
- return property;
+ if (property == null) {
+ property = getProperties().get(name);
}
-
- @Override
- public EdmNavigationProperty getNavigationProperty(final String name) {
- EdmNavigationProperty property = null;
- if (baseType != null) {
- property = baseType.getNavigationProperty(name);
- }
- if (property == null) {
- property = getNavigationProperties().get(name);
- }
- return property;
+ return property;
+ }
+
+ @Override
+ public EdmNavigationProperty getNavigationProperty(final String name) {
+ EdmNavigationProperty property = null;
+ checkBaseType();
+ if (baseType != null) {
+ property = baseType.getNavigationProperty(name);
}
+ if (property == null) {
+ property = getNavigationProperties().get(name);
+ }
+ return property;
+ }
+
+ @Override
+ public boolean compatibleTo(final EdmType targetType) {
+ EdmStructuredType sourceType = this;
+ if (targetType == null) {
+ throw new EdmException("Target type must not be null");
+ }
+ while (!sourceType.getName().equals(targetType.getName())
+ || !sourceType.getNamespace().equals(targetType.getNamespace())) {
- @Override
- public boolean compatibleTo(final EdmType targetType) {
- EdmStructuredType sourceType = this;
- if (targetType == null) {
- throw new EdmException("Target type must not be null");
- }
- while (!sourceType.getName().equals(targetType.getName())
- || !sourceType.getNamespace().equals(targetType.getNamespace())) {
-
- sourceType = sourceType.getBaseType();
- if (sourceType == null) {
- return false;
- }
- }
-
- return true;
+ sourceType = sourceType.getBaseType();
+ if (sourceType == null) {
+ return false;
+ }
}
+
+ return true;
+ }
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/809519f9/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeImpl.java
index ed20afa..6b9e7cb 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeImpl.java
@@ -1,18 +1,18 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
+ * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
+ * 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
- *
+ * 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
+ * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
@@ -25,23 +25,22 @@ import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
public class EdmTypeImpl extends EdmNamedImpl implements EdmType {
- protected final FullQualifiedName fqn;
+ protected final FullQualifiedName typeName;
+ protected final EdmTypeKind kind;
- protected final EdmTypeKind kind;
+ public EdmTypeImpl(final Edm edm, final FullQualifiedName typeName, final EdmTypeKind kind) {
+ super(edm, typeName.getName());
+ this.typeName = typeName;
+ this.kind = kind;
+ }
- public EdmTypeImpl(final Edm edm, final FullQualifiedName fqn, final EdmTypeKind kind) {
- super(edm, fqn.getName());
- this.fqn = fqn;
- this.kind = kind;
- }
+ @Override
+ public String getNamespace() {
+ return typeName.getNamespace();
+ }
- @Override
- public String getNamespace() {
- return fqn.getNamespace();
- }
-
- @Override
- public EdmTypeKind getKind() {
- return kind;
- }
+ @Override
+ public EdmTypeKind getKind() {
+ return kind;
+ }
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/809519f9/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmComplexTypeImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmComplexTypeImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmComplexTypeImpl.java
index c818c58..34df670 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmComplexTypeImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmComplexTypeImpl.java
@@ -36,8 +36,6 @@ public class EdmComplexTypeImpl extends AbstractEdmComplexType {
final Edm edm, final FullQualifiedName name, final ComplexType complexType) {
final EdmComplexTypeImpl instance = new EdmComplexTypeImpl(edm, name, complexType);
- instance.baseType = instance.buildBaseType(complexType.getBaseType());
-
return instance;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/809519f9/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmEntityTypeImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmEntityTypeImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmEntityTypeImpl.java
index 774af98..021d3bd 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmEntityTypeImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmEntityTypeImpl.java
@@ -36,34 +36,19 @@ import org.apache.olingo.server.api.edm.provider.PropertyRef;
public class EdmEntityTypeImpl extends AbstractEdmEntityType {
private final EdmStructuredTypeHelper helper;
+ private EntityType entityType;
+ private boolean baseTypeChecked = false;
public static EdmEntityTypeImpl getInstance(final Edm edm, final FullQualifiedName name,
final EntityType entityType) {
final EdmEntityTypeImpl instance = new EdmEntityTypeImpl(edm, name, entityType);
- instance.baseType = instance.buildBaseType(entityType.getBaseType());
-
- if (instance.baseType == null) {
- instance.entityBaseType = null;
-
- final List<PropertyRef> key = entityType.getKey();
- if (key != null) {
- final List<EdmKeyPropertyRef> edmKey = new ArrayList<EdmKeyPropertyRef>();
- for (PropertyRef ref : key) {
- edmKey.add(new EdmKeyPropertyRefImpl(instance, ref));
- }
- instance.setEdmKeyPropertyRef(edmKey);
- }
- } else {
- instance.entityBaseType = (EdmEntityType) instance.baseType;
- }
-
return instance;
}
private EdmEntityTypeImpl(final Edm edm, final FullQualifiedName name, final EntityType entityType) {
super(edm, name, entityType.getBaseType(), entityType.hasStream());
-
+ this.entityType = entityType;
helper = new EdmStructuredTypeHelperImpl(edm, entityType);
}
@@ -77,4 +62,28 @@ public class EdmEntityTypeImpl extends AbstractEdmEntityType {
return helper.getNavigationProperties();
}
+ @Override
+ protected void checkBaseType() {
+ if (!baseTypeChecked) {
+ if (baseTypeName != null) {
+ baseType = buildBaseType(baseTypeName);
+ }
+ if (baseType == null) {
+ entityBaseType = null;
+
+ final List<PropertyRef> key = entityType.getKey();
+ if (key != null) {
+ final List<EdmKeyPropertyRef> edmKey = new ArrayList<EdmKeyPropertyRef>();
+ for (PropertyRef ref : key) {
+ edmKey.add(new EdmKeyPropertyRefImpl(this, ref));
+ }
+ setEdmKeyPropertyRef(edmKey);
+ }
+ } else {
+ entityBaseType = (EdmEntityType) baseType;
+ }
+ baseTypeChecked = true;
+ }
+ }
+
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/809519f9/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmComplexTypeImplTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmComplexTypeImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmComplexTypeImplTest.java
index 5db5e98..cc3586d 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmComplexTypeImplTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmComplexTypeImplTest.java
@@ -59,7 +59,7 @@ public class EdmComplexTypeImplTest {
List<NavigationProperty> baseNavigationProperties = new ArrayList<NavigationProperty>();
baseNavigationProperties.add(new NavigationProperty().setName("nav1"));
baseComplexType.setName("BaseTypeName").setAbstract(false).setOpenType(false).setProperties(baseProperties)
- .setNavigationProperties(baseNavigationProperties);
+ .setNavigationProperties(baseNavigationProperties);
when(provider.getComplexType(baseName)).thenReturn(baseComplexType);
baseType = EdmComplexTypeImpl.getInstance(edm, baseName, baseComplexType);
@@ -71,7 +71,7 @@ public class EdmComplexTypeImplTest {
List<NavigationProperty> navigationProperties = new ArrayList<NavigationProperty>();
navigationProperties.add(new NavigationProperty().setName("nav2"));
complexType.setName("BaseTypeName").setAbstract(false).setOpenType(false).setProperties(properties)
- .setNavigationProperties(navigationProperties);
+ .setNavigationProperties(navigationProperties);
when(provider.getComplexType(name)).thenReturn(complexType);
type = EdmComplexTypeImpl.getInstance(edm, name, complexType);
@@ -155,10 +155,12 @@ public class EdmComplexTypeImplTest {
EdmProvider provider = mock(EdmProvider.class);
EdmProviderImpl edm = new EdmProviderImpl(provider);
FullQualifiedName typeWithNonexistingBaseTypeName = new FullQualifiedName("namespace", "typeName");
- ComplexType complexTypeForNonexistingBaseType
- = new ComplexType().setBaseType(new FullQualifiedName("wrong", "wrong"));
+ ComplexType complexTypeForNonexistingBaseType =
+ new ComplexType().setBaseType(new FullQualifiedName("wrong", "wrong"));
complexTypeForNonexistingBaseType.setName("typeName");
when(provider.getComplexType(typeWithNonexistingBaseTypeName)).thenReturn(complexTypeForNonexistingBaseType);
- EdmComplexTypeImpl.getInstance(edm, typeWithNonexistingBaseTypeName, complexTypeForNonexistingBaseType);
+ EdmComplexTypeImpl instance =
+ EdmComplexTypeImpl.getInstance(edm, typeWithNonexistingBaseTypeName, complexTypeForNonexistingBaseType);
+ instance.getBaseType();
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/809519f9/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntityTypeImplTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntityTypeImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntityTypeImplTest.java
index eeb8313..91a6018 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntityTypeImplTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntityTypeImplTest.java
@@ -96,21 +96,21 @@ public class EdmEntityTypeImplTest {
typeWithComplexKeyProvider.setName(typeWithComplexKeyName.getName());
List<Property> typeWithComplexKeyProperties = new ArrayList<Property>();
typeWithComplexKeyProperties.add(new Property().setName("Id").setType(
- EdmPrimitiveTypeKind.String.getFullQualifiedName()));
+ EdmPrimitiveTypeKind.String.getFullQualifiedName()));
List<Property> complexTypeProperties = new ArrayList<Property>();
complexTypeProperties.add(new Property().setName("ComplexPropName").setType(
- EdmPrimitiveTypeKind.String.getFullQualifiedName()));
+ EdmPrimitiveTypeKind.String.getFullQualifiedName()));
FullQualifiedName complexTypeName = new FullQualifiedName("namespace", "complexTypeName");
when(provider.getComplexType(complexTypeName)).thenReturn(
- new ComplexType().setName("complexTypeName").setProperties(complexTypeProperties));
+ new ComplexType().setName("complexTypeName").setProperties(complexTypeProperties));
typeWithComplexKeyProperties.add(new Property().setName("Comp").setType(complexTypeName));
typeWithComplexKeyProvider.setProperties(typeWithComplexKeyProperties);
List<PropertyRef> keyForTypeWithComplexKey = new ArrayList<PropertyRef>();
keyForTypeWithComplexKey.add(new PropertyRef().setPropertyName("Id"));
keyForTypeWithComplexKey.add(new PropertyRef().setPropertyName("ComplexPropName").setAlias("alias").setPath(
- "Comp/ComplexPropName"));
+ "Comp/ComplexPropName"));
typeWithComplexKeyProvider.setKey(keyForTypeWithComplexKey);
when(provider.getEntityType(typeWithComplexKeyName)).thenReturn(typeWithComplexKeyProvider);
@@ -255,7 +255,8 @@ public class EdmEntityTypeImplTest {
public void invalidBaseType() {
EdmProviderImpl edm = mock(EdmProviderImpl.class);
EntityType entityType = new EntityType().setName("n").setBaseType(new FullQualifiedName("wrong", "wrong"));
- EdmEntityTypeImpl.getInstance(edm, new FullQualifiedName("n", "n"), entityType);
+ EdmEntityTypeImpl instance = EdmEntityTypeImpl.getInstance(edm, new FullQualifiedName("n", "n"), entityType);
+ instance.getBaseType();
}
@Test
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/809519f9/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmSchemaImplTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmSchemaImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmSchemaImplTest.java
index f227796..5575fef 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmSchemaImplTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmSchemaImplTest.java
@@ -322,12 +322,14 @@ public class EdmSchemaImplTest {
List<EntityType> entityTypes = new ArrayList<EntityType>();
entityTypes.add(new EntityType().setName("entityType1"));
- entityTypes.add(new EntityType().setName("entityType2"));
+ entityTypes.add(new EntityType().setName("entityType2")
+ .setBaseType(new FullQualifiedName("namespace", "entityType1")));
providerSchema.setEntityTypes(entityTypes);
List<ComplexType> complexTypes = new ArrayList<ComplexType>();
complexTypes.add(new ComplexType().setName("complexType1"));
- complexTypes.add(new ComplexType().setName("complexType2"));
+ complexTypes.add(new ComplexType().setName("complexType2").setBaseType(
+ new FullQualifiedName("namespace", "complexType1")));
providerSchema.setComplexTypes(complexTypes);
List<Action> actions = new ArrayList<Action>();
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/809519f9/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java
index 9d08914..6a19364 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java
@@ -18,13 +18,41 @@
*/
package org.apache.olingo.server.core.serializer.xml;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import org.apache.olingo.commons.api.ODataException;
import org.apache.olingo.commons.api.ODataRuntimeException;
import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.edm.Target;
import org.apache.olingo.server.api.ODataServer;
+import org.apache.olingo.server.api.edm.provider.Action;
+import org.apache.olingo.server.api.edm.provider.ActionImport;
+import org.apache.olingo.server.api.edm.provider.ComplexType;
+import org.apache.olingo.server.api.edm.provider.EdmProvider;
+import org.apache.olingo.server.api.edm.provider.EntityContainer;
+import org.apache.olingo.server.api.edm.provider.EntitySet;
+import org.apache.olingo.server.api.edm.provider.EntityType;
+import org.apache.olingo.server.api.edm.provider.EnumMember;
+import org.apache.olingo.server.api.edm.provider.EnumType;
+import org.apache.olingo.server.api.edm.provider.Function;
+import org.apache.olingo.server.api.edm.provider.FunctionImport;
+import org.apache.olingo.server.api.edm.provider.NavigationProperty;
+import org.apache.olingo.server.api.edm.provider.NavigationPropertyBinding;
+import org.apache.olingo.server.api.edm.provider.Parameter;
+import org.apache.olingo.server.api.edm.provider.Property;
+import org.apache.olingo.server.api.edm.provider.ReturnType;
+import org.apache.olingo.server.api.edm.provider.Schema;
+import org.apache.olingo.server.api.edm.provider.Singleton;
+import org.apache.olingo.server.api.edm.provider.TypeDefinition;
import org.apache.olingo.server.api.serializer.ODataFormat;
import org.apache.olingo.server.api.serializer.ODataSerializer;
import org.apache.olingo.server.core.edm.provider.EdmProviderImpl;
@@ -48,10 +76,177 @@ public class MetadataDocumentTest {
}
@Test
+ public void writeMetadataWithLocalTestEdm() {
+ ODataSerializer serializer = ODataServer.newInstance().getSerializer(ODataFormat.XML);
+ Edm edm = new EdmProviderImpl(new TestMetadataProvider());
+ InputStream metadata = serializer.metadataDocument(edm);
+ assertNotNull(metadata);
+ String metadataString = StringUtils.inputStreamToString(metadata, false);
+ assertTrue(metadataString
+ .contains("<edmx:Edmx Version=\"4.0\" xmlns:edmx=\"http://docs.oasis-open.org/odata/ns/edmx\">"));
+
+ assertTrue(metadataString
+ .contains("<Schema xmlns=\"http://docs.oasis-open.org/odata/ns/edm\" " +
+ "Namespace=\"namespace\" Alias=\"alias\">"));
+
+ assertTrue(metadataString
+ .contains("<EntityType Name=\"ETBaseName\"><Property Name=\"P1\" Type=\"Edm.Int16\"/><NavigationProperty " +
+ "Name=\"N1\" Type=\"namespace.ETBaseName\" Nullable=\"true\" Partner=\"N1\"/></EntityType>"));
+
+ assertTrue(metadataString
+ .contains("<EntityType Name=\"ETDerivedName\" BaseType=\"namespace.ETBaseName\"><Property Name=\"P2\" " +
+ "Type=\"Edm.Int16\"/><NavigationProperty Name=\"N2\" Type=\"namespace.ETDerivedName\" Nullable=\"true\" " +
+ "Partner=\"N2\"/></EntityType>"));
+
+ assertTrue(metadataString
+ .contains("<ComplexType Name=\"CTBaseName\"><Property Name=\"P1\" Type=\"Edm.Int16\"/><NavigationProperty " +
+ "Name=\"N1\" Type=\"namespace.ETBaseName\" Nullable=\"true\" Partner=\"N1\"/></ComplexType>"));
+
+ assertTrue(metadataString
+ .contains("<ComplexType Name=\"CTDerivedName\" BaseType=\"namespace.CTBaseName\"><Property Name=\"P2\" " +
+ "Type=\"Edm.Int16\"/><NavigationProperty Name=\"N2\" Type=\"namespace.ETDerivedName\" Nullable=\"true\" " +
+ "Partner=\"N2\"/></ComplexType>"));
+
+ assertTrue(metadataString.contains("<TypeDefinition Name=\"typeDef\" Type=\"Edm.Int16\"/>"));
+
+ assertTrue(metadataString.contains("<Action Name=\"ActionWOParameter\" IsBound=\"false\"/>"));
+
+ assertTrue(metadataString
+ .contains("<Action Name=\"ActionName\" IsBound=\"true\"><Parameter Name=\"param\" Type=\"Edm.Int16\"/>" +
+ "<Parameter Name=\"param2\" Type=\"Collection(Edm.Int16)\"/><ReturnType Type=\"namespace.CTBaseName\"/>" +
+ "</Action>"));
+
+ assertTrue(metadataString
+ .contains("<Function Name=\"FunctionWOParameter\" IsBound=\"false\" IsComposable=\"false\"><ReturnType " +
+ "Type=\"namespace.CTBaseName\"/></Function>"));
+
+ assertTrue(metadataString
+ .contains("<Function Name=\"FunctionName\" IsBound=\"true\" IsComposable=\"false\"><Parameter Name=\"param\" " +
+ "Type=\"Edm.Int16\"/><Parameter Name=\"param2\" Type=\"Collection(Edm.Int16)\"/><ReturnType " +
+ "Type=\"namespace.CTBaseName\"/></Function>"));
+
+ assertTrue(metadataString.contains("<EntityContainer Name=\"container\">"));
+
+ assertTrue(metadataString
+ .contains("<EntitySet Name=\"EntitySetName\" EntityType=\"namespace.ETBaseName\"><NavigationPropertyBinding " +
+ "Path=\"N1\" Target=\"namespace.container/EntitySetName\"/></EntitySet>"));
+ assertTrue(metadataString
+ .contains("<Singleton Name=\"SingletonName\" EntityType=\"namespace.ETBaseName\"><NavigationPropertyBinding " +
+ "Path=\"N1\" Target=\"namespace.container/EntitySetName\"/></Singleton>"));
+
+ assertTrue(metadataString.contains("<ActionImport Name=\"actionImport\" Action=\"namespace.ActionWOParameter\"/>"));
+
+ assertTrue(metadataString
+ .contains("<FunctionImport Name=\"actionImport\" Function=\"namespace.FunctionName\" " +
+ "EntitySet=\"namespace.EntitySetName\" IncludeInServiceDocument=\"false\"/>"));
+
+ assertTrue(metadataString.contains("</EntityContainer></Schema></edmx:DataServices></edmx:Edmx>"));
+ }
+
+ @Test
public void writeMetadataWithTechnicalScenario() {
ODataSerializer serializer = ODataServer.newInstance().getSerializer(ODataFormat.XML);
EdmProviderImpl edm = new EdmProviderImpl(new EdmTechProvider());
InputStream metadata = serializer.metadataDocument(edm);
- StringUtils.inputStreamToString(metadata, false);
+ assertNotNull(metadata);
+ // The technical scenario is too big to verify. We are content for now to make sure we can serialize it.
+ // System.out.println(StringUtils.inputStreamToString(metadata, false));
+ }
+
+ private class TestMetadataProvider extends EdmProvider {
+
+ @Override
+ public List<Schema> getSchemas() throws ODataException {
+ Property p1 = new Property().setName("P1").setType(EdmPrimitiveTypeKind.Int16.getFullQualifiedName());
+ String ns = "namespace";
+ NavigationProperty n1 = new NavigationProperty().setName("N1")
+ .setType(new FullQualifiedName(ns, "ETBaseName")).setNullable(true).setPartner("N1");
+ Property p2 = new Property().setName("P2").setType(EdmPrimitiveTypeKind.Int16.getFullQualifiedName());
+ NavigationProperty n2 = new NavigationProperty().setName("N2")
+ .setType(new FullQualifiedName(ns, "ETDerivedName")).setNullable(true).setPartner("N2");
+ Schema schema = new Schema().setNamespace(ns).setAlias("alias");
+ List<ComplexType> complexTypes = new ArrayList<ComplexType>();
+ schema.setComplexTypes(complexTypes);
+ ComplexType ctBase =
+ new ComplexType().setName("CTBaseName").setProperties(Arrays.asList(p1)).setNavigationProperties(
+ Arrays.asList(n1));
+ complexTypes.add(ctBase);
+ ComplexType ctDerived =
+ new ComplexType().setName("CTDerivedName").setBaseType(new FullQualifiedName(ns, "CTBaseName"))
+ .setProperties(Arrays.asList(p2)).setNavigationProperties(Arrays.asList(n2));
+ complexTypes.add(ctDerived);
+
+ List<EntityType> entityTypes = new ArrayList<EntityType>();
+ schema.setEntityTypes(entityTypes);
+ EntityType etBase =
+ new EntityType().setName("ETBaseName").setProperties(Arrays.asList(p1)).setNavigationProperties(
+ Arrays.asList(n1));
+ entityTypes.add(etBase);
+ EntityType etDerived =
+ new EntityType().setName("ETDerivedName").setBaseType(new FullQualifiedName(ns, "ETBaseName"))
+ .setProperties(Arrays.asList(p2)).setNavigationProperties(Arrays.asList(n2));
+ entityTypes.add(etDerived);
+
+ List<Action> actions = new ArrayList<Action>();
+ schema.setActions(actions);
+ // TODO:EntitySetPath
+ actions.add((new Action().setName("ActionWOParameter")));
+ List<Parameter> parameters = new ArrayList<Parameter>();
+ parameters.add(new Parameter().setName("param").setType(EdmPrimitiveTypeKind.Int16.getFullQualifiedName()));
+ parameters.add(new Parameter().setName("param2").setType(EdmPrimitiveTypeKind.Int16.getFullQualifiedName())
+ .setCollection(true));
+ actions.add(new Action().setName("ActionName").setBound(true).setParameters(parameters).setReturnType(
+ new ReturnType().setType(new FullQualifiedName(ns, "CTBaseName"))));
+
+ List<Function> functions = new ArrayList<Function>();
+ schema.setFunctions(functions);
+ functions.add((new Function().setName("FunctionWOParameter")
+ .setReturnType(new ReturnType().setType(new FullQualifiedName(ns, "CTBaseName")))));
+ functions.add(new Function().setName("FunctionName").setBound(true).setParameters(parameters).setReturnType(
+ new ReturnType().setType(new FullQualifiedName(ns, "CTBaseName"))));
+
+ List<EnumType> enumTypes = new ArrayList<EnumType>();
+ schema.setEnumTypes(enumTypes);
+ List<EnumMember> members = new ArrayList<EnumMember>();
+ members.add(new EnumMember().setName("member").setValue("1"));
+ enumTypes.add(new EnumType().setName("EnumName").setFlags(true).setMembers(members));
+
+ List<TypeDefinition> typeDefinitions = new ArrayList<TypeDefinition>();
+ schema.setTypeDefinitions(typeDefinitions);
+ typeDefinitions.add(new TypeDefinition().setName("typeDef")
+ .setUnderlyingType(EdmPrimitiveTypeKind.Int16.getFullQualifiedName()));
+
+ EntityContainer container = new EntityContainer().setName("container");
+ schema.setEntityContainer(container);
+
+ List<ActionImport> actionImports = new ArrayList<ActionImport>();
+ container.setActionImports(actionImports);
+ actionImports.add(new ActionImport().setName("actionImport").setAction(
+ new FullQualifiedName(ns, "ActionWOParameter")).setEntitySet(
+ new Target().setEntityContainer(new FullQualifiedName(ns, "container")).setTargetName("EntitySetName")));
+
+ List<FunctionImport> functionImports = new ArrayList<FunctionImport>();
+ container.setFunctionImports(functionImports);
+ functionImports.add(new FunctionImport().setName("actionImport").setFunction(
+ new FullQualifiedName(ns, "FunctionName")).setEntitySet(
+ new Target().setEntityContainer(new FullQualifiedName(ns, "container")).setTargetName("EntitySetName")));
+
+ List<EntitySet> entitySets = new ArrayList<EntitySet>();
+ container.setEntitySets(entitySets);
+ List<NavigationPropertyBinding> nPB = new ArrayList<NavigationPropertyBinding>();
+ nPB.add(new NavigationPropertyBinding().setPath("N1").setTarget(
+ new Target().setEntityContainer(new FullQualifiedName(ns, "container")).setTargetName("EntitySetName")));
+ entitySets.add(new EntitySet().setName("EntitySetName").setType(new FullQualifiedName(ns, "ETBaseName"))
+ .setNavigationPropertyBindings(nPB));
+
+ List<Singleton> singletons = new ArrayList<Singleton>();
+ container.setSingletons(singletons);
+ singletons.add(new Singleton().setName("SingletonName").setType(new FullQualifiedName(ns, "ETBaseName"))
+ .setNavigationPropertyBindings(nPB));
+
+ List<Schema> schemas = new ArrayList<Schema>();
+ schemas.add(schema);
+ return schemas;
+ }
}
}