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.List;
29 import java.util.Properties;
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;
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() {
79 INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile();
81 when(mockArtifactDownloadManager.downloadArtifacts(any(INotificationData.class), any(List.class),
82 any(List.class), any(List.class))).thenReturn(false);
84 eventCallback.activateCallback(data);
86 verify(mockArtifactDownloadManager).downloadArtifacts(any(INotificationData.class), any(List.class),
87 any(List.class), any(List.class));
88 Mockito.verifyNoInteractions(mockArtifactDeploymentManager);
91 @SuppressWarnings("unchecked")
93 public void activateCallback() throws BabelArtifactParsingException {
94 INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile();
96 when(mockArtifactDownloadManager.downloadArtifacts(any(INotificationData.class), any(List.class),
97 any(List.class), any(List.class))).thenReturn(true);
99 when(mockArtifactDeploymentManager.deploy(any(String.class), any(List.class), any(List.class)))
102 eventCallback.activateCallback(data);
104 verify(mockArtifactDownloadManager).downloadArtifacts(any(INotificationData.class), any(List.class),
105 any(List.class), any(List.class));
106 verify(mockArtifactDeploymentManager).deploy(any(String.class), any(List.class), any(List.class));