Skip to content

Commit 7fa4a62

Browse files
committed
Add integration tests
1 parent 3ffb5b5 commit 7fa4a62

File tree

8 files changed

+253
-2
lines changed

8 files changed

+253
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* Copyright 2021 - 2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.sbm;
17+
18+
import org.junit.jupiter.api.*;
19+
import org.springframework.http.HttpStatus;
20+
import org.springframework.http.ResponseEntity;
21+
import org.springframework.web.client.RestTemplate;
22+
23+
import java.util.*;
24+
25+
import static org.assertj.core.api.Assertions.assertThat;
26+
27+
@TestMethodOrder(MethodOrderer.MethodName.class)
28+
//@Disabled("Temporary disabled before CI will be fixed with docker in docker issue: #351")
29+
class MigrateSimpleMuleAppDataweaveIntegrationTest extends IntegrationTestBaseClass {
30+
private final RestTemplate restTemplate = new RestTemplate();
31+
private static RunningNetworkedContainer tmDataweaveContainer;
32+
33+
@Override
34+
protected String getTestSubDir() {
35+
36+
return "mule-app/spring-dw-mule";
37+
38+
}
39+
40+
@BeforeAll
41+
public static void beforeAll() {
42+
IntegrationTestBaseClass.beforeAll();
43+
44+
// Will need to ensure this is set globally for the test
45+
System.setProperty("sbm.muleTriggerMeshTransformEnabled", "true");
46+
47+
// start TriggerMesh Dataweave Translator
48+
HashMap<String, String> envMap = new HashMap<>();
49+
envMap.put("NAMESPACE", "default");
50+
envMap.put("DATAWEAVETRANSFORMATION_ALLOW_SPELL_OVERRIDE", "true");
51+
52+
tmDataweaveContainer = startDockerContainer(
53+
new NetworkedContainer(
54+
"gcr.io/triggermesh/dataweavetransformation-adapter:v1.21.0",
55+
List.of(8080),
56+
"dwhost"),
57+
null,
58+
envMap);
59+
if (!tmDataweaveContainer.getContainer().isRunning()) {
60+
throw new RuntimeException("TriggerMesh Dataweave Transformer container could not be started");
61+
}
62+
}
63+
64+
@AfterAll
65+
public static void afterAll() {
66+
if (tmDataweaveContainer != null && tmDataweaveContainer.getContainer() != null) {
67+
tmDataweaveContainer.getContainer().stop();
68+
}
69+
}
70+
71+
@Test
72+
@Tag("integration")
73+
public void t2_dataweaveIntegrationWorks() {
74+
intializeTestProject();
75+
scanProject();
76+
applyRecipe("initialize-spring-boot-migration");
77+
applyRecipe("migrate-mule-to-triggermesh-boot");
78+
79+
executeMavenGoals(getTestDir(), "clean", "package", "spring-boot:build-image");
80+
81+
int dwPort = tmDataweaveContainer.getContainer().getMappedPort(8080);
82+
HashMap<String, String> runtimeEnv = new HashMap<>();
83+
runtimeEnv.put("K_SINK", "http://dwhost:8080");
84+
85+
RunningNetworkedContainer container = startDockerContainer(
86+
new NetworkedContainer("hellomuledw-migrated:1.0-SNAPSHOT", List.of(9081), "spring"),
87+
tmDataweaveContainer.getNetwork(),
88+
runtimeEnv);
89+
90+
checkSendHttpMessage(container.getContainer().getMappedPort(9081));
91+
checkTranslatedInboundGatewayHttpMessage(container.getContainer().getMappedPort(9081));
92+
}
93+
94+
private void checkTranslatedInboundGatewayHttpMessage(int port) {
95+
ResponseEntity<String> responseEntity = restTemplate.getForEntity("http://localhost:" + port + "/dwtest", String.class);
96+
97+
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
98+
assertThat(responseEntity.getBody()).isEqualTo("\n{\n \"greeting\": \"hello from SBM\"\n}");
99+
}
100+
101+
private void checkSendHttpMessage(int port) {
102+
ResponseEntity<String> responseEntity = restTemplate.getForEntity("http://localhost:" + port + "/test", String.class);
103+
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
104+
}
105+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
HELP.md
2+
target/
3+
!.mvn/wrapper/maven-wrapper.jar
4+
!**/src/main/**/target/
5+
!**/src/test/**/target/
6+
7+
### STS ###
8+
.apt_generated
9+
.classpath
10+
.factorypath
11+
.project
12+
.settings
13+
.springBeans
14+
.sts4-cache
15+
16+
### IntelliJ IDEA ###
17+
.idea
18+
*.iws
19+
*.iml
20+
*.ipr
21+
22+
### NetBeans ###
23+
/nbproject/private/
24+
/nbbuild/
25+
/dist/
26+
/nbdist/
27+
/.nb-gradle/
28+
build/
29+
!**/src/main/**/build/
30+
!**/src/test/**/build/
31+
32+
### VS Code ###
33+
.vscode/
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright 2021 - 2022 the original author or authors.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ https://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
18+
<project xmlns="http://maven.apache.org/POM/4.0.0"
19+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21+
<modelVersion>4.0.0</modelVersion>
22+
23+
<groupId>org.example</groupId>
24+
<artifactId>hellomuledw-migrated</artifactId>
25+
<version>1.0-SNAPSHOT</version>
26+
27+
<properties>
28+
<maven.compiler.source>11</maven.compiler.source>
29+
<maven.compiler.target>11</maven.compiler.target>
30+
</properties>
31+
32+
<dependencies>
33+
<dependency>
34+
<groupId>org.junit.jupiter</groupId>
35+
<artifactId>junit-jupiter-api</artifactId>
36+
<version>5.8.2</version>
37+
</dependency>
38+
</dependencies>
39+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.example.javadsl;
2+
3+
import org.springframework.context.annotation.Configuration;
4+
5+
@Configuration
6+
public class Foo {
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright 2021 - 2022 the original author or authors.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ https://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
<mule xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns="http://www.mulesoft.org/schema/mule/core"
18+
xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19+
xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw"
20+
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
21+
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http://www.mulesoft.org/schema/mule/ee/dw">
22+
<flow name="get:/dwtest:dwtest-config">
23+
<dw:transform-message doc:name="Transform Message">
24+
<dw:set-payload><![CDATA[%dw 2.0
25+
output application/json
26+
---
27+
greeting: "hello from SBM"
28+
]]>
29+
</dw:set-payload>
30+
</dw:transform-message>
31+
</flow>
32+
</mule>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!--
4+
~ Copyright 2021 - 2022 the original author or authors.
5+
~
6+
~ Licensed under the Apache License, Version 2.0 (the "License");
7+
~ you may not use this file except in compliance with the License.
8+
~ You may obtain a copy of the License at
9+
~
10+
~ https://www.apache.org/licenses/LICENSE-2.0
11+
~
12+
~ Unless required by applicable law or agreed to in writing, software
13+
~ distributed under the License is distributed on an "AS IS" BASIS,
14+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
~ See the License for the specific language governing permissions and
16+
~ limitations under the License.
17+
-->
18+
19+
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core"
20+
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
21+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
22+
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
23+
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
24+
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="9081" doc:name="HTTP Listener Configuration"/>
25+
<flow name="http-flow">
26+
<http:listener doc:name="Listener" doc:id="9f602d5c-5386-4fc9-ac8f-024d754c17e5" config-ref="HTTP_Listener_Configuration" path="/test"/>
27+
<logger level="INFO" doc:name="Logger" doc:id="4585ec7f-2d4a-4d86-af24-b678d4a99227" />
28+
</flow>
29+
</mule>

components/sbm-recipes-mule-to-boot/src/main/java/org/springframework/sbm/mule/actions/javadsl/translators/dwl/DwlTransformTranslator.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ public class DwlTransformTranslator implements MuleComponentToSpringIntegrationD
6868
private static final String triggermeshPayloadHandlerContent = "" +
6969
".handle((p, h) -> {\n" +
7070
" TmDwPayload dwPayload = new TmDwPayload();\n" +
71+
" String contentType = \"application/json\";\n" +
72+
" if (h.get(\"contentType\") != null) { contentType = h.get(\"contentType\").toString(); }\n" +
7173
" dwPayload.setId(h.getId().toString());\n" +
72-
" dwPayload.setSourceType(h.get(\"contentType\").toString());\n" +
74+
" dwPayload.setSourceType(contentType);\n" +
7375
" dwPayload.setSource(h.get(\"http_requestUrl\").toString());\n" +
7476
" dwPayload.setPayload(p.toString());\n" +
7577
" return dwPayload;\n" +

components/sbm-recipes-mule-to-boot/src/test/java/org/springframework/sbm/mule/actions/MuleToJavaDSLDwlTransformTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,12 @@ public void shouldTranslateDwlTransformationWithMuleTriggerMeshTransformAndSetPa
130130
" .log(LoggingHandler.Level.INFO, \"payload to be sent: #[new String(payload)]\")\n" +
131131
" .handle((p, h) -> {\n" +
132132
" TmDwPayload dwPayload = new TmDwPayload();\n" +
133+
" String contentType = \"application/json\";\n" +
134+
" if (h.get(\"contentType\") != null) {\n" +
135+
" contentType = h.get(\"contentType\").toString();\n" +
136+
" }\n" +
133137
" dwPayload.setId(h.getId().toString());\n" +
134-
" dwPayload.setSourceType(h.get(\"contentType\").toString());\n" +
138+
" dwPayload.setSourceType(contentType);\n" +
135139
" dwPayload.setSource(h.get(\"http_requestUrl\").toString());\n" +
136140
" dwPayload.setPayload(p.toString());\n" +
137141
" return dwPayload;\n" +

0 commit comments

Comments
 (0)