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.mockito.BDDMockito.given;
23 import static org.mockito.BDDMockito.then;
25 import com.fasterxml.jackson.databind.ObjectMapper;
26 import com.google.common.collect.Lists;
27 import java.io.IOException;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.mockito.InjectMocks;
32 import org.mockito.Mock;
33 import org.mockito.junit.MockitoJUnitRunner;
34 import org.onap.vid.model.PombaInstance.PombaRequest;
35 import org.onap.vid.model.PombaInstance.ServiceInstance;
36 import org.onap.vid.utils.SystemPropertiesWrapper;
38 @RunWith(MockitoJUnitRunner.class)
39 public class PombaClientImplTest {
42 private SystemPropertiesWrapper systemPropertiesWrapper;
44 private PombaRestInterface pombaRestInterface;
46 private PombaClientImpl pombaClient;
49 public void should_doHttpPost_withGivenPombaRequest() throws IOException {
51 String expectedUrl = "http://localhost/dummyUrl";
52 given(systemPropertiesWrapper.getProperty("pomba.server.url")).willReturn(expectedUrl);
53 String expectedPayload = readExpectedPombaJsonRequest();
54 PombaRequest pombaRequest = createPombaRequest();
57 pombaClient.verify(pombaRequest);
60 then(pombaRestInterface).should().RestPost("VidAaiController", expectedUrl, expectedPayload);
63 private String readExpectedPombaJsonRequest() throws IOException {
64 URL url = PombaClientImplTest.class.getClassLoader().getResource("pomba_request.json");
65 PombaRequest expectedPombaRequest = new ObjectMapper().readValue(url, PombaRequest.class);
66 return new ObjectMapper().writeValueAsString(expectedPombaRequest);
69 private PombaRequest createPombaRequest() {
70 ServiceInstance serviceInstance1 = createServiceInstance("serviceType1", "serviceInstanceId1", "customerId1",
71 "modelVersion1", "modelInvariantId1");
72 ServiceInstance serviceInstance2 = createServiceInstance("serviceType2", "serviceInstanceId2", "customerId2",
73 "modelVersion2", "modelInvariantId2");
75 PombaRequest pombaRequest = new PombaRequest(Lists.newArrayList(serviceInstance1, serviceInstance2));
79 private ServiceInstance createServiceInstance(String serviceType, String serviceInstanceId, String customerId,
80 String modelVersionId, String modelInvariantId) {
81 ServiceInstance serviceInstance = new ServiceInstance(
87 return serviceInstance;