Search in sources :

Example 1 with NotFoundException

use of com.sequenceiq.redbeams.exception.NotFoundException in project cloudbreak by hortonworks.

the class DatabaseServerConfigServiceTest method testGetByCrnsNotFound.

@Test
public void testGetByCrnsNotFound() {
    Set<String> crnSet = Set.of(SERVER_CRN.toString(), SERVER_2_CRN.toString());
    Set<DatabaseServerConfig> serverSet = Set.of(server);
    when(repository.findByResourceCrnIn(Set.of(SERVER_CRN, SERVER_2_CRN))).thenReturn(serverSet);
    NotFoundException exception = assertThrows(NotFoundException.class, () -> underTest.getByCrns(crnSet));
    assertThat(exception.getMessage(), containsString("found with crn(s) " + SERVER_2_CRN));
}
Also used : DatabaseServerConfig(com.sequenceiq.redbeams.domain.DatabaseServerConfig) NotFoundException(com.sequenceiq.redbeams.exception.NotFoundException) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 2 with NotFoundException

use of com.sequenceiq.redbeams.exception.NotFoundException in project cloudbreak by hortonworks.

the class DatabaseServerConfigService method getByClusterCrn.

public DatabaseServerConfig getByClusterCrn(String environmentCrn, String clusterCrn) {
    DatabaseServerConfig databaseServerConfig = findByEnvironmentCrnAndClusterCrn(environmentCrn, clusterCrn).orElseThrow(() -> new NotFoundException(String.format("No %s found with cluster CRN '%s' in environment '%s'", DatabaseServerConfig.class.getSimpleName(), clusterCrn, environmentCrn)));
    MDCBuilder.buildMdcContext(databaseServerConfig);
    return databaseServerConfig;
}
Also used : DatabaseServerConfig(com.sequenceiq.redbeams.domain.DatabaseServerConfig) NotFoundException(com.sequenceiq.redbeams.exception.NotFoundException)

Example 3 with NotFoundException

use of com.sequenceiq.redbeams.exception.NotFoundException in project cloudbreak by hortonworks.

the class DatabaseConfigService method getByCrn.

public DatabaseConfig getByCrn(String resourceCrn) {
    Crn crn = Crn.safeFromString(resourceCrn);
    Optional<DatabaseConfig> resourceOpt = repository.findByResourceCrn(crn);
    if (resourceOpt.isEmpty()) {
        throw new NotFoundException(String.format("No database found with crn '%s'", resourceCrn));
    }
    MDCBuilder.buildMdcContext(resourceOpt.get());
    return resourceOpt.get();
}
Also used : NotFoundException(com.sequenceiq.redbeams.exception.NotFoundException) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) DatabaseConfig(com.sequenceiq.redbeams.domain.DatabaseConfig)

Example 4 with NotFoundException

use of com.sequenceiq.redbeams.exception.NotFoundException in project cloudbreak by hortonworks.

the class DatabaseServerConfigService method getByCrn.

public DatabaseServerConfig getByCrn(String resourceCrn) {
    Crn crn = Crn.safeFromString(resourceCrn);
    Optional<DatabaseServerConfig> resourceOpt = repository.findByResourceCrn(crn);
    if (resourceOpt.isEmpty()) {
        throw new NotFoundException(String.format("No %s found with crn '%s'", DatabaseServerConfig.class.getSimpleName(), resourceCrn));
    }
    MDCBuilder.buildMdcContext(resourceOpt.get());
    return resourceOpt.get();
}
Also used : DatabaseServerConfig(com.sequenceiq.redbeams.domain.DatabaseServerConfig) NotFoundException(com.sequenceiq.redbeams.exception.NotFoundException) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn)

Example 5 with NotFoundException

use of com.sequenceiq.redbeams.exception.NotFoundException in project cloudbreak by hortonworks.

the class DatabaseServerV4ControllerTest method testUpdateClusterCrn.

@Test
public void testUpdateClusterCrn() {
    when(service.findByEnvironmentCrnAndClusterCrn(ENVIRONMENT_CRN, CLUSTER_CRN)).thenReturn(Optional.of(server));
    underTest.updateClusterCrn(ENVIRONMENT_CRN, CLUSTER_CRN, CLUSTER_CRN1, USER_CRN);
    when(service.findByEnvironmentCrnAndClusterCrn(ENVIRONMENT_CRN, CLUSTER_CRN)).thenThrow(new NotFoundException("Not found"));
    try {
        underTest.updateClusterCrn(ENVIRONMENT_CRN, CLUSTER_CRN, CLUSTER_CRN1, USER_CRN);
        Assert.fail("NotFoundException should have been thrown");
    } catch (NotFoundException notFoundException) {
    }
}
Also used : NotFoundException(com.sequenceiq.redbeams.exception.NotFoundException) Test(org.junit.Test)

Aggregations

NotFoundException (com.sequenceiq.redbeams.exception.NotFoundException)6 DatabaseServerConfig (com.sequenceiq.redbeams.domain.DatabaseServerConfig)4 Crn (com.sequenceiq.cloudbreak.auth.crn.Crn)2 Test (org.junit.Test)2 InternalOnly (com.sequenceiq.authorization.annotation.InternalOnly)1 DatabaseConfig (com.sequenceiq.redbeams.domain.DatabaseConfig)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1