aboutsummaryrefslogtreecommitdiffstats
path: root/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/JsonDgUtilImplTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/JsonDgUtilImplTest.java')
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/JsonDgUtilImplTest.java145
1 files changed, 145 insertions, 0 deletions
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/JsonDgUtilImplTest.java b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/JsonDgUtilImplTest.java
new file mode 100644
index 000000000..70534872d
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/JsonDgUtilImplTest.java
@@ -0,0 +1,145 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. 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.appc.dg.common.impl;
+
+import ch.qos.logback.core.Appender;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openecomp.appc.dg.common.impl.JsonDgUtilImpl;
+import org.openecomp.appc.exceptions.APPCException;
+import org.openecomp.sdnc.sli.SvcLogicContext;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.mock;
+
+public class JsonDgUtilImplTest {
+
+ private final Appender appender = mock(Appender.class);
+
+
+ @Test
+ public void testFlatAndAddToContext() throws Exception {
+ JsonDgUtilImpl jsonDgUtil = new JsonDgUtilImpl();
+ String key = "payload";
+ String testValueKey = "test-key";
+ String testValueValue = "test-value";
+ String testValueKey2 = "test-key2";
+ String testValueValue2 = "test-value2";
+ String payload = "{\"" + testValueKey + "\": \"" + testValueValue + "\",\""+testValueKey2+"\": \""+testValueValue2+"\"}";
+
+ SvcLogicContext ctx = new SvcLogicContext();
+ Map<String, String> params = new HashMap<>();
+ params.put(key, payload);
+ jsonDgUtil.flatAndAddToContext(params, ctx);
+
+
+ Assert.assertEquals(ctx.getAttribute(testValueKey), testValueValue);
+ Assert.assertEquals(ctx.getAttribute(testValueKey2), testValueValue2);
+
+
+
+ }
+
+
+ @Test
+ public void testFlatAndAddToContextNegativeWrongPayload() throws Exception {
+ JsonDgUtilImpl jsonDgUtil = new JsonDgUtilImpl();
+ String key = "payload";
+ String testValueKey = "test-key";
+ String testValueValue = "test-value";
+ String testValueKey2 = "test-key2";
+ String testValueValue2 = "test-value2";
+ String payload = "{{\"" + testValueKey + "\": \"" + testValueValue + "\",\""+testValueKey2+"\": \""+testValueValue2+"\"}";
+
+ SvcLogicContext ctx = new SvcLogicContext();
+ Map<String, String> params = new HashMap<>();
+ params.put(key, payload);
+ try {
+ jsonDgUtil.flatAndAddToContext(params, ctx);
+
+ } catch (APPCException e) {
+ Assert.assertNull(ctx.getAttribute(testValueKey));
+ Assert.assertNull(ctx.getAttribute(testValueKey2));
+ Assert.assertNotNull(ctx.getAttribute("output.status.message"));
+ }
+
+
+ }
+
+
+ @Test
+ public void testFlatAndAddToContextPayloadFromContext() throws Exception {
+ JsonDgUtilImpl jsonDgUtil = new JsonDgUtilImpl();
+ String key = "payload";
+ String testValueKey = "test-key";
+ String testValueValue = "test-value";
+ String testValueKey2 = "test-key2";
+ String testValueValue2 = "test-value2";
+ String payload = "{\"" + testValueKey + "\": \"" + testValueValue + "\",\""+testValueKey2+"\": \""+testValueValue2+"\"}";
+
+ SvcLogicContext ctx = new SvcLogicContext();
+ Map<String, String> params = new HashMap<>();
+ params.put(key, "");
+ ctx.setAttribute("input.payload", payload);
+ jsonDgUtil.flatAndAddToContext(params, ctx);
+
+
+ Assert.assertEquals(ctx.getAttribute(testValueKey), testValueValue);
+ Assert.assertEquals(ctx.getAttribute(testValueKey2), testValueValue2);
+ }
+
+ @Test
+ public void testFlatAndAddToContextNegativeNullPayload() throws Exception {
+ JsonDgUtilImpl jsonDgUtil = new JsonDgUtilImpl();
+ String testValueKey = "test-key";
+ String testValueKey2 = "test-key2";
+ SvcLogicContext ctx = new SvcLogicContext();
+ Map<String, String> params = new HashMap<>();
+ jsonDgUtil.flatAndAddToContext(params, ctx);
+
+
+ Assert.assertNull(ctx.getAttribute(testValueKey));
+ Assert.assertNull(ctx.getAttribute(testValueKey2));
+ }
+
+
+ @Test
+ public void testFlatAndAddToContextNegativeEmptyPayload() throws Exception {
+
+ JsonDgUtilImpl jsonDgUtil = new JsonDgUtilImpl();
+ String key = "payload";
+ String testValueKey = "test-key";
+ String testValueKey2 = "test-key2";
+
+ SvcLogicContext ctx = new SvcLogicContext();
+ Map<String, String> params = new HashMap<>();
+ params.put(key, "");
+ jsonDgUtil.flatAndAddToContext(params, ctx);
+
+ Assert.assertNull(ctx.getAttribute(testValueKey));
+ Assert.assertNull(ctx.getAttribute(testValueKey2));
+ }
+}