aboutsummaryrefslogtreecommitdiffstats
path: root/adapters
diff options
context:
space:
mode:
authorLukasz Muszkieta <lukasz.muszkieta@nokia.com>2018-01-08 18:23:10 +0100
committerLukasz Muszkieta <lukasz.muszkieta@nokia.com>2018-01-10 15:58:31 +0100
commit2b653795fab53638b62e6eb9c24d6e4add101abf (patch)
tree17c01373590fe1bd15e4e332d71d043c0bab258e /adapters
parent4da1270fb9814f230e064e995bb379db6a4d25d4 (diff)
refactoring - adding junit
Change-Id: I91ba9dafa40df25d1ca1aae5a7dce11e0afb71da Issue-ID: SO-360 Signed-off-by: Lukasz Muszkieta <lukasz.muszkieta@nokia.com>
Diffstat (limited to 'adapters')
-rw-r--r--adapters/mso-adapters-rest-interface/src/main/java/org/openecomp/mso/adapters/json/MapDeserializer.java1
-rw-r--r--adapters/mso-adapters-rest-interface/src/main/java/org/openecomp/mso/adapters/json/MapSerializer.java7
-rw-r--r--adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/adapters/AdapterRestInterfaceTest.java48
-rw-r--r--adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/adapters/BeanTest.java6
-rw-r--r--adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/adapters/json/MapSerializerTest.java56
5 files changed, 58 insertions, 60 deletions
diff --git a/adapters/mso-adapters-rest-interface/src/main/java/org/openecomp/mso/adapters/json/MapDeserializer.java b/adapters/mso-adapters-rest-interface/src/main/java/org/openecomp/mso/adapters/json/MapDeserializer.java
index 2a3a64ce1b..5bb1dacb4a 100644
--- a/adapters/mso-adapters-rest-interface/src/main/java/org/openecomp/mso/adapters/json/MapDeserializer.java
+++ b/adapters/mso-adapters-rest-interface/src/main/java/org/openecomp/mso/adapters/json/MapDeserializer.java
@@ -26,7 +26,6 @@ import org.codehaus.jackson.map.JsonDeserializer;
import org.codehaus.jackson.map.ObjectMapper;
import java.io.IOException;
-import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
diff --git a/adapters/mso-adapters-rest-interface/src/main/java/org/openecomp/mso/adapters/json/MapSerializer.java b/adapters/mso-adapters-rest-interface/src/main/java/org/openecomp/mso/adapters/json/MapSerializer.java
index c2ea8242c3..3e9f5c6b58 100644
--- a/adapters/mso-adapters-rest-interface/src/main/java/org/openecomp/mso/adapters/json/MapSerializer.java
+++ b/adapters/mso-adapters-rest-interface/src/main/java/org/openecomp/mso/adapters/json/MapSerializer.java
@@ -19,7 +19,6 @@
*/
package org.openecomp.mso.adapters.json;
-import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.map.JsonSerializer;
import org.codehaus.jackson.map.SerializerProvider;
@@ -47,12 +46,9 @@ import java.util.Map;
public class MapSerializer extends JsonSerializer<Map<String, String>> {
@Override
public void serialize(Map<String, String> map, JsonGenerator jsonGenerator,
- SerializerProvider serializerProvider) throws IOException,
- JsonGenerationException {
-
+ SerializerProvider serializerProvider) throws IOException {
jsonGenerator.writeStartObject();
jsonGenerator.writeArrayFieldStart("entry");
-
for (Map.Entry<String,String> entry : map.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
@@ -61,7 +57,6 @@ public class MapSerializer extends JsonSerializer<Map<String, String>> {
jsonGenerator.writeStringField("value", value);
jsonGenerator.writeEndObject();
}
-
jsonGenerator.writeEndArray();
jsonGenerator.writeEndObject();
}
diff --git a/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/adapters/AdapterRestInterfaceTest.java b/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/adapters/AdapterRestInterfaceTest.java
deleted file mode 100644
index 00c853ba0d..0000000000
--- a/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/adapters/AdapterRestInterfaceTest.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
- * ================================================================================
- * Licensed 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.mso.adapters;
-
-import java.io.IOException;
-import java.util.HashMap;
-import org.codehaus.jackson.JsonGenerator;
-import org.codehaus.jackson.map.SerializerProvider;
-import org.junit.Test;
-import org.mockito.Mockito;
-import org.openecomp.mso.adapters.json.MapSerializer;
-
-public class AdapterRestInterfaceTest {
-
- @Test
- public final void mapSerializerTest() {
- MapSerializer mapSerializer = new MapSerializer();
- mapSerializer.isUnwrappingSerializer();
- mapSerializer.toString();
- mapSerializer.unwrappingSerializer();
- JsonGenerator jsonGenerator = Mockito.mock(JsonGenerator.class);
- SerializerProvider serializerProvider = Mockito
- .mock(SerializerProvider.class);
- try {
- mapSerializer.serialize(new HashMap(), jsonGenerator, serializerProvider);
- } catch (IOException e) {
- }
- }
-
-}
diff --git a/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/adapters/BeanTest.java b/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/adapters/BeanTest.java
index 984ba1b0af..5c3470acd9 100644
--- a/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/adapters/BeanTest.java
+++ b/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/adapters/BeanTest.java
@@ -17,14 +17,12 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-package org.openecomp.mso.test;
+package org.openecomp.mso.adapters;
import java.lang.reflect.Method;
-import java.lang.reflect.Parameter;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
-
import org.junit.Test;
import org.openecomp.mso.adapters.nwrest.ContrailNetwork;
import org.openecomp.mso.adapters.nwrest.CreateNetworkError;
@@ -34,7 +32,6 @@ import org.openecomp.mso.adapters.nwrest.DeleteNetworkError;
import org.openecomp.mso.adapters.nwrest.DeleteNetworkRequest;
import org.openecomp.mso.adapters.nwrest.DeleteNetworkResponse;
import org.openecomp.mso.adapters.nwrest.NetworkExceptionResponse;
-import org.openecomp.mso.adapters.nwrest.NetworkRequestCommon;
import org.openecomp.mso.adapters.nwrest.NetworkTechnology;
import org.openecomp.mso.adapters.nwrest.ProviderVlanNetwork;
import org.openecomp.mso.adapters.nwrest.QueryNetworkResponse;
@@ -74,7 +71,6 @@ import org.openecomp.mso.adapters.vnfrest.UpdateVolumeGroupRequest;
import org.openecomp.mso.adapters.vnfrest.UpdateVolumeGroupResponse;
import org.openecomp.mso.adapters.vnfrest.VfModuleExceptionResponse;
import org.openecomp.mso.adapters.vnfrest.VfModuleRollback;
-import org.openecomp.mso.adapters.vnfrest.VfResponseCommon;
import org.openecomp.mso.adapters.vnfrest.VolumeGroupRollback;
import org.openecomp.mso.entity.MsoRequest;
diff --git a/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/adapters/json/MapSerializerTest.java b/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/adapters/json/MapSerializerTest.java
new file mode 100644
index 0000000000..f903f21441
--- /dev/null
+++ b/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/adapters/json/MapSerializerTest.java
@@ -0,0 +1,56 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.mso.adapters.json;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.codehaus.jackson.JsonGenerator;
+import org.codehaus.jackson.map.SerializerProvider;
+import org.junit.Test;
+
+public class MapSerializerTest {
+
+ private static final String JSON_FIELD_NAME_1 = "testKey1";
+ private static final String JSON_VALUE_1 = "testValue1";
+ private static final String JSON_FIELD_NAME_2 = "testKey2";
+ private static final String JSON_VALUE_2 = "testValue2";
+
+ @Test
+ public void serializationWritesTheProperFieldsToJson() throws Exception {
+ JsonGenerator jsonGeneratorMock = mock(JsonGenerator.class);
+ MapSerializer testedObject = new MapSerializer();
+ testedObject.serialize(prepareMap(), jsonGeneratorMock, mock(SerializerProvider.class));
+ verify(jsonGeneratorMock).writeStringField("key", JSON_FIELD_NAME_1);
+ verify(jsonGeneratorMock).writeStringField("value", JSON_VALUE_1);
+ verify(jsonGeneratorMock).writeStringField("key", JSON_FIELD_NAME_2);
+ verify(jsonGeneratorMock).writeStringField("value", JSON_VALUE_2);
+ }
+
+ private Map<String, String> prepareMap() {
+ Map<String, String> map = new HashMap<>();
+ map.put(JSON_FIELD_NAME_1, JSON_VALUE_1);
+ map.put(JSON_FIELD_NAME_2, JSON_VALUE_2);
+ return map;
+ }
+}