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());
}
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());
}
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());
}
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();
}
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);
}
Aggregations