aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/org/onap/aai/modelloader/restclient/TestBabelServiceClient.java
diff options
context:
space:
mode:
authorFiete Ostkamp <Fiete.Ostkamp@telekom.de>2024-04-17 16:06:40 +0200
committerFiete Ostkamp <fiete.ostkamp@telekom.de>2024-04-18 08:57:40 +0000
commit0e9a90774a86475f40d4e946798cf765910a31f6 (patch)
treed502db5ea90f7a625bf0df98ff62052f66b5b99d /src/test/java/org/onap/aai/modelloader/restclient/TestBabelServiceClient.java
parentf265fce93af9ccb200162fbeaa0705b418397851 (diff)
Refactor Babel related code in model-loader
- introduce BabelArtifactService - simplify babel http client by removing factory and https support Issue-ID: AAI-3827 Change-Id: I5c004d342687c8aaa8f26927342752d472f05da3 Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de>
Diffstat (limited to 'src/test/java/org/onap/aai/modelloader/restclient/TestBabelServiceClient.java')
-rw-r--r--src/test/java/org/onap/aai/modelloader/restclient/TestBabelServiceClient.java52
1 files changed, 16 insertions, 36 deletions
diff --git a/src/test/java/org/onap/aai/modelloader/restclient/TestBabelServiceClient.java b/src/test/java/org/onap/aai/modelloader/restclient/TestBabelServiceClient.java
index 169943c..d82bff0 100644
--- a/src/test/java/org/onap/aai/modelloader/restclient/TestBabelServiceClient.java
+++ b/src/test/java/org/onap/aai/modelloader/restclient/TestBabelServiceClient.java
@@ -28,34 +28,40 @@ import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Paths;
+import java.util.Base64;
import java.util.List;
-import java.util.Properties;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.onap.aai.babel.service.data.BabelArtifact;
-import org.onap.aai.modelloader.config.ModelLoaderConfig;
-import org.onap.aai.modelloader.service.HttpsBabelServiceClientFactory;
+import org.onap.aai.babel.service.data.BabelRequest;
+import org.onap.aai.modelloader.BabelClientTestConfiguration;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock;
+import org.springframework.context.annotation.Import;
+import org.springframework.test.annotation.DirtiesContext;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.tomakehurst.wiremock.client.WireMock;
-import com.github.tomakehurst.wiremock.matching.EqualToPattern;
/**
* Local testing of the Babel service client.
*
*/
@SpringBootTest
+@DirtiesContext
@AutoConfigureWireMock(port = 0)
+@Import(BabelClientTestConfiguration.class)
public class TestBabelServiceClient {
@Value("${wiremock.server.port}")
private int wiremockPort;
+ @Autowired BabelServiceClient client;
+
@BeforeAll
public static void setup() throws JsonProcessingException {
ObjectMapper objectMapper = new ObjectMapper();
@@ -64,7 +70,7 @@ public class TestBabelServiceClient {
new BabelArtifact("art2", null, ""),
new BabelArtifact("art3", null, ""));
WireMock.stubFor(
- WireMock.post(WireMock.urlEqualTo("/generate"))
+ WireMock.post(WireMock.urlEqualTo("/services/babel-service/v1/app/generateArtifacts"))
.withHeader("X-TransactionId", WireMock.equalTo("Test-Transaction-ID-BabelClient"))
.withHeader("X-FromAppId", WireMock.equalTo("ModelLoader"))
.withRequestBody(WireMock.matchingJsonPath("$.artifactName", WireMock.equalTo("service-Vscpass-Test")))
@@ -78,39 +84,13 @@ public class TestBabelServiceClient {
@Test
public void testRestClient() throws BabelServiceClientException, IOException, URISyntaxException {
- String url = "http://localhost:" + wiremockPort;
- Properties configProperties = new Properties();
- configProperties.put("ml.babel.KEYSTORE_PASSWORD", "OBF:1vn21ugu1saj1v9i1v941sar1ugw1vo0");
- configProperties.put("ml.babel.KEYSTORE_FILE", "src/test/resources/auth/aai-client-dummy.p12");
- configProperties.put("ml.babel.TRUSTSTORE_PASSWORD", "OBF:1vn21ugu1saj1v9i1v941sar1ugw1vo0");
- // In a real deployment this would be a different file (to the client keystore)
- configProperties.put("ml.babel.TRUSTSTORE_FILE", "src/test/resources/auth/aai-client-dummy.p12");
- configProperties.put("ml.babel.BASE_URL", url);
- configProperties.put("ml.babel.GENERATE_ARTIFACTS_URL", "/generate");
- configProperties.put("ml.aai.RESTCLIENT_CONNECT_TIMEOUT", "12000");
- configProperties.put("ml.aai.RESTCLIENT_READ_TIMEOUT", "12000");
- BabelServiceClient client =
- new HttpsBabelServiceClientFactory().create(new ModelLoaderConfig(configProperties, "."));
- List<BabelArtifact> result =
- client.postArtifact(readBytesFromFile("compressedArtifacts/service-VscpaasTest-csar.csar"),
- "service-Vscpass-Test", "1.0", "Test-Transaction-ID-BabelClient");
- assertThat(result.size(), is(equalTo(3)));
- }
+ BabelRequest babelRequest = new BabelRequest();
+ babelRequest.setArtifactName("service-Vscpass-Test");
+ babelRequest.setCsar(Base64.getEncoder().encodeToString(readBytesFromFile("compressedArtifacts/service-VscpaasTest-csar.csar")));
+ babelRequest.setArtifactVersion("1.0");
- @Test
- public void testRestClientHttp() throws BabelServiceClientException, IOException, URISyntaxException {
- String url = "http://localhost:" + wiremockPort;
- Properties configProperties = new Properties();
- configProperties.put("ml.babel.USE_HTTPS", "false");
- configProperties.put("ml.babel.BASE_URL", url);
- configProperties.put("ml.babel.GENERATE_ARTIFACTS_URL", "/generate");
- configProperties.put("ml.aai.RESTCLIENT_CONNECT_TIMEOUT", "3000");
- configProperties.put("ml.aai.RESTCLIENT_READ_TIMEOUT", "3000");
- BabelServiceClient client =
- new HttpsBabelServiceClientFactory().create(new ModelLoaderConfig(configProperties, "."));
List<BabelArtifact> result =
- client.postArtifact(readBytesFromFile("compressedArtifacts/service-VscpaasTest-csar.csar"),
- "service-Vscpass-Test", "1.0", "Test-Transaction-ID-BabelClient");
+ client.postArtifact(babelRequest, "Test-Transaction-ID-BabelClient");
assertThat(result.size(), is(equalTo(3)));
}