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);
}
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);
}
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());
}
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);
}
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);
}
}
Aggregations