Skip to content

Commit

Permalink
OGM-1225 Fix query that counts the number of associations created in …
Browse files Browse the repository at this point in the history
…Neo4j
  • Loading branch information
DavideD authored and gsmet committed Dec 20, 2016
1 parent 0c85461 commit d702fc0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 21 deletions.
Expand Up @@ -6,23 +6,17 @@
*/
package org.hibernate.ogm.backendtck.associations.collection.manytomany;

import static org.hibernate.ogm.utils.GridDialectType.NEO4J_EMBEDDED;
import static org.hibernate.ogm.utils.GridDialectType.NEO4J_REMOTE;
import java.util.EnumSet;
import static org.fest.assertions.Assertions.assertThat;
import static org.hibernate.ogm.utils.TestHelper.getNumberOfAssociations;
import static org.hibernate.ogm.utils.TestHelper.getNumberOfEntities;

import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.ogm.utils.GridDialectType;
import org.hibernate.ogm.utils.OgmTestCase;
import org.hibernate.ogm.utils.SkipByGridDialect;
import org.hibernate.ogm.utils.TestHelper;

import org.junit.Test;

import static org.fest.assertions.Assertions.assertThat;
import static org.hibernate.ogm.utils.TestHelper.getNumberOfAssociations;
import static org.hibernate.ogm.utils.TestHelper.getNumberOfEntities;

/**
* @author Emmanuel Bernard <emmanuel@hibernate.org>
*/
Expand Down Expand Up @@ -52,7 +46,7 @@ public void testUnidirectionalManyToMany() {
tx.commit();

assertThat( getNumberOfEntities( sessionFactory ) ).isEqualTo( 5 );
assertThat( getNumberOfAssociations( sessionFactory ) ).isEqualTo( expectedAssociationNumber() );
assertThat( getNumberOfAssociations( sessionFactory ) ).isEqualTo( 2 );
session.clear();

delete( session, math, english, john, mario, kate );
Expand All @@ -75,16 +69,6 @@ private void delete(Session session, Object... entities) {
transaction.commit();
}

private int expectedAssociationNumber() {
if ( EnumSet.of( NEO4J_EMBEDDED, NEO4J_REMOTE ).contains( TestHelper.getCurrentDialectType() ) ) {
// In Neo4j relationships are bidirectional
return 1;
}
else {
return 2;
}
}

@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] {
Expand Down
Expand Up @@ -28,7 +28,7 @@ public interface Neo4jTestHelperDelegate {
String ENTITY_COUNT_QUERY = "MATCH (n) WHERE n:" + NodeLabel.ENTITY.name() + " OR n:" + NodeLabel.EMBEDDED.name()
+ " RETURN COUNT(n) as count";

String ASSOCIATION_COUNT_QUERY = "MATCH (n) -[r]-> () RETURN COUNT(DISTINCT type(r)) as count";
String ASSOCIATION_COUNT_QUERY = "MATCH (n) -[r]-> () WITH n as e, count(distinct(type(r))) as c RETURN count(*) as count";

String DELETE_ALL = "MATCH (n) OPTIONAL MATCH (n) -[r]-> () DELETE n,r";

Expand Down

0 comments on commit d702fc0

Please sign in to comment.