@SuppressWarnings("unchecked")
@Test
public void shouldApplyWriteConcernConfiguredOnPropertyLevelForCreationOfAssociationStoredAsDocument() {
// given an empty database
MockMongoClient mockClient = mockClient().build();
OgmConfiguration configuration = TestHelper.getDefaultTestConfiguration( getAnnotatedClasses() );
configuration.getProperties().put( OgmProperties.DATASTORE_PROVIDER, new MongoDBDatastoreProvider( mockClient.getClient() ) );
configuration.getProperties().put( DocumentStoreProperties.ASSOCIATIONS_STORE, AssociationStorageType.ASSOCIATION_DOCUMENT );
configuration.configureOptionsFor( MongoDB.class )
.entity( GolfPlayer.class )
.writeConcern( WriteConcernType.REPLICA_ACKNOWLEDGED )
.property( "playedCourses", ElementType.FIELD )
.writeConcern( WriteConcernType.ACKNOWLEDGED );
sessions = configuration.buildSessionFactory();
Session session = sessions.openSession();
Transaction transaction = session.beginTransaction();
// when inserting a player with an associated course
GolfPlayer ben = new GolfPlayer( 1L, "Ben", 0.1, new GolfCourse( 1L, "Bepple Peach" ) );
session.persist( ben );
transaction.commit();
session.close();
// then expect tuple and association operations using the configured write concerns
verify( mockClient.getCollection( "GolfPlayer" ) ).insert( any( List.class ), eq( WriteConcern.REPLICA_ACKNOWLEDGED ) );
verify( mockClient.getCollection( "Associations" ) ).update( any( DBObject.class ), any( DBObject.class ), anyBoolean(), anyBoolean(), eq( WriteConcern.ACKNOWLEDGED ) );
}