2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 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.so.client.dmaapproperties;
23 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertThat;
26 import static org.mockito.Matchers.anyString;
27 import static org.mockito.Mockito.doNothing;
28 import static org.mockito.Mockito.doReturn;
29 import static org.mockito.Mockito.times;
30 import static org.mockito.Mockito.verify;
33 import java.io.IOException;
35 import org.junit.Before;
36 import org.junit.Test;
37 import org.mockito.Mockito;
38 import org.mockito.MockitoAnnotations;
39 import org.onap.so.BaseTest;
40 import org.onap.so.client.avpn.dmaap.beans.AVPNDmaapBean;
41 import org.onap.so.client.exception.MapperException;
42 import org.onap.so.client.dmaapproperties.GlobalDmaapPublisher;
43 import org.springframework.beans.factory.annotation.Autowired;
45 import com.fasterxml.jackson.core.JsonProcessingException;
46 import com.fasterxml.jackson.databind.ObjectMapper;
48 public class DmaapPropertiesClientTest extends BaseTest{
51 private DmaapPropertiesClient dmaapPropertiesClient;
54 private final String file = "src/test/resources/org/onap/so/client/avpn/dmaap/avpnDmaapAsyncRequestStatus.json";
55 private String requestId = "rq1234d1-5a33-55df-13ab-12abad84e331";
56 private String clientSource = "SPP";
57 private String correlator = "myClientId123";
58 private String serviceInstanceId = "bc305d54-75b4-431b-adb2-eb6b9e546014";
59 private String startTime = "2017-11-17T09:30:47Z";
60 private String finishTime = "2017-11-17T09:30:47Z";
61 private String requestScope = "service";
62 private String requestType = "createInstance";
63 private String timestamp = "2017-11-17T09:30:47Z";
64 private String requestState = "COMPLETE";
65 private String statusMessage = "Success";
66 private String percentProgress = "100";
69 public void testBuildRequestJson() throws MapperException, IOException {
70 AVPNDmaapBean actualBean = dmaapPropertiesClient.buildRequestJson(requestId, clientSource, correlator, serviceInstanceId, startTime, finishTime, requestScope,
71 requestType, timestamp, requestState, statusMessage, percentProgress, true);
73 AVPNDmaapBean expected = new ObjectMapper().readValue(new File(file), AVPNDmaapBean.class);
75 assertNotNull(actualBean);
76 assertThat(actualBean, sameBeanAs(expected));
80 public void testDmaapPublishRequest() throws JsonProcessingException, MapperException {
81 DmaapPropertiesClient client = Mockito.spy(DmaapPropertiesClient.class);
82 GlobalDmaapPublisher mockedClientDmaapPublisher = Mockito.mock(GlobalDmaapPublisher.class);
83 AVPNDmaapBean mockedDmaapBean = Mockito.mock(AVPNDmaapBean.class);
84 String request = "test";
86 doReturn(mockedDmaapBean).when(client).buildRequestJson(requestId, clientSource, correlator, serviceInstanceId, startTime, finishTime, requestScope,
87 requestType, timestamp, requestState, statusMessage, percentProgress, false);
89 AVPNDmaapBean actualDmaapBean = client.buildRequestJson(requestId, clientSource, correlator, serviceInstanceId, startTime, finishTime, requestScope,
90 requestType, timestamp, requestState, statusMessage, percentProgress, false);
91 mockedClientDmaapPublisher.send(request);
93 doNothing().when(mockedClientDmaapPublisher).send(anyString());
95 verify(client, times(1)).buildRequestJson(requestId, clientSource, correlator, serviceInstanceId, startTime,
96 finishTime, requestScope, requestType, timestamp, requestState, statusMessage, percentProgress, false);
97 verify(mockedClientDmaapPublisher, times(1)).send(request);
99 assertNotNull(actualDmaapBean);