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=========================================================
21 package org.onap.aai.rest;
23 import static org.junit.Assert.assertEquals;
25 import java.io.IOException;
26 import java.util.Arrays;
27 import java.util.Collection;
28 import java.util.HashMap;
31 import javax.ws.rs.core.Response;
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;
47 @RunWith(value = Parameterized.class)
48 @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
49 public class GenericVnfLInterfaceTest extends AAISetup {
51 private HttpTestUtil httpTestUtil;
53 @Parameterized.Parameter(value = 0)
54 public QueryStyle queryStyle;
56 @Parameterized.Parameters(name = "QueryStyle.{0}")
57 public static Collection<Object[]> data() {
58 return Arrays.asList(new Object[][] {{QueryStyle.TRAVERSAL}, {QueryStyle.TRAVERSAL_URI}});
63 httpTestUtil = new HttpTestUtil(queryStyle);
67 public void testPutTwoLInterfacesToGenericVnf() throws Exception {
69 Map<String, String> templateValueMap = new HashMap<>();
70 templateValueMap.put("ip-address", "ipv1");
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());
76 response = httpTestUtil.doGet("/aai/v12/network/generic-vnfs/generic-vnf/vnf1");
77 assertEquals("Expecting the generic vnf to be updated", 200, response.getStatus());
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());
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());
91 String expected = PayloadUtil.getExpectedPayload("generic-vnf-with-lag-interface.json");
92 JSONAssert.assertEquals(expected, response.getEntity().toString(), false);
94 JSONObject jsonObject = new JSONObject(response.getEntity().toString());
95 String resourceVersion = (String) jsonObject.get("resource-version");
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());