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.Matchers.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;
31 import org.junit.Before;
32 import org.junit.Rule;
33 import org.junit.Test;
34 import org.junit.rules.ExpectedException;
35 import org.mockito.MockitoAnnotations;
36 import org.onap.sdc.api.notification.IStatusData;
37 import org.onap.sdc.utils.DistributionStatusEnum;
38 import org.onap.so.asdc.BaseTest;
39 import org.onap.so.asdc.client.exceptions.ArtifactInstallerException;
40 import org.onap.so.asdc.client.test.emulators.JsonStatusData;
41 import org.springframework.beans.factory.annotation.Autowired;
43 public class ASDCStatusCallBackTest extends BaseTest {
45 private ASDCStatusCallBack statusCallback;
48 public ExpectedException expectedException = ExpectedException.none();
51 public void before() {
52 MockitoAnnotations.initMocks(this);
56 public void activateCallbackTest() throws Exception {
57 JsonStatusData statusData = new JsonStatusData();
59 doNothing().when(toscaInstaller).installTheComponentStatus(isA(JsonStatusData.class));
61 statusCallback.activateCallback(statusData);
63 verify(toscaInstaller, times(1)).installTheComponentStatus(statusData);
67 public void activateCallbackDoneErrorStatusTest() throws Exception {
68 IStatusData statusData = mock(IStatusData.class);
70 doReturn("distributionId").when(statusData).getDistributionID();
71 doReturn("componentName").when(statusData).getComponentName();
72 doReturn(DistributionStatusEnum.COMPONENT_DONE_ERROR).when(statusData).getStatus();
73 doNothing().when(toscaInstaller).installTheComponentStatus(isA(IStatusData.class));
75 statusCallback.activateCallback(statusData);
77 verify(toscaInstaller, times(1)).installTheComponentStatus(statusData);
81 public void activateCallbackExceptionTest() throws Exception {
82 IStatusData statusData = mock(IStatusData.class);
84 doReturn("distributionId").when(statusData).getDistributionID();
85 doReturn("componentName").when(statusData).getComponentName();
86 doReturn(DistributionStatusEnum.COMPONENT_DONE_OK).when(statusData).getStatus();
87 doThrow(ArtifactInstallerException.class).when(toscaInstaller).installTheComponentStatus(isA(IStatusData.class));
89 statusCallback.activateCallback(statusData);