1+ /*
2+ * Copyright 2011-2021 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.imperative
17+
18+ import org.junit.jupiter.api.Assertions.assertNotNull
19+ import org.junit.jupiter.api.BeforeAll
20+ import org.junit.jupiter.api.Test
21+ import org.neo4j.driver.Driver
22+ import org.springframework.beans.factory.annotation.Autowired
23+ import org.springframework.context.annotation.Bean
24+ import org.springframework.context.annotation.Configuration
25+ import org.springframework.data.neo4j.config.AbstractNeo4jConfig
26+ import org.springframework.data.neo4j.core.DatabaseSelectionProvider
27+ import org.springframework.data.neo4j.core.transaction.Neo4jBookmarkManager
28+ import org.springframework.data.neo4j.core.transaction.Neo4jTransactionManager
29+ import org.springframework.data.neo4j.integration.shared.common.TestNode
30+ import org.springframework.data.neo4j.repository.Neo4jRepository
31+ import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories
32+ import org.springframework.data.neo4j.repository.query.Query
33+ import org.springframework.data.neo4j.test.BookmarkCapture
34+ import org.springframework.data.neo4j.test.Neo4jExtension
35+ import org.springframework.data.neo4j.test.Neo4jIntegrationTest
36+ import org.springframework.transaction.PlatformTransactionManager
37+ import org.springframework.transaction.annotation.EnableTransactionManagement
38+
39+ @Neo4jIntegrationTest
40+ class Neo4jListContainsTest {
41+
42+ companion object {
43+ @JvmStatic
44+ private lateinit var neo4jConnectionSupport: Neo4jExtension .Neo4jConnectionSupport
45+
46+ @BeforeAll
47+ @JvmStatic
48+ fun prepareDatabase (@Autowired driver : Driver , @Autowired bookmarkCapture : BookmarkCapture ) {
49+ driver.session().use { session ->
50+ session.run (" MATCH (n) DETACH DELETE n" ).consume()
51+ session.run (" CREATE (testNode:GH2444{id: 1, items: ['item 1', 'item 2', 'item 3'], description: 'desc 1'})" ).consume();
52+ bookmarkCapture.seedWith(session.lastBookmark())
53+ }
54+ }
55+ }
56+
57+ @Autowired
58+ private lateinit var testNodeRepository: TestNodeRepository
59+
60+ @Test
61+ fun `Should find test node by items containing` () {
62+ val testNode = testNodeRepository.findByItemsContains(" item 2" )
63+ assertNotNull(testNode)
64+ }
65+
66+ @Test
67+ fun `Should find test node by using explicit query` () {
68+ val testNode = testNodeRepository.findByItemsContainsWithExplicitQuery(" item 2" )
69+ assertNotNull(testNode)
70+ }
71+
72+ @Test
73+ fun `Should find test node by description in` () {
74+ val testNode = testNodeRepository.findByDescriptionIn(listOf (" desc 1" , " desc 2" , " desc 3" ))
75+ assertNotNull(testNode)
76+ }
77+
78+ @Configuration
79+ @EnableTransactionManagement
80+ @EnableNeo4jRepositories
81+ open class MyConfig : AbstractNeo4jConfig () {
82+ @Bean
83+ override fun driver (): Driver {
84+ return neo4jConnectionSupport.driver
85+ }
86+
87+ @Bean
88+ open fun bookmarkCapture (): BookmarkCapture {
89+ return BookmarkCapture ()
90+ }
91+
92+ @Bean
93+ override fun transactionManager (driver : Driver , databaseNameProvider : DatabaseSelectionProvider ): PlatformTransactionManager {
94+ val bookmarkCapture = bookmarkCapture()
95+ return Neo4jTransactionManager (driver, databaseNameProvider, Neo4jBookmarkManager .create(bookmarkCapture))
96+ }
97+ }
98+ }
99+
100+ interface TestNodeRepository : Neo4jRepository <TestNode , Long > {
101+
102+ fun findByItemsContains (item : String ): TestNode ?
103+
104+ @Query(""" MATCH (t:GH2444) WHERE ${" $" } item IN t.items RETURN t""" )
105+ fun findByItemsContainsWithExplicitQuery (item : String ): TestNode ?
106+
107+ fun findByDescriptionIn (descriptions : List <String >): TestNode ?
108+ }
0 commit comments