sdc-distribution-client is registered twice in model-loader
[aai/model-loader.git] / src / test / java / org / onap / aai / modelloader / service / TestModelController.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.service;
22
23 import static org.hamcrest.CoreMatchers.is;
24 import static org.hamcrest.MatcherAssert.assertThat;
25 import static org.mockito.ArgumentMatchers.any;
26 import static org.mockito.Mockito.when;
27
28 import java.io.IOException;
29 import java.util.Base64;
30 import java.util.Collections;
31
32 import javax.ws.rs.core.Response;
33
34 import org.junit.jupiter.api.BeforeEach;
35 import org.junit.jupiter.api.Test;
36 import org.mockito.Mock;
37 import org.onap.aai.modelloader.config.ModelLoaderConfig;
38 import org.onap.aai.modelloader.extraction.VnfCatalogExtractor;
39 import org.onap.aai.modelloader.notification.ArtifactDownloadManager;
40 import org.onap.aai.modelloader.notification.BabelArtifactConverter;
41 import org.onap.aai.modelloader.notification.NotificationPublisher;
42 import org.onap.aai.modelloader.restclient.BabelServiceClient;
43 import org.onap.aai.modelloader.restclient.BabelServiceClientException;
44 import org.onap.aai.modelloader.util.ArtifactTestUtils;
45 import org.onap.sdc.api.IDistributionClient;
46 import org.springframework.beans.factory.annotation.Autowired;
47 import org.springframework.boot.test.context.SpringBootTest;
48 import org.springframework.test.context.TestPropertySource;
49
50 /**
51  * Tests for the ModelLoaderService class.
52  *
53  */
54 @SpringBootTest
55 @TestPropertySource(properties = {"CONFIG_HOME=src/test/resources",})
56 public class TestModelController {
57
58     @Autowired IDistributionClient iDistributionClient;
59     @Autowired ModelLoaderConfig modelLoaderConfig;
60     @Autowired ArtifactDeploymentManager artifactDeploymentManager;
61     @Autowired BabelArtifactConverter babelArtifactConverter;
62     @Autowired NotificationPublisher notificationPublisher;
63     @Autowired VnfCatalogExtractor vnfCatalogExtractor;
64
65     @Mock BabelServiceClientFactory clientFactory;
66     @Mock BabelServiceClient babelServiceClient;
67     
68     private ModelController modelController;
69
70     @BeforeEach
71     public void init() throws BabelServiceClientException {
72         when(clientFactory.create(any())).thenReturn(babelServiceClient);
73         when(babelServiceClient.postArtifact(any(), any(), any(), any())).thenReturn(Collections.emptyList());
74         ArtifactDownloadManager artifactDownloadManager = new ArtifactDownloadManager(iDistributionClient, modelLoaderConfig, clientFactory, babelArtifactConverter, notificationPublisher, vnfCatalogExtractor);
75         this.modelController = new ModelController(iDistributionClient, modelLoaderConfig, artifactDeploymentManager, artifactDownloadManager);
76     }
77
78     @Test
79     public void testLoadModel() {
80         Response response = modelController.loadModel("");
81         assertThat(response.getStatus(), is(Response.Status.OK.getStatusCode()));
82     }
83
84     @Test
85     public void testSaveModel() {
86         Response response = modelController.saveModel("", "");
87         assertThat(response.getStatus(), is(Response.Status.OK.getStatusCode()));
88     }
89
90     @Test
91     public void testIngestModel() throws IOException {
92         byte[] csarPayload = new ArtifactTestUtils().loadResource("compressedArtifacts/service-VscpaasTest-csar.csar");
93         Response response = modelController.ingestModel("model-name", "", Base64.getEncoder().encodeToString(csarPayload));
94         assertThat(response.getStatus(), is(Response.Status.OK.getStatusCode()));
95     }
96
97     @Test
98     public void testIngestModelMissingName() throws IOException {
99         byte[] csarPayload = new ArtifactTestUtils().loadResource("compressedArtifacts/service-VscpaasTest-csar.csar");
100         Response response = modelController.ingestModel("", "", Base64.getEncoder().encodeToString(csarPayload));
101         assertThat(response.getStatus(), is(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()));
102     }
103
104 }