Single Project
And now we arrive at the end, a single concise project. Signed-off-by: Ben Hale <bhale@vmware.com>
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.cloud.bindings;
|
||||
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@DisplayName("Binding")
|
||||
final class BindingTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("populates content from filesystem")
|
||||
void test() {
|
||||
Binding binding = new Binding(Paths.get("src/test/resources/test-name-1"));
|
||||
|
||||
assertThat(binding.getKind()).isEqualTo("test-kind-1");
|
||||
assertThat(binding.getProvider()).isEqualTo("test-provider-1");
|
||||
assertThat(binding.getMetadataFilePath("test-key"))
|
||||
.isEqualTo(Paths.get("src/test/resources/test-name-1/metadata/test-key"));
|
||||
assertThat(binding.getSecretFilePath("test-key"))
|
||||
.isEqualTo(Paths.get("src/test/resources/test-name-1/secret/test-key"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Copyright 2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.bindings;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.context.config.ConfigFileApplicationListener;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
import org.springframework.core.env.SimpleCommandLinePropertySource;
|
||||
import org.springframework.mock.env.MockEnvironment;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.cloud.bindings.BindingsEnvironmentPostProcessor.BINDINGS_PROPERTY_SOURCE_NAME;
|
||||
|
||||
@DisplayName("Bindings EnvironmentPostProcessor")
|
||||
final class BindingsEnvironmentPostProcessorTest {
|
||||
|
||||
private final SpringApplication application = new SpringApplication();
|
||||
|
||||
private final MockEnvironment environment = new MockEnvironment();
|
||||
|
||||
@Test
|
||||
@DisplayName("does not create PropertySource if no bindings")
|
||||
void noBindings() {
|
||||
new BindingsEnvironmentPostProcessor(new Bindings()).postProcessEnvironment(environment, application);
|
||||
|
||||
assertThat(environment.getPropertySources()).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("does not create PropertySource if no properties")
|
||||
void noProperties() {
|
||||
new BindingsEnvironmentPostProcessor(
|
||||
new Bindings(
|
||||
new Binding("test-name", Paths.get("test-path"),
|
||||
Collections.emptyMap(), Collections.emptyMap())
|
||||
)
|
||||
).postProcessEnvironment(environment, application);
|
||||
|
||||
assertThat(environment.getPropertySources()).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("creates PropertySource with properties")
|
||||
void containsProperties() {
|
||||
new BindingsEnvironmentPostProcessor(
|
||||
new Bindings(
|
||||
new Binding("test-name", Paths.get("test-path"),
|
||||
Collections.emptyMap(), Collections.emptyMap())
|
||||
),
|
||||
(environment, properties) -> properties.put("test-key", "test-value")
|
||||
).postProcessEnvironment(environment, application);
|
||||
|
||||
assertThat(environment.getPropertySources()).hasSize(2);
|
||||
assertThat(environment.getProperty("test-key")).isEqualTo("test-value");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("adds PropertySource after CommandLinePropertySource")
|
||||
void withCommandLinePropertySource() {
|
||||
environment.getPropertySources().addFirst(new SimpleCommandLinePropertySource());
|
||||
|
||||
new BindingsEnvironmentPostProcessor(
|
||||
new Bindings(
|
||||
new Binding("test-name", Paths.get("test-path"),
|
||||
Collections.emptyMap(), Collections.emptyMap())
|
||||
),
|
||||
(environment, properties) -> properties.put("test-key", "test-value")
|
||||
).postProcessEnvironment(environment, application);
|
||||
|
||||
PropertySource<?> propertySource = environment.getPropertySources().get(BINDINGS_PROPERTY_SOURCE_NAME);
|
||||
assertThat(propertySource).isNotNull();
|
||||
assertThat(environment.getPropertySources().precedenceOf(propertySource)).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("adds PropertySource first")
|
||||
void withoutCommandLinePropertySource() {
|
||||
new BindingsEnvironmentPostProcessor(
|
||||
new Bindings(
|
||||
new Binding("test-name", Paths.get("test-path"),
|
||||
Collections.emptyMap(), Collections.emptyMap())
|
||||
),
|
||||
(environment, properties) -> properties.put("test-key", "test-value")
|
||||
).postProcessEnvironment(environment, application);
|
||||
|
||||
PropertySource<?> propertySource = environment.getPropertySources().get(BINDINGS_PROPERTY_SOURCE_NAME);
|
||||
assertThat(propertySource).isNotNull();
|
||||
assertThat(environment.getPropertySources().precedenceOf(propertySource)).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("has order before ConfigFileApplicationListener")
|
||||
void order() {
|
||||
assertThat(new BindingsEnvironmentPostProcessor(new Bindings()).getOrder())
|
||||
.isLessThan(ConfigFileApplicationListener.DEFAULT_ORDER);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("included implementations are registered")
|
||||
void includedImplementations() {
|
||||
assertThat(new BindingsEnvironmentPostProcessor().processors).hasSize(8);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright 2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.cloud.bindings;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
@DisplayName("Bindings")
|
||||
final class BindingsTests {
|
||||
|
||||
@Nested
|
||||
@DisplayName("Constructor")
|
||||
final class Constructor {
|
||||
|
||||
@Test
|
||||
@DisplayName("empty if path is null")
|
||||
void nullPath() {
|
||||
Bindings b = new Bindings((String) null);
|
||||
|
||||
assertThat(b.getBindings()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("empty if path does not exist")
|
||||
void nonExistentDirectory() {
|
||||
String path = "src/test/resources/non-existent";
|
||||
Bindings b = new Bindings(path);
|
||||
|
||||
assertThat(b.getBindings()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("throws exception if path is not a directory")
|
||||
void nonDirectory() throws IOException {
|
||||
String path = File.createTempFile("bindings", "").getPath();
|
||||
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new Bindings(path));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("populates content")
|
||||
void construct() {
|
||||
String path = "src/test/resources";
|
||||
Bindings b = new Bindings(path);
|
||||
|
||||
assertThat(b.getBindings()).hasSize(2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Nested
|
||||
@DisplayName("Content")
|
||||
final class Content {
|
||||
|
||||
private final Bindings bindings = new Bindings(
|
||||
new Binding("test-name-1", Paths.get("src/test/resources/test-name-1"),
|
||||
new FluentMap().withEntry("kind", "test-kind-1").withEntry("provider", "test-provider-1"),
|
||||
Collections.emptyMap()),
|
||||
new Binding("test-name-2", Paths.get("src/test/resources/test-name-2"),
|
||||
new FluentMap().withEntry("kind", "test-kind-2").withEntry("provider", "test-provider-2"),
|
||||
Collections.emptyMap())
|
||||
);
|
||||
|
||||
@Test
|
||||
@DisplayName("returns content")
|
||||
void getBindings() {
|
||||
assertThat(bindings.getBindings()).hasSize(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("filters bindings by kind")
|
||||
void filterBindingsByKind() {
|
||||
assertThat(bindings.filterBindings("test-kind-1", null)).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("filters bindings by provider")
|
||||
void filterBindingsByProvider() {
|
||||
assertThat(bindings.filterBindings(null, "test-provider-1")).hasSize(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.bindings;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.cloud.bindings.CassandraBindingsPropertiesProcessor.KIND;
|
||||
|
||||
@DisplayName("Cassandra BindingsPropertiesProcessor")
|
||||
final class CassandraBindingsPropertiesProcessorTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("contributes properties")
|
||||
void test() {
|
||||
HashMap<String, Object> properties = new HashMap<>();
|
||||
|
||||
new CassandraBindingsPropertiesProcessor().process(new Bindings(
|
||||
new Binding("test-name", Paths.get("test-path"),
|
||||
Collections.singletonMap("kind", KIND),
|
||||
new FluentMap()
|
||||
.withEntry("node_ips", "test-node-ips")
|
||||
.withEntry("password", "test-password")
|
||||
.withEntry("port", "test-port")
|
||||
.withEntry("username", "test-username")
|
||||
)
|
||||
), properties);
|
||||
|
||||
assertThat(properties)
|
||||
.containsEntry("spring.data.cassandra.contact-points", "test-node-ips")
|
||||
.containsEntry("spring.data.cassandra.password", "test-password")
|
||||
.containsEntry("spring.data.cassandra.port", "test-port")
|
||||
.containsEntry("spring.data.cassandra.username", "test-username");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.bindings;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.cloud.bindings.Db2BindingsPropertiesProcessor.KIND;
|
||||
|
||||
@DisplayName("DB2 BindingsPropertiesProcessor")
|
||||
final class Db2BindingsPropertiesProcessorTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("contributes properties")
|
||||
void test() {
|
||||
HashMap<String, Object> properties = new HashMap<>();
|
||||
|
||||
new Db2BindingsPropertiesProcessor().process(new Bindings(
|
||||
new Binding("test-name", Paths.get("test-path"),
|
||||
Collections.singletonMap("kind", KIND),
|
||||
new FluentMap()
|
||||
.withEntry("db", "test-db")
|
||||
.withEntry("host", "test-host")
|
||||
.withEntry("password", "test-password")
|
||||
.withEntry("port", "test-port")
|
||||
.withEntry("username", "test-username")
|
||||
)
|
||||
), properties);
|
||||
|
||||
assertThat(properties)
|
||||
.containsEntry("spring.datasource.driver-class-name", "com.ibm.db2.jcc.DB2Driver")
|
||||
.containsEntry("spring.datasource.password", "test-password")
|
||||
.containsEntry("spring.datasource.url",
|
||||
"jdbc:db2://test-host:test-port/test-db?user=test-username&password=test-password")
|
||||
.containsEntry("spring.datasource.username", "test-username");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.bindings;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
final class FluentMap extends HashMap<String, String> {
|
||||
|
||||
FluentMap withEntry(String key, String value) {
|
||||
put(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.bindings;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.cloud.bindings.MongoDbBindingsPropertiesProcessor.KIND;
|
||||
|
||||
@DisplayName("MongoDB BindingsPropertiesProcessor")
|
||||
final class MongoDbBindingsPropertiesProcessorTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("contributes properties")
|
||||
void test() {
|
||||
HashMap<String, Object> properties = new HashMap<>();
|
||||
|
||||
new MongoDbBindingsPropertiesProcessor().process(new Bindings(
|
||||
new Binding("test-name", Paths.get("test-path"),
|
||||
Collections.singletonMap("kind", KIND),
|
||||
new FluentMap()
|
||||
.withEntry("uri", "test-uri")
|
||||
)
|
||||
), properties);
|
||||
|
||||
assertThat(properties)
|
||||
.containsEntry("spring.mongodb.uri", "test-uri");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.bindings;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.cloud.bindings.MySqlBindingsPropertiesProcessor.KIND;
|
||||
|
||||
@DisplayName("MySQL BindingsPropertiesProcessor")
|
||||
final class MySqlBindingsPropertiesProcessorTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("contributes properties")
|
||||
void test() {
|
||||
HashMap<String, Object> properties = new HashMap<>();
|
||||
|
||||
new MySqlBindingsPropertiesProcessor().process(new Bindings(
|
||||
new Binding("test-name", Paths.get("test-path"),
|
||||
Collections.singletonMap("kind", KIND),
|
||||
new FluentMap()
|
||||
.withEntry("db", "test-db")
|
||||
.withEntry("host", "test-host")
|
||||
.withEntry("password", "test-password")
|
||||
.withEntry("port", "test-port")
|
||||
.withEntry("username", "test-username")
|
||||
)
|
||||
), properties);
|
||||
|
||||
assertThat(properties)
|
||||
.containsEntry("spring.datasource.driver-class-name", "org.mariadb.jdbc.Driver")
|
||||
.containsEntry("spring.datasource.password", "test-password")
|
||||
.containsEntry("spring.datasource.url", "jdbc:mysql://test-host:test-port/test-db?user=test-username&password=test-password")
|
||||
.containsEntry("spring.datasource.username", "test-username");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.bindings;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.cloud.bindings.OracleBindingsPropertiesProcessor.KIND;
|
||||
|
||||
@DisplayName("Oracle BindingsPropertiesProcessor")
|
||||
final class OracleBindingsPropertiesProcessorTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("contributes properties")
|
||||
void test() {
|
||||
HashMap<String, Object> properties = new HashMap<>();
|
||||
|
||||
new OracleBindingsPropertiesProcessor().process(new Bindings(
|
||||
new Binding("test-name", Paths.get("test-path"),
|
||||
Collections.singletonMap("kind", KIND),
|
||||
new FluentMap()
|
||||
.withEntry("db", "test-db")
|
||||
.withEntry("host", "test-host")
|
||||
.withEntry("password", "test-password")
|
||||
.withEntry("port", "test-port")
|
||||
.withEntry("username", "test-username")
|
||||
)
|
||||
), properties);
|
||||
|
||||
assertThat(properties)
|
||||
.containsEntry("spring.datasource.driver-class-name", "oracle.jdbc.OracleDriver")
|
||||
.containsEntry("spring.datasource.password", "test-password")
|
||||
.containsEntry("spring.datasource.url",
|
||||
"jdbc:oracle://test-host:test-port/test-db?user=test-username&password=test-password")
|
||||
.containsEntry("spring.datasource.username", "test-username");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.bindings;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.cloud.bindings.PostgreSqlBindingsPropertiesProcessor.KIND;
|
||||
|
||||
@DisplayName("PostgreSQL BindingsPropertiesProcessor")
|
||||
final class PostgreSqlBindingsPropertiesProcessorTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("contributes properties")
|
||||
void test() {
|
||||
HashMap<String, Object> properties = new HashMap<>();
|
||||
|
||||
new PostgreSqlBindingsPropertiesProcessor().process(new Bindings(
|
||||
new Binding("test-name", Paths.get("test-path"),
|
||||
Collections.singletonMap("kind", KIND),
|
||||
new FluentMap()
|
||||
.withEntry("db", "test-db")
|
||||
.withEntry("host", "test-host")
|
||||
.withEntry("password", "test-password")
|
||||
.withEntry("port", "test-port")
|
||||
.withEntry("username", "test-username")
|
||||
)
|
||||
), properties);
|
||||
|
||||
assertThat(properties)
|
||||
.containsEntry("spring.datasource.driver-class-name", "org.postgresql.Driver")
|
||||
.containsEntry("spring.datasource.password", "test-password")
|
||||
.containsEntry("spring.datasource.url",
|
||||
"jdbc:postgres://test-host:test-port/test-db?user=test-username&password=test-password")
|
||||
.containsEntry("spring.datasource.username", "test-username");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.bindings;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.cloud.bindings.RedisBindingsPropertiesProcessor.KIND;
|
||||
|
||||
@DisplayName("Redis BindingsPropertiesProcessor")
|
||||
final class RedisBindingsPropertiesProcessorTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("contributes properties")
|
||||
void test() {
|
||||
HashMap<String, Object> properties = new HashMap<>();
|
||||
|
||||
new RedisBindingsPropertiesProcessor().process(new Bindings(
|
||||
new Binding("test-name", Paths.get("test-path"),
|
||||
Collections.singletonMap("kind", KIND),
|
||||
new FluentMap()
|
||||
.withEntry("hostname", "test-hostname")
|
||||
.withEntry("password", "test-password")
|
||||
.withEntry("port", "test-port")
|
||||
)
|
||||
), properties);
|
||||
|
||||
assertThat(properties)
|
||||
.containsEntry("spring.redis.host", "test-hostname")
|
||||
.containsEntry("spring.redis.password", "test-password")
|
||||
.containsEntry("spring.redis.port", "test-port");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.bindings;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.cloud.bindings.SqlServerBindingsPropertiesProcessor.KIND;
|
||||
|
||||
@DisplayName("SQLServer BindingsPropertiesProcessor")
|
||||
final class SqlServerBindingsPropertiesProcessorTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("contributes properties")
|
||||
void test() {
|
||||
HashMap<String, Object> properties = new HashMap<>();
|
||||
|
||||
new SqlServerBindingsPropertiesProcessor().process(new Bindings(
|
||||
new Binding("test-name", Paths.get("test-path"),
|
||||
Collections.singletonMap("kind", KIND),
|
||||
new FluentMap()
|
||||
.withEntry("db", "test-db")
|
||||
.withEntry("host", "test-host")
|
||||
.withEntry("password", "test-password")
|
||||
.withEntry("port", "test-port")
|
||||
.withEntry("username", "test-username")
|
||||
)
|
||||
), properties);
|
||||
|
||||
assertThat(properties)
|
||||
.containsEntry("spring.datasource.driver-class-name", "com.microsoft.sqlserver.jdbc.SQLServerDriver")
|
||||
.containsEntry("spring.datasource.password", "test-password")
|
||||
.containsEntry("spring.datasource.url",
|
||||
"jdbc:sqlserver://test-host:test-port/test-db?user=test-username&password=test-password")
|
||||
.containsEntry("spring.datasource.username", "test-username");
|
||||
}
|
||||
|
||||
}
|
||||
1
src/test/resources/test-name-1/metadata/kind
Normal file
1
src/test/resources/test-name-1/metadata/kind
Normal file
@@ -0,0 +1 @@
|
||||
test-kind-1
|
||||
1
src/test/resources/test-name-1/metadata/provider
Normal file
1
src/test/resources/test-name-1/metadata/provider
Normal file
@@ -0,0 +1 @@
|
||||
test-provider-1
|
||||
1
src/test/resources/test-name-1/secret/test-key
Normal file
1
src/test/resources/test-name-1/secret/test-key
Normal file
@@ -0,0 +1 @@
|
||||
test-value
|
||||
1
src/test/resources/test-name-2/metadata/kind
Normal file
1
src/test/resources/test-name-2/metadata/kind
Normal file
@@ -0,0 +1 @@
|
||||
test-kind-2
|
||||
1
src/test/resources/test-name-2/metadata/provider
Normal file
1
src/test/resources/test-name-2/metadata/provider
Normal file
@@ -0,0 +1 @@
|
||||
test-provider-2
|
||||
1
src/test/resources/test-name-2/secret/test-key
Normal file
1
src/test/resources/test-name-2/secret/test-key
Normal file
@@ -0,0 +1 @@
|
||||
test-value
|
||||
Reference in New Issue
Block a user