Polish "Upgrade to Spring Data Neo4j 6"

See gh-22299
This commit is contained in:
Stephane Nicoll
2020-07-29 10:54:02 +02:00
parent 15cd343737
commit 9bc71fe44f
35 changed files with 593 additions and 732 deletions

View File

@@ -19,8 +19,6 @@ package org.springframework.boot.test.autoconfigure.data.neo4j;
import java.time.Duration;
import org.junit.jupiter.api.Test;
import org.springframework.data.neo4j.core.Neo4jTemplate;
import org.testcontainers.containers.Neo4jContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
@@ -28,6 +26,7 @@ import org.testcontainers.junit.jupiter.Testcontainers;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.data.neo4j.core.Neo4jTemplate;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
@@ -49,6 +48,11 @@ class DataNeo4jTestIntegrationTests {
static final Neo4jContainer<?> neo4j = new Neo4jContainer<>().withoutAuthentication()
.withStartupTimeout(Duration.ofMinutes(10));
@DynamicPropertySource
static void neo4jProperties(DynamicPropertyRegistry registry) {
registry.add("spring.neo4j.uri", neo4j::getBoltUrl);
}
@Autowired
private Neo4jTemplate neo4jTemplate;
@@ -58,11 +62,6 @@ class DataNeo4jTestIntegrationTests {
@Autowired
private ApplicationContext applicationContext;
@DynamicPropertySource
static void neo4jProperties(DynamicPropertyRegistry registry) {
registry.add("spring.neo4j.uri", neo4j::getBoltUrl);
}
@Test
void testRepository() {
ExampleGraph exampleGraph = new ExampleGraph("Look, new @DataNeo4jTest!");

View File

@@ -44,14 +44,14 @@ class DataNeo4jTestPropertiesIntegrationTests {
static final Neo4jContainer<?> neo4j = new Neo4jContainer<>().withoutAuthentication()
.withStartupTimeout(Duration.ofMinutes(10));
@Autowired
private Environment environment;
@DynamicPropertySource
static void neo4jProperties(DynamicPropertyRegistry registry) {
registry.add("spring.neo4j.uri", neo4j::getBoltUrl);
}
@Autowired
private Environment environment;
@Test
void environmentWithNewProfile() {
assertThat(this.environment.getActiveProfiles()).containsExactly("test");

View File

@@ -16,30 +16,22 @@
package org.springframework.boot.test.autoconfigure.data.neo4j;
import java.time.Duration;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.data.neo4j.core.ReactiveNeo4jTemplate;
import org.springframework.data.neo4j.core.transaction.ReactiveNeo4jTransactionManager;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.ReactiveTransactionManager;
import org.testcontainers.containers.Neo4jContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
import java.time.Duration;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.data.neo4j.core.ReactiveNeo4jTemplate;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.neo4j.driver.AccessMode;
import org.neo4j.driver.Driver;
import org.neo4j.driver.Session;
import org.neo4j.driver.SessionConfig;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
/**
@@ -50,7 +42,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
*/
@DataNeo4jTest
@Testcontainers(disabledWithoutDocker = true)
class ReactiveDataNeo4jIntegrationTests {
class DataNeo4jTestReactiveIntegrationTests {
@Container
static final Neo4jContainer<?> neo4j = new Neo4jContainer<>("neo4j:4.0").withoutAuthentication()
@@ -62,24 +54,19 @@ class ReactiveDataNeo4jIntegrationTests {
}
@Autowired
private Driver driver;
private ReactiveNeo4jTemplate neo4jTemplate;
@Autowired
private ReactiveNeo4jTemplate neo4jTemplate;
private ExampleReactiveRepository exampleRepository;
@Autowired
private ApplicationContext applicationContext;
@Test
void testTemplate() {
Mono.just(new ExampleGraph("Look, new @DataNeo4jTest with reactive!")).flatMap(neo4jTemplate::save)
void testRepository() {
Mono.just(new ExampleGraph("Look, new @DataNeo4jTest with reactive!")).flatMap(this.exampleRepository::save)
.as(StepVerifier::create).expectNextCount(1).verifyComplete();
try (Session session = driver.session(SessionConfig.builder().withDefaultAccessMode(AccessMode.READ).build())) {
long cnt = session.run("MATCH (n:ExampleGraph) RETURN count(n) as cnt").single().get("cnt").asLong();
assertThat(cnt).isEqualTo(1L);
}
StepVerifier.create(this.neo4jTemplate.count(ExampleGraph.class)).expectNext(1L).verifyComplete();
}
@Test
@@ -88,13 +75,4 @@ class ReactiveDataNeo4jIntegrationTests {
.isThrownBy(() -> this.applicationContext.getBean(ExampleService.class));
}
@Test
void didProvideOnlyReactiveTransactionManager() {
assertThat(this.applicationContext.getBean(ReactiveTransactionManager.class))
.isInstanceOf(ReactiveNeo4jTransactionManager.class);
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
.isThrownBy(() -> this.applicationContext.getBean(PlatformTransactionManager.class));
}
}

View File

@@ -45,14 +45,14 @@ class DataNeo4jTestWithIncludeFilterIntegrationTests {
static final Neo4jContainer<?> neo4j = new Neo4jContainer<>().withoutAuthentication()
.withStartupTimeout(Duration.ofMinutes(10));
@Autowired
private ExampleService service;
@DynamicPropertySource
static void neo4jProperties(DynamicPropertyRegistry registry) {
registry.add("spring.neo4j.uri", neo4j::getBoltUrl);
}
@Autowired
private ExampleService service;
@Test
void testService() {
assertThat(this.service.hasNode(ExampleGraph.class)).isFalse();

View File

@@ -1,69 +0,0 @@
/*
* Copyright (c) 2019-2020 "Neo4j,"
* Neo4j Sweden AB [https://neo4j.com]
*
* This file is part of Neo4j.
*
* 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
*
* https://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.boot.test.autoconfigure.data.neo4j;
import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.classreading.SimpleMetadataReaderFactory;
import java.io.IOException;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Michael J. Simons
*/
class DataNeo4jTypeExcludeFilterTests {
private MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
@Test
void matchWithExcludeFilter() throws Exception {
DataNeo4jTypeExcludeFilter filter = new DataNeo4jTypeExcludeFilter(WithExcludeFilter.class);
assertThat(excludes(filter, ExampleService.class)).isTrue();
assertThat(excludes(filter, ExampleRepository.class)).isTrue();
}
@Test
void matchWithoutExcludeFilter() throws Exception {
DataNeo4jTypeExcludeFilter filter = new DataNeo4jTypeExcludeFilter(WithoutExcludeFilter.class);
assertThat(excludes(filter, ExampleService.class)).isTrue();
assertThat(excludes(filter, ExampleRepository.class)).isFalse();
}
@DataNeo4jTest(
excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = ExampleRepository.class))
static class WithExcludeFilter {
}
@DataNeo4jTest
static class WithoutExcludeFilter {
}
private boolean excludes(DataNeo4jTypeExcludeFilter filter, Class<?> type) throws IOException {
MetadataReader metadataReader = this.metadataReaderFactory.getMetadataReader(type.getName());
return filter.match(metadataReader, this.metadataReaderFactory);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-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.
@@ -25,7 +25,6 @@ import org.springframework.data.neo4j.core.schema.Property;
* Example graph used with {@link DataNeo4jTest @DataNeo4jTest} tests.
*
* @author Eddú Meléndez
* @author Michael J. Simons
*/
@Node
public class ExampleGraph {

View File

@@ -0,0 +1,28 @@
/*
* Copyright 2012-2019 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
*
* https://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.boot.test.autoconfigure.data.neo4j;
import org.springframework.data.neo4j.repository.ReactiveNeo4jRepository;
/**
* Example reactive repository used with {@link DataNeo4jTest @DataNeo4jTest} tests.
*
* @author Stephane Nicoll
*/
interface ExampleReactiveRepository extends ReactiveNeo4jRepository<ExampleGraph, Long> {
}