use of org.codice.ddf.security.impl.Security in project ddf by codice.
the class CommandJobTest method testEmptyCommand.
/**
* Tests that there is no exception when command is empty
*/
@Test
public void testEmptyCommand() {
// given
CommandJob commandJob = new CommandJob(new Security());
String command = "";
// when
commandJob.execute(createMockJobExecutionContext(command));
}
use of org.codice.ddf.security.impl.Security in project ddf by codice.
the class CommandJobTest method testUnableToExecuteWithSubject.
/**
* Tests that there is no exception when executing with the {@link Subject} fails.
*/
@Test
public void testUnableToExecuteWithSubject() {
// given
CommandJob commandJob = new CommandJob(new Security()) {
@Override
public Subject getSystemSubject() {
Subject subject = mock(Subject.class);
when(subject.execute(ArgumentMatchers.<Callable<Object>>any())).thenThrow(ExecutionException.class);
return subject;
}
};
String command = VALID_COMMAND;
// when
commandJob.execute(createMockJobExecutionContext(command));
}
use of org.codice.ddf.security.impl.Security in project ddf by codice.
the class CommandJobTest method testExceptionGettingSystemSubject.
/**
* Tests that there is no exception when {@link
* org.codice.ddf.security.Security#getSystemSubject()} fails. This might happen when the system
* is very slow to start up where not all of the required security bundles are started yet.
*/
@Test
public void testExceptionGettingSystemSubject() {
// given
CommandJob commandJob = new CommandJob(new Security()) {
@Override
public Subject getSystemSubject() {
throw new RuntimeException();
}
};
String command = VALID_COMMAND;
// when
commandJob.execute(createMockJobExecutionContext(command));
}
use of org.codice.ddf.security.impl.Security in project ddf by codice.
the class CommandJobTest method testSimpleCommand.
/**
* Tests the simplest command will be executed
*/
@Test
public void testSimpleCommand() throws Exception {
FirstArgumentAnswer captureInput = new FirstArgumentAnswer();
Session session = mock(Session.class);
when(session.execute(isA(CharSequence.class))).then(captureInput);
CommandJob commandJob = new CommandJob(new Security()) {
@Override
public Subject getSystemSubject() {
return createMockSubject();
}
@Override
protected SessionFactory getSessionFactory() {
SessionFactory sessionFactory = mock(SessionFactory.class);
when(sessionFactory.create(notNull(), any(), any())).thenReturn(session);
return sessionFactory;
}
};
String command = VALID_COMMAND;
// when
commandJob.execute(createMockJobExecutionContext(command));
// then
assertThat(captureInput.getInputArg(), is(command));
verify(session, times(1)).execute(command);
verify(session, times(1)).close();
}
use of org.codice.ddf.security.impl.Security in project ddf by codice.
the class CommandJobTest method testNullMergedJobDataMap.
/**
* Tests that there is no exception when the {@link JobDataMap} of the {@link JobExecutionContext}
* is null
*/
@Test
public void testNullMergedJobDataMap() {
// given
CommandJob commandJob = new CommandJob(new Security());
JobExecutionContext jobExecutionContext = mock(JobExecutionContext.class);
when(jobExecutionContext.getMergedJobDataMap()).thenReturn(null);
// when
commandJob.execute(jobExecutionContext);
}
Aggregations