|
| 1 | +/* |
| 2 | + * Copyright 2011-2021 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.data.neo4j.integration.issues.gh2326; |
| 17 | + |
| 18 | +import reactor.core.publisher.Flux; |
| 19 | +import reactor.test.StepVerifier; |
| 20 | + |
| 21 | +import java.util.ArrayList; |
| 22 | +import java.util.Arrays; |
| 23 | +import java.util.List; |
| 24 | + |
| 25 | +import org.junit.jupiter.api.Test; |
| 26 | +import org.neo4j.driver.Driver; |
| 27 | +import org.springframework.beans.factory.annotation.Autowired; |
| 28 | +import org.springframework.context.annotation.Bean; |
| 29 | +import org.springframework.context.annotation.Configuration; |
| 30 | +import org.springframework.data.neo4j.config.AbstractReactiveNeo4jConfig; |
| 31 | +import org.springframework.data.neo4j.repository.ReactiveNeo4jRepository; |
| 32 | +import org.springframework.data.neo4j.repository.config.EnableReactiveNeo4jRepositories; |
| 33 | +import org.springframework.data.neo4j.test.BookmarkCapture; |
| 34 | +import org.springframework.data.neo4j.test.Neo4jIntegrationTest; |
| 35 | +import org.springframework.transaction.annotation.EnableTransactionManagement; |
| 36 | + |
| 37 | +/** |
| 38 | + * @author Michael J. Simons |
| 39 | + */ |
| 40 | +@Neo4jIntegrationTest |
| 41 | +class ReactiveGH2326IT extends TestBase { |
| 42 | + |
| 43 | + @Test // GH-2326 |
| 44 | + void saveShouldAddAllLabels(@Autowired AnimalRepository animalRepository, @Autowired BookmarkCapture bookmarkCapture) { |
| 45 | + |
| 46 | + List<String> ids = new ArrayList<>(); |
| 47 | + List<Animal> animals = Arrays.asList(new Animal.Pet.Cat(), new Animal.Pet.Dog()); |
| 48 | + Flux.fromIterable(animals).flatMap(animalRepository::save) |
| 49 | + .map(BaseEntity::getId) |
| 50 | + .as(StepVerifier::create) |
| 51 | + .recordWith(() -> ids) |
| 52 | + .expectNextCount(2) |
| 53 | + .verifyComplete(); |
| 54 | + |
| 55 | + assertLabels(bookmarkCapture, ids); |
| 56 | + } |
| 57 | + |
| 58 | + @Test // GH-2326 |
| 59 | + void saveAllShouldAddAllLabels(@Autowired AnimalRepository animalRepository, @Autowired BookmarkCapture bookmarkCapture) { |
| 60 | + |
| 61 | + List<String> ids = new ArrayList<>(); |
| 62 | + List<Animal> animals = Arrays.asList(new Animal.Pet.Cat(), new Animal.Pet.Dog()); |
| 63 | + animalRepository.saveAll(animals) |
| 64 | + .map(BaseEntity::getId) |
| 65 | + .as(StepVerifier::create) |
| 66 | + .recordWith(() -> ids) |
| 67 | + .expectNextCount(2) |
| 68 | + .verifyComplete(); |
| 69 | + |
| 70 | + assertLabels(bookmarkCapture, ids); |
| 71 | + } |
| 72 | + |
| 73 | + public interface AnimalRepository extends ReactiveNeo4jRepository<Animal, String> { |
| 74 | + } |
| 75 | + |
| 76 | + @Configuration |
| 77 | + @EnableTransactionManagement |
| 78 | + @EnableReactiveNeo4jRepositories(considerNestedRepositories = true) |
| 79 | + static class Config extends AbstractReactiveNeo4jConfig { |
| 80 | + |
| 81 | + @Bean |
| 82 | + public BookmarkCapture bookmarkCapture() { |
| 83 | + return new BookmarkCapture(); |
| 84 | + } |
| 85 | + |
| 86 | + @Bean |
| 87 | + public Driver driver() { |
| 88 | + |
| 89 | + return neo4jConnectionSupport.getDriver(); |
| 90 | + } |
| 91 | + } |
| 92 | +} |
0 commit comments