ef346db3830de61b2e000585f47920368c2c611d
[aai/model-loader.git] / src / test / java / org / onap / aai / modelloader / notification / TestEventCallback.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017-2018 European Software Marketing Ltd.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21 package org.onap.aai.modelloader.notification;
22
23 import static org.mockito.ArgumentMatchers.any;
24 import static org.mockito.Mockito.verify;
25 import static org.mockito.Mockito.when;
26
27 import java.io.IOException;
28 import java.util.Collections;
29 import java.util.List;
30 import java.util.Properties;
31
32 import org.junit.jupiter.api.AfterEach;
33 import org.junit.jupiter.api.BeforeEach;
34 import org.junit.jupiter.api.Test;
35 import org.mockito.Mock;
36 import org.mockito.Mockito;
37 import org.mockito.MockitoAnnotations;
38 import org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder;
39 import org.onap.aai.modelloader.service.ArtifactDeploymentManager;
40 import org.onap.sdc.api.IDistributionClient;
41 import org.onap.sdc.api.notification.INotificationData;
42
43 /**
44  * Tests {@link EventCallback}.
45  */
46 public class TestEventCallback {
47
48     private static final String CONFIG_FILE = "model-loader.properties";
49
50     private Properties configProperties;
51     private EventCallback eventCallback;
52
53     @Mock private ArtifactDeploymentManager mockArtifactDeploymentManager;
54     @Mock private ArtifactDownloadManager mockArtifactDownloadManager;
55     @Mock private IDistributionClient mockDistributionClient;
56     @Mock private NotificationPublisher mockNotificationPublisher;
57
58     @BeforeEach
59     public void setup() throws IOException {
60         MockitoAnnotations.openMocks(this);
61         configProperties = new Properties();
62         configProperties.load(this.getClass().getClassLoader().getResourceAsStream(CONFIG_FILE));
63
64         eventCallback = new EventCallback(mockDistributionClient, mockArtifactDeploymentManager, mockArtifactDownloadManager, mockNotificationPublisher);
65     }
66
67     @AfterEach
68     public void tearDown() {
69         configProperties = null;
70         eventCallback = null;
71         mockArtifactDeploymentManager = null;
72         mockArtifactDownloadManager = null;
73         mockDistributionClient = null;
74     }
75
76     @Test
77     @SuppressWarnings("unchecked")
78     public void activateCallback_downloadFails() throws Exception {
79         INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile();
80
81         when(mockArtifactDownloadManager.downloadArtifacts(any(INotificationData.class), any(List.class)
82                 )).thenThrow(DownloadFailureException.class);
83
84         eventCallback.activateCallback(data);
85
86         verify(mockArtifactDownloadManager).downloadArtifacts(any(INotificationData.class), any(List.class));
87         Mockito.verifyNoInteractions(mockArtifactDeploymentManager);
88     }
89
90     @SuppressWarnings("unchecked")
91     @Test
92     public void activateCallback() throws Exception {
93         INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile();
94
95         when(mockArtifactDownloadManager.downloadArtifacts(any(INotificationData.class), any(List.class)))
96             .thenReturn(Collections.emptyList());
97
98         when(mockArtifactDeploymentManager.deploy(any(String.class), any(List.class), any(List.class)))
99                 .thenReturn(true);
100
101         eventCallback.activateCallback(data);
102
103         verify(mockArtifactDownloadManager).downloadArtifacts(any(INotificationData.class), any(List.class));
104         verify(mockArtifactDeploymentManager).deploy(any(String.class), any(List.class), any(List.class));
105     }
106 }