Search in sources :

Example 1 with PncConfigProvider

use of org.jboss.pnc.common.json.moduleprovider.PncConfigProvider in project pnc by project-ncl.

the class ModuleConfigJsonTest method deserializationTest.

@Test
public void deserializationTest() throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    PncConfigProvider<AuthenticationModuleConfig> pncProvider = new PncConfigProvider<>(AuthenticationModuleConfig.class);
    pncProvider.registerProvider(mapper);
    mapper.registerSubtypes(PNCModuleGroup.class);
    ModuleConfigJson config = mapper.readValue(loadConfig("testConfigNoSpaces.json"), ModuleConfigJson.class);
    assertNotNull(config);
    assertEquals(1, config.getConfigs().size());
    PNCModuleGroup group = (PNCModuleGroup) config.getConfigs().get(0);
    assertEquals(2, group.getConfigs().size());
}
Also used : AuthenticationModuleConfig(org.jboss.pnc.common.json.moduleconfig.AuthenticationModuleConfig) PncConfigProvider(org.jboss.pnc.common.json.moduleprovider.PncConfigProvider) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 2 with PncConfigProvider

use of org.jboss.pnc.common.json.moduleprovider.PncConfigProvider in project pnc by project-ncl.

the class ModuleConfigJsonTest method serializationTest.

@Test
public void serializationTest() throws IOException {
    ModuleConfigJson moduleConfigJson = new ModuleConfigJson("pnc-config");
    JenkinsBuildDriverModuleConfig jenkinsBuildDriverModuleConfig = new JenkinsBuildDriverModuleConfig("user", "pass");
    IndyRepoDriverModuleConfig indyRepoDriverModuleConfig = new IndyRepoDriverModuleConfig();
    indyRepoDriverModuleConfig.setBuildRepositoryAllowSnapshots(true);
    indyRepoDriverModuleConfig.setDefaultRequestTimeout(100);
    List<String> ignoredPatternsMaven = new ArrayList<>(2);
    ignoredPatternsMaven.add(".*/maven-metadata\\.xml$");
    ignoredPatternsMaven.add(".*\\.sha1$");
    IgnoredPatterns ignoredPatterns = new IgnoredPatterns();
    ignoredPatterns.setMaven(ignoredPatternsMaven);
    IgnoredPathPatterns ignoredPathPatterns = new IgnoredPathPatterns();
    ignoredPathPatterns.setPromotion(ignoredPatterns);
    indyRepoDriverModuleConfig.setIgnoredPathPatterns(ignoredPathPatterns);
    PNCModuleGroup pncGroup = new PNCModuleGroup();
    pncGroup.addConfig(jenkinsBuildDriverModuleConfig);
    pncGroup.addConfig(indyRepoDriverModuleConfig);
    moduleConfigJson.addConfig(pncGroup);
    ObjectMapper mapper = new ObjectMapper();
    PncConfigProvider<AuthenticationModuleConfig> pncProvider = new PncConfigProvider<>(AuthenticationModuleConfig.class);
    pncProvider.registerProvider(mapper);
    ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream();
    mapper.writeValue(byteOutStream, moduleConfigJson);
    assertEquals(loadConfig("testConfigNoSpaces.json"), byteOutStream.toString());
}
Also used : JenkinsBuildDriverModuleConfig(org.jboss.pnc.common.json.moduleconfig.JenkinsBuildDriverModuleConfig) IndyRepoDriverModuleConfig(org.jboss.pnc.common.json.moduleconfig.IndyRepoDriverModuleConfig) ArrayList(java.util.ArrayList) AuthenticationModuleConfig(org.jboss.pnc.common.json.moduleconfig.AuthenticationModuleConfig) PncConfigProvider(org.jboss.pnc.common.json.moduleprovider.PncConfigProvider) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IgnoredPatterns(org.jboss.pnc.common.json.moduleconfig.IndyRepoDriverModuleConfig.IgnoredPatterns) IgnoredPathPatterns(org.jboss.pnc.common.json.moduleconfig.IndyRepoDriverModuleConfig.IgnoredPathPatterns) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 3 with PncConfigProvider

use of org.jboss.pnc.common.json.moduleprovider.PncConfigProvider in project pnc by project-ncl.

the class DemoDataInitializer method initialize.

@PostConstruct
public void initialize() {
    DemoDataConfig demoDataConfig = null;
    try {
        demoDataConfig = configuration.getModuleConfig(new PncConfigProvider<>(DemoDataConfig.class));
    } catch (ConfigurationParseException e) {
        logger.warn("Cannot read demo data config.", e);
    }
    if (demoDataConfig == null || !demoDataConfig.getImportDemoData()) {
        logger.info("Demo data import is not enabled.");
        return;
    }
    long numberOfProjectInDB = projectRepository.count();
    if (numberOfProjectInDB != 0) {
        logger.info("There are >0 ({}) projects in DB. Skipping initialization." + numberOfProjectInDB);
    } else {
        logger.info("Initializing DEMO data");
        dbDataInitializer.initiliazeProjectProductData();
        dbDataInitializer.initiliazeBuildRecordDemoData();
        dbDataInitializer.verifyData();
        logger.info("Finished initializing DEMO data");
    }
}
Also used : ConfigurationParseException(org.jboss.pnc.common.json.ConfigurationParseException) PncConfigProvider(org.jboss.pnc.common.json.moduleprovider.PncConfigProvider) DemoDataConfig(org.jboss.pnc.common.json.moduleconfig.DemoDataConfig) PostConstruct(javax.annotation.PostConstruct)

Example 4 with PncConfigProvider

use of org.jboss.pnc.common.json.moduleprovider.PncConfigProvider in project pnc by project-ncl.

the class AbstractRepositoryManagerDriverTest method setup.

@Before
public void setup() throws Exception {
    // workaround for NPE in Indy 1.6.2 client
    MDC.put("dummy", "non");
    fixture = newServerFixture();
    Properties sysprops = System.getProperties();
    oldIni = sysprops.getProperty(CONFIG_SYSPROP);
    url = fixture.getUrl();
    File configFile = temp.newFile("pnc-config.json");
    ModuleConfigJson moduleConfigJson = new ModuleConfigJson("pnc-config");
    IndyRepoDriverModuleConfig mavenRepoDriverModuleConfig = new IndyRepoDriverModuleConfig();
    mavenRepoDriverModuleConfig.setIgnoredRepoPatterns(getIgnoredRepoPatterns());
    mavenRepoDriverModuleConfig.setBrewPullActiveMetadataKey(BREW_PULL_ACTIVE_METADATA_KEY);
    preConfigureMavenRepositoryDriver(mavenRepoDriverModuleConfig);
    SystemConfig systemConfig = new SystemConfig("", "", "JAAS", "4", "4", "4", "", "5", null, null, "14", "", "10");
    GlobalModuleGroup globalConfig = new GlobalModuleGroup();
    globalConfig.setIndyUrl(fixture.getUrl());
    PNCModuleGroup pncGroup = new PNCModuleGroup();
    pncGroup.addConfig(mavenRepoDriverModuleConfig);
    pncGroup.addConfig(systemConfig);
    moduleConfigJson.addConfig(globalConfig);
    moduleConfigJson.addConfig(pncGroup);
    ObjectMapper mapper = new ObjectMapper();
    PncConfigProvider<IndyRepoDriverModuleConfig> pncProvider = new PncConfigProvider<>(IndyRepoDriverModuleConfig.class);
    pncProvider.registerProvider(mapper);
    mapper.writeValue(configFile, moduleConfigJson);
    sysprops.setProperty(CONFIG_SYSPROP, configFile.getAbsolutePath());
    System.setProperties(sysprops);
    fixture.start();
    if (!fixture.isStarted()) {
        final BootStatus status = fixture.getBootStatus();
        throw new IllegalStateException("server fixture failed to boot.", status.getError());
    }
    Properties props = new Properties();
    props.setProperty("base.url", url);
    System.out.println("Using base URL: " + url);
    Configuration config = new Configuration();
    BuildRecordRepositoryMock bcRepository = new BuildRecordRepositoryMock();
    driver = new RepositoryManagerDriver(config, bcRepository);
}
Also used : SystemConfig(org.jboss.pnc.common.json.moduleconfig.SystemConfig) IndyRepoDriverModuleConfig(org.jboss.pnc.common.json.moduleconfig.IndyRepoDriverModuleConfig) Configuration(org.jboss.pnc.common.Configuration) BuildRecordRepositoryMock(org.jboss.pnc.mock.repository.BuildRecordRepositoryMock) ModuleConfigJson(org.jboss.pnc.common.json.ModuleConfigJson) BootStatus(org.commonjava.propulsor.boot.BootStatus) PncConfigProvider(org.jboss.pnc.common.json.moduleprovider.PncConfigProvider) Properties(java.util.Properties) GlobalModuleGroup(org.jboss.pnc.common.json.GlobalModuleGroup) PNCModuleGroup(org.jboss.pnc.common.json.PNCModuleGroup) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Aggregations

PncConfigProvider (org.jboss.pnc.common.json.moduleprovider.PncConfigProvider)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 AuthenticationModuleConfig (org.jboss.pnc.common.json.moduleconfig.AuthenticationModuleConfig)2 IndyRepoDriverModuleConfig (org.jboss.pnc.common.json.moduleconfig.IndyRepoDriverModuleConfig)2 Test (org.junit.Test)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 PostConstruct (javax.annotation.PostConstruct)1 BootStatus (org.commonjava.propulsor.boot.BootStatus)1 Configuration (org.jboss.pnc.common.Configuration)1 ConfigurationParseException (org.jboss.pnc.common.json.ConfigurationParseException)1 GlobalModuleGroup (org.jboss.pnc.common.json.GlobalModuleGroup)1 ModuleConfigJson (org.jboss.pnc.common.json.ModuleConfigJson)1 PNCModuleGroup (org.jboss.pnc.common.json.PNCModuleGroup)1 DemoDataConfig (org.jboss.pnc.common.json.moduleconfig.DemoDataConfig)1 IgnoredPathPatterns (org.jboss.pnc.common.json.moduleconfig.IndyRepoDriverModuleConfig.IgnoredPathPatterns)1 IgnoredPatterns (org.jboss.pnc.common.json.moduleconfig.IndyRepoDriverModuleConfig.IgnoredPatterns)1 JenkinsBuildDriverModuleConfig (org.jboss.pnc.common.json.moduleconfig.JenkinsBuildDriverModuleConfig)1