2 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.aai.modelloader.notification;
23 import static org.mockito.ArgumentMatchers.any;
24 import static org.mockito.Mockito.verify;
25 import static org.mockito.Mockito.when;
27 import java.io.IOException;
28 import java.util.Collections;
29 import java.util.List;
30 import java.util.Properties;
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;
44 * Tests {@link EventCallback}.
46 public class TestEventCallback {
48 private static final String CONFIG_FILE = "model-loader.properties";
50 private Properties configProperties;
51 private EventCallback eventCallback;
53 @Mock private ArtifactDeploymentManager mockArtifactDeploymentManager;
54 @Mock private ArtifactDownloadManager mockArtifactDownloadManager;
55 @Mock private IDistributionClient mockDistributionClient;
56 @Mock private NotificationPublisher mockNotificationPublisher;
59 public void setup() throws IOException {
60 MockitoAnnotations.openMocks(this);
61 configProperties = new Properties();
62 configProperties.load(this.getClass().getClassLoader().getResourceAsStream(CONFIG_FILE));
64 eventCallback = new EventCallback(mockDistributionClient, mockArtifactDeploymentManager, mockArtifactDownloadManager, mockNotificationPublisher);
68 public void tearDown() {
69 configProperties = null;
71 mockArtifactDeploymentManager = null;
72 mockArtifactDownloadManager = null;
73 mockDistributionClient = null;
77 @SuppressWarnings("unchecked")
78 public void activateCallback_downloadFails() throws Exception {
79 INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile();
81 when(mockArtifactDownloadManager.downloadArtifacts(any(INotificationData.class), any(List.class)
82 )).thenThrow(DownloadFailureException.class);
84 eventCallback.activateCallback(data);
86 verify(mockArtifactDownloadManager).downloadArtifacts(any(INotificationData.class), any(List.class));
87 Mockito.verifyNoInteractions(mockArtifactDeploymentManager);
90 @SuppressWarnings("unchecked")
92 public void activateCallback() throws Exception {
93 INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile();
95 when(mockArtifactDownloadManager.downloadArtifacts(any(INotificationData.class), any(List.class)))
96 .thenReturn(Collections.emptyList());
98 when(mockArtifactDeploymentManager.deploy(any(String.class), any(List.class), any(List.class)))
101 eventCallback.activateCallback(data);
103 verify(mockArtifactDownloadManager).downloadArtifacts(any(INotificationData.class), any(List.class));
104 verify(mockArtifactDeploymentManager).deploy(any(String.class), any(List.class), any(List.class));