diff options
Diffstat (limited to 'a1-policy-management/src/test')
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) { |