|
19 | 19 | import java.math.BigInteger;
|
20 | 20 | import java.math.RoundingMode;
|
21 | 21 | import java.util.Arrays;
|
| 22 | +import java.util.Optional; |
22 | 23 |
|
23 | 24 | import org.junit.Before;
|
24 | 25 | import org.junit.Test;
|
|
29 | 30 | import org.neo4j.ogm.session.SessionFactory;
|
30 | 31 | import org.springframework.beans.factory.annotation.Autowired;
|
31 | 32 | import org.springframework.context.annotation.Bean;
|
32 |
| -import org.springframework.context.annotation.ComponentScan; |
33 | 33 | import org.springframework.context.annotation.Configuration;
|
34 | 34 | import org.springframework.core.convert.ConversionService;
|
35 | 35 | import org.springframework.core.convert.ConverterNotFoundException;
|
36 | 36 | import org.springframework.core.convert.support.DefaultConversionService;
|
37 | 37 | import org.springframework.data.neo4j.conversion.MetaDataDrivenConversionService;
|
| 38 | +import org.springframework.data.neo4j.conversion.gh2213.DescribeType; |
| 39 | +import org.springframework.data.neo4j.conversion.gh2213.Describes; |
| 40 | +import org.springframework.data.neo4j.conversion.gh2213.NodeB; |
| 41 | +import org.springframework.data.neo4j.conversion.gh2213.RepositoryUnderTest; |
| 42 | +import org.springframework.data.neo4j.conversion.gh2213.NodeA; |
38 | 43 | import org.springframework.data.neo4j.integration.conversion.domain.JavaElement;
|
39 | 44 | import org.springframework.data.neo4j.integration.conversion.domain.MonetaryAmount;
|
40 | 45 | import org.springframework.data.neo4j.integration.conversion.domain.PensionPlan;
|
@@ -65,6 +70,8 @@ public class ConversionServiceTests {
|
65 | 70 | @Autowired private PensionRepository pensionRepository;
|
66 | 71 | @Autowired private JavaElementRepository javaElementRepository;
|
67 | 72 | @Autowired private SiteMemberRepository siteMemberRepository;
|
| 73 | + @Autowired private RepositoryUnderTest repositoryUnderTest; |
| 74 | + |
68 | 75 | // TODO See below, for the time being at least be explicit on which type of conversion service we're working on here
|
69 | 76 | // The only thing that is under test, is the instance of MetaDataDrivenConversionService which get's even
|
70 | 77 | // modified heavily be this test. This needs to be fixed in the near future.
|
@@ -251,9 +258,28 @@ public void shouldRecognizeJavaEnums() {
|
251 | 258 | assertThat(siteMember.getRoundingModes().contains(RoundingMode.FLOOR)).isTrue();
|
252 | 259 | }
|
253 | 260 |
|
| 261 | + @Test // GH-2213 |
| 262 | + public void enumConvertersOnConstructorsShouldWork() { |
| 263 | + |
| 264 | + long id = transactionTemplate.execute(tx -> { |
| 265 | + NodeA s = new NodeA(DescribeType.A); |
| 266 | + Describes d = new Describes(DescribeType.B, s, new NodeB()); |
| 267 | + |
| 268 | + s.setDescribes(Arrays.asList(d)); |
| 269 | + return repositoryUnderTest.save(s).getId(); |
| 270 | + }); |
| 271 | + Optional<NodeA> optionalResult = repositoryUnderTest.findById(id); |
| 272 | + assertThat(optionalResult).hasValueSatisfying(nl -> { |
| 273 | + assertThat(nl.getDescribeType()).isEqualTo(DescribeType.A); |
| 274 | + assertThat(nl.getDescribes()).hasSize(1) |
| 275 | + .first().satisfies(dl -> assertThat(dl.getSomething()).isEqualTo(DescribeType.B)); |
| 276 | + }); |
| 277 | + |
| 278 | + } |
| 279 | + |
254 | 280 | @Configuration
|
255 |
| - @Neo4jIntegrationTest(domainPackages = "org.springframework.data.neo4j.integration.conversion.domain", |
256 |
| - repositoryPackages = "org.springframework.data.neo4j.integration.conversion") |
| 281 | + @Neo4jIntegrationTest(domainPackages = {"org.springframework.data.neo4j.integration.conversion.domain", "org.springframework.data.neo4j.conversion.gh2213"}, |
| 282 | + repositoryPackages = {"org.springframework.data.neo4j.integration.conversion", "org.springframework.data.neo4j.conversion.gh2213"}) |
257 | 283 | static class ConversionServicePersistenceContext {
|
258 | 284 |
|
259 | 285 | @Bean
|
|
0 commit comments