use of org.jboss.pnc.dto.BuildConfiguration in project pnc by project-ncl.
the class BuildConfigurationEndpointTest method shouldPatchBuildConfiguration.
@Test
@InSequence(20)
public void shouldPatchBuildConfiguration() throws ClientException, PatchBuilderException {
BuildConfigurationClient client = new BuildConfigurationClient(RestClientConfiguration.asUser());
BuildConfiguration buildConfiguration = client.getAll().iterator().next();
String newDescription = "Testing patch support.";
Instant modTime = buildConfiguration.getModificationTime();
String id = buildConfiguration.getId();
Map<String, String> addElements = Collections.singletonMap("newKey", "newValue");
BuildConfigurationPatchBuilder builder = new BuildConfigurationPatchBuilder().replaceDescription(newDescription).addParameters(addElements);
BuildConfiguration updated = client.patch(id, builder);
Assert.assertEquals(newDescription, updated.getDescription());
Assert.assertNotEquals(modTime, updated.getModificationTime());
Assertions.assertThat(updated.getParameters()).contains(addElements.entrySet().toArray(new Map.Entry[1]));
String newDescription2 = "Testing patch support 2.";
BuildConfigurationPatchBuilder builder2 = new BuildConfigurationPatchBuilder().replaceDescription(newDescription2);
BuildConfiguration updated2 = client.patch(id, builder2.getJsonPatch(), BuildConfiguration.class);
Assert.assertEquals(newDescription2, updated2.getDescription());
}
use of org.jboss.pnc.dto.BuildConfiguration in project pnc by project-ncl.
the class BuildConfigurationEndpointTest method shouldUpdateBuildConfiguration.
/**
* Reproducer NCL-2615 - big generic parameters cannot be ubdated in the BuildConfiguration
*
* @throws ClientException
*/
@Test
@InSequence(30)
public void shouldUpdateBuildConfiguration() throws ClientException {
// given
final String updatedBuildScript = "mvn clean deploy -Dmaven.test.skip=true";
final String updatedName = UUID.randomUUID().toString();
final String updatedProjectId = String.valueOf(projectId);
final String updatedGenParamValue = PME_PARAMS_LONG;
final Instant modificationTime = Instant.ofEpochMilli(155382545038L);
BuildConfiguration buildConfiguration = BuildConfiguration.builder().id(configurationId).name(updatedName).buildScript(updatedBuildScript).creationTime(Instant.ofEpochMilli(1518382545038L)).modificationTime(modificationTime).project(ProjectRef.refBuilder().id(updatedProjectId).build()).environment(Environment.builder().id(environmentId).build()).parameters(Collections.singletonMap(PARAMETER_KEY, updatedGenParamValue)).scmRepository(SCMRepository.builder().id(repositoryConfigurationId).build()).buildType(BuildType.MVN).brewPullActive(true).build();
// when
BuildConfigurationClient client = new BuildConfigurationClient(RestClientConfiguration.asUser());
client.update(configurationId, buildConfiguration);
BuildConfiguration updatedBC = client.getSpecific(configurationId);
// then
assertThat(updatedBC.getId()).isEqualTo(configurationId);
assertThat(updatedBC.getName()).isEqualTo(updatedName);
assertThat(updatedBC.getBuildScript()).isEqualTo(updatedBuildScript);
assertThat(updatedBC.getScmRepository().getId()).isEqualTo(repositoryConfigurationId);
assertThat(updatedBC.getProject().getId()).isEqualTo(updatedProjectId);
assertThat(updatedBC.getParameters().get(PARAMETER_KEY)).isEqualTo(updatedGenParamValue);
assertThat(updatedBC.getEnvironment().getId()).isEqualTo(environmentId);
assertThat(modificationTime).isNotEqualTo(updatedBC.getModificationTime());
assertThat(updatedBC.getBrewPullActive()).isTrue();
}
use of org.jboss.pnc.dto.BuildConfiguration in project pnc by project-ncl.
the class BuildConfigurationEndpointTest method shouldCloneBuildConfiguration.
@Test
@InSequence(20)
public void shouldCloneBuildConfiguration() throws ClientException {
// given
BuildConfigurationClient client = new BuildConfigurationClient(RestClientConfiguration.asUser());
BuildConfiguration original = client.getSpecific(configurationId);
assertThat(original.getProductVersion()).isNotNull();
assertThat(original.getGroupConfigs()).isNotEmpty();
BuildConfiguration parent = client.getSpecific(configuration4Id);
assertThat(parent.getDependencies()).containsKey(configurationId);
// when
BuildConfiguration clone = client.clone(original.getId());
// then
assertThat(clone.getId()).isNotEmpty();
assertThat(clone.getProductVersion()).isNull();
assertThat(clone.getGroupConfigs()).isEmpty();
BuildConfiguration retrieved = client.getSpecific(clone.getId());
BuildConfiguration retrivedParent = client.getSpecific(configuration4Id);
assertThat(retrivedParent.getDependencies()).containsKey(configurationId);
assertThat(retrivedParent.getDependencies()).doesNotContainKey(clone.getId());
assertThat(clone).isEqualToIgnoringGivenFields(original, "id", "name", "groupConfigs", "creationTime", "modificationTime", "modificationTime", "productVersion", "creationUser", "modificationUser");
assertThat(retrieved).isEqualToIgnoringGivenFields(clone, "modificationTime", "creationUser", // close
"modificationUser");
// of
// transaction
// changes
// the modification time -
// WONTFIX
}
use of org.jboss.pnc.dto.BuildConfiguration in project pnc by project-ncl.
the class BuildConfigurationEndpointTest method shouldDeleteDependencyWithPatch.
@Test
@InSequence(100)
public void shouldDeleteDependencyWithPatch() throws Exception {
// given
BuildConfigurationClient bcClient = new BuildConfigurationClient(RestClientConfiguration.asUser());
BuildConfiguration gc = null;
for (BuildConfiguration bc1 : bcClient.getAll()) {
if (!bc1.getDependencies().isEmpty()) {
gc = bc1;
break;
}
}
assertThat(gc).isNotNull();
BuildConfiguration toRemove = bcClient.getSpecific(gc.getDependencies().keySet().iterator().next());
BuildConfigurationPatchBuilder builder = new BuildConfigurationPatchBuilder();
builder.removeDependencies(Collections.singletonList(toRemove.getId()));
// when
bcClient.patch(gc.getId(), builder);
// then
BuildConfiguration refresh = bcClient.getSpecific(gc.getId());
assertThat(refresh.getDependencies().keySet()).doesNotContain(toRemove.getId());
}
use of org.jboss.pnc.dto.BuildConfiguration in project pnc by project-ncl.
the class BuildConfigurationSerializationTest method shouldPatchBuildConfiguration.
@Test
public void shouldPatchBuildConfiguration() throws PatchBuilderException, IOException, JsonPatchException {
ObjectMapper mapper = ObjectMapperProvider.getInstance();
// given
Instant now = Instant.now();
Map<String, String> initialParameters = Collections.singletonMap("KEY", "VALUE");
BuildConfiguration buildConfiguration = BuildConfiguration.builder().id("1").name("name").creationTime(now).parameters(initialParameters).build();
// when
BuildConfigurationPatchBuilder patchBuilder = new BuildConfigurationPatchBuilder();
patchBuilder.replaceName("new name");
Map<String, String> newParameter = Collections.singletonMap("KEY 2", "VALUE 2");
patchBuilder.addParameters(newParameter);
JsonNode targetJson = mapper.valueToTree(buildConfiguration);
JsonPatch patch = JsonPatch.fromJson(mapper.readValue(patchBuilder.getJsonPatch(), JsonNode.class));
JsonNode result = patch.apply(targetJson);
// then
BuildConfiguration deserialized = mapper.treeToValue(result, BuildConfiguration.class);
Assert.assertEquals(now, deserialized.getCreationTime());
Assert.assertEquals("new name", deserialized.getName());
Map<String, String> finalParameters = new HashMap<>(initialParameters);
finalParameters.putAll(newParameter);
assertThat(deserialized.getParameters()).containsAllEntriesOf(finalParameters);
}
Aggregations