[OLINGO-1004] Removed ErrorResponseTestITCase and moved the full JSON Exception test into ErrorTest.
Signed-off-by: Michael <michael.bolz@sap.com>
This commit is contained in:
parent
fd2592d4e2
commit
19cfe4b494
|
@ -1,62 +0,0 @@
|
||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
||||||
* or more contributor license agreements. See the NOTICE file
|
|
||||||
* distributed with this work for additional information
|
|
||||||
* regarding copyright ownership. The ASF licenses this file
|
|
||||||
* to you 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.
|
|
||||||
*/
|
|
||||||
package org.apache.olingo.fit.base;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.olingo.client.api.communication.ODataClientErrorException;
|
|
||||||
import org.apache.olingo.commons.api.ex.ODataError;
|
|
||||||
import org.apache.olingo.commons.api.ex.ODataErrorDetail;
|
|
||||||
import org.apache.olingo.commons.api.format.ContentType;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
public class ErrorResponseTestITCase extends AbstractTestITCase {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void jsonError() {
|
|
||||||
final URI readURI = getClient().newURIBuilder(testStaticServiceRootURL).
|
|
||||||
appendEntitySetSegment("Customers").appendKeySegment(32).
|
|
||||||
build();
|
|
||||||
|
|
||||||
try {
|
|
||||||
read(ContentType.JSON, readURI);
|
|
||||||
fail("should have got exception");
|
|
||||||
} catch (Exception ex) {
|
|
||||||
final ODataError err = ((ODataClientErrorException) ex).getODataError();
|
|
||||||
|
|
||||||
// verify details
|
|
||||||
final ODataErrorDetail detail = err.getDetails().get(0);
|
|
||||||
assertEquals("Code should be correct", "301", detail.getCode());
|
|
||||||
assertEquals("Target should be correct", "$search", detail.getTarget());
|
|
||||||
assertEquals("Message should be correct", "$search query option not supported", detail.getMessage());
|
|
||||||
|
|
||||||
// verify inner error dictionary
|
|
||||||
final Map<String, String> innerErr = err.getInnerError();
|
|
||||||
assertEquals("innerError dictionary size should be correct", 2, innerErr.size());
|
|
||||||
assertEquals("innerError['context'] should be correct",
|
|
||||||
"{\"key1\":\"for debug deployment only\"}", innerErr.get("context"));
|
|
||||||
assertEquals("innerError['trace'] should be correct",
|
|
||||||
"[\"callmethod1 etc\",\"callmethod2 etc\"]", innerErr.get("trace"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -296,7 +296,7 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
|
||||||
assertEquals(HttpStatusCode.BAD_REQUEST.getStatusCode(), e.getStatusLine().getStatusCode());
|
assertEquals(HttpStatusCode.BAD_REQUEST.getStatusCode(), e.getStatusLine().getStatusCode());
|
||||||
final ODataError error = e.getODataError();
|
final ODataError error = e.getODataError();
|
||||||
assertThat(error.getMessage(), containsString("key"));
|
assertThat(error.getMessage(), containsString("key"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -64,6 +64,7 @@ import org.apache.olingo.commons.api.format.ContentType;
|
||||||
import org.apache.olingo.commons.core.edm.EdmTypeInfo;
|
import org.apache.olingo.commons.core.edm.EdmTypeInfo;
|
||||||
|
|
||||||
import com.fasterxml.aalto.stax.InputFactoryImpl;
|
import com.fasterxml.aalto.stax.InputFactoryImpl;
|
||||||
|
import org.apache.olingo.commons.api.ex.ODataErrorDetail;
|
||||||
|
|
||||||
public class AtomDeserializer implements ODataDeserializer {
|
public class AtomDeserializer implements ODataDeserializer {
|
||||||
|
|
||||||
|
@ -86,6 +87,7 @@ public class AtomDeserializer implements ODataDeserializer {
|
||||||
protected static final QName errorCodeQName = new QName(Constants.NS_METADATA, Constants.ERROR_CODE);
|
protected static final QName errorCodeQName = new QName(Constants.NS_METADATA, Constants.ERROR_CODE);
|
||||||
protected static final QName errorMessageQName = new QName(Constants.NS_METADATA, Constants.ERROR_MESSAGE);
|
protected static final QName errorMessageQName = new QName(Constants.NS_METADATA, Constants.ERROR_MESSAGE);
|
||||||
protected static final QName errorTargetQName = new QName(Constants.NS_METADATA, Constants.ERROR_TARGET);
|
protected static final QName errorTargetQName = new QName(Constants.NS_METADATA, Constants.ERROR_TARGET);
|
||||||
|
protected static final QName errorDetailQName = new QName(Constants.NS_METADATA, Constants.ERROR_DETAIL);
|
||||||
protected static final QName deletedEntryQName =
|
protected static final QName deletedEntryQName =
|
||||||
new QName(Constants.NS_ATOM_TOMBSTONE, Constants.ATOM_ELEM_DELETED_ENTRY);
|
new QName(Constants.NS_ATOM_TOMBSTONE, Constants.ATOM_ELEM_DELETED_ENTRY);
|
||||||
|
|
||||||
|
@ -826,18 +828,21 @@ public class AtomDeserializer implements ODataDeserializer {
|
||||||
|
|
||||||
private ODataError error(final XMLEventReader reader, final StartElement start) throws XMLStreamException {
|
private ODataError error(final XMLEventReader reader, final StartElement start) throws XMLStreamException {
|
||||||
final ODataError error = new ODataError();
|
final ODataError error = new ODataError();
|
||||||
|
error.setDetails(new ArrayList<ODataErrorDetail>(0));
|
||||||
|
ODataErrorDetail errorDetail = null;
|
||||||
|
|
||||||
boolean setCode = false;
|
boolean setCode = false;
|
||||||
boolean codeSet = false;
|
boolean codeSet = false;
|
||||||
boolean setMessage = false;
|
boolean setMessage = false;
|
||||||
boolean messageSet = false;
|
boolean messageSet = false;
|
||||||
boolean setTarget = false;
|
boolean setTarget = false;
|
||||||
boolean targetSet = false;
|
boolean targetSet = false;
|
||||||
|
boolean isDetails = false;
|
||||||
|
|
||||||
boolean foundEndElement = false;
|
boolean foundEndElement = false;
|
||||||
while (reader.hasNext() && !foundEndElement) {
|
while (reader.hasNext() && !foundEndElement) {
|
||||||
final XMLEvent event = reader.nextEvent();
|
final XMLEvent event = reader.nextEvent();
|
||||||
|
|
||||||
if (event.isStartElement()) {
|
if (event.isStartElement()) {
|
||||||
if (errorCodeQName.equals(event.asStartElement().getName())) {
|
if (errorCodeQName.equals(event.asStartElement().getName())) {
|
||||||
setCode = true;
|
setCode = true;
|
||||||
|
@ -845,6 +850,9 @@ public class AtomDeserializer implements ODataDeserializer {
|
||||||
setMessage = true;
|
setMessage = true;
|
||||||
} else if (errorTargetQName.equals(event.asStartElement().getName())) {
|
} else if (errorTargetQName.equals(event.asStartElement().getName())) {
|
||||||
setTarget = true;
|
setTarget = true;
|
||||||
|
} else if (errorDetailQName.equals(event.asStartElement().getName())){
|
||||||
|
isDetails = true;
|
||||||
|
errorDetail = new ODataErrorDetail();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -864,8 +872,26 @@ public class AtomDeserializer implements ODataDeserializer {
|
||||||
setTarget = false;
|
setTarget = false;
|
||||||
targetSet = true;
|
targetSet = true;
|
||||||
}
|
}
|
||||||
|
// DETAIL Error
|
||||||
|
if(setCode && isDetails){
|
||||||
|
errorDetail.setCode(event.asCharacters().getData());
|
||||||
|
setCode = false;
|
||||||
|
}
|
||||||
|
if(setMessage && isDetails){
|
||||||
|
errorDetail.setMessage(event.asCharacters().getData());
|
||||||
|
setMessage = false;
|
||||||
|
}
|
||||||
|
if(setTarget && isDetails){
|
||||||
|
errorDetail.setTarget(event.asCharacters().getData());
|
||||||
|
setTarget = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(event.isEndElement() && errorDetailQName.equals(event.asEndElement().getName())){
|
||||||
|
isDetails = false;
|
||||||
|
error.getDetails().add(errorDetail);
|
||||||
|
}
|
||||||
|
|
||||||
if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) {
|
if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) {
|
||||||
foundEndElement = true;
|
foundEndElement = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,12 +18,14 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.olingo.client.core;
|
package org.apache.olingo.client.core;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import java.util.Map;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
import org.apache.olingo.client.api.serialization.ODataDeserializerException;
|
import org.apache.olingo.client.api.serialization.ODataDeserializerException;
|
||||||
import org.apache.olingo.commons.api.ex.ODataError;
|
import org.apache.olingo.commons.api.ex.ODataError;
|
||||||
|
import org.apache.olingo.commons.api.ex.ODataErrorDetail;
|
||||||
import org.apache.olingo.commons.api.format.ContentType;
|
import org.apache.olingo.commons.api.format.ContentType;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class ErrorTest extends AbstractTest {
|
public class ErrorTest extends AbstractTest {
|
||||||
|
@ -35,16 +37,31 @@ public class ErrorTest extends AbstractTest {
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void simple(final ContentType contentType) throws ODataDeserializerException {
|
private ODataError simple(final ContentType contentType) throws ODataDeserializerException {
|
||||||
final ODataError error = error("error", contentType);
|
final ODataError error = error("error", contentType);
|
||||||
assertEquals("501", error.getCode());
|
assertEquals("501", error.getCode());
|
||||||
assertEquals("Unsupported functionality", error.getMessage());
|
assertEquals("Unsupported functionality", error.getMessage());
|
||||||
assertEquals("query", error.getTarget());
|
assertEquals("query", error.getTarget());
|
||||||
|
|
||||||
|
// verify details
|
||||||
|
final ODataErrorDetail detail = error.getDetails().get(0);
|
||||||
|
assertEquals("Code should be correct", "301", detail.getCode());
|
||||||
|
assertEquals("Target should be correct", "$search", detail.getTarget());
|
||||||
|
assertEquals("Message should be correct", "$search query option not supported", detail.getMessage());
|
||||||
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void jsonSimple() throws Exception {
|
public void jsonSimple() throws Exception {
|
||||||
simple(ContentType.JSON);
|
final ODataError error = simple(ContentType.JSON);
|
||||||
|
|
||||||
|
// verify inner error dictionary
|
||||||
|
final Map<String, String> innerErr = error.getInnerError();
|
||||||
|
assertEquals("innerError dictionary size should be correct", 2, innerErr.size());
|
||||||
|
assertEquals("innerError['context'] should be correct",
|
||||||
|
"{\"key1\":\"for debug deployment only\"}", innerErr.get("context"));
|
||||||
|
assertEquals("innerError['trace'] should be correct",
|
||||||
|
"[\"callmethod1 etc\",\"callmethod2 etc\"]", innerErr.get("trace"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -9,6 +9,10 @@
|
||||||
"target": "$search",
|
"target": "$search",
|
||||||
"message": "$search query option not supported"
|
"message": "$search query option not supported"
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"innererror": {
|
||||||
|
"trace": ["callmethod1 etc", "callmethod2 etc"],
|
||||||
|
"context": {"key1": "for debug deployment only"}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -28,4 +28,4 @@ under the License.
|
||||||
<target>$search</target>
|
<target>$search</target>
|
||||||
</detail>
|
</detail>
|
||||||
</details>
|
</details>
|
||||||
</error>
|
</error>
|
|
@ -302,6 +302,8 @@ public interface Constants {
|
||||||
|
|
||||||
String ERROR_DETAILS = "details";
|
String ERROR_DETAILS = "details";
|
||||||
|
|
||||||
|
String ERROR_DETAIL = "detail";
|
||||||
|
|
||||||
String ERROR_INNERERROR = "innererror";
|
String ERROR_INNERERROR = "innererror";
|
||||||
|
|
||||||
// canonical functions to be applied via dynamic annotation <tt>Apply</tt>
|
// canonical functions to be applied via dynamic annotation <tt>Apply</tt>
|
||||||
|
|
Loading…
Reference in New Issue