Search in sources :

Example 46 with BuildConfiguration

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

the class PncBuilderTest method getCountOfBuildConfigsForGroupBuild.

@Test
void getCountOfBuildConfigsForGroupBuild() throws Exception {
    Map<String, BuildConfigurationRef> buildConfigurations = new HashMap<>();
    BuildConfigurationRef bc1 = easyRandom.nextObject(BuildConfigurationRef.class);
    BuildConfigurationRef bc2 = easyRandom.nextObject(BuildConfigurationRef.class);
    BuildConfigurationRef bc3 = easyRandom.nextObject(BuildConfigurationRef.class);
    buildConfigurations.put(bc1.getName(), bc1);
    buildConfigurations.put(bc2.getName(), bc2);
    buildConfigurations.put(bc3.getName(), bc3);
    String groupConfigurationId = "5";
    String groupBuildId = "1";
    GroupConfiguration gc = GroupConfiguration.builder().id(groupConfigurationId).buildConfigs(buildConfigurations).build();
    GroupBuild gb = GroupBuild.builder().id(groupBuildId).groupConfig(gc).build();
    when(groupBuildClient.getSpecific(groupBuildId)).thenReturn(gb);
    when(groupConfigurationClient.getBuildConfigs(groupConfigurationId)).thenReturn(new RemoteCollection<BuildConfiguration>() {

        @Override
        public int size() {
            return buildConfigurations.size();
        }

        @Override
        public Collection<BuildConfiguration> getAll() {
            return null;
        }

        @Override
        public Iterator<BuildConfiguration> iterator() {
            return null;
        }
    });
    try (PncBuilder builder = new PncBuilder(groupBuildClient, groupConfigurationClient)) {
        assertEquals(buildConfigurations.size(), builder.getCountOfBuildConfigsForGroupBuild(groupBuildId));
    }
}
Also used : BuildConfigurationRef(org.jboss.pnc.dto.BuildConfigurationRef) BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) HashMap(java.util.HashMap) GroupBuild(org.jboss.pnc.dto.GroupBuild) Iterator(java.util.Iterator) Collection(java.util.Collection) RemoteCollection(org.jboss.pnc.client.RemoteCollection) GroupConfiguration(org.jboss.pnc.dto.GroupConfiguration) Test(org.junit.jupiter.api.Test)

Example 47 with BuildConfiguration

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

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

the class BuildInfoCollector method getBuildsFromLatestGroupConfiguration.

/**
 * Get the latest GroupBuildInfo from the groupConfiguration id. If there are no group builds, a runtime exception
 * is thrown.
 *
 * @param groupConfigurationId the group configuration id
 * @param temporaryBuild whether the group build is temporary or not
 * @return GroupBuildInfo data of the group build and the list of builds
 */
public GroupBuildInfo getBuildsFromLatestGroupConfiguration(String groupConfigurationId, boolean temporaryBuild) {
    try {
        RemoteCollection<BuildConfiguration> configs = groupConfigurationClient.getBuildConfigs(groupConfigurationId);
        Map<String, PncBuild> builds = new HashMap<>();
        for (BuildConfiguration config : configs) {
            PncBuild build = getLatestBuild(config.getId(), temporaryBuild ? BuildSearchType.ANY : BuildSearchType.PERMANENT);
            builds.put(config.getName(), build);
        }
        // TODO: builds should be enough, getting latest build group to satisfy the current API
        return new GroupBuildInfo(getLatestGroupBuild(groupConfigurationId, temporaryBuild), builds);
    } catch (RemoteResourceException e) {
        throw new RuntimeException("Cannot get list of group builds for group configuration " + groupConfigurationId);
    }
}
Also used : BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) RemoteResourceException(org.jboss.pnc.client.RemoteResourceException) HashMap(java.util.HashMap) GroupBuildInfo(org.jboss.pnc.bacon.pig.impl.config.GroupBuildInfo)

Example 49 with BuildConfiguration

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

the class BuildConfigMappingTest method testAlignmentParametersSet.

@Test
void testAlignmentParametersSet() {
    Map<String, String> parameters = new HashMap<>();
    parameters.put("ALIGNMENT_PARAMETERS", "-Dtest=true -Dme=false");
    BuildConfiguration buildConfiguration = BuildConfiguration.builder().parameters(parameters).build();
    BuildConfigMapping.setBuildConfigFieldsBasedOnParameters(buildConfiguration, buildConfig);
    assertEquals("-Dtest=true -Dme=false", buildConfig.getAlignmentParameters().stream().findFirst().get());
    // make sure no other parameters are set
    assertNull(buildConfig.getBuildPodMemory());
    assertNull(buildConfig.getBuildCategory());
    assertNull(buildConfig.getPigYamlMetadata());
    assertNull(buildConfig.getBrewBuildName());
    assertTrue(buildConfig.getExtraRepositories().size() == 0);
}
Also used : BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Example 50 with BuildConfiguration

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

the class BuildConfigMappingTest method testBuilderPodMemorySet.

@Test
void testBuilderPodMemorySet() {
    Map<String, String> parameters = new HashMap<>();
    parameters.put("BUILDER_POD_MEMORY", "10");
    BuildConfiguration buildConfiguration = BuildConfiguration.builder().parameters(parameters).build();
    BuildConfigMapping.setBuildConfigFieldsBasedOnParameters(buildConfiguration, buildConfig);
    assertTrue(Math.abs(10.0 - buildConfig.getBuildPodMemory()) <= 0.000001);
    // make sure no other parameters are set
    assertTrue(buildConfig.getAlignmentParameters().size() == 0);
    assertNull(buildConfig.getBuildCategory());
    assertNull(buildConfig.getPigYamlMetadata());
    assertNull(buildConfig.getBrewBuildName());
    assertTrue(buildConfig.getExtraRepositories().size() == 0);
}
Also used : BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Aggregations

BuildConfiguration (org.jboss.pnc.dto.BuildConfiguration)90 Test (org.junit.Test)65 ContainerTest (org.jboss.pnc.test.category.ContainerTest)45 BuildConfigurationClient (org.jboss.pnc.client.BuildConfigurationClient)31 HashMap (java.util.HashMap)17 InSequence (org.jboss.arquillian.junit.InSequence)17 Build (org.jboss.pnc.dto.Build)13 GroupBuild (org.jboss.pnc.dto.GroupBuild)12 SCMRepository (org.jboss.pnc.dto.SCMRepository)10 Test (org.junit.jupiter.api.Test)10 BuildConfigurationRef (org.jboss.pnc.dto.BuildConfigurationRef)9 Instant (java.time.Instant)8 GroupConfiguration (org.jboss.pnc.dto.GroupConfiguration)7 BuildStatus (org.jboss.pnc.enums.BuildStatus)7 GroupConfigurationClient (org.jboss.pnc.client.GroupConfigurationClient)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 ArrayList (java.util.ArrayList)4 BuildConfigurationRevision (org.jboss.pnc.dto.BuildConfigurationRevision)4 HashSet (java.util.HashSet)3