Release model-loader 1.13.6
[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.mock;
25 import static org.mockito.Mockito.verify;
26 import static org.mockito.Mockito.when;
27
28 import java.io.IOException;
29 import java.util.List;
30 import java.util.Properties;
31
32 import org.junit.After;
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.mockito.Mockito;
36 import org.onap.aai.modelloader.config.ModelLoaderConfig;
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 import org.springframework.test.util.ReflectionTestUtils;
43
44 /**
45  * Tests {@link EventCallback}.
46  */
47 public class TestEventCallback {
48
49     private static final String CONFIG_FILE = "model-loader.properties";
50
51     private ModelLoaderConfig config;
52     private Properties configProperties;
53     private EventCallback eventCallback;
54
55     private ArtifactDeploymentManager mockArtifactDeploymentManager;
56     private ArtifactDownloadManager mockArtifactDownloadManager;
57     private IDistributionClient mockDistributionClient;
58     private NotificationPublisher mockNotificationPublisher;
59
60     @Before
61     public void setup() throws IOException {
62         configProperties = new Properties();
63         configProperties.load(this.getClass().getClassLoader().getResourceAsStream(CONFIG_FILE));
64         config = new ModelLoaderConfig(configProperties, null);
65
66         mockArtifactDeploymentManager = mock(ArtifactDeploymentManager.class);
67         mockArtifactDownloadManager = mock(ArtifactDownloadManager.class);
68         mockDistributionClient = mock(IDistributionClient.class);
69         mockNotificationPublisher = mock(NotificationPublisher.class);
70
71         eventCallback = new EventCallback(mockDistributionClient, config, null);
72
73         ReflectionTestUtils.setField(eventCallback, "artifactDeploymentManager", mockArtifactDeploymentManager);
74         ReflectionTestUtils.setField(eventCallback, "artifactDownloadManager", mockArtifactDownloadManager);
75         ReflectionTestUtils.setField(eventCallback, "notificationPublisher", mockNotificationPublisher);
76     }
77
78     @After
79     public void tearDown() {
80         config = null;
81         configProperties = null;
82         eventCallback = null;
83         mockArtifactDeploymentManager = null;
84         mockArtifactDownloadManager = null;
85         mockDistributionClient = null;
86     }
87
88     @Test
89     @SuppressWarnings("unchecked")
90     public void activateCallback_downloadFails() {
91         INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile();
92
93         when(mockArtifactDownloadManager.downloadArtifacts(any(INotificationData.class), any(List.class),
94                 any(List.class), any(List.class))).thenReturn(false);
95
96         eventCallback.activateCallback(data);
97
98         verify(mockArtifactDownloadManager).downloadArtifacts(any(INotificationData.class), any(List.class),
99                 any(List.class), any(List.class));
100         Mockito.verifyNoInteractions(mockArtifactDeploymentManager);
101     }
102
103     @SuppressWarnings("unchecked")
104     @Test
105     public void activateCallback() throws BabelArtifactParsingException {
106         INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile();
107
108         when(mockArtifactDownloadManager.downloadArtifacts(any(INotificationData.class), any(List.class),
109                 any(List.class), any(List.class))).thenReturn(true);
110
111         when(mockArtifactDeploymentManager.deploy(any(INotificationData.class), any(List.class), any(List.class)))
112                 .thenReturn(true);
113
114         eventCallback.activateCallback(data);
115
116         verify(mockArtifactDownloadManager).downloadArtifacts(any(INotificationData.class), any(List.class),
117                 any(List.class), any(List.class));
118         verify(mockArtifactDeploymentManager).deploy(any(INotificationData.class), any(List.class), any(List.class));
119     }
120 }