Search in sources :

Example 11 with ResultSetExecution

use of org.teiid.translator.ResultSetExecution in project teiid by teiid.

the class TestODataQueryExecution method testNoResults.

@Test
public void testNoResults() throws Exception {
    String query = "SELECT * FROM Categories Where CategoryName = 'Beverages'";
    String expectedURL = "Categories?$filter=CategoryName eq 'Beverages'&$select=CategoryID,CategoryName,Description,Picture";
    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();
}
Also used : ResultSetExecution(org.teiid.translator.ResultSetExecution) FileReader(java.io.FileReader) Test(org.junit.Test)

Example 12 with ResultSetExecution

use of org.teiid.translator.ResultSetExecution in project teiid by teiid.

the class TestODataQueryExecution method testGeometryFilter.

@Test
public void testGeometryFilter() throws Exception {
    String query = "SELECT Loc FROM Airports_Location where st_distance(Loc, st_geomfromtext('point(1 2)')) < 2";
    String expectedURL = "Airports?$select=Location&$filter=geo.distance(Location/Loc,geometry'SRID=0;Point(1.0 2.0)') lt 2.0";
    FileReader reader = new FileReader(UnitTestUtil.getTestDataFile("airport-locations.json"));
    ResultSetExecution execution = helpExecute(TestODataMetadataProcessor.tripPinMetadata(), query, ObjectConverterUtil.convertToString(reader), expectedURL);
    // make sure the format is valid
    EdmGeometryPoint.getInstance().valueOfString("geometry'SRID=0;Point(1.0 2.0)'", false, 4000, 0, 0, true, Point.class);
}
Also used : ResultSetExecution(org.teiid.translator.ResultSetExecution) FileReader(java.io.FileReader) Test(org.junit.Test)

Example 13 with ResultSetExecution

use of org.teiid.translator.ResultSetExecution in project teiid by teiid.

the class TestODataQueryExecution method testComplexType_InnerJoin.

@Test
public void testComplexType_InnerJoin() throws Exception {
    String query = "select p.UserName, pa.Address from People p JOIN People_AddressInfo pa " + "ON p.UserName = pa.People_UserName";
    String expectedURL = "People?$select=UserName,AddressInfo";
    FileReader reader = new FileReader(UnitTestUtil.getTestDataFile("people.json"));
    ResultSetExecution excution = helpExecute(TestODataMetadataProcessor.tripPinMetadata(), query, ObjectConverterUtil.convertToString(reader), expectedURL);
    reader.close();
    assertArrayEquals(new Object[] { "russellwhyte", "187 Suffolk Ln." }, excution.next().toArray(new Object[2]));
    assertArrayEquals(new Object[] { "scottketchum", "2817 Milton Dr." }, excution.next().toArray(new Object[2]));
    assertArrayEquals(new Object[] { "javieralfred", "89 Jefferson Way Suite 2" }, excution.next().toArray(new Object[2]));
    assertArrayEquals(new Object[] { "vincentcalabrese", "55 Grizzly Peak Rd." }, excution.next().toArray(new Object[2]));
    assertNull(excution.next());
}
Also used : ResultSetExecution(org.teiid.translator.ResultSetExecution) FileReader(java.io.FileReader) Test(org.junit.Test)

Example 14 with ResultSetExecution

use of org.teiid.translator.ResultSetExecution in project teiid by teiid.

the class TestODataQueryExecution method testComplexType_3Way_LeftOuterJoin.

@Test
public void testComplexType_3Way_LeftOuterJoin() throws Exception {
    String query = "select p.UserName, pa.Address, pf.UserName from People p " + "LEFT OUTER JOIN People_AddressInfo pa " + "ON p.UserName = pa.People_UserName " + "LEFT OUTER JOIN People_Friends pf " + "ON p.UserName = pf.People_UserName";
    String expectedURL = "People?$select=UserName,AddressInfo&$expand=Friends($select=UserName)";
    FileReader reader = new FileReader(UnitTestUtil.getTestDataFile("people-friends.json"));
    ResultSetExecution excution = helpExecute(TestODataMetadataProcessor.tripPinMetadata(), query, ObjectConverterUtil.convertToString(reader), expectedURL);
    reader.close();
    assertArrayEquals(new Object[] { "russellwhyte", "187 Suffolk Ln.", "scottketchum" }, excution.next().toArray(new Object[3]));
    assertArrayEquals(new Object[] { "russellwhyte", "187 Suffolk Ln.", "ronaldmundy" }, excution.next().toArray(new Object[3]));
    assertArrayEquals(new Object[] { "russellwhyte", "187 Suffolk Ln.", "javieralfred" }, excution.next().toArray(new Object[3]));
    assertArrayEquals(new Object[] { "russellwhyte", "187 Suffolk Ln.", "angelhuffman" }, excution.next().toArray(new Object[3]));
    assertArrayEquals(new Object[] { "scottketchum", "2817 Milton Dr.", "russellwhyte" }, excution.next().toArray(new Object[3]));
    assertArrayEquals(new Object[] { "scottketchum", "2817 Milton Dr.", "ronaldmundy" }, excution.next().toArray(new Object[3]));
    assertArrayEquals(new Object[] { "ronaldmundy", null, "russellwhyte" }, excution.next().toArray(new Object[3]));
    assertArrayEquals(new Object[] { "ronaldmundy", null, "scottketchum" }, excution.next().toArray(new Object[3]));
    assertArrayEquals(new Object[] { "javieralfred", "89 Jefferson Way Suite 2", "willieashmore" }, excution.next().toArray(new Object[3]));
    assertArrayEquals(new Object[] { "javieralfred", "89 Jefferson Way Suite 2", "vincentcalabrese" }, excution.next().toArray(new Object[3]));
    assertArrayEquals(new Object[] { "javieralfred", "89 Jefferson Way Suite 2", "georginabarlow" }, excution.next().toArray(new Object[3]));
    assertArrayEquals(new Object[] { "willieashmore", null, "javieralfred" }, excution.next().toArray(new Object[3]));
    assertArrayEquals(new Object[] { "willieashmore", null, "vincentcalabrese" }, excution.next().toArray(new Object[3]));
    // extra row from test from above
    assertArrayEquals(new Object[] { "vincentcalabrese", "55 Grizzly Peak Rd.", null }, excution.next().toArray(new Object[3]));
    assertArrayEquals(new Object[] { "clydeguess", null, "keithpinckney" }, excution.next().toArray(new Object[3]));
    assertArrayEquals(new Object[] { "clydeguess", null, "ursulabright" }, excution.next().toArray(new Object[3]));
    assertArrayEquals(new Object[] { "keithpinckney", null, "clydeguess" }, excution.next().toArray(new Object[3]));
    assertArrayEquals(new Object[] { "keithpinckney", null, "marshallgaray" }, excution.next().toArray(new Object[3]));
    assertNull(excution.next());
}
Also used : ResultSetExecution(org.teiid.translator.ResultSetExecution) FileReader(java.io.FileReader) Test(org.junit.Test)

Example 15 with ResultSetExecution

use of org.teiid.translator.ResultSetExecution in project teiid by teiid.

the class TestODataQueryExecution method testComplexType_InnerJoin_3way_Sibiling.

@Test
public void testComplexType_InnerJoin_3way_Sibiling() throws Exception {
    String query = "select p.UserName, pa.Address, pf.UserName from People p JOIN People_AddressInfo pa " + "ON p.UserName = pa.People_UserName JOIN People_Friends pf " + "ON p.UserName = pf.People_UserName";
    String expectedURL = "People?$select=UserName,AddressInfo&$expand=Friends($select=UserName)";
    FileReader reader = new FileReader(UnitTestUtil.getTestDataFile("people-friends.json"));
    ResultSetExecution excution = helpExecute(TestODataMetadataProcessor.tripPinMetadata(), query, ObjectConverterUtil.convertToString(reader), expectedURL);
    reader.close();
    assertArrayEquals(new Object[] { "russellwhyte", "187 Suffolk Ln.", "scottketchum" }, excution.next().toArray(new Object[3]));
    assertArrayEquals(new Object[] { "russellwhyte", "187 Suffolk Ln.", "ronaldmundy" }, excution.next().toArray(new Object[3]));
    assertArrayEquals(new Object[] { "russellwhyte", "187 Suffolk Ln.", "javieralfred" }, excution.next().toArray(new Object[3]));
    assertArrayEquals(new Object[] { "russellwhyte", "187 Suffolk Ln.", "angelhuffman" }, excution.next().toArray(new Object[3]));
    assertArrayEquals(new Object[] { "scottketchum", "2817 Milton Dr.", "russellwhyte" }, excution.next().toArray(new Object[3]));
    assertArrayEquals(new Object[] { "scottketchum", "2817 Milton Dr.", "ronaldmundy" }, excution.next().toArray(new Object[3]));
    assertArrayEquals(new Object[] { "javieralfred", "89 Jefferson Way Suite 2", "willieashmore" }, excution.next().toArray(new Object[3]));
    assertArrayEquals(new Object[] { "javieralfred", "89 Jefferson Way Suite 2", "vincentcalabrese" }, excution.next().toArray(new Object[3]));
    assertArrayEquals(new Object[] { "javieralfred", "89 Jefferson Way Suite 2", "georginabarlow" }, excution.next().toArray(new Object[3]));
    assertNull(excution.next());
}
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