Search in sources :

Example 6 with Security

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));
}
Also used : Security(org.codice.ddf.security.impl.Security) Test(org.junit.Test)

Example 7 with Security

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));
}
Also used : Security(org.codice.ddf.security.impl.Security) Subject(ddf.security.Subject) Test(org.junit.Test)

Example 8 with Security

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));
}
Also used : Security(org.codice.ddf.security.impl.Security) Test(org.junit.Test)

Example 9 with Security

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();
}
Also used : SessionFactory(org.apache.karaf.shell.api.console.SessionFactory) Security(org.codice.ddf.security.impl.Security) Session(org.apache.karaf.shell.api.console.Session) Test(org.junit.Test)

Example 10 with Security

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);
}
Also used : JobExecutionContext(org.quartz.JobExecutionContext) Security(org.codice.ddf.security.impl.Security) Test(org.junit.Test)

Aggregations

Security (org.codice.ddf.security.impl.Security)18 Test (org.junit.Test)14 FilterPlugin (ddf.catalog.security.filter.plugin.FilterPlugin)5 PermissionsImpl (ddf.security.permission.impl.PermissionsImpl)4 SecurityLogger (ddf.security.audit.SecurityLogger)3 QueryResponseImpl (ddf.catalog.operation.impl.QueryResponseImpl)2 Subject (ddf.security.Subject)2 SubjectUtils (ddf.security.service.impl.SubjectUtils)2 Before (org.junit.Before)2 AttributeRegistry (ddf.catalog.data.AttributeRegistry)1 Metacard (ddf.catalog.data.Metacard)1 ResultImpl (ddf.catalog.data.impl.ResultImpl)1 GeotoolsFilterAdapterImpl (ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl)1 DeleteRequest (ddf.catalog.operation.DeleteRequest)1 QueryResponse (ddf.catalog.operation.QueryResponse)1 ResourceRequest (ddf.catalog.operation.ResourceRequest)1 CreateRequestImpl (ddf.catalog.operation.impl.CreateRequestImpl)1 DeleteResponseImpl (ddf.catalog.operation.impl.DeleteResponseImpl)1 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)1 ResourceResponseImpl (ddf.catalog.operation.impl.ResourceResponseImpl)1