|
| 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 | +} |
0 commit comments