2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright 2019 Nokia
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
22 package org.onap.vid.aai;
24 import static org.mockito.BDDMockito.given;
25 import static org.mockito.BDDMockito.then;
27 import com.fasterxml.jackson.databind.ObjectMapper;
28 import com.google.common.collect.Lists;
29 import java.io.IOException;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.mockito.InjectMocks;
34 import org.mockito.Mock;
35 import org.mockito.junit.MockitoJUnitRunner;
36 import org.onap.vid.model.PombaInstance.PombaRequest;
37 import org.onap.vid.model.PombaInstance.ServiceInstance;
38 import org.onap.vid.utils.SystemPropertiesWrapper;
40 @RunWith(MockitoJUnitRunner.class)
41 public class PombaClientImplTest {
44 private SystemPropertiesWrapper systemPropertiesWrapper;
46 private PombaRestInterface pombaRestInterface;
48 private PombaClientImpl pombaClient;
51 public void should_doHttpPost_withGivenPombaRequest() throws IOException {
53 String expectedUrl = "http://localhost/dummyUrl";
54 given(systemPropertiesWrapper.getProperty("pomba.server.url")).willReturn(expectedUrl);
55 String expectedPayload = readExpectedPombaJsonRequest();
56 PombaRequest pombaRequest = createPombaRequest();
59 pombaClient.verify(pombaRequest);
62 then(pombaRestInterface).should().RestPost("VidAaiController", expectedUrl, expectedPayload);
65 private String readExpectedPombaJsonRequest() throws IOException {
66 URL url = PombaClientImplTest.class.getClassLoader().getResource("pomba_request.json");
67 PombaRequest expectedPombaRequest = new ObjectMapper().readValue(url, PombaRequest.class);
68 return new ObjectMapper().writeValueAsString(expectedPombaRequest);
71 private PombaRequest createPombaRequest() {
72 ServiceInstance serviceInstance1 = createServiceInstance("serviceType1", "serviceInstanceId1", "customerId1",
73 "modelVersion1", "modelInvariantId1");
74 ServiceInstance serviceInstance2 = createServiceInstance("serviceType2", "serviceInstanceId2", "customerId2",
75 "modelVersion2", "modelInvariantId2");
77 PombaRequest pombaRequest = new PombaRequest();
78 pombaRequest.serviceInstanceList = Lists.newArrayList(serviceInstance1, serviceInstance2);
82 private ServiceInstance createServiceInstance(String serviceType, String serviceInstanceId, String customerId,
83 String modelVersionId, String modelInvariantId) {
84 ServiceInstance serviceInstance = new ServiceInstance();
85 serviceInstance.serviceType = serviceType;
86 serviceInstance.serviceInstanceId = serviceInstanceId;
87 serviceInstance.customerId = customerId;
88 serviceInstance.modelInvariantId = modelInvariantId;
89 serviceInstance.modelVersionId = modelVersionId;
90 return serviceInstance;