Search in sources :

Example 21 with Event

use of org.osgi.service.event.Event in project ddf by codice.

the class TestRegistryStorePublisher method setup.

@Before
public void setup() {
    registryId = new AttributeImpl(RegistryObjectMetacardType.REGISTRY_ID, "registryId");
    mockRegPubService = mock(RegistryPublicationService.class);
    mockFedAdminService = mock(FederationAdminService.class);
    executorService = mock(ScheduledExecutorService.class);
    serviceReference = mock(ServiceReference.class);
    mockRegistryStore = mock(RegistryStore.class);
    mockServiceEvent = mock(ServiceEvent.class);
    bundleContext = mock(BundleContext.class);
    mockIdentity = mock(Metacard.class);
    optMetacard = Optional.of(mockIdentity);
    registryStorePublisher = spy(new RegistryStorePublisher() {

        @Override
        BundleContext getBundleContext() {
            return bundleContext;
        }
    });
    registryStorePublisher.setExecutor(executorService);
    registryStorePublisher.setFederationAdminService(mockFedAdminService);
    registryStorePublisher.setRegistryPublicationService(mockRegPubService);
    Dictionary<String, Object> eventProperties = new Hashtable<>();
    eventProperties.put(EventConstants.EVENT, mockServiceEvent);
    eventProperties.put(Constants.SERVICE_PID, "servicePid");
    event = new Event("org/osgi/framework/ServiceEvent/MODIFIED", eventProperties);
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) RegistryStore(org.codice.ddf.registry.api.internal.RegistryStore) Hashtable(java.util.Hashtable) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) FederationAdminService(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminService) Matchers.anyString(org.mockito.Matchers.anyString) ServiceReference(org.osgi.framework.ServiceReference) Metacard(ddf.catalog.data.Metacard) ServiceEvent(org.osgi.framework.ServiceEvent) ServiceEvent(org.osgi.framework.ServiceEvent) Event(org.osgi.service.event.Event) RegistryPublicationService(org.codice.ddf.registry.federationadmin.service.internal.RegistryPublicationService) BundleContext(org.osgi.framework.BundleContext) Before(org.junit.Before)

Example 22 with Event

use of org.osgi.service.event.Event in project ddf by codice.

the class RegistryMetacardHandlerTest method testDeleteEvent.

@Test
public void testDeleteEvent() throws Exception {
    event = new Event(EventProcessor.EVENTS_TOPIC_DELETED, eventProperties);
    setupSerialExecutor();
    when(federationAdmin.getRegistryMetacardsByRegistryIds(any())).thenReturn(Collections.singletonList(mcard));
    when(federationAdmin.getInternalRegistryMetacardsByRegistryId(any())).thenReturn(Collections.emptyList());
    rmh.handleEvent(event);
    verify(federationAdmin).deleteRegistryEntriesByRegistryIds(any());
}
Also used : Event(org.osgi.service.event.Event) Test(org.junit.Test)

Example 23 with Event

use of org.osgi.service.event.Event in project ddf by codice.

the class RegistryMetacardHandlerTest method setup.

@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    rmh = new RegistryMetacardHandler(executorService, federationAdmin);
    mcardInternal = new MetacardImpl();
    mcardInternal.setModifiedDate(new Date());
    mcardInternal.setId("internalId");
    mcardInternal.setAttribute(Metacard.TAGS, RegistryConstants.REGISTRY_TAG_INTERNAL);
    mcardInternal.setAttribute(new AttributeImpl(RegistryObjectMetacardType.REGISTRY_ID, "testRegId"));
    mcard = new MetacardImpl();
    mcard.setId("id");
    mcard.setModifiedDate(new Date());
    mcard.setAttribute(Metacard.TAGS, RegistryConstants.REGISTRY_TAG);
    mcard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.REGISTRY_ID, "testRegId"));
    eventProperties = new Hashtable<>();
    eventProperties.put("ddf.catalog.event.metacard", mcardInternal);
    event = new Event("myevent", eventProperties);
}
Also used : AttributeImpl(ddf.catalog.data.impl.AttributeImpl) Event(org.osgi.service.event.Event) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Date(java.util.Date) Before(org.junit.Before)

Example 24 with Event

use of org.osgi.service.event.Event in project ddf by codice.

the class RegistryMetacardHandlerTest method testUpdateEventNoNewData.

@Test
public void testUpdateEventNoNewData() throws Exception {
    event = new Event(EventProcessor.EVENTS_TOPIC_UPDATED, eventProperties);
    setupSerialExecutor();
    when(federationAdmin.getRegistryMetacardsByRegistryIds(any())).thenReturn(Collections.singletonList(mcard));
    rmh.handleEvent(event);
    verify(federationAdmin, never()).addRegistryEntry(mcardInternal);
    verify(federationAdmin, never()).updateRegistryEntry(mcardInternal);
}
Also used : Event(org.osgi.service.event.Event) Test(org.junit.Test)

Example 25 with Event

use of org.osgi.service.event.Event in project ddf by codice.

the class RegistryStoreCleanupHandlerTest method handleEvent.

private void handleEvent(ServiceReference bindRef, ServiceReference eventRef, int serviceEventType, String searchRegId, List<Metacard> metacards) throws Exception {
    cleanupHandler.bindRegistryStore(bindRef);
    ServiceEvent serviceEvent = mock(ServiceEvent.class);
    when(serviceEvent.getType()).thenReturn(serviceEventType);
    when(serviceEvent.getServiceReference()).thenReturn(eventRef);
    eventProperties.put(EventConstants.EVENT, serviceEvent);
    when(federationAdmin.getInternalRegistryMetacards()).thenReturn(metacards);
    event = new Event("myevent", eventProperties);
    cleanupHandler.handleEvent(event);
}
Also used : ServiceEvent(org.osgi.framework.ServiceEvent) ServiceEvent(org.osgi.framework.ServiceEvent) Event(org.osgi.service.event.Event)

Aggregations

Event (org.osgi.service.event.Event)142 Test (org.junit.Test)79 HashMap (java.util.HashMap)48 Hashtable (java.util.Hashtable)44 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)23 ContentTypePredicate (ddf.catalog.pubsub.predicate.ContentTypePredicate)20 EventAdmin (org.osgi.service.event.EventAdmin)19 GeospatialPredicate (ddf.catalog.pubsub.predicate.GeospatialPredicate)18 Predicate (ddf.catalog.pubsub.predicate.Predicate)16 ArrayList (java.util.ArrayList)16 ActivityEvent (org.codice.ddf.activities.ActivityEvent)13 EventHandler (org.osgi.service.event.EventHandler)13 SubscriptionFilterVisitor (ddf.catalog.pubsub.internal.SubscriptionFilterVisitor)11 Date (java.util.Date)11 Job (org.apache.sling.event.jobs.Job)9 Map (java.util.Map)8 List (java.util.List)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 JobManager (org.apache.sling.event.jobs.JobManager)7 JobConsumer (org.apache.sling.event.jobs.consumer.JobConsumer)7