use of datawave.webservice.common.exception.DatawaveWebApplicationException in project datawave by NationalSecurityAgency.
the class ExtendedQueryExecutorBeanTest method testExecute_InvalidMediaType.
@Test
public void testExecute_InvalidMediaType() 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;
String systemFrom = "systemFrom";
String dataSetType = "dataSetType";
String purpose = "purpose";
String parentAuditId = "parentAuditId";
UUID queryId = UUID.randomUUID();
List<MediaType> mediaTypes = new ArrayList<>();
mediaTypes.add(MediaType.APPLICATION_OCTET_STREAM_TYPE);
GenericResponse<String> createResponse = new GenericResponse<>();
createResponse.setResult(queryId.toString());
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).anyTimes();
// 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 = null;
try {
MultivaluedMap<String, String> queryParameters = new MultivaluedMapImpl<>();
queryParameters.putAll(QueryParametersImpl.paramsToMap(queryLogicName, query, queryName, queryVisibility, beginDate, endDate, queryAuthorizations, expirationDate, pagesize, pageTimeout, maxResultsOverride, persistenceMode, parameters, trace));
result1 = subject.execute(queryLogicName, queryParameters, httpHeaders);
fail("Should have failed due to unsupported media type");
} catch (DatawaveWebApplicationException e) {
if (!(((QueryException) e.getCause()).getErrorCode().equals("500-13"))) {
fail("Unknown exception type: " + e.getCause());
}
}
PowerMock.verifyAll();
// Verify results
assertNull("Expected a non-null response", result1);
}
use of datawave.webservice.common.exception.DatawaveWebApplicationException in project datawave by NationalSecurityAgency.
the class ExtendedQueryExecutorBeanTest method testNext_UserNotOwner.
@Test
public void testNext_UserNotOwner() throws Exception {
// Set local test input
String userName = "userName";
String userSid = "userSid";
String otherSid = "otherSid";
UUID queryId = UUID.randomUUID();
// Set expectations
expect(this.context.getCallerPrincipal()).andReturn(this.principal).anyTimes();
expect(this.principal.getName()).andReturn(userName);
expect(this.principal.getShortName()).andReturn(otherSid);
expect(this.principal.getProxyServers()).andReturn(new ArrayList<>(0));
expect(this.context.getUserTransaction()).andReturn(this.transaction).anyTimes();
this.transaction.begin();
expect(this.cache.get(queryId.toString())).andReturn(this.runningQuery);
expect(this.cache.lock(queryId.toString())).andReturn(true);
expect(this.responseObjectFactory.getEventQueryResponse()).andReturn(new DefaultEventQueryResponse());
expect(this.runningQuery.getConnection()).andReturn(this.connector);
expect(this.runningQuery.getSettings()).andReturn(this.query);
expect(this.query.getOwner()).andReturn(userSid);
expect(this.runningQuery.getSettings()).andReturn(this.query);
expect(this.query.getOwner()).andReturn(userSid);
cache.unlock(queryId.toString());
expect(this.transaction.getStatus()).andReturn(Status.STATUS_PREPARING).times(2);
this.transaction.setRollbackOnly();
this.transaction.commit();
this.runningQuery.setActiveCall(false);
expect(this.runningQuery.getLogic()).andReturn((QueryLogic) this.queryLogic1);
expect(this.queryLogic1.getCollectQueryMetrics()).andReturn(true);
expect(this.runningQuery.getMetric()).andReturn(this.queryMetric).times(2);
expectLastCall();
this.queryMetric.setError(isA(Throwable.class));
// Run the test
PowerMock.replayAll();
QueryExecutorBean subject = new QueryExecutorBean();
setInternalState(subject, EJBContext.class, context);
setInternalState(subject, QueryCache.class, cache);
setInternalState(subject, ClosedQueryCache.class, closedCache);
setInternalState(subject, ResponseObjectFactory.class, responseObjectFactory);
setInternalState(subject, QueryMetricFactory.class, new QueryMetricFactoryImpl());
Exception result1 = null;
try {
subject.next(queryId.toString());
} catch (DatawaveWebApplicationException e) {
result1 = e;
assertTrue(e.getCause() instanceof QueryException);
assertEquals("401-1", ((QueryException) e.getCause().getCause()).getErrorCode());
}
PowerMock.verifyAll();
// Verify results
assertNotNull("Expected a DatawaveWebApplicationException to be thrown due an unchecked exception", result1);
}
use of datawave.webservice.common.exception.DatawaveWebApplicationException in project datawave by NationalSecurityAgency.
the class ExtendedQueryExecutorBeanTest method testCreateQueryAndNext_UndefinedQueryLogic.
@Test
public void testCreateQueryAndNext_UndefinedQueryLogic() 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 + 999999);
int pagesize = 1;
int pageTimeout = -1;
Long maxResultsOverride = null;
QueryPersistence persistenceMode = QueryPersistence.PERSISTENT;
String parameters = null;
boolean trace = false;
// Set expectations
expect(context.getCallerPrincipal()).andReturn(principal);
expect(this.queryLogicFactory.getQueryLogic(queryLogicName, principal)).andThrow(new IllegalArgumentException("INTENTIONALLY THROWN TEST EXCEPTION: UNDEFINED QUERY LOGIC"));
// Run the test
PowerMock.replayAll();
QueryExecutorBean subject = new QueryExecutorBean();
setInternalState(subject, QueryLogicFactory.class, queryLogicFactory);
setInternalState(subject, EJBContext.class, context);
setInternalState(subject, QueryExpirationConfiguration.class, queryExpirationConf);
setInternalState(subject, QueryParameters.class, new QueryParametersImpl());
setInternalState(subject, QueryMetricFactory.class, new QueryMetricFactoryImpl());
Throwable result1 = null;
try {
MultivaluedMap<String, String> queryParameters = new MultivaluedMapImpl<>();
queryParameters.putAll(QueryParametersImpl.paramsToMap(queryLogicName, query, queryName, queryVisibility, beginDate, endDate, queryAuthorizations, expirationDate, pagesize, pageTimeout, maxResultsOverride, persistenceMode, parameters, trace));
subject.createQueryAndNext(queryLogicName, queryParameters);
} catch (DatawaveWebApplicationException e) {
result1 = e.getCause();
}
PowerMock.verifyAll();
// Verify results
assertTrue("QueryException expected to have been thrown", result1 instanceof QueryException);
assertTrue("Thrown exception expected to have been due to undefined query logic", result1.getCause().getMessage().toLowerCase().contains("undefined query logic"));
}
use of datawave.webservice.common.exception.DatawaveWebApplicationException in project datawave by NationalSecurityAgency.
the class ExtendedQueryExecutorBeanTest method testDefineQuery_InvalidPageSize.
@Test
public void testDefineQuery_InvalidPageSize() 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);
int pagesize = 0;
int pageTimeout = -1;
Long maxResultsOverride = null;
QueryPersistence persistenceMode = QueryPersistence.PERSISTENT;
String parameters = null;
boolean trace = false;
// Run the test
PowerMock.replayAll();
QueryExecutorBean subject = new QueryExecutorBean();
setInternalState(subject, QueryParameters.class, new QueryParametersImpl());
setInternalState(subject, QueryMetricFactory.class, new QueryMetricFactoryImpl());
Throwable result1 = null;
try {
MultivaluedMap<String, String> queryParameters = new MultivaluedMapImpl<>();
queryParameters.putAll(QueryParametersImpl.paramsToMap(queryLogicName, query, queryName, queryVisibility, beginDate, endDate, queryAuthorizations, expirationDate, pagesize, pageTimeout, maxResultsOverride, persistenceMode, parameters, trace));
subject.defineQuery(queryLogicName, queryParameters);
} catch (DatawaveWebApplicationException e) {
result1 = e;
}
PowerMock.verifyAll();
// Verify results
assertTrue("BadRequestException expected to have been thrown", result1 instanceof BadRequestException);
assertEquals("Thrown exception expected to have been due to invalid page size", "400-2", ((QueryException) result1.getCause()).getErrorCode());
}
use of datawave.webservice.common.exception.DatawaveWebApplicationException in project datawave by NationalSecurityAgency.
the class ExtendedQueryExecutorBeanTest method testCreateQueryAndNext_InvalidPageSize.
@Test
public void testCreateQueryAndNext_InvalidPageSize() 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);
int pagesize = 0;
int pageTimeout = -1;
Long maxResultsOverride = null;
QueryPersistence persistenceMode = QueryPersistence.PERSISTENT;
String parameters = null;
boolean trace = false;
MultivaluedMap<String, String> p = new MultivaluedMapImpl<>();
p.putAll(QueryParametersImpl.paramsToMap(queryLogicName, query, queryName, queryVisibility, beginDate, endDate, queryAuthorizations, expirationDate, pagesize, pageTimeout, maxResultsOverride, persistenceMode, parameters, trace));
// Run the test
PowerMock.replayAll();
QueryExecutorBean subject = new QueryExecutorBean();
setInternalState(subject, QueryParameters.class, new QueryParametersImpl());
setInternalState(subject, QueryMetricFactory.class, new QueryMetricFactoryImpl());
Throwable result1 = null;
try {
subject.createQueryAndNext(queryLogicName, p);
} catch (DatawaveWebApplicationException e) {
result1 = e;
}
PowerMock.verifyAll();
// Verify results
assertTrue("BadRequestException expected to have been thrown", result1 instanceof BadRequestException);
assertEquals("Thrown exception expected to have been due to invalid page size", "400-2", ((QueryException) result1.getCause()).getErrorCode());
}
Aggregations