|
| 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.bookmark; |
| 17 | + |
| 18 | +import static org.assertj.core.api.Assertions.assertThat; |
| 19 | +import static org.assertj.core.api.Assertions.assertThatIllegalStateException; |
| 20 | + |
| 21 | +import java.util.Collection; |
| 22 | +import java.util.Collections; |
| 23 | + |
| 24 | +import org.junit.Test; |
| 25 | +import org.springframework.context.ConfigurableApplicationContext; |
| 26 | +import org.springframework.context.annotation.AnnotationConfigApplicationContext; |
| 27 | +import org.springframework.context.annotation.Bean; |
| 28 | +import org.springframework.context.annotation.Configuration; |
| 29 | +import org.springframework.data.neo4j.annotation.EnableBookmarkManagement; |
| 30 | +import org.springframework.transaction.annotation.EnableTransactionManagement; |
| 31 | + |
| 32 | +/** |
| 33 | + * @author Michael J. Simons |
| 34 | + */ |
| 35 | +public class BookmarkManagementConfigurationTests { |
| 36 | + |
| 37 | + @Test // GH-1691 |
| 38 | + public void bookmarkManagerShouldBeRequired() { |
| 39 | + |
| 40 | + assertThatIllegalStateException().isThrownBy(() -> new AnnotationConfigApplicationContext(BookmarkManagementConfiguration.class)) |
| 41 | + .withMessageStartingWith("Bookmark management has been enabled via `@EnableBookmarkManagement` but no bean implementing `org.springframework.data.neo4j.bookmark.BookmarkManager` has been provided."); |
| 42 | + } |
| 43 | + |
| 44 | + @Test // GH-1691 |
| 45 | + public void bookmarkManagerShouldBeRecognized() { |
| 46 | + |
| 47 | + try(ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(BookmarkManagementConfiguration.class, BookmarkManagerConfiguration.class)) { |
| 48 | + assertThat(ctx.getBean(BookmarkInterceptor.class)).isNotNull(); |
| 49 | + assertThat(ctx.getBean(BeanFactoryBookmarkOperationAdvisor.class)).isNotNull(); |
| 50 | + assertThat(ctx.getBean( |
| 51 | + org.springframework.data.neo4j.bookmark.BookmarkManagementConfiguration.BookmarkManagerContextValidator.class)).isNotNull(); |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + @Configuration |
| 56 | + @EnableBookmarkManagement |
| 57 | + @EnableTransactionManagement |
| 58 | + static class BookmarkManagementConfiguration { |
| 59 | + } |
| 60 | + |
| 61 | + @Configuration |
| 62 | + static class BookmarkManagerConfiguration { |
| 63 | + @Bean |
| 64 | + public BookmarkManager bookmarkManager() { |
| 65 | + return new BookmarkManager() { |
| 66 | + @Override |
| 67 | + public Collection<String> getBookmarks() { |
| 68 | + return Collections.emptyList(); |
| 69 | + } |
| 70 | + |
| 71 | + @Override |
| 72 | + public void storeBookmark(String bookmark, Collection<String> previous) { |
| 73 | + } |
| 74 | + }; |
| 75 | + } |
| 76 | + } |
| 77 | +} |
0 commit comments