use of org.jboss.pnc.client.BuildConfigurationClient in project pnc by project-ncl.
the class BuildConfigurationEndpointTest method prepareData.
@SuppressWarnings("unchecked")
@BeforeClass
public static void prepareData() throws Exception {
BuildConfigurationClient bcc = new BuildConfigurationClient(RestClientConfiguration.asAnonymous());
Iterator<BuildConfiguration> it = bcc.getAll().iterator();
configurationId = it.next().getId();
configuration2Id = it.next().getId();
configuration3Id = it.next().getId();
configuration4Id = it.next().getId();
ProductClient pdc = new ProductClient(RestClientConfiguration.asAnonymous());
productId = pdc.getAll().iterator().next().getId();
EnvironmentClient ec = new EnvironmentClient(RestClientConfiguration.asAnonymous());
environmentId = ec.getAll().iterator().next().getId();
ProjectClient pjc = new ProjectClient(RestClientConfiguration.asAnonymous());
projectId = pjc.getAll().iterator().next().getId();
SCMRepositoryClient scmrc = new SCMRepositoryClient(RestClientConfiguration.asAnonymous());
final Iterator<SCMRepository> scmrIt = scmrc.getAll(null, null).iterator();
repositoryConfigurationId = scmrIt.next().getId();
repositoryConfiguration2Id = scmrIt.next().getId();
}
use of org.jboss.pnc.client.BuildConfigurationClient in project pnc by project-ncl.
the class BuildConfigurationEndpointTest method shouldRestoreBuildConfigurationRevision.
@Test
@InSequence(50)
public void shouldRestoreBuildConfigurationRevision() throws Exception {
// given
BuildConfigurationClient client = new BuildConfigurationClient(RestClientConfiguration.asUser());
BuildConfiguration original = client.getSpecific(configurationId);
String description = original.getDescription();
Iterator<BuildConfigurationRevision> it = client.getRevisions(configurationId).iterator();
// given latest revision
BuildConfigurationRevision originalRev = it.next();
while (it.hasNext()) {
BuildConfigurationRevision candidate = it.next();
if (candidate.getRev() > originalRev.getRev()) {
originalRev = candidate;
}
}
// when
String newDescription = "shouldRestoreBuildConfigurationRevision Updated";
BuildConfiguration toUpdate = original.toBuilder().description(newDescription).build();
client.update(configurationId, toUpdate);
assertThat(toUpdate.getDescription()).isNotEqualTo(description);
// and when
BuildConfiguration restored = client.restoreRevision(configurationId, originalRev.getRev());
BuildConfiguration retrieved = client.getSpecific(configurationId);
// then
// we don't audit anymore the description, so it cannot be restored from a previous revision
assertThat(restored.getDescription()).isEqualTo(toUpdate.getDescription());
assertThat(restored).isEqualToIgnoringGivenFields(original, "description", "modificationTime", "modificationUser", "creationTime", "creationUser");
assertThat(retrieved).isEqualToIgnoringGivenFields(restored, "description", "modificationTime", "modificationUser", "creationTime", "creationUser");
}
use of org.jboss.pnc.client.BuildConfigurationClient in project pnc by project-ncl.
the class BuildConfigurationEndpointTest method shouldCreateWithInternalUrlMatchingPattern.
@Test
@InSequence(62)
public void shouldCreateWithInternalUrlMatchingPattern() throws ClientException {
// given
BuildConfigurationClient client = new BuildConfigurationClient(RestClientConfiguration.asUser());
BuildConfiguration bc = client.getSpecific(configurationId);
BuildConfiguration newBC = BuildConfiguration.builder().name("othernameforbc").buildScript(bc.getBuildScript()).project(bc.getProject()).environment(bc.getEnvironment()).parameters(bc.getParameters()).buildType(bc.getBuildType()).build();
BuildConfigWithSCMRequest request = BuildConfigWithSCMRequest.builder().buildConfig(newBC).scmUrl("ssh://git@github.com:22/newUser/newRepo.git").build();
BuildConfigCreationResponse received = client.createWithSCM(request);
assertThat(received).isNotNull();
assertThat(received.getBuildConfig().getId()).isNotNull();
assertThat(client.getSpecific(received.getBuildConfig().getId())).hasFieldOrPropertyWithValue("name", "othernameforbc");
}
use of org.jboss.pnc.client.BuildConfigurationClient in project pnc by project-ncl.
the class BuildConfigurationEndpointTest method testRemoveDependency.
@Test
@InSequence(40)
public void testRemoveDependency() throws ClientException {
BuildConfigurationClient client = new BuildConfigurationClient(RestClientConfiguration.asUser());
// given
BuildConfiguration parent = client.getSpecific(configuration3Id);
Map<String, BuildConfigurationRef> oldDependencies = parent.getDependencies();
assertThat(oldDependencies).isNotEmpty();
BuildConfigurationRef toDelete = oldDependencies.values().iterator().next();
// when
client.removeDependency(parent.getId(), toDelete.getId());
// then
RemoteCollection<BuildConfiguration> all = client.getDependencies(parent.getId());
oldDependencies.remove(toDelete.getId());
assertThat(all).extracting(DTOEntity::getId).doesNotContain(toDelete.getId()).containsAll(oldDependencies.keySet().stream().collect(Collectors.toList()));
}
use of org.jboss.pnc.client.BuildConfigurationClient in project pnc by project-ncl.
the class BuildConfigurationEndpointTest method shouldGetConflictWhenCreatingNewBuildConfigurationWithTheSameNameAndProjectId.
@Test
public void shouldGetConflictWhenCreatingNewBuildConfigurationWithTheSameNameAndProjectId() throws ClientException {
BuildConfigurationClient client = new BuildConfigurationClient(RestClientConfiguration.asUser());
BuildConfiguration bc = client.getSpecific(configurationId);
BuildConfiguration duplicate = BuildConfiguration.builder().name(bc.getName()).buildScript(bc.getBuildScript()).project(bc.getProject()).environment(bc.getEnvironment()).parameters(bc.getParameters()).scmRepository(bc.getScmRepository()).buildType(bc.getBuildType()).build();
assertThatThrownBy(() -> client.createNew(duplicate)).hasCauseInstanceOf(ClientErrorException.class).has(new Condition<Throwable>((e -> ((ClientErrorException) e.getCause()).getResponse().getStatus() == 409), "HTTP 409 Conflict"));
}
Aggregations