Search in sources :

Example 1 with ProjectIdSchema

use of bio.terra.buffer.generated.model.ProjectIdSchema in project terra-resource-buffer by DataBiosphere.

the class PoolServiceTest method updateFromConfig_updateResourceConfigOnExistingPool_throwsException.

@Test
public void updateFromConfig_updateResourceConfigOnExistingPool_throwsException() throws Exception {
    PoolId poolId = PoolId.create("poolId");
    PoolConfig poolConfig = new PoolConfig().poolId(poolId.toString()).size(1).resourceConfigName(RESOURCE_CONFIG_NAME);
    PoolWithResourceConfig parsedPoolConfig = PoolWithResourceConfig.create(poolConfig, newResourceConfig());
    poolService.updateFromConfig(ImmutableList.of(parsedPoolConfig));
    // Sets ResourceConfig's GCP project id prefix to newer value.
    PoolWithResourceConfig updatedPoolConfig = PoolWithResourceConfig.create(poolConfig, newResourceConfig(new GcpProjectConfig().projectIdSchema(new ProjectIdSchema().prefix("aou-rw-test2").scheme(ProjectIdSchema.SchemeEnum.RANDOM_CHAR))));
    assertThrows(RuntimeException.class, () -> poolService.updateFromConfig(ImmutableList.of(updatedPoolConfig)));
    assertThat(bufferDao.retrievePools().stream().map(Pool::resourceConfig).collect(Collectors.toList()), Matchers.containsInAnyOrder(parsedPoolConfig.resourceConfig()));
}
Also used : PoolId(bio.terra.buffer.common.PoolId) ProjectIdSchema(bio.terra.buffer.generated.model.ProjectIdSchema) GcpProjectConfig(bio.terra.buffer.generated.model.GcpProjectConfig) PoolConfig(bio.terra.buffer.generated.model.PoolConfig) Pool(bio.terra.buffer.common.Pool) BaseUnitTest(bio.terra.buffer.common.BaseUnitTest) Test(org.junit.jupiter.api.Test)

Example 2 with ProjectIdSchema

use of bio.terra.buffer.generated.model.ProjectIdSchema in project terra-resource-buffer by DataBiosphere.

the class ResourceConfigValidatorTest method testValidateGcpConfig_prefixTooLong.

@Test
public void testValidateGcpConfig_prefixTooLong() {
    ResourceConfig resourceConfig = new ResourceConfig().configName("testConfig").gcpProjectConfig(newValidGcpProjectConfig().projectIdSchema(new ProjectIdSchema().prefix("prefixlongerthan12characters").scheme(ProjectIdSchema.SchemeEnum.TWO_WORDS_NUMBER)));
    InvalidPoolConfigException exception = assertThrows(InvalidPoolConfigException.class, () -> new GcpResourceConfigValidator().validate(resourceConfig));
    assertTrue(exception.getMessage().contains("Project id prefix is too long for TWO_WORDS_NUMBER naming scheme"));
}
Also used : ProjectIdSchema(bio.terra.buffer.generated.model.ProjectIdSchema) ResourceConfig(bio.terra.buffer.generated.model.ResourceConfig) InvalidPoolConfigException(bio.terra.buffer.common.exception.InvalidPoolConfigException) Test(org.junit.jupiter.api.Test) BaseUnitTest(bio.terra.buffer.common.BaseUnitTest)

Example 3 with ProjectIdSchema

use of bio.terra.buffer.generated.model.ProjectIdSchema in project terra-resource-buffer by DataBiosphere.

the class GcpProjectIdGeneratorTest method generateId_wordPair.

@Test
public void generateId_wordPair() {
    ProjectIdSchema generatorConfig = new ProjectIdSchema().prefix("prefix").scheme(TWO_WORDS_NUMBER);
    String generatedID = gcpProjectIDGenerator.generateId(generatorConfig);
    assertThat(generatedID, matchesPattern("prefix-[a-z]+-[a-z]+-[0-9]+"));
}
Also used : ProjectIdSchema(bio.terra.buffer.generated.model.ProjectIdSchema) Test(org.junit.jupiter.api.Test) BaseUnitTest(bio.terra.buffer.common.BaseUnitTest)

Example 4 with ProjectIdSchema

use of bio.terra.buffer.generated.model.ProjectIdSchema in project terra-resource-buffer by DataBiosphere.

the class GcpProjectIdGeneratorTest method generateId_randomChar.

@Test
public void generateId_randomChar() {
    ProjectIdSchema generatorConfig = new ProjectIdSchema().prefix("prefix").scheme(RANDOM_CHAR);
    String generatedID = gcpProjectIDGenerator.generateId(generatorConfig);
    assertTrue(generatedID.startsWith("prefix-"));
    assertEquals(RANDOM_ID_SIZE, generatedID.substring("prefix-".length()).length());
}
Also used : ProjectIdSchema(bio.terra.buffer.generated.model.ProjectIdSchema) Test(org.junit.jupiter.api.Test) BaseUnitTest(bio.terra.buffer.common.BaseUnitTest)

Example 5 with ProjectIdSchema

use of bio.terra.buffer.generated.model.ProjectIdSchema in project terra-resource-buffer by DataBiosphere.

the class GcpProjectIdGeneratorTest method generateIdWithRetries_retriesExhausted.

@Test
public void generateIdWithRetries_retriesExhausted() {
    ProjectIdSchema generatorConfig = new ProjectIdSchema().prefix("prefixthatislongerthan30characters").scheme(TWO_WORDS_NUMBER);
    InterruptedException interruptedException = assertThrows(InterruptedException.class, () -> gcpProjectIDGenerator.generateIdWithRetries(generatorConfig));
    assertTrue(interruptedException.getMessage().contains("No project id found after maximum number of retries"));
}
Also used : ProjectIdSchema(bio.terra.buffer.generated.model.ProjectIdSchema) Test(org.junit.jupiter.api.Test) BaseUnitTest(bio.terra.buffer.common.BaseUnitTest)

Aggregations

BaseUnitTest (bio.terra.buffer.common.BaseUnitTest)5 ProjectIdSchema (bio.terra.buffer.generated.model.ProjectIdSchema)5 Test (org.junit.jupiter.api.Test)5 Pool (bio.terra.buffer.common.Pool)1 PoolId (bio.terra.buffer.common.PoolId)1 InvalidPoolConfigException (bio.terra.buffer.common.exception.InvalidPoolConfigException)1 GcpProjectConfig (bio.terra.buffer.generated.model.GcpProjectConfig)1 PoolConfig (bio.terra.buffer.generated.model.PoolConfig)1 ResourceConfig (bio.terra.buffer.generated.model.ResourceConfig)1