aboutsummaryrefslogtreecommitdiffstats
path: root/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/YamlMessageBodyHandlerTest.java
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2019-09-12 17:29:49 -0400
committerJim Hahn <jrh3@att.com>2019-09-12 18:06:10 -0400
commit3075051aa8ae9a2af4267148da5221687c6da9ba (patch)
tree1f4cfe861f508aa84dd7476da9da520ddd91930d /policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/YamlMessageBodyHandlerTest.java
parent173c4dbea9a1175a6f18031a221bb701deeecaa7 (diff)
Report bad-request for invalid YAML
Added classes and modified code to report bad-request when a servlet attempts to read invalid YAML. Change-Id: Iacddee92a448fb69d5c778a3c3f3f2b5528983f7 Issue-ID: POLICY-2085 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/YamlMessageBodyHandlerTest.java')
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/YamlMessageBodyHandlerTest.java13
1 files changed, 12 insertions, 1 deletions
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/YamlMessageBodyHandlerTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/YamlMessageBodyHandlerTest.java
index b8963e9b..0ddad0bf 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/YamlMessageBodyHandlerTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/YamlMessageBodyHandlerTest.java
@@ -36,6 +36,7 @@ import javax.ws.rs.core.MediaType;
import org.junit.Before;
import org.junit.Test;
import org.onap.policy.common.endpoints.http.server.YamlMessageBodyHandler;
+import org.yaml.snakeyaml.error.YAMLException;
public class YamlMessageBodyHandlerTest {
private static final String EXPECTED_EXCEPTION = "expected exception";
@@ -168,7 +169,17 @@ public class YamlMessageBodyHandlerTest {
};
assertThatThrownBy(() -> hdlr.readFrom(CLASS_OBJ, CLASS_OBJ, null, null, null, inpstr))
- .isInstanceOf(IOException.class);
+ .isInstanceOf(YAMLException.class);
+
+ inpstr.close();
+ }
+
+ @Test
+ public void testReadFrom_Invalid() throws Exception {
+ InputStream inpstr = new ByteArrayInputStream("plain text".getBytes());
+
+ assertThatThrownBy(() -> hdlr.readFrom(CLASS_OBJ, CLASS_OBJ, null, null, null, inpstr))
+ .isInstanceOf(YAMLException.class);
inpstr.close();
}