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