Search in sources :

Example 11 with RuntimeMetadata

use of org.teiid.metadata.RuntimeMetadata in project teiid by teiid.

the class TestLDAPDirectQueryExecution method testWithoutMarker.

@Test(expected = TranslatorException.class)
public void testWithoutMarker() throws Exception {
    String input = "exec native('context-name=corporate;filter=(objectClass=*);count-limit=5;timout=6;search-scope=ONELEVEL_SCOPE;attributes=uid,cn')";
    TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
    Command command = util.parseCommand(input);
    ExecutionContext ec = Mockito.mock(ExecutionContext.class);
    RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
    LdapContext connection = Mockito.mock(LdapContext.class);
    LdapContext ctx = Mockito.mock(LdapContext.class);
    Mockito.stub(connection.lookup("corporate")).toReturn(ctx);
    Execution execution = TRANSLATOR.createExecution(command, ec, rm, connection);
    assertTrue(!(execution instanceof LDAPDirectSearchQueryExecution));
    execution.execute();
}
Also used : ExecutionContext(org.teiid.translator.ExecutionContext) Execution(org.teiid.translator.Execution) Command(org.teiid.language.Command) TranslationUtility(org.teiid.cdk.api.TranslationUtility) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) LdapContext(javax.naming.ldap.LdapContext) Test(org.junit.Test)

Example 12 with RuntimeMetadata

use of org.teiid.metadata.RuntimeMetadata in project teiid by teiid.

the class TestQueryExecution method testUnwrapExtract.

@Test
public void testUnwrapExtract() throws Exception {
    TranslationUtility util = new TranslationUtility(RealMetadataFactory.fromDDL("CREATE FOREIGN TABLE GROUP_PEOPLE (\"member\" string options (\"teiid_ldap:unwrap\" true, \"teiid_ldap:rdn_type\" 'uid', \"teiid_ldap:dn_prefix\" 'ou=users')) OPTIONS(nameinsource 'ou=Infrastructure,ou=Support,o=DEMOCORP,c=AU', updatable true);", "x", "y"));
    Command command = util.parseCommand("select * from group_people");
    ExecutionContext ec = Mockito.mock(ExecutionContext.class);
    RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
    LdapContext connection = Mockito.mock(LdapContext.class);
    LdapContext ctx = Mockito.mock(LdapContext.class);
    Mockito.stub(connection.lookup("ou=Infrastructure,ou=Support,o=DEMOCORP,c=AU")).toReturn(ctx);
    BasicAttributes attributes = new BasicAttributes(true);
    BasicAttribute attrib = new BasicAttribute("member");
    attributes.put(attrib);
    attrib.add("uid=foo,ou=users");
    // does not match rdn type
    attrib.add("user=bar,ou=users");
    // does not dn prefix
    attrib.add("uid=bar");
    final SearchResult sr = new SearchResult("x", null, attributes);
    NamingEnumeration<SearchResult> enumeration = new SimpleNamingEnumeration(Arrays.asList(sr).iterator());
    Mockito.stub(ctx.search((String) Mockito.any(), (String) Mockito.any(), (SearchControls) Mockito.any())).toReturn(enumeration);
    LDAPExecutionFactory lef = new LDAPExecutionFactory();
    lef.start();
    LDAPSyncQueryExecution execution = (LDAPSyncQueryExecution) lef.createExecution(command, ec, rm, connection);
    execution.execute();
    List<?> result = execution.next();
    assertEquals(Arrays.asList("foo"), result);
    assertNull(execution.next());
}
Also used : BasicAttribute(javax.naming.directory.BasicAttribute) BasicAttributes(javax.naming.directory.BasicAttributes) TranslationUtility(org.teiid.cdk.api.TranslationUtility) SearchResult(javax.naming.directory.SearchResult) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) LdapContext(javax.naming.ldap.LdapContext) Test(org.junit.Test)

Example 13 with RuntimeMetadata

use of org.teiid.metadata.RuntimeMetadata in project teiid by teiid.

the class TestJPADirectQueryExecution method testSearch.

@Test
public void testSearch() throws Exception {
    String input = "exec native('search;SELECT Account.Id, Account.Type, Account.Name FROM Account')";
    TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
    Command command = util.parseCommand(input);
    ExecutionContext ec = Mockito.mock(ExecutionContext.class);
    RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
    EntityManager connection = Mockito.mock(EntityManager.class);
    Query query = Mockito.mock(Query.class);
    Mockito.stub(connection.createQuery("SELECT Account.Id, Account.Type, Account.Name FROM Account")).toReturn(query);
    JPQLDirectQueryExecution execution = (JPQLDirectQueryExecution) TRANSLATOR.createExecution(command, ec, rm, connection);
    execution.execute();
    Mockito.verify(connection, Mockito.times(1)).createQuery("SELECT Account.Id, Account.Type, Account.Name FROM Account");
}
Also used : EntityManager(javax.persistence.EntityManager) ExecutionContext(org.teiid.translator.ExecutionContext) Query(javax.persistence.Query) Command(org.teiid.language.Command) TranslationUtility(org.teiid.cdk.api.TranslationUtility) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) Test(org.junit.Test)

Example 14 with RuntimeMetadata

use of org.teiid.metadata.RuntimeMetadata in project teiid by teiid.

the class TestSalesForceDirectQueryExecution method testWithoutMarker.

@Test(expected = TranslatorException.class)
public void testWithoutMarker() throws Exception {
    String input = "exec native('salesforce query')";
    TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
    Command command = util.parseCommand(input);
    ExecutionContext ec = Mockito.mock(ExecutionContext.class);
    RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
    SalesforceConnection connection = Mockito.mock(SalesforceConnection.class);
    DirectQueryExecution execution = (DirectQueryExecution) TRANSLATOR.createExecution(command, ec, rm, connection);
    execution.execute();
}
Also used : ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) TranslationUtility(org.teiid.cdk.api.TranslationUtility) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) SalesforceConnection(org.teiid.translator.salesforce.SalesforceConnection) Test(org.junit.Test)

Example 15 with RuntimeMetadata

use of org.teiid.metadata.RuntimeMetadata in project teiid by teiid.

the class TestSalesForceDirectQueryExecution method testSearch.

@Test
public void testSearch() throws Exception {
    String input = "exec native('search;SELECT Account.Id, Account.Type, Account.Name FROM Account')";
    TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
    Command command = util.parseCommand(input);
    ExecutionContext ec = Mockito.mock(ExecutionContext.class);
    RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
    SalesforceConnection connection = Mockito.mock(SalesforceConnection.class);
    QueryResult qr = Mockito.mock(QueryResult.class);
    Mockito.stub(qr.isDone()).toReturn(true);
    SObject[] results = new SObject[1];
    SObject s = new SObject();
    s.setType("Account");
    s.setId("The ID");
    results[0] = s;
    s.addField("Type", "The Type");
    s.addField("Name", "The Name");
    Mockito.stub(qr.getRecords()).toReturn(results);
    Mockito.stub(connection.query("SELECT Account.Id, Account.Type, Account.Name FROM Account", 0, false)).toReturn(qr);
    DirectQueryExecution execution = (DirectQueryExecution) TRANSLATOR.createExecution(command, ec, rm, connection);
    execution.execute();
    Mockito.verify(connection, Mockito.times(1)).query("SELECT Account.Id, Account.Type, Account.Name FROM Account", 0, false);
    assertArrayEquals(new Object[] { "The ID", "The Type", "The Name" }, (Object[]) execution.next().get(0));
}
Also used : QueryResult(com.sforce.soap.partner.QueryResult) ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) TranslationUtility(org.teiid.cdk.api.TranslationUtility) SObject(com.sforce.soap.partner.sobject.SObject) SObject(com.sforce.soap.partner.sobject.SObject) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) SalesforceConnection(org.teiid.translator.salesforce.SalesforceConnection) Test(org.junit.Test)

Aggregations

RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)46 ExecutionContext (org.teiid.translator.ExecutionContext)40 Test (org.junit.Test)38 Command (org.teiid.language.Command)33 TranslationUtility (org.teiid.cdk.api.TranslationUtility)26 ResultSetExecution (org.teiid.translator.ResultSetExecution)14 QueryExpression (org.teiid.language.QueryExpression)11 TranslatorException (org.teiid.translator.TranslatorException)10 LdapContext (javax.naming.ldap.LdapContext)9 List (java.util.List)8 ExecutionFactory (org.teiid.translator.ExecutionFactory)8 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)7 SalesforceConnection (org.teiid.translator.salesforce.SalesforceConnection)7 ArrayList (java.util.ArrayList)6 DataNotAvailableException (org.teiid.translator.DataNotAvailableException)5 ResultSetFuture (com.datastax.driver.core.ResultSetFuture)4 SObject (com.sforce.soap.partner.sobject.SObject)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 EntityManager (javax.persistence.EntityManager)4 UpdateExecution (org.teiid.translator.UpdateExecution)4