Search in sources :

Example 11 with ProcedureExecution

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

the class TestODataQueryExecution method testFunctionReturnsPrimitiveCollection.

@Test
public void testFunctionReturnsPrimitiveCollection() throws Exception {
    String query = "exec invoke(1, 'foo')";
    String expectedURL = "invoke?e1=1&e2='foo'";
    String response = "{\"value\": [\"returnX\", \"returnY\"]}";
    CsdlReturnType returnType = new CsdlReturnType();
    returnType.setType("Edm.String");
    returnType.setCollection(true);
    MetadataFactory mf = TestODataMetadataProcessor.functionMetadata("invoke", returnType, null);
    ProcedureExecution excution = helpProcedureExecute(mf, query, response, expectedURL, 200);
    assertArrayEquals(new Object[] { "returnX", "returnY" }, ((List) excution.getOutputParameterValues().get(0)).toArray());
}
Also used : MetadataFactory(org.teiid.metadata.MetadataFactory) ProcedureExecution(org.teiid.translator.ProcedureExecution) CsdlReturnType(org.apache.olingo.commons.api.edm.provider.CsdlReturnType) Test(org.junit.Test)

Example 12 with ProcedureExecution

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

the class TestODataQueryExecution method testFunctionReturnsComplex.

@Test
public void testFunctionReturnsComplex() throws Exception {
    String query = "exec invoke(1, 'foo')";
    String expectedURL = "invoke?e1=1&e2='foo'";
    String response = "{\"value\":{\n" + "            \"street\":\"United States\",\n" + "            \"city\":\"Boise\",\n" + "            \"state\":\"ID\"\n" + "         }}";
    CsdlComplexType complex = TestODataMetadataProcessor.complexType("Address");
    CsdlReturnType returnType = new CsdlReturnType();
    returnType.setType("namespace.Address");
    MetadataFactory mf = TestODataMetadataProcessor.functionMetadata("invoke", returnType, complex);
    ProcedureExecution excution = helpProcedureExecute(mf, query, response, expectedURL, 200);
    assertArrayEquals(new Object[] { "United States", "Boise", "ID" }, excution.next().toArray(new Object[3]));
    assertNull(excution.next());
}
Also used : MetadataFactory(org.teiid.metadata.MetadataFactory) ProcedureExecution(org.teiid.translator.ProcedureExecution) CsdlComplexType(org.apache.olingo.commons.api.edm.provider.CsdlComplexType) CsdlReturnType(org.apache.olingo.commons.api.edm.provider.CsdlReturnType) Test(org.junit.Test)

Example 13 with ProcedureExecution

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

the class TestODataQueryExecution method testFunctionReturnsPrimitiveEncoded.

@Test
public void testFunctionReturnsPrimitiveEncoded() throws Exception {
    String query = "exec invoke(1, 'foo bar')";
    String expectedURL = "invoke?e1=1&e2=%27foo%20bar%27";
    String response = "{\"value\":\"returnX\"}";
    CsdlReturnType returnType = new CsdlReturnType();
    returnType.setType("Edm.String");
    MetadataFactory mf = TestODataMetadataProcessor.functionMetadata("invoke", returnType, null);
    ProcedureExecution excution = helpProcedureExecute(mf, query, response, expectedURL, 200, false);
    assertArrayEquals(new Object[] { "returnX" }, excution.getOutputParameterValues().toArray(new Object[1]));
}
Also used : MetadataFactory(org.teiid.metadata.MetadataFactory) ProcedureExecution(org.teiid.translator.ProcedureExecution) CsdlReturnType(org.apache.olingo.commons.api.edm.provider.CsdlReturnType) Test(org.junit.Test)

Example 14 with ProcedureExecution

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

the class TestODataQueryExecution method testFunctionReturnsComplexCollection.

@Test
public void testFunctionReturnsComplexCollection() throws Exception {
    String query = "exec invoke(1, 'foo')";
    String expectedURL = "invoke?e1=1&e2='foo'";
    String response = "{\"value\":[{\n" + "            \"street\":\"United States\",\n" + "            \"city\":\"Boise\",\n" + "            \"state\":\"ID\"\n" + "           }," + "           {" + "            \"street\":\"China\",\n" + "            \"city\":\"Newyork\",\n" + "            \"state\":\"NY\"\n" + "         }]}";
    CsdlComplexType complex = TestODataMetadataProcessor.complexType("Address");
    CsdlReturnType returnType = new CsdlReturnType();
    returnType.setType("namespace.Address");
    MetadataFactory mf = TestODataMetadataProcessor.functionMetadata("invoke", returnType, complex);
    ProcedureExecution excution = helpProcedureExecute(mf, query, response, expectedURL, 200);
    assertArrayEquals(new Object[] { "United States", "Boise", "ID" }, excution.next().toArray(new Object[3]));
    assertArrayEquals(new Object[] { "China", "Newyork", "NY" }, excution.next().toArray(new Object[3]));
    assertNull(excution.next());
}
Also used : MetadataFactory(org.teiid.metadata.MetadataFactory) ProcedureExecution(org.teiid.translator.ProcedureExecution) CsdlComplexType(org.apache.olingo.commons.api.edm.provider.CsdlComplexType) CsdlReturnType(org.apache.olingo.commons.api.edm.provider.CsdlReturnType) Test(org.junit.Test)

Example 15 with ProcedureExecution

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

the class TestODataQueryExecution method testFunctionReturnsPrimitive.

@Test
public void testFunctionReturnsPrimitive() throws Exception {
    String query = "exec invoke(1, 'foo')";
    String expectedURL = "invoke?e1=1&e2='foo'";
    String response = "{\"value\":\"returnX\"}";
    CsdlReturnType returnType = new CsdlReturnType();
    returnType.setType("Edm.String");
    MetadataFactory mf = TestODataMetadataProcessor.functionMetadata("invoke", returnType, null);
    ProcedureExecution excution = helpProcedureExecute(mf, query, response, expectedURL, 200);
    assertArrayEquals(new Object[] { "returnX" }, excution.getOutputParameterValues().toArray(new Object[1]));
}
Also used : MetadataFactory(org.teiid.metadata.MetadataFactory) ProcedureExecution(org.teiid.translator.ProcedureExecution) CsdlReturnType(org.apache.olingo.commons.api.edm.provider.CsdlReturnType) Test(org.junit.Test)

Aggregations

ProcedureExecution (org.teiid.translator.ProcedureExecution)24 Test (org.junit.Test)20 MetadataFactory (org.teiid.metadata.MetadataFactory)7 CsdlReturnType (org.apache.olingo.commons.api.edm.provider.CsdlReturnType)6 List (java.util.List)5 ExecutionContext (org.teiid.translator.ExecutionContext)4 CsdlComplexType (org.apache.olingo.commons.api.edm.provider.CsdlComplexType)3 Call (org.teiid.language.Call)3 Command (org.teiid.language.Command)3 TranslatorException (org.teiid.translator.TranslatorException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 Connection (java.sql.Connection)2 Timestamp (java.sql.Timestamp)2 ArrayList (java.util.ArrayList)2 Properties (java.util.Properties)2 DataSource (javax.activation.DataSource)2 TranslationUtility (org.teiid.cdk.api.TranslationUtility)2 DataNotAvailableException (org.teiid.translator.DataNotAvailableException)2