use of org.teiid.cdk.api.TranslationUtility in project teiid by teiid.
the class TestODataSQLVistor method setUp.
@Before
public void setUp() throws Exception {
translator = new ODataExecutionFactory();
translator.start();
String csdl = ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("northwind.xml"));
EdmDataServices eds = new EdmxFormatParser().parseMetadata(StaxUtil.newXMLEventReader(new InputStreamReader(new ByteArrayInputStream(csdl.getBytes()))));
ODataMetadataProcessor processor = new ODataMetadataProcessor();
Properties props = new Properties();
props.setProperty("schemaNamespace", "ODataWeb.Northwind.Model");
props.setProperty("entityContainer", "NorthwindEntities");
MetadataFactory mf = new MetadataFactory("vdb", 1, "nw", SystemMetadata.getInstance().getRuntimeTypeMap(), props, null);
processor.getMetadata(mf, eds);
TransformationMetadata metadata = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "northwind", new FunctionTree("foo", new UDFSource(translator.getPushDownFunctions())));
ValidatorReport report = new MetadataValidator().validate(metadata.getVdbMetaData(), metadata.getMetadataStore());
if (report.hasItems()) {
throw new RuntimeException(report.getFailureMessage());
}
// TransformationMetadata metadata = RealMetadataFactory.fromDDL(ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("northwind.ddl")), "northwind", "nw");
utility = new TranslationUtility(metadata);
}
use of org.teiid.cdk.api.TranslationUtility in project teiid by teiid.
the class TestODataUpdateExecution method helpExecute.
private String helpExecute(String query, final String resultXML, String expectedURL, int[] responseCode, TransformationMetadata metadata, int times) throws Exception {
ODataExecutionFactory translator = new ODataExecutionFactory();
translator.start();
TranslationUtility utility = new TranslationUtility(metadata);
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[0]));
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(resultXML.getBytes());
return in;
}
@Override
public String getContentType() {
return "application/xml";
}
};
ArgumentCaptor<DataSource> payload = ArgumentCaptor.forClass(DataSource.class);
Mockito.stub(dispatch.invoke(payload.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, Mockito.times(times)).createDispatch(binding.capture(), endpoint.capture(), Mockito.eq(DataSource.class), Mockito.eq(Mode.MESSAGE));
Mockito.verify(dispatch, Mockito.times(times)).invoke(payload.capture());
assertEquals(expectedURL, URLDecoder.decode(endpoint.getValue(), "utf-8"));
if (payload.getAllValues() != null) {
List<DataSource> listDS = payload.getAllValues();
InputStream in = null;
if (times > 1) {
in = listDS.get(1).getInputStream();
} else {
in = listDS.get(0).getInputStream();
}
return new String(ObjectConverterUtil.convertToByteArray(in));
}
return "";
}
use of org.teiid.cdk.api.TranslationUtility in project teiid by teiid.
the class TestSAPODataMetadataProcessor method testSchema.
@Test
public void testSchema() throws Exception {
translator = new SAPODataExecutionFactory();
translator.start();
String csdl = ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("sap-metadata.xml"));
SAPMetadataProcessor processor = new SAPMetadataProcessor();
Properties props = new Properties();
MetadataFactory mf = new MetadataFactory("vdb", 1, "flight", SystemMetadata.getInstance().getRuntimeTypeMap(), props, null);
processor.getMetadata(mf, new EdmxFormatParser().parseMetadata(StaxUtil.newXMLEventReader(new InputStreamReader(new ByteArrayInputStream(csdl.getBytes())))));
TransformationMetadata metadata = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "flight", new FunctionTree("foo", new UDFSource(translator.getPushDownFunctions())));
ValidatorReport report = new MetadataValidator().validate(metadata.getVdbMetaData(), metadata.getMetadataStore());
if (report.hasItems()) {
throw new RuntimeException(report.getFailureMessage());
}
// String ddl = DDLStringVisitor.getDDLString(mf.getSchema(), null, null);
// System.out.println(ddl);
//
// MetadataFactory mf2 = new MetadataFactory(null, 1, "flight", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), null);
// QueryParser.getQueryParser().parseDDL(mf2, ddl);
TranslationUtility utility = new TranslationUtility(metadata);
RuntimeMetadata rm = utility.createRuntimeMetadata();
Table t = rm.getTable("flight", "SubscriptionCollection");
assertNotNull(t);
// check the label name
assertNotNull(t.getColumnByName("persistNotifications"));
assertTrue(!t.getColumnByName("ID").isUpdatable());
assertEquals("Persist Notification", t.getColumnByName("persistNotifications").getAnnotation());
// check filterable
assertEquals(SearchType.Unsearchable, t.getColumnByName("persistNotifications").getSearchType());
// check sortable
assertEquals(SearchType.Unsearchable, t.getColumnByName("filter").getSearchType());
// check visible
assertEquals(false, t.getColumnByName("filter").isSelectable());
// check required-in-filter
assertEquals(1, t.getAccessPatterns().size());
assertEquals(2, t.getAccessPatterns().get(0).getColumns().size());
}
use of org.teiid.cdk.api.TranslationUtility in project teiid by teiid.
the class TestHotrodExecution method setup.
@BeforeClass
public static void setup() throws Exception {
TimestampWithTimezone.resetCalendar(TimeZone.getTimeZone("GMT-5"));
SERVER = new HotRodTestServer(PORT);
MetadataFactory mf = TestProtobufMetadataProcessor.protoMatadata("tables.proto");
EF = new InfinispanExecutionFactory();
TransformationMetadata tm = TestProtobufMetadataProcessor.getTransformationMetadata(mf, EF);
// String ddl = DDLStringVisitor.getDDLString(mf.getSchema(), null, null);
// System.out.println(ddl);
METADATA = new RuntimeMetadataImpl(tm);
UTILITY = new TranslationUtility(tm);
InfinispanConnection connection = SERVER.getConnection();
// only use G2 & G4 as cache only support single id
connection.registerProtobufFile(new ProtobufResource("tables.proto", ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("tables.proto"))));
EC = Mockito.mock(ExecutionContext.class);
Mockito.stub(EC.getBatchSize()).toReturn(512);
}
use of org.teiid.cdk.api.TranslationUtility in project teiid by teiid.
the class TestIckleConversionVisitor method helpExecute.
private IckleConversionVisitor helpExecute(MetadataFactory mf, String query, String expected) throws Exception {
InfinispanExecutionFactory ef = new InfinispanExecutionFactory();
TransformationMetadata metadata = TestProtobufMetadataProcessor.getTransformationMetadata(mf, ef);
TranslationUtility utility = new TranslationUtility(metadata);
Select cmd = (Select) utility.parseCommand(query);
IckleConversionVisitor visitor = new IckleConversionVisitor(new RuntimeMetadataImpl(metadata), false);
visitor.visitNode(cmd);
if (!visitor.exceptions.isEmpty()) {
throw visitor.exceptions.get(0);
}
String actual = visitor.getQuery();
assertEquals(expected, actual);
return visitor;
}
Aggregations