Search in sources :

Example 6 with ProductVersion

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);
}
Also used : ProductMilestoneRef(org.jboss.pnc.dto.ProductMilestoneRef) ProductVersion(org.jboss.pnc.dto.ProductVersion) ProductVersionClient(org.jboss.pnc.client.ProductVersionClient) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 7 with ProductVersion

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());
}
Also used : BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) ProductVersion(org.jboss.pnc.dto.ProductVersion) BuildConfigurationClient(org.jboss.pnc.client.BuildConfigurationClient) ProductVersionPatchBuilder(org.jboss.pnc.client.patch.ProductVersionPatchBuilder) ProductVersionClient(org.jboss.pnc.client.ProductVersionClient) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 8 with ProductVersion

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);
}
Also used : ProductVersion(org.jboss.pnc.dto.ProductVersion) ProductVersionClient(org.jboss.pnc.client.ProductVersionClient) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 9 with ProductVersion

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());
    });
}
Also used : Product(org.jboss.pnc.model.Product) ProductVersion(org.jboss.pnc.dto.ProductVersion) ConflictedEntryException(org.jboss.pnc.facade.validation.ConflictedEntryException) InvalidEntityException(org.jboss.pnc.facade.validation.InvalidEntityException)

Example 10 with ProductVersion

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);
        }
    }
}
Also used : ProductVersion(org.jboss.pnc.dto.ProductVersion) ClientException(org.jboss.pnc.client.ClientException)

Aggregations

ProductVersion (org.jboss.pnc.dto.ProductVersion)24 ProductVersionClient (org.jboss.pnc.client.ProductVersionClient)17 ContainerTest (org.jboss.pnc.test.category.ContainerTest)16 Test (org.junit.Test)16 GroupConfiguration (org.jboss.pnc.dto.GroupConfiguration)5 GroupConfigurationRef (org.jboss.pnc.dto.GroupConfigurationRef)5 HashMap (java.util.HashMap)4 GroupConfigurationClient (org.jboss.pnc.client.GroupConfigurationClient)4 ProductClient (org.jboss.pnc.client.ProductClient)4 ProductVersionPatchBuilder (org.jboss.pnc.client.patch.ProductVersionPatchBuilder)3 Product (org.jboss.pnc.dto.Product)3 ClientException (org.jboss.pnc.client.ClientException)2 RemoteResourceException (org.jboss.pnc.client.RemoteResourceException)2 BuildConfiguration (org.jboss.pnc.dto.BuildConfiguration)2 ProductMilestone (org.jboss.pnc.dto.ProductMilestone)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 Instant (java.time.Instant)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1