Search in sources :

Example 11 with ProductVersion

use of org.jboss.pnc.dto.ProductVersion in project bacon by project-ncl.

the class PigFacade method getBrewTag.

private static String getBrewTag(ProductVersionRef versionRef) {
    try (ProductVersionClient productVersionClient = new ProductVersionClient(PncClientHelper.getPncConfiguration())) {
        String versionId = versionRef.getId();
        ProductVersion version;
        try {
            version = productVersionClient.getSpecific(versionId);
        } catch (RemoteResourceException e) {
            throw new RuntimeException("Unable to get product version for " + versionId, e);
        }
        return version.getAttributes().get("BREW_TAG_PREFIX");
    }
}
Also used : RemoteResourceException(org.jboss.pnc.client.RemoteResourceException) ProductVersion(org.jboss.pnc.dto.ProductVersion) ProductVersionClient(org.jboss.pnc.client.ProductVersionClient)

Example 12 with ProductVersion

use of org.jboss.pnc.dto.ProductVersion in project bacon by project-ncl.

the class PigTest method shouldCreateProduct.

@Test
@Order(1)
void shouldCreateProduct() throws IOException {
    final Path configFile = CONFIG_LOCATION;
    replaceSuffixInConfigFile(configFile.resolve("build-config.yaml"));
    final Product product = Product.builder().id(UNIVERSAL_ID).name(PRODUCT_NAME).abbreviation(PRODUCT_ABBREVIATION).build();
    final ProductVersion productVersion = ProductVersion.builder().id(UNIVERSAL_ID).version(VERSION).product(product).build();
    final ProductMilestone productMilestone = ProductMilestone.builder().id(UNIVERSAL_ID).productVersion(productVersion).version(MILESTONE).build();
    final ProductVersion productVersionWithCurrentMilestone = productVersion.toBuilder().currentProductMilestone(productMilestone).build();
    final GroupConfiguration groupConfig = GroupConfiguration.builder().id(UNIVERSAL_ID).name(GROUP_NAME).productVersion(productVersionWithCurrentMilestone).build();
    final Project project = Project.builder().id(UNIVERSAL_ID).name(PROJECT_NAME).build();
    final SCMRepository scmRepository = SCMRepository.builder().id(UNIVERSAL_ID).internalUrl(SCM_URL).preBuildSyncEnabled(true).build();
    final Environment environment = Environment.builder().id(UNIVERSAL_ID).deprecated(false).build();
    final BuildConfiguration buildConfig = BuildConfiguration.builder().id(UNIVERSAL_ID).name(BC_NAME).buildScript(BUILD_SCRIPT).scmRevision(SCM_REVISION).creationTime(Instant.now()).modificationTime(Instant.now()).scmRepository(scmRepository).environment(environment).project(project).productVersion(productVersionWithCurrentMilestone).build();
    final GroupConfiguration groupConfigWithBuildConfig = groupConfig.toBuilder().buildConfigs(Collections.singletonMap(UNIVERSAL_ID, buildConfig)).build();
    wmock.list(PRODUCT, new Page<Product>());
    wmock.creation(PRODUCT, product);
    wmock.list(PRODUCT_VERSIONS.apply(UNIVERSAL_ID), new Page<ProductVersion>());
    wmock.creation(PRODUCT_VERSION, productVersion);
    wmock.list(PRODUCT_VERSION_MILESTONES.apply(UNIVERSAL_ID), new Page<ProductMilestone>());
    wmock.creation(PRODUCT_MILESTONE, productMilestone);
    wmock.update(PRODUCT_VERSION, productVersion, productVersionWithCurrentMilestone);
    wmock.list(GROUP_CONFIG, new Page<GroupConfiguration>());
    wmock.creation(GROUP_CONFIG, groupConfig);
    wmock.list(GROUP_CONFIG_BUILD_CONFIGS.apply(UNIVERSAL_ID), new Page<BuildConfiguration>());
    wmock.list(BUILD_CONFIG, new Page<BuildConfiguration>());
    wmock.list(PROJECT, new Page<Project>());
    wmock.creation(PROJECT, project);
    wmock.list(SCM_REPOSITORY, new Page<SCMRepository>());
    wmock.creation(SCM_REPOSITORY_CREATE, RepositoryCreationResponse.builder().repository(scmRepository).build());
    wmock.get(ENVIRONMENT, environment);
    wmock.creation(BUILD_CONFIG, buildConfig);
    wmock.list(BUILD_CONFIG_DEPENDENCIES.apply(UNIVERSAL_ID), new Page<BuildConfiguration>());
    wmock.get(BUILD_CONFIG, buildConfig);
    wmock.creation(BUILD_CONFIG, buildConfig);
    wmock.scenario("add BC to GC").getEntity(GROUP_CONFIG, groupConfig).when().post(GROUP_CONFIG_BUILD_CONFIGS.apply(UNIVERSAL_ID)).then().getEntity(GROUP_CONFIG, groupConfigWithBuildConfig);
    ExecutionResult output = executeAndGetResult("pig", "configure", configFile.toString());
    assertThat(output.getOutput()).contains("name: \"Product Foobar " + SUFFIX + "\"");
}
Also used : Path(java.nio.file.Path) ProductMilestone(org.jboss.pnc.dto.ProductMilestone) Product(org.jboss.pnc.dto.Product) ExecutionResult(org.jboss.pnc.bacon.test.ExecutionResult) ProductVersion(org.jboss.pnc.dto.ProductVersion) GroupConfiguration(org.jboss.pnc.dto.GroupConfiguration) BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) Project(org.jboss.pnc.dto.Project) Environment(org.jboss.pnc.dto.Environment) SCMRepository(org.jboss.pnc.dto.SCMRepository) Order(org.junit.jupiter.api.Order) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) AbstractTest(org.jboss.pnc.bacon.test.AbstractTest) Test(org.junit.jupiter.api.Test)

Example 13 with ProductVersion

use of org.jboss.pnc.dto.ProductVersion in project bacon by project-ncl.

the class ProductMilestoneCli method validateProductMilestoneVersion.

/**
 * Product Milestone version format is: <d>.<d>.<d>.<word> The first 2 digits must match the digit for the product
 * version
 *
 * @param productVersionId
 * @param milestoneVersion
 * @return
 */
public static boolean validateProductMilestoneVersion(String productVersionId, String milestoneVersion) throws ClientException {
    try (ProductVersionClient client = VERSION_CREATOR.newClient()) {
        ProductVersion productVersionDTO = client.getSpecific(productVersionId);
        String productVersion = productVersionDTO.getVersion();
        if (!milestoneVersion.startsWith(productVersion)) {
            return false;
        }
        String[] items = milestoneVersion.split("\\.");
        if (items.length != 4) {
            return false;
        }
        return items[2].matches("\\d+");
    }
}
Also used : ProductVersion(org.jboss.pnc.dto.ProductVersion) ProductVersionClient(org.jboss.pnc.client.ProductVersionClient)

Example 14 with ProductVersion

use of org.jboss.pnc.dto.ProductVersion 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 15 with ProductVersion

use of org.jboss.pnc.dto.ProductVersion 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)

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