Search in sources :

Example 11 with SCMRepository

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

the class SCMRepositoryProviderTest method testStoreNewRepositoryWithIdShouldFail.

@Test
public void testStoreNewRepositoryWithIdShouldFail() {
    // when
    SCMRepository toCreate = createNewSCMRepository("https://" + UUID.randomUUID().toString() + ".ca", "git+ssh://" + UUID.randomUUID().toString() + ".eu", true, Integer.toString(entityId.getAndIncrement()));
    // then
    assertThatThrownBy(() -> provider.store(toCreate)).isInstanceOf(InvalidEntityException.class);
}
Also used : SCMRepository(org.jboss.pnc.dto.SCMRepository) Test(org.junit.Test)

Example 12 with SCMRepository

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

the class SCMRepositoryProviderTest method testUpdateWithUpdatedInternalUrlShouldFail.

@Test
public void testUpdateWithUpdatedInternalUrlShouldFail() {
    // when
    SCMRepository toUpdate = createNewSCMRepository(mock.getExternalUrl(), mock.getInternalUrl() + "ssss", mock.isPreBuildSyncEnabled(), mock.getId().toString());
    // then
    assertThatThrownBy(() -> provider.update(toUpdate.getId(), toUpdate)).isInstanceOf(InvalidEntityException.class);
}
Also used : SCMRepository(org.jboss.pnc.dto.SCMRepository) Test(org.junit.Test)

Example 13 with SCMRepository

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

the class SCMRepositoryProviderTest method testStoreNewRepositoryWithoutId.

@Test
public void testStoreNewRepositoryWithoutId() {
    // when
    SCMRepository toCreate = createNewSCMRepository("https://" + UUID.randomUUID().toString() + ".ca", "git+ssh://" + UUID.randomUUID().toString() + ".eu", true, null);
    SCMRepository created = provider.store(toCreate);
    // then
    assertThat(created).isNotNull();
    assertThat(created.getId()).isNotNull().isNotEmpty();
    assertThat(created.getInternalUrl()).isEqualTo(toCreate.getInternalUrl());
    assertThat(created.getExternalUrl()).isEqualTo(toCreate.getExternalUrl());
    assertThat(created.getPreBuildSyncEnabled()).isEqualTo(toCreate.getPreBuildSyncEnabled());
}
Also used : SCMRepository(org.jboss.pnc.dto.SCMRepository) Test(org.junit.Test)

Example 14 with SCMRepository

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

the class SCMRepositoryProviderTest method testUpdateWithOwnUrl.

@Test
public void testUpdateWithOwnUrl() {
    // with
    String external = "http://external.sh/foo/bar";
    when(repour.translateExternalUrl(external)).thenReturn(mockInternalOnly.getInternalUrl());
    SCMRepository toUpdate = createNewSCMRepository(external, mockInternalOnly.getInternalUrl(), mockInternalOnly.isPreBuildSyncEnabled(), mockInternalOnly.getId().toString());
    // when
    SCMRepository updated = provider.update(toUpdate.getId(), toUpdate);
    // then
    assertThat(updated.getExternalUrl()).isEqualTo(external);
}
Also used : SCMRepository(org.jboss.pnc.dto.SCMRepository) Test(org.junit.Test)

Example 15 with SCMRepository

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

the class BuildConfigurationProviderImpl method createBuildConfigurationWithRepository.

public void createBuildConfigurationWithRepository(String taskId, int scmRepositoryId, BuildConfiguration configuration) {
    RepositoryConfiguration repositoryConfiguration = repositoryConfigurationRepository.queryById(scmRepositoryId);
    final boolean sendMessage = taskId != null;
    if (repositoryConfiguration == null) {
        String errorMessage = "Repository Configuration was not found in database.";
        logger.error(errorMessage);
        if (sendMessage) {
            sendErrorMessage(SCMRepository.builder().id(Integer.toString(scmRepositoryId)).build(), null, errorMessage, taskId);
            return;
        }
        throw new RepositoryViolationException("Repository Configuration was not found in database.");
    }
    org.jboss.pnc.model.BuildConfiguration buildConfiguration = mapper.toEntity(configuration);
    buildConfiguration.setRepositoryConfiguration(repositoryConfiguration);
    org.jboss.pnc.model.BuildConfiguration buildConfigurationSaved = repository.save(buildConfiguration);
    Set<Integer> bcSetIds;
    if (configuration.getGroupConfigs() == null) {
        bcSetIds = Collections.emptySet();
    } else {
        bcSetIds = configuration.getGroupConfigs().keySet().stream().map(Integer::valueOf).collect(Collectors.toSet());
    }
    SCMRepository scmRepository = scmRepositoryMapper.toDTO(repositoryConfiguration);
    BuildConfiguration buildConfig = mapper.toDTO(buildConfigurationSaved);
    try {
        addBuildConfigurationToSet(buildConfigurationSaved, bcSetIds);
    } catch (Exception e) {
        logger.error(e.getMessage());
        if (sendMessage) {
            sendErrorMessage(scmRepository, buildConfig, e.getMessage(), taskId);
            return;
        }
        throw new RepositoryViolationException("Failed to add BuildConfig to BuildConfigSets.");
    }
    logger.info("Created Build Configuration with Repository: {}.", buildConfig);
    if (sendMessage) {
        BuildConfigurationCreation successMessage = BuildConfigurationCreation.success(scmRepository, buildConfig, taskId);
        notifier.sendMessage(successMessage);
    }
}
Also used : BuildConfigurationCreation(org.jboss.pnc.dto.notification.BuildConfigurationCreation) EmptyEntityException(org.jboss.pnc.facade.validation.EmptyEntityException) RepositoryViolationException(org.jboss.pnc.facade.validation.RepositoryViolationException) ConflictedEntryException(org.jboss.pnc.facade.validation.ConflictedEntryException) DTOValidationException(org.jboss.pnc.facade.validation.DTOValidationException) InvalidEntityException(org.jboss.pnc.facade.validation.InvalidEntityException) BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) RepositoryViolationException(org.jboss.pnc.facade.validation.RepositoryViolationException) RepositoryConfiguration(org.jboss.pnc.model.RepositoryConfiguration) SCMRepository(org.jboss.pnc.dto.SCMRepository)

Aggregations

SCMRepository (org.jboss.pnc.dto.SCMRepository)28 Test (org.junit.Test)17 ContainerTest (org.jboss.pnc.test.category.ContainerTest)9 BuildConfiguration (org.jboss.pnc.dto.BuildConfiguration)8 Environment (org.jboss.pnc.dto.Environment)5 ProjectRef (org.jboss.pnc.dto.ProjectRef)4 CreateAndSyncSCMRequest (org.jboss.pnc.dto.requests.CreateAndSyncSCMRequest)4 ClientErrorException (javax.ws.rs.ClientErrorException)3 SCMRepositoryClient (org.jboss.pnc.client.SCMRepositoryClient)3 RepositoryCreationResponse (org.jboss.pnc.dto.response.RepositoryCreationResponse)3 InvalidEntityException (org.jboss.pnc.facade.validation.InvalidEntityException)3 RepositoryConfiguration (org.jboss.pnc.model.RepositoryConfiguration)3 BuildConfigurationClient (org.jboss.pnc.client.BuildConfigurationClient)2 EnvironmentClient (org.jboss.pnc.client.EnvironmentClient)2 Project (org.jboss.pnc.dto.Project)2 BuildConfigurationCreation (org.jboss.pnc.dto.notification.BuildConfigurationCreation)2 ConflictedEntryException (org.jboss.pnc.facade.validation.ConflictedEntryException)2 DTOValidationException (org.jboss.pnc.facade.validation.DTOValidationException)2 EmptyEntityException (org.jboss.pnc.facade.validation.EmptyEntityException)2 RepositoryViolationException (org.jboss.pnc.facade.validation.RepositoryViolationException)2