2 * ============LICENSE_START=======================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * ============LICENSE_END=========================================================
23 package org.onap.appc.listener.LCM.impl;
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;
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;
40 public class WorkerImplTest {
42 private EventHandler mockEventHandler = mock(EventHandler.class);
43 private ProviderOperations mockProviderOperations = mock(ProviderOperations.class);
46 @Test(expected = IllegalStateException.class)
47 public void should_throw_when_one_of_worker_fields_is_null() {
49 WorkerImpl worker = new WorkerImpl(null, mockEventHandler, mockProviderOperations);
54 public void should_post_error_message_to_dmaap_on_exception() throws APPCException {
56 when(mockProviderOperations.topologyDG(anyString(), any(JsonNode.class)))
57 .thenThrow(new RuntimeException("test exception"));
59 WorkerImpl worker = new WorkerImpl(buildDmaapMessage(), mockEventHandler, mockProviderOperations);
62 verify(mockEventHandler).postStatus(anyString(), anyString());
67 public void should_post_message_to_dmaap_on_successful_run() throws APPCException {
69 JsonNode testOutputJsonNode = Mapper.toJsonNodeFromJsonString(JSON_OUTPUT_BODY_STR);
70 when(mockProviderOperations.topologyDG(anyString(), any(JsonNode.class)))
71 .thenReturn(testOutputJsonNode);
73 WorkerImpl worker = new WorkerImpl(buildDmaapMessage(), mockEventHandler, mockProviderOperations);
76 verify(mockEventHandler).postStatus(anyString(), anyString());