Skip to content

Commit

Permalink
GH-2728 - Add test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
meistermeier committed May 26, 2023
1 parent 5efb9b2 commit db05e2e
Show file tree
Hide file tree
Showing 7 changed files with 218 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package org.springframework.data.neo4j.integration.issues.gh2728;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.neo4j.driver.Driver;
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.integration.issues.gh2168.UnrelatedObjectPropertyConverterAsBean;
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;

/**
* @author Gerrit Meier
*/
@Neo4jIntegrationTest
public class Neo4jVersionDependentRelationshipSaveIT {

protected static Neo4jExtension.Neo4jConnectionSupport neo4jConnectionSupport;

@Autowired
private TestEntityWithGeneratedDeprecatedId1Repository generatedDeprecatedIdRepository;

@Autowired
private TestEntityWithAssignedId1Repository assignedIdRepository;

@Test
public void testGeneratedDeprecatedIds() {
TestEntityWithGeneratedDeprecatedId2 t2 = new TestEntityWithGeneratedDeprecatedId2(null, "v2");
TestEntityWithGeneratedDeprecatedId1 t1 = new TestEntityWithGeneratedDeprecatedId1(null, "v1", t2);

TestEntityWithGeneratedDeprecatedId1 result = generatedDeprecatedIdRepository.save(t1);

TestEntityWithGeneratedDeprecatedId1 freshRetrieved = generatedDeprecatedIdRepository.findById(result.getId()).get();

Assertions.assertNotNull(result.getRelatedEntity());
Assertions.assertNotNull(freshRetrieved.getRelatedEntity()); // FAILS!
}

@Test
public void testAssignedIds() {
TestEntityWithAssignedId2 t2 = new TestEntityWithAssignedId2("second", "v2");
TestEntityWithAssignedId1 t1 = new TestEntityWithAssignedId1("first", "v1", t2);

TestEntityWithAssignedId1 result = assignedIdRepository.save(t1);

TestEntityWithAssignedId1 freshRetrieved = assignedIdRepository.findById(result.getAssignedId()).get();

Assertions.assertNotNull(result.getRelatedEntity());
Assertions.assertNotNull(freshRetrieved.getRelatedEntity()); // FAILS!
}

@Configuration
@EnableTransactionManagement
@EnableNeo4jRepositories(considerNestedRepositories = true)
static class Config extends Neo4jImperativeTestConfiguration {

@Bean
public Driver driver() {

return neo4jConnectionSupport.getDriver();
}

@Bean
public BookmarkCapture bookmarkCapture() {
return new BookmarkCapture();
}

@Bean
public UnrelatedObjectPropertyConverterAsBean converterBean() {
return new UnrelatedObjectPropertyConverterAsBean();
}

@Override
public PlatformTransactionManager transactionManager(Driver driver,
DatabaseSelectionProvider databaseNameProvider) {

BookmarkCapture bookmarkCapture = bookmarkCapture();
return new Neo4jTransactionManager(driver, databaseNameProvider,
Neo4jBookmarkManager.create(bookmarkCapture));
}

@Override
public boolean isCypher5Compatible() {
return neo4jConnectionSupport.isCypher5SyntaxCompatible();
// return false; // explicitly not compatible with Neo4j 5 although connected to one
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.springframework.data.neo4j.integration.issues.gh2728;

import org.springframework.data.neo4j.core.schema.Id;
import org.springframework.data.neo4j.core.schema.Node;
import org.springframework.data.neo4j.core.schema.Property;
import org.springframework.data.neo4j.core.schema.Relationship;

@Node
public class TestEntityWithAssignedId1 {

@Id
private String assignedId;

@Property("value_one")
private String valueOne;

@Relationship("related_to")
private TestEntityWithAssignedId2 relatedEntity;

public TestEntityWithAssignedId1(String assignedId, String valueOne, TestEntityWithAssignedId2 relatedEntity) {
this.assignedId = assignedId;
this.valueOne = valueOne;
this.relatedEntity = relatedEntity;
}
public String getAssignedId() {
return assignedId;
}

public TestEntityWithAssignedId2 getRelatedEntity() {
return relatedEntity;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.springframework.data.neo4j.integration.issues.gh2728;

import org.springframework.data.neo4j.repository.Neo4jRepository;

public interface TestEntityWithAssignedId1Repository extends Neo4jRepository<TestEntityWithAssignedId1, String> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.springframework.data.neo4j.integration.issues.gh2728;

import org.springframework.data.neo4j.core.schema.Id;
import org.springframework.data.neo4j.core.schema.Node;
import org.springframework.data.neo4j.core.schema.Property;

@Node
public class TestEntityWithAssignedId2 {

@Id
private String assignedId;

@Property("valueTwo")
private String valueTwo;

public TestEntityWithAssignedId2(String assignedId, String valueTwo) {
this.assignedId = assignedId;
this.valueTwo = valueTwo;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.springframework.data.neo4j.integration.issues.gh2728;

import org.springframework.data.neo4j.core.schema.GeneratedValue;
import org.springframework.data.neo4j.core.schema.Id;
import org.springframework.data.neo4j.core.schema.Node;
import org.springframework.data.neo4j.core.schema.Property;
import org.springframework.data.neo4j.core.schema.Relationship;

@Node
public class TestEntityWithGeneratedDeprecatedId1 {

@Id
@GeneratedValue
private Long id;

@Property("value_one")
private String valueOne;

@Relationship("related_to")
private TestEntityWithGeneratedDeprecatedId2 relatedEntity;

public TestEntityWithGeneratedDeprecatedId1(Long id, String valueOne, TestEntityWithGeneratedDeprecatedId2 relatedEntity) {
this.id = id;
this.valueOne = valueOne;
this.relatedEntity = relatedEntity;
}
public Long getId() {
return id;
}

public TestEntityWithGeneratedDeprecatedId2 getRelatedEntity() {
return relatedEntity;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.springframework.data.neo4j.integration.issues.gh2728;

import org.springframework.data.neo4j.repository.Neo4jRepository;

public interface TestEntityWithGeneratedDeprecatedId1Repository extends Neo4jRepository<TestEntityWithGeneratedDeprecatedId1, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.springframework.data.neo4j.integration.issues.gh2728;

import org.springframework.data.neo4j.core.schema.GeneratedValue;
import org.springframework.data.neo4j.core.schema.Id;
import org.springframework.data.neo4j.core.schema.Node;
import org.springframework.data.neo4j.core.schema.Property;

@Node
public class TestEntityWithGeneratedDeprecatedId2 {

@Id
@GeneratedValue
private Long id;

@Property("valueTwo")
private String valueTwo;

public TestEntityWithGeneratedDeprecatedId2(Long id, String valueTwo) {
this.id = id;
this.valueTwo = valueTwo;
}
}

0 comments on commit db05e2e

Please sign in to comment.