Merge branch '20-neo4j'

Signed-off-by: Ben Hale <bhale@vmware.com>
This commit is contained in:
Ben Hale
2020-05-11 16:57:25 -07:00
5 changed files with 133 additions and 1 deletions

View File

@@ -117,6 +117,16 @@ Disable Property: `org.springframework.cloud.bindings.boot.mysql.enable`
| `spring.datasource.url` | `jdbc:mysql://{host}:{port}/{database}`
| `spring.datasource.username` | `{username}`
### Neo4J
Kind: `Neo4J`
Disable Property: `org.springframework.cloud.bindings.boot.neo4j.enable`
| Property | Value (`{secret}`)
| -------- | ------------------
| `spring.data.neo4j.password` | `{password}`
| `spring.data.neo4j.uri` | `{uri}`
| `spring.data.neo4j.username` | `{username}`
### Oracle RDBMS
Kind: `Oracle`
Disable Property: `org.springframework.cloud.bindings.boot.oracle.enable`

View File

@@ -0,0 +1,51 @@
/*
* 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.boot;
import org.springframework.cloud.bindings.Binding;
import org.springframework.cloud.bindings.Bindings;
import org.springframework.core.env.Environment;
import java.util.Map;
import static org.springframework.cloud.bindings.boot.Guards.isKindEnabled;
/**
* An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of kind: {@value KIND}.
*/
final class Neo4JBindingsPropertiesProcessor implements BindingsPropertiesProcessor {
/**
* The {@link Binding} kind that this processor is interested in: {@value}.
**/
public static final String KIND = "Neo4J";
@Override
public void process(Environment environment, Bindings bindings, Map<String, Object> properties) {
if (!isKindEnabled(environment, KIND)) {
return;
}
bindings.filterBindings(KIND).forEach(binding -> {
MapMapper map = new MapMapper(binding.getSecret(), properties);
map.from("password").to("spring.data.neo4j.password");
map.from("uri").to("spring.data.neo4j.uri");
map.from("username").to("spring.data.neo4j.username");
});
}
}

View File

@@ -9,6 +9,7 @@ org.springframework.cloud.bindings.boot.BindingsPropertiesProcessor=\
org.springframework.cloud.bindings.boot.ElasticsearchBindingsPropertiesProcessor, \
org.springframework.cloud.bindings.boot.MongoDbBindingsPropertiesProcessor, \
org.springframework.cloud.bindings.boot.MySqlBindingsPropertiesProcessor, \
org.springframework.cloud.bindings.boot.Neo4JBindingsPropertiesProcessor, \
org.springframework.cloud.bindings.boot.OracleBindingsPropertiesProcessor, \
org.springframework.cloud.bindings.boot.PostgreSqlBindingsPropertiesProcessor, \
org.springframework.cloud.bindings.boot.RedisBindingsPropertiesProcessor, \

View File

@@ -98,7 +98,7 @@ final class BindingSpecificEnvironmentPostProcessorTest {
@Test
@DisplayName("included implementations are registered")
void includedImplementations() {
assertThat(new BindingSpecificEnvironmentPostProcessor().processors).hasSize(10);
assertThat(new BindingSpecificEnvironmentPostProcessor().processors).hasSize(11);
}
}

View File

@@ -0,0 +1,70 @@
/*
* 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.boot;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.cloud.bindings.Binding;
import org.springframework.cloud.bindings.Bindings;
import org.springframework.cloud.bindings.FluentMap;
import org.springframework.mock.env.MockEnvironment;
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.boot.Neo4JBindingsPropertiesProcessor.KIND;
@DisplayName("Neo4J BindingsPropertiesProcessor")
final class Neo4JBindingsPropertiesProcessorTest {
private final Bindings bindings = new Bindings(
new Binding("test-name", Paths.get("test-path"),
Collections.singletonMap("kind", KIND),
new FluentMap()
.withEntry("password", "test-password")
.withEntry("uri", "test-uri")
.withEntry("username", "test-username")
)
);
private final MockEnvironment environment = new MockEnvironment();
private final HashMap<String, Object> properties = new HashMap<>();
@Test
@DisplayName("contributes properties")
void test() {
new Neo4JBindingsPropertiesProcessor().process(environment, bindings, properties);
assertThat(properties)
.containsEntry("spring.data.neo4j.password", "test-password")
.containsEntry("spring.data.neo4j.uri", "test-uri")
.containsEntry("spring.data.neo4j.username", "test-username");
}
@Test
@DisplayName("can be disabled")
void disabled() {
environment.setProperty("org.springframework.cloud.bindings.boot.neo4j.enable", "false");
new Neo4JBindingsPropertiesProcessor().process(environment, bindings, properties);
assertThat(properties).isEmpty();
}
}