2 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.aai.datarouter.util;
23 import static org.junit.Assert.assertNull;
24 import static org.junit.Assert.assertTrue;
25 import static org.junit.Assert.fail;
27 import org.junit.BeforeClass;
28 import org.junit.Test;
29 import org.onap.aai.datarouter.util.AaiUiSvcPolicyUtil;
31 import com.fasterxml.jackson.databind.JsonNode;
32 import com.fasterxml.jackson.databind.ObjectMapper;
34 public class AaiUiSvcPolicyUtilTest {
36 private final static String ORIGIN_URI = "testUri/somePath";
37 private final static String ORIGIN_PAYLOAD = "test payload";
39 private final static String validPayload = "{" +
40 "\"origin-uri\": \"" + ORIGIN_URI + "\"," +
41 "\"origin-payload\": \"" + ORIGIN_PAYLOAD + "\"}";
43 private final static String payloadWithoutOriginUri = "{" +
44 "\"origin-payload\": \"" + ORIGIN_PAYLOAD + "\"}";
46 private final static String payloadWithoutOriginPayload = "{" +
47 "\"origin-uri\": \"" + ORIGIN_URI + "\"}";
49 private static JsonNode node = null;
50 private static JsonNode nodeWithoutOrginUri = null;
51 private static JsonNode nodeWithoutOrginPayload = null;
52 static ObjectMapper mapper = new ObjectMapper();
55 public static void init(){
57 node = mapper.readTree(validPayload);
58 nodeWithoutOrginUri = mapper.readTree(payloadWithoutOriginUri);
59 nodeWithoutOrginPayload = mapper.readTree(payloadWithoutOriginPayload);
60 } catch (Exception e) {
61 fail("Initialization error");
66 public void testGetOriginPayload_missingPayload() {
67 JsonNode value = null;
69 value = AaiUiSvcPolicyUtil.getOriginPayload(nodeWithoutOrginPayload);
70 assertNull("Failure to extract origin payload", value);
71 } catch (Exception e) {
72 fail("Failure to extract origin payload");
77 public void testGetOriginPayload_validPayload() {
78 JsonNode value = null;
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");
88 public void testGetOriginUri_missingUri() {
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");
99 public void testGetOriginUri_validPayload() {
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");