diff options
author | Henrik Andersson <henrik.b.andersson@est.tech> | 2019-04-09 10:55:51 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-04-09 10:55:51 +0000 |
commit | a64dfa11dba25f9e22ae931a4e5c9b177e6527e0 (patch) | |
tree | 4f2f6653ed113ca6b543e9c33ed567103e9e313f /src/test | |
parent | dc280ce19354f127d4f1ffd1ff83f6642a7eeb6a (diff) | |
parent | 4393d54cb1f76beef314dd6810f00624d87b0db6 (diff) |
Merge "Fix required config validation"
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/java/org/onap/dcaegen2/pmmapper/config/ConfigHandlerTests.java | 30 | ||||
-rw-r--r-- | src/test/resources/incomplete_mapper_config.json | 24 |
2 files changed, 28 insertions, 26 deletions
diff --git a/src/test/java/org/onap/dcaegen2/pmmapper/config/ConfigHandlerTests.java b/src/test/java/org/onap/dcaegen2/pmmapper/config/ConfigHandlerTests.java index f6aa2a8..e2bb4f5 100644 --- a/src/test/java/org/onap/dcaegen2/pmmapper/config/ConfigHandlerTests.java +++ b/src/test/java/org/onap/dcaegen2/pmmapper/config/ConfigHandlerTests.java @@ -25,6 +25,8 @@ import java.io.BufferedReader; import java.io.IOException;
import java.io.InputStreamReader;
import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -48,6 +50,8 @@ import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner;
import com.google.gson.Gson;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.read.ListAppender;
@@ -114,8 +118,24 @@ public class ConfigHandlerTests { @Test
public void mapper_parse_valid_json_missing_attributes() throws Exception {
- when(sender.send(anyString())).thenReturn(getFileContents("incomplete_mapper_config.json"));
- assertThrows(MapperConfigException.class, this::getMapperConfig);
+ Map<String,String> invalidConfigs = new HashMap<>();
+ invalidConfigs.put("streams_subscribes", "{}");
+ invalidConfigs.put("streams_publishes", "{}");
+ invalidConfigs.put("streams_publishes", null);
+ invalidConfigs.remove("streams_publishes");
+ invalidConfigs.put("pm-mapper-filter", null);
+ invalidConfigs.put("pm-mapper-filter", "{}");
+ invalidConfigs.put("pm-mapper-filter", "{ \"filters\": null},");
+ invalidConfigs.put("pm-mapper-filter", "{ \"filters\": [{\"pmDefVsn\": \"V9\"}] },");
+
+ invalidConfigs.forEach( (k,v) -> {
+ try {
+ when(sender.send(anyString())).thenReturn( getInvalidConfig(k,v));
+ assertThrows(MapperConfigException.class, this::getMapperConfig);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ });
}
private MapperConfig getMapperConfig()
@@ -136,4 +156,10 @@ public class ConfigHandlerTests { return fileAsString;
}
+ private String getInvalidConfig(String validKey, String invalidValue) {
+ JsonObject invalidConfigJson = new JsonParser().parse(validMapperConfig).getAsJsonObject();
+ invalidConfigJson.addProperty(validKey, invalidValue);
+ return invalidConfigJson.toString();
+ }
+
}
diff --git a/src/test/resources/incomplete_mapper_config.json b/src/test/resources/incomplete_mapper_config.json deleted file mode 100644 index ed4ebd7..0000000 --- a/src/test/resources/incomplete_mapper_config.json +++ /dev/null @@ -1,24 +0,0 @@ -{
- "_comment": "This mapper config is missing streams_subscribes",
- "pm-mapper-filter": {
- "filters": "{[]}"
- },
- "3GPP.schema.file": "{\"3GPP_Schema\":\"./etc/3GPP_relaxed_schema.xsd\"}",
- "streams_subscribes": null,
- "streams_publishes": {
- "pm_mapper_handle_out": {
- "type": "message_router",
- "aaf_password": null,
- "dmaap_info": {
- "topic_url": "https://we-are-message-router.us:3905/events/some-topic",
- "client_role": null,
- "location": null,
- "client_id": null
- },
- "aaf_username": null
- }
- },
- "some parameter": "unauthenticated.PM_VES_OUTPUT",
- "some field": "1",
- "services_calls": {}
-}
\ No newline at end of file |