Search in sources :

Example 6 with RegistryStore

use of org.codice.ddf.registry.api.internal.RegistryStore in project ddf by codice.

the class RegistryPublicationServiceImpl method unbindRegistryStore.

public void unbindRegistryStore(ServiceReference serviceReference) {
    BundleContext bundleContext = getBundleContext();
    if (serviceReference != null && bundleContext != null) {
        RegistryStore registryStore = (RegistryStore) bundleContext.getService(serviceReference);
        registryStores.remove(registryStore);
    }
}
Also used : RegistryStore(org.codice.ddf.registry.api.internal.RegistryStore) BundleContext(org.osgi.framework.BundleContext)

Example 7 with RegistryStore

use of org.codice.ddf.registry.api.internal.RegistryStore in project ddf by codice.

the class FederationAdminTest method testRegistryStatusNoMatchingConfig.

@Test
public void testRegistryStatusNoMatchingConfig() throws Exception {
    RegistryStore source = mock(RegistryStore.class);
    Configuration config = mock(Configuration.class);
    Dictionary<String, Object> props = new Hashtable<>();
    props.put("service.pid", "servicePid2");
    when(config.getProperties()).thenReturn(props);
    when(source.isAvailable()).thenReturn(true);
    when(helper.getRegistrySources()).thenReturn(Collections.singletonList(source));
    when(helper.getConfiguration(any(ConfiguredService.class))).thenReturn(config);
    assertThat(federationAdmin.registryStatus("servicePid"), is(false));
}
Also used : RegistryStore(org.codice.ddf.registry.api.internal.RegistryStore) RegistrySourceConfiguration(org.codice.ddf.registry.federationadmin.service.internal.RegistrySourceConfiguration) Configuration(org.osgi.service.cm.Configuration) Hashtable(java.util.Hashtable) ConfiguredService(ddf.catalog.service.ConfiguredService) Test(org.junit.Test)

Example 8 with RegistryStore

use of org.codice.ddf.registry.api.internal.RegistryStore in project ddf by codice.

the class FederationAdminTest method testRegistryStatusNoConfig.

@Test
public void testRegistryStatusNoConfig() throws Exception {
    RegistryStore source = mock(RegistryStore.class);
    when(source.isAvailable()).thenReturn(true);
    when(helper.getRegistrySources()).thenReturn(Collections.singletonList(source));
    when(helper.getConfiguration(any(ConfiguredService.class))).thenReturn(null);
    assertThat(federationAdmin.registryStatus("servicePid"), is(false));
}
Also used : RegistryStore(org.codice.ddf.registry.api.internal.RegistryStore) ConfiguredService(ddf.catalog.service.ConfiguredService) Test(org.junit.Test)

Example 9 with RegistryStore

use of org.codice.ddf.registry.api.internal.RegistryStore in project ddf by codice.

the class RegistryPublicationServiceImplTest method testUpdate.

@Test
public void testUpdate() throws Exception {
    String registryId1 = "registryId1";
    String registryId2 = "registryId2";
    String registryId3 = "registryId3";
    String storeId1 = "store1";
    String storeId3 = "store3";
    // Purposely leave out mock for registry store 2
    // so a store id won't be found for registryId2
    // Not a likely case but should be handled
    RegistryStore store1 = mock(RegistryStore.class);
    when(store1.getId()).thenReturn(storeId1);
    when(store1.getRegistryId()).thenReturn(registryId1);
    RegistryStore store3 = mock(RegistryStore.class);
    when(store3.getId()).thenReturn(storeId3);
    when(store3.getRegistryId()).thenReturn(registryId3);
    when(bundleContext.getService(serviceReference)).thenReturn(store1);
    registryPublicationService.bindRegistryStore(serviceReference);
    when(bundleContext.getService(serviceReference)).thenReturn(store3);
    registryPublicationService.bindRegistryStore(serviceReference);
    List<Serializable> publishedLocations = ImmutableList.of(registryId1, registryId2, registryId3);
    Date now = new Date();
    Date before = new Date(now.getTime() - 100000);
    MetacardImpl metacard = new MetacardImpl();
    metacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.PUBLISHED_LOCATIONS, publishedLocations));
    metacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.LAST_PUBLISHED, before));
    registryPublicationService.update(metacard);
    // update will only be callled with storeIds 1 and 3, 2 didn't have a storeId match for registryId2
    verify(federationAdminService, times(1)).updateRegistryEntry(eq(metacard), (Set<String>) argThat(contains(storeId1, storeId3)));
    verify(federationAdminService, times(1)).updateRegistryEntry(metacard);
    Attribute lastPublished = metacard.getAttribute(RegistryObjectMetacardType.LAST_PUBLISHED);
    assertThat(lastPublished, notNullValue());
    Date lastPublishedDate = (Date) lastPublished.getValue();
    assertThat(lastPublishedDate.after(before), is(equalTo(true)));
}
Also used : Serializable(java.io.Serializable) RegistryStore(org.codice.ddf.registry.api.internal.RegistryStore) Attribute(ddf.catalog.data.Attribute) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) Date(java.util.Date) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 10 with RegistryStore

use of org.codice.ddf.registry.api.internal.RegistryStore in project ddf by codice.

the class RefreshRegistryEntriesTest method testMultipleStores.

@Test
public void testMultipleStores() throws Exception {
    Metacard mcard = getPopulatedTestRegistryMetacard();
    RegistryStore registryStore2 = mock(RegistryStore.class);
    when(registryStore2.getId()).thenReturn("id2");
    when(registryStore2.getRegistryId()).thenReturn("regId2");
    when(registryStore2.isAvailable()).thenReturn(true);
    when(registryStore2.isPullAllowed()).thenReturn(true);
    SourceResponse response = new SourceResponseImpl(null, Collections.singletonList(new ResultImpl(mcard)));
    when(registryStore2.query(any(QueryRequest.class))).thenReturn(response);
    when(registryStore.query(any(QueryRequest.class))).thenThrow(new UnsupportedQueryException());
    when(registryStore.isAvailable()).thenReturn(true);
    when(registryStore.isPullAllowed()).thenReturn(true);
    when(registryStore2.query(any(QueryRequest.class))).thenReturn(response);
    List<RegistryStore> stores = new ArrayList<>();
    stores.add(registryStore);
    stores.add(registryStore2);
    refreshRegistryEntries.setRegistryStores(stores);
    refreshRegistryEntries.refreshRegistryEntries();
    verify(federationAdminService).addRegistryEntries(Collections.singletonList(mcard), null);
}
Also used : Metacard(ddf.catalog.data.Metacard) RegistryStore(org.codice.ddf.registry.api.internal.RegistryStore) SourceResponse(ddf.catalog.operation.SourceResponse) QueryRequest(ddf.catalog.operation.QueryRequest) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) ArrayList(java.util.ArrayList) ResultImpl(ddf.catalog.data.impl.ResultImpl) Test(org.junit.Test)

Aggregations

RegistryStore (org.codice.ddf.registry.api.internal.RegistryStore)13 BundleContext (org.osgi.framework.BundleContext)6 Test (org.junit.Test)5 Metacard (ddf.catalog.data.Metacard)3 ConfiguredService (ddf.catalog.service.ConfiguredService)3 SourceResponse (ddf.catalog.operation.SourceResponse)2 Serializable (java.io.Serializable)2 PrivilegedActionException (java.security.PrivilegedActionException)2 ArrayList (java.util.ArrayList)2 Hashtable (java.util.Hashtable)2 Attribute (ddf.catalog.data.Attribute)1 Result (ddf.catalog.data.Result)1 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)1 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)1 ResultImpl (ddf.catalog.data.impl.ResultImpl)1 FilterBuilder (ddf.catalog.filter.FilterBuilder)1 PropertyNameImpl (ddf.catalog.filter.impl.PropertyNameImpl)1 Query (ddf.catalog.operation.Query)1 QueryRequest (ddf.catalog.operation.QueryRequest)1 QueryImpl (ddf.catalog.operation.impl.QueryImpl)1