@Test
  @SkipByDatastoreProvider(DatastoreProviderType.FONGO)
  public void testDefaultAuthenticationMechanism() throws Exception {
    LeakingMongoDBDatastoreProvider provider = new LeakingMongoDBDatastoreProvider();
    cfg.put(OgmProperties.DATASTORE_PROVIDER, provider);

    // will start the service
    TestHelper.getDefaultTestStandardServiceRegistry(cfg).getService(DatastoreProvider.class);

    assertThat(provider.leakingClient.getCredentialsList().get(0).getMechanism()).isEqualTo(null);
  }
  @Test
  @SkipByDatastoreProvider(DatastoreProviderType.FONGO)
  public void testConnectionErrorWrappedInHibernateException() throws Exception {
    cfg.put(OgmProperties.HOST, NON_EXISTENT_IP);

    error.expect(ServiceException.class);
    error.expectMessage("OGM000071");
    // nested exception
    error.expectCause(hasMessage(containsString("OGM001214")));

    // will start the service
    TestHelper.getDefaultTestStandardServiceRegistry(cfg).getService(DatastoreProvider.class);
  }
  @Test
  @SkipByDatastoreProvider(DatastoreProviderType.FONGO)
  public void testNotRecognizedAuthenticationMechanism() throws Exception {
    cfg.put(MongoDBProperties.AUTHENTICATION_MECHANISM, "alhdfoiehfnl");

    error.expect(ServiceException.class);
    error.expectMessage("OGM000072");
    // nested exception
    error.expectCause(hasMessage(containsString("OGM000051")));

    // will start the service
    TestHelper.getDefaultTestStandardServiceRegistry(cfg).getService(DatastoreProvider.class);
  }
  @Test
  @SkipByDatastoreProvider(DatastoreProviderType.FONGO)
  public void testSCRAMSHA1AuthenticationMechanism() throws Exception {
    LeakingMongoDBDatastoreProvider provider = new LeakingMongoDBDatastoreProvider();
    cfg.put(
        MongoDBProperties.AUTHENTICATION_MECHANISM, AuthenticationMechanismType.SCRAM_SHA_1.name());
    cfg.put(OgmProperties.DATASTORE_PROVIDER, provider);

    // will start the service
    TestHelper.getDefaultTestStandardServiceRegistry(cfg).getService(DatastoreProvider.class);

    assertThat(provider.leakingClient.getCredentialsList().get(0).getMechanism())
        .isEqualTo(MongoCredential.SCRAM_SHA_1_MECHANISM);
  }
  @Test
  @SkipByDatastoreProvider(DatastoreProviderType.FONGO)
  public void testAuthentication() throws Exception {
    error.expect(ServiceException.class);
    error.expectMessage("OGM000071");
    // the timeout exception thrown by the driver will actually contain some information about the
    // authentication
    // error. Obviously quite fragile. Might change
    error.expectCause(hasMessage(containsString("Exception authenticating")));

    StandardServiceRegistry serviceRegistry = TestHelper.getDefaultTestStandardServiceRegistry(cfg);

    // will start the service
    serviceRegistry.getService(DatastoreProvider.class);
  }
  @Test
  @SkipByDatastoreProvider(DatastoreProviderType.FONGO)
  public void testConnectionTimeout() {
    cfg.put(OgmProperties.HOST, NON_EXISTENT_IP);
    cfg.put(OgmProperties.DATABASE, "ogm_test_database");

    error.expect(ServiceException.class);
    error.expectMessage("OGM000071");
    // the timeout exception thrown by the driver will actually contain some information about the
    // authentication
    // error. Obviously quite fragile. Might change
    error.expectCause(hasMessage(containsString("Timed out")));

    // will start the service
    TestHelper.getDefaultTestStandardServiceRegistry(cfg).getService(DatastoreProvider.class);
  }