Skip to content

Commit a880c97

Browse files
GH-2498 - Add additional tests to ensure CypherDSL condition executioner works with anon parameters.
1 parent d409063 commit a880c97

File tree

3 files changed

+176
-0
lines changed

3 files changed

+176
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2011-2022 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.integration.issues.gh2498;
17+
18+
import java.util.UUID;
19+
20+
import org.springframework.data.neo4j.core.schema.GeneratedValue;
21+
import org.springframework.data.neo4j.core.schema.Id;
22+
import org.springframework.data.neo4j.core.schema.Node;
23+
24+
/**
25+
* @author Michael J. Simons
26+
*/
27+
@Node
28+
public class DomainModel {
29+
30+
@Id @GeneratedValue UUID id;
31+
32+
private final String name;
33+
34+
public DomainModel(String name) {
35+
this.name = name;
36+
}
37+
38+
public UUID getId() {
39+
return id;
40+
}
41+
42+
public String getName() {
43+
return name;
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2011-2022 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.integration.issues.gh2498;
17+
18+
import java.util.UUID;
19+
20+
import org.springframework.data.neo4j.repository.Neo4jRepository;
21+
import org.springframework.data.neo4j.repository.support.CypherdslConditionExecutor;
22+
23+
/**
24+
* @author Michael J. Simons
25+
*/
26+
public interface DomainModelRepository extends Neo4jRepository<DomainModel, UUID>, CypherdslConditionExecutor<DomainModel> {
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
* Copyright 2011-2022 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.integration.issues.gh2498;
17+
18+
import java.util.Arrays;
19+
import java.util.Collection;
20+
import java.util.List;
21+
22+
import org.assertj.core.api.Assertions;
23+
import org.junit.jupiter.api.BeforeEach;
24+
import org.junit.jupiter.api.Test;
25+
import org.neo4j.cypherdsl.core.Condition;
26+
import org.neo4j.cypherdsl.core.Cypher;
27+
import org.neo4j.cypherdsl.core.Node;
28+
import org.neo4j.cypherdsl.core.Parameter;
29+
import org.neo4j.cypherdsl.core.Property;
30+
import org.neo4j.driver.Driver;
31+
import org.neo4j.driver.Session;
32+
import org.springframework.beans.factory.annotation.Autowired;
33+
import org.springframework.context.annotation.Bean;
34+
import org.springframework.context.annotation.Configuration;
35+
import org.springframework.data.neo4j.config.AbstractNeo4jConfig;
36+
import org.springframework.data.neo4j.core.DatabaseSelectionProvider;
37+
import org.springframework.data.neo4j.core.transaction.Neo4jBookmarkManager;
38+
import org.springframework.data.neo4j.core.transaction.Neo4jTransactionManager;
39+
import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories;
40+
import org.springframework.data.neo4j.test.BookmarkCapture;
41+
import org.springframework.data.neo4j.test.Neo4jExtension;
42+
import org.springframework.data.neo4j.test.Neo4jIntegrationTest;
43+
import org.springframework.transaction.PlatformTransactionManager;
44+
import org.springframework.transaction.annotation.EnableTransactionManagement;
45+
46+
/**
47+
* @author Michael J. Simons
48+
*/
49+
@Neo4jIntegrationTest
50+
public class GH2498IT {
51+
52+
protected static Neo4jExtension.Neo4jConnectionSupport neo4jConnectionSupport;
53+
54+
@BeforeEach
55+
void setupData(@Autowired Driver driver, @Autowired BookmarkCapture bookmarkCapture) {
56+
57+
try (Session session = driver.session()) {
58+
session.writeTransaction(tx -> tx.run("MATCH (n:DomainModel) DETACH DELETE n").consume());
59+
session.writeTransaction(tx -> tx.run(
60+
"UNWIND ['A', 'B', 'C'] AS name WITH name CREATE (n:DomainModel {id: randomUUID(), name: name})")
61+
.consume());
62+
bookmarkCapture.seedWith(session.lastBookmark());
63+
}
64+
}
65+
66+
@Test // GH-2498
67+
void cypherdslConditionExecutorShouldWorkWithAnonParameters(@Autowired DomainModelRepository repository) {
68+
69+
Node node = Cypher.node("DomainModel").named("n");
70+
Property name = node.property("name");
71+
Parameter<List<String>> parameters = Cypher.anonParameter(Arrays.asList("A", "C"));
72+
Condition in = name.in(parameters);
73+
Collection<DomainModel> result = repository.findAll(in, Cypher.sort(name).descending());
74+
Assertions.assertThat(result).hasSize(2)
75+
.map(DomainModel::getName)
76+
.containsExactly("C", "A");
77+
}
78+
79+
@Configuration
80+
@EnableTransactionManagement
81+
@EnableNeo4jRepositories
82+
static class Config extends AbstractNeo4jConfig {
83+
84+
@Bean
85+
public BookmarkCapture bookmarkCapture() {
86+
return new BookmarkCapture();
87+
}
88+
89+
@Override
90+
public PlatformTransactionManager transactionManager(
91+
Driver driver, DatabaseSelectionProvider databaseNameProvider) {
92+
93+
BookmarkCapture bookmarkCapture = bookmarkCapture();
94+
return new Neo4jTransactionManager(driver, databaseNameProvider,
95+
Neo4jBookmarkManager.create(bookmarkCapture));
96+
}
97+
98+
@Bean
99+
public Driver driver() {
100+
101+
return neo4jConnectionSupport.getDriver();
102+
}
103+
}
104+
}

0 commit comments

Comments
 (0)