2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Nokia
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.vid.aai;
22 import static org.assertj.core.api.Assertions.assertThatCode;
23 import static org.mockito.BDDMockito.given;
24 import static org.mockito.BDDMockito.then;
26 import com.fasterxml.jackson.databind.ObjectMapper;
27 import com.google.common.collect.Lists;
28 import java.io.IOException;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.mockito.InjectMocks;
33 import org.mockito.Mock;
34 import org.mockito.junit.MockitoJUnitRunner;
35 import org.onap.vid.model.PombaInstance.PombaRequest;
36 import org.onap.vid.model.PombaInstance.ServiceInstance;
37 import org.onap.vid.utils.SystemPropertiesWrapper;
39 @RunWith(MockitoJUnitRunner.class)
40 public class PombaClientImplTest {
43 private SystemPropertiesWrapper systemPropertiesWrapper;
45 private PombaRestInterface pombaRestInterface;
47 private PombaClientImpl pombaClient;
50 public void should_doHttpPost_withGivenPombaRequest() throws IOException {
52 String expectedUrl = "http://localhost/dummyUrl";
53 given(systemPropertiesWrapper.getProperty("pomba.server.url")).willReturn(expectedUrl);
54 String expectedPayload = readExpectedPombaJsonRequest();
55 PombaRequest pombaRequest = createPombaRequest();
58 pombaClient.verify(pombaRequest);
61 then(pombaRestInterface).should().RestPost("VidAaiController", expectedUrl, expectedPayload);
65 public void should_handleException_withoutRethrowing() throws IOException {
67 String expectedUrl = "http://localhost/dummyUrl";
68 String expectedPayload = readExpectedPombaJsonRequest();
69 given(systemPropertiesWrapper.getProperty("pomba.server.url")).willReturn(expectedUrl);
70 given(pombaRestInterface.RestPost("VidAaiController", expectedUrl, expectedPayload))
71 .willThrow(new NullPointerException());
72 PombaRequest pombaRequest = createPombaRequest();
75 assertThatCode(() -> pombaClient.verify(pombaRequest)).doesNotThrowAnyException();
78 private String readExpectedPombaJsonRequest() throws IOException {
79 URL url = PombaClientImplTest.class.getClassLoader().getResource("pomba_request.json");
80 PombaRequest expectedPombaRequest = new ObjectMapper().readValue(url, PombaRequest.class);
81 return new ObjectMapper().writeValueAsString(expectedPombaRequest);
84 private PombaRequest createPombaRequest() {
85 ServiceInstance serviceInstance1 = createServiceInstance("serviceType1", "serviceInstanceId1", "customerId1",
86 "modelVersion1", "modelInvariantId1");
87 ServiceInstance serviceInstance2 = createServiceInstance("serviceType2", "serviceInstanceId2", "customerId2",
88 "modelVersion2", "modelInvariantId2");
90 PombaRequest pombaRequest = new PombaRequest(Lists.newArrayList(serviceInstance1, serviceInstance2));
94 private ServiceInstance createServiceInstance(String serviceType, String serviceInstanceId, String customerId,
95 String modelVersionId, String modelInvariantId) {
96 ServiceInstance serviceInstance = new ServiceInstance(
102 return serviceInstance;