Search in sources :

Example 16 with EmbeddedConfiguration

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);
}
Also used : FileExecutionFactory(org.teiid.translator.file.FileExecutionFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) EmbeddedConfiguration(org.teiid.runtime.EmbeddedConfiguration) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 17 with EmbeddedConfiguration

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();
    }
}
Also used : JBossLogger(org.teiid.runtime.JBossLogger) EmbeddedConfiguration(org.teiid.runtime.EmbeddedConfiguration) CacheFactory(org.teiid.cache.CacheFactory) FileInputStream(java.io.FileInputStream) LRUCache(org.teiid.core.util.LRUCache) Cache(org.teiid.cache.Cache)

Example 18 with EmbeddedConfiguration

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");
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) SQLException(java.sql.SQLException) Statement(java.sql.Statement) Connection(java.sql.Connection) EmbeddedConfiguration(org.teiid.runtime.EmbeddedConfiguration) Test(org.junit.Test)

Example 19 with EmbeddedConfiguration

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();
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InetSocketAddress(java.net.InetSocketAddress) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) SocketConfiguration(org.teiid.transport.SocketConfiguration) EmbeddedConfiguration(org.teiid.runtime.EmbeddedConfiguration) Properties(java.util.Properties) Test(org.junit.Test)

Example 20 with EmbeddedConfiguration

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();
        }
    }
}
Also used : DummyTransactionManager(org.infinispan.transaction.tm.DummyTransactionManager) ByteArrayInputStream(java.io.ByteArrayInputStream) Connection(java.sql.Connection) EmbeddedConfiguration(org.teiid.runtime.EmbeddedConfiguration) PreparedStatement(java.sql.PreparedStatement) Test(org.junit.Test)

Aggregations

EmbeddedConfiguration (org.teiid.runtime.EmbeddedConfiguration)26 Test (org.junit.Test)12 Connection (java.sql.Connection)9 BeforeClass (org.junit.BeforeClass)8 FakeServer (org.teiid.jdbc.FakeServer)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 FileInputStream (java.io.FileInputStream)7 ResultSet (java.sql.ResultSet)6 EmbeddedServer (org.teiid.runtime.EmbeddedServer)6 Statement (java.sql.Statement)5 InetSocketAddress (java.net.InetSocketAddress)4 DummyTransactionManager (org.infinispan.transaction.tm.DummyTransactionManager)3 Before (org.junit.Before)3 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)3 HardCodedExecutionFactory (org.teiid.runtime.HardCodedExecutionFactory)3 File (java.io.File)2 SQLException (java.sql.SQLException)2 Properties (java.util.Properties)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Subject (javax.security.auth.Subject)2