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.service;
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.mock;
27 import static org.mockito.Mockito.when;
29 import java.io.IOException;
30 import java.util.Base64;
31 import java.util.Collections;
33 import javax.ws.rs.core.Response;
35 import org.junit.jupiter.api.AfterEach;
36 import org.junit.jupiter.api.BeforeEach;
37 import org.junit.jupiter.api.Test;
38 import org.mockito.Mock;
39 import org.onap.aai.modelloader.config.ModelLoaderConfig;
40 import org.onap.aai.modelloader.extraction.VnfCatalogExtractor;
41 import org.onap.aai.modelloader.notification.ArtifactDownloadManager;
42 import org.onap.aai.modelloader.notification.BabelArtifactConverter;
43 import org.onap.aai.modelloader.notification.EventCallback;
44 import org.onap.aai.modelloader.notification.NotificationPublisher;
45 import org.onap.aai.modelloader.restclient.BabelServiceClient;
46 import org.onap.aai.modelloader.restclient.BabelServiceClientException;
47 import org.onap.aai.modelloader.util.ArtifactTestUtils;
48 import org.onap.sdc.api.IDistributionClient;
49 import org.springframework.beans.factory.annotation.Autowired;
50 import org.springframework.boot.test.context.SpringBootTest;
51 import org.springframework.test.context.TestPropertySource;
54 * Tests for the ModelLoaderService class.
58 @TestPropertySource(properties = {"CONFIG_HOME=src/test/resources",})
59 public class TestModelController {
61 @Autowired IDistributionClient iDistributionClient;
62 @Autowired ModelLoaderConfig modelLoaderConfig;
63 @Autowired EventCallback eventCallback;
64 @Autowired ArtifactDeploymentManager artifactDeploymentManager;
65 @Autowired BabelArtifactConverter babelArtifactConverter;
66 @Autowired NotificationPublisher notificationPublisher;
67 @Autowired VnfCatalogExtractor vnfCatalogExtractor;
69 @Mock BabelServiceClientFactory clientFactory;
70 @Mock BabelServiceClient babelServiceClient;
72 private ModelController modelController;
75 public void init() throws BabelServiceClientException {
76 when(clientFactory.create(any())).thenReturn(babelServiceClient);
77 when(babelServiceClient.postArtifact(any(), any(), any(), any())).thenReturn(Collections.emptyList());
78 ArtifactDownloadManager artifactDownloadManager = new ArtifactDownloadManager(iDistributionClient, modelLoaderConfig, clientFactory, babelArtifactConverter, notificationPublisher, vnfCatalogExtractor);
79 this.modelController = new ModelController(iDistributionClient, modelLoaderConfig, eventCallback, artifactDeploymentManager, artifactDownloadManager);
83 public void shutdown() {
84 modelController.preShutdownOperations();
88 public void testLoadModel() {
89 Response response = modelController.loadModel("");
90 assertThat(response.getStatus(), is(Response.Status.OK.getStatusCode()));
94 public void testSaveModel() {
95 Response response = modelController.saveModel("", "");
96 assertThat(response.getStatus(), is(Response.Status.OK.getStatusCode()));
100 public void testIngestModel() throws IOException {
101 byte[] csarPayload = new ArtifactTestUtils().loadResource("compressedArtifacts/service-VscpaasTest-csar.csar");
102 Response response = modelController.ingestModel("model-name", "", Base64.getEncoder().encodeToString(csarPayload));
103 assertThat(response.getStatus(), is(Response.Status.OK.getStatusCode()));
107 public void testIngestModelMissingName() throws IOException {
108 byte[] csarPayload = new ArtifactTestUtils().loadResource("compressedArtifacts/service-VscpaasTest-csar.csar");
109 Response response = modelController.ingestModel("", "", Base64.getEncoder().encodeToString(csarPayload));
110 assertThat(response.getStatus(), is(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()));