- // This test requires a running Babel system. To test locally, annotate with org.junit.Test
- @Ignore
- public void testRestClient() throws Exception { // NOSONAR
- Properties configProperties = new Properties();
- try {
- configProperties.load(this.getClass().getClassLoader().getResourceAsStream(CONFIG_FILE));
- } catch (IOException e) {
- fail();
- }
- BabelServiceClient client = new BabelServiceClient(new ModelLoaderConfig(configProperties, "."));
- List<BabelArtifact> result =
- client.postArtifact(readBytesFromFile("compressedArtifacts/service-VscpaasTest-csar.csar"),
- "service-Vscpass-Test", "1.0", "Test-Transaction-ID-BabelClient");
+ @Autowired BabelServiceClient client;
+
+ @BeforeAll
+ public static void setup() throws JsonProcessingException {
+ ObjectMapper objectMapper = new ObjectMapper();
+ List<BabelArtifact> artifacts = List.of(
+ new BabelArtifact("art1", null, ""),
+ new BabelArtifact("art2", null, ""),
+ new BabelArtifact("art3", null, ""));
+ WireMock.stubFor(
+ 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")))
+ .withRequestBody(WireMock.matchingJsonPath("$.artifactVersion", WireMock.equalTo("1.0")))
+ .withRequestBody(WireMock.matchingJsonPath("$.csar", WireMock.matching(".*")))
+ .willReturn(
+ WireMock.aResponse()
+ .withHeader("Content-Type", "application/json")
+ .withBody(objectMapper.writeValueAsString(artifacts))));
+ }
+
+ @Test
+ public void testRestClient() throws BabelServiceClientException, IOException, URISyntaxException {
+ BabelRequest babelRequest = new BabelRequest();
+ babelRequest.setArtifactName("service-Vscpass-Test");
+ babelRequest.setCsar(Base64.getEncoder().encodeToString(readBytesFromFile("compressedArtifacts/service-VscpaasTest-csar.csar")));
+ babelRequest.setArtifactVersion("1.0");