Replaced all tabs with spaces in java and pom.xml
[so.git] / asdc-controller / src / test / java / org / onap / so / asdc / client / ASDCStatusCallBackTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.so.asdc.client;
22
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;
41
42 public class ASDCStatusCallBackTest extends BaseTest {
43     @Autowired
44     private ASDCStatusCallBack statusCallback;
45
46     @Rule
47     public ExpectedException expectedException = ExpectedException.none();
48
49     @Before
50     public void before() {
51         MockitoAnnotations.initMocks(this);
52     }
53
54     @Test
55     public void activateCallbackTest() throws Exception {
56         JsonStatusData statusData = new JsonStatusData();
57
58         doNothing().when(toscaInstaller).installTheComponentStatus(isA(JsonStatusData.class));
59
60         statusCallback.activateCallback(statusData);
61
62         verify(toscaInstaller, times(1)).installTheComponentStatus(statusData);
63     }
64
65     @Test
66     public void activateCallbackDoneErrorStatusTest() throws Exception {
67         IStatusData statusData = mock(IStatusData.class);
68
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));
73
74         statusCallback.activateCallback(statusData);
75
76         verify(toscaInstaller, times(1)).installTheComponentStatus(statusData);
77     }
78
79     @Test
80     public void activateCallbackExceptionTest() throws Exception {
81         IStatusData statusData = mock(IStatusData.class);
82
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));
88
89         statusCallback.activateCallback(statusData);
90     }
91 }