2 * ============LICENSE_START=======================================================
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
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 package org.onap.aai.rest;
22 import org.json.JSONObject;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.junit.runner.RunWith;
26 import org.junit.runners.Parameterized;
27 import org.onap.aai.AAIJunitRunner;
28 import org.onap.aai.AAISetup;
29 import org.onap.aai.HttpTestUtil;
30 import org.onap.aai.PayloadUtil;
31 import org.onap.aai.serialization.engines.QueryStyle;
32 import org.skyscreamer.jsonassert.JSONAssert;
34 import javax.ws.rs.core.Response;
35 import java.util.Arrays;
36 import java.util.Collection;
37 import java.util.HashMap;
40 import static org.junit.Assert.assertEquals;
42 @RunWith(value = AAIJunitRunner.class)
43 public class GenericVnfLInterfaceTest extends AAISetup {
45 private HttpTestUtil httpTestUtil;
47 @Parameterized.Parameter(value = 0)
48 public QueryStyle queryStyle;
50 @Parameterized.Parameters(name = "QueryStyle.{0}")
51 public static Collection<Object[]> data() {
52 return Arrays.asList(new Object[][]{
53 {QueryStyle.TRAVERSAL}
59 httpTestUtil = new HttpTestUtil(queryStyle);
63 public void testPutTwoLInterfacesToGenericVnf() throws Exception {
65 Map<String, String> templateValueMap = new HashMap<>();
66 templateValueMap.put("ip-address", "ipv1");
68 String resource = PayloadUtil.getTemplatePayload("generic-vnf-with-lag-interface.json", templateValueMap);
69 Response response = httpTestUtil.doPut("/aai/v12/network/generic-vnfs/generic-vnf/vnf1", resource);
70 assertEquals("Expecting the generic vnf to be created", 201, response.getStatus());
72 response = httpTestUtil.doGet("/aai/v12/network/generic-vnfs/generic-vnf/vnf1");
73 assertEquals("Expecting the generic vnf to be updated", 200, response.getStatus());
75 resource = response.getEntity().toString();
76 resource = resource.replaceAll("ipv1\",\"resource-version\":\"\\d+\"", "ipv2\"");
77 response = httpTestUtil.doPut("/aai/v12/network/generic-vnfs/generic-vnf/vnf1", resource);
78 assertEquals("Expecting the generic vnf to be updated", 200, response.getStatus());
80 response = httpTestUtil.doGet("/aai/v12/network/generic-vnfs/generic-vnf/vnf1");
81 assertEquals("Expecting the generic vnf to be updated", 200, response.getStatus());
83 String expected = PayloadUtil.getExpectedPayload("generic-vnf-with-lag-interface.json");
84 JSONAssert.assertEquals(expected, response.getEntity().toString(), false);
86 JSONObject jsonObject = new JSONObject(response.getEntity().toString());
87 String resourceVersion = (String) jsonObject.get("resource-version");
89 response = httpTestUtil.doDelete("/aai/v12/network/generic-vnfs/generic-vnf/vnf1", resourceVersion);
90 assertEquals("Expecting the generic vnf to be deleted", 204, response.getStatus());