You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by il...@apache.org on 2014/05/22 13:43:21 UTC
[13/51] [abbrv] [partial] Removing /ODataJClient: merge complete
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/19f3792f/ODataJClient/proxy/src/main/java/com/msopentech/odatajclient/proxy/utils/ClassUtils.java
----------------------------------------------------------------------
diff --git a/ODataJClient/proxy/src/main/java/com/msopentech/odatajclient/proxy/utils/ClassUtils.java b/ODataJClient/proxy/src/main/java/com/msopentech/odatajclient/proxy/utils/ClassUtils.java
deleted file mode 100644
index 55e0b22..0000000
--- a/ODataJClient/proxy/src/main/java/com/msopentech/odatajclient/proxy/utils/ClassUtils.java
+++ /dev/null
@@ -1,142 +0,0 @@
-/**
- * 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 com.msopentech.odatajclient.proxy.utils;
-
-import com.msopentech.odatajclient.proxy.api.annotations.CompoundKey;
-import com.msopentech.odatajclient.proxy.api.annotations.EntityType;
-import com.msopentech.odatajclient.proxy.api.annotations.Key;
-import com.msopentech.odatajclient.proxy.api.annotations.KeyRef;
-import com.msopentech.odatajclient.proxy.api.annotations.Namespace;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.AccessibleObject;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
-import java.util.HashSet;
-import java.util.Set;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public final class ClassUtils {
-
- /**
- * Logger.
- */
- private static final Logger LOG = LoggerFactory.getLogger(ClassUtils.class);
-
- private ClassUtils() {
- // Empty private constructor for static utility classes
- }
-
- @SuppressWarnings("unchecked")
- public static Class<?> extractTypeArg(final Class<?> paramType) {
- final Type[] params = ((ParameterizedType) paramType.getGenericInterfaces()[0]).getActualTypeArguments();
- return (Class<?>) params[0];
- }
-
- public static Method findGetterByAnnotatedName(
- final Class<?> clazz, final Class<? extends Annotation> ann, final String name) {
- final Method[] methods = clazz.getMethods();
-
- Method result = null;
- for (int i = 0; i < methods.length && result == null; i++) {
- final Annotation annotation = methods[i].getAnnotation(ann);
- try {
- if ((annotation != null)
- && methods[i].getName().startsWith("get") // Assumption: getter is always prefixed by 'get' word
- && name.equals(ann.getMethod("name").invoke(annotation))) {
- result = methods[i];
- }
- } catch (Exception e) {
- LOG.warn("Error retrieving value annotation name for {}.{}", clazz.getName(), methods[i].getName());
- }
- }
-
- return result;
- }
-
- @SuppressWarnings("unchecked")
- public static <ANN extends Annotation> ANN getAnnotation(final Class<ANN> reference, final AccessibleObject obj) {
- final Annotation ann = obj.getAnnotation(reference);
- return ann == null ? null : (ANN) ann;
- }
-
- public static Class<?> getCompoundKeyRef(final Class<?> entityTypeRef) {
- if (entityTypeRef.getAnnotation(EntityType.class) == null) {
- throw new IllegalArgumentException("Invalid annotation for entity type " + entityTypeRef);
- }
-
- final Annotation ann = entityTypeRef.getAnnotation(KeyRef.class);
-
- return ann == null || ((KeyRef) ann).value().getAnnotation(CompoundKey.class) == null
- ? null
- : ((KeyRef) ann).value();
- }
-
- public static Class<?> getKeyRef(final Class<?> entityTypeRef) {
- Class<?> res = getCompoundKeyRef(entityTypeRef);
-
- if (res == null) {
- final Set<Method> keyGetters = new HashSet<Method>();
-
- for (Method method : entityTypeRef.getDeclaredMethods()) {
- if (method.getName().startsWith("get") && method.getAnnotation(Key.class) != null) {
- keyGetters.add(method);
- }
- }
-
- if (keyGetters.size() == 1) {
- res = keyGetters.iterator().next().getReturnType();
- } else {
- throw new IllegalStateException(entityTypeRef.getSimpleName() + "'s key reference not found");
- }
- }
-
- return res;
- }
-
- public static String getEntityTypeName(final Class<?> ref) {
- final Annotation annotation = ref.getAnnotation(EntityType.class);
- if (!(annotation instanceof EntityType)) {
- throw new IllegalArgumentException(ref.getPackage().getName()
- + " is not annotated as @" + EntityType.class.getSimpleName());
- }
- return ((EntityType) annotation).name();
- }
-
- public static String getNamespace(final Class<?> ref) {
- final Annotation annotation = ref.getAnnotation(Namespace.class);
- if (!(annotation instanceof Namespace)) {
- throw new IllegalArgumentException(ref.getName()
- + " is not annotated as @" + Namespace.class.getSimpleName());
- }
- return ((Namespace) annotation).value();
- }
-
- public static Void returnVoid()
- throws NoSuchMethodException, InstantiationException, IllegalAccessException,
- IllegalArgumentException, InvocationTargetException {
-
- final Constructor<Void> voidConstructor = Void.class.getDeclaredConstructor();
- voidConstructor.setAccessible(true);
- return voidConstructor.newInstance();
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/19f3792f/ODataJClient/proxy/src/main/java/com/msopentech/odatajclient/proxy/utils/EngineUtils.java
----------------------------------------------------------------------
diff --git a/ODataJClient/proxy/src/main/java/com/msopentech/odatajclient/proxy/utils/EngineUtils.java b/ODataJClient/proxy/src/main/java/com/msopentech/odatajclient/proxy/utils/EngineUtils.java
deleted file mode 100644
index c2e9c84..0000000
--- a/ODataJClient/proxy/src/main/java/com/msopentech/odatajclient/proxy/utils/EngineUtils.java
+++ /dev/null
@@ -1,419 +0,0 @@
-/**
- * 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 com.msopentech.odatajclient.proxy.utils;
-
-import com.msopentech.odatajclient.engine.client.ODataClient;
-import com.msopentech.odatajclient.engine.data.ODataCollectionValue;
-import com.msopentech.odatajclient.engine.data.ODataComplexValue;
-import com.msopentech.odatajclient.engine.data.ODataEntity;
-import com.msopentech.odatajclient.engine.data.ODataGeospatialValue;
-import com.msopentech.odatajclient.engine.data.ODataLink;
-import com.msopentech.odatajclient.engine.data.ODataPrimitiveValue;
-import com.msopentech.odatajclient.engine.data.ODataProperty;
-import com.msopentech.odatajclient.engine.data.ODataValue;
-import com.msopentech.odatajclient.engine.metadata.EdmType;
-import com.msopentech.odatajclient.engine.metadata.EdmV3Metadata;
-import com.msopentech.odatajclient.engine.metadata.EdmV3Type;
-import com.msopentech.odatajclient.engine.metadata.edm.EdmSimpleType;
-import com.msopentech.odatajclient.engine.metadata.edm.geospatial.Geospatial;
-import com.msopentech.odatajclient.proxy.api.AbstractComplexType;
-import com.msopentech.odatajclient.proxy.api.annotations.ComplexType;
-import com.msopentech.odatajclient.proxy.api.annotations.CompoundKeyElement;
-import com.msopentech.odatajclient.proxy.api.annotations.Key;
-import com.msopentech.odatajclient.proxy.api.annotations.Property;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.ServiceLoader;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public final class EngineUtils {
-
- /**
- * Logger.
- */
- private static final Logger LOG = LoggerFactory.getLogger(EngineUtils.class);
-
- private EngineUtils() {
- // Empty private constructor for static utility classes
- }
-
- public static ODataLink getNavigationLink(final String name, final ODataEntity entity) {
- ODataLink res = null;
- final List<ODataLink> links = entity.getNavigationLinks();
-
- for (int i = 0; i < links.size() && res == null; i++) {
- if (links.get(i).getName().equalsIgnoreCase(name)) {
- res = links.get(i);
- }
- }
- return res;
- }
-
- public static ODataValue getODataValue(
- final ODataClient client, final EdmV3Metadata metadata, final EdmType type, final Object obj) {
-
- final ODataValue value;
-
- if (type.isCollection()) {
- value = new ODataCollectionValue(type.getTypeExpression());
- final EdmType intType = new EdmV3Type(metadata, type.getBaseType());
- for (Object collectionItem : (Collection) obj) {
- if (intType.isSimpleType()) {
- ((ODataCollectionValue) value).add(
- getODataValue(client, metadata, intType, collectionItem).asPrimitive());
- } else if (intType.isComplexType()) {
- ((ODataCollectionValue) value).add(
- getODataValue(client, metadata, intType, collectionItem).asComplex());
- } else if (intType.isEnumType()) {
- // TODO: manage enum types
- throw new UnsupportedOperationException("Usupported enum type " + intType.getTypeExpression());
- } else {
- throw new UnsupportedOperationException("Usupported object type " + intType.getTypeExpression());
- }
- }
- } else if (type.isComplexType()) {
- value = new ODataComplexValue(type.getBaseType());
- if (obj.getClass().isAnnotationPresent(ComplexType.class)) {
- for (Method method : obj.getClass().getMethods()) {
- final Property complexPropertyAnn = method.getAnnotation(Property.class);
- try {
- if (complexPropertyAnn != null) {
- value.asComplex().add(
- getODataProperty(client, metadata, complexPropertyAnn.name(), method.invoke(obj)));
- }
- } catch (Exception ignore) {
- // ignore value
- LOG.warn("Error attaching complex field '{}'", complexPropertyAnn.name(), ignore);
- }
- }
- } else {
- throw new IllegalArgumentException(
- "Object '" + obj.getClass().getSimpleName() + "' is not a complex value");
- }
- } else if (type.isEnumType()) {
- // TODO: manage enum types
- throw new UnsupportedOperationException("Usupported enum type " + type.getTypeExpression());
- } else {
- final EdmSimpleType simpleType = EdmSimpleType.fromValue(type.getTypeExpression());
- if (simpleType.isGeospatial()) {
- value = new ODataGeospatialValue.Builder(client).setValue((Geospatial) obj).
- setType(simpleType).build();
- } else {
- value = new ODataPrimitiveValue.Builder(client).setValue(obj).setType(simpleType).build();
- }
- }
-
- return value;
- }
-
- private static ODataProperty getODataProperty(
- final ODataClient client, final EdmV3Metadata metadata, final String name, final Object obj) {
- final ODataProperty oprop;
-
- final EdmType type = getEdmType(client, metadata, obj);
- try {
- if (type == null || obj == null) {
- oprop = client.getObjectFactory().newPrimitiveProperty(name, null);
- } else if (type.isCollection()) {
- // create collection property
- oprop = client.getObjectFactory().newCollectionProperty(
- name, getODataValue(client, metadata, type, obj).asCollection());
- } else if (type.isSimpleType()) {
- // create a primitive property
- oprop = client.getObjectFactory().newPrimitiveProperty(
- name, getODataValue(client, metadata, type, obj).asPrimitive());
- } else if (type.isComplexType()) {
- // create a complex property
- oprop = client.getObjectFactory().newComplexProperty(
- name, getODataValue(client, metadata, type, obj).asComplex());
- } else if (type.isEnumType()) {
- // TODO: manage enum types
- throw new UnsupportedOperationException("Usupported enum type " + type.getTypeExpression());
- } else {
- throw new UnsupportedOperationException("Usupported object type " + type.getTypeExpression());
- }
-
- return oprop;
- } catch (Exception e) {
- throw new IllegalStateException(e);
- }
- }
-
- public static void addProperties(
- final ODataClient client,
- final EdmV3Metadata metadata,
- final Map<String, Object> changes,
- final ODataEntity entity) {
-
- for (Map.Entry<String, Object> property : changes.entrySet()) {
- // if the getter exists and it is annotated as expected then get value/value and add a new property
- final ODataProperty odataProperty = entity.getProperty(property.getKey());
- if (odataProperty != null) {
- entity.removeProperty(odataProperty);
- }
-
- entity.addProperty(getODataProperty(client, metadata, property.getKey(), property.getValue()));
- }
- }
-
- @SuppressWarnings("unchecked")
- private static void setPropertyValue(final Object bean, final Method getter, final Object value)
- throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
-
- // Assumption: setter is always prefixed by 'set' word
- final String setterName = getter.getName().replaceFirst("get", "set");
- bean.getClass().getMethod(setterName, getter.getReturnType()).invoke(bean, value);
- }
-
- public static Object getKey(
- final EdmV3Metadata metadata, final Class<?> entityTypeRef, final ODataEntity entity) {
- final Object res;
-
- if (entity.getProperties().isEmpty()) {
- res = null;
- } else {
- final Class<?> keyRef = ClassUtils.getCompoundKeyRef(entityTypeRef);
- if (keyRef == null) {
- final ODataProperty property = entity.getProperty(firstValidEntityKey(entityTypeRef));
- res = property == null || !property.hasPrimitiveValue()
- ? null
- : property.getPrimitiveValue().toValue();
-
- } else {
- try {
- res = keyRef.newInstance();
- populate(metadata, res, CompoundKeyElement.class, entity.getProperties().iterator());
- } catch (Exception e) {
- LOG.error("Error population compound key {}", keyRef.getSimpleName(), e);
- throw new IllegalArgumentException("Cannot populate compound key");
- }
- }
- }
-
- return res;
- }
-
- @SuppressWarnings("unchecked")
- public static void populate(
- final EdmV3Metadata metadata,
- final Object bean,
- final Class<? extends Annotation> getterAnn,
- final Iterator<ODataProperty> propItor) {
-
- if (bean != null) {
- while (propItor.hasNext()) {
- final ODataProperty property = propItor.next();
-
- final Method getter =
- ClassUtils.findGetterByAnnotatedName(bean.getClass(), getterAnn, property.getName());
-
- if (getter == null) {
- LOG.warn("Could not find any property annotated as {} in {}",
- property.getName(), bean.getClass().getName());
- } else {
- try {
- if (property.hasNullValue()) {
- setPropertyValue(bean, getter, null);
- }
- if (property.hasPrimitiveValue()) {
- setPropertyValue(bean, getter, property.getPrimitiveValue().toValue());
- }
- if (property.hasComplexValue()) {
- final Object complex = getter.getReturnType().newInstance();
- populate(metadata, complex, Property.class, property.getComplexValue().iterator());
- setPropertyValue(bean, getter, complex);
- }
- if (property.hasCollectionValue()) {
- final ParameterizedType collType = (ParameterizedType) getter.getGenericReturnType();
- final Class<?> collItemClass = (Class<?>) collType.getActualTypeArguments()[0];
-
- Collection collection = (Collection) getter.invoke(bean);
- if (collection == null) {
- collection = new ArrayList();
- setPropertyValue(bean, getter, collection);
- }
-
- final Iterator<ODataValue> collPropItor = property.getCollectionValue().iterator();
- while (collPropItor.hasNext()) {
- final ODataValue value = collPropItor.next();
- if (value.isPrimitive()) {
- collection.add(value.asPrimitive().toValue());
- }
- if (value.isComplex()) {
- final Object collItem = collItemClass.newInstance();
- populate(metadata, collItem, Property.class, value.asComplex().iterator());
- collection.add(collItem);
- }
- }
- }
- } catch (Exception e) {
- LOG.error("Could not set property {} on {}", getter, bean, e);
- }
- }
- }
- }
- }
-
- @SuppressWarnings("unchecked")
- public static Object getValueFromProperty(final EdmV3Metadata metadata, final ODataProperty property)
- throws InstantiationException, IllegalAccessException {
-
- final Object value;
-
- if (property == null || property.hasNullValue()) {
- value = null;
- } else if (property.hasCollectionValue()) {
- value = new ArrayList();
-
- final Iterator<ODataValue> collPropItor = property.getCollectionValue().iterator();
- while (collPropItor.hasNext()) {
- final ODataValue odataValue = collPropItor.next();
- if (odataValue.isPrimitive()) {
- ((Collection) value).add(odataValue.asPrimitive().toValue());
- }
- if (odataValue.isComplex()) {
- final Object collItem =
- buildComplexInstance(metadata, property.getName(), odataValue.asComplex().iterator());
- ((Collection) value).add(collItem);
- }
- }
- } else if (property.hasPrimitiveValue()) {
- value = property.getPrimitiveValue().toValue();
- } else if (property.hasComplexValue()) {
- value = buildComplexInstance(metadata, property.getComplexValue().getTypeName(), property.getComplexValue().
- iterator());
- } else {
- throw new IllegalArgumentException("Invalid property " + property);
- }
-
- return value;
- }
-
- @SuppressWarnings("unchecked")
- private static <C extends AbstractComplexType> C buildComplexInstance(
- final EdmV3Metadata metadata, final String name, final Iterator<ODataProperty> properties) {
-
- for (C complex : (Iterable<C>) ServiceLoader.load(AbstractComplexType.class)) {
- final ComplexType ann = complex.getClass().getAnnotation(ComplexType.class);
- final String fn = ann == null ? null : ClassUtils.getNamespace(complex.getClass()) + "." + ann.value();
-
- if (name.equals(fn)) {
- populate(metadata, complex, Property.class, properties);
- return complex;
- }
- }
-
- return null;
- }
-
- @SuppressWarnings({ "unchecked", "rawtypes" })
- public static Object getValueFromProperty(
- final EdmV3Metadata metadata, final ODataProperty property, final Type type)
- throws InstantiationException, IllegalAccessException {
-
- final Object value;
-
- if (property == null || property.hasNullValue()) {
- value = null;
- } else if (property.hasCollectionValue()) {
- value = new ArrayList();
-
- final ParameterizedType collType = (ParameterizedType) type;
- final Class<?> collItemClass = (Class<?>) collType.getActualTypeArguments()[0];
-
- final Iterator<ODataValue> collPropItor = property.getCollectionValue().iterator();
- while (collPropItor.hasNext()) {
- final ODataValue odataValue = collPropItor.next();
- if (odataValue.isPrimitive()) {
- ((Collection) value).add(odataValue.asPrimitive().toValue());
- }
- if (odataValue.isComplex()) {
- final Object collItem = collItemClass.newInstance();
- populate(metadata, collItem, Property.class, odataValue.asComplex().iterator());
- ((Collection) value).add(collItem);
- }
- }
- } else if (property.hasPrimitiveValue()) {
- value = property.getPrimitiveValue().toValue();
- } else if (property.hasComplexValue()) {
- value = ((Class<?>) type).newInstance();
- populate(metadata, value, Property.class, property.getComplexValue().iterator());
- } else {
- throw new IllegalArgumentException("Invalid property " + property);
- }
-
- return value;
- }
-
- private static String firstValidEntityKey(final Class<?> entityTypeRef) {
- for (Method method : entityTypeRef.getDeclaredMethods()) {
- if (method.getAnnotation(Key.class) != null) {
- final Annotation ann = method.getAnnotation(Property.class);
- if (ann != null) {
- return ((Property) ann).name();
- }
- }
- }
- return null;
- }
-
- private static EdmType getEdmType(final ODataClient client, final EdmV3Metadata metadata, final Object obj) {
- final EdmType res;
-
- if (obj == null) {
- res = null;
- } else if (Collection.class.isAssignableFrom(obj.getClass())) {
- if (((Collection) obj).isEmpty()) {
- res = new EdmV3Type(metadata, "Collection(" + getEdmType(client, metadata, "Edm.String"));
- } else {
- res = new EdmV3Type(metadata, "Collection("
- + getEdmType(client, metadata, ((Collection) obj).iterator().next()).getTypeExpression() + ")");
- }
- } else if (obj.getClass().isAnnotationPresent(ComplexType.class)) {
- final String ns = ClassUtils.getNamespace(obj.getClass());
- final ComplexType ann = obj.getClass().getAnnotation(ComplexType.class);
- res = new EdmV3Type(metadata, ns + "." + ann.value());
- } else {
- final EdmSimpleType simpleType = EdmSimpleType.fromObject(client.getWorkingVersion(), obj);
- res = new EdmV3Type(metadata, simpleType.toString());
- }
-
- return res;
- }
-
- public static URI getEditMediaLink(final String name, final ODataEntity entity) {
- for (ODataLink editMediaLink : entity.getEditMediaLinks()) {
- if (name.equalsIgnoreCase(editMediaLink.getName())) {
- return editMediaLink.getLink();
- }
- }
-
- throw new IllegalArgumentException("Invalid streamed property " + name);
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/19f3792f/ODataJClient/proxy/src/test/java/com/msopentech/odatajclient/proxy/AbstractTest.java
----------------------------------------------------------------------
diff --git a/ODataJClient/proxy/src/test/java/com/msopentech/odatajclient/proxy/AbstractTest.java b/ODataJClient/proxy/src/test/java/com/msopentech/odatajclient/proxy/AbstractTest.java
deleted file mode 100644
index 56dd285..0000000
--- a/ODataJClient/proxy/src/test/java/com/msopentech/odatajclient/proxy/AbstractTest.java
+++ /dev/null
@@ -1,185 +0,0 @@
-/**
- * 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 com.msopentech.odatajclient.proxy;
-
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import com.msopentech.odatajclient.proxy.api.EntityContainerFactory;
-import com.msopentech.odatajclient.proxy.api.context.EntityContext;
-import com.msopentech.odatajclient.proxy.defaultservice.microsoft.test.odata.services.astoriadefaultservice.DefaultContainer;
-import com.msopentech.odatajclient.proxy.defaultservice.microsoft.test.odata.services.astoriadefaultservice.types.Aliases;
-import com.msopentech.odatajclient.proxy.defaultservice.microsoft.test.odata.services.astoriadefaultservice.types.ContactDetails;
-import com.msopentech.odatajclient.proxy.defaultservice.microsoft.test.odata.services.astoriadefaultservice.types.Customer;
-import com.msopentech.odatajclient.proxy.defaultservice.microsoft.test.odata.services.astoriadefaultservice.types.Phone;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Locale;
-import java.util.Properties;
-import org.junit.BeforeClass;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public abstract class AbstractTest {
-
- /**
- * Logger.
- */
- protected static final Logger LOG = LoggerFactory.getLogger(AbstractTest.class);
-
- protected static final String TEST_PRODUCT_TYPE = "Microsoft.Test.OData.Services.AstoriaDefaultService.Product";
-
- protected static final String servicesODataServiceRootURL =
- "http://services.odata.org/V3/(S(csquyjnoaywmz5xcdbfhlc1p))/OData/OData.svc/";
-
- protected static String testDefaultServiceRootURL;
-
- protected static String testActionOverloadingServiceRootURL;
-
- protected static String testKeyAsSegmentServiceRootURL;
-
- protected static String testODataWriterDefaultServiceRootURL;
-
- protected static String testOpenTypesServiceRootURL;
-
- protected static String testPrimitiveKeysServiceRootURL;
-
- protected static String testOpenTypeServiceRootURL;
-
- protected static String testLargeModelServiceRootURL;
-
- protected static String testAuthServiceRootURL;
-
- protected final EntityContext entityContext = EntityContainerFactory.getContext().entityContext();
-
- protected static EntityContainerFactory containerFactory;
-
- protected static DefaultContainer container;
-
- /**
- * This is needed for correct number handling (Double, for example).
- */
- @BeforeClass
- public static void setEnglishLocale() {
- Locale.setDefault(Locale.ENGLISH);
- }
-
- @BeforeClass
- public static void setUpODataServiceRoot() throws IOException {
- String testBaseURL = null;
-
- InputStream propStream = null;
- try {
- propStream = AbstractTest.class.getResourceAsStream("/test.properties");
- final Properties props = new Properties();
- props.load(propStream);
-
- testBaseURL = props.getProperty("test.base.url");
- } catch (Exception e) {
- LOG.error("Could not load test.properties", e);
- } finally {
- if (propStream != null) {
- propStream.close();
- }
- }
- assertNotNull("Check value for the 'test.base.url' property", testBaseURL);
-
- testDefaultServiceRootURL = testBaseURL + "/DefaultService.svc";
- testActionOverloadingServiceRootURL = testBaseURL + "/ActionOverloadingService.svc";
- testKeyAsSegmentServiceRootURL = testBaseURL + "/KeyAsSegmentService.svc";
- testODataWriterDefaultServiceRootURL = testBaseURL + "/ODataWriterDefaultService.svc";
- testOpenTypeServiceRootURL = testBaseURL + "/OpenTypeService.svc";
- testPrimitiveKeysServiceRootURL = testBaseURL + "/PrimitiveKeys.svc";
- testLargeModelServiceRootURL = testBaseURL + "/LargeModelService.svc";
- testAuthServiceRootURL = "http://localhost:9080/DefaultService.svc";
-
- containerFactory = EntityContainerFactory.getV3Instance(testDefaultServiceRootURL);
- container = containerFactory.getEntityContainer(DefaultContainer.class);
- assertNotNull(container);
- }
-
- protected Customer getSampleCustomerProfile(
- final Integer id,
- final String sampleName,
- final DefaultContainer container) {
-
- final Customer customer = container.getCustomer().newCustomer();
-
- // add name attribute
- customer.setName(sampleName);
-
- // add key attribute
- customer.setCustomerId(id);
-
- final ContactDetails cd = new ContactDetails();
- cd.setAlternativeNames(Arrays.asList("alternative1", "alternative2"));
- cd.setEmailBag(Collections.<String>singleton("myname@mydomain.org"));
- cd.setMobilePhoneBag(Collections.<Phone>emptySet());
-
- final Aliases aliases = new Aliases();
- aliases.setAlternativeNames(Collections.<String>singleton("myAlternativeName"));
- cd.setContactAlias(aliases);
-
- final ContactDetails bcd = new ContactDetails();
- bcd.setAlternativeNames(Arrays.asList("alternative3", "alternative4"));
- bcd.setEmailBag(Collections.<String>emptySet());
- bcd.setMobilePhoneBag(Collections.<Phone>emptySet());
-
- customer.setPrimaryContactInfo(cd);
- customer.setBackupContactInfo(Collections.<ContactDetails>singletonList(bcd));
-
- return customer;
- }
-
- protected void checKSampleCustomerProfile(
- final Customer customer,
- final Integer id,
- final String sampleName) {
-
- assertEquals(id, customer.getCustomerId());
- assertNotNull(customer.getPrimaryContactInfo());
- assertFalse(customer.getBackupContactInfo().isEmpty());
-
- final ContactDetails cd = customer.getPrimaryContactInfo();
- final ContactDetails bcd = customer.getBackupContactInfo().iterator().next();
-
- assertTrue(cd.getAlternativeNames().contains("alternative1"));
- assertTrue(cd.getAlternativeNames().contains("alternative2"));
- assertEquals("myname@mydomain.org", cd.getEmailBag().iterator().next());
- assertEquals("myAlternativeName", cd.getContactAlias().getAlternativeNames().iterator().next());
- assertTrue(cd.getMobilePhoneBag().isEmpty());
-
- assertTrue(bcd.getAlternativeNames().contains("alternative3"));
- assertTrue(bcd.getAlternativeNames().contains("alternative4"));
- assertTrue(bcd.getEmailBag().isEmpty());
- assertTrue(bcd.getMobilePhoneBag().isEmpty());
- }
-
- protected Customer readCustomer(final DefaultContainer container, int id) {
- final Customer customer = container.getCustomer().get(id);
- assertNotNull(customer);
- assertEquals(Integer.valueOf(id), customer.getCustomerId());
-
- return customer;
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/19f3792f/ODataJClient/proxy/src/test/java/com/msopentech/odatajclient/proxy/ActionOverloadingTestITCase.java
----------------------------------------------------------------------
diff --git a/ODataJClient/proxy/src/test/java/com/msopentech/odatajclient/proxy/ActionOverloadingTestITCase.java b/ODataJClient/proxy/src/test/java/com/msopentech/odatajclient/proxy/ActionOverloadingTestITCase.java
deleted file mode 100644
index 36f2738..0000000
--- a/ODataJClient/proxy/src/test/java/com/msopentech/odatajclient/proxy/ActionOverloadingTestITCase.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/**
- * 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 com.msopentech.odatajclient.proxy;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import com.msopentech.odatajclient.proxy.actionoverloadingservice.microsoft.test.odata.services.astoriadefaultservice.DefaultContainer;
-import com.msopentech.odatajclient.proxy.actionoverloadingservice.microsoft.test.odata.services.astoriadefaultservice.types.Employee;
-import com.msopentech.odatajclient.proxy.actionoverloadingservice.microsoft.test.odata.services.astoriadefaultservice.types.EmployeeCollection;
-import com.msopentech.odatajclient.proxy.actionoverloadingservice.microsoft.test.odata.services.astoriadefaultservice.types.OrderLineKey;
-import com.msopentech.odatajclient.proxy.actionoverloadingservice.microsoft.test.odata.services.astoriadefaultservice.types.SpecialEmployee;
-import com.msopentech.odatajclient.proxy.actionoverloadingservice.microsoft.test.odata.services.astoriadefaultservice.types.SpecialEmployeeCollection;
-import com.msopentech.odatajclient.proxy.api.EntityContainerFactory;
-import org.junit.Test;
-
-/**
- * This is the unit test class to check actions overloading.
- */
-public class ActionOverloadingTestITCase extends AbstractTest {
-
- @Test
- public void retrieveProduct() {
- final DefaultContainer aocontainer = EntityContainerFactory.getV3Instance(testActionOverloadingServiceRootURL).
- getEntityContainer(DefaultContainer.class);
-
- int res = aocontainer.retrieveProduct();
- assertEquals(-10, res);
-
- EntityContainerFactory.getContext().detachAll();
-
- res = aocontainer.getProduct().get(-10).retrieveProduct();
- assertEquals(-10, res);
-
- EntityContainerFactory.getContext().detachAll();
-
- final OrderLineKey key = new OrderLineKey();
- key.setOrderId(-10);
- key.setProductId(-10);
-
- res = aocontainer.getOrderLine().get(key).retrieveProduct();
- assertEquals(-10, res);
- }
-
- @Test
- public void increaseSalaries() {
- final DefaultContainer aocontainer = EntityContainerFactory.getV3Instance(testActionOverloadingServiceRootURL).
- getEntityContainer(DefaultContainer.class);
-
- EmployeeCollection ecoll = aocontainer.getPerson().getAll(EmployeeCollection.class);
- assertFalse(ecoll.isEmpty());
-
- Employee empl = ecoll.iterator().next();
- assertNotNull(empl);
-
- int key = empl.getPersonId();
- int salary = empl.getSalary();
-
- ecoll.increaseSalaries(5);
-
- EntityContainerFactory.getContext().detachAll();
-
- empl = aocontainer.getPerson().get(key, Employee.class);
- assertEquals(salary + 5, empl.getSalary().intValue());
-
- SpecialEmployeeCollection secoll = aocontainer.getPerson().getAll(SpecialEmployeeCollection.class);
- assertFalse(secoll.isEmpty());
-
- SpecialEmployee sempl = secoll.iterator().next();
- assertNotNull(sempl);
-
- key = sempl.getPersonId();
- salary = sempl.getSalary();
-
- secoll.increaseSalaries(5);
-
- EntityContainerFactory.getContext().detachAll();
-
- sempl = aocontainer.getPerson().get(key, SpecialEmployee.class);
- assertEquals(salary + 5, sempl.getSalary().intValue());
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/19f3792f/ODataJClient/proxy/src/test/java/com/msopentech/odatajclient/proxy/AsyncTestITCase.java
----------------------------------------------------------------------
diff --git a/ODataJClient/proxy/src/test/java/com/msopentech/odatajclient/proxy/AsyncTestITCase.java b/ODataJClient/proxy/src/test/java/com/msopentech/odatajclient/proxy/AsyncTestITCase.java
deleted file mode 100644
index 9744f82..0000000
--- a/ODataJClient/proxy/src/test/java/com/msopentech/odatajclient/proxy/AsyncTestITCase.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/**
- * 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 com.msopentech.odatajclient.proxy;
-
-import static com.msopentech.odatajclient.proxy.AbstractTest.container;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import com.msopentech.odatajclient.proxy.api.AsyncCall;
-import com.msopentech.odatajclient.proxy.api.Query;
-import com.msopentech.odatajclient.proxy.defaultservice.microsoft.test.odata.services.astoriadefaultservice.types.Employee;
-import com.msopentech.odatajclient.proxy.defaultservice.microsoft.test.odata.services.astoriadefaultservice.types.EmployeeCollection;
-import com.msopentech.odatajclient.proxy.defaultservice.microsoft.test.odata.services.astoriadefaultservice.types.Product;
-import com.msopentech.odatajclient.proxy.defaultservice.microsoft.test.odata.services.astoriadefaultservice.types.ProductCollection;
-import com.msopentech.odatajclient.proxy.defaultservice.microsoft.test.odata.services.astoriadefaultservice.types.SpecialEmployee;
-import com.msopentech.odatajclient.proxy.defaultservice.microsoft.test.odata.services.astoriadefaultservice.types.SpecialEmployeeCollection;
-import java.util.UUID;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
-import org.junit.Test;
-
-public class AsyncTestITCase extends AbstractTest {
-
- @Test
- public void retrieveEntitySet() throws InterruptedException, ExecutionException {
- final Future<ProductCollection> futureProds =
- new AsyncCall<ProductCollection>(containerFactory.getConfiguration()) {
-
- @Override
- public ProductCollection call() {
- return container.getProduct().getAll();
- }
- };
- assertNotNull(futureProds);
-
- while (!futureProds.isDone()) {
- }
-
- final ProductCollection products = futureProds.get();
- assertNotNull(products);
- assertFalse(products.isEmpty());
- for (Product product : products) {
- assertNotNull(product);
- }
- }
-
- @Test
- public void updateEntity() throws InterruptedException, ExecutionException {
- final String random = UUID.randomUUID().toString();
-
- final Product product = container.getProduct().get(-10);
- product.setDescription("AsyncTest#updateEntity " + random);
-
- final Future<Void> futureFlush = new AsyncCall<Void>(containerFactory.getConfiguration()) {
-
- @Override
- public Void call() {
- container.flush();
- return null;
- }
- };
- assertNotNull(futureFlush);
-
- while (!futureFlush.isDone()) {
- }
-
- final Future<Product> futureProd = new AsyncCall<Product>(containerFactory.getConfiguration()) {
-
- @Override
- public Product call() {
- return container.getProduct().get(-10);
- }
- };
-
- assertEquals("AsyncTest#updateEntity " + random, futureProd.get().getDescription());
- }
-
- @Test
- public void polymorphQuery() throws Exception {
- final Future<Query<Employee, EmployeeCollection>> queryEmployee =
- new AsyncCall<Query<Employee, EmployeeCollection>>(containerFactory.getConfiguration()) {
-
- @Override
- public Query<Employee, EmployeeCollection> call() {
- return container.getPerson().createQuery(EmployeeCollection.class);
- }
- };
- assertFalse(queryEmployee.get().getResult().isEmpty());
-
- final Future<Query<SpecialEmployee, SpecialEmployeeCollection>> querySpecialEmployee =
- new AsyncCall<Query<SpecialEmployee, SpecialEmployeeCollection>>(containerFactory.getConfiguration()) {
-
- @Override
- public Query<SpecialEmployee, SpecialEmployeeCollection> call() {
- return container.getPerson().createQuery(SpecialEmployeeCollection.class);
- }
- };
- assertFalse(querySpecialEmployee.get().getResult().isEmpty());
-
- assertTrue(container.getPerson().getAll().size()
- > queryEmployee.get().getResult().size() + querySpecialEmployee.get().getResult().size());
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/19f3792f/ODataJClient/proxy/src/test/java/com/msopentech/odatajclient/proxy/AuthEntityRetrieveTestITCase.java
----------------------------------------------------------------------
diff --git a/ODataJClient/proxy/src/test/java/com/msopentech/odatajclient/proxy/AuthEntityRetrieveTestITCase.java b/ODataJClient/proxy/src/test/java/com/msopentech/odatajclient/proxy/AuthEntityRetrieveTestITCase.java
deleted file mode 100644
index 46ed120..0000000
--- a/ODataJClient/proxy/src/test/java/com/msopentech/odatajclient/proxy/AuthEntityRetrieveTestITCase.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/**
- * 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 com.msopentech.odatajclient.proxy;
-
-import static org.junit.Assert.assertNotNull;
-
-import com.msopentech.odatajclient.engine.client.http.AbstractBasicAuthHttpClientFactory;
-import com.msopentech.odatajclient.engine.client.http.DefaultHttpClientFactory;
-import com.msopentech.odatajclient.proxy.api.EntityContainerFactory;
-import com.msopentech.odatajclient.proxy.defaultservice.microsoft.test.odata.services.astoriadefaultservice.DefaultContainer;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-
-public class AuthEntityRetrieveTestITCase extends EntityRetrieveTestITCase {
-
- @BeforeClass
- public static void enableBasicAuth() {
- containerFactory.getConfiguration().setHttpClientFactory(new AbstractBasicAuthHttpClientFactory() {
-
- private static final long serialVersionUID = 1325970029455062815L;
-
- @Override
- protected String getUsername() {
- return "odatajclient";
- }
-
- @Override
- protected String getPassword() {
- return "odatajclient";
- }
- });
- }
-
- @AfterClass
- public static void disableBasicAuth() {
- containerFactory.getConfiguration().setHttpClientFactory(new DefaultHttpClientFactory());
- }
-
- @BeforeClass
- public static void setupContaner() {
- containerFactory = EntityContainerFactory.getV3Instance(testAuthServiceRootURL);
- container = containerFactory.getEntityContainer(DefaultContainer.class);
- assertNotNull(container);
- }
-
- @Override
- protected DefaultContainer getContainer() {
- return container;
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/19f3792f/ODataJClient/proxy/src/test/java/com/msopentech/odatajclient/proxy/ContextTestITCase.java
----------------------------------------------------------------------
diff --git a/ODataJClient/proxy/src/test/java/com/msopentech/odatajclient/proxy/ContextTestITCase.java b/ODataJClient/proxy/src/test/java/com/msopentech/odatajclient/proxy/ContextTestITCase.java
deleted file mode 100644
index b8a3c55..0000000
--- a/ODataJClient/proxy/src/test/java/com/msopentech/odatajclient/proxy/ContextTestITCase.java
+++ /dev/null
@@ -1,462 +0,0 @@
-/**
- * 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 com.msopentech.odatajclient.proxy;
-
-import static org.junit.Assert.fail;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
-import com.msopentech.odatajclient.proxy.api.annotations.NavigationProperty;
-import com.msopentech.odatajclient.proxy.api.context.AttachedEntityStatus;
-import com.msopentech.odatajclient.proxy.api.impl.EntityTypeInvocationHandler;
-import com.msopentech.odatajclient.proxy.defaultservice.microsoft.test.odata.services.astoriadefaultservice.types.ContactDetails;
-import com.msopentech.odatajclient.proxy.defaultservice.microsoft.test.odata.services.astoriadefaultservice.types.Customer;
-import com.msopentech.odatajclient.proxy.defaultservice.microsoft.test.odata.services.astoriadefaultservice.types.CustomerInfo;
-import com.msopentech.odatajclient.proxy.defaultservice.microsoft.test.odata.services.astoriadefaultservice.types.Login;
-import com.msopentech.odatajclient.proxy.defaultservice.microsoft.test.odata.services.astoriadefaultservice.types.Order;
-import com.msopentech.odatajclient.proxy.defaultservice.microsoft.test.odata.services.astoriadefaultservice.types.OrderCollection;
-import com.msopentech.odatajclient.proxy.defaultservice.microsoft.test.odata.services.astoriadefaultservice.types.Phone;
-import java.lang.reflect.Proxy;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import org.junit.Test;
-
-/**
- * This is the unit test class to check entity retrieve operations.
- */
-public class ContextTestITCase extends AbstractTest {
-
- @Test
- public void attachDetachNewEntity() {
- final Customer customer1 = container.getCustomer().newCustomer();
- final Customer customer2 = container.getCustomer().newCustomer();
-
- final EntityTypeInvocationHandler source1 =
- (EntityTypeInvocationHandler) Proxy.getInvocationHandler(customer1);
- final EntityTypeInvocationHandler source2 =
- (EntityTypeInvocationHandler) Proxy.getInvocationHandler(customer2);
-
- assertTrue(entityContext.isAttached(source1));
- assertTrue(entityContext.isAttached(source2));
-
- entityContext.detach(source1);
- assertFalse(entityContext.isAttached(source1));
- assertTrue(entityContext.isAttached(source2));
-
- entityContext.detach(source2);
- assertFalse(entityContext.isAttached(source1));
- assertFalse(entityContext.isAttached(source2));
- }
-
- @Test
- public void attachDetachExistingEntity() {
- final Customer customer1 = container.getCustomer().get(-10);
- final Customer customer2 = container.getCustomer().get(-9);
- final Customer customer3 = container.getCustomer().get(-10);
-
- final EntityTypeInvocationHandler source1 =
- (EntityTypeInvocationHandler) Proxy.getInvocationHandler(customer1);
- final EntityTypeInvocationHandler source2 =
- (EntityTypeInvocationHandler) Proxy.getInvocationHandler(customer2);
- final EntityTypeInvocationHandler source3 =
- (EntityTypeInvocationHandler) Proxy.getInvocationHandler(customer3);
-
- assertFalse(entityContext.isAttached(source1));
- assertFalse(entityContext.isAttached(source2));
- assertFalse(entityContext.isAttached(source3));
-
- entityContext.attach(source1);
- assertTrue(entityContext.isAttached(source1));
- assertFalse(entityContext.isAttached(source2));
- assertTrue(entityContext.isAttached(source3));
-
- entityContext.attach(source2);
- assertTrue(entityContext.isAttached(source1));
- assertTrue(entityContext.isAttached(source2));
- assertTrue(entityContext.isAttached(source3));
-
- try {
- entityContext.attach(source3);
- fail();
- } catch (IllegalStateException ignore) {
- // ignore
- }
-
- entityContext.detach(source1);
- assertFalse(entityContext.isAttached(source1));
- assertTrue(entityContext.isAttached(source2));
- assertFalse(entityContext.isAttached(source3));
-
- entityContext.detach(source2);
- assertFalse(entityContext.isAttached(source1));
- assertFalse(entityContext.isAttached(source2));
- assertFalse(entityContext.isAttached(source3));
- }
-
- @Test
- public void linkTargetExisting() {
- final Customer customer = container.getCustomer().newCustomer();
- final CustomerInfo customerInfo = container.getCustomerInfo().get(11);
-
- customer.setInfo(customerInfo);
-
- assertNotNull(customer.getInfo());
-
- final EntityTypeInvocationHandler source =
- (EntityTypeInvocationHandler) Proxy.getInvocationHandler(customer);
- final EntityTypeInvocationHandler target =
- (EntityTypeInvocationHandler) Proxy.getInvocationHandler(customerInfo);
-
- assertTrue(entityContext.isAttached(source));
- assertEquals(AttachedEntityStatus.NEW, entityContext.getStatus(source));
- assertTrue(entityContext.isAttached(target));
- assertEquals(AttachedEntityStatus.LINKED, entityContext.getStatus(target));
-
- checkUnidirectional("Info", source, "Customer", target, false);
-
- entityContext.detachAll();
-
- assertFalse(entityContext.isAttached(source));
- assertFalse(entityContext.isAttached(target));
- }
-
- @Test
- public void linkSourceExisting() {
- final Customer customer = container.getCustomer().get(-10);;
- final CustomerInfo customerInfo = container.getCustomerInfo().newCustomerInfo();
-
- customer.setInfo(customerInfo);
-
- assertNotNull(customer.getInfo());
-
- final EntityTypeInvocationHandler source =
- (EntityTypeInvocationHandler) Proxy.getInvocationHandler(customer);
- final EntityTypeInvocationHandler target =
- (EntityTypeInvocationHandler) Proxy.getInvocationHandler(customerInfo);
-
- assertTrue(entityContext.isAttached(source));
- assertEquals(AttachedEntityStatus.CHANGED, entityContext.getStatus(source));
- assertTrue(entityContext.isAttached(target));
- assertEquals(AttachedEntityStatus.NEW, entityContext.getStatus(target));
-
- checkUnidirectional("Info", source, "Customer", target, false);
-
- entityContext.detachAll();
-
- assertFalse(entityContext.isAttached(source));
- assertFalse(entityContext.isAttached(target));
- }
-
- @Test
- public void linkBothExisting() {
- final Customer customer = container.getCustomer().get(-10);
- final CustomerInfo customerInfo = container.getCustomerInfo().get(12);
-
- customer.setInfo(customerInfo);
-
- assertNotNull(customer.getInfo());
-
- final EntityTypeInvocationHandler source =
- (EntityTypeInvocationHandler) Proxy.getInvocationHandler(customer);
- final EntityTypeInvocationHandler target =
- (EntityTypeInvocationHandler) Proxy.getInvocationHandler(customerInfo);
-
- assertTrue(entityContext.isAttached(source));
- assertEquals(AttachedEntityStatus.CHANGED, entityContext.getStatus(source));
- assertTrue(entityContext.isAttached(target));
- assertEquals(AttachedEntityStatus.LINKED, entityContext.getStatus(target));
-
- checkUnidirectional("Info", source, "Customer", target, false);
-
- entityContext.detachAll();
-
- assertFalse(entityContext.isAttached(source));
- assertFalse(entityContext.isAttached(target));
- }
-
- @Test
- public void linkEntitySet() {;
- final Customer customer = container.getCustomer().newCustomer();
-
- final OrderCollection toBeLinked = container.getOrder().newOrderCollection();
- toBeLinked.add(container.getOrder().newOrder());
- toBeLinked.add(container.getOrder().newOrder());
- toBeLinked.add(container.getOrder().newOrder());
-
- customer.setOrders(toBeLinked);
- assertNotNull(customer.getOrders());
- assertEquals(3, customer.getOrders().size());
-
- final EntityTypeInvocationHandler source =
- (EntityTypeInvocationHandler) Proxy.getInvocationHandler(customer);
-
- assertTrue(entityContext.isAttached(source));
- assertEquals(AttachedEntityStatus.NEW, entityContext.getStatus(source));
- assertEquals(3, ((Collection) (source.getLinkChanges().entrySet().iterator().next().getValue())).size());
-
- for (Order order : toBeLinked) {
- final EntityTypeInvocationHandler target =
- (EntityTypeInvocationHandler) Proxy.getInvocationHandler(order);
-
- assertTrue(entityContext.isAttached(target));
- assertEquals(AttachedEntityStatus.NEW, entityContext.getStatus(target));
- checkUnidirectional("Orders", source, "Customer", target, true);
- }
-
- entityContext.detachAll();
-
- assertFalse(entityContext.isAttached(source));
-
- for (Order order : toBeLinked) {
- assertFalse(entityContext.isAttached((EntityTypeInvocationHandler) Proxy.getInvocationHandler(order)));
- }
- }
-
- @Test
- public void addProperty() {
- final Customer customer = container.getCustomer().newCustomer();
- customer.setCustomerId(100);
-
- final ContactDetails cd = new ContactDetails();
- customer.setPrimaryContactInfo(cd);
-
- cd.setAlternativeNames(Arrays.asList("alternative1", "alternative2"));
-
- final ContactDetails bcd = new ContactDetails();
- customer.setBackupContactInfo(Collections.<ContactDetails>singletonList(bcd));
-
- bcd.setAlternativeNames(Arrays.asList("alternative3", "alternative4"));
-
- assertEquals(Integer.valueOf(100), customer.getCustomerId());
- assertNotNull(customer.getPrimaryContactInfo().getAlternativeNames());
- assertEquals(2, customer.getPrimaryContactInfo().getAlternativeNames().size());
- assertTrue(customer.getPrimaryContactInfo().getAlternativeNames().contains("alternative1"));
- assertEquals(2, customer.getBackupContactInfo().iterator().next().getAlternativeNames().size());
- assertTrue(customer.getBackupContactInfo().iterator().next().getAlternativeNames().contains("alternative4"));
-
- final EntityTypeInvocationHandler source = (EntityTypeInvocationHandler) Proxy.getInvocationHandler(customer);
-
- assertTrue(entityContext.isAttached(source));
- assertEquals(AttachedEntityStatus.NEW, entityContext.getStatus(source));
-
- entityContext.detachAll();
-
- assertFalse(entityContext.isAttached(source));
- }
-
- @Test
- public void readEntityInTheContext() {
- CustomerInfo customerInfo = container.getCustomerInfo().get(16);
- customerInfo.setInformation("some other info ...");
-
- assertEquals("some other info ...", customerInfo.getInformation());
-
- customerInfo = container.getCustomerInfo().get(16);
- assertEquals("some other info ...", customerInfo.getInformation());
-
- entityContext.detachAll();
- customerInfo = container.getCustomerInfo().get(16);
- assertNotEquals("some other info ...", customerInfo.getInformation());
- }
-
- @Test
- public void readAllWithEntityInTheContext() {
- CustomerInfo customerInfo = container.getCustomerInfo().get(16);
- customerInfo.setInformation("some other info ...");
-
- assertEquals("some other info ...", customerInfo.getInformation());
-
- boolean found = false;
- for (CustomerInfo info : container.getCustomerInfo().getAll()) {
- if (info.getCustomerInfoId() == 16) {
- assertEquals("some other info ...", customerInfo.getInformation());
- found = true;
- }
- }
- assertTrue(found);
-
- entityContext.detachAll();
-
- found = false;
- for (CustomerInfo info : container.getCustomerInfo().getAll()) {
- if (info.getCustomerInfoId() == 16) {
- assertNotEquals("some other info ...", info.getInformation());
- found = true;
- }
- }
- assertTrue(found);
- }
-
- @Test
- public void checkContextInCaseOfErrors() {
- final Login login = container.getLogin().newLogin();
-
- final EntityTypeInvocationHandler handler = (EntityTypeInvocationHandler) Proxy.getInvocationHandler(login);
-
- assertTrue(entityContext.isAttached(handler));
-
- try {
- container.flush();
- fail();
- } catch (Exception e) {
- // ignore
- }
-
- assertTrue(entityContext.isAttached(handler));
-
- login.setCustomerId(-10);
- login.setUsername("customer");
-
- container.flush();
- assertFalse(entityContext.isAttached(handler));
- assertNotNull(container.getLogin().get("customer"));
-
- container.getLogin().delete(login.getUsername());
- assertTrue(entityContext.isAttached(handler));
-
- container.flush();
- assertFalse(entityContext.isAttached(handler));
- assertNull(container.getLogin().get("customer"));
- }
-
- @Test
- public void flushTest() {
- Customer customer = container.getCustomer().newCustomer();
- customer.setCustomerId(300);
- customer.setName("samplename");
-
- final List<Integer> keys = new ArrayList<Integer>();
- keys.add(-200);
- keys.add(-201);
- keys.add(-202);
-
- final OrderCollection toBeLinked = container.getOrder().newOrderCollection();
- for (Integer key : keys) {
- final Order order = container.getOrder().newOrder();
- order.setOrderId(key);
- order.setCustomerId(300);
- order.setCustomer(customer);
- toBeLinked.add(order);
- }
-
- customer.setOrders(toBeLinked);
-
- final CustomerInfo customerInfo = container.getCustomerInfo().get(16);
- customerInfo.setInformation("some new info ...");
- customer.setInfo(customerInfo);
-
- final ContactDetails cd = new ContactDetails();
- cd.setAlternativeNames(Arrays.asList("alternative1", "alternative2"));
- cd.setEmailBag(Collections.<String>singleton("myemail@mydomain.org"));
- cd.setMobilePhoneBag(Collections.<Phone>emptySet());
-
- final ContactDetails bcd = new ContactDetails();
- bcd.setAlternativeNames(Arrays.asList("alternative3", "alternative4"));
- bcd.setEmailBag(Collections.<String>emptySet());
- bcd.setMobilePhoneBag(Collections.<Phone>emptySet());
-
- customer.setPrimaryContactInfo(cd);
- customer.setBackupContactInfo(Collections.<ContactDetails>singletonList(bcd));
-
- assertTrue(entityContext.isAttached((EntityTypeInvocationHandler) Proxy.getInvocationHandler(customerInfo)));
- assertTrue(entityContext.isAttached((EntityTypeInvocationHandler) Proxy.getInvocationHandler(customer)));
- for (Order linked : toBeLinked) {
- assertTrue(entityContext.isAttached((EntityTypeInvocationHandler) Proxy.getInvocationHandler(linked)));
- }
-
- container.flush();
-
- assertFalse(entityContext.isAttached((EntityTypeInvocationHandler) Proxy.getInvocationHandler(customerInfo)));
- assertFalse(entityContext.isAttached((EntityTypeInvocationHandler) Proxy.getInvocationHandler(customer)));
- for (Order linked : toBeLinked) {
- assertFalse(entityContext.isAttached((EntityTypeInvocationHandler) Proxy.getInvocationHandler(linked)));
- }
-
- assertEquals("some new info ...", container.getCustomerInfo().get(16).getInformation());
-
- container.getOrder().delete(toBeLinked);
- container.getCustomer().delete(customer.getCustomerId());
-
- assertTrue(entityContext.isAttached((EntityTypeInvocationHandler) Proxy.getInvocationHandler(customer)));
- for (Order linked : toBeLinked) {
- assertTrue(entityContext.isAttached((EntityTypeInvocationHandler) Proxy.getInvocationHandler(linked)));
- }
-
- container.flush();
-
- assertFalse(entityContext.isAttached((EntityTypeInvocationHandler) Proxy.getInvocationHandler(customer)));
- for (Order linked : toBeLinked) {
- assertFalse(entityContext.isAttached((EntityTypeInvocationHandler) Proxy.getInvocationHandler(linked)));
- }
- }
-
- private void checkUnlink(
- final String sourceName,
- final EntityTypeInvocationHandler source) {
- boolean found = false;
- for (Map.Entry<NavigationProperty, Object> property : source.getLinkChanges().entrySet()) {
- if (property.getKey().name().equals(sourceName)) {
- found = true;
- }
- }
- assertFalse(found);
- }
-
- private void checkLink(
- final String sourceName,
- final EntityTypeInvocationHandler source,
- final EntityTypeInvocationHandler target,
- final boolean isCollection) {
- boolean found = false;
- for (Map.Entry<NavigationProperty, Object> property : source.getLinkChanges().entrySet()) {
- if (property.getKey().name().equals(sourceName)) {
- if (isCollection) {
- found = false;
- for (Object proxy : (Collection) property.getValue()) {
- if (target.equals((EntityTypeInvocationHandler) Proxy.getInvocationHandler(proxy))) {
- found = true;
- }
- }
- } else {
- found = target.equals(
- (EntityTypeInvocationHandler) Proxy.getInvocationHandler(property.getValue()));
- }
- }
- }
- assertTrue(found);
- }
-
- private void checkUnidirectional(
- final String sourceName,
- final EntityTypeInvocationHandler source,
- final String targetName,
- final EntityTypeInvocationHandler target,
- final boolean isCollection) {
- checkLink(sourceName, source, target, isCollection);
- checkUnlink(targetName, target);
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/19f3792f/ODataJClient/proxy/src/test/java/com/msopentech/odatajclient/proxy/EntityCreateTestITCase.java
----------------------------------------------------------------------
diff --git a/ODataJClient/proxy/src/test/java/com/msopentech/odatajclient/proxy/EntityCreateTestITCase.java b/ODataJClient/proxy/src/test/java/com/msopentech/odatajclient/proxy/EntityCreateTestITCase.java
deleted file mode 100644
index af3f528..0000000
--- a/ODataJClient/proxy/src/test/java/com/msopentech/odatajclient/proxy/EntityCreateTestITCase.java
+++ /dev/null
@@ -1,198 +0,0 @@
-/**
- * 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 com.msopentech.odatajclient.proxy;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-import com.msopentech.odatajclient.proxy.defaultservice.microsoft.test.odata.services.astoriadefaultservice.types.Customer;
-import com.msopentech.odatajclient.proxy.defaultservice.microsoft.test.odata.services.astoriadefaultservice.types.Employee;
-import com.msopentech.odatajclient.proxy.defaultservice.microsoft.test.odata.services.astoriadefaultservice.types.Message;
-import com.msopentech.odatajclient.proxy.defaultservice.microsoft.test.odata.services.astoriadefaultservice.types.MessageKey;
-import com.msopentech.odatajclient.proxy.defaultservice.microsoft.test.odata.services.astoriadefaultservice.types.Order;
-import com.msopentech.odatajclient.proxy.defaultservice.microsoft.test.odata.services.astoriadefaultservice.types.OrderCollection;
-import org.junit.Test;
-
-/**
- * This is the unit test class to check entity create operations.
- */
-public class EntityCreateTestITCase extends AbstractTest {
-
- @Test
- public void create() {
- final String sampleName = "sample customer from proxy";
- final Integer id = 100;
-
- getSampleCustomerProfile(id, sampleName, container);
- container.flush();
-
- Customer actual = readCustomer(container, id);
- checKSampleCustomerProfile(actual, id, sampleName);
-
- container.getCustomer().delete(actual.getCustomerId());
- actual = container.getCustomer().get(id);
- assertNull(actual);
-
- entityContext.detachAll();
- actual = container.getCustomer().get(id);
- assertNotNull(actual);
-
- container.getCustomer().delete(actual.getCustomerId());
- container.flush();
-
- actual = container.getCustomer().get(id);
- assertNull(actual);
-
- entityContext.detachAll();
- actual = container.getCustomer().get(id);
- assertNull(actual);
- }
-
- @Test
- public void createEmployee() {
- final Integer id = 101;
-
- final Employee employee = container.getPerson().newEmployee();
- employee.setPersonId(id);
- employee.setName("sample employee from proxy");
- employee.setManagersPersonId(-9918);
- employee.setSalary(2147483647);
- employee.setTitle("CEO");
-
- container.flush();
-
- Employee actual = container.getPerson().get(id, Employee.class);
- assertNotNull(actual);
- assertEquals(id, actual.getPersonId());
-
- entityContext.detachAll();
- actual = container.getPerson().get(id, Employee.class);
- assertNotNull(actual);
-
- container.getPerson().delete(actual.getPersonId());
- container.flush();
-
- actual = container.getPerson().get(id, Employee.class);
- assertNull(actual);
-
- entityContext.detachAll();
- actual = container.getPerson().get(id, Employee.class);
- assertNull(actual);
- }
-
- @Test
- public void createWithNavigation() {
- final String sampleName = "sample customer from proxy with navigation";
- final Integer id = 101;
-
- final Customer original = getSampleCustomerProfile(id, sampleName, container);
- original.setInfo(container.getCustomerInfo().get(16));
- container.flush();
-
- Customer actual = readCustomer(container, id);
- checKSampleCustomerProfile(actual, id, sampleName);
- assertEquals(Integer.valueOf(16), actual.getInfo().getCustomerInfoId());
-
- container.getCustomer().delete(actual.getCustomerId());
- container.flush();
-
- actual = container.getCustomer().get(id);
- assertNull(actual);
- }
-
- @Test
- public void createWithBackNavigation() {
- final String sampleName = "sample customer from proxy with back navigation";
- final Integer id = 102;
-
- Order order = container.getOrder().newOrder();
- order.setCustomerId(id);
- order.setOrderId(id); // same id ...
-
- final Customer customer = getSampleCustomerProfile(id, sampleName, container);
-
- final OrderCollection orders = container.getOrder().newOrderCollection();
- orders.add(order);
-
- customer.setOrders(orders);
- order.setCustomer(customer);
- container.flush();
-
- assertEquals(id, order.getOrderId());
- assertEquals(id, order.getCustomerId());
-
- Customer actual = readCustomer(container, id);
- checKSampleCustomerProfile(actual, id, sampleName);
-
- assertEquals(1, actual.getOrders().size());
- assertEquals(id, actual.getOrders().iterator().next().getOrderId());
- assertEquals(id, actual.getOrders().iterator().next().getCustomerId());
-
- order = container.getOrder().get(id);
- assertNotNull(order);
- assertEquals(id, order.getCustomer().getCustomerId());
-
- container.getOrder().delete(actual.getOrders());
- container.flush();
-
- order = container.getOrder().get(id);
- assertNull(order);
-
- actual = readCustomer(container, id);
- assertTrue(actual.getOrders().isEmpty());
-
- container.getCustomer().delete(actual.getCustomerId());
- container.flush();
-
- actual = container.getCustomer().get(id);
- assertNull(actual);
- }
-
- @Test
- public void multiKey() {
- Message message = container.getMessage().newMessage();
- message.setMessageId(100);
- message.setFromUsername("fromusername");
- message.setToUsername("myusername");
- message.setIsRead(false);
- message.setSubject("test message");
- message.setBody("test");
-
- container.flush();
-
- MessageKey key = new MessageKey();
- key.setFromUsername("fromusername");
- key.setMessageId(100);
-
- message = container.getMessage().get(key);
- assertNotNull(message);
- assertEquals(Integer.valueOf(100), message.getMessageId());
- assertEquals("fromusername", message.getFromUsername());
- assertEquals("myusername", message.getToUsername());
- assertEquals("test message", message.getSubject());
- assertEquals("test", message.getBody());
-
- container.getMessage().delete(key);
- container.flush();
-
- assertNull(container.getMessage().get(key));
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/19f3792f/ODataJClient/proxy/src/test/java/com/msopentech/odatajclient/proxy/EntityRetrieveTestITCase.java
----------------------------------------------------------------------
diff --git a/ODataJClient/proxy/src/test/java/com/msopentech/odatajclient/proxy/EntityRetrieveTestITCase.java b/ODataJClient/proxy/src/test/java/com/msopentech/odatajclient/proxy/EntityRetrieveTestITCase.java
deleted file mode 100644
index c602043..0000000
--- a/ODataJClient/proxy/src/test/java/com/msopentech/odatajclient/proxy/EntityRetrieveTestITCase.java
+++ /dev/null
@@ -1,189 +0,0 @@
-/**
- * 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 com.msopentech.odatajclient.proxy;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import com.msopentech.odatajclient.engine.data.ODataTimestamp;
-import com.msopentech.odatajclient.engine.metadata.edm.geospatial.Geospatial;
-import com.msopentech.odatajclient.engine.metadata.edm.geospatial.Geospatial.Type;
-import com.msopentech.odatajclient.engine.metadata.edm.geospatial.MultiLineString;
-import com.msopentech.odatajclient.engine.metadata.edm.geospatial.Point;
-import com.msopentech.odatajclient.proxy.api.impl.EntityTypeInvocationHandler;
-import com.msopentech.odatajclient.proxy.defaultservice.microsoft.test.odata.services.astoriadefaultservice.DefaultContainer;
-import com.msopentech.odatajclient.proxy.defaultservice.microsoft.test.odata.services.astoriadefaultservice.types.AllSpatialTypes;
-import com.msopentech.odatajclient.proxy.defaultservice.microsoft.test.odata.services.astoriadefaultservice.types.ComputerDetail;
-import com.msopentech.odatajclient.proxy.defaultservice.microsoft.test.odata.services.astoriadefaultservice.types.ConcurrencyInfo;
-import com.msopentech.odatajclient.proxy.defaultservice.microsoft.test.odata.services.astoriadefaultservice.types.Contractor;
-import com.msopentech.odatajclient.proxy.defaultservice.microsoft.test.odata.services.astoriadefaultservice.types.ContractorCollection;
-import com.msopentech.odatajclient.proxy.defaultservice.microsoft.test.odata.services.astoriadefaultservice.types.Customer;
-import com.msopentech.odatajclient.proxy.defaultservice.microsoft.test.odata.services.astoriadefaultservice.types.CustomerInfo;
-import com.msopentech.odatajclient.proxy.defaultservice.microsoft.test.odata.services.astoriadefaultservice.types.Employee;
-import com.msopentech.odatajclient.proxy.defaultservice.microsoft.test.odata.services.astoriadefaultservice.types.EmployeeCollection;
-import com.msopentech.odatajclient.proxy.defaultservice.microsoft.test.odata.services.astoriadefaultservice.types.Message;
-import com.msopentech.odatajclient.proxy.defaultservice.microsoft.test.odata.services.astoriadefaultservice.types.MessageKey;
-import com.msopentech.odatajclient.proxy.defaultservice.microsoft.test.odata.services.astoriadefaultservice.types.Order;
-import com.msopentech.odatajclient.proxy.defaultservice.microsoft.test.odata.services.astoriadefaultservice.types.OrderCollection;
-import com.msopentech.odatajclient.proxy.defaultservice.microsoft.test.odata.services.astoriadefaultservice.types.Person;
-import com.msopentech.odatajclient.proxy.defaultservice.microsoft.test.odata.services.astoriadefaultservice.types.PersonCollection;
-import com.msopentech.odatajclient.proxy.defaultservice.microsoft.test.odata.services.astoriadefaultservice.types.Product;
-import com.msopentech.odatajclient.proxy.defaultservice.microsoft.test.odata.services.astoriadefaultservice.types.SpecialEmployee;
-import com.msopentech.odatajclient.proxy.defaultservice.microsoft.test.odata.services.astoriadefaultservice.types.SpecialEmployeeCollection;
-import java.lang.reflect.Proxy;
-import java.util.Collection;
-import org.apache.commons.lang3.StringUtils;
-import org.junit.Test;
-
-/**
- * This is the unit test class to check entity retrieve operations.
- */
-public class EntityRetrieveTestITCase extends AbstractTest {
-
- protected DefaultContainer getContainer() {
- return container;
- }
-
- @Test
- public void exists() {
- assertTrue(getContainer().getPerson().exists(-10));
- assertFalse(getContainer().getPerson().exists(-11));
- }
-
- @Test
- public void get() {
- readCustomer(getContainer(), -10);
- }
-
- @Test
- public void getAll() {
- final PersonCollection all = getContainer().getPerson().getAll();
- assertNotNull(all);
- assertFalse(all.isEmpty());
- for (Person person : all) {
- assertNotNull(person);
- }
-
- final EmployeeCollection employees = getContainer().getPerson().getAll(EmployeeCollection.class);
- assertNotNull(employees);
- assertFalse(employees.isEmpty());
- for (Employee employee : employees) {
- assertNotNull(employee);
- }
-
- final SpecialEmployeeCollection specialEmployees = getContainer().getPerson().getAll(
- SpecialEmployeeCollection.class);
- assertNotNull(specialEmployees);
- assertFalse(specialEmployees.isEmpty());
- for (SpecialEmployee employee : specialEmployees) {
- assertNotNull(employee);
- }
-
- final ContractorCollection contractors = getContainer().getPerson().getAll(ContractorCollection.class);
- assertNotNull(contractors);
- assertFalse(contractors.isEmpty());
- for (Contractor contractor : contractors) {
- assertNotNull(contractor);
- }
-
- assertTrue(employees.size() > specialEmployees.size());
- assertTrue(all.size() > employees.size() + contractors.size());
- }
-
- @Test
- public void navigate() {
- final Order order = getContainer().getOrder().get(-9);
- assertNotNull(order);
- assertEquals(Integer.valueOf(-9), order.getOrderId());
-
- final ConcurrencyInfo concurrency = order.getConcurrency();
- assertNotNull(concurrency);
- assertEquals("2012-02-12T11:32:50.5072026", concurrency.getQueriedDateTime().toString());
- assertEquals(Integer.valueOf(78), order.getCustomerId());
- }
-
- @Test
- public void withGeospatial() {
- final AllSpatialTypes allSpatialTypes = getContainer().getAllGeoTypesSet().get(-10);
- assertNotNull(allSpatialTypes);
- assertEquals(Integer.valueOf(-10), allSpatialTypes.getId());
-
- final MultiLineString geogMultiLine = allSpatialTypes.getGeogMultiLine();
- assertNotNull(geogMultiLine);
- assertEquals(Type.MULTILINESTRING, geogMultiLine.getType());
- assertEquals(Geospatial.Dimension.GEOGRAPHY, geogMultiLine.getDimension());
- assertFalse(geogMultiLine.isEmpty());
-
- final Point geogPoint = allSpatialTypes.getGeogPoint();
- assertNotNull(geogPoint);
- assertEquals(Type.POINT, geogPoint.getType());
- assertEquals(Geospatial.Dimension.GEOGRAPHY, geogPoint.getDimension());
- assertEquals(52.8606, geogPoint.getY(), 0);
- assertEquals(173.334, geogPoint.getX(), 0);
- }
-
- @Test
- public void withInlineEntry() {
- final Customer customer = readCustomer(getContainer(), -10);
- final CustomerInfo customerInfo = customer.getInfo();
- assertNotNull(customerInfo);
- assertEquals(Integer.valueOf(11), customerInfo.getCustomerInfoId());
- }
-
- @Test
- public void withInlineFeed() {
- final Customer customer = readCustomer(getContainer(), -10);
- final OrderCollection orders = customer.getOrders();
- assertFalse(orders.isEmpty());
- }
-
- @Test
- public void withActions() {
- final ComputerDetail computerDetail = getContainer().getComputerDetail().get(-10);
- assertEquals(Integer.valueOf(-10), computerDetail.getComputerDetailId());
-
- try {
- assertNotNull(ComputerDetail.class.getMethod("resetComputerDetailsSpecifications",
- Collection.class, ODataTimestamp.class));
- } catch (Exception e) {
- fail();
- }
- }
-
- @Test
- public void multiKey() {
- final MessageKey messageKey = new MessageKey();
- messageKey.setFromUsername("1");
- messageKey.setMessageId(-10);
-
- final Message message = getContainer().getMessage().get(messageKey);
- assertNotNull(message);
- assertEquals("1", message.getFromUsername());
- }
-
- @Test
- public void checkForETag() {
- Product product = getContainer().getProduct().get(-10);
- assertTrue(StringUtils.isNotBlank(
- ((EntityTypeInvocationHandler) Proxy.getInvocationHandler(product)).getETag()));
- }
-}