diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/examples/galaxy/GalaxyContextConfiguration.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/examples/galaxy/GalaxyContextConfiguration.java index 0b0ec635b..3af03d690 100644 --- a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/examples/galaxy/GalaxyContextConfiguration.java +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/examples/galaxy/GalaxyContextConfiguration.java @@ -21,7 +21,9 @@ import org.springframework.data.neo4j.test.Neo4jIntegrationTest; /** * @author Michael J. Simons */ -@Neo4jIntegrationTest(domainPackages = "org.springframework.data.neo4j.examples.galaxy.domain", - repositoryPackages = "org.springframework.data.neo4j.examples.galaxy.repo") +@Neo4jIntegrationTest(domainPackages = { "org.springframework.data.neo4j.examples.galaxy.domain", + "org.springframework.data.neo4j.queries.ogmgh552" }, + repositoryPackages = { "org.springframework.data.neo4j.examples.galaxy.repo", + "org.springframework.data.neo4j.queries.ogmgh552" }) @ComponentScan("org.springframework.data.neo4j.examples.galaxy.service") public class GalaxyContextConfiguration {} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/queries/QueryResultIntegrationTests.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/queries/QueryResultIntegrationTests.java index 8a557d023..e5e806ba7 100644 --- a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/queries/QueryResultIntegrationTests.java +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/queries/QueryResultIntegrationTests.java @@ -25,7 +25,6 @@ import org.junit.runner.RunWith; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Transaction; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.data.neo4j.queries.ogmgh551.AnotherThing; import org.springframework.data.neo4j.queries.ogmgh551.ThingRepository; @@ -77,8 +76,7 @@ public class QueryResultIntegrationTests { } @Configuration - @Neo4jIntegrationTest(domainPackages = "org.springframework.data.neo4j.queries.ogmgh551") - @ComponentScan("org.springframework.data.neo4j.queries.ogmgh551") + @Neo4jIntegrationTest(repositoryPackages = "org.springframework.data.neo4j.queries.ogmgh551", domainPackages = "org.springframework.data.neo4j.queries.ogmgh551") static class ContextConfig { } } diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/queries/QueryReturnTypesTests.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/queries/QueryReturnTypesTests.java index 1f1d8e31f..35f62cd8b 100644 --- a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/queries/QueryReturnTypesTests.java +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/queries/QueryReturnTypesTests.java @@ -25,6 +25,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.neo4j.examples.galaxy.GalaxyContextConfiguration; import org.springframework.data.neo4j.examples.galaxy.domain.World; import org.springframework.data.neo4j.examples.galaxy.repo.WorldRepository; +import org.springframework.data.neo4j.queries.ogmgh552.Thing; +import org.springframework.data.neo4j.queries.ogmgh552.ThingRepository; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.transaction.annotation.Transactional; @@ -32,12 +34,15 @@ import org.springframework.transaction.support.TransactionTemplate; import static org.assertj.core.api.Assertions.assertThat; +import java.util.List; + /** * @author Vince Bickers * @author Luanne Misquitta * @author Mark Angrish * @author Mark Paluch * @author Jens Schauder + * @author Michael J. Simons */ @ContextConfiguration(classes = GalaxyContextConfiguration.class) @RunWith(SpringRunner.class) @@ -52,6 +57,8 @@ public class QueryReturnTypesTests { @Autowired Session session; + @Autowired ThingRepository thingRepository; + @Before public void clearDatabase() { graphDatabaseService.execute("MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE r, n"); @@ -70,6 +77,13 @@ public class QueryReturnTypesTests { assertThat(world.getUpdated()).isNotNull(); } + @Test + public void queryResultsAndEntitiesMappedToTheSameSimpleTypeShouldNotBeMixedUp() { + + List result = this.thingRepository.findAllTheThings(); + assertThat(result).hasSize(1).extracting(Thing::getNotAName).containsExactly("NOT A NAME!!!"); + } + @Test // DATAGRAPH-704 public void shouldCallExecuteWhenVoidReturnTypeOnQuery() { diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/queries/ogmgh552/Thing.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/queries/ogmgh552/Thing.java new file mode 100644 index 000000000..8226457ed --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/queries/ogmgh552/Thing.java @@ -0,0 +1,30 @@ +/* + * Copyright 2011-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.data.neo4j.queries.ogmgh552; + +import org.springframework.data.neo4j.annotation.QueryResult; + +/** + * @author Michael J. Simons + */ +@QueryResult +public class Thing { + private String notAName; + + public String getNotAName() { + return notAName; + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/queries/ogmgh552/ThingEntity.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/queries/ogmgh552/ThingEntity.java new file mode 100644 index 000000000..77c7a88f7 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/queries/ogmgh552/ThingEntity.java @@ -0,0 +1,32 @@ +/* + * Copyright 2011-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.data.neo4j.queries.ogmgh552; + +import org.neo4j.ogm.annotation.GeneratedValue; +import org.neo4j.ogm.annotation.Id; +import org.neo4j.ogm.annotation.NodeEntity; + +/** + * @author Michael J. Simons + */ +@NodeEntity("Thing") +public class ThingEntity { + @Id @GeneratedValue + private Long id; + + private String name; +} + diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/queries/ogmgh552/ThingRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/queries/ogmgh552/ThingRepository.java new file mode 100644 index 000000000..0dab3662f --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/queries/ogmgh552/ThingRepository.java @@ -0,0 +1,30 @@ +/* + * Copyright 2011-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.data.neo4j.queries.ogmgh552; + +import java.util.List; + +import org.springframework.data.neo4j.annotation.Query; +import org.springframework.data.neo4j.repository.Neo4jRepository; + +/** + * @author Michael J. Simons + */ +public interface ThingRepository extends Neo4jRepository { + + @Query("return 'NOT A NAME!!!' as notAName") + List findAllTheThings(); +}