use of org.teiid.translator.ProcedureExecution in project teiid by teiid.
the class TestODataQueryExecution method helpProcedureExecute.
private ProcedureExecution helpProcedureExecute(MetadataFactory mf, String query, final String resultJson, String expectedURL, int responseCode, boolean decode) 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);
ProcedureExecution execution = translator.createProcedureExecution((Call) 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, decode ? URLDecoder.decode(endpoint.getValue(), "utf-8") : endpoint.getValue());
return execution;
}
use of org.teiid.translator.ProcedureExecution in project teiid by teiid.
the class TestSwaggerQueryExecution method testScalarResponse.
@Test
public void testScalarResponse() throws Exception {
String query = "exec loginStatus('foo');";
String expectedURL = "http://petstore.swagger.io/v2/user/loginStatus?username=foo";
String response = "foo";
ProcedureExecution excution = helpProcedureExecute(query, response, expectedURL, 200, true, "GET", null, getHeaders());
assertEquals("foo", excution.getOutputParameterValues().get(0));
}
use of org.teiid.translator.ProcedureExecution in project teiid by teiid.
the class TestSwaggerQueryExecution method testPostBasedQuery.
@Test
public void testPostBasedQuery() throws Exception {
String query = "exec addPet(id=>99, category_id=>0,category_name=>'canine',name=>'nikky'," + "photoUrls=>('photo1','photo2'),tags_tag_id=>0, tags_tag_name=>'doggie'," + "status=>'available');";
String expectedURL = "http://petstore.swagger.io/v2/pet";
String response = "{" + "\"id\":99," + "\"name\":\"nikky\"," + "\"photoUrls\":[\"photo1\",\"photo2\"]," + "\"status\":\"available\"," + "\"category\":{" + "\"id\":0," + "\"name\":\"canine\"" + "}," + "\"tags\":[" + "{\"id\":0," + "\"name\":\"doggie\"" + "}" + "]}";
ProcedureExecution excution = helpProcedureExecute(query, response, expectedURL, 200, true, "POST", response, getHeaders());
}
use of org.teiid.translator.ProcedureExecution in project teiid by teiid.
the class TestSwaggerQueryExecution method testNullParameter.
@Test(expected = TeiidRuntimeException.class)
public void testNullParameter() throws Exception {
String query = "exec loginStatus(null);";
String expectedURL = null;
String response = null;
ProcedureExecution excution = helpProcedureExecute(query, response, expectedURL, 200, true, "GET", null, getHeaders());
}
use of org.teiid.translator.ProcedureExecution in project teiid by teiid.
the class TestSwaggerQueryExecution method testDefaultResponse.
@Test
public void testDefaultResponse() throws Exception {
String query = "exec logoutUser();";
String expectedURL = "http://petstore.swagger.io/v2/user/logout";
String response = "";
ProcedureExecution excution = helpProcedureExecute(query, response, expectedURL, 200, true, "GET", null, getHeaders());
assertNull(excution.next());
}
Aggregations