Search in sources :

Example 36 with TranslationUtility

use of org.teiid.cdk.api.TranslationUtility 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 37 with TranslationUtility

use of org.teiid.cdk.api.TranslationUtility 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)

Example 38 with TranslationUtility

use of org.teiid.cdk.api.TranslationUtility in project teiid by teiid.

the class TestQueryExecution method testUnwrap.

@Test
public void testUnwrap() throws Exception {
    TranslationUtility util = new TranslationUtility(RealMetadataFactory.fromDDL("CREATE FOREIGN TABLE GROUP_PEOPLE (objectClass string options (\"teiid_ldap:unwrap\" true)) 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);
    Attributes attribs = Mockito.mock(Attributes.class);
    Attribute attrib = Mockito.mock(Attribute.class);
    Mockito.stub(attrib.size()).toReturn(2);
    NamingEnumeration attribValues = new SimpleNamingEnumeration(Arrays.asList("foo", "bar").iterator());
    Mockito.stub(attrib.getAll()).toReturn(attribValues);
    Mockito.stub(attribs.get("objectClass")).toReturn(attrib);
    final SearchResult sr = new SearchResult("x", null, attribs);
    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);
    result = execution.next();
    assertEquals(Arrays.asList("bar"), result);
    assertNull(execution.next());
    // missing attribute handling
    Mockito.stub(attribs.get("objectClass")).toReturn(null);
    enumeration = new SimpleNamingEnumeration(Arrays.asList(sr).iterator());
    Mockito.stub(ctx.search((String) Mockito.any(), (String) Mockito.any(), (SearchControls) Mockito.any())).toReturn(enumeration);
    execution = (LDAPSyncQueryExecution) lef.createExecution(command, ec, rm, connection);
    execution.execute();
    result = execution.next();
    assertEquals(Collections.singletonList(null), result);
    assertNull(execution.next());
    // empty attribute handling
    attribValues = new SimpleNamingEnumeration(new ArrayList<Object>().iterator());
    Mockito.stub(attrib.size()).toReturn(0);
    Mockito.stub(attrib.getAll()).toReturn(attribValues);
    Mockito.stub(attribs.get("objectClass")).toReturn(attrib);
    enumeration = new SimpleNamingEnumeration(Arrays.asList(sr).iterator());
    Mockito.stub(ctx.search((String) Mockito.any(), (String) Mockito.any(), (SearchControls) Mockito.any())).toReturn(enumeration);
    execution = (LDAPSyncQueryExecution) lef.createExecution(command, ec, rm, connection);
    execution.execute();
    result = execution.next();
    assertEquals(Collections.singletonList(null), result);
    assertNull(execution.next());
}
Also used : BasicAttribute(javax.naming.directory.BasicAttribute) Attribute(javax.naming.directory.Attribute) TranslationUtility(org.teiid.cdk.api.TranslationUtility) BasicAttributes(javax.naming.directory.BasicAttributes) Attributes(javax.naming.directory.Attributes) NamingEnumeration(javax.naming.NamingEnumeration) 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 39 with TranslationUtility

use of org.teiid.cdk.api.TranslationUtility in project teiid by teiid.

the class TestEmbeddedMongoExecution method setUp.

@BeforeClass
public static void setUp() throws Exception {
    translator = new MongoDBExecutionFactory();
    translator.start();
    TransformationMetadata metadata = RealMetadataFactory.fromDDL(ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("test.ddl")), "test", "dummy");
    utility = new TranslationUtility(metadata);
    mongodb = new EmbeddedMongoDB();
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) TranslationUtility(org.teiid.cdk.api.TranslationUtility) BeforeClass(org.junit.BeforeClass)

Example 40 with TranslationUtility

use of org.teiid.cdk.api.TranslationUtility in project teiid by teiid.

the class TestTeradataTranslator method testPositionalOrderByUnion.

@Test
public void testPositionalOrderByUnion() throws Exception {
    String input = "SELECT a as b, b as a from (SELECT intkey as a, stringkey as b from BQT1.smalla union SELECT intkey as a, stringkey as b from BQT1.smalla) as x order by a";
    String output = "SELECT v_0.c_0, v_0.c_1 FROM (SELECT g_1.IntKey AS c_0, g_1.StringKey AS c_1 FROM SmallA AS g_1 UNION SELECT g_0.IntKey AS c_0, g_0.StringKey AS c_1 FROM SmallA AS g_0) AS v_0 ORDER BY 2";
    TranslationUtility tu = TranslationHelper.getTranslationUtility(TranslationHelper.BQT_VDB, null);
    Command command = tu.parseCommand(input, true, true);
    TranslationHelper.helpTestVisitor(output, TRANSLATOR, command);
}
Also used : Command(org.teiid.language.Command) TranslationUtility(org.teiid.cdk.api.TranslationUtility) Test(org.junit.Test)

Aggregations

TranslationUtility (org.teiid.cdk.api.TranslationUtility)76 Command (org.teiid.language.Command)52 Test (org.junit.Test)45 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)35 ExecutionContext (org.teiid.translator.ExecutionContext)33 RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)26 SimpleDBSQLVisitor (org.teiid.translator.simpledb.SimpleDBSQLVisitor)14 MetadataFactory (org.teiid.metadata.MetadataFactory)13 FunctionTree (org.teiid.query.function.FunctionTree)11 UDFSource (org.teiid.query.function.UDFSource)11 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)11 Before (org.junit.Before)10 LdapContext (javax.naming.ldap.LdapContext)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 SimpleDBExecutionFactory (org.teiid.translator.simpledb.SimpleDBExecutionFactory)8 List (java.util.List)7 ResultSetExecution (org.teiid.translator.ResultSetExecution)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 DataSource (javax.activation.DataSource)6 WSConnection (org.teiid.translator.WSConnection)6