Renaming openecomp to onap
[aai/data-router.git] / src / test / java / org / onap / aai / 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.onap.aai.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 import org.onap.aai.datarouter.util.AaiUiSvcPolicyUtil;
35
36 import com.fasterxml.jackson.databind.JsonNode;
37 import com.fasterxml.jackson.databind.ObjectMapper;
38
39 public class AaiUiSvcPolicyUtilTest {
40   
41   private final static String ORIGIN_URI = "testUri/somePath";
42   private final static String ORIGIN_PAYLOAD = "test payload";
43
44   private final static String validPayload = "{" +
45         "\"origin-uri\": \"" + ORIGIN_URI + "\"," + 
46         "\"origin-payload\": \"" + ORIGIN_PAYLOAD + "\"}";
47   
48   private final static String payloadWithoutOriginUri = "{" +
49       "\"origin-payload\": \"" + ORIGIN_PAYLOAD + "\"}";
50   
51   private final static String payloadWithoutOriginPayload = "{" +
52       "\"origin-uri\": \"" + ORIGIN_URI + "\"}";
53   
54   private static JsonNode node = null;
55   private static JsonNode nodeWithoutOrginUri = null;
56   private static JsonNode nodeWithoutOrginPayload = null;
57   static ObjectMapper mapper = new ObjectMapper();
58   
59   @BeforeClass
60   public static void init(){
61     try {
62       node = mapper.readTree(validPayload);
63       nodeWithoutOrginUri = mapper.readTree(payloadWithoutOriginUri);
64       nodeWithoutOrginPayload = mapper.readTree(payloadWithoutOriginPayload);
65     } catch (Exception e) {
66       fail("Initialization error");
67     }
68   }
69   
70   @Test
71   public void testGetOriginPayload_missingPayload() {
72     JsonNode value = null;
73     try {
74       value = AaiUiSvcPolicyUtil.getOriginPayload(nodeWithoutOrginPayload);
75       assertNull("Failure to extract origin payload", value);
76     } catch (Exception e) {
77       fail("Failure to extract origin payload");
78     }
79   }
80
81   @Test
82   public void testGetOriginPayload_validPayload() {
83     JsonNode value = null;
84     try {
85       value = AaiUiSvcPolicyUtil.getOriginPayload(node);
86       assertTrue("Failure to extract origin payload", ORIGIN_PAYLOAD.equals(value.asText()));
87     } catch (Exception e) {
88       fail("Failure to extract origin payload");
89     }
90   }
91   
92   @Test
93   public void testGetOriginUri_missingUri() {
94     String value = null;
95     try {
96       value = AaiUiSvcPolicyUtil.getOriginUri(nodeWithoutOrginUri);
97       assertTrue("Failure to extract origin uri", value.isEmpty());
98     } catch (Exception e) {
99       fail("Failure to extract origin uri");
100     }
101   }
102
103   @Test
104   public void testGetOriginUri_validPayload() {
105     String value = null;
106     try {
107       value = AaiUiSvcPolicyUtil.getOriginUri(node);
108       assertTrue("Failure to extract origin uri", ORIGIN_URI.equals(value));
109     } catch (Exception e) {
110       fail("Failure to extract origin uri");
111     }
112   }
113 }