Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OGM-783 [Neo4j] Additional test for the mapping of collection in embe…
…ddeds
- Loading branch information
Showing
1 changed file
with
88 additions
and
0 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
...a/org/hibernate/ogm/datastore/neo4j/test/mapping/EmbeddableWithCollectionMappingTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 }; | ||
} | ||
|
||
} |