From 4393d54cb1f76beef314dd6810f00624d87b0db6 Mon Sep 17 00:00:00 2001 From: emartin Date: Fri, 5 Apr 2019 09:51:13 +0000 Subject: Fix required config validation *Nested objects and list validation Change-Id: Icf615a610dd6e669d66ae07adc1316ca167a671b Issue-ID: DCAEGEN2-1327 Signed-off-by: emartin --- .../pmmapper/config/ConfigHandlerTests.java | 30 ++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'src/test/java') 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 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(); + } + } -- cgit 1.2.3-korg