2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 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.so.client.namingservice;
23 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
24 import static com.github.tomakehurst.wiremock.client.WireMock.delete;
25 import static com.github.tomakehurst.wiremock.client.WireMock.post;
26 import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
27 import static org.junit.Assert.assertTrue;
28 import java.io.IOException;
29 import java.util.ArrayList;
30 import java.util.List;
31 import org.apache.http.HttpStatus;
32 import org.junit.Rule;
33 import org.junit.Test;
34 import org.junit.rules.ExpectedException;
35 import org.onap.namingservice.model.Deleteelement;
36 import org.onap.namingservice.model.Element;
37 import org.onap.namingservice.model.NameGenDeleteRequest;
38 import org.onap.namingservice.model.NameGenRequest;
39 import org.onap.so.BaseIntegrationTest;
40 import org.onap.so.client.exception.BadResponseException;
41 import org.springframework.beans.factory.annotation.Autowired;
42 import com.fasterxml.jackson.core.JsonProcessingException;
44 public class NamingClientIT extends BaseIntegrationTest {
48 NamingRequestObjectBuilder requestBuilder;
50 public ExpectedException thrown = ExpectedException.none();
53 public void assignNameGenRequest() throws BadResponseException, IOException {
54 wireMockServer.stubFor(post(urlPathEqualTo("/web/service/v1/genNetworkElementName"))
55 .willReturn(aResponse().withHeader("Content-Type", "application/json")
56 .withBodyFile("NamingClient/AssignResponse.json").withStatus(HttpStatus.SC_ACCEPTED)));
58 NameGenRequest request = assignSetup();
59 String response = client.postNameGenRequest(request);
60 assertTrue(response.equals("$vnf-name"));
64 public void assignNameGenRequestError() throws BadResponseException, IOException {
65 wireMockServer.stubFor(post(urlPathEqualTo("/web/service/v1/genNetworkElementName")).willReturn(aResponse()
66 .withHeader("Content-Type", "application/json").withBodyFile("NamingClient/ErrorResponse.json")
67 .withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR)));
69 thrown.expect(BadResponseException.class);
70 thrown.expectMessage("Error from Naming Service: External Key is required and must be unique");
71 NameGenRequest request = assignSetup();
72 client.postNameGenRequest(request);
76 public void unassignNameGenRequest() throws BadResponseException, IOException {
77 wireMockServer.stubFor(delete(urlPathEqualTo("/web/service/v1/genNetworkElementName"))
78 .willReturn(aResponse().withHeader("Content-Type", "application/json")
79 .withBodyFile("NamingClient/UnassignResponse.json").withStatus(HttpStatus.SC_ACCEPTED)));
81 String response = client.deleteNameGenRequest(unassignSetup());
82 assertTrue(response.equals(""));
86 public void unassignNameGenRequestError() throws BadResponseException, IOException {
87 wireMockServer.stubFor(delete(urlPathEqualTo("/web/service/v1/genNetworkElementName")).willReturn(aResponse()
88 .withHeader("Content-Type", "application/json").withBodyFile("NamingClient/ErrorResponse.json")
89 .withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR)));
91 thrown.expect(BadResponseException.class);
92 thrown.expectMessage("Error from Naming Service: External Key is required and must be unique");
93 client.deleteNameGenRequest(unassignSetup());
96 public NameGenRequest assignSetup() throws JsonProcessingException {
97 NameGenRequest request = new NameGenRequest();
98 List<Element> elements = new ArrayList<>();
99 Element testElement = new Element();
100 testElement = requestBuilder.elementMapper("SomeUniqueValue", "SDNC_Policy.Config_MS_1806SRIOV_VNATJson.4.xml",
101 "VNF", "nfNamingCode", "vnf_name");
102 elements.add(testElement);
103 request = requestBuilder.nameGenRequestMapper(elements);
107 public NameGenDeleteRequest unassignSetup() throws JsonProcessingException {
108 NameGenDeleteRequest request = new NameGenDeleteRequest();
109 List<Deleteelement> deleteElements = new ArrayList<>();
110 Deleteelement testElement = new Deleteelement();
111 testElement = requestBuilder.deleteElementMapper("instanceGroupId");
112 deleteElements.add(testElement);
113 request = requestBuilder.nameGenDeleteRequestMapper(deleteElements);