olingo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sklev...@apache.org
Subject [18/52] [abbrv] [OLINGO-65] Implementation completed
Date Tue, 01 Apr 2014 09:00:30 GMT
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/PropertyTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/PropertyTestITCase.java
b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/PropertyTestITCase.java
index c39335f..56eb4fb 100644
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/PropertyTestITCase.java
+++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/PropertyTestITCase.java
@@ -38,11 +38,11 @@ import org.apache.olingo.client.api.communication.response.ODataValueUpdateRespo
 import org.apache.olingo.client.api.domain.ODataCollectionValue;
 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.client.api.format.ODataValueFormat;
 import org.apache.olingo.client.api.http.HttpMethod;
 import org.apache.olingo.client.api.uri.CommonURIBuilder;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
 import static org.junit.Assert.assertNotNull;
 import org.junit.Test;
 
@@ -56,17 +56,17 @@ public class PropertyTestITCase extends AbstractTestITCase {
   }
 
   @Test
-  public void replacePropertyValue() throws IOException {
+  public void replacePropertyValue() throws Exception {
     updatePropertyValue(ODataValueFormat.TEXT, UpdateType.REPLACE);
   }
 
   @Test
-  public void replacePrimitivePropertyAsXML() throws IOException {
+  public void replacePrimitivePropertyAsXML() throws IOException, EdmPrimitiveTypeException
{
     updatePrimitiveProperty(ODataFormat.XML);
   }
 
   @Test
-  public void replacePrimitivePropertyAsJSON() throws IOException {
+  public void replacePrimitivePropertyAsJSON() throws IOException, EdmPrimitiveTypeException
{
     updatePrimitiveProperty(ODataFormat.JSON_FULL_METADATA);
   }
 
@@ -128,10 +128,10 @@ public class PropertyTestITCase extends AbstractTestITCase {
     final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
     req.setFormat(ODataValueFormat.TEXT);
 
-    final ODataRetrieveResponse<ODataValue> res = req.execute();
+    final ODataRetrieveResponse<ODataPrimitiveValue> res = req.execute();
     assertEquals(200, res.getStatusCode());
 
-    final ODataValue value = res.getBody();
+    final ODataPrimitiveValue value = res.getBody();
     debugODataValue(value, "Retrieved property");
 
     assertNotNull(value);
@@ -157,7 +157,9 @@ public class PropertyTestITCase extends AbstractTestITCase {
             execute();
   }
 
-  private void updatePropertyValue(final ODataValueFormat format, final UpdateType type)
throws IOException {
+  private void updatePropertyValue(final ODataValueFormat format, final UpdateType type)
+          throws IOException, EdmPrimitiveTypeException {
+
     final CommonURIBuilder<?> uriBuilder = client.getURIBuilder(getServiceRoot()).
             appendEntitySetSegment("Customer").appendKeySegment(-9).
             appendPropertySegment("PrimaryContactInfo").
@@ -168,13 +170,13 @@ public class PropertyTestITCase extends AbstractTestITCase {
     ODataValueRequest retrieveReq = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
     retrieveReq.setFormat(format);
 
-    ODataRetrieveResponse<ODataValue> retrieveRes = retrieveReq.execute();
+    ODataRetrieveResponse<ODataPrimitiveValue> retrieveRes = retrieveReq.execute();
     assertEquals(200, retrieveRes.getStatusCode());
 
-    ODataValue phoneNumber = retrieveRes.getBody();
+    ODataPrimitiveValue phoneNumber = retrieveRes.getBody();
     assertNotNull(phoneNumber);
 
-    final String oldMsg = phoneNumber.asPrimitive().<String>toCastValue();
+    final String oldMsg = phoneNumber.toCastValue(String.class);
     final String newMsg = "new msg (" + System.currentTimeMillis() + ")";
 
     assertNotEquals(newMsg, oldMsg);
@@ -197,7 +199,7 @@ public class PropertyTestITCase extends AbstractTestITCase {
     phoneNumber = retrieveRes.getBody();
     assertNotNull(phoneNumber);
 
-    assertEquals(newMsg, phoneNumber.asPrimitive().<String>toCastValue());
+    assertEquals(newMsg, phoneNumber.asPrimitive().toCastValue(String.class));
   }
 
   private void updateComplexProperty(final ODataFormat format, final UpdateType type) throws
IOException {
@@ -293,7 +295,7 @@ public class PropertyTestITCase extends AbstractTestITCase {
     assertEquals(origSize + 1, alternativeNames.getCollectionValue().size());
   }
 
-  private void updatePrimitiveProperty(final ODataFormat format) throws IOException {
+  private void updatePrimitiveProperty(final ODataFormat format) throws IOException, EdmPrimitiveTypeException
{
     final CommonURIBuilder<?> uriBuilder = client.getURIBuilder(getServiceRoot());
     uriBuilder.appendEntitySetSegment("Customer").appendKeySegment(-9).
             appendPropertySegment("PrimaryContactInfo").
@@ -307,7 +309,7 @@ public class PropertyTestITCase extends AbstractTestITCase {
 
     ODataProperty phoneNumber = retrieveRes.getBody();
 
-    final String oldMsg = phoneNumber.getPrimitiveValue().<String>toCastValue();
+    final String oldMsg = phoneNumber.getPrimitiveValue().toCastValue(String.class);
     final String newMsg = "new item " + System.currentTimeMillis();
 
     assertNotEquals(newMsg, oldMsg);
@@ -334,7 +336,7 @@ public class PropertyTestITCase extends AbstractTestITCase {
     assertEquals(200, retrieveRes.getStatusCode());
 
     phoneNumber = retrieveRes.getBody();
-    assertEquals(newMsg, phoneNumber.getPrimitiveValue().<String>toCastValue());
+    assertEquals(newMsg, phoneNumber.getPrimitiveValue().toCastValue(String.class));
   }
 
   private void rawRequest(final ODataFormat format) {

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/QueryOptionsTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/QueryOptionsTestITCase.java
b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/QueryOptionsTestITCase.java
index 3b47ef0..3501482 100644
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/QueryOptionsTestITCase.java
+++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/QueryOptionsTestITCase.java
@@ -36,6 +36,7 @@ import org.apache.olingo.client.api.format.ODataPubFormat;
 import org.apache.olingo.client.api.uri.CommonURIBuilder;
 import org.apache.olingo.client.api.uri.v3.URIBuilder.InlineCount;
 import org.apache.olingo.client.core.data.AtomEntryImpl;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
 import org.junit.Test;
 
 /**
@@ -58,7 +59,7 @@ public class QueryOptionsTestITCase extends AbstractTestITCase {
    * @see org.apache.olingo.client.core.v3.FilterFactoryTest for more tests.
    */
   @Test
-  public void filterOrderby() {
+  public void filterOrderby() throws EdmPrimitiveTypeException {
     final CommonURIBuilder<?> uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
             appendEntitySetSegment("Car").filter("(VIN lt 16)");
 
@@ -71,7 +72,7 @@ public class QueryOptionsTestITCase extends AbstractTestITCase {
     // 2. extract VIN values - sorted ASC by default
     final List<Integer> vinsASC = new ArrayList<Integer>(5);
     for (ODataEntity entity : feed.getEntities()) {
-      final Integer vin = entity.getProperty("VIN").getPrimitiveValue().<Integer>toCastValue();
+      final Integer vin = entity.getProperty("VIN").getPrimitiveValue().toCastValue(Integer.class);
       assertTrue(vin < 16);
       vinsASC.add(vin);
     }
@@ -85,7 +86,7 @@ public class QueryOptionsTestITCase extends AbstractTestITCase {
     // 4. extract again VIN value - now they were required to be sorted DESC
     final List<Integer> vinsDESC = new ArrayList<Integer>(5);
     for (ODataEntity entity : feed.getEntities()) {
-      vinsDESC.add(entity.getProperty("VIN").getPrimitiveValue().<Integer>toCastValue());
+      vinsDESC.add(entity.getProperty("VIN").getPrimitiveValue().toCastValue(Integer.class));
     }
 
     // 5. reverse vinsASC and expect to be equal to vinsDESC
@@ -131,7 +132,7 @@ public class QueryOptionsTestITCase extends AbstractTestITCase {
    * Test <tt>$skiptoken</tt>.
    */
   @Test
-  public void skiptoken() {
+  public void skiptoken() throws EdmPrimitiveTypeException {
     final CommonURIBuilder<?> uriBuilder = client.getURIBuilder(testStaticServiceRootURL);
     uriBuilder.appendEntitySetSegment("Customer").skipToken("-10");
 
@@ -141,7 +142,7 @@ public class QueryOptionsTestITCase extends AbstractTestITCase {
     assertEquals(2, feed.getEntities().size());
 
     for (ODataEntity entity : feed.getEntities()) {
-      assertTrue(entity.getProperty("CustomerId").getPrimitiveValue().<Integer>toCastValue()
> -10);
+      assertTrue(entity.getProperty("CustomerId").getPrimitiveValue().toCastValue(Integer.class)
> -10);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4780fc51/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/EntityTest.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/EntityTest.java
b/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/EntityTest.java
index 903adf8..0147fc0 100644
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/EntityTest.java
+++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/EntityTest.java
@@ -88,9 +88,8 @@ public class EntityTest extends AbstractTest {
     for (ODataProperty property : entity.getProperties()) {
       if ("GeogMultiLine".equals(property.getName())) {
         found = true;
-        assertTrue(property.hasPrimitiveValue());
-        assertEquals(EdmPrimitiveTypeKind.GeographyMultiLineString.getFullQualifiedName().toString(),
-                property.getPrimitiveValue().getTypeName());
+        assertTrue(property.hasGeospatialValue());
+        assertEquals(EdmPrimitiveTypeKind.GeographyMultiLineString, property.getGeospatialValue().getTypeKind());
       }
     }
     assertTrue(found);
@@ -168,11 +167,10 @@ public class EntityTest extends AbstractTest {
     assertNotNull(entity);
 
     final ODataProperty geogCollection = entity.getProperty("GeogCollection");
-    assertEquals(EdmPrimitiveTypeKind.GeographyCollection.getFullQualifiedName().toString(),
-            geogCollection.getPrimitiveValue().getTypeName());
+    assertEquals(EdmPrimitiveTypeKind.GeographyCollection, geogCollection.getGeospatialValue().getTypeKind());
 
     int count = 0;
-    for (Geospatial g : geogCollection.getPrimitiveValue().<GeospatialCollection>toCastValue())
{
+    for (Geospatial g : geogCollection.getGeospatialValue().toCastValue(GeospatialCollection.class))
{
       assertNotNull(g);
       count++;
     }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4780fc51/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/PrimitiveValueTest.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/PrimitiveValueTest.java
b/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/PrimitiveValueTest.java
index c5e4aee..d950d2e 100644
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/PrimitiveValueTest.java
+++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/PrimitiveValueTest.java
@@ -23,18 +23,19 @@ import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import java.math.BigDecimal;
+import java.sql.Timestamp;
 import java.util.ArrayList;
+import java.util.Calendar;
 import java.util.Iterator;
 import java.util.List;
+import java.util.TimeZone;
 import java.util.UUID;
+import javax.xml.datatype.Duration;
 import org.apache.commons.codec.binary.Base64;
-import org.apache.olingo.client.api.v3.ODataClient;
-import org.apache.olingo.client.api.domain.ODataDuration;
-import org.apache.olingo.client.api.domain.ODataPrimitiveValue;
-import org.apache.olingo.client.api.domain.ODataTimestamp;
 import org.apache.olingo.client.api.domain.ODataValue;
+import org.apache.olingo.client.api.v3.ODataClient;
 import org.apache.olingo.client.core.AbstractTest;
-import org.apache.olingo.client.core.ODataClientFactory;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
 import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
 import org.apache.olingo.commons.api.edm.geo.Geospatial;
 import org.apache.olingo.commons.api.edm.geo.GeospatialCollection;
@@ -44,6 +45,7 @@ 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 org.junit.Test;
 
 public class PrimitiveValueTest extends AbstractTest {
@@ -54,119 +56,129 @@ public class PrimitiveValueTest extends AbstractTest {
   }
 
   @Test
-  public void manageInt32() {
+  public void manageInt32() throws EdmPrimitiveTypeException {
     final int primitive = -10;
     ODataValue value = getClient().getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.Int32).
             setValue(primitive).build();
-    assertEquals(EdmPrimitiveTypeKind.Int32.getFullQualifiedName().toString(), value.asPrimitive().getTypeName());
-    assertEquals(Integer.valueOf(primitive), value.asPrimitive().<Integer>toCastValue());
+    assertEquals(EdmPrimitiveTypeKind.Int32, value.asPrimitive().getTypeKind());
+    assertEquals(Integer.valueOf(primitive), value.asPrimitive().toCastValue(Integer.class));
 
     value = getClient().getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.Int32).setText("9").build();
-    assertEquals("9", value.asPrimitive().<Integer>toCastValue().toString());
+    assertEquals("9", value.asPrimitive().toCastValue(Integer.class).toString());
   }
 
   @Test
-  public void manageString() {
+  public void manageString() throws EdmPrimitiveTypeException {
     final String primitive = UUID.randomUUID().toString();
     ODataValue value = getClient().getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.String).
             setText(primitive).build();
-    assertEquals(EdmPrimitiveTypeKind.String.getFullQualifiedName().toString(), value.asPrimitive().getTypeName());
+    assertEquals(EdmPrimitiveTypeKind.String, value.asPrimitive().getTypeKind());
     assertEquals(primitive, value.toString());
 
     value = getClient().getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.String).
             setText("1126a28b-a4af-4bbd-bf0a-2b2c22635565").build();
-    assertEquals("1126a28b-a4af-4bbd-bf0a-2b2c22635565", value.asPrimitive().<String>toCastValue().toString());
+    assertEquals("1126a28b-a4af-4bbd-bf0a-2b2c22635565", value.asPrimitive().toCastValue(String.class).toString());
   }
 
   @Test
-  public void manageDecimal() {
+  public void manageDecimal() throws EdmPrimitiveTypeException {
     final BigDecimal primitive = new BigDecimal("-79228162514264337593543950335");
     ODataValue value = getClient().getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.Decimal).
             setValue(primitive).build();
-    assertEquals(EdmPrimitiveTypeKind.Decimal.getFullQualifiedName().toString(), value.asPrimitive().getTypeName());
-    assertEquals(primitive, value.asPrimitive().<BigDecimal>toCastValue());
+    assertEquals(EdmPrimitiveTypeKind.Decimal, value.asPrimitive().getTypeKind());
+    assertEquals(primitive, value.asPrimitive().toCastValue(BigDecimal.class));
 
     value = getClient().getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.Decimal).
             setText("-79228162514264337593543950335").build();
-    assertEquals("-79228162514264337593543950335", value.asPrimitive().<BigDecimal>toCastValue().toString());
+    assertEquals("-79228162514264337593543950335", value.asPrimitive().toCastValue(BigDecimal.class).toString());
   }
 
   @Test
-  public void manageDateTime() {
-    // OData V3 only
-    final String primitive = "2013-01-10T06:27:51.1667673";
-    try {
-      new ODataPrimitiveValue.Builder(ODataClientFactory.getV4()).
-              setType(EdmPrimitiveTypeKind.DateTime).setText(primitive).build();
-      fail();
-    } catch (IllegalArgumentException iae) {
-      // ignore
-    }
-    final ODataValue value =
-            getClient().getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.DateTime).
-            setText(primitive).build();
-    assertEquals(EdmPrimitiveTypeKind.DateTime.getFullQualifiedName().toString(), value.asPrimitive().getTypeName());
-    // performed cast to improve the check
-    assertEquals(primitive, value.asPrimitive().<ODataTimestamp>toCastValue().toString());
+  public void manageDateTime() throws EdmPrimitiveTypeException {
+    final Calendar expected = Calendar.getInstance();
+    expected.clear();
+    expected.set(2013, 0, 10, 2, 0, 0);
+    expected.set(Calendar.MILLISECOND, 1667673);
+
+    final ODataValue value = getClient().getPrimitiveValueBuilder().
+            setType(EdmPrimitiveTypeKind.DateTime).setValue(expected).build();
+    assertEquals(EdmPrimitiveTypeKind.DateTime, value.asPrimitive().getTypeKind());
+
+    final Calendar actual = value.asPrimitive().toCastValue(Calendar.class);
+    assertEquals(expected.get(Calendar.YEAR), actual.get(Calendar.YEAR));
+    assertEquals(expected.get(Calendar.MONTH), actual.get(Calendar.MONTH));
+    assertEquals(expected.get(Calendar.DATE), actual.get(Calendar.DATE));
+    assertEquals(expected.get(Calendar.HOUR), actual.get(Calendar.HOUR));
+    assertEquals(expected.get(Calendar.MINUTE), actual.get(Calendar.MINUTE));
+    assertEquals(expected.get(Calendar.SECOND), actual.get(Calendar.SECOND));
+    assertEquals(expected.get(Calendar.MILLISECOND), actual.get(Calendar.MILLISECOND));
+
+    // Timestamp
+    final Timestamp timestamp = value.asPrimitive().toCastValue(Timestamp.class);
+    assertEquals(expected.get(Calendar.MILLISECOND), timestamp.getNanos());
+
+    assertEquals("2013-01-10T02:27:47.673", value.asPrimitive().toString());
   }
 
   @Test
-  public void manageTime() {
-    // OData V3 only
+  public void manageTime() throws EdmPrimitiveTypeException {
     final String primitive = "-P9DT51M10.5063807S";
-    try {
-      new ODataPrimitiveValue.Builder(ODataClientFactory.getV4()).
-              setType(EdmPrimitiveTypeKind.Time).setText(primitive).build();
-      fail();
-    } catch (IllegalArgumentException iae) {
-      // ignore
-    }
-
     final ODataValue value =
             getClient().getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.Time).
             setText(primitive).build();
-    assertEquals(EdmPrimitiveTypeKind.Time.getFullQualifiedName().toString(), value.asPrimitive().getTypeName());
+    assertEquals(EdmPrimitiveTypeKind.Time, value.asPrimitive().getTypeKind());
     // performed cast to improve the check
-    assertEquals(primitive, value.asPrimitive().<ODataDuration>toCastValue().toString());
+    assertEquals(primitive, value.asPrimitive().toCastValue(Duration.class).toString());
   }
 
   @Test
-  public void manageDateTimeOffset() {
-    final String primitive = "2013-01-10T02:00:00";
+  public void manageDateTimeOffset() throws EdmPrimitiveTypeException {
+    final Calendar expected = Calendar.getInstance();
+    expected.clear();
+    expected.setTimeZone(TimeZone.getTimeZone("GMT"));
+    expected.set(2013, 0, 10, 2, 0, 0);
+
     final ODataValue value = getClient().getPrimitiveValueBuilder().
-            setType(EdmPrimitiveTypeKind.DateTimeOffset).setText(primitive).build();
-    assertEquals(EdmPrimitiveTypeKind.DateTimeOffset.getFullQualifiedName().toString(), 
-            value.asPrimitive().getTypeName());
-    // performed cast to improve the check
-    assertEquals(primitive, value.asPrimitive().<ODataTimestamp>toCastValue().toString());
+            setType(EdmPrimitiveTypeKind.DateTimeOffset).setValue(expected).build();
+    assertEquals(EdmPrimitiveTypeKind.DateTimeOffset, value.asPrimitive().getTypeKind());
+
+    final Calendar actual = value.asPrimitive().toCastValue(Calendar.class);
+    assertEquals(expected.get(Calendar.YEAR), actual.get(Calendar.YEAR));
+    assertEquals(expected.get(Calendar.MONTH), actual.get(Calendar.MONTH));
+    assertEquals(expected.get(Calendar.DATE), actual.get(Calendar.DATE));
+    assertEquals(expected.get(Calendar.HOUR), actual.get(Calendar.HOUR));
+    assertEquals(expected.get(Calendar.MINUTE), actual.get(Calendar.MINUTE));
+    assertEquals(expected.get(Calendar.SECOND), actual.get(Calendar.SECOND));
+
+    assertEquals("2013-01-10T02:00:00Z", value.asPrimitive().toString());
   }
 
   @Test
-  public void manageGuid() {
+  public void manageGuid() throws EdmPrimitiveTypeException {
     final UUID primitive = UUID.fromString("1126a28b-a4af-4bbd-bf0a-2b2c22635565");
     ODataValue value = getClient().getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.Guid).
             setValue(primitive).build();
-    assertEquals(EdmPrimitiveTypeKind.Guid.getFullQualifiedName().toString(), value.asPrimitive().getTypeName());
-    assertEquals(primitive, value.asPrimitive().<UUID>toCastValue());
+    assertEquals(EdmPrimitiveTypeKind.Guid, value.asPrimitive().getTypeKind());
+    assertEquals(primitive, value.asPrimitive().toCastValue(UUID.class));
 
     value = getClient().getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.Guid).
             setText("1126a28b-a4af-4bbd-bf0a-2b2c22635565").build();
-    assertEquals("1126a28b-a4af-4bbd-bf0a-2b2c22635565", value.asPrimitive().<UUID>toCastValue().toString());
+    assertEquals("1126a28b-a4af-4bbd-bf0a-2b2c22635565", value.asPrimitive().toCastValue(UUID.class).toString());
   }
 
   @Test
-  public void manageBinary() {
+  public void manageBinary() throws EdmPrimitiveTypeException {
     final byte[] primitive = UUID.randomUUID().toString().getBytes();
     ODataValue value = getClient().getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.Binary).
             setValue(primitive).build();
-    assertEquals(EdmPrimitiveTypeKind.Binary.getFullQualifiedName().toString(), value.asPrimitive().getTypeName());
+    assertEquals(EdmPrimitiveTypeKind.Binary, value.asPrimitive().getTypeKind());
     assertEquals(
             Base64.encodeBase64String(primitive),
-            Base64.encodeBase64String(value.asPrimitive().<byte[]>toCastValue()));
+            Base64.encodeBase64String(value.asPrimitive().toCastValue(byte[].class)));
 
     value = getClient().getPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.Binary).
             setText(Base64.encodeBase64String("primitive".getBytes())).build();
-    assertEquals("primitive", new String(value.asPrimitive().<byte[]>toCastValue()));
+    assertEquals("primitive", new String(value.asPrimitive().toCastValue(byte[].class)));
   }
 
   @Test
@@ -187,10 +199,11 @@ public class PrimitiveValueTest extends AbstractTest {
             getClient().getGeospatialValueBuilder().setType(EdmPrimitiveTypeKind.GeographyPoint).
             setValue(primitive).
             build();
-    assertEquals(EdmPrimitiveTypeKind.GeographyPoint.getFullQualifiedName().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()));
+    assertEquals(EdmPrimitiveTypeKind.GeographyPoint, value.asGeospatial().getTypeKind());
+    assertEquals(Double.valueOf(primitive.getX()),
+            Double.valueOf(value.asGeospatial().toCastValue(Point.class).getX()));
+    assertEquals(Double.valueOf(primitive.getY()),
+            Double.valueOf(value.asGeospatial().toCastValue(Point.class).getY()));
   }
 
   @Test
@@ -220,10 +233,9 @@ public class PrimitiveValueTest extends AbstractTest {
 
     final ODataValue value = getClient().getGeospatialValueBuilder().
             setType(EdmPrimitiveTypeKind.GeographyLineString).setValue(primitive).build();
-    assertEquals(EdmPrimitiveTypeKind.GeographyLineString.getFullQualifiedName().toString(),

-            value.asPrimitive().getTypeName());
+    assertEquals(EdmPrimitiveTypeKind.GeographyLineString, value.asGeospatial().getTypeKind());
 
-    final Iterator<Point> iter = value.asPrimitive().<LineString>toCastValue().iterator();
+    final Iterator<Point> iter = value.asGeospatial().toCastValue(LineString.class).iterator();
 
     // take the third one and check the point value ...
     iter.next();
@@ -246,10 +258,9 @@ public class PrimitiveValueTest extends AbstractTest {
 
     final ODataValue value = getClient().getGeospatialValueBuilder().
             setType(EdmPrimitiveTypeKind.GeometryMultiPoint).setValue(primitive).build();
-    assertEquals(EdmPrimitiveTypeKind.GeometryMultiPoint.getFullQualifiedName().toString(),

-            value.asPrimitive().getTypeName());
+    assertEquals(EdmPrimitiveTypeKind.GeometryMultiPoint, value.asGeospatial().getTypeKind());
 
-    final Iterator<Point> iter = value.asPrimitive().<MultiPoint>toCastValue().iterator();
+    final Iterator<Point> iter = value.asGeospatial().toCastValue(MultiPoint.class).iterator();
     point = iter.next();
 
     assertEquals(Double.valueOf(points.get(0).getX()), Double.valueOf(point.getX()));
@@ -308,10 +319,9 @@ public class PrimitiveValueTest extends AbstractTest {
     final ODataValue value =
             getClient().getGeospatialValueBuilder().setType(EdmPrimitiveTypeKind.GeometryMultiLineString).
             setValue(primitive).build();
-    assertEquals(EdmPrimitiveTypeKind.GeometryMultiLineString.getFullQualifiedName().toString(),

-            value.asPrimitive().getTypeName());
+    assertEquals(EdmPrimitiveTypeKind.GeometryMultiLineString, value.asGeospatial().getTypeKind());
 
-    final Iterator<LineString> lineIter = value.asPrimitive().<MultiLineString>toCastValue().iterator();
+    final Iterator<LineString> lineIter = value.asGeospatial().toCastValue(MultiLineString.class).iterator();
 
     // take the second line and check the third point value ...
     lineIter.next();
@@ -362,11 +372,10 @@ public class PrimitiveValueTest extends AbstractTest {
     final ODataValue value =
             getClient().getGeospatialValueBuilder().setType(EdmPrimitiveTypeKind.GeographyPolygon).
             setValue(primitive).build();
-    assertEquals(EdmPrimitiveTypeKind.GeographyPolygon.getFullQualifiedName().toString(),

-            value.asPrimitive().getTypeName());
+    assertEquals(EdmPrimitiveTypeKind.GeographyPolygon, value.asGeospatial().getTypeKind());
 
-    assertTrue(value.asPrimitive().<Polygon>toCastValue().getInterior().isEmpty());
-    final Iterator<Point> iter = value.asPrimitive().<Polygon>toCastValue().getExterior().iterator();
+    assertTrue(value.asGeospatial().toCastValue(Polygon.class).getInterior().isEmpty());
+    final Iterator<Point> iter = value.asGeospatial().toCastValue(Polygon.class).getExterior().iterator();
 
     // take the third one ...
     iter.next();
@@ -469,10 +478,9 @@ public class PrimitiveValueTest extends AbstractTest {
     final ODataValue value =
             getClient().getGeospatialValueBuilder().setType(EdmPrimitiveTypeKind.GeometryMultiPolygon).
             setValue(primitive).build();
-    assertEquals(EdmPrimitiveTypeKind.GeometryMultiPolygon.getFullQualifiedName().toString(),

-            value.asPrimitive().getTypeName());
+    assertEquals(EdmPrimitiveTypeKind.GeometryMultiPolygon, value.asGeospatial().getTypeKind());
 
-    final Iterator<Polygon> iter = value.asPrimitive().<MultiPolygon>toCastValue().iterator();
+    final Iterator<Polygon> iter = value.asGeospatial().toCastValue(MultiPolygon.class).iterator();
 
     // second one polygon
     iter.next();
@@ -516,10 +524,9 @@ public class PrimitiveValueTest extends AbstractTest {
     final ODataValue value =
             getClient().getGeospatialValueBuilder().setType(EdmPrimitiveTypeKind.GeometryCollection).
             setValue(primitive).build();
-    assertEquals(EdmPrimitiveTypeKind.GeometryCollection.getFullQualifiedName().toString(),

-            value.asPrimitive().getTypeName());
+    assertEquals(EdmPrimitiveTypeKind.GeometryCollection, value.asGeospatial().getTypeKind());
 
-    final Iterator<Geospatial> iter = value.asPrimitive().<GeospatialCollection>toCastValue().iterator();
+    final Iterator<Geospatial> iter = value.asGeospatial().toCastValue(GeospatialCollection.class).iterator();
     iter.next();
     final Point collectedPoint = (Point) iter.next();
 
@@ -549,10 +556,9 @@ public class PrimitiveValueTest extends AbstractTest {
     final ODataValue value =
             getClient().getGeospatialValueBuilder().setType(EdmPrimitiveTypeKind.GeographyCollection).
             setValue(primitive).build();
-    assertEquals(EdmPrimitiveTypeKind.GeographyCollection.getFullQualifiedName().toString(),

-            value.asPrimitive().getTypeName());
+    assertEquals(EdmPrimitiveTypeKind.GeographyCollection, value.asGeospatial().getTypeKind());
 
-    final Iterator<Geospatial> iter = value.asPrimitive().<GeospatialCollection>toCastValue().iterator();
+    final Iterator<Geospatial> iter = value.asGeospatial().toCastValue(GeospatialCollection.class).iterator();
     iter.next();
     final Point collectedPoint = (Point) iter.next();
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4780fc51/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/PrimitiveValueTest.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/PrimitiveValueTest.java
b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/PrimitiveValueTest.java
index d72861d..d879e5b 100644
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/PrimitiveValueTest.java
+++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/PrimitiveValueTest.java
@@ -18,16 +18,13 @@
  */
 package org.apache.olingo.client.core.v4;
 
+import java.util.Calendar;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
 
 import org.apache.olingo.client.api.v4.ODataClient;
-import org.apache.olingo.client.api.domain.ODataDuration;
-import org.apache.olingo.client.api.domain.ODataPrimitiveValue;
-import org.apache.olingo.client.api.domain.ODataTimestamp;
 import org.apache.olingo.client.api.domain.ODataValue;
 import org.apache.olingo.client.core.AbstractTest;
-import org.apache.olingo.client.core.ODataClientFactory;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
 import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
 import org.junit.Test;
 
@@ -39,40 +36,38 @@ public class PrimitiveValueTest extends AbstractTest {
   }
 
   @Test
-  public void manageTimeOfDay() {
-    // OData V4 only
-    final String primitive = "-P9DT51M12.5063807S";
-    try {
-      new ODataPrimitiveValue.Builder(ODataClientFactory.getV3()).
-              setType(EdmPrimitiveTypeKind.TimeOfDay).setText(primitive).build();
-      fail();
-    } catch (IllegalArgumentException iae) {
-      // ignore
-    }
+  public void manageTimeOfDay() throws EdmPrimitiveTypeException {
+    final Calendar expected = Calendar.getInstance();
+    expected.clear();
+    expected.set(2013, 0, 10, 21, 45, 17);
 
     final ODataValue value = getClient().getPrimitiveValueBuilder().
-            setType(EdmPrimitiveTypeKind.TimeOfDay).setText(primitive).build();
-    assertEquals(EdmPrimitiveTypeKind.TimeOfDay.getFullQualifiedName().toString(), value.asPrimitive().getTypeName());
-    // performed cast to improve the check
-    assertEquals(primitive, value.asPrimitive().<ODataDuration>toCastValue().toString());
+            setType(EdmPrimitiveTypeKind.TimeOfDay).setValue(expected).build();
+    assertEquals(EdmPrimitiveTypeKind.TimeOfDay, value.asPrimitive().getTypeKind());
+
+    final Calendar actual = value.asPrimitive().toCastValue(Calendar.class);
+    assertEquals(expected.get(Calendar.HOUR), actual.get(Calendar.HOUR));
+    assertEquals(expected.get(Calendar.MINUTE), actual.get(Calendar.MINUTE));
+    assertEquals(expected.get(Calendar.SECOND), actual.get(Calendar.SECOND));
+    
+    assertEquals("21:45:17", value.asPrimitive().toString());
   }
 
   @Test
-  public void manageDate() {
-    // OData V4 only
-    final String primitive = "2013-01-10";
-    try {
-      new ODataPrimitiveValue.Builder(ODataClientFactory.getV3()).
-              setType(EdmPrimitiveTypeKind.Date).setText(primitive).build();
-      fail();
-    } catch (IllegalArgumentException iae) {
-      // ignore
-    }
+  public void manageDate() throws EdmPrimitiveTypeException {
+    final Calendar expected = Calendar.getInstance();
+    expected.clear();
+    expected.set(2013, 0, 10);
 
     final ODataValue value = getClient().getPrimitiveValueBuilder().
-            setType(EdmPrimitiveTypeKind.Date).setText(primitive).build();
-    assertEquals(EdmPrimitiveTypeKind.Date.getFullQualifiedName().toString(), value.asPrimitive().getTypeName());
-    // performed cast to improve the check
-    assertEquals(primitive, value.asPrimitive().<ODataTimestamp>toCastValue().toString());
+            setType(EdmPrimitiveTypeKind.Date).setValue(expected).build();
+    assertEquals(EdmPrimitiveTypeKind.Date, value.asPrimitive().getTypeKind());
+
+    final Calendar actual = value.asPrimitive().toCastValue(Calendar.class);
+    assertEquals(expected.get(Calendar.YEAR), actual.get(Calendar.YEAR));
+    assertEquals(expected.get(Calendar.MONTH), actual.get(Calendar.MONTH));
+    assertEquals(expected.get(Calendar.DATE), actual.get(Calendar.DATE));
+
+    assertEquals("2013-01-10", value.asPrimitive().toString());
   }
 }


Mime
View raw message