Upgrade spring-boot to 2.7.X in model-loader
[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.List;
29 import java.util.Properties;
30
31 import org.junit.jupiter.api.AfterEach;
32 import org.junit.jupiter.api.BeforeEach;
33 import org.junit.jupiter.api.Test;
34 import org.mockito.Mock;
35 import org.mockito.Mockito;
36 import org.mockito.MockitoAnnotations;
37 import org.onap.aai.modelloader.entity.model.BabelArtifactParsingException;
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() {
79         INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile();
80
81         when(mockArtifactDownloadManager.downloadArtifacts(any(INotificationData.class), any(List.class),
82                 any(List.class), any(List.class))).thenReturn(false);
83
84         eventCallback.activateCallback(data);
85
86         verify(mockArtifactDownloadManager).downloadArtifacts(any(INotificationData.class), any(List.class),
87                 any(List.class), any(List.class));
88         Mockito.verifyNoInteractions(mockArtifactDeploymentManager);
89     }
90
91     @SuppressWarnings("unchecked")
92     @Test
93     public void activateCallback() throws BabelArtifactParsingException {
94         INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile();
95
96         when(mockArtifactDownloadManager.downloadArtifacts(any(INotificationData.class), any(List.class),
97                 any(List.class), any(List.class))).thenReturn(true);
98
99         when(mockArtifactDeploymentManager.deploy(any(INotificationData.class), any(List.class), any(List.class)))
100                 .thenReturn(true);
101
102         eventCallback.activateCallback(data);
103
104         verify(mockArtifactDownloadManager).downloadArtifacts(any(INotificationData.class), any(List.class),
105                 any(List.class), any(List.class));
106         verify(mockArtifactDeploymentManager).deploy(any(INotificationData.class), any(List.class), any(List.class));
107     }
108 }