Skip to content

Commit

Permalink
TEIID-2678: It looks to be apache cxf returns the response headers as…
Browse files Browse the repository at this point in the history
… arraylist, fixed for that, also allowed 404 as allowed result type where it represents the no results found
  • Loading branch information
rareddy committed Oct 1, 2013
1 parent 5014aeb commit 16798cf
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 7 deletions.
Expand Up @@ -116,9 +116,10 @@ protected ODataEntitiesResponse executeWithReturnEntity(String method, String ur
BinaryWSProcedureExecution execution = executeDirect(method, uri, payload, headers);
for (Status status:expectedStatus) {
if (status.getStatusCode() == execution.getResponseCode()) {
if (execution.getResponseCode() != Status.NO_CONTENT.getStatusCode()) {
if (execution.getResponseCode() != Status.NO_CONTENT.getStatusCode()
&& execution.getResponseCode() != Status.NOT_FOUND.getStatusCode()) {
Blob blob = (Blob)execution.getOutputParameterValues().get(0);
ODataVersion version = getDataServiceVersion((String)execution.getResponseHeader(ODataConstants.Headers.DATA_SERVICE_VERSION));
ODataVersion version = getODataVersion(execution);
Feed feed = parse(blob, version, entityTable, edsMetadata);
return new ODataEntitiesResponse(uri, feed, entityTable, edsMetadata);
}
Expand All @@ -130,6 +131,18 @@ protected ODataEntitiesResponse executeWithReturnEntity(String method, String ur
return new ODataEntitiesResponse(buildError(execution));
}

ODataVersion getODataVersion(BinaryWSProcedureExecution execution) {
return getDataServiceVersion(getHeader(execution, ODataConstants.Headers.DATA_SERVICE_VERSION));
}

String getHeader(BinaryWSProcedureExecution execution, String header) {
Object value = execution.getResponseHeader(header);
if (value instanceof List) {
return (String)((List)value).get(0);
}
return (String)value;
}

protected ODataEntitiesResponse executeWithComplexReturn(String method, String uri, String payload, String complexTypeName, EdmDataServices edsMetadata, String eTag, Status... expectedStatus) throws TranslatorException {
Map<String, List<String>> headers = getDefaultHeaders();
if (eTag != null) {
Expand Down Expand Up @@ -340,7 +353,7 @@ private void fetchNextBatch(boolean fetch, EdmDataServices edsMetadata) throws T
BinaryWSProcedureExecution execution = executeDirect("GET", nextUri, null, getDefaultHeaders()); //$NON-NLS-1$
validateResponse(execution);
Blob blob = (Blob)execution.getOutputParameterValues().get(0);
ODataVersion version = getDataServiceVersion((String)execution.getResponseHeader(ODataConstants.Headers.DATA_SERVICE_VERSION));
ODataVersion version = getODataVersion(execution);

this.feed = parse(blob, version, this.entityTypeName, edsMetadata);
this.rowIter = this.feed.getEntries().iterator();
Expand Down
Expand Up @@ -29,7 +29,6 @@

import javax.ws.rs.core.Response.Status;

import org.odata4j.core.ODataConstants;
import org.odata4j.core.ODataVersion;
import org.odata4j.core.OObject;
import org.odata4j.core.OSimpleObject;
Expand Down Expand Up @@ -93,7 +92,7 @@ public void execute() throws TranslatorException {
}

Blob blob = (Blob)execution.getOutputParameterValues().get(0);
ODataVersion version = getDataServiceVersion((String)execution.getResponseHeader(ODataConstants.Headers.DATA_SERVICE_VERSION));
ODataVersion version = getODataVersion(execution);

// if the procedure is not void
if (this.visitor.getReturnType() != null) {
Expand Down
Expand Up @@ -89,7 +89,7 @@ public void execute() throws TranslatorException {
else {
Schema schema = visitor.getEnityTable().getParent();
EdmDataServices edm = new TeiidEdmMetadata(schema.getName(), ODataEntitySchemaBuilder.buildMetadata( schema));
this.response = executeWithReturnEntity("GET", URI, null, visitor.getEnityTable().getName(), edm, null, Status.OK, Status.NO_CONTENT); //$NON-NLS-1$
this.response = executeWithReturnEntity("GET", URI, null, visitor.getEnityTable().getName(), edm, null, Status.OK, Status.NO_CONTENT, Status.NOT_FOUND); //$NON-NLS-1$
if (this.response != null && this.response.hasError()) {
throw this.response.getError();
}
Expand Down
Expand Up @@ -87,7 +87,7 @@ else if(this.visitor.getMethod().equals("PUT")) { //$NON-NLS-1$
EdmDataServices edm = new TeiidEdmMetadata(schema.getName(), ODataEntitySchemaBuilder.buildMetadata( schema));
BinaryWSProcedureExecution execution = executeDirect("GET", this.visitor.buildURL(), null, getDefaultHeaders()); //$NON-NLS-1$
if (execution.getResponseCode() == Status.OK.getStatusCode()) {
String etag = (String)execution.getResponseHeader("ETag"); //$NON-NLS-1$
String etag = getHeader(execution, "ETag"); //$NON-NLS-1$
String payload = buildPayload(this.visitor.getTable().getName(), this.visitor.getPayload(), edm);
this.response = executeWithReturnEntity(this.visitor.getMethod(), this.visitor.buildURL(), payload, this.visitor.getTable().getName(), edm, etag, Status.OK, Status.NO_CONTENT);
if (this.response != null) {
Expand Down
Expand Up @@ -23,6 +23,7 @@

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
Expand Down Expand Up @@ -131,6 +132,7 @@ public void testSimpleSelectNoAssosiations() throws Exception {
assertArrayEquals(new Object[] {1, "Beverages", "Soft drinks, coffees, teas, beers, and ales"}, excution.next().toArray(new Object[3]));
assertArrayEquals(new Object[] {2, "Condiments", "Sweet and savory sauces, relishes, spreads, and seasonings"}, excution.next().toArray(new Object[3]));
assertArrayEquals(new Object[] {3, "Confections", "Desserts, candies, and sweet breads"}, excution.next().toArray(new Object[3]));
reader.close();
}

@Test
Expand All @@ -140,6 +142,7 @@ public void testSimpleSelectStar() throws Exception {

FileReader reader = new FileReader(UnitTestUtil.getTestDataFile("categories.xml"));
ResultSetExecution excution = helpExecute(query, ObjectConverterUtil.convertToString(reader), expectedURL);
reader.close();
}

@Test
Expand All @@ -149,6 +152,7 @@ public void testSimpleSelectEmbedded() throws Exception {

FileReader reader = new FileReader(UnitTestUtil.getTestDataFile("categories.xml"));
ResultSetExecution excution = helpExecute(query, ObjectConverterUtil.convertToString(reader), expectedURL);
reader.close();
}

@Test
Expand All @@ -158,6 +162,7 @@ public void testSimplePKWhere() throws Exception {

FileReader reader = new FileReader(UnitTestUtil.getTestDataFile("categories.xml"));
ResultSetExecution excution = helpExecute(query, ObjectConverterUtil.convertToString(reader), expectedURL);
reader.close();
}

@Test
Expand All @@ -167,6 +172,7 @@ public void testSimpleWhere() throws Exception {

FileReader reader = new FileReader(UnitTestUtil.getTestDataFile("categories.xml"));
ResultSetExecution excution = helpExecute(query, ObjectConverterUtil.convertToString(reader), expectedURL);
reader.close();
}

@Test(expected=TranslatorException.class)
Expand All @@ -182,4 +188,21 @@ public void testError() throws Exception {
ResultSetExecution excution = helpExecute(query, error, expectedURL, 400);
excution.next();
}

@Test
public void testNoResults() throws Exception {
String query = "SELECT * FROM Categories Where CategoryName = 'Beverages'";
String expectedURL = "Categories?$filter=CategoryName eq 'Beverages'&$select=Picture,Description,CategoryName,CategoryID";
FileReader reader = new FileReader(UnitTestUtil.getTestDataFile("categories.xml"));
ResultSetExecution excution = helpExecute(query, ObjectConverterUtil.convertToString(reader), expectedURL, 404);
excution.execute();
assertNull(excution.next());
reader.close();

reader = new FileReader(UnitTestUtil.getTestDataFile("categories.xml"));
excution = helpExecute(query, ObjectConverterUtil.convertToString(reader), expectedURL, 204);
excution.execute();
assertNull(excution.next());
reader.close();
}
}

0 comments on commit 16798cf

Please sign in to comment.