Changed to unmaintained
[appc.git] / appc-event-listener / appc-event-listener-bundle / src / test / java / org / onap / appc / listener / LCM / impl / WorkerImplTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2018 Nokia Solutions and Networks
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
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
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  * 
21  * ============LICENSE_END=========================================================
22  */
23 package org.onap.appc.listener.LCM.impl;
24
25 import static org.mockito.Matchers.any;
26 import static org.mockito.Matchers.anyString;
27 import static org.mockito.Mockito.mock;
28 import static org.mockito.Mockito.verify;
29 import static org.mockito.Mockito.when;
30 import static org.onap.appc.listener.TestUtil.JSON_OUTPUT_BODY_STR;
31 import static org.onap.appc.listener.TestUtil.buildDmaapMessage;
32
33 import com.fasterxml.jackson.databind.JsonNode;
34 import org.junit.Test;
35 import org.onap.appc.exceptions.APPCException;
36 import org.onap.appc.listener.EventHandler;
37 import org.onap.appc.listener.LCM.operation.ProviderOperations;
38 import org.onap.appc.listener.util.Mapper;
39
40 public class WorkerImplTest {
41
42     private EventHandler mockEventHandler = mock(EventHandler.class);
43     private ProviderOperations mockProviderOperations = mock(ProviderOperations.class);
44
45
46     @Test(expected = IllegalStateException.class)
47     public void should_throw_when_one_of_worker_fields_is_null() {
48
49         WorkerImpl worker = new WorkerImpl(null, mockEventHandler, mockProviderOperations);
50         worker.run();
51     }
52
53     @Test
54     public void should_post_error_message_to_dmaap_on_exception() throws APPCException {
55
56         when(mockProviderOperations.topologyDG(anyString(), any(JsonNode.class)))
57             .thenThrow(new RuntimeException("test exception"));
58
59         WorkerImpl worker = new WorkerImpl(buildDmaapMessage(), mockEventHandler, mockProviderOperations);
60         worker.run();
61
62         verify(mockEventHandler).postStatus(anyString(), anyString());
63     }
64
65
66     @Test
67     public void should_post_message_to_dmaap_on_successful_run() throws APPCException {
68
69         JsonNode testOutputJsonNode = Mapper.toJsonNodeFromJsonString(JSON_OUTPUT_BODY_STR);
70         when(mockProviderOperations.topologyDG(anyString(), any(JsonNode.class)))
71             .thenReturn(testOutputJsonNode);
72
73         WorkerImpl worker = new WorkerImpl(buildDmaapMessage(), mockEventHandler, mockProviderOperations);
74         worker.run();
75
76         verify(mockEventHandler).postStatus(anyString(), anyString());
77     }
78 }