Search in sources :

Example 16 with ProductVersionClient

use of org.jboss.pnc.client.ProductVersionClient in project pnc by project-ncl.

the class ProductMilestoneEndpointTest method shouldGetMilestoneRelease.

@Test
public void shouldGetMilestoneRelease() throws IOException, RemoteResourceException {
    // given
    ProductClient productClient = new ProductClient(RestClientConfiguration.asAnonymous());
    RemoteCollection<Product> products = productClient.getAll(Optional.empty(), Optional.of("name==\"" + PNC_PRODUCT_NAME + "\""));
    Product product = products.iterator().next();
    Map<String, ProductVersionRef> productVersions = product.getProductVersions();
    Optional<ProductVersionRef> productVersion = productVersions.values().stream().filter(pv -> pv.getVersion().equals(DatabaseDataInitializer.PNC_PRODUCT_VERSION_1)).findAny();
    ProductVersionClient productVersionClient = new ProductVersionClient(RestClientConfiguration.asAnonymous());
    RemoteCollection<ProductMilestone> milestones = productVersionClient.getMilestones(productVersion.get().getId(), Optional.empty(), Optional.of("version==\"" + PNC_PRODUCT_MILESTONE3 + "\""));
    ProductMilestone milestone = milestones.iterator().next();
    ProductMilestoneClient milestoneClient = new ProductMilestoneClient(RestClientConfiguration.asAnonymous());
    // when
    RemoteCollection<ProductMilestoneCloseResult> milestoneReleases = milestoneClient.getCloseResults(milestone.getId(), null);
    // then
    Assert.assertEquals(3, milestoneReleases.size());
    // make sure the result is ordered by date
    Instant previous = Instant.EPOCH;
    for (Iterator<ProductMilestoneCloseResult> iter = milestoneReleases.iterator(); iter.hasNext(); ) {
        ProductMilestoneCloseResult next = iter.next();
        logger.debug("MilestoneRelease id: {}, StartingDate: {}.", next.getId(), next.getStartingDate());
        Assert.assertTrue("Wong milestone releases order.", next.getStartingDate().isAfter(previous));
        previous = next.getStartingDate();
    }
    // when
    ProductMilestoneCloseParameters filter = new ProductMilestoneCloseParameters();
    filter.setLatest(true);
    RemoteCollection<ProductMilestoneCloseResult> latestMilestoneRelease = milestoneClient.getCloseResults(milestone.getId(), filter);
    // then
    Assert.assertEquals(1, latestMilestoneRelease.getAll().size());
    // the latest one in demo data has status SUCCEEDED
    Assert.assertEquals(MilestoneCloseStatus.SUCCEEDED, latestMilestoneRelease.iterator().next().getStatus());
}
Also used : BeforeClass(org.junit.BeforeClass) Arquillian(org.jboss.arquillian.junit.Arquillian) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) LoggerFactory(org.slf4j.LoggerFactory) ProductClient(org.jboss.pnc.client.ProductClient) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) RemoteCollection(org.jboss.pnc.client.RemoteCollection) ContainerTest(org.jboss.pnc.test.category.ContainerTest) ClientException(org.jboss.pnc.client.ClientException) ProductMilestoneCloseParameters(org.jboss.pnc.rest.api.parameters.ProductMilestoneCloseParameters) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ProductMilestone(org.jboss.pnc.dto.ProductMilestone) Map(java.util.Map) BadRequestException(javax.ws.rs.BadRequestException) Deployments(org.jboss.pnc.integration.setup.Deployments) PNC_PRODUCT_MILESTONE3(org.jboss.pnc.demo.data.DatabaseDataInitializer.PNC_PRODUCT_MILESTONE3) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) ValidationResponse(org.jboss.pnc.dto.response.ValidationResponse) ValidationErrorType(org.jboss.pnc.enums.ValidationErrorType) DatabaseDataInitializer(org.jboss.pnc.demo.data.DatabaseDataInitializer) EnterpriseArchive(org.jboss.shrinkwrap.api.spec.EnterpriseArchive) Product(org.jboss.pnc.dto.Product) ProductMilestoneClient(org.jboss.pnc.client.ProductMilestoneClient) Test(org.junit.Test) IOException(java.io.IOException) Artifact(org.jboss.pnc.dto.Artifact) VersionValidationRequest(org.jboss.pnc.dto.requests.validation.VersionValidationRequest) Category(org.junit.experimental.categories.Category) Instant(java.time.Instant) RestClientConfiguration(org.jboss.pnc.integration.setup.RestClientConfiguration) ProductVersionClient(org.jboss.pnc.client.ProductVersionClient) Build(org.jboss.pnc.dto.Build) PNC_PRODUCT_NAME(org.jboss.pnc.demo.data.DatabaseDataInitializer.PNC_PRODUCT_NAME) Deployment(org.jboss.arquillian.container.test.api.Deployment) ProductMilestoneCloseResult(org.jboss.pnc.dto.ProductMilestoneCloseResult) ProductVersionRef(org.jboss.pnc.dto.ProductVersionRef) ProductVersion(org.jboss.pnc.dto.ProductVersion) RemoteResourceException(org.jboss.pnc.client.RemoteResourceException) Optional(java.util.Optional) Assert(org.junit.Assert) MilestoneCloseStatus(org.jboss.pnc.enums.MilestoneCloseStatus) ProductMilestone(org.jboss.pnc.dto.ProductMilestone) ProductMilestoneClient(org.jboss.pnc.client.ProductMilestoneClient) Instant(java.time.Instant) Product(org.jboss.pnc.dto.Product) ProductVersionRef(org.jboss.pnc.dto.ProductVersionRef) ProductMilestoneCloseParameters(org.jboss.pnc.rest.api.parameters.ProductMilestoneCloseParameters) ProductVersionClient(org.jboss.pnc.client.ProductVersionClient) ProductClient(org.jboss.pnc.client.ProductClient) ProductMilestoneCloseResult(org.jboss.pnc.dto.ProductMilestoneCloseResult) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 17 with ProductVersionClient

use of org.jboss.pnc.client.ProductVersionClient in project pnc by project-ncl.

the class ProductVersionEndpointTest method shouldNotUpdateGroupConfigsWhenOneIsAlreadyAsssociatedWithAnotherProductVersionUsingPatch.

@Test
public void shouldNotUpdateGroupConfigsWhenOneIsAlreadyAsssociatedWithAnotherProductVersionUsingPatch() throws ClientException, PatchBuilderException {
    // given
    ProductVersionClient client = new ProductVersionClient(RestClientConfiguration.asUser());
    GroupConfigurationRef alreadyAssignedGC = client.getSpecific(productVersionsId).getGroupConfigs().values().iterator().next();
    Map<String, GroupConfigurationRef> groupConfis = new HashMap<>();
    assertThat(alreadyAssignedGC).isNotNull();
    // when
    ProductVersionPatchBuilder patchBuilder = new ProductVersionPatchBuilder();
    ProductVersionPatchBuilder patch = patchBuilder.addGroupConfigs(Collections.singletonMap(alreadyAssignedGC.getId(), alreadyAssignedGC));
    // then
    assertThatThrownBy(() -> client.patch(productVersionsId2, patch)).isInstanceOf(ClientException.class);
}
Also used : GroupConfigurationRef(org.jboss.pnc.dto.GroupConfigurationRef) HashMap(java.util.HashMap) 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 18 with ProductVersionClient

use of org.jboss.pnc.client.ProductVersionClient in project pnc by project-ncl.

the class ProductVersionEndpointTest method shouldGenerateBrewTagWhenCreatingProductVersion.

@Test
public void shouldGenerateBrewTagWhenCreatingProductVersion() throws Exception {
    // given
    final String version = "42.3";
    ProductVersion productVersion = ProductVersion.builder().product(product).version(version).build();
    // when
    ProductVersionClient client = new ProductVersionClient(RestClientConfiguration.asUser());
    ProductVersion created = client.createNew(productVersion);
    // then
    assertThat(created.getAttributes()).containsKey(Attributes.BREW_TAG_PREFIX);
    assertThat(created.getAttributes().get(Attributes.BREW_TAG_PREFIX)).isEqualTo(product.getAbbreviation().toLowerCase() + "-" + version + "-pnc");
}
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 19 with ProductVersionClient

use of org.jboss.pnc.client.ProductVersionClient in project pnc by project-ncl.

the class ProductVersionEndpointTest method testGetReleases.

@Test
public void testGetReleases() throws ClientException {
    ProductVersionClient client = new ProductVersionClient(RestClientConfiguration.asAnonymous());
    RemoteCollection<ProductRelease> all = client.getReleases(productVersionsId);
    assertThat(all).hasSize(1).allMatch(v -> v.getProductVersion().getId().equals(productVersionsId));
}
Also used : ProductRelease(org.jboss.pnc.dto.ProductRelease) ProductVersionClient(org.jboss.pnc.client.ProductVersionClient) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 20 with ProductVersionClient

use of org.jboss.pnc.client.ProductVersionClient in project pnc by project-ncl.

the class ProductVersionEndpointTest method testCreateNew.

@Test
public void testCreateNew() throws ClientException {
    // given
    ProductVersion productVersion = ProductVersion.builder().product(product).version("42.0").build();
    // when
    ProductVersionClient client = new ProductVersionClient(RestClientConfiguration.asUser());
    ProductVersion created = client.createNew(productVersion);
    // then
    assertThat(created.getId()).isNotEmpty();
    ProductVersion retrieved = client.getSpecific(created.getId());
    ProductVersion toCompare = productVersion.toBuilder().productMilestones(// query had null, but server responds with empty map
    Collections.emptyMap()).productReleases(// query had null, but server responds with empty map
    Collections.emptyMap()).groupConfigs(// query had null, but server responds with empty map
    Collections.emptyMap()).buildConfigs(// query had null, but server responds with empty map
    Collections.emptyMap()).build();
    assertThat(created.getProduct().getId()).isEqualTo(toCompare.getProduct().getId());
    assertThat(created).isEqualToIgnoringGivenFields(toCompare, "id", "product", "attributes");
    assertThat(retrieved).isEqualTo(created);
}
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)

Aggregations

ProductVersionClient (org.jboss.pnc.client.ProductVersionClient)25 ContainerTest (org.jboss.pnc.test.category.ContainerTest)20 Test (org.junit.Test)20 ProductVersion (org.jboss.pnc.dto.ProductVersion)17 GroupConfigurationRef (org.jboss.pnc.dto.GroupConfigurationRef)6 HashMap (java.util.HashMap)5 ProductClient (org.jboss.pnc.client.ProductClient)4 ProductVersionPatchBuilder (org.jboss.pnc.client.patch.ProductVersionPatchBuilder)4 GroupConfiguration (org.jboss.pnc.dto.GroupConfiguration)4 ProductMilestone (org.jboss.pnc.dto.ProductMilestone)4 GroupConfigurationClient (org.jboss.pnc.client.GroupConfigurationClient)3 ProductMilestoneClient (org.jboss.pnc.client.ProductMilestoneClient)2 RemoteResourceException (org.jboss.pnc.client.RemoteResourceException)2 BuildConfiguration (org.jboss.pnc.dto.BuildConfiguration)2 Product (org.jboss.pnc.dto.Product)2 ValidationResponse (org.jboss.pnc.dto.response.ValidationResponse)2 BeforeClass (org.junit.BeforeClass)2 IOException (java.io.IOException)1 Instant (java.time.Instant)1 Iterator (java.util.Iterator)1