2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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.openecomp.mso.bpmn.infrastructure.pnf.dmaap;
23 import static org.assertj.core.api.Assertions.assertThat;
24 import static org.mockito.Mockito.mock;
25 import static org.mockito.Mockito.verify;
27 import java.lang.reflect.Field;
28 import org.apache.http.client.HttpClient;
29 import org.apache.http.client.methods.HttpGet;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.mockito.ArgumentCaptor;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.test.context.ContextConfiguration;
36 import org.springframework.test.context.junit4.SpringRunner;
38 @RunWith(SpringRunner.class)
39 @ContextConfiguration({"classpath:springConfig_PnfEventReadyConsumer.xml"})
40 public class PnfEventReadyConsumerTest {
43 private PnfEventReadyConsumer pnfEventReadyConsumer;
45 private HttpClient httpClientMock;
48 public void init() throws NoSuchFieldException, IllegalAccessException {
49 httpClientMock = mock(HttpClient.class);
54 public void restClientInvokesWithProperURI() throws Exception {
55 ArgumentCaptor<HttpGet> captor1 = ArgumentCaptor.forClass(HttpGet.class);
56 pnfEventReadyConsumer.notifyWhenPnfReady("correlationId");
57 verify(httpClientMock).execute(captor1.capture());
58 assertThat(captor1.getValue().getURI()).hasHost("hostTest").hasPort(1234).hasScheme("http")
59 .hasPath("/eventsForTesting/eventTopicTest/consumerGroupTest/consumerTestId");
62 private void setPrivateField() throws NoSuchFieldException, IllegalAccessException {
63 Field field = pnfEventReadyConsumer.getClass().getDeclaredField("httpClient");
64 field.setAccessible(true);
65 field.set(pnfEventReadyConsumer, httpClientMock);