2 * ============LICENSE_START==========================================
\r
4 * ===================================================================
\r
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
\r
6 * Copyright © 2017-2018 Amdocs
\r
7 * ===================================================================
\r
8 * Licensed under the Apache License, Version 2.0 (the "License");
\r
9 * you may not use this file except in compliance with the License.
\r
10 * You may obtain a copy of the License at
\r
12 * http://www.apache.org/licenses/LICENSE-2.0
\r
14 * Unless required by applicable law or agreed to in writing, software
\r
15 * distributed under the License is distributed on an "AS IS" BASIS,
\r
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
17 * See the License for the specific language governing permissions and
\r
18 * limitations under the License.
\r
19 * ============LICENSE_END============================================
\r
21 package org.onap.aai.modelloader.notification;
\r
23 import static org.mockito.Matchers.any;
\r
24 import static org.mockito.Mockito.mock;
\r
25 import static org.mockito.Mockito.verify;
\r
26 import static org.mockito.Mockito.when;
\r
28 import java.io.IOException;
\r
29 import java.util.List;
\r
30 import java.util.Properties;
\r
31 import org.junit.After;
\r
32 import org.junit.Before;
\r
33 import org.junit.Test;
\r
34 import org.mockito.Mockito;
\r
35 import org.mockito.internal.util.reflection.Whitebox;
\r
36 import org.onap.aai.modelloader.config.ModelLoaderConfig;
\r
37 import org.onap.aai.modelloader.entity.model.BabelArtifactParsingException;
\r
38 import org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder;
\r
39 import org.openecomp.sdc.api.IDistributionClient;
\r
40 import org.openecomp.sdc.api.notification.INotificationData;
\r
43 * Tests {@link EventCallback}
\r
45 public class EventCallbackTest {
\r
47 private static final String CONFIG_FILE = "model-loader.properties";
\r
49 private ModelLoaderConfig config;
\r
50 private Properties configProperties;
\r
51 private EventCallback eventCallback;
\r
53 private ArtifactDeploymentManager mockArtifactDeploymentManager;
\r
54 private ArtifactDownloadManager mockArtifactDownloadManager;
\r
55 private IDistributionClient mockDistributionClient;
\r
58 public void setup() throws IOException {
\r
59 configProperties = new Properties();
\r
60 configProperties.load(this.getClass().getClassLoader().getResourceAsStream(CONFIG_FILE));
\r
61 config = new ModelLoaderConfig(configProperties, null);
\r
63 mockArtifactDeploymentManager = mock(ArtifactDeploymentManager.class);
\r
64 mockArtifactDownloadManager = mock(ArtifactDownloadManager.class);
\r
65 mockDistributionClient = mock(IDistributionClient.class);
\r
67 eventCallback = new EventCallback(mockDistributionClient, config);
\r
69 Whitebox.setInternalState(eventCallback, "artifactDeploymentManager", mockArtifactDeploymentManager);
\r
70 Whitebox.setInternalState(eventCallback, "artifactDownloadManager", mockArtifactDownloadManager);
\r
74 public void tearDown() {
\r
76 configProperties = null;
\r
77 eventCallback = null;
\r
78 mockArtifactDeploymentManager = null;
\r
79 mockArtifactDownloadManager = null;
\r
80 mockDistributionClient = null;
\r
84 @SuppressWarnings("unchecked")
\r
85 public void activateCallback_downloadFails() {
\r
86 INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile();
\r
88 when(mockArtifactDownloadManager.downloadArtifacts(any(INotificationData.class), any(List.class),
\r
89 any(List.class), any(List.class))).thenReturn(false);
\r
91 eventCallback.activateCallback(data);
\r
93 verify(mockArtifactDownloadManager).downloadArtifacts(any(INotificationData.class), any(List.class),
\r
94 any(List.class), any(List.class));
\r
95 Mockito.verifyZeroInteractions(mockArtifactDeploymentManager);
\r
98 @SuppressWarnings("unchecked")
\r
100 public void activateCallback() throws BabelArtifactParsingException {
\r
101 INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile();
\r
103 when(mockArtifactDownloadManager.downloadArtifacts(any(INotificationData.class), any(List.class),
\r
104 any(List.class), any(List.class))).thenReturn(true);
\r
106 when(mockArtifactDeploymentManager.deploy(any(INotificationData.class), any(List.class), any(List.class),
\r
107 any(List.class))).thenReturn(true);
\r
109 eventCallback.activateCallback(data);
\r
111 verify(mockArtifactDownloadManager).downloadArtifacts(any(INotificationData.class), any(List.class),
\r
112 any(List.class), any(List.class));
\r
113 verify(mockArtifactDeploymentManager).deploy(any(INotificationData.class), any(List.class), any(List.class),
\r