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.openecomp.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;
35 import com.fasterxml.jackson.databind.JsonNode;
36 import com.fasterxml.jackson.databind.ObjectMapper;
38 public class AaiUiSvcPolicyUtilTest {
40 private final static String ORIGIN_URI = "testUri/somePath";
41 private final static String ORIGIN_PAYLOAD = "test payload";
43 private final static String validPayload = "{" +
44 "\"origin-uri\": \"" + ORIGIN_URI + "\"," +
45 "\"origin-payload\": \"" + ORIGIN_PAYLOAD + "\"}";
47 private final static String payloadWithoutOriginUri = "{" +
48 "\"origin-payload\": \"" + ORIGIN_PAYLOAD + "\"}";
50 private final static String payloadWithoutOriginPayload = "{" +
51 "\"origin-uri\": \"" + ORIGIN_URI + "\"}";
53 private static JsonNode node = null;
54 private static JsonNode nodeWithoutOrginUri = null;
55 private static JsonNode nodeWithoutOrginPayload = null;
56 static ObjectMapper mapper = new ObjectMapper();
59 public static void init(){
61 node = mapper.readTree(validPayload);
62 nodeWithoutOrginUri = mapper.readTree(payloadWithoutOriginUri);
63 nodeWithoutOrginPayload = mapper.readTree(payloadWithoutOriginPayload);
64 } catch (Exception e) {
65 fail("Initialization error");
70 public void testGetOriginPayload_missingPayload() {
71 JsonNode value = null;
73 value = AaiUiSvcPolicyUtil.getOriginPayload(nodeWithoutOrginPayload);
74 assertNull("Failure to extract origin payload", value);
75 } catch (Exception e) {
76 fail("Failure to extract origin payload");
81 public void testGetOriginPayload_validPayload() {
82 JsonNode value = null;
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");
92 public void testGetOriginUri_missingUri() {
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");
103 public void testGetOriginUri_validPayload() {
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");