2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2018 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.onap.so.asdc.client;
23 import static org.mockito.ArgumentMatchers.isA;
24 import static org.mockito.Mockito.doNothing;
25 import static org.mockito.Mockito.doReturn;
26 import static org.mockito.Mockito.doThrow;
27 import static org.mockito.Mockito.mock;
28 import static org.mockito.Mockito.times;
29 import static org.mockito.Mockito.verify;
30 import org.junit.Before;
31 import org.junit.Rule;
32 import org.junit.Test;
33 import org.junit.rules.ExpectedException;
34 import org.mockito.MockitoAnnotations;
35 import org.onap.sdc.api.notification.IStatusData;
36 import org.onap.sdc.utils.DistributionStatusEnum;
37 import org.onap.so.asdc.BaseTest;
38 import org.onap.so.asdc.client.exceptions.ArtifactInstallerException;
39 import org.onap.so.asdc.client.test.emulators.JsonStatusData;
40 import org.springframework.beans.factory.annotation.Autowired;
42 public class ASDCStatusCallBackTest extends BaseTest {
44 private ASDCStatusCallBack statusCallback;
47 public ExpectedException expectedException = ExpectedException.none();
50 public void before() {
51 MockitoAnnotations.initMocks(this);
55 public void activateCallbackTest() throws Exception {
56 JsonStatusData statusData = new JsonStatusData();
58 doNothing().when(toscaInstaller).installTheComponentStatus(isA(JsonStatusData.class));
60 statusCallback.activateCallback(statusData);
62 verify(toscaInstaller, times(1)).installTheComponentStatus(statusData);
66 public void activateCallbackDoneErrorStatusTest() throws Exception {
67 IStatusData statusData = mock(IStatusData.class);
69 doReturn("distributionId").when(statusData).getDistributionID();
70 doReturn("componentName").when(statusData).getComponentName();
71 doReturn(DistributionStatusEnum.COMPONENT_DONE_ERROR).when(statusData).getStatus();
72 doNothing().when(toscaInstaller).installTheComponentStatus(isA(IStatusData.class));
74 statusCallback.activateCallback(statusData);
76 verify(toscaInstaller, times(1)).installTheComponentStatus(statusData);
80 public void activateCallbackExceptionTest() throws Exception {
81 IStatusData statusData = mock(IStatusData.class);
83 doReturn("distributionId").when(statusData).getDistributionID();
84 doReturn("componentName").when(statusData).getComponentName();
85 doReturn(DistributionStatusEnum.COMPONENT_DONE_OK).when(statusData).getStatus();
86 doThrow(ArtifactInstallerException.class).when(toscaInstaller)
87 .installTheComponentStatus(isA(IStatusData.class));
89 statusCallback.activateCallback(statusData);