Skip to content

Commit

Permalink
OGM-783 [Neo4j] Additional test for the mapping of collection in embe…
Browse files Browse the repository at this point in the history
…ddeds
  • Loading branch information
DavideD committed May 15, 2015
1 parent 4c4dd69 commit 927f508
Showing 1 changed file with 88 additions and 0 deletions.
@@ -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 };
}

}

0 comments on commit 927f508

Please sign in to comment.