Insert subprcess to delete E2E service instance
[so.git] / common / src / test / java / org / openecomp / mso / client / dmaap / PnfReadyEventConsumerTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2018 Huawei 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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.openecomp.mso.client.dmaap;
22
23 import static org.assertj.core.api.Assertions.assertThat;
24 import static org.mockito.Mockito.mock;
25 import static org.mockito.Mockito.spy;
26 import static org.mockito.Mockito.when;
27
28 import java.io.IOException;
29 import java.util.Arrays;
30 import java.util.Optional;
31 import org.junit.Test;
32 import org.openecomp.mso.client.sdno.dmaap.PnfReadyEventConsumer;
33
34 public class PnfReadyEventConsumerTest {
35
36     private static final String CORRELATION_ID = "correlation_id_test";
37
38     private static final String JSON_WITH_CORRELATION_ID = " {\"pnfRegistrationFields\": {\n"
39             + "      \"correlationId\": \"correlation_id_test\"\n"
40             + "    }}";
41
42     @Test
43     public void eventIsFoundForGivenCorrelationId2() throws Exception {
44         PnfReadyEventConsumerForTesting testedObjectSpy = spy(new PnfReadyEventConsumerForTesting(CORRELATION_ID));
45         Consumer consumerMock = mock(Consumer.class);
46         when(testedObjectSpy.getConsumer()).thenReturn(consumerMock);
47         when(consumerMock.fetch()).thenReturn(Arrays.asList(JSON_WITH_CORRELATION_ID));
48         testedObjectSpy.consume();
49         assertThat(testedObjectSpy.continuePolling()).isFalse();
50     }
51
52     // TODO this is temporary class, when methods are defined, it will be deleted
53     private class PnfReadyEventConsumerForTesting extends PnfReadyEventConsumer {
54
55         public PnfReadyEventConsumerForTesting(String correlationId) throws IOException {
56             super(correlationId);
57         }
58
59         @Override
60         public String getUserName(){
61             return "userNameTest";
62         }
63         @Override
64         public String getPassword(){
65             return "passTest";
66         }
67         @Override
68         public String getTopic(){
69             return "topicTest";
70         }
71         @Override
72         public Optional<String> getHost(){
73             return Optional.of("http://localhost");
74         }
75         @Override
76         public boolean isFailure(String message) {
77             return false;
78         }
79         @Override
80         public String getRequestId() {
81             return "requestTest";
82         }
83     }
84
85 }