1 /*******************************************************************************
2 * ============LICENSE_START==================================================
4 * * ===========================================================================
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * * ===========================================================================
7 * * Licensed under the Apache License, Version 2.0 (the "License");
8 * * you may not use this file except in compliance with the License.
9 * * You may obtain a copy of the License at
11 * * http://www.apache.org/licenses/LICENSE-2.0
13 * * Unless required by applicable law or agreed to in writing, software
14 * * distributed under the License is distributed on an "AS IS" BASIS,
15 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * * See the License for the specific language governing permissions and
17 * * limitations under the License.
18 * * ============LICENSE_END====================================================
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 ******************************************************************************/
23 package org.onap.dmaap.datarouter.provisioning.beans;
25 import org.apache.commons.lang3.reflect.FieldUtils;
26 import org.json.JSONArray;
27 import org.json.JSONObject;
28 import org.junit.Assert;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.powermock.api.mockito.PowerMockito;
33 import org.powermock.core.classloader.annotations.PowerMockIgnore;
34 import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
35 import org.powermock.modules.junit4.PowerMockRunner;
37 import java.util.ArrayList;
38 import java.util.HashMap;
39 import java.util.List;
42 import static org.mockito.Mockito.mock;
44 @RunWith(PowerMockRunner.class)
45 @SuppressStaticInitializationFor("org.onap.dmaap.datarouter.provisioning.beans.Feed")
46 @PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "org.w3c.*"})
47 public class IngressRouteTest {
49 private IngressRoute ingressRoute;
52 public void setUp() throws IllegalAccessException{
53 PowerMockito.mockStatic(Feed.class);
54 Feed feed = mock(Feed.class);
55 PowerMockito.when(Feed.getFeedById(1)).thenReturn(feed);
56 Map<String, Integer> map = new HashMap<>();
57 FieldUtils.writeDeclaredStaticField(NodeClass.class, "nodesMap", map, true);
61 public void Validate_IngressRoute_Constructors_Create_Same_Object() {
62 List<String> nodes = new ArrayList<>();
63 nodes.add("node.datarouternew.com");
64 ingressRoute = new IngressRoute(1, 1, "user1", "172.100.0.0/25", nodes);
65 JSONObject ingressRouteJson = createIngressRouteJson();
66 Assert.assertEquals(ingressRoute, new IngressRoute(ingressRouteJson));
70 public void Validate_AsJsonObject_Returns_Same_Values() {
71 List<String> nodes = new ArrayList<>();
72 nodes.add("node.datarouternew.com");
73 ingressRoute = new IngressRoute(1, 1, "user1", "172.100.0.0/25", nodes);
74 JSONObject ingressRouteJson = createIngressRouteJson();
75 Assert.assertEquals(ingressRoute.asJSONObject().toString(), ingressRouteJson.toString());
78 private JSONObject createIngressRouteJson() {
79 JSONObject ingressRouteJson = new JSONObject();
80 ingressRouteJson.put("seq", 1);
81 ingressRouteJson.put("feedid", 1);
82 ingressRouteJson.put("user", "user1");
83 ingressRouteJson.put("subnet", "172.100.0.0/25");
84 JSONArray nodes = new JSONArray();
85 nodes.put("node.datarouternew.com");
86 ingressRouteJson.put("node", nodes);
87 return ingressRouteJson;