use of org.teiid.cdk.api.TranslationUtility 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.cdk.api.TranslationUtility 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.cdk.api.TranslationUtility in project teiid by teiid.
the class TestODataSQLVistor method testBigDecimalParameter.
@Test
public void testBigDecimalParameter() throws Exception {
ODataExecutionFactory ef = new ODataExecutionFactory();
TranslationUtility utility = new TranslationUtility(TestODataMetadataProcessor.getTransformationMetadata(TestODataMetadataProcessor.tripPinMetadata(), ef));
Call cmd = (Call) utility.parseCommand("call GetNearestAirport(1.1, 1.2, 2.0)");
String params = ODataProcedureExecution.getQueryParameters(cmd);
assertEquals("lat=1.1&lon=1.2&within=2.0", params);
}
use of org.teiid.cdk.api.TranslationUtility in project teiid by teiid.
the class TestODataSQLVistor method helpExecute.
private void helpExecute(MetadataFactory mf, String query, String expected) throws Exception {
ODataExecutionFactory ef = new ODataExecutionFactory();
TranslationUtility utility = new TranslationUtility(TestODataMetadataProcessor.getTransformationMetadata(mf, ef));
Select cmd = (Select) utility.parseCommand(query);
ODataSQLVisitor visitor = new ODataSQLVisitor(ef, utility.createRuntimeMetadata());
visitor.visitNode(cmd);
String actual = URLDecoder.decode(visitor.buildURL(""), "UTF-8");
assertEquals(expected, actual);
}
use of org.teiid.cdk.api.TranslationUtility in project teiid by teiid.
the class TestODataUpdateExecution method helpExecute.
private UpdateExecution helpExecute(MetadataFactory mf, String query, String expectedPayload, final String resultJson, String expectedURL, String expectedMethod, 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/json";
}
};
ArgumentCaptor<DataSource> data = ArgumentCaptor.forClass(DataSource.class);
Mockito.stub(dispatch.invoke(data.capture())).toReturn(ds);
UpdateExecution execution = translator.createUpdateExecution(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"));
String payload = new String(ObjectConverterUtil.convertToByteArray(((ClobInputStreamFactory) data.getValue()).getInputStream()));
assertEquals(expectedPayload, payload);
assertEquals(expectedMethod, dispatch.getRequestContext().get(MessageContext.HTTP_REQUEST_METHOD));
return execution;
}
Aggregations