diff options
author | PatrikBuhr <patrik.buhr@est.tech> | 2020-11-23 13:24:45 +0100 |
---|---|---|
committer | PatrikBuhr <patrik.buhr@est.tech> | 2020-11-24 14:47:16 +0100 |
commit | 3b56b4ff40eba05108651d04df4b9a2ef3a4eb1d (patch) | |
tree | b071a923bd9295617f79e3cd95d943e04ab34a8a /a1-policy-management/src/test/java | |
parent | 50fe65ea5daca6935cdbc1155adbfb53f5a28c40 (diff) |
Added GET config
Corrected config so that PUT config receives an object intestead of a string
Change-Id: Id784cc2840a2e2e981b0c4e874b8a848964e00ea
Issue-ID: CCSDK-2966
Signed-off-by: PatrikBuhr <patrik.buhr@est.tech>
Diffstat (limited to 'a1-policy-management/src/test/java')
2 files changed, 26 insertions, 13 deletions
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java index 516ddd5f..30ce4c3e 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java @@ -30,10 +30,12 @@ import static org.mockito.Mockito.doReturn; import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import java.io.FileNotFoundException; import java.io.FileOutputStream; +import java.io.IOException; import java.io.PrintStream; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; import java.time.Duration; import java.time.Instant; import java.util.ArrayList; @@ -211,12 +213,14 @@ class ApplicationTest { } @Test - void createApiDoc() throws FileNotFoundException { + void createApiDoc() throws IOException { String url = "https://localhost:" + this.port + "/v2/api-docs"; ResponseEntity<String> resp = restClient("", false).getForEntity(url).block(); assertThat(resp.getStatusCode()).isEqualTo(HttpStatus.OK); String indented = (new JSONObject(resp.getBody())).toString(4); - try (PrintStream out = new PrintStream(new FileOutputStream("../docs/offeredapis/swagger/pms-api.json"))) { + String docDir = "../docs/offeredapis/swagger/"; + Files.createDirectories(Paths.get(docDir)); + try (PrintStream out = new PrintStream(new FileOutputStream(docDir + "pms-api.json"))) { out.print(indented); } } diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationControllerTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationControllerTest.java index 8f9d236b..376ce76e 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationControllerTest.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationControllerTest.java @@ -105,27 +105,36 @@ class ConfigurationControllerTest { @Test void putValidConfigurationWithNewRic_shouldUpdateRepository() throws Exception { - String url = "https://localhost:" + this.port + "/v2/configuration"; + String url = "/v2/configuration"; - File configFile = new File(getClass().getClassLoader() - .getResource("test_application_configuration_with_dmaap_config.json").getFile()); - String configFileAsString = FileUtils.readFileToString(configFile, "UTF-8"); - - String resp = restClient().put(url, configFileAsString).block(); + String resp = restClient().put(url, configAsString()).block(); assertThat(resp).isEmpty(); await().until(rics::size, equalTo(2)); + + // GET config + resp = restClient().get(url).block(); + assertThat(resp).contains("config"); + } + + @Test + void getNoFileExists() { + String url = "/v2/configuration"; + testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND, "File does not exist"); + } + + private String configAsString() throws Exception { + File configFile = new File(getClass().getClassLoader() + .getResource("test_application_configuration_with_dmaap_config.json").getFile()); + return FileUtils.readFileToString(configFile, "UTF-8"); } @Test void putInvalidConfiguration_shouldReturnError400() throws Exception { - String url = "https://localhost:" + this.port + "/v2/configuration"; + String url = "/v2/configuration"; // Valid JSON but invalid configuration. testErrorCode(restClient().put(url, "{\"error\":\"error\"}"), HttpStatus.BAD_REQUEST, "Faulty configuration"); - - // Invalid JSON. - testErrorCode(restClient().put(url, "{\"error\":\"error\""), HttpStatus.BAD_REQUEST, "Faulty configuration"); } private void testErrorCode(Mono<?> request, HttpStatus expStatus, String responseContains) { |