Java is complicated
Actually I’m at the beginning of my app and what you see is pretty much I have.
The complete test case:
@Test
public void testProjectAssociation() {
User user = new User();
user.setName("My user");
Project project = new Project();
project.setName("My project");
project.setOwner(user);
project = new Project();
project.setName("My project");
project.setOwner(user);
user = userRepository.save(user);
project = projectRepository.save(project);
assertEquals("My user", project.getOwner().getName());
assertEquals(2, user.getProjects().size());
projectRepository.delete(project);
projectRepository.flush();
userRepository.flush();
//user.getProjects().remove(project);
assertEquals("My user", project.getOwner().getName());
assertEquals(1, user.getProjects().size());
}
The log:
2019-01-28 22:15:39.213 INFO 74436 --- [ main] o.s.t.c.transaction.TransactionContext : Began transaction (1) for test context [DefaultTestContext@33afa13b testClass = UserTest, testInstance = com.diffshelf.domain.UserTest@78aab498, testMethod = testProjectAssociation@UserTest, testException = [null], mergedContextConfiguration = [MergedContextConfiguration@7a4ccb53 testClass = UserTest, locations = '{}', classes = '{class com.diffshelf.DiffshelfApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTestContextBootstrapper=true}', contextCustomizers = set[[ImportsContextCustomizer@309e345f key = [org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration, org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration, org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration, org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration, org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration, org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration, org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration, org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration, org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration, org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfiguration, org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManagerAutoConfiguration]], org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@13eb8acf, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@43738a82, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.autoconfigure.OverrideAutoConfigurationContextCustomizerFactory$DisableAutoConfigurationContextCustomizer@401e7803, org.springframework.boot.test.autoconfigure.filter.TypeExcludeFiltersContextCustomizer@351584c0, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@20395fc8, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@27d415d9], contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map[[empty]]]; transaction manager [org.springframework.orm.jpa.JpaTransactionManager@9cfc77]; rollback [true]
2019-01-28 22:15:39.270 DEBUG 74436 --- [ main] org.hibernate.SQL : call next value for hibernate_sequence
Hibernate: call next value for hibernate_sequence
2019-01-28 22:15:39.292 DEBUG 74436 --- [ main] org.hibernate.SQL : call next value for hibernate_sequence
Hibernate: call next value for hibernate_sequence
2019-01-28 22:15:39.312 DEBUG 74436 --- [ main] org.hibernate.SQL : insert into users (createdAt, updatedAt, email, name, id) values (?, ?, ?, ?, ?)
Hibernate: insert into users (createdAt, updatedAt, email, name, id) values (?, ?, ?, ?, ?)
2019-01-28 22:15:39.314 TRACE 74436 --- [ main] o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [TIMESTAMP] - [2019-01-28T22:15:39.309]
2019-01-28 22:15:39.316 TRACE 74436 --- [ main] o.h.type.descriptor.sql.BasicBinder : binding parameter [2] as [TIMESTAMP] - [2019-01-28T22:15:39.310]
2019-01-28 22:15:39.316 TRACE 74436 --- [ main] o.h.type.descriptor.sql.BasicBinder : binding parameter [3] as [VARCHAR] - [null]
2019-01-28 22:15:39.317 TRACE 74436 --- [ main] o.h.type.descriptor.sql.BasicBinder : binding parameter [4] as [VARCHAR] - [My user]
2019-01-28 22:15:39.317 TRACE 74436 --- [ main] o.h.type.descriptor.sql.BasicBinder : binding parameter [5] as [INTEGER] - [1]
2019-01-28 22:15:39.318 DEBUG 74436 --- [ main] org.hibernate.SQL : insert into projects (createdAt, updatedAt, apiKey, name, owner_id, id) values (?, ?, ?, ?, ?, ?)
Hibernate: insert into projects (createdAt, updatedAt, apiKey, name, owner_id, id) values (?, ?, ?, ?, ?, ?)
2019-01-28 22:15:39.318 TRACE 74436 --- [ main] o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [TIMESTAMP] - [2019-01-28T22:15:39.318]
2019-01-28 22:15:39.318 TRACE 74436 --- [ main] o.h.type.descriptor.sql.BasicBinder : binding parameter [2] as [TIMESTAMP] - [2019-01-28T22:15:39.318]
2019-01-28 22:15:39.318 TRACE 74436 --- [ main] o.h.type.descriptor.sql.BasicBinder : binding parameter [3] as [VARCHAR] - [null]
2019-01-28 22:15:39.318 TRACE 74436 --- [ main] o.h.type.descriptor.sql.BasicBinder : binding parameter [4] as [VARCHAR] - [My project]
2019-01-28 22:15:39.318 TRACE 74436 --- [ main] o.h.type.descriptor.sql.BasicBinder : binding parameter [5] as [INTEGER] - [1]
2019-01-28 22:15:39.318 TRACE 74436 --- [ main] o.h.type.descriptor.sql.BasicBinder : binding parameter [6] as [INTEGER] - [2]
2019-01-28 22:15:39.322 DEBUG 74436 --- [ main] org.hibernate.SQL : delete from projects where id=?
Hibernate: delete from projects where id=?
2019-01-28 22:15:39.322 TRACE 74436 --- [ main] o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [INTEGER] - [2]
2019-01-28 22:15:39.330 INFO 74436 --- [ main] o.s.t.c.transaction.TransactionContext : Rolled back transaction for test: [DefaultTestContext@33afa13b testClass = UserTest, testInstance = com.diffshelf.domain.UserTest@78aab498, testMethod = testProjectAssociation@UserTest, testException = java.lang.AssertionError: expected:<1> but was:<2>, mergedContextConfiguration = [MergedContextConfiguration@7a4ccb53 testClass = UserTest, locations = '{}', classes = '{class com.diffshelf.DiffshelfApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTestContextBootstrapper=true}', contextCustomizers = set[[ImportsContextCustomizer@309e345f key = [org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration, org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration, org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration, org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration, org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration, org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration, org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration, org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration, org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration, org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfiguration, org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManagerAutoConfiguration]], org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@13eb8acf, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@43738a82, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.autoconfigure.OverrideAutoConfigurationContextCustomizerFactory$DisableAutoConfigurationContextCustomizer@401e7803, org.springframework.boot.test.autoconfigure.filter.TypeExcludeFiltersContextCustomizer@351584c0, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@20395fc8, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@27d415d9], contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map[[empty]]]
What do you mean with the data access logic that you are executing
?