diff options
author | Jim Hahn <jrh3@att.com> | 2019-09-12 17:29:49 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2019-09-12 18:06:10 -0400 |
commit | 3075051aa8ae9a2af4267148da5221687c6da9ba (patch) | |
tree | 1f4cfe861f508aa84dd7476da9da520ddd91930d /policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/YamlExceptionMapperTest.java | |
parent | 173c4dbea9a1175a6f18031a221bb701deeecaa7 (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/YamlExceptionMapperTest.java')
-rw-r--r-- | policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/YamlExceptionMapperTest.java | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/YamlExceptionMapperTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/YamlExceptionMapperTest.java new file mode 100644 index 00000000..96c23ed3 --- /dev/null +++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/YamlExceptionMapperTest.java @@ -0,0 +1,50 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP + * ================================================================================ + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.common.endpoints.http.server.test; + +import static org.junit.Assert.assertEquals; + +import javax.ws.rs.core.Response; +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.common.endpoints.http.server.YamlExceptionMapper; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.common.utils.coder.StandardYamlCoder; +import org.yaml.snakeyaml.error.YAMLException; + +public class YamlExceptionMapperTest { + private YamlExceptionMapper mapper; + + @Before + public void setUp() { + mapper = new YamlExceptionMapper(); + } + + @Test + public void testToResponse() throws CoderException { + YAMLException ex = new YAMLException("expected exception"); + Response resp = mapper.toResponse(ex); + + assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), resp.getStatus()); + assertEquals("errorDetails: Invalid request", + new StandardYamlCoder().encode(resp.getEntity()).trim()); + } +} |