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.github.tomakehurst.wiremock.client.WireMock.aResponse;
24 import static com.github.tomakehurst.wiremock.client.WireMock.post;
25 import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
26 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
27 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.assertThat;
29 import static org.junit.Assert.assertTrue;
32 import java.io.IOException;
34 import org.apache.http.HttpStatus;
35 import org.junit.Test;
36 import org.onap.so.client.avpn.dmaap.beans.AVPNDmaapBean;
37 import org.onap.so.client.exception.MapperException;
38 import org.onap.so.BaseTest;
39 import org.springframework.beans.factory.annotation.Autowired;
41 import com.fasterxml.jackson.core.JsonProcessingException;
42 import com.fasterxml.jackson.databind.ObjectMapper;
43 import static com.github.tomakehurst.wiremock.client.WireMock.*;
45 public class DmaapPropertiesClientTest extends BaseTest{
48 private DmaapPropertiesClient dmaapPropertiesClient;
51 private final String file = "src/test/resources/org/onap/so/client/avpn/dmaap/avpnDmaapAsyncRequestStatus.json";
52 private String requestId = "rq1234d1-5a33-55df-13ab-12abad84e331";
53 private String clientSource = "SPP";
54 private String correlator = "myClientId123";
55 private String serviceInstanceId = "bc305d54-75b4-431b-adb2-eb6b9e546014";
56 private String startTime = "2017-11-17T09:30:47Z";
57 private String finishTime = "2017-11-17T09:30:47Z";
58 private String requestScope = "service";
59 private String requestType = "createInstance";
60 private String timestamp = "2017-11-17T09:30:47Z";
61 private String requestState = "COMPLETE";
62 private String statusMessage = "Success";
63 private String percentProgress = "100";
66 public void testBuildRequestJson() throws MapperException, IOException {
67 AVPNDmaapBean actualBean = dmaapPropertiesClient.buildRequestJson(requestId, clientSource, correlator, serviceInstanceId, startTime, finishTime, requestScope,
68 requestType, timestamp, requestState, statusMessage, percentProgress, true);
70 AVPNDmaapBean expected = new ObjectMapper().readValue(new File(file), AVPNDmaapBean.class);
72 assertNotNull(actualBean);
73 assertThat(actualBean, sameBeanAs(expected));
77 public void testDmaapPublishRequest() throws JsonProcessingException, MapperException {
78 stubFor(post(urlEqualTo("/events/com.att.mso.asyncStatusUpdate?timeout=20000"))
79 .willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_ACCEPTED)));
81 dmaapPropertiesClient.dmaapPublishRequest(requestId, clientSource, correlator, serviceInstanceId, startTime, finishTime, requestScope,
82 requestType, timestamp, requestState, statusMessage, percentProgress, false);