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