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/01 11:00:31 UTC
[19/52] [abbrv] [OLINGO-65] Implementation completed
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4780fc51/lib/client-core/src/main/java/org/apache/olingo/client/core/domain/ODataPrimitiveValueImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/domain/ODataPrimitiveValueImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/domain/ODataPrimitiveValueImpl.java
new file mode 100644
index 0000000..4f191d8
--- /dev/null
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/domain/ODataPrimitiveValueImpl.java
@@ -0,0 +1,174 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.client.core.domain;
+
+import java.sql.Timestamp;
+import java.util.Calendar;
+import org.apache.commons.lang3.builder.EqualsBuilder;
+import org.apache.commons.lang3.builder.HashCodeBuilder;
+import org.apache.olingo.client.api.domain.AbstractODataValue;
+import org.apache.olingo.client.api.domain.ODataPrimitiveValue;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
+import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
+import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
+
+public class ODataPrimitiveValueImpl extends AbstractODataValue implements ODataPrimitiveValue {
+
+ private static final long serialVersionUID = 8889282662298376036L;
+
+ public static class BuilderImpl implements Builder {
+
+ private final ODataServiceVersion version;
+
+ private final ODataPrimitiveValueImpl instance;
+
+ public BuilderImpl(final ODataServiceVersion version) {
+ this.version = version;
+ this.instance = new ODataPrimitiveValueImpl();
+ }
+
+ @Override
+ public BuilderImpl setType(final EdmPrimitiveTypeKind type) {
+ if (type != null && !type.getSupportedVersions().contains(version)) {
+ throw new IllegalArgumentException(String.format(
+ "Type %s not supported by OData version %s", type.toString(), version));
+ }
+ if (type == EdmPrimitiveTypeKind.Stream) {
+ throw new IllegalArgumentException(String.format(
+ "Cannot build a primitive value for %s", EdmPrimitiveTypeKind.Stream.toString()));
+ }
+ if (type != null && type.isGeospatial()) {
+ throw new IllegalArgumentException("Don't use this for geospatial types");
+ }
+
+ this.instance.typeKind = type == null ? EdmPrimitiveTypeKind.String : type;
+ this.instance.type = EdmPrimitiveTypeFactory.getNonGeoInstance(this.instance.typeKind);
+
+ return this;
+ }
+
+ @Override
+ public BuilderImpl setText(final String text) {
+ this.instance.text = text;
+ return this;
+ }
+
+ @Override
+ public BuilderImpl setValue(final Object value) {
+ this.instance.value = value;
+ return this;
+ }
+
+ @Override
+ public ODataPrimitiveValueImpl build() {
+ if (this.instance.text == null && this.instance.value == null) {
+ throw new IllegalArgumentException("Must provide either text or value");
+ }
+ if (this.instance.text != null && this.instance.value != null) {
+ throw new IllegalArgumentException("Cannot provide both text and value");
+ }
+
+ if (this.instance.type == null) {
+ setType(EdmPrimitiveTypeKind.String);
+ }
+
+ if (this.instance.text != null) {
+ final Class<?> returnType = this.instance.type.getDefaultType().isAssignableFrom(Calendar.class)
+ ? Timestamp.class : this.instance.type.getDefaultType();
+ try {
+ // TODO: when Edm is available, set facets when calling this method
+ this.instance.value = this.instance.type.valueOfString(
+ this.instance.text, null, null, 40, 25, null, returnType);
+ } catch (EdmPrimitiveTypeException e) {
+ throw new IllegalArgumentException(e);
+ }
+ }
+ if (this.instance.value != null) {
+ try {
+ // TODO: when Edm is available, set facets when calling this method
+ this.instance.text = this.instance.type.valueToString(
+ this.instance.value, null, null, 40, 25, null);
+ } catch (EdmPrimitiveTypeException e) {
+ throw new IllegalArgumentException(e);
+ }
+ }
+
+ return this.instance;
+ }
+ }
+
+ /**
+ * Type kind.
+ */
+ private EdmPrimitiveTypeKind typeKind;
+
+ /**
+ * Type.
+ */
+ private EdmPrimitiveType type;
+
+ /**
+ * Text value.
+ */
+ private String text;
+
+ /**
+ * Actual value.
+ */
+ private Object value;
+
+ @Override
+ public EdmPrimitiveTypeKind getTypeKind() {
+ return typeKind;
+ }
+
+ @Override
+ public EdmPrimitiveType getType() {
+ return type;
+ }
+
+ @Override
+ public Object toValue() {
+ return this.value;
+ }
+
+ @Override
+ public <T> T toCastValue(final Class<T> reference) throws EdmPrimitiveTypeException {
+ // TODO: when Edm is available, set facets when calling this method
+ return type.valueOfString(this.text, null, null, 40, 25, null, reference);
+ }
+
+ @Override
+ public String toString() {
+ return this.text;
+ }
+
+ @Override
+ public int hashCode() {
+ return HashCodeBuilder.reflectionHashCode(this);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return EqualsBuilder.reflectionEquals(this, obj);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4780fc51/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/AbstractODataBinder.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/AbstractODataBinder.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/AbstractODataBinder.java
index b185d5d..2c2cdea 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/AbstractODataBinder.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/AbstractODataBinder.java
@@ -22,8 +22,8 @@ import java.io.StringWriter;
import java.net.URI;
import java.util.Iterator;
import org.apache.commons.lang3.StringUtils;
-import org.apache.olingo.client.api.Constants;
import org.apache.olingo.client.api.CommonODataClient;
+import org.apache.olingo.client.api.Constants;
import org.apache.olingo.client.api.data.Entry;
import org.apache.olingo.client.api.data.Feed;
import org.apache.olingo.client.api.data.Link;
@@ -35,18 +35,15 @@ import org.apache.olingo.client.api.domain.ODataCollectionValue;
import org.apache.olingo.client.api.domain.ODataComplexValue;
import org.apache.olingo.client.api.domain.ODataEntity;
import org.apache.olingo.client.api.domain.ODataEntitySet;
-import org.apache.olingo.client.api.domain.ODataGeospatialValue;
import org.apache.olingo.client.api.domain.ODataInlineEntity;
import org.apache.olingo.client.api.domain.ODataInlineEntitySet;
import org.apache.olingo.client.api.domain.ODataLink;
import org.apache.olingo.client.api.domain.ODataOperation;
-import org.apache.olingo.client.api.domain.ODataPrimitiveValue;
import org.apache.olingo.client.api.domain.ODataProperty;
import org.apache.olingo.client.api.domain.ODataServiceDocument;
import org.apache.olingo.client.api.domain.ODataValue;
import org.apache.olingo.client.api.format.ODataPubFormat;
import org.apache.olingo.client.api.op.CommonODataBinder;
-import org.apache.olingo.client.api.utils.URIUtils;
import org.apache.olingo.client.core.data.CollectionValueImpl;
import org.apache.olingo.client.core.data.ComplexValueImpl;
import org.apache.olingo.client.core.data.GeospatialValueImpl;
@@ -54,6 +51,7 @@ import org.apache.olingo.client.core.data.JSONPropertyImpl;
import org.apache.olingo.client.core.data.LinkImpl;
import org.apache.olingo.client.core.data.NullValueImpl;
import org.apache.olingo.client.core.data.PrimitiveValueImpl;
+import org.apache.olingo.client.core.uri.URIUtils;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -216,11 +214,11 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
if (setType) {
if (property.hasPrimitiveValue()) {
- propertyResource.setType(property.getPrimitiveValue().getTypeName());
+ propertyResource.setType(property.getPrimitiveValue().getType().toString());
} else if (property.hasComplexValue()) {
- propertyResource.setType(property.getComplexValue().getTypeName());
+ propertyResource.setType(property.getComplexValue().getType());
} else if (property.hasCollectionValue()) {
- propertyResource.setType(property.getCollectionValue().getTypeName());
+ propertyResource.setType(property.getCollectionValue().getType());
}
}
@@ -233,12 +231,9 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
if (value == null) {
valueResource = new NullValueImpl();
} else if (value.isPrimitive()) {
- final ODataPrimitiveValue _value = value.asPrimitive();
- if (_value instanceof ODataGeospatialValue) {
- valueResource = new GeospatialValueImpl(((ODataGeospatialValue) _value).getGeospatial());
- } else {
- valueResource = new PrimitiveValueImpl(_value.toString());
- }
+ valueResource = new PrimitiveValueImpl(value.asPrimitive().toString());
+ } else if (value.isGeospatial()) {
+ valueResource = new GeospatialValueImpl(value.asGeospatial().toValue());
} else if (value.isComplex()) {
final ODataComplexValue _value = value.asComplex();
valueResource = new ComplexValueImpl();
@@ -375,12 +370,14 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
ODataValue value = null;
if (resource.getValue().isSimple()) {
- value = new ODataPrimitiveValue.Builder(client).setText(resource.getValue().asSimple().get()).
+ value = client.getPrimitiveValueBuilder().
+ setText(resource.getValue().asSimple().get()).
setType(resource.getType() == null
? null
: EdmPrimitiveTypeKind.valueOfFQN(client.getServiceVersion(), resource.getType())).build();
} else if (resource.getValue().isGeospatial()) {
- value = new ODataGeospatialValue.Builder(client).setValue(resource.getValue().asGeospatial().get()).
+ value = client.getGeospatialValueBuilder().
+ setValue(resource.getValue().asGeospatial().get()).
setType(resource.getType() == null
|| EdmPrimitiveTypeKind.Geography.getFullQualifiedName().toString().equals(resource.getType())
|| EdmPrimitiveTypeKind.Geometry.getFullQualifiedName().toString().equals(resource.getType())
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4780fc51/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/ODataObjectFactoryImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/ODataObjectFactoryImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/ODataObjectFactoryImpl.java
index 3104b8e..cc0b388 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/ODataObjectFactoryImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/ODataObjectFactoryImpl.java
@@ -25,6 +25,7 @@ import org.apache.olingo.client.api.domain.ODataCollectionValue;
import org.apache.olingo.client.api.domain.ODataComplexValue;
import org.apache.olingo.client.api.domain.ODataEntity;
import org.apache.olingo.client.api.domain.ODataEntitySet;
+import org.apache.olingo.client.api.domain.ODataGeospatialValue;
import org.apache.olingo.client.api.domain.ODataInlineEntity;
import org.apache.olingo.client.api.domain.ODataInlineEntitySet;
import org.apache.olingo.client.api.domain.ODataLink;
@@ -42,45 +43,21 @@ public class ODataObjectFactoryImpl implements ODataObjectFactory {
this.client = client;
}
- /**
- * Instantiates a new entity set.
- *
- * @return entity set.
- */
@Override
public ODataEntitySet newEntitySet() {
return new ODataEntitySet();
}
- /**
- * Instantiates a new entity set.
- *
- * @param next next link.
- * @return entity set.
- */
@Override
public ODataEntitySet newEntitySet(final URI next) {
return new ODataEntitySet(next);
}
- /**
- * Instantiates a new entity.
- *
- * @param name OData entity name.
- * @return entity.
- */
@Override
public ODataEntity newEntity(final String name) {
return new ODataEntity(name);
}
- /**
- * Instantiates a new entity.
- *
- * @param name OData entity name.
- * @param link self link.
- * @return entity.
- */
@Override
public ODataEntity newEntity(final String name, final URI link) {
final ODataEntity result = new ODataEntity(name);
@@ -88,14 +65,6 @@ public class ODataObjectFactoryImpl implements ODataObjectFactory {
return result;
}
- /**
- * Instantiates a new in-line entity set.
- *
- * @param name name.
- * @param link edit link.
- * @param entitySet entity set.
- * @return in-line entity set.
- */
@Override
public ODataInlineEntitySet newInlineEntitySet(final String name, final URI link,
final ODataEntitySet entitySet) {
@@ -104,15 +73,6 @@ public class ODataObjectFactoryImpl implements ODataObjectFactory {
link, ODataLinkType.ENTITY_SET_NAVIGATION, name, entitySet);
}
- /**
- * Instantiates a new in-line entity set.
- *
- * @param name name.
- * @param baseURI base URI.
- * @param href href.
- * @param entitySet entity set.
- * @return in-line entity set.
- */
@Override
public ODataInlineEntitySet newInlineEntitySet(final String name, final URI baseURI, final String href,
final ODataEntitySet entitySet) {
@@ -121,28 +81,11 @@ public class ODataObjectFactoryImpl implements ODataObjectFactory {
baseURI, href, ODataLinkType.ENTITY_SET_NAVIGATION, name, entitySet);
}
- /**
- * Instantiates a new in-line entity.
- *
- * @param name name.
- * @param link edit link.
- * @param entity entity.
- * @return in-line entity.
- */
@Override
public ODataInlineEntity newInlineEntity(final String name, final URI link, final ODataEntity entity) {
return new ODataInlineEntity(client.getServiceVersion(), link, ODataLinkType.ENTITY_NAVIGATION, name, entity);
}
- /**
- * Instantiates a new in-line entity.
- *
- * @param name name.
- * @param baseURI base URI.
- * @param href href.
- * @param entity entity.
- * @return in-line entity.
- */
@Override
public ODataInlineEntity newInlineEntity(final String name, final URI baseURI, final String href,
final ODataEntity entity) {
@@ -151,145 +94,69 @@ public class ODataObjectFactoryImpl implements ODataObjectFactory {
baseURI, href, ODataLinkType.ENTITY_NAVIGATION, name, entity);
}
- /**
- * Instantiates a new entity navigation link.
- *
- * @param name name.
- * @param link link.
- * @return entity navigation link.
- */
@Override
public ODataLink newEntityNavigationLink(final String name, final URI link) {
return new ODataLink.Builder().setVersion(client.getServiceVersion()).setURI(link).
setType(ODataLinkType.ENTITY_NAVIGATION).setTitle(name).build();
}
- /**
- * Instantiates a new entity navigation link.
- *
- * @param name name.
- * @param baseURI base URI.
- * @param href href.
- * @return entity navigation link.
- */
@Override
public ODataLink newEntityNavigationLink(final String name, final URI baseURI, final String href) {
return new ODataLink.Builder().setVersion(client.getServiceVersion()).setURI(baseURI, href).
setType(ODataLinkType.ENTITY_NAVIGATION).setTitle(name).build();
}
- /**
- * Instantiates a new entity set navigation link.
- *
- * @param name name.
- * @param link link.
- * @return entity set navigation link.
- */
@Override
public ODataLink newFeedNavigationLink(final String name, final URI link) {
return new ODataLink.Builder().setVersion(client.getServiceVersion()).setURI(link).
setType(ODataLinkType.ENTITY_SET_NAVIGATION).setTitle(name).build();
}
- /**
- * Instantiates a new entity set navigation link.
- *
- * @param name name.
- * @param baseURI base URI.
- * @param href href.
- * @return entity set navigation link.
- */
@Override
public ODataLink newFeedNavigationLink(final String name, final URI baseURI, final String href) {
return new ODataLink.Builder().setVersion(client.getServiceVersion()).setURI(baseURI, href).
setType(ODataLinkType.ENTITY_SET_NAVIGATION).setTitle(name).build();
}
- /**
- * Instantiates a new association link.
- *
- * @param name name.
- * @param link link.
- * @return association link.
- */
@Override
public ODataLink newAssociationLink(final String name, final URI link) {
return new ODataLink.Builder().setVersion(client.getServiceVersion()).setURI(link).
setType(ODataLinkType.ASSOCIATION).setTitle(name).build();
}
- /**
- * Instantiates a new association link.
- *
- * @param name name.
- * @param baseURI base URI.
- * @param href href.
- * @return association link.
- */
@Override
public ODataLink newAssociationLink(final String name, final URI baseURI, final String href) {
return new ODataLink.Builder().setVersion(client.getServiceVersion()).setURI(baseURI, href).
setType(ODataLinkType.ASSOCIATION).setTitle(name).build();
}
- /**
- * Instantiates a new media-edit link.
- *
- * @param name name.
- * @param link link.
- * @return media-edit link.
- */
@Override
public ODataLink newMediaEditLink(final String name, final URI link) {
return new ODataLink.Builder().setVersion(client.getServiceVersion()).setURI(link).
setType(ODataLinkType.MEDIA_EDIT).setTitle(name).build();
}
- /**
- * Instantiates a new media-edit link.
- *
- * @param name name.
- * @param baseURI base URI.
- * @param href href.
- * @return media-edit link.
- */
@Override
public ODataLink newMediaEditLink(final String name, final URI baseURI, final String href) {
return new ODataLink.Builder().setVersion(client.getServiceVersion()).setURI(baseURI, href).
setType(ODataLinkType.MEDIA_EDIT).setTitle(name).build();
}
- /**
- * Instantiates a new primitive property.
- *
- * @param name name.
- * @param value value.
- * @return primitive property.
- */
@Override
public ODataProperty newPrimitiveProperty(final String name, final ODataPrimitiveValue value) {
return new ODataProperty(name, value);
}
- /**
- * Instantiates a new complex property.
- *
- * @param name name.
- * @param value value.
- * @return complex property.
- */
+ @Override
+ public ODataProperty newPrimitiveProperty(final String name, final ODataGeospatialValue value) {
+ return new ODataProperty(name, value);
+ }
+
@Override
public ODataProperty newComplexProperty(final String name, final ODataComplexValue value) {
return new ODataProperty(name, value);
}
- /**
- * Instantiates a new collection property.
- *
- * @param name name.
- * @param value value.
- * @return collection property.
- */
@Override
public ODataProperty newCollectionProperty(final String name, final ODataCollectionValue value) {
return new ODataProperty(name, value);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4780fc51/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataBinderImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataBinderImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataBinderImpl.java
index 8812129..9951db2 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataBinderImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataBinderImpl.java
@@ -22,7 +22,7 @@ import org.apache.olingo.client.api.data.ServiceDocument;
import org.apache.olingo.client.api.data.ServiceDocumentItem;
import org.apache.olingo.client.api.domain.ODataServiceDocument;
import org.apache.olingo.client.api.op.v4.ODataBinder;
-import org.apache.olingo.client.api.utils.URIUtils;
+import org.apache.olingo.client.core.uri.URIUtils;
import org.apache.olingo.client.api.v4.ODataClient;
import org.apache.olingo.client.core.op.impl.AbstractODataBinder;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4780fc51/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/AbstractURIBuilder.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/AbstractURIBuilder.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/AbstractURIBuilder.java
index 14f2704..2beecb3 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/AbstractURIBuilder.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/AbstractURIBuilder.java
@@ -18,7 +18,6 @@
*/
package org.apache.olingo.client.core.uri;
-import org.apache.olingo.client.api.utils.URIUtils;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4780fc51/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/FilterLiteral.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/FilterLiteral.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/FilterLiteral.java
index c7e2d6a..cef0349 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/FilterLiteral.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/FilterLiteral.java
@@ -19,7 +19,6 @@
package org.apache.olingo.client.core.uri;
import org.apache.olingo.client.api.uri.FilterArg;
-import org.apache.olingo.client.api.utils.URIUtils;
/**
* Filter value literals; obtain instances via <tt>FilterArgFactory</tt>.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4780fc51/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/URIUtils.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/URIUtils.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/URIUtils.java
new file mode 100644
index 0000000..50245ff
--- /dev/null
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/URIUtils.java
@@ -0,0 +1,202 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.client.core.uri;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.math.BigDecimal;
+import java.net.URI;
+import java.net.URLEncoder;
+import java.sql.Timestamp;
+import java.text.DecimalFormat;
+import java.util.Calendar;
+import java.util.UUID;
+import javax.xml.datatype.Duration;
+import org.apache.commons.codec.binary.Hex;
+import org.apache.commons.io.IOUtils;
+import org.apache.http.entity.InputStreamEntity;
+import org.apache.olingo.client.api.CommonODataClient;
+import org.apache.olingo.client.api.Constants;
+import org.apache.olingo.commons.api.edm.EdmEntityContainer;
+import org.apache.olingo.commons.api.edm.EdmFunctionImport;
+import org.apache.olingo.commons.core.edm.primitivetype.EdmDateTime;
+import org.apache.olingo.commons.core.edm.primitivetype.EdmDateTimeOffset;
+import org.apache.olingo.commons.core.edm.primitivetype.EdmTime;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * URI utilities.
+ */
+public final class URIUtils {
+
+ /**
+ * Logger.
+ */
+ private static final Logger LOG = LoggerFactory.getLogger(URIUtils.class);
+
+ private URIUtils() {
+ // Empty private constructor for static utility classes
+ }
+
+ /**
+ * Build URI starting from the given base and href.
+ * <br/>
+ * If href is absolute or base is null then base will be ignored.
+ *
+ * @param base URI prefix.
+ * @param href URI suffix.
+ * @return built URI.
+ */
+ public static URI getURI(final String base, final String href) {
+ if (href == null) {
+ throw new IllegalArgumentException("Null link provided");
+ }
+
+ URI uri = URI.create(href);
+
+ if (!uri.isAbsolute() && base != null) {
+ uri = URI.create(base + "/" + href);
+ }
+
+ return uri.normalize();
+ }
+
+ /**
+ * Build URI starting from the given base and href.
+ * <br/>
+ * If href is absolute or base is null then base will be ignored.
+ *
+ * @param base URI prefix.
+ * @param href URI suffix.
+ * @return built URI.
+ */
+ public static URI getURI(final URI base, final URI href) {
+ if (href == null) {
+ throw new IllegalArgumentException("Null link provided");
+ }
+ return getURI(base, href.toASCIIString());
+ }
+
+ /**
+ * Build URI starting from the given base and href.
+ * <br/>
+ * If href is absolute or base is null then base will be ignored.
+ *
+ * @param base URI prefix.
+ * @param href URI suffix.
+ * @return built URI.
+ */
+ public static URI getURI(final URI base, final String href) {
+ if (href == null) {
+ throw new IllegalArgumentException("Null link provided");
+ }
+
+ URI uri = URI.create(href);
+
+ if (!uri.isAbsolute() && base != null) {
+ uri = URI.create(base.toASCIIString() + "/" + href);
+ }
+
+ return uri.normalize();
+ }
+
+ /**
+ * Gets function import URI segment.
+ *
+ * @param entityContainer entity container.
+ * @param functionImport function import.
+ * @return URI segment.
+ */
+ public static String rootFunctionImportURISegment(
+ final EdmEntityContainer entityContainer, final EdmFunctionImport functionImport) {
+
+ final StringBuilder result = new StringBuilder();
+ // TODO: https://issues.apache.org/jira/browse/OLINGO-209
+ // if (!entityContainer.isDefaultEntityContainer()) {
+ // result.append(entityContainer.getName()).append('.');
+ // }
+ result.append(functionImport.getName());
+
+ return result.toString();
+ }
+
+ /**
+ * Turns primitive values into their respective URI representation.
+ *
+ * @param obj primitive value
+ * @return URI representation
+ */
+ public static String escape(final Object obj) {
+ String value;
+
+ try {
+ value = (obj instanceof UUID)
+ ? "guid'" + obj.toString() + "'"
+ : (obj instanceof byte[])
+ ? "X'" + Hex.encodeHexString((byte[]) obj) + "'"
+ : (obj instanceof Timestamp)
+ ? "datetime'" + URLEncoder.encode(EdmDateTime.getInstance().
+ valueToString(obj, null, null, null, null, null), Constants.UTF8) + "'"
+ : (obj instanceof Calendar)
+ ? "datetimeoffset'" + URLEncoder.encode(EdmDateTimeOffset.getInstance().
+ valueToString(obj, null, null, null, null, null), Constants.UTF8)
+ + "'"
+ : (obj instanceof Duration)
+ ? "time'" + URLEncoder.encode(EdmTime.getInstance().
+ valueToString(obj, null, null, null, null, null), Constants.UTF8) + "'"
+ : (obj instanceof BigDecimal)
+ ? new DecimalFormat("#.#######################").format((BigDecimal) obj) + "M"
+ : (obj instanceof Double)
+ ? new DecimalFormat("#.#######################E0").format((Double) obj) + "D"
+ : (obj instanceof Float)
+ ? new DecimalFormat("#.#######E0").format((Float) obj) + "f"
+ : (obj instanceof Long)
+ ? ((Long) obj).toString() + "L"
+ : (obj instanceof String)
+ ? "'" + URLEncoder.encode((String) obj, Constants.UTF8) + "'"
+ : obj.toString();
+ } catch (Exception e) {
+ LOG.warn("While escaping '{}', using toString()", obj, e);
+ value = obj.toString();
+ }
+
+ return value;
+ }
+
+ public static InputStreamEntity buildInputStreamEntity(final CommonODataClient client, final InputStream input) {
+ InputStreamEntity entity;
+ if (client.getConfiguration().isUseChuncked()) {
+ entity = new InputStreamEntity(input, -1);
+ } else {
+ byte[] bytes = new byte[0];
+ try {
+ bytes = IOUtils.toByteArray(input);
+ } catch (IOException e) {
+ LOG.error("While reading input for not chunked encoding", e);
+ }
+
+ entity = new InputStreamEntity(new ByteArrayInputStream(bytes), bytes.length);
+ }
+ entity.setChunked(client.getConfiguration().isUseChuncked());
+
+ return entity;
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4780fc51/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/v3/URIBuilderImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/v3/URIBuilderImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/v3/URIBuilderImpl.java
index ced9a6e..b541579 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/v3/URIBuilderImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/v3/URIBuilderImpl.java
@@ -18,7 +18,7 @@
*/
package org.apache.olingo.client.core.uri.v3;
-import org.apache.olingo.client.api.utils.URIUtils;
+import org.apache.olingo.client.core.uri.URIUtils;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4780fc51/lib/client-core/src/test/java/org/apache/olingo/client/core/AbstractPrimitiveTest.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/AbstractPrimitiveTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/AbstractPrimitiveTest.java
index 5326602..df66603 100644
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/AbstractPrimitiveTest.java
+++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/AbstractPrimitiveTest.java
@@ -18,13 +18,10 @@
*/
package org.apache.olingo.client.core;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
import java.io.File;
import java.io.InputStream;
import java.math.BigDecimal;
+import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
@@ -35,8 +32,8 @@ import org.apache.olingo.client.api.Constants;
import org.apache.olingo.client.api.domain.ODataGeospatialValue;
import org.apache.olingo.client.api.domain.ODataPrimitiveValue;
import org.apache.olingo.client.api.domain.ODataProperty;
-import org.apache.olingo.client.api.domain.ODataTimestamp;
import org.apache.olingo.client.api.format.ODataFormat;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
import org.apache.olingo.commons.api.edm.geo.Geospatial;
@@ -48,6 +45,9 @@ import org.apache.olingo.commons.api.edm.geo.MultiPoint;
import org.apache.olingo.commons.api.edm.geo.MultiPolygon;
import org.apache.olingo.commons.api.edm.geo.Point;
import org.apache.olingo.commons.api.edm.geo.Polygon;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
public abstract class AbstractPrimitiveTest extends AbstractTest {
@@ -65,18 +65,9 @@ public abstract class AbstractPrimitiveTest extends AbstractTest {
}
protected ODataPrimitiveValue writePrimitiveValue(final ODataPrimitiveValue value) {
- final ODataPrimitiveValue newValue;
- final EdmPrimitiveTypeKind typeKind = EdmPrimitiveTypeKind.valueOfFQN(
- getClient().getServiceVersion(), value.getTypeName());
- if (typeKind.isGeospatial()) {
- newValue = getClient().getGeospatialValueBuilder().
- setType(EdmPrimitiveTypeKind.valueOfFQN(getVersion(), value.getTypeName())).
- setValue(((ODataGeospatialValue) value).getGeospatial()).build();
- } else {
- newValue = getClient().getPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.valueOfFQN(getClient().getServiceVersion(), value.getTypeName())).
- setValue(value.toValue()).build();
- }
+ final ODataPrimitiveValue newValue = getClient().getPrimitiveValueBuilder().
+ setType(value.getTypeKind()).
+ setValue(value.toValue()).build();
final InputStream written = getClient().getWriter().writeProperty(
getClient().getObjectFactory().newPrimitiveProperty(Constants.ELEM_PROPERTY, newValue),
@@ -97,69 +88,102 @@ public abstract class AbstractPrimitiveTest extends AbstractTest {
final ODataPrimitiveValue value =
readPrimitiveValue(getClass().getResourceAsStream(getFilename(entity, propertyName)));
- final EdmPrimitiveTypeKind typeKind = EdmPrimitiveTypeKind.valueOfFQN(
- getClient().getServiceVersion(), value.getTypeName());
- if (typeKind.isGeospatial()) {
- assertEquals(value.toValue(), writePrimitiveValue(value).toValue());
- } else {
- assertEquals(value.toString(), writePrimitiveValue(value).toString());
- }
+ assertEquals(value.toString(), writePrimitiveValue(value).toString());
return value;
}
- protected void int32(final String entity, final String propertyName, final int check) {
+ protected ODataGeospatialValue writeGeospatialValue(final ODataGeospatialValue value) {
+ final ODataGeospatialValue newValue = getClient().getGeospatialValueBuilder().
+ setType(value.getTypeKind()).
+ setValue(value.toValue()).
+ build();
+ final InputStream written = getClient().getWriter().writeProperty(
+ getClient().getObjectFactory().newPrimitiveProperty(Constants.ELEM_PROPERTY, newValue),
+ getFormat());
+ return readGeospatialValue(written);
+ }
+
+ protected ODataGeospatialValue readGeospatialValue(final InputStream input) {
+ final ODataProperty property = getClient().getReader().readProperty(input, getFormat());
+ assertNotNull(property);
+ assertTrue(property.hasGeospatialValue());
+ assertNotNull(property.getGeospatialValue());
+
+ return property.getGeospatialValue();
+ }
+
+ protected ODataGeospatialValue readGeospatialValue(final String entity, final String propertyName) {
+ final ODataGeospatialValue value =
+ readGeospatialValue(getClass().getResourceAsStream(getFilename(entity, propertyName)));
+
+ assertEquals(value.toValue(), writeGeospatialValue(value).toValue());
+
+ return value;
+ }
+
+ protected void int32(final String entity, final String propertyName, final int check)
+ throws EdmPrimitiveTypeException {
+
final ODataPrimitiveValue opv = readPrimitiveValue(entity, propertyName);
- assertEquals(EdmPrimitiveTypeKind.Int32.toString(), opv.getTypeName());
+ assertEquals(EdmPrimitiveTypeKind.Int32, opv.getTypeKind());
- final Integer value = opv.<Integer>toCastValue();
+ final Integer value = opv.toCastValue(Integer.class);
assertNotNull(value);
assertTrue(check == value);
}
- protected void string(final String entity, final String propertyName, final String check) {
+ protected void string(final String entity, final String propertyName, final String check)
+ throws EdmPrimitiveTypeException {
+
final ODataPrimitiveValue opv = readPrimitiveValue(entity, propertyName);
- assertEquals(EdmPrimitiveTypeKind.String.toString(), opv.getTypeName());
+ assertEquals(EdmPrimitiveTypeKind.String, opv.getTypeKind());
- final String value = opv.<String>toCastValue();
+ final String value = opv.toCastValue(String.class);
assertNotNull(value);
assertEquals(check, value);
assertEquals(opv, writePrimitiveValue(opv));
}
- protected void decimal(final String entity, final String propertyName, final BigDecimal check) {
+ protected void decimal(final String entity, final String propertyName, final BigDecimal check)
+ throws EdmPrimitiveTypeException {
+
final ODataPrimitiveValue opv = readPrimitiveValue(entity, propertyName);
- assertEquals(EdmPrimitiveTypeKind.Decimal.toString(), opv.getTypeName());
+ assertEquals(EdmPrimitiveTypeKind.Decimal, opv.getTypeKind());
- final BigDecimal value = opv.<BigDecimal>toCastValue();
+ final BigDecimal value = opv.toCastValue(BigDecimal.class);
assertNotNull(value);
assertTrue(check.equals(value));
}
- protected void datetime(final String entity, final String propertyName, final String check) {
+ protected void datetime(final String entity, final String propertyName, final String check)
+ throws EdmPrimitiveTypeException {
+
final ODataPrimitiveValue opv = readPrimitiveValue(entity, propertyName);
- assertEquals(EdmPrimitiveTypeKind.DateTime.toString(), opv.getTypeName());
+ assertEquals(EdmPrimitiveTypeKind.DateTime, opv.getTypeKind());
- final ODataTimestamp value = opv.<ODataTimestamp>toCastValue();
+ final Timestamp value = opv.toCastValue(Timestamp.class);
assertNotNull(value);
assertEquals(check, opv.toString());
}
- protected void guid(final String entity, final String propertyName, final String check) {
+ protected void guid(final String entity, final String propertyName, final String check)
+ throws EdmPrimitiveTypeException {
+
final ODataPrimitiveValue opv = readPrimitiveValue(entity, propertyName);
- assertEquals(EdmPrimitiveTypeKind.Guid.toString(), opv.getTypeName());
+ assertEquals(EdmPrimitiveTypeKind.Guid, opv.getTypeKind());
- final UUID value = opv.<UUID>toCastValue();
+ final UUID value = opv.toCastValue(UUID.class);
assertNotNull(value);
assertEquals(check, opv.toString());
}
- protected void binary(final String entity, final String propertyName) {
+ protected void binary(final String entity, final String propertyName) throws EdmPrimitiveTypeException {
final ODataPrimitiveValue opv = readPrimitiveValue(entity, propertyName);
- assertEquals(EdmPrimitiveTypeKind.Binary.toString(), opv.getTypeName());
+ assertEquals(EdmPrimitiveTypeKind.Binary, opv.getTypeKind());
- final byte[] value = opv.<byte[]>toCastValue();
+ final byte[] value = opv.toCastValue(byte[].class);
assertNotNull(value);
assertTrue(value.length > 0);
assertTrue(Base64.isBase64(opv.toString()));
@@ -178,10 +202,10 @@ public abstract class AbstractPrimitiveTest extends AbstractTest {
final EdmPrimitiveTypeKind expectedType,
final Dimension expectedDimension) {
- final ODataPrimitiveValue opv = readPrimitiveValue(entity, propertyName);
- assertEquals(expectedType.toString(), opv.getTypeName());
+ final ODataGeospatialValue opv = readGeospatialValue(entity, propertyName);
+ assertEquals(expectedType, opv.getTypeKind());
- final Point point = opv.<Point>toCastValue();
+ final Point point = opv.toCastValue(Point.class);
assertNotNull(point);
assertEquals(expectedDimension, point.getDimension());
@@ -209,10 +233,10 @@ public abstract class AbstractPrimitiveTest extends AbstractTest {
final EdmPrimitiveTypeKind expectedType,
final Dimension expectedDimension) {
- final ODataPrimitiveValue opv = readPrimitiveValue(entity, propertyName);
- assertEquals(expectedType.toString(), opv.getTypeName());
+ final ODataGeospatialValue opv = readGeospatialValue(entity, propertyName);
+ assertEquals(expectedType, opv.getTypeKind());
- final LineString lineString = opv.<LineString>toCastValue();
+ final LineString lineString = opv.toCastValue(LineString.class);
assertNotNull(lineString);
assertEquals(expectedDimension, lineString.getDimension());
@@ -226,10 +250,10 @@ public abstract class AbstractPrimitiveTest extends AbstractTest {
final EdmPrimitiveTypeKind expectedType,
final Dimension expectedDimension) {
- final ODataPrimitiveValue opv = readPrimitiveValue(entity, propertyName);
- assertEquals(expectedType.toString(), opv.getTypeName());
+ final ODataGeospatialValue opv = readGeospatialValue(entity, propertyName);
+ assertEquals(expectedType, opv.getTypeKind());
- final MultiPoint multiPoint = opv.<MultiPoint>toCastValue();
+ final MultiPoint multiPoint = opv.toCastValue(MultiPoint.class);
assertNotNull(multiPoint);
assertEquals(expectedDimension, multiPoint.getDimension());
@@ -253,10 +277,10 @@ public abstract class AbstractPrimitiveTest extends AbstractTest {
final EdmPrimitiveTypeKind expectedType,
final Dimension expectedDimension) {
- final ODataPrimitiveValue opv = readPrimitiveValue(entity, propertyName);
- assertEquals(expectedType.toString(), opv.getTypeName());
+ final ODataGeospatialValue opv = readGeospatialValue(entity, propertyName);
+ assertEquals(expectedType, opv.getTypeKind());
- final MultiLineString multiLine = opv.<MultiLineString>toCastValue();
+ final MultiLineString multiLine = opv.toCastValue(MultiLineString.class);
assertNotNull(multiLine);
assertEquals(expectedDimension, multiLine.getDimension());
@@ -308,10 +332,10 @@ public abstract class AbstractPrimitiveTest extends AbstractTest {
final EdmPrimitiveTypeKind expectedType,
final Dimension expectedDimension) {
- final ODataPrimitiveValue opv = readPrimitiveValue(entity, propertyName);
- assertEquals(expectedType.toString(), opv.getTypeName());
+ final ODataGeospatialValue opv = readGeospatialValue(entity, propertyName);
+ assertEquals(expectedType, opv.getTypeKind());
- final Polygon polygon = opv.<Polygon>toCastValue();
+ final Polygon polygon = opv.toCastValue(Polygon.class);
assertNotNull(polygon);
assertEquals(expectedDimension, polygon.getDimension());
@@ -328,10 +352,10 @@ public abstract class AbstractPrimitiveTest extends AbstractTest {
final EdmPrimitiveTypeKind expectedType,
final Dimension expectedDimension) {
- final ODataPrimitiveValue opv = readPrimitiveValue(entity, propertyName);
- assertEquals(expectedType.toString(), opv.getTypeName());
+ final ODataGeospatialValue opv = readGeospatialValue(entity, propertyName);
+ assertEquals(expectedType, opv.getTypeKind());
- final MultiPolygon multiPolygon = opv.<MultiPolygon>toCastValue();
+ final MultiPolygon multiPolygon = opv.toCastValue(MultiPolygon.class);
assertNotNull(multiPolygon);
assertEquals(expectedDimension, multiPolygon.getDimension());
@@ -351,10 +375,10 @@ public abstract class AbstractPrimitiveTest extends AbstractTest {
final EdmPrimitiveTypeKind expectedType,
final Dimension expectedDimension) {
- final ODataPrimitiveValue opv = readPrimitiveValue(entity, propertyName);
- assertEquals(expectedType.toString(), opv.getTypeName());
+ final ODataGeospatialValue opv = readGeospatialValue(entity, propertyName);
+ assertEquals(expectedType, opv.getTypeKind());
- final GeospatialCollection collection = opv.<GeospatialCollection>toCastValue();
+ final GeospatialCollection collection = opv.toCastValue(GeospatialCollection.class);
assertNotNull(collection);
assertEquals(expectedDimension, collection.getDimension());
@@ -380,10 +404,10 @@ public abstract class AbstractPrimitiveTest extends AbstractTest {
final EdmPrimitiveTypeKind expectedType,
final Dimension expectedDimension) {
- final ODataPrimitiveValue opv = readPrimitiveValue(entity, propertyName);
- assertEquals(expectedType.toString(), opv.getTypeName());
+ final ODataGeospatialValue opv = readGeospatialValue(entity, propertyName);
+ assertEquals(expectedType, opv.getTypeKind());
- final GeospatialCollection collection = opv.<GeospatialCollection>toCastValue();
+ final GeospatialCollection collection = opv.toCastValue(GeospatialCollection.class);
assertNotNull(collection);
assertEquals(expectedDimension, collection.getDimension());
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4780fc51/lib/client-core/src/test/java/org/apache/olingo/client/core/AbstractPropertyTest.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/AbstractPropertyTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/AbstractPropertyTest.java
index e9b97f2..a67f8b8 100644
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/AbstractPropertyTest.java
+++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/AbstractPropertyTest.java
@@ -33,6 +33,7 @@ import org.apache.olingo.client.api.domain.ODataPrimitiveValue;
import org.apache.olingo.client.api.domain.ODataProperty;
import org.apache.olingo.client.api.domain.ODataValue;
import org.apache.olingo.client.api.format.ODataFormat;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
import org.junit.Test;
@@ -51,7 +52,7 @@ public abstract class AbstractPropertyTest extends AbstractTest {
getVersion().name().toLowerCase() + File.separatorChar
+ "Customer_-10_CustomerId_value.txt");
- final ODataValue value = getClient().getPrimitiveValueBuilder().
+ final ODataPrimitiveValue value = getClient().getPrimitiveValueBuilder().
setType(EdmPrimitiveTypeKind.String).
setText(IOUtils.toString(input)).
build();
@@ -59,14 +60,14 @@ public abstract class AbstractPropertyTest extends AbstractTest {
assertEquals("-10", value.toString());
}
- private ODataProperty primitive() throws IOException {
+ private ODataProperty primitive() throws IOException, EdmPrimitiveTypeException {
final InputStream input = getClass().getResourceAsStream(
getVersion().name().toLowerCase() + File.separatorChar
+ "Customer_-10_CustomerId." + getSuffix(getFormat()));
final ODataProperty property = getClient().getReader().readProperty(input, getFormat());
assertNotNull(property);
assertTrue(property.hasPrimitiveValue());
- assertTrue(-10 == property.getPrimitiveValue().<Integer>toCastValue());
+ assertTrue(-10 == property.getPrimitiveValue().toCastValue(Integer.class));
ODataProperty comparable;
final ODataProperty written = getClient().getReader().readProperty(
@@ -76,8 +77,7 @@ public abstract class AbstractPropertyTest extends AbstractTest {
} else {
// This is needed because type information gets lost with JSON serialization
final ODataPrimitiveValue typedValue = getClient().getPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.valueOfFQN(
- getClient().getServiceVersion(), property.getPrimitiveValue().getTypeName())).
+ setType(property.getPrimitiveValue().getTypeKind()).
setText(written.getPrimitiveValue().toString()).
build();
comparable = getClient().getObjectFactory().newPrimitiveProperty(written.getName(), typedValue);
@@ -89,7 +89,7 @@ public abstract class AbstractPropertyTest extends AbstractTest {
}
@Test
- public void readPrimitiveProperty() throws IOException {
+ public void readPrimitiveProperty() throws IOException, EdmPrimitiveTypeException {
primitive();
}
@@ -109,7 +109,7 @@ public abstract class AbstractPropertyTest extends AbstractTest {
comparable = written;
} else {
// This is needed because type information gets lost with JSON serialization
- final ODataComplexValue typedValue = new ODataComplexValue(property.getComplexValue().getTypeName());
+ final ODataComplexValue typedValue = new ODataComplexValue(property.getComplexValue().getType());
for (final Iterator<ODataProperty> itor = written.getComplexValue().iterator(); itor.hasNext();) {
final ODataProperty prop = itor.next();
typedValue.add(prop);
@@ -144,7 +144,7 @@ public abstract class AbstractPropertyTest extends AbstractTest {
} else {
// This is needed because type information gets lost with JSON serialization
final ODataCollectionValue typedValue =
- new ODataCollectionValue(property.getCollectionValue().getTypeName());
+ new ODataCollectionValue(property.getCollectionValue().getType());
for (final Iterator<ODataValue> itor = written.getCollectionValue().iterator(); itor.hasNext();) {
final ODataValue value = itor.next();
if (value.isPrimitive()) {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4780fc51/lib/client-core/src/test/java/org/apache/olingo/client/core/it/AbstractTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/AbstractTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/AbstractTestITCase.java
index e87b877..1a30ef7 100644
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/AbstractTestITCase.java
+++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/AbstractTestITCase.java
@@ -64,7 +64,7 @@ import org.apache.olingo.client.api.domain.ODataValue;
import org.apache.olingo.client.api.format.ODataPubFormat;
import org.apache.olingo.client.api.http.HttpMethod;
import org.apache.olingo.client.api.uri.CommonURIBuilder;
-import org.apache.olingo.client.api.utils.URIUtils;
+import org.apache.olingo.client.core.uri.URIUtils;
import org.apache.olingo.client.core.data.AtomEntryImpl;
import org.apache.olingo.client.core.data.JSONEntryImpl;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
@@ -198,8 +198,8 @@ public abstract class AbstractTestITCase {
assertTrue("Found " + actual + " but expected " + original, found);
} else {
assertTrue("Primitive value for '" + propertyName + "' type mismatch: " + original.asPrimitive().
- getTypeName() + "-" + actual.asPrimitive().getTypeName(),
- original.asPrimitive().getTypeName().equals(actual.asPrimitive().getTypeName()));
+ getTypeKind() + "-" + actual.asPrimitive().getTypeKind(),
+ original.asPrimitive().getTypeKind().equals(actual.asPrimitive().getTypeKind()));
assertEquals("Primitive value for '" + propertyName + "' mismatch: " + original.asPrimitive().toString()
+ "-" + actual.asPrimitive().toString(),
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4780fc51/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/AsyncTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/AsyncTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/AsyncTestITCase.java
index 4527aa0..294d190 100644
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/AsyncTestITCase.java
+++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/AsyncTestITCase.java
@@ -22,7 +22,6 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertFalse;
-import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.util.concurrent.ExecutionException;
@@ -95,7 +94,7 @@ public class AsyncTestITCase extends AbstractTestITCase {
*/
@Test
@Ignore
- public void createMediaEntity() throws InterruptedException, ExecutionException, IOException {
+ public void createMediaEntity() throws Exception {
CommonURIBuilder<?> builder = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Car");
final String TO_BE_UPDATED = "async buffered stream sample";
@@ -110,7 +109,7 @@ public class AsyncTestITCase extends AbstractTestITCase {
while (!futureCreateRes.isDone()) {
Thread.sleep(1000L);
}
-
+
final ODataMediaEntityCreateResponse createRes = futureCreateRes.get();
assertEquals(201, createRes.getStatusCode());
@@ -120,8 +119,8 @@ public class AsyncTestITCase extends AbstractTestITCase {
assertEquals(2, created.getProperties().size());
final int id = "VIN".equals(created.getProperties().get(0).getName())
- ? created.getProperties().get(0).getPrimitiveValue().<Integer>toCastValue()
- : created.getProperties().get(1).getPrimitiveValue().<Integer>toCastValue();
+ ? created.getProperties().get(0).getPrimitiveValue().toCastValue(Integer.class)
+ : created.getProperties().get(1).getPrimitiveValue().toCastValue(Integer.class);
builder = client.getURIBuilder(testStaticServiceRootURL).
appendEntitySetSegment("Car").appendKeySegment(id).appendValueSegment();
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4780fc51/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/CountTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/CountTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/CountTestITCase.java
index bcdef88..455d376 100644
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/CountTestITCase.java
+++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/CountTestITCase.java
@@ -28,35 +28,33 @@ import org.apache.olingo.client.api.format.ODataValueFormat;
import org.apache.olingo.client.api.uri.CommonURIBuilder;
public class CountTestITCase extends AbstractTestITCase {
- //counts the total number of customers
- @Test
- public void entityCount() {
- CommonURIBuilder<?> uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Customer").count();
- final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
- req.setFormat(ODataValueFormat.TEXT);
- try {
- final ODataValue value = req.execute().getBody();
- assertTrue(10 <= Integer.parseInt(value.toString()));
- } catch (ODataClientErrorException e) {
- LOG.error("Error code: {}", e.getStatusLine().getStatusCode(), e);
- }
+ @Test
+ public void entityCount() {
+ CommonURIBuilder<?> uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Customer").count();
+ final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
+ req.setFormat(ODataValueFormat.TEXT);
+ try {
+ final ODataValue value = req.execute().getBody();
+ assertTrue(10 <= Integer.parseInt(value.toString()));
+ } catch (ODataClientErrorException e) {
+ LOG.error("Error code: {}", e.getStatusLine().getStatusCode(), e);
}
- //returns 415 error for invalid header.
+ }
- @Test
- public void invalidAccept() {
- final CommonURIBuilder<?> uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Customer").count();
- final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
- req.setFormat(ODataValueFormat.TEXT);
- req.setAccept("application/json;odata=fullmetadata");
- try {
- final ODataValue value = req.execute().getBody();
- fail();
- } catch (ODataClientErrorException e) {
- assertEquals(415, e.getStatusLine().getStatusCode());
- }
+ @Test
+ public void invalidAccept() {
+ final CommonURIBuilder<?> uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Customer").count();
+ final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
+ req.setFormat(ODataValueFormat.TEXT);
+ req.setAccept("application/json;odata=fullmetadata");
+ try {
+ final ODataValue value = req.execute().getBody();
+ fail();
+ } catch (ODataClientErrorException e) {
+ assertEquals(415, e.getStatusLine().getStatusCode());
}
+ }
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4780fc51/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/EntityCreateTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/EntityCreateTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/EntityCreateTestITCase.java
index 465dc07..d16f060 100644
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/EntityCreateTestITCase.java
+++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/EntityCreateTestITCase.java
@@ -47,7 +47,8 @@ import org.apache.olingo.client.api.domain.ODataProperty;
import org.apache.olingo.client.api.format.ODataPubFormat;
import org.apache.olingo.client.api.http.NoContentException;
import org.apache.olingo.client.api.uri.CommonURIBuilder;
-import org.apache.olingo.client.api.utils.URIUtils;
+import org.apache.olingo.client.core.uri.URIUtils;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.junit.Ignore;
import org.junit.Test;
@@ -182,14 +183,14 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
}
@Test
- public void createWithFeedNavigationAsAtom() {
+ public void createWithFeedNavigationAsAtom() throws EdmPrimitiveTypeException {
final ODataPubFormat format = ODataPubFormat.ATOM;
final ODataEntity actual = createWithFeedNavigationLink(format, 7);
cleanAfterCreate(format, actual, false, getServiceRoot());
}
@Test
- public void createWithFeedNavigationAsJSON() {
+ public void createWithFeedNavigationAsJSON() throws EdmPrimitiveTypeException {
// this needs to be full, otherwise there is no mean to recognize links
final ODataPubFormat format = ODataPubFormat.JSON_FULL_METADATA;
final ODataEntity actual = createWithFeedNavigationLink(format, 8);
@@ -197,14 +198,14 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
}
@Test
- public void createWithBackNavigationAsAtom() {
+ public void createWithBackNavigationAsAtom() throws EdmPrimitiveTypeException {
final ODataPubFormat format = ODataPubFormat.ATOM;
final ODataEntity actual = createWithBackNavigationLink(format, 9);
cleanAfterCreate(format, actual, true, getServiceRoot());
}
@Test
- public void createWithBackNavigationAsJSON() {
+ public void createWithBackNavigationAsJSON() throws EdmPrimitiveTypeException {
// this needs to be full, otherwise there is no mean to recognize links
final ODataPubFormat format = ODataPubFormat.JSON_FULL_METADATA;
final ODataEntity actual = createWithBackNavigationLink(format, 10);
@@ -275,7 +276,9 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
}
}
- private ODataEntity createWithFeedNavigationLink(final ODataPubFormat format, final int id) {
+ private ODataEntity createWithFeedNavigationLink(final ODataPubFormat format, final int id)
+ throws EdmPrimitiveTypeException {
+
final String sampleName = "Sample customer";
final ODataEntity original = getSampleCustomerProfile(id, sampleName, false);
@@ -321,8 +324,8 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
assertEquals(2, entitySet.getCount());
for (ODataEntity entity : entitySet.getEntities()) {
- final Integer key = entity.getProperty("OrderId").getPrimitiveValue().<Integer>toCastValue();
- final Integer customerId = entity.getProperty("CustomerId").getPrimitiveValue().<Integer>toCastValue();
+ final Integer key = entity.getProperty("OrderId").getPrimitiveValue().toCastValue(Integer.class);
+ final Integer customerId = entity.getProperty("CustomerId").getPrimitiveValue().toCastValue(Integer.class);
assertTrue(keys.contains(key));
assertEquals(Integer.valueOf(id), customerId);
keys.remove(key);
@@ -374,7 +377,9 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
return actual;
}
- private ODataEntity createWithBackNavigationLink(final ODataPubFormat format, final int id) {
+ private ODataEntity createWithBackNavigationLink(final ODataPubFormat format, final int id)
+ throws EdmPrimitiveTypeException {
+
final String sampleName = "Sample customer";
ODataEntity customer = getSampleCustomerProfile(id, sampleName, false);
@@ -405,8 +410,8 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
customer = customerreq.execute().getBody();
- assertEquals(
- Integer.valueOf(id), customer.getProperty("CustomerId").getPrimitiveValue().<Integer>toCastValue());
+ assertEquals(Integer.valueOf(id),
+ customer.getProperty("CustomerId").getPrimitiveValue().toCastValue(Integer.class));
final ODataEntitySetRequest orderreq = client.getRetrieveRequestFactory().getEntitySetRequest(
URIUtils.getURI(getServiceRoot(), customer.getEditLink().toASCIIString() + "/Orders"));
@@ -417,7 +422,7 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
assertEquals(Integer.valueOf(id),
orderres.getBody().getEntities().get(0).getProperty("OrderId").getPrimitiveValue().
- <Integer>toCastValue());
+ toCastValue(Integer.class));
final ODataEntityRequest req = client.getRetrieveRequestFactory().getEntityRequest(
URIUtils.getURI(getServiceRoot(), customer.getEditLink().toASCIIString() + "?$expand=Orders"));
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4780fc51/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/EntityRetrieveTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/EntityRetrieveTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/EntityRetrieveTestITCase.java
index 02a74ae..6637346 100644
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/EntityRetrieveTestITCase.java
+++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/EntityRetrieveTestITCase.java
@@ -39,6 +39,7 @@ import org.apache.olingo.client.api.domain.ODataProperty;
import org.apache.olingo.client.api.format.ODataPubFormat;
import org.apache.olingo.client.api.uri.CommonURIBuilder;
import org.apache.olingo.client.core.op.impl.ResourceFactory;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
import org.junit.Test;
/**
@@ -170,7 +171,7 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase {
rawRequest(ODataPubFormat.JSON_FULL_METADATA);
}
- private void multiKey(final ODataPubFormat format) {
+ private void multiKey(final ODataPubFormat format) throws EdmPrimitiveTypeException {
final LinkedHashMap<String, Object> multiKey = new LinkedHashMap<String, Object>();
multiKey.put("FromUsername", "1");
multiKey.put("MessageId", -10);
@@ -184,16 +185,16 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase {
final ODataRetrieveResponse<ODataEntity> res = req.execute();
final ODataEntity entity = res.getBody();
assertNotNull(entity);
- assertEquals("1", entity.getProperty("FromUsername").getPrimitiveValue().<String>toCastValue());
+ assertEquals("1", entity.getProperty("FromUsername").getPrimitiveValue().toCastValue(String.class));
}
@Test
- public void multiKeyAsAtom() {
+ public void multiKeyAsAtom() throws EdmPrimitiveTypeException {
multiKey(ODataPubFormat.ATOM);
}
@Test
- public void multiKeyAsJSON() {
+ public void multiKeyAsJSON() throws EdmPrimitiveTypeException {
multiKey(ODataPubFormat.JSON_FULL_METADATA);
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4780fc51/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/EntitySetTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/EntitySetTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/EntitySetTestITCase.java
index 08c414f..35cc3d6 100644
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/EntitySetTestITCase.java
+++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/EntitySetTestITCase.java
@@ -32,7 +32,7 @@ import org.apache.olingo.client.api.domain.ODataEntitySet;
import org.apache.olingo.client.api.domain.ODataEntitySetIterator;
import org.apache.olingo.client.api.format.ODataPubFormat;
import org.apache.olingo.client.api.uri.CommonURIBuilder;
-import org.apache.olingo.client.api.utils.URIUtils;
+import org.apache.olingo.client.core.uri.URIUtils;
import org.apache.olingo.client.core.op.impl.ResourceFactory;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4780fc51/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/EntityUpdateTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/EntityUpdateTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/EntityUpdateTestITCase.java
index 8399494..6e918e9 100644
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/EntityUpdateTestITCase.java
+++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/EntityUpdateTestITCase.java
@@ -33,6 +33,7 @@ import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRe
import org.apache.olingo.client.api.communication.response.ODataEntityUpdateResponse;
import org.apache.olingo.client.api.domain.ODataEntity;
import org.apache.olingo.client.api.format.ODataPubFormat;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.junit.Test;
@@ -106,16 +107,16 @@ public class EntityUpdateTestITCase extends AbstractTestITCase {
}
@Test
- public void patchLinkAsAtom() {
+ public void patchLinkAsAtom() throws EdmPrimitiveTypeException {
patchLink(ODataPubFormat.ATOM);
}
@Test
- public void patchLinkAsJSON() {
+ public void patchLinkAsJSON() throws EdmPrimitiveTypeException {
patchLink(ODataPubFormat.JSON_FULL_METADATA);
}
- public void patchLink(final ODataPubFormat format) {
+ public void patchLink(final ODataPubFormat format) throws EdmPrimitiveTypeException {
final URI uri = client.getURIBuilder(getServiceRoot()).
appendEntitySetSegment("Customer").appendKeySegment(-10).build();
@@ -142,7 +143,7 @@ public class EntityUpdateTestITCase extends AbstractTestITCase {
ODataEntity newInfo = req.execute().getBody();
assertEquals(Integer.valueOf(12),
- newInfo.getProperty("CustomerInfoId").getPrimitiveValue().<Integer>toCastValue());
+ newInfo.getProperty("CustomerInfoId").getPrimitiveValue().toCastValue(Integer.class));
// ---------------------------------------
// ---------------------------------------
@@ -167,11 +168,13 @@ public class EntityUpdateTestITCase extends AbstractTestITCase {
newInfo = req.execute().getBody();
assertEquals(Integer.valueOf(11),
- newInfo.getProperty("CustomerInfoId").getPrimitiveValue().<Integer>toCastValue());
+ newInfo.getProperty("CustomerInfoId").getPrimitiveValue().toCastValue(Integer.class));
// ---------------------------------------
}
- private ODataEntityUpdateRequest buildMultiKeyUpdateReq(final ODataPubFormat format) {
+ private ODataEntityUpdateRequest buildMultiKeyUpdateReq(final ODataPubFormat format)
+ throws EdmPrimitiveTypeException {
+
final LinkedHashMap<String, Object> multiKey = new LinkedHashMap<String, Object>();
multiKey.put("FromUsername", "1");
multiKey.put("MessageId", -10);
@@ -180,7 +183,7 @@ public class EntityUpdateTestITCase extends AbstractTestITCase {
message.getAssociationLinks().clear();
message.getNavigationLinks().clear();
- final boolean before = message.getProperty("IsRead").getPrimitiveValue().<Boolean>toCastValue();
+ final boolean before = message.getProperty("IsRead").getPrimitiveValue().toCastValue(Boolean.class);
message.getProperties().remove(message.getProperty("IsRead"));
message.getProperties().add(client.getObjectFactory().newPrimitiveProperty("IsRead",
client.getPrimitiveValueBuilder().setValue(!before).
@@ -189,23 +192,23 @@ public class EntityUpdateTestITCase extends AbstractTestITCase {
return client.getCUDRequestFactory().getEntityUpdateRequest(UpdateType.MERGE, message);
}
- private void mergeMultiKey(final ODataPubFormat format) {
+ private void mergeMultiKey(final ODataPubFormat format) throws EdmPrimitiveTypeException {
final ODataEntityUpdateResponse res = buildMultiKeyUpdateReq(format).execute();
assertEquals(204, res.getStatusCode());
}
@Test
- public void mergeMultiKeyAsAtom() {
+ public void mergeMultiKeyAsAtom() throws EdmPrimitiveTypeException {
mergeMultiKey(ODataPubFormat.ATOM);
}
@Test
- public void mergeMultiKeyAsJSON() {
+ public void mergeMultiKeyAsJSON() throws EdmPrimitiveTypeException {
mergeMultiKey(ODataPubFormat.JSON_FULL_METADATA);
}
@Test
- public void updateReturnContent() {
+ public void updateReturnContent() throws EdmPrimitiveTypeException {
final ODataEntityUpdateRequest req = buildMultiKeyUpdateReq(client.getConfiguration().getDefaultPubFormat());
req.setPrefer(ODataHeaderValues.preferReturnContent);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4780fc51/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/ErrorTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/ErrorTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/ErrorTestITCase.java
index e4b9212..a61b853 100644
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/ErrorTestITCase.java
+++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/ErrorTestITCase.java
@@ -36,7 +36,7 @@ import org.apache.olingo.client.api.domain.ODataEntity;
import org.apache.olingo.client.api.format.ODataPubFormat;
import org.apache.olingo.client.api.http.HttpMethod;
import org.apache.olingo.client.api.uri.CommonURIBuilder;
-import org.apache.olingo.client.api.utils.URIUtils;
+import org.apache.olingo.client.core.uri.URIUtils;
import org.apache.olingo.client.core.communication.request.AbstractODataBasicRequest;
import org.apache.olingo.client.core.communication.response.AbstractODataResponse;
import org.apache.olingo.commons.api.edm.Edm;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4780fc51/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/MediaEntityTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/MediaEntityTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/MediaEntityTestITCase.java
index a043430..33446cf 100644
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/MediaEntityTestITCase.java
+++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/MediaEntityTestITCase.java
@@ -171,7 +171,7 @@ public class MediaEntityTestITCase extends AbstractTestITCase {
Integer id = null;
for (ODataProperty prop : created.getProperties()) {
if ("VIN".equals(prop.getName())) {
- id = prop.getPrimitiveValue().<Integer>toCastValue();
+ id = prop.getPrimitiveValue().toCastValue(Integer.class);
}
}
assertNotNull(id);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4780fc51/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/NavigationLinkCreateTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/NavigationLinkCreateTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/NavigationLinkCreateTestITCase.java
index b8ce3b4..a1a90f9 100644
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/NavigationLinkCreateTestITCase.java
+++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/NavigationLinkCreateTestITCase.java
@@ -50,7 +50,8 @@ import org.apache.olingo.client.api.domain.ODataValue;
import org.apache.olingo.client.api.format.ODataPubFormat;
import org.apache.olingo.client.api.http.HttpClientException;
import org.apache.olingo.client.api.uri.CommonURIBuilder;
-import org.apache.olingo.client.api.utils.URIUtils;
+import org.apache.olingo.client.core.uri.URIUtils;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.junit.Test;
@@ -122,7 +123,7 @@ public class NavigationLinkCreateTestITCase extends AbstractTestITCase {
// create collection navigation link with ATOM
@Test
- public void createCollectionNavWithAtom() {
+ public void createCollectionNavWithAtom() throws EdmPrimitiveTypeException {
final ODataPubFormat format = ODataPubFormat.ATOM;
final String contentType = "application/atom+xml";
final String prefer = "return-content";
@@ -132,7 +133,7 @@ public class NavigationLinkCreateTestITCase extends AbstractTestITCase {
// create collection navigation link with JSON
@Test
- public void createCollectionNavWithJSON() {
+ public void createCollectionNavWithJSON() throws EdmPrimitiveTypeException {
final ODataPubFormat format = ODataPubFormat.JSON_FULL_METADATA;
final String contentType = "application/json;odata=fullmetadata";
final String prefer = "return-content";
@@ -195,7 +196,7 @@ public class NavigationLinkCreateTestITCase extends AbstractTestITCase {
// create collection navigation link
public ODataEntity createCollectionNavigation(final ODataPubFormat format, final int id,
- final String contentType, final String prefer) {
+ final String contentType, final String prefer) throws EdmPrimitiveTypeException {
{
final String name = "Collection Navigation Key Customer";
final ODataEntity original = getNewCustomer(id, name, false);
@@ -242,8 +243,8 @@ public class NavigationLinkCreateTestITCase extends AbstractTestITCase {
assertEquals(2, entitySet.getCount());
for (ODataEntity entity : entitySet.getEntities()) {
- final Integer key = entity.getProperty("OrderId").getPrimitiveValue().<Integer>toCastValue();
- final Integer customerId = entity.getProperty("CustomerId").getPrimitiveValue().<Integer>toCastValue();
+ final Integer key = entity.getProperty("OrderId").getPrimitiveValue().toCastValue(Integer.class);
+ final Integer customerId = entity.getProperty("CustomerId").getPrimitiveValue().toCastValue(Integer.class);
assertTrue(navigationKeys.contains(key));
assertEquals(Integer.valueOf(id), customerId);
navigationKeys.remove(key);
@@ -511,7 +512,7 @@ public class NavigationLinkCreateTestITCase extends AbstractTestITCase {
assertTrue("Found " + actual + " and expected " + original, found);
} else {
assertTrue("Primitive value for '" + propertyName + "' type mismatch",
- original.asPrimitive().getTypeName().equals(actual.asPrimitive().getTypeName()));
+ original.asPrimitive().getTypeKind() == actual.asPrimitive().getTypeKind());
assertEquals("Primitive value for '" + propertyName + "' mismatch",
original.asPrimitive().toString(), actual.asPrimitive().toString());
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4780fc51/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/OpenTypeTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/OpenTypeTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/OpenTypeTestITCase.java
index c64d7bb..2d06ba0 100644
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/OpenTypeTestITCase.java
+++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/OpenTypeTestITCase.java
@@ -69,17 +69,11 @@ public class OpenTypeTestITCase extends AbstractTestITCase {
private void read(final ODataPubFormat format) {
ODataEntity row = readRow(format, "71f7d0dc-ede4-45eb-b421-555a2aa1e58f");
- assertEquals(
- EdmPrimitiveTypeKind.Double.toString(),
- row.getProperty("Double").getPrimitiveValue().getTypeName());
- assertEquals(
- EdmPrimitiveTypeKind.Guid.toString(),
- row.getProperty("Id").getPrimitiveValue().getTypeName());
+ assertEquals(EdmPrimitiveTypeKind.Double, row.getProperty("Double").getPrimitiveValue().getTypeKind());
+ assertEquals(EdmPrimitiveTypeKind.Guid, row.getProperty("Id").getPrimitiveValue().getTypeKind());
row = readRow(format, "672b8250-1e6e-4785-80cf-b94b572e42b3");
- assertEquals(
- EdmPrimitiveTypeKind.Decimal.toString(),
- row.getProperty("Decimal").getPrimitiveValue().getTypeName());
+ assertEquals(EdmPrimitiveTypeKind.Decimal, row.getProperty("Decimal").getPrimitiveValue().getTypeKind());
}
@Test
@@ -213,45 +207,45 @@ public class OpenTypeTestITCase extends AbstractTestITCase {
final ODataEntityCreateRequest createReq = client.getCUDRequestFactory().
getEntityCreateRequest(client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Row").build(), row);
+ appendEntitySetSegment("Row").build(), row);
createReq.setFormat(format);
final ODataEntityCreateResponse createRes = createReq.execute();
assertEquals(201, createRes.getStatusCode());
row = readRow(format, guid.toString());
assertNotNull(row);
- assertEquals(EdmPrimitiveTypeKind.Guid.toString(),
- row.getProperty("Id").getPrimitiveValue().getTypeName());
- assertEquals(EdmPrimitiveTypeKind.String.toString(),
- row.getProperty("aString").getPrimitiveValue().getTypeName());
- assertEquals(EdmPrimitiveTypeKind.Boolean.toString(),
- row.getProperty("aBoolean").getPrimitiveValue().getTypeName());
- assertEquals(EdmPrimitiveTypeKind.Int64.toString(),
- row.getProperty("aLong").getPrimitiveValue().getTypeName());
- assertEquals(EdmPrimitiveTypeKind.Double.toString(),
- row.getProperty("aDouble").getPrimitiveValue().getTypeName());
- assertEquals(EdmPrimitiveTypeKind.SByte.toString(),
- row.getProperty("aByte").getPrimitiveValue().getTypeName());
- assertEquals(EdmPrimitiveTypeKind.DateTime.toString(),
- row.getProperty("aDate").getPrimitiveValue().getTypeName());
- assertEquals(EdmPrimitiveTypeKind.GeographyPoint.toString(),
- row.getProperty("aPoint").getPrimitiveValue().getTypeName());
- assertEquals(EdmPrimitiveTypeKind.GeometryMultiPoint.toString(),
- row.getProperty("aMultiPoint").getPrimitiveValue().getTypeName());
- assertEquals(EdmPrimitiveTypeKind.GeometryLineString.toString(),
- row.getProperty("aLineString").getPrimitiveValue().getTypeName());
- assertEquals(EdmPrimitiveTypeKind.GeometryMultiLineString.toString(),
- row.getProperty("aMultiLineString").getPrimitiveValue().getTypeName());
- assertEquals(EdmPrimitiveTypeKind.GeographyPolygon.toString(),
- row.getProperty("aPolygon").getPrimitiveValue().getTypeName());
- assertEquals(EdmPrimitiveTypeKind.GeographyMultiPolygon.toString(),
- row.getProperty("aMultiPolygon").getPrimitiveValue().getTypeName());
- assertEquals(EdmPrimitiveTypeKind.GeographyCollection.toString(),
- row.getProperty("aCollection").getPrimitiveValue().getTypeName());
+ assertEquals(EdmPrimitiveTypeKind.Guid,
+ row.getProperty("Id").getPrimitiveValue().getTypeKind());
+ assertEquals(EdmPrimitiveTypeKind.String,
+ row.getProperty("aString").getPrimitiveValue().getTypeKind());
+ assertEquals(EdmPrimitiveTypeKind.Boolean,
+ row.getProperty("aBoolean").getPrimitiveValue().getTypeKind());
+ assertEquals(EdmPrimitiveTypeKind.Int64,
+ row.getProperty("aLong").getPrimitiveValue().getTypeKind());
+ assertEquals(EdmPrimitiveTypeKind.Double,
+ row.getProperty("aDouble").getPrimitiveValue().getTypeKind());
+ assertEquals(EdmPrimitiveTypeKind.SByte,
+ row.getProperty("aByte").getPrimitiveValue().getTypeKind());
+ assertEquals(EdmPrimitiveTypeKind.DateTime,
+ row.getProperty("aDate").getPrimitiveValue().getTypeKind());
+ assertEquals(EdmPrimitiveTypeKind.GeographyPoint,
+ row.getProperty("aPoint").getPrimitiveValue().getTypeKind());
+ assertEquals(EdmPrimitiveTypeKind.GeometryMultiPoint,
+ row.getProperty("aMultiPoint").getPrimitiveValue().getTypeKind());
+ assertEquals(EdmPrimitiveTypeKind.GeometryLineString,
+ row.getProperty("aLineString").getPrimitiveValue().getTypeKind());
+ assertEquals(EdmPrimitiveTypeKind.GeometryMultiLineString,
+ row.getProperty("aMultiLineString").getPrimitiveValue().getTypeKind());
+ assertEquals(EdmPrimitiveTypeKind.GeographyPolygon,
+ row.getProperty("aPolygon").getPrimitiveValue().getTypeKind());
+ assertEquals(EdmPrimitiveTypeKind.GeographyMultiPolygon,
+ row.getProperty("aMultiPolygon").getPrimitiveValue().getTypeKind());
+ assertEquals(EdmPrimitiveTypeKind.GeographyCollection,
+ row.getProperty("aCollection").getPrimitiveValue().getTypeKind());
assertEquals("Microsoft.Test.OData.Services.OpenTypesService.ContactDetails",
- row.getProperty("aContact").getComplexValue().getTypeName());
- assertEquals(EdmPrimitiveTypeKind.SByte.toString(),
- row.getProperty("aContact").getComplexValue().get("SignedByte").getPrimitiveValue().getTypeName());
+ row.getProperty("aContact").getComplexValue().getType());
+ assertEquals(EdmPrimitiveTypeKind.SByte,
+ row.getProperty("aContact").getComplexValue().get("SignedByte").getPrimitiveValue().getTypeKind());
final ODataDeleteResponse deleteRes = client.getCUDRequestFactory().getDeleteRequest(row.getEditLink()).
execute();
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4780fc51/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/PrimitiveKeysTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/PrimitiveKeysTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/PrimitiveKeysTestITCase.java
index f7db133..d69fb68 100644
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/PrimitiveKeysTestITCase.java
+++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/PrimitiveKeysTestITCase.java
@@ -25,7 +25,6 @@ import java.math.BigDecimal;
import java.util.UUID;
import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
-import org.apache.olingo.client.api.domain.ODataDuration;
import org.apache.olingo.client.api.domain.ODataEntity;
import org.apache.olingo.client.api.format.ODataPubFormat;
import org.junit.Test;
@@ -46,26 +45,16 @@ public class PrimitiveKeysTestITCase extends AbstractTestITCase {
}
private void readPrimitiveKeys(final ODataPubFormat format) {
- // commented as per #115
- //readEntity("EdmBinarySet", new byte[] {Byte.valueOf("2"), Byte.valueOf("3"), Byte.valueOf("4")}, format);
readEntity("EdmBooleanSet", Boolean.TRUE, format);
readEntity("EdmByteSet", 255, format);
readEntity("EdmDecimalSet", new BigDecimal("79228162514264337593543950335"), format);
readEntity("EdmDoubleSet", 1.7976931348623157E+308D, format);
- readEntity("EdmSingleSet", 3.40282347E+38F, format);
+ readEntity("EdmSingleSet", 3.4028235E+38F, format);
readEntity("EdmGuidSet", UUID.fromString("00000000-0000-0000-0000-000000000000"), format);
readEntity("EdmInt16Set", 32767, format);
readEntity("EdmInt32Set", -2147483648, format);
readEntity("EdmInt64Set", 9223372036854775807L, format);
readEntity("EdmStringSet", "$", format);
- readEntity("EdmTimeSet", new ODataDuration("-P10675199DT2H48M5.4775808S"), format);
- // commented as per #115
- //readEntity("EdmDateTimeSet",
- // ODataTimestamp.parse(EdmSimpleType.DATE_TIME.pattern(), "0001-01-01T00:00:00"),
- // format);
- //readEntity("EdmDateTimeOffsetSet",
- // ODataTimestamp.parse(EdmSimpleType.DATE_TIME_OFFSET.pattern(), "2013-08-14T13:33:46.1045905+02:00"),
- // format);
}
@Test