2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 * ECOMP and OpenECOMP are trademarks
23 * and service marks of AT&T Intellectual Property.
26 package org.onap.aai.datarouter.util;
28 import static org.junit.Assert.assertNull;
29 import static org.junit.Assert.assertTrue;
30 import static org.junit.Assert.fail;
32 import org.junit.BeforeClass;
33 import org.junit.Test;
34 import org.onap.aai.datarouter.util.AaiUiSvcPolicyUtil;
36 import com.fasterxml.jackson.databind.JsonNode;
37 import com.fasterxml.jackson.databind.ObjectMapper;
39 public class AaiUiSvcPolicyUtilTest {
41 private final static String ORIGIN_URI = "testUri/somePath";
42 private final static String ORIGIN_PAYLOAD = "test payload";
44 private final static String validPayload = "{" +
45 "\"origin-uri\": \"" + ORIGIN_URI + "\"," +
46 "\"origin-payload\": \"" + ORIGIN_PAYLOAD + "\"}";
48 private final static String payloadWithoutOriginUri = "{" +
49 "\"origin-payload\": \"" + ORIGIN_PAYLOAD + "\"}";
51 private final static String payloadWithoutOriginPayload = "{" +
52 "\"origin-uri\": \"" + ORIGIN_URI + "\"}";
54 private static JsonNode node = null;
55 private static JsonNode nodeWithoutOrginUri = null;
56 private static JsonNode nodeWithoutOrginPayload = null;
57 static ObjectMapper mapper = new ObjectMapper();
60 public static void init(){
62 node = mapper.readTree(validPayload);
63 nodeWithoutOrginUri = mapper.readTree(payloadWithoutOriginUri);
64 nodeWithoutOrginPayload = mapper.readTree(payloadWithoutOriginPayload);
65 } catch (Exception e) {
66 fail("Initialization error");
71 public void testGetOriginPayload_missingPayload() {
72 JsonNode value = null;
74 value = AaiUiSvcPolicyUtil.getOriginPayload(nodeWithoutOrginPayload);
75 assertNull("Failure to extract origin payload", value);
76 } catch (Exception e) {
77 fail("Failure to extract origin payload");
82 public void testGetOriginPayload_validPayload() {
83 JsonNode value = null;
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");
93 public void testGetOriginUri_missingUri() {
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");
104 public void testGetOriginUri_validPayload() {
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");