use of org.teiid.translator.ResultSetExecution in project teiid by teiid.
the class TestODataQueryExecution method testSimpleAggregate.
@Test
public void testSimpleAggregate() throws Exception {
String query = "SELECT Count(*) FROM People";
String expectedURL = "People/$count";
ResultSetExecution excution = helpExecute(TestODataMetadataProcessor.tripPinMetadata(), query, "19", expectedURL);
assertEquals(Arrays.asList(19), excution.next());
}
use of org.teiid.translator.ResultSetExecution in project teiid by teiid.
the class TestODataQueryExecution method testSimpleSelectNoAssosiations.
@Test
public void testSimpleSelectNoAssosiations() throws Exception {
String query = "SELECT UserName,FirstName,LastName FROM People";
String expectedURL = "People?$select=UserName,FirstName,LastName";
FileReader reader = new FileReader(UnitTestUtil.getTestDataFile("people.json"));
ResultSetExecution excution = helpExecute(TestODataMetadataProcessor.tripPinMetadata(), query, ObjectConverterUtil.convertToString(reader), expectedURL);
assertArrayEquals(new Object[] { "russellwhyte", "Russell", "Whyte" }, excution.next().toArray(new Object[3]));
assertArrayEquals(new Object[] { "scottketchum", "Scott", "Ketchum" }, excution.next().toArray(new Object[3]));
assertArrayEquals(new Object[] { "ronaldmundy", "Ronald", "Mundy" }, excution.next().toArray(new Object[3]));
reader.close();
}
use of org.teiid.translator.ResultSetExecution in project teiid by teiid.
the class TestODataQueryExecution method testReadArray.
@Test
public void testReadArray() throws Exception {
String query = "SELECT Emails FROM People";
String expectedURL = "People?$select=Emails";
FileReader reader = new FileReader(UnitTestUtil.getTestDataFile("people.json"));
ResultSetExecution excution = helpExecute(TestODataMetadataProcessor.tripPinMetadata(), query, ObjectConverterUtil.convertToString(reader), expectedURL);
assertArrayEquals(new String[] { "Russell@example.com", "Russell@contoso.com" }, (String[]) excution.next().get(0));
assertArrayEquals(new String[] { "Scott@example.com" }, (String[]) excution.next().get(0));
assertArrayEquals(new String[] { "Ronald@example.com", "Ronald@contoso.com" }, (String[]) excution.next().get(0));
reader.close();
}
use of org.teiid.translator.ResultSetExecution in project teiid by teiid.
the class TestODataQueryExecution method helpExecute.
private ResultSetExecution helpExecute(MetadataFactory mf, String query, final String resultJson, String expectedURL, int responseCode) throws Exception {
ODataExecutionFactory translator = new ODataExecutionFactory();
translator.start();
TranslationUtility utility = new TranslationUtility(TestODataMetadataProcessor.getTransformationMetadata(mf, translator));
Command cmd = utility.parseCommand(query);
ExecutionContext context = Mockito.mock(ExecutionContext.class);
WSConnection connection = Mockito.mock(WSConnection.class);
Map<String, Object> headers = new HashMap<String, Object>();
headers.put(MessageContext.HTTP_REQUEST_HEADERS, new HashMap<String, List<String>>());
headers.put(WSConnection.STATUS_CODE, new Integer(responseCode));
Dispatch<DataSource> dispatch = Mockito.mock(Dispatch.class);
Mockito.stub(dispatch.getRequestContext()).toReturn(headers);
Mockito.stub(dispatch.getResponseContext()).toReturn(headers);
Mockito.stub(connection.createDispatch(Mockito.eq(HTTPBinding.HTTP_BINDING), Mockito.anyString(), Mockito.eq(DataSource.class), Mockito.eq(Mode.MESSAGE))).toReturn(dispatch);
DataSource ds = new DataSource() {
@Override
public OutputStream getOutputStream() throws IOException {
return new ByteArrayOutputStream();
}
@Override
public String getName() {
return "result";
}
@Override
public InputStream getInputStream() throws IOException {
ByteArrayInputStream in = new ByteArrayInputStream(resultJson.getBytes());
return in;
}
@Override
public String getContentType() {
return "application/xml";
}
};
Mockito.stub(dispatch.invoke(Mockito.any(DataSource.class))).toReturn(ds);
ResultSetExecution execution = translator.createResultSetExecution((QueryExpression) cmd, context, utility.createRuntimeMetadata(), connection);
execution.execute();
ArgumentCaptor<String> endpoint = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> binding = ArgumentCaptor.forClass(String.class);
Mockito.verify(connection).createDispatch(binding.capture(), endpoint.capture(), Mockito.eq(DataSource.class), Mockito.eq(Mode.MESSAGE));
assertEquals(expectedURL, URLDecoder.decode(endpoint.getValue(), "utf-8"));
return execution;
}
use of org.teiid.translator.ResultSetExecution in project teiid by teiid.
the class TestODataQueryExecution method testSimpleSelectEmbedded.
@Test
public void testSimpleSelectEmbedded() throws Exception {
String query = "SELECT * FROM Customers";
String expectedURL = "Customers?$select=CustomerID,CompanyName,ContactName,ContactTitle,Mailing,Shipping";
FileReader reader = new FileReader(UnitTestUtil.getTestDataFile("customer.xml"));
ResultSetExecution excution = helpExecute(query, ObjectConverterUtil.convertToString(reader), expectedURL);
reader.close();
assertEquals(18, excution.next().size());
}
Aggregations