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:41 UTC
[33/51] [abbrv] [partial] Removing /ODataJClient: merge complete
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/19f3792f/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/utils/URIUtils.java
----------------------------------------------------------------------
diff --git a/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/utils/URIUtils.java b/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/utils/URIUtils.java
deleted file mode 100644
index 3374893..0000000
--- a/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/utils/URIUtils.java
+++ /dev/null
@@ -1,194 +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.engine.utils;
-
-import com.msopentech.odatajclient.engine.client.ODataClient;
-import com.msopentech.odatajclient.engine.data.ODataDuration;
-import com.msopentech.odatajclient.engine.data.ODataTimestamp;
-import com.msopentech.odatajclient.engine.metadata.edm.EdmSimpleType;
-import com.msopentech.odatajclient.engine.metadata.edm.AbstractEntityContainer;
-import com.msopentech.odatajclient.engine.metadata.edm.AbstractFunctionImport;
-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.text.DecimalFormat;
-import java.util.UUID;
-import org.apache.commons.codec.binary.Hex;
-import org.apache.commons.io.IOUtils;
-import org.apache.http.entity.InputStreamEntity;
-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 AbstractEntityContainer entityContainer, final AbstractFunctionImport functionImport) {
-
- final StringBuilder result = new StringBuilder();
- 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 ODataTimestamp) && ((ODataTimestamp) obj).getTimezone() == null)
- ? "datetime'" + URLEncoder.encode(((ODataTimestamp) obj).toString(), ODataConstants.UTF8) + "'"
- : ((obj instanceof ODataTimestamp) && ((ODataTimestamp) obj).getTimezone() != null)
- ? "datetimeoffset'" + URLEncoder.encode(((ODataTimestamp) obj).toString(), ODataConstants.UTF8)
- + "'"
- : (obj instanceof ODataDuration)
- ? "time'" + ((ODataDuration) obj).toString() + "'"
- : (obj instanceof BigDecimal)
- ? new DecimalFormat(EdmSimpleType.Decimal.pattern()).format((BigDecimal) obj) + "M"
- : (obj instanceof Double)
- ? new DecimalFormat(EdmSimpleType.Double.pattern()).format((Double) obj) + "D"
- : (obj instanceof Float)
- ? new DecimalFormat(EdmSimpleType.Single.pattern()).format((Float) obj) + "f"
- : (obj instanceof Long)
- ? ((Long) obj).toString() + "L"
- : (obj instanceof String)
- ? "'" + URLEncoder.encode((String) obj, ODataConstants.UTF8) + "'"
- : obj.toString();
- } catch (Exception e) {
- LOG.warn("While generating key segment for '{}', using toString()", obj, e);
- value = obj.toString();
- }
-
- return value;
- }
-
- public static InputStreamEntity buildInputStreamEntity(final ODataClient 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/19f3792f/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/utils/Wrapper.java
----------------------------------------------------------------------
diff --git a/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/utils/Wrapper.java b/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/utils/Wrapper.java
deleted file mode 100644
index 455f853..0000000
--- a/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/utils/Wrapper.java
+++ /dev/null
@@ -1,41 +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.engine.utils;
-
-/**
- * Generic wrapper class.
- *
- * @param <T>
- */
-public class Wrapper<T> {
-
- private T wrapped;
-
- public void setWrapped(final T wrapped) {
- this.wrapped = wrapped;
- }
-
- public T getWrapped() {
- if (wrapped == null) {
- throw new IllegalStateException("Wrapped object not set");
- }
-
- return wrapped;
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/19f3792f/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/utils/XMLUtils.java
----------------------------------------------------------------------
diff --git a/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/utils/XMLUtils.java b/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/utils/XMLUtils.java
deleted file mode 100644
index 473a5ed..0000000
--- a/ODataJClient/engine/src/main/java/com/msopentech/odatajclient/engine/utils/XMLUtils.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.engine.utils;
-
-import com.msopentech.odatajclient.engine.metadata.edm.EdmSimpleType;
-import com.msopentech.odatajclient.engine.metadata.edm.geospatial.Geospatial;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.ServiceLoader;
-import javax.xml.parsers.DocumentBuilderFactory;
-import org.apache.commons.lang3.StringUtils;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-/**
- * XML utilities.
- */
-public final class XMLUtils {
-
- /**
- * DOM factory.
- */
- public static final DocumentBuilderFactory DOC_BUILDER_FACTORY = DocumentBuilderFactory.newInstance();
-
- public static final AbstractDOMParser PARSER;
-
- static {
- final Iterator<AbstractDOMParser> itor =
- ServiceLoader.load(AbstractDOMParser.class, Thread.currentThread().getContextClassLoader()).iterator();
- PARSER = itor.hasNext() ? itor.next() : new DefaultDOMParserImpl();
- }
-
- private XMLUtils() {
- // Empty private constructor for static utility classes
- }
-
- /**
- * Gets XML node name.
- *
- * @param node node.
- * @return node name.
- */
- public static String getSimpleName(final Node node) {
- return node.getLocalName() == null
- ? node.getNodeName().substring(node.getNodeName().indexOf(':') + 1)
- : node.getLocalName();
- }
-
- /**
- * Gets the given node's children of the given type.
- *
- * @param node parent.
- * @param nodetype searched child type.
- * @return children.
- */
- public static List<Node> getChildNodes(final Node node, final short nodetype) {
- final List<Node> result = new ArrayList<Node>();
-
- final NodeList children = node.getChildNodes();
- for (int i = 0; i < children.getLength(); i++) {
- final Node child = children.item(i);
- if (child.getNodeType() == nodetype) {
- result.add(child);
- }
- }
-
- return result;
- }
-
- /**
- * Gets the given node's children with the given name.
- *
- * @param node parent.
- * @param name searched child name.
- * @return children.
- */
- public static List<Element> getChildElements(final Element node, final String name) {
- final List<Element> result = new ArrayList<Element>();
-
- if (StringUtils.isNotBlank(name)) {
- final NodeList children = node.getChildNodes();
- for (int i = 0; i < children.getLength(); i++) {
- final Node child = children.item(i);
- if ((child instanceof Element) && name.equals(child.getNodeName())) {
- result.add((Element) child);
- }
- }
- }
-
- return result;
- }
-
- /**
- * Checks if the given node has <tt>element</tt> children.
- *
- * @param node parent.
- * @return 'TRUE' if the given node has at least one <tt>element</tt> child; 'FALSE' otherwise.
- */
- public static boolean hasElementsChildNode(final Node node) {
- boolean found = false;
-
- for (Node child : getChildNodes(node, Node.ELEMENT_NODE)) {
- if (ODataConstants.ELEM_ELEMENT.equals(XMLUtils.getSimpleName(child))) {
- found = true;
- }
- }
-
- return found;
- }
-
- /**
- * Checks if the given node has only text children.
- *
- * @param node parent.
- * @return 'TRUE' if the given node has only text children; 'FALSE' otherwise.
- */
- public static boolean hasOnlyTextChildNodes(final Node node) {
- boolean result = true;
- final NodeList children = node.getChildNodes();
- for (int i = 0; result && i < children.getLength(); i++) {
- final Node child = children.item(i);
- if (child.getNodeType() != Node.TEXT_NODE) {
- result = false;
- }
- }
-
- return result;
- }
-
- public static EdmSimpleType simpleTypeForNode(final Geospatial.Dimension dimension, final Node node) {
- EdmSimpleType type = null;
-
- if (ODataConstants.ELEM_POINT.equals(node.getNodeName())) {
- type = dimension == Geospatial.Dimension.GEOGRAPHY
- ? EdmSimpleType.GeographyPoint
- : EdmSimpleType.GeometryPoint;
- } else if (ODataConstants.ELEM_MULTIPOINT.equals(node.getNodeName())) {
- type = dimension == Geospatial.Dimension.GEOGRAPHY
- ? EdmSimpleType.GeographyMultiPoint
- : EdmSimpleType.GeometryMultiPoint;
- } else if (ODataConstants.ELEM_LINESTRING.equals(node.getNodeName())) {
- type = dimension == Geospatial.Dimension.GEOGRAPHY
- ? EdmSimpleType.GeographyLineString
- : EdmSimpleType.GeometryLineString;
- } else if (ODataConstants.ELEM_MULTILINESTRING.equals(node.getNodeName())) {
- type = dimension == Geospatial.Dimension.GEOGRAPHY
- ? EdmSimpleType.GeographyMultiLineString
- : EdmSimpleType.GeometryMultiLineString;
- } else if (ODataConstants.ELEM_POLYGON.equals(node.getNodeName())) {
- type = dimension == Geospatial.Dimension.GEOGRAPHY
- ? EdmSimpleType.GeographyPolygon
- : EdmSimpleType.GeometryPolygon;
- } else if (ODataConstants.ELEM_MULTIPOLYGON.equals(node.getNodeName())) {
- type = dimension == Geospatial.Dimension.GEOGRAPHY
- ? EdmSimpleType.GeographyMultiPolygon
- : EdmSimpleType.GeometryMultiPolygon;
- } else if (ODataConstants.ELEM_GEOCOLLECTION.equals(node.getNodeName())
- || ODataConstants.ELEM_GEOMEMBERS.equals(node.getNodeName())) {
-
- type = dimension == Geospatial.Dimension.GEOGRAPHY
- ? EdmSimpleType.GeographyCollection
- : EdmSimpleType.GeometryCollection;
- }
-
- return type;
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/19f3792f/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/AbstractPrimitiveTest.java
----------------------------------------------------------------------
diff --git a/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/AbstractPrimitiveTest.java b/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/AbstractPrimitiveTest.java
deleted file mode 100644
index 18ec67b..0000000
--- a/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/AbstractPrimitiveTest.java
+++ /dev/null
@@ -1,405 +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.engine;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import com.msopentech.odatajclient.engine.client.ODataClient;
-import com.msopentech.odatajclient.engine.data.ODataObjectFactory;
-import com.msopentech.odatajclient.engine.data.ODataGeospatialValue;
-import com.msopentech.odatajclient.engine.data.ODataPrimitiveValue;
-import com.msopentech.odatajclient.engine.data.ODataProperty;
-import com.msopentech.odatajclient.engine.data.ODataTimestamp;
-import com.msopentech.odatajclient.engine.metadata.edm.EdmSimpleType;
-import com.msopentech.odatajclient.engine.metadata.edm.geospatial.Geospatial;
-import com.msopentech.odatajclient.engine.metadata.edm.geospatial.Geospatial.Dimension;
-import com.msopentech.odatajclient.engine.metadata.edm.geospatial.GeospatialCollection;
-import com.msopentech.odatajclient.engine.metadata.edm.geospatial.LineString;
-import com.msopentech.odatajclient.engine.metadata.edm.geospatial.MultiLineString;
-import com.msopentech.odatajclient.engine.metadata.edm.geospatial.MultiPoint;
-import com.msopentech.odatajclient.engine.metadata.edm.geospatial.MultiPolygon;
-import com.msopentech.odatajclient.engine.metadata.edm.geospatial.Point;
-import com.msopentech.odatajclient.engine.metadata.edm.geospatial.Polygon;
-import com.msopentech.odatajclient.engine.format.ODataFormat;
-import com.msopentech.odatajclient.engine.utils.ODataConstants;
-import com.msopentech.odatajclient.engine.utils.ODataVersion;
-import java.io.File;
-import java.io.InputStream;
-import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.UUID;
-import org.apache.commons.codec.binary.Base64;
-
-public abstract class AbstractPrimitiveTest extends AbstractTest {
-
- protected abstract ODataFormat getFormat();
-
- protected abstract ODataClient getClient();
-
- protected ODataVersion getVersion() {
- return getClient().getWorkingVersion();
- }
-
- protected String getFilename(final String entity, final String propertyName) {
- return getVersion().name().toLowerCase()
- + File.separatorChar
- + entity.replace('(', '_').replace(")", "")
- + "_" + propertyName.replaceAll("/", "_") + "." + getSuffix(getFormat());
- }
-
- protected ODataPrimitiveValue writePrimitiveValue(final ODataPrimitiveValue value) {
- final ODataPrimitiveValue newValue;
- if (EdmSimpleType.isGeospatial(value.getTypeName())) {
- newValue = getClient().getGeospatialValueBuilder().
- setType(EdmSimpleType.fromValue(value.getTypeName())).
- setTree(((ODataGeospatialValue) value).toTree()).build();
- } else {
- newValue = getClient().getPrimitiveValueBuilder().
- setType(EdmSimpleType.fromValue(value.getTypeName())).
- setValue(value.toValue()).build();
- }
-
- final InputStream written = getClient().getWriter().writeProperty(
- getClient().getObjectFactory().newPrimitiveProperty(ODataConstants.ELEM_PROPERTY, newValue),
- getFormat());
- return readPrimitiveValue(written);
- }
-
- protected ODataPrimitiveValue readPrimitiveValue(final InputStream input) {
- final ODataProperty property = getClient().getReader().readProperty(input, getFormat());
- assertNotNull(property);
- assertTrue(property.hasPrimitiveValue());
- assertNotNull(property.getPrimitiveValue());
-
- return property.getPrimitiveValue();
- }
-
- protected ODataPrimitiveValue readPrimitiveValue(final String entity, final String propertyName) {
- final ODataPrimitiveValue value =
- readPrimitiveValue(getClass().getResourceAsStream(getFilename(entity, propertyName)));
-
- if (EdmSimpleType.isGeospatial(value.getTypeName())) {
- assertEquals(value.toValue(), writePrimitiveValue(value).toValue());
- } else {
- assertEquals(value.toString(), writePrimitiveValue(value).toString());
- }
-
- return value;
- }
-
- protected void int32(final String entity, final String propertyName, final int check) {
- final ODataPrimitiveValue opv = readPrimitiveValue(entity, propertyName);
- assertEquals(EdmSimpleType.Int32.toString(), opv.getTypeName());
-
- final Integer value = opv.<Integer>toCastValue();
- assertNotNull(value);
- assertTrue(check == value);
- }
-
- protected void string(final String entity, final String propertyName, final String check) {
- final ODataPrimitiveValue opv = readPrimitiveValue(entity, propertyName);
- assertEquals(EdmSimpleType.String.toString(), opv.getTypeName());
-
- final String value = opv.<String>toCastValue();
- assertNotNull(value);
- assertEquals(check, value);
-
- assertEquals(opv, writePrimitiveValue(opv));
- }
-
- protected void decimal(final String entity, final String propertyName, final BigDecimal check) {
- final ODataPrimitiveValue opv = readPrimitiveValue(entity, propertyName);
- assertEquals(EdmSimpleType.Decimal.toString(), opv.getTypeName());
-
- final BigDecimal value = opv.<BigDecimal>toCastValue();
- assertNotNull(value);
- assertTrue(check.equals(value));
- }
-
- protected void datetime(final String entity, final String propertyName, final String check) {
- final ODataPrimitiveValue opv = readPrimitiveValue(entity, propertyName);
- assertEquals(EdmSimpleType.DateTime.toString(), opv.getTypeName());
-
- final ODataTimestamp value = opv.<ODataTimestamp>toCastValue();
- assertNotNull(value);
- assertEquals(check, opv.toString());
- }
-
- protected void guid(final String entity, final String propertyName, final String check) {
- final ODataPrimitiveValue opv = readPrimitiveValue(entity, propertyName);
- assertEquals(EdmSimpleType.Guid.toString(), opv.getTypeName());
-
- final UUID value = opv.<UUID>toCastValue();
- assertNotNull(value);
- assertEquals(check, opv.toString());
- }
-
- protected void binary(final String entity, final String propertyName) {
- final ODataPrimitiveValue opv = readPrimitiveValue(entity, propertyName);
- assertEquals(EdmSimpleType.Binary.toString(), opv.getTypeName());
-
- final byte[] value = opv.<byte[]>toCastValue();
- assertNotNull(value);
- assertTrue(value.length > 0);
- assertTrue(Base64.isBase64(opv.toString()));
- }
-
- private void checkPoint(final Point point, final Point check) {
- assertEquals(check.getX(), point.getX(), 0);
- assertEquals(check.getY(), point.getY(), 0);
- assertEquals(check.getZ(), point.getZ(), 0);
- }
-
- protected void point(
- final String entity,
- final String propertyName,
- final Point expectedValues,
- final EdmSimpleType expectedType,
- final Dimension expectedDimension) {
-
- final ODataPrimitiveValue opv = readPrimitiveValue(entity, propertyName);
- assertEquals(expectedType.toString(), opv.getTypeName());
-
- final Point point = opv.<Point>toCastValue();
- assertNotNull(point);
- assertEquals(expectedDimension, point.getDimension());
-
- checkPoint(point, expectedValues);
- }
-
- private void checkLine(final LineString line, final List<Point> check) {
- final List<Point> points = new ArrayList<Point>();
-
- for (Point point : line) {
- points.add(point);
- }
-
- assertEquals(check.size(), points.size());
-
- for (int i = 0; i < points.size(); i++) {
- checkPoint(points.get(i), check.get(i));
- }
- }
-
- protected void lineString(
- final String entity,
- final String propertyName,
- final List<Point> check,
- final EdmSimpleType expectedType,
- final Dimension expectedDimension) {
-
- final ODataPrimitiveValue opv = readPrimitiveValue(entity, propertyName);
- assertEquals(expectedType.toString(), opv.getTypeName());
-
- final LineString lineString = opv.<LineString>toCastValue();
- assertNotNull(lineString);
- assertEquals(expectedDimension, lineString.getDimension());
-
- checkLine(lineString, check);
- }
-
- protected void multiPoint(
- final String entity,
- final String propertyName,
- final List<Point> check,
- final EdmSimpleType expectedType,
- final Dimension expectedDimension) {
-
- final ODataPrimitiveValue opv = readPrimitiveValue(entity, propertyName);
- assertEquals(expectedType.toString(), opv.getTypeName());
-
- final MultiPoint multiPoint = opv.<MultiPoint>toCastValue();
- assertNotNull(multiPoint);
- assertEquals(expectedDimension, multiPoint.getDimension());
-
- final List<Point> points = new ArrayList<Point>();
-
- for (Point point : multiPoint) {
- points.add(point);
- }
-
- assertEquals(check.size(), points.size());
-
- for (int i = 0; i < points.size(); i++) {
- checkPoint(points.get(i), check.get(i));
- }
- }
-
- protected void multiLine(
- final String entity,
- final String propertyName,
- final List<List<Point>> check,
- final EdmSimpleType expectedType,
- final Dimension expectedDimension) {
-
- final ODataPrimitiveValue opv = readPrimitiveValue(entity, propertyName);
- assertEquals(expectedType.toString(), opv.getTypeName());
-
- final MultiLineString multiLine = opv.<MultiLineString>toCastValue();
- assertNotNull(multiLine);
- assertEquals(expectedDimension, multiLine.getDimension());
-
- final List<LineString> lines = new ArrayList<LineString>();
-
- int i = 0;
- for (LineString line : multiLine) {
- checkLine(line, check.get(i));
- i++;
- }
- }
-
- private void checkPoligon(
- final Polygon polygon,
- final List<Point> checkInterior,
- final List<Point> checkExterior) {
-
- final List<Point> points = new ArrayList<Point>();
-
- for (Point point : polygon.getInterior()) {
- points.add(point);
- }
-
- assertEquals(checkInterior.size(), points.size());
-
- for (int i = 0; i < points.size(); i++) {
- checkPoint(checkInterior.get(i), points.get(i));
- }
-
- points.clear();
-
- for (Point point : polygon.getExterior()) {
- points.add(point);
- }
-
- assertEquals(checkExterior.size(), points.size());
-
- for (int i = 0; i < points.size(); i++) {
- checkPoint(checkExterior.get(i), points.get(i));
- }
-
- }
-
- protected void polygon(
- final String entity,
- final String propertyName,
- final List<Point> checkInterior,
- final List<Point> checkExterior,
- final EdmSimpleType expectedType,
- final Dimension expectedDimension) {
-
- final ODataPrimitiveValue opv = readPrimitiveValue(entity, propertyName);
- assertEquals(expectedType.toString(), opv.getTypeName());
-
- final Polygon polygon = opv.<Polygon>toCastValue();
-
- assertNotNull(polygon);
- assertEquals(expectedDimension, polygon.getDimension());
-
- checkPoligon(polygon, checkInterior, checkExterior);
-
- }
-
- protected void multiPolygon(
- final String entity,
- final String propertyName,
- final List<List<Point>> checkInterior,
- final List<List<Point>> checkExterior,
- final EdmSimpleType expectedType,
- final Dimension expectedDimension) {
-
- final ODataPrimitiveValue opv = readPrimitiveValue(entity, propertyName);
- assertEquals(expectedType.toString(), opv.getTypeName());
-
- final MultiPolygon multiPolygon = opv.<MultiPolygon>toCastValue();
- assertNotNull(multiPolygon);
- assertEquals(expectedDimension, multiPolygon.getDimension());
-
- int i = 0;
- for (Polygon polygon : multiPolygon) {
- checkPoligon(
- polygon,
- checkInterior.isEmpty() ? Collections.<Point>emptyList() : checkInterior.get(i),
- checkExterior.isEmpty() ? Collections.<Point>emptyList() : checkExterior.get(i));
- i++;
- }
- }
-
- protected void geomCollection(
- final String entity,
- final String propertyName,
- final EdmSimpleType expectedType,
- final Dimension expectedDimension) {
-
- final ODataPrimitiveValue opv = readPrimitiveValue(entity, propertyName);
- assertEquals(expectedType.toString(), opv.getTypeName());
-
- final GeospatialCollection collection = opv.<GeospatialCollection>toCastValue();
- assertNotNull(collection);
- assertEquals(expectedDimension, collection.getDimension());
-
- final Iterator<Geospatial> itor = collection.iterator();
- int count = 0;
- while (itor.hasNext()) {
- count++;
-
- final Geospatial geospatial = itor.next();
- if (count == 1) {
- assertTrue(geospatial instanceof Point);
- }
- if (count == 2) {
- assertTrue(geospatial instanceof LineString);
- }
- }
- assertEquals(2, count);
- }
-
- protected void geogCollection(
- final String entity,
- final String propertyName,
- final EdmSimpleType expectedType,
- final Dimension expectedDimension) {
-
- final ODataPrimitiveValue opv = readPrimitiveValue(entity, propertyName);
- assertEquals(expectedType.toString(), opv.getTypeName());
-
- final GeospatialCollection collection = opv.<GeospatialCollection>toCastValue();
- assertNotNull(collection);
- assertEquals(expectedDimension, collection.getDimension());
-
- final Iterator<Geospatial> itor = collection.iterator();
- int count = 0;
- while (itor.hasNext()) {
- count++;
-
- final Geospatial geospatial = itor.next();
- if (count == 1) {
- assertTrue(geospatial instanceof GeospatialCollection);
- }
- if (count == 2) {
- assertTrue(geospatial instanceof GeospatialCollection);
- }
- }
- assertEquals(2, count);
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/19f3792f/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/AbstractPropertyTest.java
----------------------------------------------------------------------
diff --git a/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/AbstractPropertyTest.java b/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/AbstractPropertyTest.java
deleted file mode 100644
index ecbe16f..0000000
--- a/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/AbstractPropertyTest.java
+++ /dev/null
@@ -1,178 +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.engine;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-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.ODataObjectFactory;
-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.edm.EdmSimpleType;
-import com.msopentech.odatajclient.engine.format.ODataFormat;
-import com.msopentech.odatajclient.engine.utils.ODataVersion;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Iterator;
-import org.apache.commons.io.IOUtils;
-import org.junit.Test;
-
-public abstract class AbstractPropertyTest extends AbstractTest {
-
- protected abstract ODataFormat getFormat();
-
- protected abstract ODataClient getClient();
-
- protected ODataVersion getVersion() {
- return getClient().getWorkingVersion();
- }
-
- @Test
- public void readPropertyValue() throws IOException {
- final InputStream input = getClass().getResourceAsStream(
- getVersion().name().toLowerCase() + File.separatorChar
- + "Customer_-10_CustomerId_value.txt");
-
- final ODataValue value = getClient().getPrimitiveValueBuilder().
- setType(EdmSimpleType.String).
- setText(IOUtils.toString(input)).
- build();
- assertNotNull(value);
- assertEquals("-10", value.toString());
- }
-
- private ODataProperty primitive() throws IOException {
- 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());
-
- ODataProperty comparable;
- final ODataProperty written = getClient().getReader().readProperty(
- getClient().getWriter().writeProperty(property, getFormat()), getFormat());
- if (getFormat() == ODataFormat.XML) {
- comparable = written;
- } else {
- // This is needed because type information gets lost with JSON serialization
- final ODataPrimitiveValue typedValue = getClient().getPrimitiveValueBuilder().
- setType(EdmSimpleType.fromValue(property.getPrimitiveValue().getTypeName())).
- setText(written.getPrimitiveValue().toString()).
- build();
- comparable = getClient().getObjectFactory().newPrimitiveProperty(written.getName(), typedValue);
- }
-
- assertEquals(property, comparable);
-
- return property;
- }
-
- @Test
- public void readPrimitiveProperty() throws IOException {
- primitive();
- }
-
- private ODataProperty complex() throws IOException {
- final InputStream input = getClass().getResourceAsStream(
- getVersion().name().toLowerCase() + File.separatorChar
- + "Customer_-10_PrimaryContactInfo." + getSuffix(getFormat()));
- final ODataProperty property = getClient().getReader().readProperty(input, getFormat());
- assertNotNull(property);
- assertTrue(property.hasComplexValue());
- assertEquals(6, property.getComplexValue().size());
-
- ODataProperty comparable;
- final ODataProperty written = getClient().getReader().readProperty(
- getClient().getWriter().writeProperty(property, getFormat()), getFormat());
- if (getFormat() == ODataFormat.XML) {
- comparable = written;
- } else {
- // This is needed because type information gets lost with JSON serialization
- final ODataComplexValue typedValue = new ODataComplexValue(property.getComplexValue().getTypeName());
- for (final Iterator<ODataProperty> itor = written.getComplexValue().iterator(); itor.hasNext();) {
- final ODataProperty prop = itor.next();
- typedValue.add(prop);
- }
- comparable = getClient().getObjectFactory().newComplexProperty(written.getName(), typedValue);
- }
-
- assertEquals(property, comparable);
-
- return property;
- }
-
- @Test
- public void readComplexProperty() throws IOException {
- complex();
- }
-
- private ODataProperty collection() throws IOException {
- final InputStream input = getClass().getResourceAsStream(
- getVersion().name().toLowerCase() + File.separatorChar
- + "Customer_-10_BackupContactInfo." + getSuffix(getFormat()));
- final ODataProperty property = getClient().getReader().readProperty(input, getFormat());
- assertNotNull(property);
- assertTrue(property.hasCollectionValue());
- assertEquals(9, property.getCollectionValue().size());
-
- ODataProperty comparable;
- final ODataProperty written = getClient().getReader().readProperty(
- getClient().getWriter().writeProperty(property, getFormat()), getFormat());
- if (getFormat() == ODataFormat.XML) {
- comparable = written;
- } else {
- // This is needed because type information gets lost with JSON serialization
- final ODataCollectionValue typedValue =
- new ODataCollectionValue(property.getCollectionValue().getTypeName());
- for (final Iterator<ODataValue> itor = written.getCollectionValue().iterator(); itor.hasNext();) {
- final ODataValue value = itor.next();
- if (value.isPrimitive()) {
- typedValue.add(value);
- }
- if (value.isComplex()) {
- final ODataComplexValue typedComplexValue =
- new ODataComplexValue("Microsoft.Test.OData.Services.AstoriaDefaultService.ContactDetails");
- for (final Iterator<ODataProperty> valueItor = value.asComplex().iterator(); valueItor.hasNext();) {
- final ODataProperty prop = valueItor.next();
- typedComplexValue.add(prop);
- }
- typedValue.add(typedComplexValue);
- }
- }
- comparable = getClient().getObjectFactory().newCollectionProperty(written.getName(), typedValue);
- }
-
- assertEquals(property, comparable);
-
- return property;
- }
-
- @Test
- public void readCollectionProperty() throws IOException {
- collection();
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/19f3792f/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/AbstractTest.java
----------------------------------------------------------------------
diff --git a/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/AbstractTest.java b/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/AbstractTest.java
deleted file mode 100644
index 0a90a6a..0000000
--- a/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/AbstractTest.java
+++ /dev/null
@@ -1,59 +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.engine;
-
-import com.msopentech.odatajclient.engine.client.ODataClient;
-import com.msopentech.odatajclient.engine.client.ODataClientFactory;
-import com.msopentech.odatajclient.engine.client.ODataV3Client;
-import com.msopentech.odatajclient.engine.client.ODataV4Client;
-import com.msopentech.odatajclient.engine.format.ODataFormat;
-import com.msopentech.odatajclient.engine.format.ODataPubFormat;
-import java.util.Locale;
-import org.junit.BeforeClass;
-
-public abstract class AbstractTest {
-
- protected static ODataV3Client v3Client;
-
- protected static ODataV4Client v4Client;
-
- protected abstract ODataClient getClient();
-
- /**
- * This is needed for correct number handling (Double, for example).
- */
- @BeforeClass
- public static void setEnglishLocale() {
- Locale.setDefault(Locale.ENGLISH);
- }
-
- @BeforeClass
- public static void setClientInstances() {
- v3Client = ODataClientFactory.getV3();
- v4Client = ODataClientFactory.getV4();
- }
-
- protected String getSuffix(final ODataPubFormat format) {
- return format == ODataPubFormat.ATOM ? "xml" : "json";
- }
-
- protected String getSuffix(final ODataFormat format) {
- return format == ODataFormat.XML ? "xml" : "json";
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/19f3792f/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/EntitySetTest.java
----------------------------------------------------------------------
diff --git a/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/EntitySetTest.java b/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/EntitySetTest.java
deleted file mode 100644
index 0bc44f0..0000000
--- a/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/EntitySetTest.java
+++ /dev/null
@@ -1,62 +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.engine;
-
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertEquals;
-
-import com.msopentech.odatajclient.engine.client.ODataV3Client;
-import com.msopentech.odatajclient.engine.data.ODataEntitySet;
-import com.msopentech.odatajclient.engine.data.ResourceFactory;
-import com.msopentech.odatajclient.engine.format.ODataPubFormat;
-import java.io.IOException;
-import java.io.InputStream;
-import org.junit.Test;
-
-public class EntitySetTest extends AbstractTest {
-
- @Override
- protected ODataV3Client getClient() {
- return v3Client;
- }
-
- private void read(final ODataPubFormat format) throws IOException {
- final InputStream input = getClass().getResourceAsStream("Customer." + getSuffix(format));
- final ODataEntitySet entitySet = getClient().getBinder().getODataEntitySet(
- getClient().getDeserializer().toFeed(input, ResourceFactory.feedClassForFormat(format)));
- assertNotNull(entitySet);
-
- assertEquals(2, entitySet.getEntities().size());
- assertNotNull(entitySet.getNext());
-
- final ODataEntitySet written = getClient().getBinder().getODataEntitySet(
- getClient().getBinder().getFeed(entitySet, ResourceFactory.feedClassForFormat(format)));
- assertEquals(entitySet, written);
- }
-
- @Test
- public void fromAtom() throws IOException {
- read(ODataPubFormat.ATOM);
- }
-
- @Test
- public void fromJSON() throws IOException {
- read(ODataPubFormat.JSON);
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/19f3792f/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/EntityTest.java
----------------------------------------------------------------------
diff --git a/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/EntityTest.java b/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/EntityTest.java
deleted file mode 100644
index 5a65534..0000000
--- a/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/EntityTest.java
+++ /dev/null
@@ -1,191 +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.engine;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import com.msopentech.odatajclient.engine.client.ODataV3Client;
-import com.msopentech.odatajclient.engine.data.ODataEntity;
-import com.msopentech.odatajclient.engine.data.ODataLink;
-import com.msopentech.odatajclient.engine.data.ODataOperation;
-import com.msopentech.odatajclient.engine.data.ODataProperty;
-import com.msopentech.odatajclient.engine.data.ResourceFactory;
-import com.msopentech.odatajclient.engine.metadata.edm.EdmSimpleType;
-import com.msopentech.odatajclient.engine.metadata.edm.geospatial.Geospatial;
-import com.msopentech.odatajclient.engine.metadata.edm.geospatial.GeospatialCollection;
-import com.msopentech.odatajclient.engine.format.ODataPubFormat;
-import java.io.InputStream;
-import java.util.Collections;
-import org.junit.Test;
-
-public class EntityTest extends AbstractTest {
-
- @Override
- protected ODataV3Client getClient() {
- return v3Client;
- }
-
- private void readAndWrite(final ODataPubFormat format) {
- final InputStream input = getClass().getResourceAsStream("Customer_-10." + getSuffix(format));
- final ODataEntity entity = getClient().getBinder().getODataEntity(
- getClient().getDeserializer().toEntry(input, ResourceFactory.entryClassForFormat(format)));
- assertNotNull(entity);
-
- assertEquals("Microsoft.Test.OData.Services.AstoriaDefaultService.Customer", entity.getName());
- assertTrue(entity.getEditLink().toASCIIString().endsWith("/Customer(-10)"));
- assertEquals(5, entity.getNavigationLinks().size());
- assertEquals(2, entity.getEditMediaLinks().size());
-
- boolean check = false;
-
- for (ODataLink link : entity.getNavigationLinks()) {
- if ("Wife".equals(link.getName()) && (link.getLink().toASCIIString().endsWith("/Customer(-10)/Wife"))) {
- check = true;
- }
- }
-
- assertTrue(check);
-
- final ODataEntity written = getClient().getBinder().getODataEntity(
- getClient().getBinder().getEntry(entity, ResourceFactory.entryClassForFormat(format)));
- assertEquals(entity, written);
- }
-
- @Test
- public void fromAtom() {
- readAndWrite(ODataPubFormat.ATOM);
- }
-
- @Test
- public void fromJSON() {
- readAndWrite(ODataPubFormat.JSON_FULL_METADATA);
- }
-
- private void readGeospatial(final ODataPubFormat format) {
- final InputStream input = getClass().getResourceAsStream("AllGeoTypesSet_-8." + getSuffix(format));
- final ODataEntity entity = getClient().getBinder().getODataEntity(
- getClient().getDeserializer().toEntry(input, ResourceFactory.entryClassForFormat(format)));
- assertNotNull(entity);
-
- boolean found = false;
- for (ODataProperty property : entity.getProperties()) {
- if ("GeogMultiLine".equals(property.getName())) {
- found = true;
- assertTrue(property.hasPrimitiveValue());
- assertEquals(EdmSimpleType.GeographyMultiLineString.toString(),
- property.getPrimitiveValue().getTypeName());
- }
- }
- assertTrue(found);
-
- final ODataEntity written = getClient().getBinder().getODataEntity(
- getClient().getBinder().getEntry(entity, ResourceFactory.entryClassForFormat(format)));
- assertEquals(entity, written);
- }
-
- @Test
- public void withGeospatialFromAtom() {
- readGeospatial(ODataPubFormat.ATOM);
- }
-
- @Test
- public void withGeospatialFromJSON() {
- // this needs to be full, otherwise there is no mean to recognize geospatial types
- readGeospatial(ODataPubFormat.JSON_FULL_METADATA);
- }
-
- private void withActions(final ODataPubFormat format) {
- final InputStream input = getClass().getResourceAsStream("ComputerDetail_-10." + getSuffix(format));
- final ODataEntity entity = getClient().getBinder().getODataEntity(
- getClient().getDeserializer().toEntry(input, ResourceFactory.entryClassForFormat(format)));
- assertNotNull(entity);
-
- assertEquals(1, entity.getOperations().size());
- assertEquals("ResetComputerDetailsSpecifications", entity.getOperations().get(0).getTitle());
-
- final ODataEntity written = getClient().getBinder().getODataEntity(
- getClient().getBinder().getEntry(entity, ResourceFactory.entryClassForFormat(format)));
- entity.setOperations(Collections.<ODataOperation>emptyList());
- assertEquals(entity, written);
- }
-
- @Test
- public void withActionsFromAtom() {
- withActions(ODataPubFormat.ATOM);
- }
-
- @Test
- public void withActionsFromJSON() {
- // this needs to be full, otherwise actions will not be provided
- withActions(ODataPubFormat.JSON_FULL_METADATA);
- }
-
- private void mediaEntity(final ODataPubFormat format) {
- final InputStream input = getClass().getResourceAsStream("Car_16." + getSuffix(format));
- final ODataEntity entity = getClient().getBinder().getODataEntity(
- getClient().getDeserializer().toEntry(input, ResourceFactory.entryClassForFormat(format)));
- assertNotNull(entity);
- assertTrue(entity.isMediaEntity());
- assertNotNull(entity.getMediaContentSource());
- assertNotNull(entity.getMediaContentType());
-
- final ODataEntity written = getClient().getBinder().getODataEntity(
- getClient().getBinder().getEntry(entity, ResourceFactory.entryClassForFormat(format)));
- assertEquals(entity, written);
- }
-
- @Test
- public void mediaEntityFromAtom() {
- mediaEntity(ODataPubFormat.ATOM);
- }
-
- @Test
- public void mediaEntityFromJSON() {
- mediaEntity(ODataPubFormat.JSON_FULL_METADATA);
- }
-
- private void issue128(final ODataPubFormat format) {
- final InputStream input = getClass().getResourceAsStream("AllGeoTypesSet_-5." + getSuffix(format));
- final ODataEntity entity = getClient().getBinder().getODataEntity(
- getClient().getDeserializer().toEntry(input, ResourceFactory.entryClassForFormat(format)));
- assertNotNull(entity);
-
- final ODataProperty geogCollection = entity.getProperty("GeogCollection");
- assertEquals(EdmSimpleType.GeographyCollection.toString(), geogCollection.getPrimitiveValue().getTypeName());
-
- int count = 0;
- for (Geospatial g : geogCollection.getPrimitiveValue().<GeospatialCollection>toCastValue()) {
- assertNotNull(g);
- count++;
- }
- assertEquals(2, count);
- }
-
- @Test
- public void issue128FromAtom() {
- issue128(ODataPubFormat.ATOM);
- }
-
- @Test
- public void issue128FromJSON() {
- issue128(ODataPubFormat.JSON_FULL_METADATA);
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/19f3792f/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/EntryReadTest.java
----------------------------------------------------------------------
diff --git a/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/EntryReadTest.java b/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/EntryReadTest.java
deleted file mode 100644
index f2a6661..0000000
--- a/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/EntryReadTest.java
+++ /dev/null
@@ -1,96 +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.engine;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import com.msopentech.odatajclient.engine.client.ODataV3Client;
-import com.msopentech.odatajclient.engine.data.Entry;
-import com.msopentech.odatajclient.engine.data.ResourceFactory;
-import com.msopentech.odatajclient.engine.format.ODataPubFormat;
-import com.msopentech.odatajclient.engine.utils.ODataConstants;
-import com.msopentech.odatajclient.engine.utils.XMLUtils;
-import java.io.IOException;
-import java.io.InputStream;
-import org.junit.Test;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-
-public class EntryReadTest extends AbstractTest {
-
- @Override
- protected ODataV3Client getClient() {
- return v3Client;
- }
-
- private void read(final ODataPubFormat format) throws IOException {
- InputStream input = getClass().getResourceAsStream("Car_16." + getSuffix(format));
-
- Entry entry = getClient().getDeserializer().toEntry(input, ResourceFactory.entryClassForFormat(format));
- assertNotNull(entry);
-
- input.close();
-
- // ---------------------------------------------
- input = getClass().getResourceAsStream("Customer_-10." + getSuffix(format));
-
- entry = getClient().getDeserializer().toEntry(input, ResourceFactory.entryClassForFormat(format));
- assertNotNull(entry);
-
- input.close();
-
- if (ODataPubFormat.JSON_FULL_METADATA == format || ODataPubFormat.ATOM == format) {
- assertEquals("Microsoft.Test.OData.Services.AstoriaDefaultService.Customer", entry.getType());
- assertNotNull(entry.getBaseURI());
- }
-
- final Element content = entry.getContent();
- assertEquals(ODataConstants.ELEM_PROPERTIES, content.getNodeName());
-
- boolean entered = false;
- boolean checked = false;
- for (int i = 0; i < content.getChildNodes().getLength(); i++) {
- entered = true;
-
- final Node property = content.getChildNodes().item(i);
- if ("PrimaryContactInfo".equals(XMLUtils.getSimpleName(property))) {
- checked = true;
-
- if (ODataPubFormat.JSON_FULL_METADATA == format || ODataPubFormat.ATOM == format) {
- assertEquals("Microsoft.Test.OData.Services.AstoriaDefaultService.ContactDetails",
- ((Element) property).getAttribute(ODataConstants.ATTR_M_TYPE));
- }
- }
- }
- assertTrue(entered);
- assertTrue(checked);
- }
-
- @Test
- public void atom() throws IOException {
- read(ODataPubFormat.ATOM);
- }
-
- @Test
- public void json() throws IOException {
- read(ODataPubFormat.JSON_FULL_METADATA);
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/19f3792f/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/ErrorTest.java
----------------------------------------------------------------------
diff --git a/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/ErrorTest.java b/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/ErrorTest.java
deleted file mode 100644
index 72a9553..0000000
--- a/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/ErrorTest.java
+++ /dev/null
@@ -1,48 +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.engine;
-
-import static org.junit.Assert.assertNotNull;
-
-import com.msopentech.odatajclient.engine.client.ODataV3Client;
-import com.msopentech.odatajclient.engine.data.ODataError;
-import org.junit.Test;
-
-public class ErrorTest extends AbstractTest {
-
- @Override
- protected ODataV3Client getClient() {
- return v3Client;
- }
-
- private void xmlError(final String name) {
- final ODataError error = getClient().getReader().readError(getClass().getResourceAsStream(name), true);
- assertNotNull(error);
- }
-
- @Test
- public void error() {
- xmlError("error.xml");
- }
-
- @Test
- public void stacktrace() {
- xmlError("stacktrace.xml");
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/19f3792f/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/PrimitiveValueTest.java
----------------------------------------------------------------------
diff --git a/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/PrimitiveValueTest.java b/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/PrimitiveValueTest.java
deleted file mode 100644
index cff6210..0000000
--- a/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/PrimitiveValueTest.java
+++ /dev/null
@@ -1,585 +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.engine;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import com.msopentech.odatajclient.engine.client.ODataClientFactory;
-import com.msopentech.odatajclient.engine.client.ODataV3Client;
-import com.msopentech.odatajclient.engine.data.ODataDuration;
-import com.msopentech.odatajclient.engine.data.ODataPrimitiveValue;
-import com.msopentech.odatajclient.engine.data.ODataTimestamp;
-import com.msopentech.odatajclient.engine.data.ODataValue;
-import com.msopentech.odatajclient.engine.metadata.edm.EdmSimpleType;
-import com.msopentech.odatajclient.engine.metadata.edm.geospatial.Geospatial;
-import com.msopentech.odatajclient.engine.metadata.edm.geospatial.GeospatialCollection;
-import com.msopentech.odatajclient.engine.metadata.edm.geospatial.LineString;
-import com.msopentech.odatajclient.engine.metadata.edm.geospatial.MultiLineString;
-import com.msopentech.odatajclient.engine.metadata.edm.geospatial.MultiPoint;
-import com.msopentech.odatajclient.engine.metadata.edm.geospatial.MultiPolygon;
-import com.msopentech.odatajclient.engine.metadata.edm.geospatial.Point;
-import com.msopentech.odatajclient.engine.metadata.edm.geospatial.Polygon;
-import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.UUID;
-import org.apache.commons.codec.binary.Base64;
-import org.junit.Test;
-
-public class PrimitiveValueTest extends AbstractTest {
-
- @Override
- protected ODataV3Client getClient() {
- return v3Client;
- }
-
- @Test
- public void manageInt32() {
- final int primitive = -10;
- ODataValue value = getClient().getPrimitiveValueBuilder().setType(EdmSimpleType.Int32).setValue(primitive).
- build();
- assertEquals(EdmSimpleType.Int32.toString(), value.asPrimitive().getTypeName());
- assertEquals(Integer.valueOf(primitive), value.asPrimitive().<Integer>toCastValue());
-
- value = getClient().getPrimitiveValueBuilder().setType(EdmSimpleType.Int32).setText("9").build();
- assertEquals("9", value.asPrimitive().<Integer>toCastValue().toString());
- }
-
- @Test
- public void manageString() {
- final String primitive = UUID.randomUUID().toString();
- ODataValue value = getClient().getPrimitiveValueBuilder().setType(EdmSimpleType.String).setText(primitive).
- build();
- assertEquals(EdmSimpleType.String.toString(), value.asPrimitive().getTypeName());
- assertEquals(primitive, value.toString());
-
- value = getClient().getPrimitiveValueBuilder().setType(EdmSimpleType.String).
- setText("1126a28b-a4af-4bbd-bf0a-2b2c22635565").build();
- assertEquals("1126a28b-a4af-4bbd-bf0a-2b2c22635565", value.asPrimitive().<String>toCastValue().toString());
- }
-
- @Test
- public void manageDecimal() {
- final BigDecimal primitive = new BigDecimal("-79228162514264337593543950335");
- ODataValue value = getClient().getPrimitiveValueBuilder().setType(EdmSimpleType.Decimal).setValue(primitive).
- build();
- assertEquals(EdmSimpleType.Decimal.toString(), value.asPrimitive().getTypeName());
- assertEquals(primitive, value.asPrimitive().<BigDecimal>toCastValue());
-
- value = getClient().getPrimitiveValueBuilder().setType(EdmSimpleType.Decimal).
- setText("-79228162514264337593543950335").build();
- assertEquals("-79228162514264337593543950335", value.asPrimitive().<BigDecimal>toCastValue().toString());
- }
-
- @Test
- public void manageDateTime() {
- // OData V3 only
- final String primitive = "2013-01-10T06:27:51.1667673";
- try {
- new ODataPrimitiveValue.Builder(ODataClientFactory.getV4()).
- setType(EdmSimpleType.DateTime).setText(primitive).build();
- fail();
- } catch (IllegalArgumentException iae) {
- // ignore
- }
- final ODataValue value =
- getClient().getPrimitiveValueBuilder().setType(EdmSimpleType.DateTime).setText(primitive).build();
- assertEquals(EdmSimpleType.DateTime.toString(), value.asPrimitive().getTypeName());
- // performed cast to improve the check
- assertEquals(primitive, value.asPrimitive().<ODataTimestamp>toCastValue().toString());
- }
-
- @Test
- public void manageTime() {
- // OData V3 only
- final String primitive = "-P9DT51M10.5063807S";
- try {
- new ODataPrimitiveValue.Builder(ODataClientFactory.getV4()).
- setType(EdmSimpleType.Time).setText(primitive).build();
- fail();
- } catch (IllegalArgumentException iae) {
- // ignore
- }
-
- final ODataValue value =
- getClient().getPrimitiveValueBuilder().setType(EdmSimpleType.Time).setText(primitive).build();
- assertEquals(EdmSimpleType.Time.toString(), value.asPrimitive().getTypeName());
- // performed cast to improve the check
- assertEquals(primitive, value.asPrimitive().<ODataDuration>toCastValue().toString());
- }
-
- @Test
- public void manageTimeOfDay() {
- // OData V4 only
- final String primitive = "-P9DT51M12.5063807S";
- try {
- getClient().getPrimitiveValueBuilder().setType(EdmSimpleType.TimeOfDay).setText(primitive).build();
- fail();
- } catch (IllegalArgumentException iae) {
- // ignore
- }
-
- final ODataValue value = new ODataPrimitiveValue.Builder(ODataClientFactory.getV4()).
- setType(EdmSimpleType.TimeOfDay).setText(primitive).build();
- assertEquals(EdmSimpleType.TimeOfDay.toString(), value.asPrimitive().getTypeName());
- // performed cast to improve the check
- assertEquals(primitive, value.asPrimitive().<ODataDuration>toCastValue().toString());
- }
-
- @Test
- public void manageDate() {
- // OData V4 only
- final String primitive = "2013-01-10";
- try {
- getClient().getPrimitiveValueBuilder().setType(EdmSimpleType.Date).setText(primitive).build();
- fail();
- } catch (IllegalArgumentException iae) {
- // ignore
- }
-
- final ODataValue value = new ODataPrimitiveValue.Builder(ODataClientFactory.getV4()).
- setType(EdmSimpleType.Date).setText(primitive).build();
- assertEquals(EdmSimpleType.Date.toString(), value.asPrimitive().getTypeName());
- // performed cast to improve the check
- assertEquals(primitive, value.asPrimitive().<ODataTimestamp>toCastValue().toString());
- }
-
- @Test
- public void manageDateTimeOffset() {
- final String primitive = "2013-01-10T02:00:00";
- final ODataValue value = getClient().getPrimitiveValueBuilder().setType(EdmSimpleType.DateTimeOffset).
- setText(primitive).build();
- assertEquals(EdmSimpleType.DateTimeOffset.toString(), value.asPrimitive().getTypeName());
- // performed cast to improve the check
- assertEquals(primitive, value.asPrimitive().<ODataTimestamp>toCastValue().toString());
- }
-
- @Test
- public void manageGuid() {
- final UUID primitive = UUID.fromString("1126a28b-a4af-4bbd-bf0a-2b2c22635565");
- ODataValue value = getClient().getPrimitiveValueBuilder().setType(EdmSimpleType.Guid).setValue(primitive).
- build();
- assertEquals(EdmSimpleType.Guid.toString(), value.asPrimitive().getTypeName());
- assertEquals(primitive, value.asPrimitive().<UUID>toCastValue());
-
- value = getClient().getPrimitiveValueBuilder().setType(EdmSimpleType.Guid).
- setText("1126a28b-a4af-4bbd-bf0a-2b2c22635565").build();
- assertEquals("1126a28b-a4af-4bbd-bf0a-2b2c22635565", value.asPrimitive().<UUID>toCastValue().toString());
- }
-
- @Test
- public void manageBinary() {
- final byte[] primitive = UUID.randomUUID().toString().getBytes();
- ODataValue value = getClient().getPrimitiveValueBuilder().setType(EdmSimpleType.Binary).setValue(primitive).
- build();
- assertEquals(EdmSimpleType.Binary.toString(), value.asPrimitive().getTypeName());
- assertEquals(
- Base64.encodeBase64String(primitive),
- Base64.encodeBase64String(value.asPrimitive().<byte[]>toCastValue()));
-
- value = getClient().getPrimitiveValueBuilder().setType(EdmSimpleType.Binary).
- setText(Base64.encodeBase64String("primitive".getBytes())).build();
- assertEquals("primitive", new String(value.asPrimitive().<byte[]>toCastValue()));
- }
-
- @Test
- public void managePoint() {
- final Point primitive = new Point(Geospatial.Dimension.GEOGRAPHY);
- primitive.setX(52.8606);
- primitive.setY(173.334);
-
- try {
- getClient().getPrimitiveValueBuilder().setType(EdmSimpleType.GeographyPoint).setValue(primitive).build();
- fail();
- } catch (IllegalArgumentException iae) {
- // nothing top do
- }
-
- final ODataValue value =
- getClient().getGeospatialValueBuilder().setType(EdmSimpleType.GeographyPoint).setValue(primitive).
- build();
- assertEquals(EdmSimpleType.GeographyPoint.toString(), value.asPrimitive().getTypeName());
- assertEquals(Double.valueOf(primitive.getX()), Double.valueOf(value.asPrimitive().<Point>toCastValue().getX()));
- assertEquals(Double.valueOf(primitive.getY()), Double.valueOf(value.asPrimitive().<Point>toCastValue().getY()));
- }
-
- @Test
- public void manageLineString() {
- final List<Point> points = new ArrayList<Point>();
- Point point = new Point(Geospatial.Dimension.GEOGRAPHY);
- point.setX(40.5);
- point.setY(40.5);
- points.add(point);
-
- point = new Point(Geospatial.Dimension.GEOGRAPHY);
- point.setX(30.5);
- point.setY(30.5);
- points.add(point);
-
- point = new Point(Geospatial.Dimension.GEOGRAPHY);
- point.setX(20.5);
- point.setY(40.5);
- points.add(point);
-
- point = new Point(Geospatial.Dimension.GEOGRAPHY);
- point.setX(10.5);
- point.setY(30.5);
- points.add(point);
-
- final LineString primitive = new LineString(Geospatial.Dimension.GEOGRAPHY, points);
-
- final ODataValue value = getClient().getGeospatialValueBuilder().setType(EdmSimpleType.GeographyLineString).
- setValue(primitive).build();
- assertEquals(EdmSimpleType.GeographyLineString.toString(), value.asPrimitive().getTypeName());
-
- final Iterator<Point> iter = value.asPrimitive().<LineString>toCastValue().iterator();
-
- // take the third one and check the point value ...
- iter.next();
- iter.next();
- point = iter.next();
-
- assertEquals(Double.valueOf(points.get(2).getX()), Double.valueOf(point.getX()));
- assertEquals(Double.valueOf(points.get(2).getY()), Double.valueOf(point.getY()));
- }
-
- @Test
- public void manageMultiPoint() {
- final List<Point> points = new ArrayList<Point>();
- Point point = new Point(Geospatial.Dimension.GEOMETRY);
- point.setX(0);
- point.setY(0);
- points.add(point);
-
- final MultiPoint primitive = new MultiPoint(Geospatial.Dimension.GEOMETRY, points);
-
- final ODataValue value = getClient().getGeospatialValueBuilder().setType(EdmSimpleType.GeometryMultiPoint).
- setValue(primitive).build();
- assertEquals(EdmSimpleType.GeometryMultiPoint.toString(), value.asPrimitive().getTypeName());
-
- final Iterator<Point> iter = value.asPrimitive().<MultiPoint>toCastValue().iterator();
- point = iter.next();
-
- assertEquals(Double.valueOf(points.get(0).getX()), Double.valueOf(point.getX()));
- assertEquals(Double.valueOf(points.get(0).getY()), Double.valueOf(point.getY()));
- }
-
- @Test
- public void manageMultiLine() {
- final List<LineString> lines = new ArrayList<LineString>();
-
- // line one ...
- List<Point> points = new ArrayList<Point>();
- Point point = new Point(Geospatial.Dimension.GEOMETRY);
- point.setX(10);
- point.setY(10);
- points.add(point);
-
- point = new Point(Geospatial.Dimension.GEOMETRY);
- point.setX(20);
- point.setY(20);
- points.add(point);
-
- point = new Point(Geospatial.Dimension.GEOMETRY);
- point.setX(10);
- point.setY(40);
- points.add(point);
-
- lines.add(new LineString(Geospatial.Dimension.GEOMETRY, points));
-
- // line two ...
- points = new ArrayList<Point>();
-
- point = new Point(Geospatial.Dimension.GEOMETRY);
- point.setX(40);
- point.setY(40);
- points.add(point);
-
- point = new Point(Geospatial.Dimension.GEOMETRY);
- point.setX(30);
- point.setY(30);
- points.add(point);
-
- point = new Point(Geospatial.Dimension.GEOMETRY);
- point.setX(40);
- point.setY(20);
- points.add(point);
-
- point = new Point(Geospatial.Dimension.GEOMETRY);
- point.setX(30);
- point.setY(10);
- points.add(point);
- lines.add(new LineString(Geospatial.Dimension.GEOMETRY, points));
-
- final MultiLineString primitive = new MultiLineString(Geospatial.Dimension.GEOMETRY, lines);
-
- final ODataValue value =
- getClient().getGeospatialValueBuilder().setType(EdmSimpleType.GeometryMultiLineString).
- setValue(primitive).build();
- assertEquals(EdmSimpleType.GeometryMultiLineString.toString(), value.asPrimitive().getTypeName());
-
- final Iterator<LineString> lineIter = value.asPrimitive().<MultiLineString>toCastValue().iterator();
-
- // take the second line and check the third point value ...
- lineIter.next();
- final LineString line = lineIter.next();
-
- final Iterator<Point> pointIter = line.iterator();
- pointIter.next();
- pointIter.next();
- point = pointIter.next();
-
- assertEquals(Double.valueOf(points.get(2).getX()), Double.valueOf(point.getX()));
- assertEquals(Double.valueOf(points.get(2).getY()), Double.valueOf(point.getY()));
- }
-
- @Test
- public void managePolygon() {
-
- final List<Point> interior = new ArrayList<Point>();
- final List<Point> exterior = new ArrayList<Point>();
-
- Point point = new Point(Geospatial.Dimension.GEOGRAPHY);
- point.setX(5);
- point.setY(15);
- exterior.add(point);
-
- point = new Point(Geospatial.Dimension.GEOGRAPHY);
- point.setX(10);
- point.setY(40);
- exterior.add(point);
-
- point = new Point(Geospatial.Dimension.GEOGRAPHY);
- point.setX(20);
- point.setY(10);
- exterior.add(point);
-
- point = new Point(Geospatial.Dimension.GEOGRAPHY);
- point.setX(10);
- point.setY(5);
- exterior.add(point);
-
- point = new Point(Geospatial.Dimension.GEOGRAPHY);
- point.setX(5);
- point.setY(15);
- exterior.add(point);
-
- final Polygon primitive = new Polygon(Geospatial.Dimension.GEOGRAPHY, interior, exterior);
-
- final ODataValue value =
- getClient().getGeospatialValueBuilder().setType(EdmSimpleType.GeographyPolygon).
- setValue(primitive).build();
- assertEquals(EdmSimpleType.GeographyPolygon.toString(), value.asPrimitive().getTypeName());
-
- assertTrue(value.asPrimitive().<Polygon>toCastValue().getInterior().isEmpty());
- final Iterator<Point> iter = value.asPrimitive().<Polygon>toCastValue().getExterior().iterator();
-
- // take the third one ...
- iter.next();
- iter.next();
- point = iter.next();
-
- assertEquals(Double.valueOf(exterior.get(2).getX()), Double.valueOf(point.getX()));
- assertEquals(Double.valueOf(exterior.get(2).getY()), Double.valueOf(point.getY()));
- }
-
- @Test
- public void manageMultiPolygon() {
- final List<Polygon> polygons = new ArrayList<Polygon>();
-
- List<Point> interior = new ArrayList<Point>();
- List<Point> exterior = new ArrayList<Point>();
-
- // exterior one ...
- Point point = new Point(Geospatial.Dimension.GEOMETRY);
- point.setX(40);
- point.setY(40);
- exterior.add(point);
-
- point = new Point(Geospatial.Dimension.GEOMETRY);
- point.setX(20);
- point.setY(45);
- exterior.add(point);
-
- point = new Point(Geospatial.Dimension.GEOMETRY);
- point.setX(45);
- point.setY(30);
- exterior.add(point);
-
- point = new Point(Geospatial.Dimension.GEOMETRY);
- point.setX(40);
- point.setY(40);
- exterior.add(point);
-
- polygons.add(new Polygon(Geospatial.Dimension.GEOMETRY, interior, exterior));
-
- // interior two ...
- interior = new ArrayList<Point>();
- exterior = new ArrayList<Point>();
-
- point = new Point(Geospatial.Dimension.GEOMETRY);
- point.setX(30);
- point.setY(20);
- interior.add(point);
-
- point = new Point(Geospatial.Dimension.GEOMETRY);
- point.setX(20);
- point.setY(25);
- interior.add(point);
-
- point = new Point(Geospatial.Dimension.GEOMETRY);
- point.setX(20);
- point.setY(15);
- interior.add(point);
-
- point = new Point(Geospatial.Dimension.GEOMETRY);
- point.setX(30);
- point.setY(20);
- interior.add(point);
-
- // exterior two ...
- point = new Point(Geospatial.Dimension.GEOMETRY);
- point.setX(20);
- point.setY(35);
- exterior.add(point);
-
- point = new Point(Geospatial.Dimension.GEOMETRY);
- point.setX(45);
- point.setY(20);
- exterior.add(point);
-
- point = new Point(Geospatial.Dimension.GEOMETRY);
- point.setX(30);
- point.setY(5);
- exterior.add(point);
-
- point = new Point(Geospatial.Dimension.GEOMETRY);
- point.setX(10);
- point.setY(10);
- exterior.add(point);
-
- point = new Point(Geospatial.Dimension.GEOMETRY);
- point.setX(10);
- point.setY(30);
- exterior.add(point);
-
- point = new Point(Geospatial.Dimension.GEOMETRY);
- point.setX(20);
- point.setY(35);
- exterior.add(point);
-
- polygons.add(new Polygon(Geospatial.Dimension.GEOMETRY, interior, exterior));
-
- final MultiPolygon primitive = new MultiPolygon(Geospatial.Dimension.GEOMETRY, polygons);
-
- final ODataValue value =
- getClient().getGeospatialValueBuilder().setType(EdmSimpleType.GeometryMultiPolygon).
- setValue(primitive).build();
- assertEquals(EdmSimpleType.GeometryMultiPolygon.toString(), value.asPrimitive().getTypeName());
-
- final Iterator<Polygon> iter = value.asPrimitive().<MultiPolygon>toCastValue().iterator();
-
- // second one polygon
- iter.next();
- final Polygon polygon = iter.next();
- Iterator<Point> pointIter = polygon.getInterior().iterator();
- pointIter.next();
- point = pointIter.next();
-
- // check the second point from interior
- assertEquals(Double.valueOf(interior.get(1).getX()), Double.valueOf(point.getX()));
- assertEquals(Double.valueOf(interior.get(1).getY()), Double.valueOf(point.getY()));
-
- pointIter = polygon.getExterior().iterator();
- pointIter.next();
- pointIter.next();
- point = pointIter.next();
-
- // check the third point from exterior
- assertEquals(Double.valueOf(exterior.get(2).getX()), Double.valueOf(point.getX()));
- assertEquals(Double.valueOf(exterior.get(2).getY()), Double.valueOf(point.getY()));
- }
-
- @Test
- public void manageGeomCollection() {
- final List<Geospatial> collection = new ArrayList<Geospatial>();
-
- Point point = new Point(Geospatial.Dimension.GEOMETRY);
- point.setX(1);
- point.setY(2);
- point.setZ(3);
- collection.add(point);
-
- point = new Point(Geospatial.Dimension.GEOMETRY);
- point.setX(4);
- point.setY(5);
- point.setZ(6);
- collection.add(point);
-
- final GeospatialCollection primitive = new GeospatialCollection(Geospatial.Dimension.GEOMETRY, collection);
-
- final ODataValue value =
- getClient().getGeospatialValueBuilder().setType(EdmSimpleType.GeometryCollection).
- setValue(primitive).build();
- assertEquals(EdmSimpleType.GeometryCollection.toString(), value.asPrimitive().getTypeName());
-
- final Iterator<Geospatial> iter = value.asPrimitive().<GeospatialCollection>toCastValue().iterator();
- iter.next();
- final Point collectedPoint = (Point) iter.next();
-
- assertTrue(point.getX() == collectedPoint.getX()
- && point.getY() == collectedPoint.getY()
- && point.getZ() == collectedPoint.getZ());
- }
-
- @Test
- public void manageGeogCollection() {
- final List<Geospatial> collection = new ArrayList<Geospatial>();
-
- Point point = new Point(Geospatial.Dimension.GEOGRAPHY);
- point.setX(1);
- point.setY(2);
- point.setZ(3);
- collection.add(point);
-
- point = new Point(Geospatial.Dimension.GEOGRAPHY);
- point.setX(4);
- point.setY(5);
- point.setZ(6);
- collection.add(point);
-
- final GeospatialCollection primitive = new GeospatialCollection(Geospatial.Dimension.GEOGRAPHY, collection);
-
- final ODataValue value =
- getClient().getGeospatialValueBuilder().setType(EdmSimpleType.GeographyCollection).
- setValue(primitive).build();
- assertEquals(EdmSimpleType.GeographyCollection.toString(), value.asPrimitive().getTypeName());
-
- final Iterator<Geospatial> iter = value.asPrimitive().<GeospatialCollection>toCastValue().iterator();
- iter.next();
- final Point collectedPoint = (Point) iter.next();
-
- assertTrue(point.getX() == collectedPoint.getX()
- && point.getY() == collectedPoint.getY()
- && point.getZ() == collectedPoint.getZ());
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/19f3792f/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/AbstractMetadataTestITCase.java
----------------------------------------------------------------------
diff --git a/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/AbstractMetadataTestITCase.java b/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/AbstractMetadataTestITCase.java
deleted file mode 100644
index 2fe796c..0000000
--- a/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/AbstractMetadataTestITCase.java
+++ /dev/null
@@ -1,30 +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.engine.it;
-
-import com.msopentech.odatajclient.engine.client.ODataClient;
-
-public abstract class AbstractMetadataTestITCase extends AbstractTestITCase {
-
- protected abstract ODataClient getClient();
-
- protected String getTestServiceRoot() {
- return "http://localhost:9080/StaticService/" + getClient().getWorkingVersion().name() + "/Static.svc";
- }
-}