Springboot 2.0 upgrade
[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
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;
42
43 public class ASDCStatusCallBackTest extends BaseTest {
44         @Autowired
45         private ASDCStatusCallBack statusCallback;
46         
47         @Rule
48         public ExpectedException expectedException = ExpectedException.none();
49         
50         @Before
51         public void before() {
52                 MockitoAnnotations.initMocks(this);
53         }
54         
55         @Test
56         public void activateCallbackTest() throws Exception {
57                 JsonStatusData statusData = new JsonStatusData();
58                 
59                 doNothing().when(toscaInstaller).installTheComponentStatus(isA(JsonStatusData.class));
60                 
61                 statusCallback.activateCallback(statusData);
62                 
63                 verify(toscaInstaller, times(1)).installTheComponentStatus(statusData);
64         }
65         
66         @Test
67         public void activateCallbackDoneErrorStatusTest() throws Exception {
68                 IStatusData statusData = mock(IStatusData.class);
69                 
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));
74                 
75                 statusCallback.activateCallback(statusData);
76                 
77                 verify(toscaInstaller, times(1)).installTheComponentStatus(statusData);
78         }
79         
80         @Test
81         public void activateCallbackExceptionTest() throws Exception {
82                 IStatusData statusData = mock(IStatusData.class);
83                 
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));
88                 
89                 statusCallback.activateCallback(statusData);
90         }
91 }