Refactor babel-related code to not update parameter values
[aai/model-loader.git] / src / test / java / org / onap / aai / modelloader / notification / ArtifactDownloadManagerTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2024 Deutsche Telekom AG Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *       http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.aai.modelloader.notification;
21
22 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
23 import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
24 import static com.github.tomakehurst.wiremock.client.WireMock.get;
25 import static com.github.tomakehurst.wiremock.client.WireMock.matching;
26 import static com.github.tomakehurst.wiremock.client.WireMock.matchingJsonPath;
27 import static com.github.tomakehurst.wiremock.client.WireMock.post;
28 import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
29 import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
30 import static org.junit.jupiter.api.Assertions.assertEquals;
31 import static org.junit.jupiter.api.Assertions.assertTrue;
32
33 import java.util.ArrayList;
34 import java.util.List;
35
36 import org.apache.http.entity.ContentType;
37 import org.junit.jupiter.api.Test;
38 import org.onap.aai.modelloader.DistributionClientTestConfiguration;
39 import org.onap.aai.modelloader.entity.Artifact;
40 import org.onap.aai.modelloader.entity.ArtifactType;
41 import org.onap.aai.modelloader.service.ArtifactInfoImpl;
42 import org.onap.sdc.api.notification.IArtifactInfo;
43 import org.springframework.beans.factory.annotation.Autowired;
44 import org.springframework.boot.test.context.SpringBootTest;
45 import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock;
46 import org.springframework.context.annotation.Import;
47 import org.springframework.http.MediaType;
48 import org.springframework.kafka.test.context.EmbeddedKafka;
49 import org.springframework.test.annotation.DirtiesContext;
50
51 import com.fasterxml.jackson.core.JsonProcessingException;
52
53 @DirtiesContext
54 @AutoConfigureWireMock(port = 0)
55 @EmbeddedKafka(partitions = 1, ports = 9092, topics = {"${topics.distribution.notification}"})
56 @SpringBootTest(properties = { "ml.distribution.connection.enabled=true" })
57 @Import(DistributionClientTestConfiguration.class)
58 public class ArtifactDownloadManagerTest {
59
60   @Autowired ArtifactDownloadManager artifactDownloadManager;
61
62   @Test
63   public void downloadArtifacts() throws JsonProcessingException {
64     NotificationDataImpl notificationData = new NotificationDataImpl();
65     notificationData.setDistributionID("distributionID");
66     notificationData.setServiceVersion("2.0");
67
68     stubFor(get(urlEqualTo("/sdc/v1/catalog/services/DemovlbCds/1.0/artifacts/service-TestSvc-csar.csar"))
69         .withHeader("Accept", equalTo(ContentType.APPLICATION_OCTET_STREAM.toString()))
70         .withHeader("X-ECOMP-RequestID", matching(".+"))
71         .withHeader("X-ECOMP-InstanceID", equalTo("aai-ml-id-test"))
72         .willReturn(aResponse()
73           .withHeader("Content-Type", MediaType.APPLICATION_OCTET_STREAM.toString())
74           .withBodyFile("service-TestSvc-csar.csar")));
75     
76     stubFor(
77         post(urlEqualTo("/services/babel-service/v1/app/generateArtifacts"))
78             .withHeader("X-TransactionId", equalTo("distributionID"))
79             .withHeader("X-FromAppId", equalTo("ModelLoader"))
80             .withHeader("Content-Type", equalTo(MediaType.APPLICATION_JSON_VALUE))
81             .withRequestBody(matchingJsonPath("$.artifactName", equalTo("service-TestSvc-csar.csar")))
82             .withRequestBody(matchingJsonPath("$.artifactVersion", equalTo("2.0")))
83             .withRequestBody(matchingJsonPath("$.csar", matching(".*")))
84             .willReturn(
85                 aResponse()
86                     .withHeader("Content-Type", "application/json")
87                     .withBodyFile("service-TestSvc-csar-babel-response.json")));
88
89     ArtifactInfoImpl artifactInfo = new ArtifactInfoImpl();
90     artifactInfo.setArtifactName("service-TestSvc-csar.csar");
91     artifactInfo.setArtifactVersion("1.0");
92     artifactInfo.setArtifactURL("/sdc/v1/catalog/services/DemovlbCds/1.0/artifacts/service-TestSvc-csar.csar");
93     artifactInfo.setArtifactType("TOSCA_CSAR");
94     artifactInfo.setArtifactChecksum("ZmI5NzQ1MWViZGFkMjRjZWEwNTQzY2U0OWQwYjlmYjQ=");
95     artifactInfo.setArtifactUUID("f6f907f1-3f45-4fb4-8cbe-15a4c6ee16db");
96     List<IArtifactInfo> artifacts = new ArrayList<>();
97     artifacts.add(artifactInfo);
98     List<Artifact> modelArtifacts = new ArrayList<>(); // processed artifacts will be written to this list
99     List<Artifact> catalogArtifacts = new ArrayList<>(); // processed artifacts will be written to this list
100     boolean result = artifactDownloadManager.downloadArtifacts(notificationData, artifacts, modelArtifacts, catalogArtifacts);
101     
102     assertEquals(1, modelArtifacts.size());
103     assertEquals(ArtifactType.MODEL, modelArtifacts.get(0).getType());
104     assertTrue(result);
105   }
106
107 }