Skip to content

Commit

Permalink
#316 Fix for loading config file and parsing json
Browse files Browse the repository at this point in the history
  • Loading branch information
rnc authored and thescouser89 committed Aug 20, 2020
1 parent ec64a0b commit 55c9943
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
11 changes: 11 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ profile:
pnc:
url: ""
bifrostBaseurl: ""
keycloak:
url: ""
realm: ""
username: ""
clientId: ""
pig:
kojiHubUrl: ""
licenseServerUrl: ""
indyUrl: ""
da:
url: ""
# ******************************************************************************
# Authentication information
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private BuildFinderUtils() {

private static final String KOJI_BUILD_FINDER_CONFIG_PROP = "koji.build.finder.config";

private static final String KOJI_BUILD_FINDER_CONFIG_TEMPLATE = "koji-build-finder/config.json";
private static final String KOJI_BUILD_FINDER_CONFIG_TEMPLATE = "/koji-build-finder/config.json";

public static BuildConfig getKojiBuildFinderConfigFromFile(File file) {
try {
Expand All @@ -66,10 +66,9 @@ public static BuildConfig getKojiBuildFinderConfigFromResource(String resourceNa
}

public static BuildConfig getKojiBuildFinderConfigFromJson(String json) {
ObjectMapper mapper = new KojiObjectMapper();

try {
return mapper.readValue(json, BuildConfig.class);
return BuildConfig.load(json);
} catch (IOException e) {
throw new IllegalStateException("Failed read Koji Build Finder configuration from json: " + json, e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.jboss.pnc.bacon.pig.impl.utils;

import java.io.File;

import com.redhat.red.build.finder.BuildConfig;
import org.jboss.pnc.bacon.config.Config;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertTrue;

class BuildFinderUtilsTest {
@Test
void getKojiBuildFinderConfig() {
File configFile = new File(
new File(BuildFinderUtilsTest.class.getResource("/").getFile()).getParentFile()
.getParentFile()
.getParentFile(),
"config.yaml");
Config.configure(configFile.getParent(), configFile.getName(), "default");
Config.instance().getActiveProfile().getPig().setKojiHubUrl("https://127.0.0.1");

BuildConfig bc = BuildFinderUtils.getKojiBuildFinderConfig();
assertTrue(bc.getKojiHubURL().toString().contains("127.0.0.1"));
}
}

0 comments on commit 55c9943

Please sign in to comment.