[08/24] olingo-odata2 git commit: [OLINGO-1253]Client Module for Olingo v2

2018-04-09 Thread archanarai
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/4261deb7/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/serializer/JsonEntryEntitySerializerTest.java
--
diff --git 
a/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/serializer/JsonEntryEntitySerializerTest.java
 
b/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/serializer/JsonEntryEntitySerializerTest.java
new file mode 100644
index 000..f7e0433
--- /dev/null
+++ 
b/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/serializer/JsonEntryEntitySerializerTest.java
@@ -0,0 +1,1027 @@
+/***
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ 
**/
+package org.apache.olingo.odata2.client.core.ep.serializer;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.TimeZone;
+
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.olingo.odata2.api.edm.Edm;
+import org.apache.olingo.odata2.api.edm.EdmConcurrencyMode;
+import org.apache.olingo.odata2.api.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.edm.EdmFacets;
+import org.apache.olingo.odata2.api.edm.EdmMapping;
+import org.apache.olingo.odata2.api.edm.EdmProperty;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeException;
+import org.apache.olingo.odata2.api.edm.EdmTyped;
+import org.apache.olingo.odata2.api.ep.EntityProviderException;
+import org.apache.olingo.odata2.api.processor.ODataResponse;
+import org.apache.olingo.odata2.client.api.edm.ClientEdm;
+import org.apache.olingo.odata2.client.api.edm.EdmDataServices;
+import org.apache.olingo.odata2.client.api.ep.Entity;
+import org.apache.olingo.odata2.client.api.ep.EntityCollection;
+import org.apache.olingo.odata2.client.api.ep.EntitySerializerProperties;
+import org.apache.olingo.odata2.client.core.ep.JsonSerializerDeserializer;
+import 
org.apache.olingo.odata2.client.core.ep.deserializer.XmlMetadataDeserializer;
+import org.apache.olingo.odata2.core.ep.EntityProviderProducerException;
+import org.apache.olingo.odata2.testutil.fit.BaseTest;
+import org.apache.olingo.odata2.testutil.helper.StringHelper;
+import org.apache.olingo.odata2.testutil.mock.MockFacade;
+import org.junit.Test;
+
+import com.google.gson.Gson;
+import com.google.gson.internal.LinkedTreeMap;
+
+/**
+ *  
+ */
+public class JsonEntryEntitySerializerTest extends BaseTest { 
+  protected static final String BASE_URI = "http://host:80/service/;;
+  protected static final EntitySerializerProperties DEFAULT_PROPERTIES =
+  EntitySerializerProperties.serviceRoot(URI.create(BASE_URI)).build();
+  protected static final String ERROR_MSG = "Entity or expanded entity cannot 
have null value.";
+  protected static final String ERROR_MSG1 = "Navigation has to be either an 
Entity or a Map.";
+  
+
+  @Test
+  public void entry() throws Exception {
+final EdmEntitySet entitySet = 
MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Teams");
+Entity entity = new Entity();
+entity.addProperty("Id", "1");
+entity.addProperty("isScrumTeam", true);
+entity.setWriteProperties(DEFAULT_PROPERTIES);
+
+final ODataResponse response = new 
JsonSerializerDeserializer().writeEntry(entitySet, entity);
+final String json = verifyResponse(response);
+assertEquals("{\"Id\":\"1\",\"isScrumTeam\":true}", json);
+  }
+
+  

[08/24] olingo-odata2 git commit: [OLINGO-1253]Client Module for Olingo v2

2018-04-02 Thread archanarai
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/9e949e40/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/serializer/JsonEntryEntitySerializerTest.java
--
diff --git 
a/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/serializer/JsonEntryEntitySerializerTest.java
 
b/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/serializer/JsonEntryEntitySerializerTest.java
new file mode 100644
index 000..f7e0433
--- /dev/null
+++ 
b/odata2-lib/odata-client-core/src/test/java/org/apache/olingo/odata2/client/core/ep/serializer/JsonEntryEntitySerializerTest.java
@@ -0,0 +1,1027 @@
+/***
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ 
**/
+package org.apache.olingo.odata2.client.core.ep.serializer;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.TimeZone;
+
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.olingo.odata2.api.edm.Edm;
+import org.apache.olingo.odata2.api.edm.EdmConcurrencyMode;
+import org.apache.olingo.odata2.api.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.edm.EdmFacets;
+import org.apache.olingo.odata2.api.edm.EdmMapping;
+import org.apache.olingo.odata2.api.edm.EdmProperty;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeException;
+import org.apache.olingo.odata2.api.edm.EdmTyped;
+import org.apache.olingo.odata2.api.ep.EntityProviderException;
+import org.apache.olingo.odata2.api.processor.ODataResponse;
+import org.apache.olingo.odata2.client.api.edm.ClientEdm;
+import org.apache.olingo.odata2.client.api.edm.EdmDataServices;
+import org.apache.olingo.odata2.client.api.ep.Entity;
+import org.apache.olingo.odata2.client.api.ep.EntityCollection;
+import org.apache.olingo.odata2.client.api.ep.EntitySerializerProperties;
+import org.apache.olingo.odata2.client.core.ep.JsonSerializerDeserializer;
+import 
org.apache.olingo.odata2.client.core.ep.deserializer.XmlMetadataDeserializer;
+import org.apache.olingo.odata2.core.ep.EntityProviderProducerException;
+import org.apache.olingo.odata2.testutil.fit.BaseTest;
+import org.apache.olingo.odata2.testutil.helper.StringHelper;
+import org.apache.olingo.odata2.testutil.mock.MockFacade;
+import org.junit.Test;
+
+import com.google.gson.Gson;
+import com.google.gson.internal.LinkedTreeMap;
+
+/**
+ *  
+ */
+public class JsonEntryEntitySerializerTest extends BaseTest { 
+  protected static final String BASE_URI = "http://host:80/service/;;
+  protected static final EntitySerializerProperties DEFAULT_PROPERTIES =
+  EntitySerializerProperties.serviceRoot(URI.create(BASE_URI)).build();
+  protected static final String ERROR_MSG = "Entity or expanded entity cannot 
have null value.";
+  protected static final String ERROR_MSG1 = "Navigation has to be either an 
Entity or a Map.";
+  
+
+  @Test
+  public void entry() throws Exception {
+final EdmEntitySet entitySet = 
MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Teams");
+Entity entity = new Entity();
+entity.addProperty("Id", "1");
+entity.addProperty("isScrumTeam", true);
+entity.setWriteProperties(DEFAULT_PROPERTIES);
+
+final ODataResponse response = new 
JsonSerializerDeserializer().writeEntry(entitySet, entity);
+final String json = verifyResponse(response);
+assertEquals("{\"Id\":\"1\",\"isScrumTeam\":true}", json);
+  }
+
+