import org.codehaus.jackson.map.ObjectMapper;
import java.io.IOException;
-import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
*/
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;
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();
jsonGenerator.writeStringField("value", value);
jsonGenerator.writeEndObject();
}
-
jsonGenerator.writeEndArray();
jsonGenerator.writeEndObject();
}
+++ /dev/null
-/*-\r
- * ============LICENSE_START=======================================================\r
- * ONAP - SO\r
- * ================================================================================\r
- * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.\r
- * ================================================================================\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- * ============LICENSE_END=========================================================\r
- */\r
-\r
-package org.openecomp.mso.adapters;\r
-\r
-import java.io.IOException;\r
-import java.util.HashMap;\r
-import org.codehaus.jackson.JsonGenerator;\r
-import org.codehaus.jackson.map.SerializerProvider;\r
-import org.junit.Test;\r
-import org.mockito.Mockito;\r
-import org.openecomp.mso.adapters.json.MapSerializer;\r
-\r
-public class AdapterRestInterfaceTest {\r
-\r
- @Test\r
- public final void mapSerializerTest() {\r
- MapSerializer mapSerializer = new MapSerializer();\r
- mapSerializer.isUnwrappingSerializer();\r
- mapSerializer.toString();\r
- mapSerializer.unwrappingSerializer();\r
- JsonGenerator jsonGenerator = Mockito.mock(JsonGenerator.class);\r
- SerializerProvider serializerProvider = Mockito\r
- .mock(SerializerProvider.class);\r
- try {\r
- mapSerializer.serialize(new HashMap(), jsonGenerator, serializerProvider);\r
- } catch (IOException e) {\r
- }\r
- }\r
-\r
-}\r
* 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;
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;
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;
--- /dev/null
+/*-
+ * ============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;
+ }
+}