AAI-1523 Batch reformat aai-core
[aai/aai-common.git] / aai-core / src / test / java / org / onap / aai / rest / GenericVnfLInterfaceTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 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
10  *
11  *    http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.aai.rest;
22
23 import static org.junit.Assert.assertEquals;
24
25 import java.io.IOException;
26 import java.util.Arrays;
27 import java.util.Collection;
28 import java.util.HashMap;
29 import java.util.Map;
30
31 import javax.ws.rs.core.Response;
32
33 import org.json.JSONObject;
34 import org.junit.After;
35 import org.junit.Before;
36 import org.junit.Test;
37 import org.junit.runner.RunWith;
38 import org.junit.runners.Parameterized;
39 import org.onap.aai.AAISetup;
40 import org.onap.aai.HttpTestUtil;
41 import org.onap.aai.PayloadUtil;
42 import org.onap.aai.exceptions.AAIException;
43 import org.onap.aai.serialization.engines.QueryStyle;
44 import org.skyscreamer.jsonassert.JSONAssert;
45 import org.springframework.test.annotation.DirtiesContext;
46
47 @RunWith(value = Parameterized.class)
48 @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
49 public class GenericVnfLInterfaceTest extends AAISetup {
50
51     private HttpTestUtil httpTestUtil;
52
53     @Parameterized.Parameter(value = 0)
54     public QueryStyle queryStyle;
55
56     @Parameterized.Parameters(name = "QueryStyle.{0}")
57     public static Collection<Object[]> data() {
58         return Arrays.asList(new Object[][] {{QueryStyle.TRAVERSAL}, {QueryStyle.TRAVERSAL_URI}});
59     }
60
61     @Before
62     public void setUp() {
63         httpTestUtil = new HttpTestUtil(queryStyle);
64     }
65
66     @Test
67     public void testPutTwoLInterfacesToGenericVnf() throws Exception {
68
69         Map<String, String> templateValueMap = new HashMap<>();
70         templateValueMap.put("ip-address", "ipv1");
71
72         String resource = PayloadUtil.getTemplatePayload("generic-vnf-with-lag-interface.json", templateValueMap);
73         Response response = httpTestUtil.doPut("/aai/v12/network/generic-vnfs/generic-vnf/vnf1", resource);
74         assertEquals("Expecting the generic vnf to be created", 201, response.getStatus());
75
76         response = httpTestUtil.doGet("/aai/v12/network/generic-vnfs/generic-vnf/vnf1");
77         assertEquals("Expecting the generic vnf to be updated", 200, response.getStatus());
78
79         resource = response.getEntity().toString();
80         resource = resource.replaceAll("ipv1\",\"resource-version\":\"\\d+\"", "ipv2\"");
81         response = httpTestUtil.doPut("/aai/v12/network/generic-vnfs/generic-vnf/vnf1", resource);
82         assertEquals("Expecting the generic vnf to be updated", 200, response.getStatus());
83
84     }
85
86     @After
87     public void tearDown() throws IOException, AAIException {
88         Response response = httpTestUtil.doGet("/aai/v12/network/generic-vnfs/generic-vnf/vnf1");
89         assertEquals("Expecting the generic vnf to be updated", 200, response.getStatus());
90
91         String expected = PayloadUtil.getExpectedPayload("generic-vnf-with-lag-interface.json");
92         JSONAssert.assertEquals(expected, response.getEntity().toString(), false);
93
94         JSONObject jsonObject = new JSONObject(response.getEntity().toString());
95         String resourceVersion = (String) jsonObject.get("resource-version");
96
97         response = httpTestUtil.doDelete("/aai/v12/network/generic-vnfs/generic-vnf/vnf1", resourceVersion);
98         assertEquals("Expecting the generic vnf to be deleted", 204, response.getStatus());
99     }
100 }