Program: 37621
Project: 37621
Buggy source:
@Test public void canCRUDSqlDatabaseWithElasticPool() throws Exception {
  SqlServer sqlServer=createSqlServer();
  Creatable<SqlElasticPool> sqlElasticPoolCreatable=sqlServer.elasticPools().define(SQL_ELASTIC_POOL_NAME).withEdition(ElasticPoolEditions.STANDARD);
  Observable<Indexable> resourceStream=sqlServer.databases().define(SQL_DATABASE_NAME).withNewElasticPool(sqlElasticPoolCreatable).withCollation(COLLATION).createAsync();
  SqlDatabase sqlDatabase=Utils.<SqlDatabase>rootResource(resourceStream).toBlocking().first();
  validateSqlDatabase(sqlDatabase,SQL_DATABASE_NAME);
  sqlServer=sqlServerManager.sqlServers().getByResourceGroup(RG_NAME,SQL_SERVER_NAME);
  validateSqlServer(sqlServer);
  SqlElasticPool elasticPool=sqlServer.elasticPools().get(SQL_ELASTIC_POOL_NAME);
  validateSqlElasticPool(elasticPool);
  validateSqlDatabaseWithElasticPool(sqlServer.databases().get(SQL_DATABASE_NAME),SQL_DATABASE_NAME);
  validateListSqlDatabase(sqlServer.databases().list());
  sqlDatabase.update().withoutElasticPool().withEdition(DatabaseEditions.STANDARD).withServiceObjective(ServiceObjectiveName.S3).apply();
  sqlDatabase=sqlServer.databases().get(SQL_DATABASE_NAME);
  Assert.assertNull(sqlDatabase.elasticPoolName());
  sqlDatabase.update().withEdition(DatabaseEditions.PREMIUM).withServiceObjective(ServiceObjectiveName.P1).apply();
  sqlDatabase=sqlServer.databases().get(SQL_DATABASE_NAME);
  Assert.assertEquals(sqlDatabase.edition(),DatabaseEditions.PREMIUM);
  Assert.assertEquals(sqlDatabase.serviceLevelObjective(),ServiceObjectiveName.P1);
  sqlDatabase.update().withServiceObjective(ServiceObjectiveName.P2).apply();
  sqlDatabase=sqlServer.databases().get(SQL_DATABASE_NAME);
  Assert.assertEquals(sqlDatabase.serviceLevelObjective(),ServiceObjectiveName.P2);
  Assert.assertEquals(sqlDatabase.requestedServiceObjectiveName(),ServiceObjectiveName.P2);
  sqlDatabase.update().withMaxSizeBytes(268435456000L).apply();
  sqlDatabase=sqlServer.databases().get(SQL_DATABASE_NAME);
  Assert.assertEquals(sqlDatabase.maxSizeBytes(),268435456000L);
  sqlDatabase.update().withExistingElasticPool(SQL_ELASTIC_POOL_NAME).apply();
  sqlDatabase=sqlServer.databases().get(SQL_DATABASE_NAME);
  Assert.assertEquals(sqlDatabase.elasticPoolName(),SQL_ELASTIC_POOL_NAME);
  Assert.assertNotNull(elasticPool.listActivities());
  Assert.assertNotNull(elasticPool.listDatabaseActivities());
  List<SqlDatabase> databasesInElasticPool=elasticPool.listDatabases();
  Assert.assertNotNull(databasesInElasticPool);
  Assert.assertEquals(databasesInElasticPool.size(),1);
  SqlDatabase databaseInElasticPool=elasticPool.getDatabase(SQL_DATABASE_NAME);
  validateSqlDatabase(databaseInElasticPool,SQL_DATABASE_NAME);
  databaseInElasticPool.refresh();
  SqlDatabase db_which_does_not_exist=elasticPool.getDatabase("String_Node_Str");
  Assert.assertNull(db_which_does_not_exist);
  sqlServer.databases().delete(SQL_DATABASE_NAME);
  validateSqlDatabaseNotFound(SQL_DATABASE_NAME);
  SqlElasticPool sqlElasticPool=sqlServer.elasticPools().get(SQL_ELASTIC_POOL_NAME);
  resourceStream=sqlServer.databases().define("String_Node_Str").withExistingElasticPool(sqlElasticPool).withCollation(COLLATION).createAsync();
  sqlDatabase=Utils.<SqlDatabase>rootResource(resourceStream).toBlocking().first();
  sqlServer.databases().delete(sqlDatabase.name());
  validateSqlDatabaseNotFound("String_Node_Str");
  sqlServer.elasticPools().delete(SQL_ELASTIC_POOL_NAME);
  sqlServerManager.sqlServers().deleteByResourceGroup(sqlServer.resourceGroupName(),sqlServer.name());
  validateSqlServerNotFound(sqlServer);
}

Fixed version (ground truth):
@Test public void canCRUDSqlDatabaseWithElasticPool() throws Exception {
  SqlServer sqlServer=createSqlServer();
  Creatable<SqlElasticPool> sqlElasticPoolCreatable=sqlServer.elasticPools().define(SQL_ELASTIC_POOL_NAME).withEdition(ElasticPoolEditions.STANDARD).withTag("String_Node_Str","String_Node_Str");
  Observable<Indexable> resourceStream=sqlServer.databases().define(SQL_DATABASE_NAME).withNewElasticPool(sqlElasticPoolCreatable).withCollation(COLLATION).createAsync();
  SqlDatabase sqlDatabase=Utils.<SqlDatabase>rootResource(resourceStream).toBlocking().first();
  validateSqlDatabase(sqlDatabase,SQL_DATABASE_NAME);
  sqlServer=sqlServerManager.sqlServers().getByResourceGroup(RG_NAME,SQL_SERVER_NAME);
  validateSqlServer(sqlServer);
  SqlElasticPool elasticPool=sqlServer.elasticPools().get(SQL_ELASTIC_POOL_NAME);
  validateSqlElasticPool(elasticPool);
  validateSqlDatabaseWithElasticPool(sqlServer.databases().get(SQL_DATABASE_NAME),SQL_DATABASE_NAME);
  validateListSqlDatabase(sqlServer.databases().list());
  sqlDatabase.update().withoutElasticPool().withEdition(DatabaseEditions.STANDARD).withServiceObjective(ServiceObjectiveName.S3).apply();
  sqlDatabase=sqlServer.databases().get(SQL_DATABASE_NAME);
  Assert.assertNull(sqlDatabase.elasticPoolName());
  sqlDatabase.update().withEdition(DatabaseEditions.PREMIUM).withServiceObjective(ServiceObjectiveName.P1).apply();
  sqlDatabase=sqlServer.databases().get(SQL_DATABASE_NAME);
  Assert.assertEquals(sqlDatabase.edition(),DatabaseEditions.PREMIUM);
  Assert.assertEquals(sqlDatabase.serviceLevelObjective(),ServiceObjectiveName.P1);
  sqlDatabase.update().withServiceObjective(ServiceObjectiveName.P2).apply();
  sqlDatabase=sqlServer.databases().get(SQL_DATABASE_NAME);
  Assert.assertEquals(sqlDatabase.serviceLevelObjective(),ServiceObjectiveName.P2);
  Assert.assertEquals(sqlDatabase.requestedServiceObjectiveName(),ServiceObjectiveName.P2);
  sqlDatabase.update().withMaxSizeBytes(268435456000L).apply();
  sqlDatabase=sqlServer.databases().get(SQL_DATABASE_NAME);
  Assert.assertEquals(sqlDatabase.maxSizeBytes(),268435456000L);
  sqlDatabase.update().withExistingElasticPool(SQL_ELASTIC_POOL_NAME).apply();
  sqlDatabase=sqlServer.databases().get(SQL_DATABASE_NAME);
  Assert.assertEquals(sqlDatabase.elasticPoolName(),SQL_ELASTIC_POOL_NAME);
  Assert.assertNotNull(elasticPool.listActivities());
  Assert.assertNotNull(elasticPool.listDatabaseActivities());
  List<SqlDatabase> databasesInElasticPool=elasticPool.listDatabases();
  Assert.assertNotNull(databasesInElasticPool);
  Assert.assertEquals(databasesInElasticPool.size(),1);
  SqlDatabase databaseInElasticPool=elasticPool.getDatabase(SQL_DATABASE_NAME);
  validateSqlDatabase(databaseInElasticPool,SQL_DATABASE_NAME);
  databaseInElasticPool.refresh();
  SqlDatabase db_which_does_not_exist=elasticPool.getDatabase("String_Node_Str");
  Assert.assertNull(db_which_does_not_exist);
  sqlServer.databases().delete(SQL_DATABASE_NAME);
  validateSqlDatabaseNotFound(SQL_DATABASE_NAME);
  SqlElasticPool sqlElasticPool=sqlServer.elasticPools().get(SQL_ELASTIC_POOL_NAME);
  resourceStream=sqlServer.databases().define("String_Node_Str").withExistingElasticPool(sqlElasticPool).withCollation(COLLATION).createAsync();
  sqlDatabase=Utils.<SqlDatabase>rootResource(resourceStream).toBlocking().first();
  sqlServer.databases().delete(sqlDatabase.name());
  validateSqlDatabaseNotFound("String_Node_Str");
  sqlServer.elasticPools().delete(SQL_ELASTIC_POOL_NAME);
  sqlServerManager.sqlServers().deleteByResourceGroup(sqlServer.resourceGroupName(),sqlServer.name());
  validateSqlServerNotFound(sqlServer);
}