use of org.jboss.pnc.dto.ProductVersion in project pnc by project-ncl.
the class ProductVersionEndpointTest method shouldNotUpdateCurrentToClosedMilestone.
@Test
public void shouldNotUpdateCurrentToClosedMilestone() throws ClientException {
ProductVersionClient client = new ProductVersionClient(RestClientConfiguration.asUser());
ProductVersion productVersion = client.getSpecific(productVersionsId);
Map<String, ProductMilestoneRef> milestones = productVersion.getProductMilestones();
ProductMilestoneRef closedMilestoneRef = null;
for (ProductMilestoneRef milestone : milestones.values()) {
if (milestone.getVersion().equals("1.0.0.Build4")) {
closedMilestoneRef = milestone;
break;
}
}
assertThat(closedMilestoneRef.getEndDate()).isNotNull();
ProductVersion updatedWithClosedMilestone = productVersion.toBuilder().currentProductMilestone(closedMilestoneRef).build();
assertThatThrownBy(() -> client.update(productVersionsId, updatedWithClosedMilestone)).isInstanceOf(ClientException.class);
}
use of org.jboss.pnc.dto.ProductVersion in project pnc by project-ncl.
the class ProductVersionEndpointTest method shouldDeleteBuildConfigWithPatch.
@Test
public void shouldDeleteBuildConfigWithPatch() throws Exception {
// given
ProductVersionClient client = new ProductVersionClient(RestClientConfiguration.asUser());
BuildConfigurationClient bcClient = new BuildConfigurationClient(RestClientConfiguration.asUser());
ProductVersion productVersion = client.getSpecific(productVersionsId2);
assertThat(productVersion.getBuildConfigs()).isNotEmpty();
BuildConfiguration toRemove = bcClient.getSpecific(productVersion.getBuildConfigs().keySet().iterator().next());
ProductVersionPatchBuilder builder = new ProductVersionPatchBuilder();
builder.removeBuildConfigs(Collections.singletonList(toRemove.getId()));
// when
client.patch(productVersion.getId(), builder);
// then
ProductVersion refresh = client.getSpecific(productVersionsId2);
assertThat(refresh.getBuildConfigs().keySet()).doesNotContain(toRemove.getId());
}
use of org.jboss.pnc.dto.ProductVersion in project pnc by project-ncl.
the class ProductVersionEndpointTest method testUpdate.
@Test
public void testUpdate() throws ClientException {
// given
ProductVersionClient client = new ProductVersionClient(RestClientConfiguration.asUser());
final String version = "2.1";
ProductVersion dto = client.getSpecific(productVersionsId2);
ProductVersion toUpdate = dto.toBuilder().version(version).build();
// when
client.update(productVersionsId2, toUpdate);
// then
ProductVersion retrieved = client.getSpecific(dto.getId());
assertThat(retrieved).isEqualTo(toUpdate);
assertThat(retrieved).isEqualToIgnoringGivenFields(dto, "version");
assertThat(retrieved.getVersion()).isEqualTo(version);
}
use of org.jboss.pnc.dto.ProductVersion in project pnc by project-ncl.
the class ProductVersionProviderImpl method validateBeforeSaving.
@Override
protected void validateBeforeSaving(ProductVersion restEntity) {
super.validateBeforeSaving(restEntity);
Product product = productRepository.queryById(Integer.valueOf(restEntity.getProduct().getId()));
if (product == null) {
throw new InvalidEntityException("Product with id: " + restEntity.getProduct().getId() + " does not exist.");
}
Set<org.jboss.pnc.model.ProductVersion> productVersionList = product.getProductVersions();
if (productVersionList == null) {
return;
}
productVersionList.stream().filter(pv -> pv.getVersion().equals(restEntity.getVersion())).findFirst().ifPresent(pv -> {
throw new ConflictedEntryException("Product version with version " + restEntity.getVersion() + " already exists", org.jboss.pnc.model.ProductVersion.class, pv.getId().toString());
});
}
use of org.jboss.pnc.dto.ProductVersion in project bacon by project-ncl.
the class PncEntitiesImporter method setBrewTagPrefix.
/**
* Override the default brewTagPrefix for the product version with the one specified in the pig configuration This
* only happens if the brewTagPrefix in the pig configuration is not null/empty
*/
private void setBrewTagPrefix(ProductVersion productVersion) {
String brewTagPrefix = pigConfiguration.getBrewTagPrefix();
if (brewTagPrefix != null && !brewTagPrefix.isEmpty()) {
log.info("Updating the product version's brewTagPrefix with: {}", brewTagPrefix);
Map<String, String> attributes = productVersion.getAttributes();
attributes.put(Attributes.BREW_TAG_PREFIX, brewTagPrefix);
ProductVersion update = productVersion.toBuilder().attributes(attributes).build();
try {
versionClient.update(productVersion.getId(), update);
} catch (ClientException e) {
throw new RuntimeException("Failed to update the brew tag prefix of the product version", e);
}
}
}
Aggregations