Search in sources :

Example 16 with RuntimeMetadata

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

the class TestSalesForceDirectQueryExecution method testDelete.

@Test
public void testDelete() throws Exception {
    String input = "exec native('delete;', 'id1','id2')";
    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);
    ArgumentCaptor<String[]> payloadArgument = ArgumentCaptor.forClass(String[].class);
    Mockito.stub(connection.delete(payloadArgument.capture())).toReturn(23);
    DirectQueryExecution execution = (DirectQueryExecution) TRANSLATOR.createExecution(command, ec, rm, connection);
    execution.execute();
    Mockito.verify(connection, Mockito.times(1)).delete(payloadArgument.capture());
    assertEquals("id1", payloadArgument.getValue()[0]);
    assertEquals("id2", payloadArgument.getValue()[1]);
    assertArrayEquals(new Object[] { 23 }, (Object[]) execution.next().get(0));
}
Also used : ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) TranslationUtility(org.teiid.cdk.api.TranslationUtility) SObject(com.sforce.soap.partner.sobject.SObject) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) SalesforceConnection(org.teiid.translator.salesforce.SalesforceConnection) Test(org.junit.Test)

Example 17 with RuntimeMetadata

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

the class TestLDAPDirectQueryExecution method testDelete.

@Test
public void testDelete() throws Exception {
    String input = "exec native('delete;uid=doe,ou=people,o=teiid.org')";
    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("")).toReturn(ctx);
    LDAPDirectCreateUpdateDeleteQueryExecution execution = (LDAPDirectCreateUpdateDeleteQueryExecution) TRANSLATOR.createExecution(command, ec, rm, connection);
    execution.execute();
    Mockito.verify(ctx, Mockito.times(1)).destroySubcontext("uid=doe,ou=people,o=teiid.org");
}
Also used : ExecutionContext(org.teiid.translator.ExecutionContext) 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 18 with RuntimeMetadata

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

the class TestLDAPDirectQueryExecution method testCreateFail.

@Test(expected = TranslatorException.class)
public void testCreateFail() throws Exception {
    String input = "exec native('create;uid=doe,ou=people,o=teiid.org;attributes=one,two,three', 'one')";
    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("")).toReturn(ctx);
    LDAPDirectCreateUpdateDeleteQueryExecution execution = (LDAPDirectCreateUpdateDeleteQueryExecution) 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) LdapContext(javax.naming.ldap.LdapContext) Test(org.junit.Test)

Example 19 with RuntimeMetadata

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

the class TestLDAPDirectQueryExecution method testSearch.

@Test
public void testSearch() throws Exception {
    String input = "exec native('search;context-name=corporate;filter=(objectClass=*);count-limit=5;timeout=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);
    LDAPDirectSearchQueryExecution execution = (LDAPDirectSearchQueryExecution) TRANSLATOR.createExecution(command, ec, rm, connection);
    execution.execute();
    LDAPSearchDetails details = execution.getDelegate().getSearchDetails();
    assertEquals("corporate", details.getContextName());
    assertEquals("(objectClass=*)", details.getContextFilter());
    assertEquals(5, details.getCountLimit());
    assertEquals(6, details.getTimeLimit());
    assertEquals(1, details.getSearchScope());
    assertEquals(2, details.getElementList().size());
    assertEquals("uid", details.getElementList().get(0).getName());
    assertEquals("cn", details.getElementList().get(1).getName());
}
Also used : ExecutionContext(org.teiid.translator.ExecutionContext) 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 20 with RuntimeMetadata

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

the class TestLDAPDirectQueryExecution method testCreate.

@Test
public void testCreate() throws Exception {
    String input = "exec native('create;uid=doe,ou=people,o=teiid.org;attributes=one,two,three', 'one', 2, 3.0)";
    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("")).toReturn(ctx);
    LDAPDirectCreateUpdateDeleteQueryExecution execution = (LDAPDirectCreateUpdateDeleteQueryExecution) TRANSLATOR.createExecution(command, ec, rm, connection);
    execution.execute();
    ArgumentCaptor<String> nameArgument = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<BasicAttributes> createItemArgument = ArgumentCaptor.forClass(BasicAttributes.class);
    Mockito.verify(ctx).createSubcontext(nameArgument.capture(), createItemArgument.capture());
    assertEquals("uid=doe,ou=people,o=teiid.org", nameArgument.getValue());
    assertEquals("one", createItemArgument.getValue().get("one").getID());
    assertEquals("one", createItemArgument.getValue().get("one").get());
    assertEquals("two", createItemArgument.getValue().get("two").getID());
    assertEquals("2", createItemArgument.getValue().get("two").get());
    assertEquals("three", createItemArgument.getValue().get("three").getID());
    assertEquals("3.0", createItemArgument.getValue().get("three").get());
}
Also used : BasicAttributes(javax.naming.directory.BasicAttributes) ExecutionContext(org.teiid.translator.ExecutionContext) 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)

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