use of datawave.webservice.query.QueryImpl in project datawave by NationalSecurityAgency.
the class QueryExecutorBeanTest method testCreateWithNoSelectedAuths.
@SuppressWarnings("unchecked")
@Test(expected = DatawaveWebApplicationException.class)
public void testCreateWithNoSelectedAuths() throws Exception {
String queryLogicName = "EventQueryLogic";
String queryName = "Something";
String query = "FOO == BAR";
Date beginDate = new Date();
Date expirationDate = DateUtils.addDays(new Date(), 1);
int pagesize = 10;
QueryPersistence persist = QueryPersistence.TRANSIENT;
Set<QueryImpl.Parameter> parameters = new HashSet<>();
// need to call the getQueryByName() method. Maybe a partial mock of QueryExecutorBean would be better
// setup principal mock
String userDN = "CN=Guy Some Other soguy, OU=MY_SUBDIVISION, OU=MY_DIVISION, O=ORG, C=US";
String[] auths = new String[2];
auths[0] = "PRIVATE";
auths[1] = "PUBLIC";
QueryImpl q = new QueryImpl();
q.setBeginDate(beginDate);
q.setEndDate(beginDate);
q.setExpirationDate(expirationDate);
q.setPagesize(pagesize);
q.setParameters(parameters);
q.setQuery(query);
q.setQueryAuthorizations(StringUtils.join(auths, ","));
q.setQueryLogicName(queryLogicName);
q.setUserDN(userDN);
q.setId(UUID.randomUUID());
@SuppressWarnings("rawtypes") QueryLogic logic = createMock(BaseQueryLogic.class);
MultivaluedMap<String, String> p = new MultivaluedMapImpl<>();
p.putSingle(QueryParameters.QUERY_AUTHORIZATIONS, "");
p.putSingle(QueryParameters.QUERY_BEGIN, QueryParametersImpl.formatDate(beginDate));
p.putSingle(QueryParameters.QUERY_END, QueryParametersImpl.formatDate(beginDate));
p.putSingle(QueryParameters.QUERY_EXPIRATION, QueryParametersImpl.formatDate(expirationDate));
p.putSingle(QueryParameters.QUERY_NAME, queryName);
p.putSingle(QueryParameters.QUERY_PAGESIZE, Integer.toString(pagesize));
p.putSingle(QueryParameters.QUERY_STRING, query);
p.putSingle(QueryParameters.QUERY_PERSISTENCE, persist.name());
p.putSingle(ColumnVisibilitySecurityMarking.VISIBILITY_MARKING, "PRIVATE|PUBLIC");
InMemoryInstance instance = new InMemoryInstance();
Connector c = instance.getConnector("root", new PasswordToken(""));
QueryParameters qp = new QueryParametersImpl();
MultivaluedMap<String, String> optionalParameters = new MultivaluedMapImpl<>();
optionalParameters.putAll(qp.getUnknownParameters(p));
DatawaveUser user = new DatawaveUser(SubjectIssuerDNPair.of(userDN, "<CN=MY_CA, OU=MY_SUBDIVISION, OU=MY_DIVISION, O=ORG, C=US>"), UserType.USER, Arrays.asList(auths), null, null, 0L);
DatawavePrincipal principal = new DatawavePrincipal(Collections.singletonList(user));
String[] dns = principal.getDNs();
Arrays.sort(dns);
List<String> dnList = Arrays.asList(dns);
PowerMock.resetAll();
EasyMock.expect(ctx.getCallerPrincipal()).andReturn(principal).anyTimes();
suppress(constructor(QueryParametersImpl.class));
EasyMock.expect(persister.create(userDN, dnList, (SecurityMarking) Whitebox.getField(bean.getClass(), "marking").get(bean), queryLogicName, (QueryParameters) Whitebox.getField(bean.getClass(), "qp").get(bean), optionalParameters)).andReturn(q);
EasyMock.expect(queryLogicFactory.getQueryLogic(queryLogicName, principal)).andReturn(logic);
EasyMock.expect(logic.getRequiredQueryParameters()).andReturn(Collections.EMPTY_SET);
EasyMock.expect(logic.containsDNWithAccess(dnList)).andReturn(true);
EasyMock.expect(logic.getMaxPageSize()).andReturn(0);
EasyMock.expect(logic.getAuditType(EasyMock.<Query>anyObject())).andReturn(AuditType.ACTIVE).anyTimes();
EasyMock.expect(logic.getSelectors(anyObject())).andReturn(null);
Map<String, String> auditParams = new HashMap<>();
auditParams.put(QueryParameters.QUERY_STRING, p.getFirst(QueryParameters.QUERY_STRING));
auditParams.put(AuditParameters.USER_DN, userDN);
auditParams.put(AuditParameters.QUERY_SECURITY_MARKING_COLVIZ, "PRIVATE|PUBLIC");
auditParams.put(AuditParameters.QUERY_AUDIT_TYPE, AuditType.ACTIVE.name());
auditParams.put(AuditParameters.QUERY_LOGIC_CLASS, "EventQueryLogic");
EasyMock.expect(auditService.audit(eq(auditParams))).andReturn(null);
logic.close();
EasyMock.expectLastCall();
persister.remove(anyObject(Query.class));
PowerMock.replayAll();
bean.createQuery(queryLogicName, p);
PowerMock.verifyAll();
}
use of datawave.webservice.query.QueryImpl in project datawave by NationalSecurityAgency.
the class QueryExecutorBeanTest method testCloseActuallyCloses.
@SuppressWarnings("unchecked")
@Test(timeout = 5000)
public void testCloseActuallyCloses() throws Exception {
QueryImpl q = createNewQuery();
final MultivaluedMap<String, String> queryParameters = createNewQueryParameterMap();
queryParameters.putSingle(QueryParameters.QUERY_LOGIC_NAME, "EventQueryLogic");
final Thread createQuery = new Thread(() -> {
try {
bean.createQuery("EventQueryLogic", queryParameters);
} catch (Exception e) {
// ok if we fail the call
log.debug("createQuery terminated with " + e);
}
});
final Throwable[] createQueryException = { null };
createQuery.setUncaughtExceptionHandler((t, e) -> createQueryException[0] = e);
@SuppressWarnings("rawtypes") QueryLogic logic = createMock(BaseQueryLogic.class);
DatawaveUser user = new DatawaveUser(SubjectIssuerDNPair.of(userDN, "<CN=MY_CA, OU=MY_SUBDIVISION, OU=MY_DIVISION, O=ORG, C=US>"), UserType.USER, Arrays.asList(auths), null, null, 0L);
DatawavePrincipal principal = new DatawavePrincipal(Collections.singletonList(user));
principal.getShortName();
String[] dns = principal.getDNs();
Arrays.sort(dns);
List<String> dnList = Arrays.asList(dns);
InMemoryInstance instance = new InMemoryInstance();
Connector c = instance.getConnector("root", new PasswordToken(""));
MultivaluedMap<String, String> optionalParameters = createNewQueryParameters(q, queryParameters);
PowerMock.resetAll();
EasyMock.expect(ctx.getCallerPrincipal()).andReturn(principal).anyTimes();
EasyMock.expect(logic.getAuditType(null)).andReturn(AuditType.NONE);
EasyMock.expect(persister.create(principal.getUserDN().subjectDN(), dnList, Whitebox.getInternalState(bean, SecurityMarking.class), queryLogicName, Whitebox.getInternalState(bean, QueryParameters.class), optionalParameters)).andReturn(q);
EasyMock.expect(persister.findById(EasyMock.anyString())).andReturn(null).anyTimes();
EasyMock.expect(connectionFactory.getTrackingMap(anyObject())).andReturn(Maps.newHashMap()).anyTimes();
BaseQueryMetric metric = new QueryMetricFactoryImpl().createMetric();
metric.populate(q);
EasyMock.expectLastCall();
metric.setQueryType(RunningQuery.class.getSimpleName());
metric.setLifecycle(Lifecycle.DEFINED);
System.out.println(metric);
Set<Prediction> predictions = new HashSet<>();
predictions.add(new Prediction("source", 1));
EasyMock.expect(predictor.predict(metric)).andReturn(predictions);
connectionRequestBean.requestBegin(q.getId().toString());
EasyMock.expectLastCall();
EasyMock.expect(connectionFactory.getConnection(eq("connPool1"), anyObject(), anyObject())).andReturn(c).anyTimes();
connectionRequestBean.requestEnd(q.getId().toString());
EasyMock.expectLastCall();
connectionFactory.returnConnection(c);
EasyMock.expectLastCall();
EasyMock.expect(queryLogicFactory.getQueryLogic(queryLogicName, principal)).andReturn(logic);
EasyMock.expect(logic.getRequiredQueryParameters()).andReturn(Collections.emptySet());
EasyMock.expect(logic.getConnectionPriority()).andReturn(AccumuloConnectionFactory.Priority.NORMAL).atLeastOnce();
EasyMock.expect(logic.containsDNWithAccess(dnList)).andReturn(true);
EasyMock.expect(logic.getMaxPageSize()).andReturn(0);
EasyMock.expect(logic.getAuditType(q)).andReturn(AuditType.NONE);
EasyMock.expect(logic.getConnPoolName()).andReturn("connPool1");
EasyMock.expect(logic.getResultLimit(eq(q.getDnList()))).andReturn(-1L).anyTimes();
EasyMock.expect(logic.getMaxResults()).andReturn(-1L).anyTimes();
EasyMock.expect(connectionRequestBean.cancelConnectionRequest(q.getId().toString(), principal)).andReturn(false).anyTimes();
connectionFactory.returnConnection(EasyMock.isA(Connector.class));
final AtomicBoolean initializeLooping = new AtomicBoolean(false);
// During initialize, mark that we get here, and then sleep
final IAnswer<GenericQueryConfiguration> initializeAnswer = () -> {
initializeLooping.set(true);
try {
while (true) {
Thread.sleep(1000);
log.debug("Initialize: woke up");
}
} catch (InterruptedException e) {
throw new QueryException("EXPECTED EXCEPTION: initialize interrupted");
}
};
EasyMock.expect(logic.initialize(anyObject(Connector.class), anyObject(Query.class), anyObject(Set.class))).andAnswer(initializeAnswer);
EasyMock.expect(logic.getCollectQueryMetrics()).andReturn(Boolean.FALSE);
// On close, interrupt the thread to simulate the ScannerFactory cleaning up
final IAnswer<Object> closeAnswer = () -> {
if (null != createQuery) {
log.debug("createQuery thread is not null. interrupting");
createQuery.interrupt();
} else {
log.debug("createQuery thread is null. not interrupting");
}
return null;
};
logic.close();
EasyMock.expectLastCall().andAnswer(closeAnswer).anyTimes();
// Make the QueryLogic mock not threadsafe, otherwise it will be blocked infinitely
// trying to get the lock on the infinite loop
EasyMock.makeThreadSafe(logic, false);
metrics.updateMetric(EasyMock.isA(QueryMetric.class));
PowerMock.replayAll();
try {
createQuery.start();
// Wait for the create call to get to initialize
while (!initializeLooping.get()) {
if (!createQuery.isAlive() && !initializeLooping.get()) {
Assert.fail("createQuery thread died before reaching initialize: " + createQueryException[0]);
}
Thread.sleep(50);
}
// initialize has not completed yet so it will not appear in the cache
Object cachedRunningQuery = cache.get(q.getId().toString());
Assert.assertNull(cachedRunningQuery);
Pair<QueryLogic<?>, Connector> pair = qlCache.poll(q.getId().toString());
Assert.assertNotNull(pair);
Assert.assertEquals(logic, pair.getFirst());
Assert.assertEquals(c, pair.getSecond());
// Have to add these back because poll was destructive
qlCache.add(q.getId().toString(), principal.getShortName(), pair.getFirst(), pair.getSecond());
// Call close
bean.close(q.getId().toString());
// Make sure that it's gone from the qlCache
pair = qlCache.poll(q.getId().toString());
Assert.assertNull("Still found an entry in the qlCache: " + pair, pair);
// Should have already joined by now, but just to be sure
createQuery.join();
} finally {
if (null != createQuery && createQuery.isAlive()) {
createQuery.interrupt();
}
}
}
use of datawave.webservice.query.QueryImpl in project datawave by NationalSecurityAgency.
the class ExtendedQueryExecutorBeanTest method testExecute_HappyPath.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testExecute_HappyPath() throws Exception {
// Set local test input
String queryLogicName = "queryLogicName";
String query = "query";
String queryName = "queryName";
String queryVisibility = "A&B";
long currentTime = System.currentTimeMillis();
Date beginDate = new Date(currentTime - 5000);
Date endDate = new Date(currentTime - 1000);
String queryAuthorizations = "AUTH_1";
Date expirationDate = new Date(currentTime + 9999);
int pagesize = 10;
int pageTimeout = -1;
Long maxResultsOverride = null;
QueryPersistence persistenceMode = QueryPersistence.PERSISTENT;
String parameters = "invalidparam; valid:param";
boolean trace = false;
UUID queryId = UUID.randomUUID();
List<MediaType> mediaTypes = new ArrayList<>();
mediaTypes.add(MediaType.APPLICATION_XML_TYPE);
GenericResponse<String> createResponse = new GenericResponse<>();
createResponse.setResult(queryId.toString());
QueryImpl qp = new QueryImpl();
qp.setQuery(query);
qp.setQueryName(queryName);
qp.setDnList(Collections.singletonList("someDN"));
qp.setQueryAuthorizations(queryAuthorizations);
qp.setColumnVisibility(queryVisibility);
qp.setBeginDate(beginDate);
qp.setEndDate(endDate);
qp.setExpirationDate(expirationDate);
qp.setPagesize(pagesize);
qp.setPageTimeout(pageTimeout);
qp.setColumnVisibility(queryAuthorizations);
MultivaluedMap<String, String> params = new MultivaluedMapImpl<>();
params.putAll(qp.toMap());
params.putSingle(QueryParameters.QUERY_TRACE, Boolean.toString(trace));
params.putSingle(QueryParameters.QUERY_PERSISTENCE, persistenceMode.name());
params.putSingle(QueryParameters.QUERY_PARAMS, parameters);
QueryExecutorBean subject = PowerMock.createPartialMock(QueryExecutorBean.class, "createQuery");
// Set expectations of the create logic
expect(this.context.getCallerPrincipal()).andReturn(this.principal).anyTimes();
expect(this.principal.getProxyServers()).andReturn(new ArrayList<>(0)).anyTimes();
expect(this.httpHeaders.getAcceptableMediaTypes()).andReturn(mediaTypes);
expect(this.queryLogicFactory.getQueryLogic(queryLogicName, principal)).andReturn((QueryLogic) this.queryLogic1);
expect(this.queryLogic1.getTransformer(isA(Query.class))).andReturn(this.transformer);
expect(this.transformer.createResponse(isA(ResultsPage.class))).andReturn(this.baseResponse);
expect(subject.createQuery(queryLogicName, params, httpHeaders)).andReturn(createResponse);
expect(this.cache.get(eq(queryId.toString()))).andReturn(this.runningQuery);
expect(this.runningQuery.getMetric()).andReturn(this.queryMetric);
this.queryMetric.setCreateCallTime(EasyMock.geq(0L));
// return streaming response
// Run the test
PowerMock.replayAll();
setInternalState(subject, EJBContext.class, context);
setInternalState(subject, AccumuloConnectionFactory.class, connectionFactory);
setInternalState(subject, ResponseObjectFactory.class, responseObjectFactory);
setInternalState(subject, CreatedQueryLogicCacheBean.class, qlCache);
setInternalState(subject, QueryCache.class, cache);
setInternalState(subject, ClosedQueryCache.class, closedCache);
setInternalState(subject, Persister.class, persister);
setInternalState(subject, QueryLogicFactory.class, queryLogicFactory);
setInternalState(subject, QueryExpirationConfiguration.class, queryExpirationConf);
setInternalState(subject, AuditBean.class, auditor);
setInternalState(subject, QueryMetricsBean.class, metrics);
setInternalState(subject, Multimap.class, traceInfos);
setInternalState(subject, QueryMetricFactory.class, new QueryMetricFactoryImpl());
StreamingOutput result1 = subject.execute(queryLogicName, params, httpHeaders);
PowerMock.verifyAll();
// Verify results
assertNotNull("Expected a non-null response", result1);
}
use of datawave.webservice.query.QueryImpl in project datawave by NationalSecurityAgency.
the class ExtendedQueryExecutorBeanTest method testDuplicateQuery_HappyPath.
@Ignore
// TODO: Fix Query duplicate method
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testDuplicateQuery_HappyPath() throws Exception {
// Set local test input
String queryLogicName = "queryLogicName";
String query = "query";
String newQueryName = "newQueryName";
String queryVisibility = "A&B";
long currentTime = System.currentTimeMillis();
Date beginDate = new Date(currentTime - 5000);
Date endDate = new Date(currentTime - 1000);
String queryAuthorizations = "AUTH_1";
Date expirationDate = new Date(currentTime + 9999);
int pagesize = 10;
int pageTimeout = -1;
Long maxResultsOverride = null;
QueryPersistence persistenceMode = QueryPersistence.PERSISTENT;
String parameters = "invalidparam; valid:param";
boolean trace = true;
String userName = "userName";
String userSid = "userSid";
String userDN = "userDN";
SubjectIssuerDNPair userDNpair = SubjectIssuerDNPair.of(userDN);
List<String> dnList = Collections.singletonList(userDN);
UUID queryId = UUID.randomUUID();
MultivaluedMap<String, String> queryParameters = new MultivaluedMapImpl<>();
queryParameters.putSingle(QueryParameters.QUERY_STRING, query);
queryParameters.putSingle(QueryParameters.QUERY_NAME, newQueryName);
queryParameters.putSingle(QueryParameters.QUERY_BEGIN, QueryParametersImpl.formatDate(beginDate));
queryParameters.putSingle(QueryParameters.QUERY_END, QueryParametersImpl.formatDate(endDate));
queryParameters.putSingle(QueryParameters.QUERY_EXPIRATION, QueryParametersImpl.formatDate(expirationDate));
queryParameters.putSingle(QueryParameters.QUERY_AUTHORIZATIONS, queryAuthorizations);
queryParameters.putSingle(QueryParameters.QUERY_PARAMS, parameters);
queryParameters.putSingle(QueryParameters.QUERY_PAGESIZE, String.valueOf(pagesize));
queryParameters.putSingle(QueryParameters.QUERY_PAGETIMEOUT, String.valueOf(pageTimeout));
queryParameters.putSingle(QueryParameters.QUERY_PERSISTENCE, persistenceMode.name());
queryParameters.putSingle(QueryParameters.QUERY_TRACE, String.valueOf(trace));
queryParameters.putSingle(ColumnVisibilitySecurityMarking.VISIBILITY_MARKING, queryVisibility);
ColumnVisibilitySecurityMarking marking = new ColumnVisibilitySecurityMarking();
marking.validate(queryParameters);
QueryParameters qp = new QueryParametersImpl();
qp.validate(queryParameters);
MultivaluedMap<String, String> op = new MultivaluedMapImpl<>();
op.putAll(qp.getUnknownParameters(queryParameters));
op.putSingle(PrivateAuditConstants.LOGIC_CLASS, queryLogic1.getClass().getSimpleName());
op.putSingle(PrivateAuditConstants.COLUMN_VISIBILITY, queryVisibility);
op.putSingle(PrivateAuditConstants.USER_DN, userDN);
// Set expectations of the create logic
expect(this.context.getCallerPrincipal()).andReturn(this.principal).times(2);
expect(this.principal.getName()).andReturn(userName).times(2);
expect(this.principal.getShortName()).andReturn(userSid).times(2);
expect(this.principal.getUserDN()).andReturn(userDNpair);
expect(this.principal.getDNs()).andReturn(new String[] { userDN });
expect(this.principal.getProxyServers()).andReturn(new ArrayList<>(0)).anyTimes();
queryLogic1.validate(queryParameters);
expect(this.queryLogic1.getAuditType(null)).andReturn(AuditType.NONE);
expect(this.principal.getAuthorizations()).andReturn((Collection) Arrays.asList(Arrays.asList(queryAuthorizations))).times(2);
expect(this.cache.get(queryId.toString())).andReturn(this.runningQuery);
expect(this.runningQuery.getSettings()).andReturn(this.query).times(2);
expect(this.query.getOwner()).andReturn(userSid);
QueryImpl newQuery1 = new QueryImpl();
newQuery1.setId(UUID.randomUUID());
newQuery1.setQuery(query);
newQuery1.setQueryName(newQueryName);
newQuery1.setBeginDate(beginDate);
newQuery1.setEndDate(endDate);
newQuery1.setExpirationDate(expirationDate);
newQuery1.setDnList(Collections.singletonList(userDN));
expect(this.query.duplicate(newQueryName)).andReturn(newQuery1);
expect(context.getCallerPrincipal()).andReturn(principal).times(2);
expect(this.queryLogicFactory.getQueryLogic(queryLogicName, principal)).andReturn((QueryLogic) this.queryLogic1).times(2);
expect(this.queryLogic1.getLogicName()).andReturn(queryLogicName).times(2);
expect(this.queryLogic1.getMaxPageSize()).andReturn(100).times(2);
QueryImpl newQuery2 = new TestQuery(newQuery1);
expect(persister.create(eq(userDNpair.subjectDN()), eq(dnList), eq(marking), eq(queryLogicName), eq(qp), eq(op))).andReturn(newQuery2);
expect(this.queryLogic1.getAuditType(newQuery2)).andReturn(AuditType.NONE);
expect(this.queryLogic1.getConnectionPriority()).andReturn(Priority.NORMAL);
expect(this.queryLogic1.getConnPoolName()).andReturn("connPool1");
expect(this.connectionFactory.getTrackingMap(isA(StackTraceElement[].class))).andReturn(null);
expect(this.connectionFactory.getConnection("connPool1", Priority.NORMAL, null)).andReturn(this.connector);
expect(this.qlCache.add(newQuery1.getId().toString(), userSid, this.queryLogic1, this.connector)).andReturn(true);
expect(this.queryLogic1.getCollectQueryMetrics()).andReturn(false);
expect(this.queryLogic1.initialize(eq(this.connector), isA(Query.class), isA(Set.class))).andReturn(this.genericConfiguration);
this.queryLogic1.setupQuery(this.genericConfiguration);
expect(this.queryLogic1.getTransformIterator(eq(newQuery2))).andReturn(this.transformIterator);
expect(this.genericConfiguration.getQueryString()).andReturn(query).once();
this.cache.put(eq(newQuery2.getId().toString()), isA(RunningQuery.class));
expect(this.qlCache.poll(newQuery1.getId().toString())).andReturn(null);
// Run the test
PowerMock.replayAll();
QueryExecutorBean subject = new QueryExecutorBean();
setInternalState(subject, EJBContext.class, context);
setInternalState(subject, AccumuloConnectionFactory.class, connectionFactory);
setInternalState(subject, ResponseObjectFactory.class, responseObjectFactory);
setInternalState(subject, CreatedQueryLogicCacheBean.class, qlCache);
setInternalState(subject, QueryCache.class, cache);
setInternalState(subject, ClosedQueryCache.class, closedCache);
setInternalState(subject, Persister.class, persister);
setInternalState(subject, QueryLogicFactory.class, queryLogicFactory);
setInternalState(subject, QueryExpirationConfiguration.class, queryExpirationConf);
setInternalState(subject, QueryMetricsBean.class, metrics);
setInternalState(subject, Multimap.class, traceInfos);
setInternalState(subject, QueryParameters.class, new QueryParametersImpl());
setInternalState(subject, QueryMetricFactory.class, new QueryMetricFactoryImpl());
GenericResponse<String> result1 = subject.duplicateQuery(queryId.toString(), newQueryName, queryLogicName, query, queryVisibility, beginDate, endDate, queryAuthorizations, expirationDate, pagesize, pageTimeout, maxResultsOverride, persistenceMode, parameters, trace);
PowerMock.verifyAll();
// Verify results
assertNotNull("Expected a non-null response", result1);
}
use of datawave.webservice.query.QueryImpl in project datawave by NationalSecurityAgency.
the class ExecutableExpansionVisitorTest method runTestQuery.
protected void runTestQuery(List<String> expected, String querystr, Date startDate, Date endDate, Map<String, String> extraParms, Connector connector) throws ParseException, Exception {
log.debug("runTestQuery");
log.trace("Creating QueryImpl");
QueryImpl settings = new QueryImpl();
settings.setBeginDate(startDate);
settings.setEndDate(endDate);
settings.setPagesize(Integer.MAX_VALUE);
settings.setQueryAuthorizations(auths.serialize());
settings.setQuery(querystr);
settings.setParameters(extraParms);
settings.setId(UUID.randomUUID());
log.debug("query: " + settings.getQuery());
log.debug("logic: " + settings.getQueryLogicName());
GenericQueryConfiguration config = logic.initialize(connector, settings, authSet);
logic.setupQuery(config);
HashSet<String> expectedSet = new HashSet<String>(expected);
HashSet<String> resultSet;
resultSet = new HashSet<String>();
Set<Document> docs = new HashSet<Document>();
for (Map.Entry<Key, Value> entry : logic) {
Document d = deserializer.apply(entry).getValue();
log.trace(entry.getKey() + " => " + d);
Attribute<?> attr = d.get("UUID");
if (attr == null)
attr = d.get("UUID.0");
Assert.assertNotNull("Result Document did not contain a 'UUID'", attr);
Assert.assertTrue("Expected result to be an instance of DatwawaveTypeAttribute, was: " + attr.getClass().getName(), attr instanceof TypeAttribute || attr instanceof PreNormalizedAttribute);
TypeAttribute<?> UUIDAttr = (TypeAttribute<?>) attr;
String UUID = UUIDAttr.getType().getDelegate().toString();
Assert.assertTrue("Received unexpected UUID: " + UUID, expected.contains(UUID));
resultSet.add(UUID);
docs.add(d);
}
if (expected.size() > resultSet.size()) {
expectedSet.addAll(expected);
expectedSet.removeAll(resultSet);
for (String s : expectedSet) {
log.warn("Missing: " + s);
}
}
if (!expected.containsAll(resultSet)) {
log.error("Expected results " + expected + " differ form actual results " + resultSet);
}
Assert.assertTrue("Expected results " + expected + " differ form actual results " + resultSet, expected.containsAll(resultSet));
Assert.assertEquals("Unexpected number of records", expected.size(), resultSet.size());
}
Aggregations