use of org.teiid.runtime.EmbeddedConfiguration in project teiid by teiid.
the class TestDDLMetadataStore method testConvertVDBXML.
@Test
public void testConvertVDBXML() throws Exception {
EmbeddedConfiguration ec = new EmbeddedConfiguration();
ec.setUseDisk(false);
es.addTranslator("file", new FileExecutionFactory());
es.addTranslator("h2", new ExecutionFactory<>());
es.start(ec);
FileInputStream vdb = new FileInputStream(UnitTestUtil.getTestDataPath() + "/" + "portfolio-vdb.xml");
es.deployVDB(vdb);
String content = ConvertVDB.convert(new File(UnitTestUtil.getTestDataPath() + "/" + "portfolio-vdb.xml"));
es.undeployVDB("Portfolio");
/*
FileWriter fw = new FileWriter(new File(UnitTestUtil.getTestDataPath() + "/" + "portfolio-vdb.ddl"));
fw.write(content);
fw.close();
*/
String expected = ObjectConverterUtil.convertFileToString(new File(UnitTestUtil.getTestDataPath() + "/" + "portfolio-vdb.ddl"));
assertEquals(expected, content);
// make sure the output is valid
es.deployVDB(new ByteArrayInputStream(content.getBytes("UTF-8")), true);
}
use of org.teiid.runtime.EmbeddedConfiguration in project teiid by teiid.
the class ConvertVDB method convert.
public static String convert(File f) throws VirtualDatabaseException, ConnectorManagerException, TranslatorException, IOException, URISyntaxException, MalformedURLException, AdminException, Exception, FileNotFoundException {
LogManager.setLogListener(new JBossLogger() {
@Override
public boolean isEnabled(String context, int level) {
return false;
}
});
EmbeddedConfiguration ec = new EmbeddedConfiguration();
ec.setUseDisk(false);
ec.setCacheFactory(new CacheFactory() {
@Override
public <K, V> Cache<K, V> get(String name) {
return new MockCache<>(name, 10);
}
@Override
public void destroy() {
}
});
MyServer es = new MyServer();
LogManager.setLogListener(new JBossLogger() {
@Override
public boolean isEnabled(String context, int level) {
return false;
}
});
es.start(ec);
try {
return es.convertVDB(new FileInputStream(f));
} finally {
es.stop();
}
}
use of org.teiid.runtime.EmbeddedConfiguration in project teiid by teiid.
the class TestDataRoles method testMaterializationWithSecurity.
@Test
public void testMaterializationWithSecurity() throws Exception {
es = new ExtendedEmbeddedServer();
EmbeddedConfiguration ec = new EmbeddedConfiguration();
es.start(ec);
es.deployVDB(new ByteArrayInputStream(new String("<vdb name=\"role-1\" version=\"1\">" + "<model name=\"myschema\" type=\"virtual\">" + "<metadata type = \"DDL\"><![CDATA[CREATE VIEW vw as select 'a' as col;]]></metadata></model>" + "<data-role name=\"y\" any-authenticated=\"true\"/></vdb>").getBytes()));
Connection c = es.getDriver().connect("jdbc:teiid:role-1", null);
Statement s = c.createStatement();
try {
s.execute("select * from vw");
Assert.fail();
} catch (SQLException e) {
// not authorized
}
es.getMaterializationManager().executeQuery(es.getVDBRepository().getLiveVDB("role-1"), "select * from vw");
}
use of org.teiid.runtime.EmbeddedConfiguration in project teiid by teiid.
the class TestInternalConnection method testInternalRemote.
@Test
public void testInternalRemote() throws Exception {
SocketConfiguration s = new SocketConfiguration();
InetSocketAddress addr = new InetSocketAddress(0);
s.setBindAddress(addr.getHostName());
s.setPortNumber(addr.getPort());
s.setProtocol(WireProtocol.teiid);
EmbeddedConfiguration config = new EmbeddedConfiguration();
config.addTransport(s);
config.setSecurityHelper(new ThreadLocalSecurityHelper());
es.start(config);
es.deployVDB(new ByteArrayInputStream(vdb.getBytes()));
Connection conn = null;
try {
TeiidDriver driver = new TeiidDriver();
Properties p = new Properties();
p.setProperty("user", "me");
conn = driver.connect("jdbc:teiid:test@mm://" + addr.getHostName() + ":" + es.getPort(0), p);
ResultSet rs = conn.createStatement().executeQuery("select func(1)");
rs.next();
assertEquals("me@teiid-securityHELLO WORLD1", rs.getString(1));
} finally {
if (conn != null) {
conn.close();
}
}
}
use of org.teiid.runtime.EmbeddedConfiguration in project teiid by teiid.
the class TestInternalConnection method testInternalLocalNestedTransactions.
@Test
public void testInternalLocalNestedTransactions() throws Exception {
useTxn = true;
EmbeddedConfiguration config = new EmbeddedConfiguration();
config.setSecurityHelper(new ThreadLocalSecurityHelper());
config.setTransactionManager(new DummyTransactionManager());
es.start(config);
es.deployVDB(new ByteArrayInputStream(vdb.getBytes()));
Connection conn = null;
TeiidDriver driver = es.getDriver();
conn = driver.connect("jdbc:teiid:test;autoCommitTxn=on", null);
try {
PreparedStatement ps = conn.prepareStatement("select func(?)");
ps.setInt(1, 1);
ps.execute();
} finally {
if (conn != null) {
conn.close();
}
}
conn = driver.connect("jdbc:teiid:test;autoCommitTxn=on", null);
try {
conn.setAutoCommit(false);
PreparedStatement ps = conn.prepareStatement("select func(?)");
ps.setInt(1, 1);
ps.execute();
conn.commit();
} finally {
if (conn != null) {
conn.close();
}
}
}
Aggregations