Package org.hibernate.ogm.datastore.mongodb.utils.MockMongoClientBuilder

Examples of org.hibernate.ogm.datastore.mongodb.utils.MockMongoClientBuilder.MockMongoClient


  }

  @Test
  public void shouldApplyConfiguredWriteConcernForUpdateOfAssociationStoredAsDocument() {
    // given a persisted player with one associated golf course
    MockMongoClient mockClient = mockClient()
        .insert( "GolfPlayer", getPlayer() )
        .insert( "GolfCourse", getGolfCourse() )
        .insert( "Associations", getPlayedCoursesAssociationAsDocument() )
        .build();

    setupSessionFactory( new MongoDBDatastoreProvider( mockClient.getClient() ), AssociationStorageType.ASSOCIATION_DOCUMENT );

    Session session = sessions.openSession();
    Transaction transaction = session.beginTransaction();

    // when merging the player with two associated courses
    GolfPlayer ben = new GolfPlayer( 1L, "Ben", 0.1, new GolfCourse( 1L, "Bepple Peach" ), new GolfCourse( 2L, "Ant Sandrews" ) );
    session.merge( ben );

    transaction.commit();
    session.close();

    // then expect one update to the association collection
    verify( mockClient.getCollection( "Associations" ), times( 1 ) ).update( any( DBObject.class ), any( DBObject.class ), anyBoolean(), anyBoolean(), eq( WriteConcern.MAJORITY ) );
  }
View Full Code Here


  public void shouldApplyConfiguredWriteConcernForRemovalOfEmbeddedAssociation() {
    // given a persisted player with one associated golf course
    BasicDBObject player = getPlayer();
    player.put( "playedCourses", getPlayedCoursesAssociationEmbedded() );

    MockMongoClient mockClient = mockClient()
        .insert( "GolfPlayer", player )
        .insert( "GolfCourse", getGolfCourse() )
        .build();

    setupSessionFactory( new MongoDBDatastoreProvider( mockClient.getClient() ) );

    Session session = sessions.openSession();
    Transaction transaction = session.beginTransaction();

    // when removing the association
    GolfPlayer ben = new GolfPlayer( 1L, "Ben", 0.1 );
    session.merge( ben );

    transaction.commit();
    session.close();

    // then expect one call to update using the configured write concern
    verify( mockClient.getCollection( "GolfPlayer" ) ).update( any( DBObject.class ), any( DBObject.class ), anyBoolean(), anyBoolean(), eq( WriteConcern.MAJORITY ) );
  }
View Full Code Here

  }

  @Test
  public void shouldApplyConfiguredWriteConcernForRemovalOfAssociationStoredAsDocument() {
    // given a persisted player with one associated golf course
    MockMongoClient mockClient = mockClient()
        .insert( "GolfPlayer", getPlayer() )
        .insert( "GolfCourse", getGolfCourse() )
        .insert( "Associations", getPlayedCoursesAssociationAsDocument() )
        .build();

    setupSessionFactory( new MongoDBDatastoreProvider( mockClient.getClient() ) , AssociationStorageType.ASSOCIATION_DOCUMENT );

    Session session = sessions.openSession();
    Transaction transaction = session.beginTransaction();

    // when removing the association
    GolfPlayer ben = new GolfPlayer( 1L, "Ben", 0.1 );
    session.merge( ben );

    transaction.commit();
    session.close();

    // then expect one call to remove with the configured write concern
    verify( mockClient.getCollection( "Associations" ) ).remove( any( DBObject.class ), eq( WriteConcern.MAJORITY ) );
  }
View Full Code Here

TOP

Related Classes of org.hibernate.ogm.datastore.mongodb.utils.MockMongoClientBuilder.MockMongoClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.