Search in sources :

Example 31 with ResultSetExecution

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());
}
Also used : ResultSetExecution(org.teiid.translator.ResultSetExecution) Test(org.junit.Test)

Example 32 with ResultSetExecution

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();
}
Also used : ResultSetExecution(org.teiid.translator.ResultSetExecution) FileReader(java.io.FileReader) Test(org.junit.Test)

Example 33 with ResultSetExecution

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();
}
Also used : ResultSetExecution(org.teiid.translator.ResultSetExecution) FileReader(java.io.FileReader) Test(org.junit.Test)

Example 34 with ResultSetExecution

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;
}
Also used : WSConnection(org.teiid.translator.WSConnection) HashMap(java.util.HashMap) TranslationUtility(org.teiid.cdk.api.TranslationUtility) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataSource(javax.activation.DataSource) ResultSetExecution(org.teiid.translator.ResultSetExecution) ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) ByteArrayInputStream(java.io.ByteArrayInputStream) List(java.util.List)

Example 35 with ResultSetExecution

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());
}
Also used : ResultSetExecution(org.teiid.translator.ResultSetExecution) FileReader(java.io.FileReader) Test(org.junit.Test)

Aggregations

ResultSetExecution (org.teiid.translator.ResultSetExecution)50 Test (org.junit.Test)41 ExecutionContext (org.teiid.translator.ExecutionContext)22 FileReader (java.io.FileReader)19 Command (org.teiid.language.Command)17 RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)15 QueryExpression (org.teiid.language.QueryExpression)12 List (java.util.List)11 ArrayList (java.util.ArrayList)10 TranslatorException (org.teiid.translator.TranslatorException)10 ExecutionFactory (org.teiid.translator.ExecutionFactory)8 TranslationUtility (org.teiid.cdk.api.TranslationUtility)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 Connection (java.sql.Connection)4 ResultSet (java.sql.ResultSet)4 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)4 MongoDBConnection (org.teiid.mongodb.MongoDBConnection)4 DataNotAvailableException (org.teiid.translator.DataNotAvailableException)4 UpdateExecution (org.teiid.translator.UpdateExecution)4 DatabaseMetaData (java.sql.DatabaseMetaData)3