-
Notifications
You must be signed in to change notification settings - Fork 617
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Look for static labels to contain a label, not vice versa. (#2887)
Fixes #2886.
- Loading branch information
1 parent
b2744f0
commit 4ff3e11
Showing
8 changed files
with
308 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/test/java/org/springframework/data/neo4j/integration/issues/gh2886/Apple.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright 2011-2024 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.integration.issues.gh2886; | ||
|
||
import org.springframework.data.neo4j.core.schema.Node; | ||
|
||
/** | ||
* GH-2886 | ||
*/ | ||
@Node(primaryLabel = "Apple") | ||
public class Apple extends MagicalFruit { | ||
} |
52 changes: 52 additions & 0 deletions
52
src/test/java/org/springframework/data/neo4j/integration/issues/gh2886/Fruit.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright 2011-2024 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.integration.issues.gh2886; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import org.springframework.data.neo4j.core.schema.DynamicLabels; | ||
import org.springframework.data.neo4j.core.schema.Id; | ||
import org.springframework.data.neo4j.core.schema.Node; | ||
|
||
/** | ||
* GH-2886 | ||
*/ | ||
@Node(primaryLabel = "Fruit") | ||
public abstract class Fruit { | ||
|
||
@Id | ||
protected String id; | ||
|
||
@DynamicLabels | ||
protected Set<String> labels = new HashSet<>(); | ||
|
||
public String getId() { | ||
return this.id; | ||
} | ||
|
||
public Set<String> getLabels() { | ||
return this.labels; | ||
} | ||
|
||
public void setId(String id) { | ||
this.id = id; | ||
} | ||
|
||
public void setLabels(Set<String> labels) { | ||
this.labels = labels; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/test/java/org/springframework/data/neo4j/integration/issues/gh2886/FruitRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright 2011-2024 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.integration.issues.gh2886; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.data.neo4j.repository.Neo4jRepository; | ||
import org.springframework.data.neo4j.repository.query.Query; | ||
import org.springframework.stereotype.Repository; | ||
|
||
/** | ||
* GH-2886 | ||
*/ | ||
@Repository | ||
public interface FruitRepository extends Neo4jRepository<Fruit, String> { | ||
@Query("MATCH (f:Fruit) RETURN f") | ||
List<Fruit> findAllFruits(); | ||
} |
119 changes: 119 additions & 0 deletions
119
src/test/java/org/springframework/data/neo4j/integration/issues/gh2886/Gh2886IT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* | ||
* Copyright 2011-2024 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.integration.issues.gh2886; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.neo4j.driver.Driver; | ||
import org.neo4j.driver.Session; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.neo4j.core.DatabaseSelectionProvider; | ||
import org.springframework.data.neo4j.core.transaction.Neo4jBookmarkManager; | ||
import org.springframework.data.neo4j.core.transaction.Neo4jTransactionManager; | ||
import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories; | ||
import org.springframework.data.neo4j.test.BookmarkCapture; | ||
import org.springframework.data.neo4j.test.Neo4jExtension; | ||
import org.springframework.data.neo4j.test.Neo4jImperativeTestConfiguration; | ||
import org.springframework.data.neo4j.test.Neo4jIntegrationTest; | ||
import org.springframework.transaction.PlatformTransactionManager; | ||
import org.springframework.transaction.annotation.EnableTransactionManagement; | ||
|
||
/** | ||
* GH-2886 | ||
*/ | ||
@Neo4jIntegrationTest | ||
public class Gh2886IT { | ||
|
||
protected static Neo4jExtension.Neo4jConnectionSupport neo4jConnectionSupport; | ||
|
||
@BeforeAll | ||
static void setup(@Autowired Driver driver, @Autowired BookmarkCapture bookmarkCapture) { | ||
try (Session session = driver.session(bookmarkCapture.createSessionConfig())) { | ||
session.run("MATCH (n) detach delete n").consume(); | ||
bookmarkCapture.seedWith(session.lastBookmark()); | ||
} | ||
} | ||
|
||
@Test | ||
void dynamicLabels(@Autowired FruitRepository repository) { | ||
|
||
Apple f1 = new Apple(); | ||
f1.setVolume(1.0); | ||
f1.setColor("Red"); | ||
f1.setLabels(Collections.singleton("X")); | ||
|
||
Apple f2 = new Apple(); | ||
f2.setColor("Blue"); | ||
|
||
Orange f3 = new Orange(); | ||
f2.setVolume(3.0); | ||
f3.setColor("Red"); | ||
f3.setLabels(Collections.singleton("Y")); | ||
|
||
Orange f4 = new Orange(); | ||
f4.setColor("Yellow"); | ||
|
||
repository.saveAll(Stream.of(f1, f2, f3, f4).collect(Collectors.toList())); | ||
|
||
List<Fruit> fruits = repository.findAllFruits(); | ||
assertThat(fruits).allMatch(f -> f instanceof Apple || f instanceof Orange); | ||
} | ||
|
||
@Configuration | ||
@EnableTransactionManagement | ||
@EnableNeo4jRepositories(considerNestedRepositories = true) | ||
static class Config extends Neo4jImperativeTestConfiguration { | ||
|
||
@Bean | ||
public BookmarkCapture bookmarkCapture() { | ||
return new BookmarkCapture(); | ||
} | ||
|
||
@Override | ||
public PlatformTransactionManager transactionManager( | ||
Driver driver, DatabaseSelectionProvider databaseNameProvider) { | ||
|
||
BookmarkCapture bookmarkCapture = bookmarkCapture(); | ||
return new Neo4jTransactionManager(driver, databaseNameProvider, | ||
Neo4jBookmarkManager.create(bookmarkCapture)); | ||
} | ||
|
||
@Override | ||
protected Collection<String> getMappingBasePackages() { | ||
return Collections.singleton(Apple.class.getPackage().getName()); | ||
} | ||
|
||
@Bean | ||
public Driver driver() { | ||
return neo4jConnectionSupport.getDriver(); | ||
} | ||
|
||
@Override | ||
public boolean isCypher5Compatible() { | ||
return neo4jConnectionSupport.isCypher5SyntaxCompatible(); | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/test/java/org/springframework/data/neo4j/integration/issues/gh2886/MagicalFruit.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright 2011-2024 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.integration.issues.gh2886; | ||
|
||
import org.springframework.data.neo4j.core.schema.Node; | ||
|
||
/** | ||
* GH-2886 | ||
*/ | ||
@Node(primaryLabel = "MagicalFruit") | ||
public class MagicalFruit extends Fruit { | ||
|
||
private double volume; | ||
|
||
private String color; | ||
|
||
public double getVolume() { | ||
return this.volume; | ||
} | ||
|
||
public String getColor() { | ||
return this.color; | ||
} | ||
|
||
public void setVolume(double volume) { | ||
this.volume = volume; | ||
} | ||
|
||
public void setColor(String color) { | ||
this.color = color; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/test/java/org/springframework/data/neo4j/integration/issues/gh2886/Orange.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright 2011-2024 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.integration.issues.gh2886; | ||
|
||
import org.springframework.data.neo4j.core.schema.Node; | ||
|
||
/** | ||
* GH-2886 | ||
*/ | ||
@Node(primaryLabel = "Orange") | ||
public class Orange extends MagicalFruit { | ||
} |