Skip to content

Commit 22d6c95

Browse files
sanagaraj-pivotalBoykoAlex
authored andcommitted
Mule Mysql connector support
1 parent 195be17 commit 22d6c95

File tree

5 files changed

+141
-3
lines changed

5 files changed

+141
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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.mule.actions.javadsl.translators.db;
17+
18+
import org.mulesoft.schema.mule.db.MySqlDatabaseConfigType;
19+
import org.mulesoft.schema.mule.db.OracleDatabaseConfigType;
20+
import org.springframework.sbm.build.api.Dependency;
21+
import org.springframework.sbm.mule.api.toplevel.configuration.ConfigurationTypeAdapter;
22+
import org.springframework.stereotype.Component;
23+
24+
import java.util.AbstractMap;
25+
import java.util.ArrayList;
26+
import java.util.List;
27+
28+
@Component
29+
public class MysqlConfigAdapter extends ConfigurationTypeAdapter<MySqlDatabaseConfigType> {
30+
@Override
31+
public String getName() {
32+
return getMuleConfiguration().getName();
33+
}
34+
35+
@Override
36+
public Class getMuleConfigurationType() {
37+
return MySqlDatabaseConfigType.class;
38+
}
39+
40+
@Override
41+
public List<AbstractMap.SimpleEntry<String, String>> configProperties() {
42+
List<AbstractMap.SimpleEntry<String, String>> properties = new ArrayList<>();
43+
properties.add(new AbstractMap.SimpleEntry<>("spring.datasource.url", "--INSERT--DB-URL-HERE-Example:--INSERT--DB-URL-HERE-Example:jdbc:mysql://localhost:3306/sonoo"));
44+
properties.add(new AbstractMap.SimpleEntry<>("spring.datasource.username", "--INSERT-USER-NAME--"));
45+
properties.add(new AbstractMap.SimpleEntry<>("spring.datasource.password", "--INSERT-PASSWORD--"));
46+
properties.add(new AbstractMap.SimpleEntry<>("spring.datasource.driverClassName", "com.mysql.cj.jdbc.Driver"));
47+
properties.add(new AbstractMap.SimpleEntry<>("spring.jpa.show-sql", "true"));
48+
return properties;
49+
}
50+
51+
@Override
52+
public List<Dependency> getDependencies() {
53+
54+
return List.of(Dependency.builder()
55+
.groupId("mysql")
56+
.artifactId("mysql-connector-java")
57+
.version("8.0.29")
58+
.build());
59+
}
60+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
public class HttpListenerTranslator implements MuleComponentToSpringIntegrationDslTranslator<ListenerType> {
3838

3939
private final static String javaDslHttpListenerTemplate =
40-
"return IntegrationFlows.from(Http.inboundChannelAdapter(\"${path}\")).handle((p, h) -> p)";
40+
"return IntegrationFlows.from(Http.inboundGateway(\"${path}\")).handle((p, h) -> p)";
4141

4242
@Override
4343
public Class<ListenerType> getSupportedMuleType() {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.springframework.sbm.mule.actions.javadsl.translators.common.ExpressionLanguageTranslator;
2727
import org.springframework.sbm.mule.actions.javadsl.translators.core.*;
2828
import org.springframework.sbm.mule.actions.javadsl.translators.db.InsertTranslator;
29+
import org.springframework.sbm.mule.actions.javadsl.translators.db.MysqlConfigAdapter;
2930
import org.springframework.sbm.mule.actions.javadsl.translators.db.OracleConfigAdapter;
3031
import org.springframework.sbm.mule.actions.javadsl.translators.db.SelectTranslator;
3132
import org.springframework.sbm.mule.actions.javadsl.translators.dwl.DwlTransformTranslator;
@@ -98,7 +99,8 @@ public void setup() {
9899
new HttpListenerConfigTypeAdapter(),
99100
new WmqConnectorTypeAdapter(),
100101
new RequestConfigTypeAdapter(),
101-
new OracleConfigAdapter()
102+
new OracleConfigAdapter(),
103+
new MysqlConfigAdapter()
102104
)
103105
);
104106
MuleMigrationContextFactory muleMigrationContextFactory = new MuleMigrationContextFactory(new MuleConfigurationsExtractor(configurationTypeAdapterFactory));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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.mule.actions.db;
17+
18+
import org.junit.jupiter.api.Test;
19+
import org.springframework.sbm.mule.actions.JavaDSLActionBaseTest;
20+
21+
22+
import java.util.Set;
23+
import java.util.stream.Collectors;
24+
25+
import static org.assertj.core.api.Assertions.assertThat;
26+
27+
28+
public class MuleToJavaDSLMysqlDBConfigTest extends JavaDSLActionBaseTest {
29+
30+
private final String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
31+
"<mule xmlns:scripting=\"http://www.mulesoft.org/schema/mule/scripting\"\n" +
32+
"\txmlns=\"http://www.mulesoft.org/schema/mule/core\" xmlns:api-platform-gw=\"http://www.mulesoft.org/schema/mule/api-platform-gw\" xmlns:apikit=\"http://www.mulesoft.org/schema/mule/apikit\" xmlns:cmis=\"http://www.mulesoft.org/schema/mule/cmis\" xmlns:context=\"http://www.springframework.org/schema/context\" xmlns:db=\"http://www.mulesoft.org/schema/mule/db\" xmlns:doc=\"http://www.mulesoft.org/schema/mule/documentation\" xmlns:dw=\"http://www.mulesoft.org/schema/mule/ee/dw\" xmlns:ee=\"http://www.mulesoft.org/schema/mule/ee/core\" xmlns:http=\"http://www.mulesoft.org/schema/mule/http\" xmlns:spring=\"http://www.springframework.org/schema/beans\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd\n" +
33+
"http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-current.xsd\n" +
34+
"http://www.mulesoft.org/schema/mule/api-platform-gw http://www.mulesoft.org/schema/mule/api-platform-gw/current/mule-api-platform-gw.xsd\n" +
35+
"http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd\n" +
36+
"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd\n" +
37+
"http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd\n" +
38+
"http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd\n" +
39+
"http://www.mulesoft.org/schema/mule/apikit http://www.mulesoft.org/schema/mule/apikit/current/mule-apikit.xsd\n" +
40+
"http://www.mulesoft.org/schema/mule/cmis http://www.mulesoft.org/schema/mule/cmis/current/mule-cmis.xsd\n" +
41+
"http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd\n" +
42+
"http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd\">\n" +
43+
" <db:mysql-config name=\"MySQL_Configuration\" host=\"localhost\" port=\"3306\" user=\"root\" password=\"pw\" database=\"mule\" doc:name=\"MySQL Configuration\"/>\n" +
44+
" <http:listener-config name=\"http-lc-0.0.0.0-8081\" host=\"0.0.0.0\" port=\"8080\" protocol=\"HTTP\"/>\n" +
45+
"</mule>";
46+
47+
48+
@Test
49+
public void fillApplicationPropertiesForDBConnection() {
50+
addXMLFileToResource(xml);
51+
runAction();
52+
assertThat(getApplicationPropertyContent()).isEqualTo("server.port=8080\n" +
53+
"spring.datasource.url=--INSERT--DB-URL-HERE-Example:--INSERT--DB-URL-HERE-Example:jdbc:mysql://localhost:3306/sonoo\n" +
54+
"spring.datasource.username=--INSERT-USER-NAME--\n" +
55+
"spring.datasource.password=--INSERT-PASSWORD--\n" +
56+
"spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver\n" +
57+
"spring.jpa.show-sql=true"
58+
);
59+
}
60+
61+
62+
63+
@Test
64+
public void importsOracleDrivers() {
65+
addXMLFileToResource(xml);
66+
runAction();
67+
68+
Set<String> declaredDependencies = projectContext
69+
.getBuildFile().getDeclaredDependencies()
70+
.stream()
71+
.map(dependency -> dependency.getGroupId() + ":" + dependency.getArtifactId() + ":" + dependency.getVersion())
72+
.collect(Collectors.toSet());
73+
74+
assertThat(declaredDependencies).contains("mysql:mysql-connector-java:8.0.29");
75+
}
76+
}

components/sbm-recipes-mule-to-boot/src/test/java/org/springframework/sbm/mule/actions/javadsl/translators/http/HttpListenerTranslatorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void httpTranslator() {
6262
.build();
6363

6464
DslSnippet snippet = apply(projectContext);
65-
assertThat(snippet.getRenderedSnippet()).isEqualTo("return IntegrationFlows.from(Http.inboundChannelAdapter(\"/test\")).handle((p, h) -> p)");
65+
assertThat(snippet.getRenderedSnippet()).isEqualTo("return IntegrationFlows.from(Http.inboundGateway(\"/test\")).handle((p, h) -> p)");
6666
}
6767

6868

0 commit comments

Comments
 (0)