2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
24 package org.onap.appc.listener.LCM.impl;
26 import static org.mockito.Matchers.any;
27 import static org.mockito.Matchers.anyString;
28 import static org.mockito.Mockito.mock;
29 import static org.mockito.Mockito.verify;
30 import static org.mockito.Mockito.when;
31 import static org.onap.appc.listener.TestUtil.JSON_OUTPUT_BODY_STR;
32 import static org.onap.appc.listener.TestUtil.buildDmaapMessage;
34 import com.fasterxml.jackson.databind.JsonNode;
35 import org.junit.Test;
36 import org.onap.appc.exceptions.APPCException;
37 import org.onap.appc.listener.EventHandler;
38 import org.onap.appc.listener.LCM.operation.ProviderOperations;
39 import org.onap.appc.listener.util.Mapper;
41 public class WorkerImplTest {
43 private EventHandler mockEventHandler = mock(EventHandler.class);
44 private ProviderOperations mockProviderOperations = mock(ProviderOperations.class);
47 @Test(expected = IllegalStateException.class)
48 public void should_throw_when_one_of_worker_fields_is_null() {
50 WorkerImpl worker = new WorkerImpl(null, mockEventHandler, mockProviderOperations);
55 public void should_post_error_message_to_dmaap_on_exception() throws APPCException {
57 when(mockProviderOperations.topologyDG(anyString(), any(JsonNode.class)))
58 .thenThrow(new RuntimeException("test exception"));
60 WorkerImpl worker = new WorkerImpl(buildDmaapMessage(), mockEventHandler, mockProviderOperations);
63 verify(mockEventHandler).postStatus(anyString(), anyString());
68 public void should_post_message_to_dmaap_on_successful_run() throws APPCException {
70 JsonNode testOutputJsonNode = Mapper.toJsonNodeFromJsonString(JSON_OUTPUT_BODY_STR);
71 when(mockProviderOperations.topologyDG(anyString(), any(JsonNode.class)))
72 .thenReturn(testOutputJsonNode);
74 WorkerImpl worker = new WorkerImpl(buildDmaapMessage(), mockEventHandler, mockProviderOperations);
77 verify(mockEventHandler).postStatus(anyString(), anyString());