Search in sources :

Example 1 with CreateAndSyncSCMRequest

use of org.jboss.pnc.dto.requests.CreateAndSyncSCMRequest in project pnc by project-ncl.

the class SCMRepositoryEndpointTest method shouldFailOnCreatingNewWithConflictingInternalUrl.

@Test
public void shouldFailOnCreatingNewWithConflictingInternalUrl() {
    SCMRepository repository = SCMRepository.builder().internalUrl(// from DatabaseDataInitializer.class
    "ssh://git@github.com:22/project-ncl/pnc.git").preBuildSyncEnabled(false).build();
    CreateAndSyncSCMRequest request = CreateAndSyncSCMRequest.builder().scmUrl(repository.getInternalUrl()).preBuildSyncEnabled(repository.getPreBuildSyncEnabled()).build();
    assertThatThrownBy(() -> repositoryClient.createNew(request)).hasCauseInstanceOf(ClientErrorException.class).has(new Condition<Throwable>((e -> ((ClientErrorException) e.getCause()).getResponse().getStatus() == 409), "Has Cause with conflicted status code 409"));
}
Also used : CreateAndSyncSCMRequest(org.jboss.pnc.dto.requests.CreateAndSyncSCMRequest) ClientErrorException(javax.ws.rs.ClientErrorException) SCMRepository(org.jboss.pnc.dto.SCMRepository) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 2 with CreateAndSyncSCMRequest

use of org.jboss.pnc.dto.requests.CreateAndSyncSCMRequest in project pnc by project-ncl.

the class SCMRepositoryEndpointTest method shouldFailToCreateNewWithInvalidUrl.

@Test
public void shouldFailToCreateNewWithInvalidUrl() {
    SCMRepository repository = SCMRepository.builder().internalUrl(// from DatabaseDataInitializer
    "I will totally fail!!").preBuildSyncEnabled(false).build();
    CreateAndSyncSCMRequest request = CreateAndSyncSCMRequest.builder().scmUrl(repository.getInternalUrl()).preBuildSyncEnabled(repository.getPreBuildSyncEnabled()).build();
    assertThatThrownBy(() -> repositoryClient.createNew(request)).hasCauseInstanceOf(BadRequestException.class);
}
Also used : CreateAndSyncSCMRequest(org.jboss.pnc.dto.requests.CreateAndSyncSCMRequest) SCMRepository(org.jboss.pnc.dto.SCMRepository) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 3 with CreateAndSyncSCMRequest

use of org.jboss.pnc.dto.requests.CreateAndSyncSCMRequest in project bacon by project-ncl.

the class PncEntitiesImporter method createRepository.

private SCMRepository createRepository(BuildConfig buildConfig) {
    String scmUrl = buildConfig.getScmUrl();
    CreateAndSyncSCMRequest createRepoRequest = CreateAndSyncSCMRequest.builder().preBuildSyncEnabled(true).scmUrl(scmUrl).build();
    try {
        CompletableFuture<AdvancedSCMRepositoryClient.SCMCreationResult> response = repoClient.createNewAndWait(createRepoRequest);
        log.info("Waiting for repository creation of '{}'", scmUrl);
        SleepUtils.waitFor(response::isDone, 10, true);
        AdvancedSCMRepositoryClient.SCMCreationResult result = response.join();
        log.info("{}", result.toString());
        if (result.isSuccess()) {
            return result.getScmRepositoryCreationSuccess().getScmRepository();
        } else {
            throw new RuntimeException("Error on creation of repository: " + result.getRepositoryCreationFailure());
        }
    } catch (ClientException e) {
        throw new RuntimeException("Failed to trigger repository creation for " + scmUrl, e);
    }
}
Also used : CreateAndSyncSCMRequest(org.jboss.pnc.dto.requests.CreateAndSyncSCMRequest) ClientException(org.jboss.pnc.client.ClientException) AdvancedSCMRepositoryClient(org.jboss.pnc.restclient.AdvancedSCMRepositoryClient)

Example 4 with CreateAndSyncSCMRequest

use of org.jboss.pnc.dto.requests.CreateAndSyncSCMRequest in project pnc by project-ncl.

the class SCMRepositoryEndpointTest method shouldCreateNewWithInternalUrl.

@Test
public void shouldCreateNewWithInternalUrl() throws ClientException {
    // With
    SCMRepository repository = SCMRepository.builder().internalUrl("ssh://git@github.com:22/newUser/newRepo.git").preBuildSyncEnabled(false).build();
    CreateAndSyncSCMRequest request = CreateAndSyncSCMRequest.builder().scmUrl(repository.getInternalUrl()).preBuildSyncEnabled(repository.getPreBuildSyncEnabled()).build();
    // When
    RepositoryCreationResponse response = repositoryClient.createNew(request);
    // Then
    assertThat(response).isNotNull();
    assertThat(response.getRepository().getId()).isNotNull();
    SCMRepository refreshed = repositoryClient.getSpecific(response.getRepository().getId());
    assertThat(refreshed).isEqualToIgnoringGivenFields(repository, "id");
}
Also used : CreateAndSyncSCMRequest(org.jboss.pnc.dto.requests.CreateAndSyncSCMRequest) SCMRepository(org.jboss.pnc.dto.SCMRepository) RepositoryCreationResponse(org.jboss.pnc.dto.response.RepositoryCreationResponse) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Aggregations

CreateAndSyncSCMRequest (org.jboss.pnc.dto.requests.CreateAndSyncSCMRequest)4 SCMRepository (org.jboss.pnc.dto.SCMRepository)3 ContainerTest (org.jboss.pnc.test.category.ContainerTest)3 Test (org.junit.Test)3 ClientErrorException (javax.ws.rs.ClientErrorException)1 ClientException (org.jboss.pnc.client.ClientException)1 RepositoryCreationResponse (org.jboss.pnc.dto.response.RepositoryCreationResponse)1 AdvancedSCMRepositoryClient (org.jboss.pnc.restclient.AdvancedSCMRepositoryClient)1