From a6c92d6abcc2210dba05bba6aa57cfedb72726d5 Mon Sep 17 00:00:00 2001 From: Michael Simons Date: Fri, 28 Aug 2020 12:17:38 +0200 Subject: [PATCH] =?UTF-8?q?DATAGRAPH-1303=20-=20Ensure=20that=20unrelated?= =?UTF-8?q?=20annotation=20don=E2=80=99t=20break=20OGM=20metadata.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commits adds two tests ensuring that OGM 3.2.15 and 3.1.21 don’t fail on unrelated, package private annotations any more. --- .../mapping/AnnotationScanningTests.java | 54 +++++++++++++++++++ .../mapping/datagraph1303/DomainObject.java | 26 +++++++++ .../neo4j/mapping/datagraph1303/Endpoint.java | 33 ++++++++++++ .../datagraph1303/EndpointController.java | 40 ++++++++++++++ .../datagraph1303/TheEndpointController.java | 24 +++++++++ 5 files changed, 177 insertions(+) create mode 100644 spring-data-neo4j/src/test/java/org/springframework/data/neo4j/mapping/AnnotationScanningTests.java create mode 100644 spring-data-neo4j/src/test/java/org/springframework/data/neo4j/mapping/datagraph1303/DomainObject.java create mode 100644 spring-data-neo4j/src/test/java/org/springframework/data/neo4j/mapping/datagraph1303/Endpoint.java create mode 100644 spring-data-neo4j/src/test/java/org/springframework/data/neo4j/mapping/datagraph1303/EndpointController.java create mode 100644 spring-data-neo4j/src/test/java/org/springframework/data/neo4j/mapping/datagraph1303/TheEndpointController.java diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/mapping/AnnotationScanningTests.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/mapping/AnnotationScanningTests.java new file mode 100644 index 000000000..b2675537f --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/mapping/AnnotationScanningTests.java @@ -0,0 +1,54 @@ +/* + * Copyright 2011-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 + * + * 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.data.neo4j.mapping; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.neo4j.ogm.metadata.AnnotationsInfo; +import org.neo4j.ogm.session.SessionFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.neo4j.test.Neo4jIntegrationTest; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * @author Michael J. Simons + * @soundtrack Metallica - S&M2 + */ +@RunWith(SpringRunner.class) +public class AnnotationScanningTests { + + @Autowired + private SessionFactory sessionFactory; + + @Test + public void shouldBeAbleToWorkWithAnnotatedAnnotations() { + AnnotationsInfo annotations = sessionFactory.metaData().classInfo("TheEndpointController").annotationsInfo(); + assertThat(annotations.get("org.springframework.data.neo4j.mapping.datagraph1303.EndpointController")) + .isNotNull().extracting(i -> i.get("value")) + .isEqualTo("foobar"); + } + + @Configuration + @Neo4jIntegrationTest( + domainPackages = { "org.springframework.data.neo4j.mapping.datagraph1303" }, + repositoryPackages = { "org.springframework.data.neo4j.mapping.datagraph1303" } + ) + static class Config { + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/mapping/datagraph1303/DomainObject.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/mapping/datagraph1303/DomainObject.java new file mode 100644 index 000000000..4aa2bf3a7 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/mapping/datagraph1303/DomainObject.java @@ -0,0 +1,26 @@ +/* + * Copyright 2011-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 + * + * 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.data.neo4j.mapping.datagraph1303; + +import org.neo4j.ogm.annotation.NodeEntity; + +/** + * @author Michael J. Simons + * @soundtrack Metallica - S&M2 + */ +@NodeEntity +public class DomainObject { +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/mapping/datagraph1303/Endpoint.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/mapping/datagraph1303/Endpoint.java new file mode 100644 index 000000000..e9bd631f3 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/mapping/datagraph1303/Endpoint.java @@ -0,0 +1,33 @@ +/* + * Copyright 2011-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 + * + * 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.data.neo4j.mapping.datagraph1303; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * @author Michael J. Simons + * @soundtrack Metallica - S&M2 + */ +@Documented +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) @interface Endpoint { + + String id() default ""; +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/mapping/datagraph1303/EndpointController.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/mapping/datagraph1303/EndpointController.java new file mode 100644 index 000000000..089f0e314 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/mapping/datagraph1303/EndpointController.java @@ -0,0 +1,40 @@ +/* + * Copyright 2011-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 + * + * 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.data.neo4j.mapping.datagraph1303; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.springframework.core.annotation.AliasFor; +import org.springframework.stereotype.Controller; + +/** + * @author Michael J. Simons + * @soundtrack Metallica - S&M2 + */ +@Controller +@Documented +@Endpoint +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +@interface EndpointController { + + @AliasFor(annotation = Endpoint.class, attribute = "id") + String value(); +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/mapping/datagraph1303/TheEndpointController.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/mapping/datagraph1303/TheEndpointController.java new file mode 100644 index 000000000..4ad574acd --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/mapping/datagraph1303/TheEndpointController.java @@ -0,0 +1,24 @@ +/* + * Copyright 2011-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 + * + * 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.data.neo4j.mapping.datagraph1303; + +/** + * @author Michael J. Simons + * @soundtrack Metallica - S&M2 + */ +@EndpointController("foobar") +public class TheEndpointController { +}