DATAGRAPH-1271 - Fix invalid class lookup for @QueryResults.

This commit is contained in:
Michael Simons
2019-12-02 17:00:17 +01:00
parent 1c95b298ec
commit 51959eec7f
6 changed files with 111 additions and 5 deletions

View File

@@ -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 {}

View File

@@ -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 {
}
}

View File

@@ -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<Thing> result = this.thingRepository.findAllTheThings();
assertThat(result).hasSize(1).extracting(Thing::getNotAName).containsExactly("NOT A NAME!!!");
}
@Test // DATAGRAPH-704
public void shouldCallExecuteWhenVoidReturnTypeOnQuery() {

View File

@@ -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;
}
}

View File

@@ -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;
}

View File

@@ -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<ThingEntity, Long> {
@Query("return 'NOT A NAME!!!' as notAName")
List<Thing> findAllTheThings();
}