-
Notifications
You must be signed in to change notification settings - Fork 199
/
EmbeddableWithCollectionMappingTest.java
88 lines (69 loc) · 2.89 KB
/
EmbeddableWithCollectionMappingTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
* Hibernate OGM, Domain model persistence for NoSQL datastores
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.ogm.datastore.neo4j.test.mapping;
import static org.hibernate.ogm.datastore.neo4j.dialect.impl.NodeLabel.EMBEDDED;
import static org.hibernate.ogm.datastore.neo4j.dialect.impl.NodeLabel.ENTITY;
import static org.hibernate.ogm.datastore.neo4j.test.dsl.GraphAssertions.node;
import java.util.Arrays;
import javax.persistence.EntityManager;
import org.hibernate.ogm.backendtck.embeddable.Order;
import org.hibernate.ogm.backendtck.embeddable.PhoneNumber;
import org.hibernate.ogm.backendtck.embeddable.ShippingAddress;
import org.hibernate.ogm.datastore.neo4j.test.dsl.NodeForGraphAssertions;
import org.hibernate.ogm.datastore.neo4j.test.dsl.RelationshipsChainForGraphAssertions;
import org.junit.Before;
import org.junit.Test;
/**
* @author Davide D'Alto
*/
public class EmbeddableWithCollectionMappingTest extends Neo4jJpaTestCase {
@Before
public void prepareDB() throws Exception {
final EntityManager em = getFactory().createEntityManager();
em.getTransaction().begin();
Order order = new Order(
"order-1",
"Telescope",
new ShippingAddress(
new PhoneNumber( "+1-222-555-0111", Arrays.asList( "+1-222-555-0222", "+1-202-555-0333" ) ),
"Planet road 68"
)
);
em.persist( order );
em.getTransaction().commit();
em.close();
}
@Test
public void testMapping() throws Exception {
NodeForGraphAssertions orderNode = node( "order", Order.class.getSimpleName(), ENTITY.name())
.property( "id", "order-1")
.property( "item", "Telescope" );
NodeForGraphAssertions shippingAddressNode = node( "adress", EMBEDDED.name())
.property( "addressLine", "Planet road 68");
NodeForGraphAssertions phoneNode = node( "phone", EMBEDDED.name())
.property( "main", "+1-222-555-0111");
NodeForGraphAssertions altenative1 = node( "alt1", EMBEDDED.name())
.property( "alternatives", "+1-222-555-0222");
NodeForGraphAssertions altenative2 = node( "alt2", EMBEDDED.name())
.property( "alternatives", "+1-202-555-0333");
RelationshipsChainForGraphAssertions rel1 = orderNode.relationshipTo( shippingAddressNode, "shippingAddress" ).relationshipTo( phoneNode, "phone" ).relationshipTo( altenative1, "alternatives" );
RelationshipsChainForGraphAssertions rel2 = phoneNode.relationshipTo( altenative2, "alternatives" );
getTransactionManager().begin();
assertThatOnlyTheseNodesExist( createExecutionEngine()
, orderNode
, shippingAddressNode
, phoneNode
, altenative1
, altenative2 );
assertThatOnlyTheseRelationshipsExist( createExecutionEngine(), rel1, rel2 );
getTransactionManager().commit();
}
@Override
public Class<?>[] getEntities() {
return new Class<?>[] { Order.class };
}
}