JAVA-20167 Changes in MovieRepositoryIntegrationTest
This commit is contained in:
parent
2fd4c39a21
commit
b50712ae42
|
@ -105,6 +105,18 @@
|
||||||
</exclusion>
|
</exclusion>
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.neo4j.test</groupId>
|
||||||
|
<artifactId>neo4j-harness</artifactId>
|
||||||
|
<version>5.5.0</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-nop</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
package com.baeldung.spring.data.neo4j;
|
package com.baeldung.spring.data.neo4j;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
import com.baeldung.spring.data.neo4j.config.MovieDatabaseNeo4jTestConfiguration;
|
import com.baeldung.spring.data.neo4j.config.MovieDatabaseNeo4jTestConfiguration;
|
||||||
import com.baeldung.spring.data.neo4j.domain.Movie;
|
import com.baeldung.spring.data.neo4j.domain.Movie;
|
||||||
import com.baeldung.spring.data.neo4j.domain.Person;
|
import com.baeldung.spring.data.neo4j.domain.Person;
|
||||||
|
@ -7,37 +11,44 @@ import com.baeldung.spring.data.neo4j.domain.Role;
|
||||||
import com.baeldung.spring.data.neo4j.repository.MovieRepository;
|
import com.baeldung.spring.data.neo4j.repository.MovieRepository;
|
||||||
import com.baeldung.spring.data.neo4j.repository.PersonRepository;
|
import com.baeldung.spring.data.neo4j.repository.PersonRepository;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.AfterAll;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.neo4j.harness.Neo4j;
|
||||||
|
import org.neo4j.harness.Neo4jBuilders;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.autoconfigure.data.neo4j.DataNeo4jTest;
|
||||||
import org.springframework.test.annotation.DirtiesContext;
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
import org.springframework.test.context.ActiveProfiles;
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.DynamicPropertyRegistry;
|
||||||
|
import org.springframework.test.context.DynamicPropertySource;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import static junit.framework.TestCase.assertNull;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
|
||||||
@ContextConfiguration(classes = MovieDatabaseNeo4jTestConfiguration.class)
|
@ContextConfiguration(classes = MovieDatabaseNeo4jTestConfiguration.class)
|
||||||
@ActiveProfiles(profiles = "test")
|
@ActiveProfiles(profiles = "test")
|
||||||
public class MovieRepositoryIntegrationTest {
|
@DataNeo4jTest
|
||||||
|
class MovieRepositoryIntegrationTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private MovieRepository movieRepository;
|
private static MovieRepository movieRepository;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private PersonRepository personRepository;
|
private static PersonRepository personRepository;
|
||||||
|
|
||||||
public MovieRepositoryIntegrationTest() {
|
public MovieRepositoryIntegrationTest() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
private static Neo4j embeddedDatabaseServer;
|
||||||
public void initializeDatabase() {
|
|
||||||
|
@BeforeAll
|
||||||
|
static void initializeNeo4j() {
|
||||||
|
|
||||||
|
embeddedDatabaseServer = Neo4jBuilders.newInProcessBuilder()
|
||||||
|
.withDisabledServer()
|
||||||
|
.build();
|
||||||
|
|
||||||
System.out.println("seeding embedded database");
|
System.out.println("seeding embedded database");
|
||||||
Movie italianJob = new Movie();
|
Movie italianJob = new Movie();
|
||||||
italianJob.setTitle("The Italian Job");
|
italianJob.setTitle("The Italian Job");
|
||||||
|
@ -60,9 +71,23 @@ public class MovieRepositoryIntegrationTest {
|
||||||
movieRepository.save(italianJob);
|
movieRepository.save(italianJob);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DynamicPropertySource
|
||||||
|
static void neo4jProperties(DynamicPropertyRegistry registry) {
|
||||||
|
|
||||||
|
registry.add("spring.neo4j.uri", embeddedDatabaseServer::boltURI);
|
||||||
|
registry.add("spring.neo4j.authentication.username", () -> "neo4j");
|
||||||
|
registry.add("spring.neo4j.authentication.password", () -> null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterAll
|
||||||
|
static void stopNeo4j() {
|
||||||
|
|
||||||
|
embeddedDatabaseServer.close();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
public void testFindByTitle() {
|
void testFindByTitle() {
|
||||||
System.out.println("findByTitle");
|
System.out.println("findByTitle");
|
||||||
String title = "The Italian Job";
|
String title = "The Italian Job";
|
||||||
Movie result = movieRepository.findByTitle(title);
|
Movie result = movieRepository.findByTitle(title);
|
||||||
|
@ -72,7 +97,7 @@ public class MovieRepositoryIntegrationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
public void testCount() {
|
void testCount() {
|
||||||
System.out.println("count");
|
System.out.println("count");
|
||||||
long movieCount = movieRepository.count();
|
long movieCount = movieRepository.count();
|
||||||
|
|
||||||
|
@ -81,7 +106,7 @@ public class MovieRepositoryIntegrationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
public void testFindAll() {
|
void testFindAll() {
|
||||||
System.out.println("findAll");
|
System.out.println("findAll");
|
||||||
Collection<Movie> result = movieRepository.findAll();
|
Collection<Movie> result = movieRepository.findAll();
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
|
@ -90,7 +115,7 @@ public class MovieRepositoryIntegrationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
public void testFindByTitleContaining() {
|
void testFindByTitleContaining() {
|
||||||
System.out.println("findByTitleContaining");
|
System.out.println("findByTitleContaining");
|
||||||
String title = "Italian";
|
String title = "Italian";
|
||||||
Collection<Movie> result = movieRepository.findByTitleContaining(title);
|
Collection<Movie> result = movieRepository.findByTitleContaining(title);
|
||||||
|
@ -100,7 +125,7 @@ public class MovieRepositoryIntegrationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
public void testGraph() {
|
void testGraph() {
|
||||||
System.out.println("graph");
|
System.out.println("graph");
|
||||||
List<Map<String, Object>> graph = movieRepository.graph(5);
|
List<Map<String, Object>> graph = movieRepository.graph(5);
|
||||||
assertEquals(1, graph.size());
|
assertEquals(1, graph.size());
|
||||||
|
@ -114,7 +139,7 @@ public class MovieRepositoryIntegrationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
public void testDeleteMovie() {
|
void testDeleteMovie() {
|
||||||
System.out.println("deleteMovie");
|
System.out.println("deleteMovie");
|
||||||
movieRepository.delete(movieRepository.findByTitle("The Italian Job"));
|
movieRepository.delete(movieRepository.findByTitle("The Italian Job"));
|
||||||
assertNull(movieRepository.findByTitle("The Italian Job"));
|
assertNull(movieRepository.findByTitle("The Italian Job"));
|
||||||
|
@ -122,7 +147,7 @@ public class MovieRepositoryIntegrationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
public void testDeleteAll() {
|
void testDeleteAll() {
|
||||||
System.out.println("deleteAll");
|
System.out.println("deleteAll");
|
||||||
movieRepository.deleteAll();
|
movieRepository.deleteAll();
|
||||||
Collection<Movie> result = movieRepository.findAll();
|
Collection<Movie> result = movieRepository.findAll();
|
||||||
|
|
Loading…
Reference in New Issue