Upversion artifacts to 1.8.0-SNAPSHOT
[aai/data-router.git] / src / test / java / org / onap / aai / datarouter / util / AaiUiSvcPolicyUtilTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017-2018 Amdocs
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21 package org.onap.aai.datarouter.util;
22
23 import static org.junit.Assert.assertNull;
24 import static org.junit.Assert.assertTrue;
25 import static org.junit.Assert.fail;
26
27 import org.junit.BeforeClass;
28 import org.junit.Test;
29 import org.onap.aai.datarouter.util.AaiUiSvcPolicyUtil;
30
31 import com.fasterxml.jackson.databind.JsonNode;
32 import com.fasterxml.jackson.databind.ObjectMapper;
33
34 public class AaiUiSvcPolicyUtilTest {
35   
36   private final static String ORIGIN_URI = "testUri/somePath";
37   private final static String ORIGIN_PAYLOAD = "test payload";
38
39   private final static String validPayload = "{" +
40         "\"origin-uri\": \"" + ORIGIN_URI + "\"," + 
41         "\"origin-payload\": \"" + ORIGIN_PAYLOAD + "\"}";
42   
43   private final static String payloadWithoutOriginUri = "{" +
44       "\"origin-payload\": \"" + ORIGIN_PAYLOAD + "\"}";
45   
46   private final static String payloadWithoutOriginPayload = "{" +
47       "\"origin-uri\": \"" + ORIGIN_URI + "\"}";
48   
49   private static JsonNode node = null;
50   private static JsonNode nodeWithoutOrginUri = null;
51   private static JsonNode nodeWithoutOrginPayload = null;
52   static ObjectMapper mapper = new ObjectMapper();
53   
54   @BeforeClass
55   public static void init(){
56     try {
57       node = mapper.readTree(validPayload);
58       nodeWithoutOrginUri = mapper.readTree(payloadWithoutOriginUri);
59       nodeWithoutOrginPayload = mapper.readTree(payloadWithoutOriginPayload);
60     } catch (Exception e) {
61       fail("Initialization error");
62     }
63   }
64   
65   @Test
66   public void testGetOriginPayload_missingPayload() {
67     JsonNode value = null;
68     try {
69       value = AaiUiSvcPolicyUtil.getOriginPayload(nodeWithoutOrginPayload);
70       assertNull("Failure to extract origin payload", value);
71     } catch (Exception e) {
72       fail("Failure to extract origin payload");
73     }
74   }
75
76   @Test
77   public void testGetOriginPayload_validPayload() {
78     JsonNode value = null;
79     try {
80       value = AaiUiSvcPolicyUtil.getOriginPayload(node);
81       assertTrue("Failure to extract origin payload", ORIGIN_PAYLOAD.equals(value.asText()));
82     } catch (Exception e) {
83       fail("Failure to extract origin payload");
84     }
85   }
86   
87   @Test
88   public void testGetOriginUri_missingUri() {
89     String value = null;
90     try {
91       value = AaiUiSvcPolicyUtil.getOriginUri(nodeWithoutOrginUri);
92       assertTrue("Failure to extract origin uri", value.isEmpty());
93     } catch (Exception e) {
94       fail("Failure to extract origin uri");
95     }
96   }
97
98   @Test
99   public void testGetOriginUri_validPayload() {
100     String value = null;
101     try {
102       value = AaiUiSvcPolicyUtil.getOriginUri(node);
103       assertTrue("Failure to extract origin uri", ORIGIN_URI.equals(value));
104     } catch (Exception e) {
105       fail("Failure to extract origin uri");
106     }
107   }
108 }