Search in sources :

Example 76 with Dictionary

use of java.util.Dictionary in project ddf by codice.

the class SourceConfigurationHandlerTest method testConfigurationUpdateActivateConfigActivePriorityNotAvailable.

@Test
public void testConfigurationUpdateActivateConfigActivePriorityNotAvailable() throws Exception {
    ArgumentCaptor<Dictionary> captor = ArgumentCaptor.forClass(Dictionary.class);
    mcard.setAttribute(RegistryObjectMetacardType.REGISTRY_IDENTITY_NODE, null);
    when(configAdmin.listConfigurations(anyString())).thenReturn(new Configuration[] { config });
    Hashtable<String, Object> props = new Hashtable<>();
    props.put("id", "TestRegNode");
    props.put("origConfig", "origConfigValue");
    props.put(RegistryConstants.CONFIGURATION_REGISTRY_ID_PROPERTY, "urn:uuid:2014ca7f59ac46f495e32b4a67a51276");
    props.put("bindingType", "Some_Other_Binding_Type");
    Configuration newDisabledConfig = mock(Configuration.class);
    when(newDisabledConfig.getFactoryPid()).thenReturn("Some_Other_Source_disabled");
    when(configAdmin.createFactoryConfiguration("Some_Other_Source_disabled", null)).thenReturn(newDisabledConfig);
    doReturn(props).when(newDisabledConfig).getProperties();
    Configuration newActiveConfig = mock(Configuration.class);
    when(configAdmin.createFactoryConfiguration("Csw_Federated_Source", null)).thenReturn(newActiveConfig);
    doReturn("Csw_Federated_Source").when(newActiveConfig).getFactoryPid();
    when(config.getProperties()).thenReturn(props);
    when(config.getFactoryPid()).thenReturn("Some_Other_Source");
    List<String> priority = new ArrayList<>();
    priority.add("Top_Priority_Source");
    priority.add("CSW_2.0.2");
    List<String> bindings = new ArrayList<>();
    bindings.add("Top_Priority_Source=Some_Other_Source");
    bindings.add("CSW_2.0.2=Csw_Federated_Source");
    sch.setBindingTypeFactoryPid(bindings);
    sch.setSourceActivationPriorityOrder(priority);
    sch.setPreserveActiveConfigurations(false);
    sch.setActivateConfigurations(true);
    setupSerialExecutor();
    sch.handleEvent(updateEvent);
    verify(config, times(1)).delete();
    verify(configAdmin, times(1)).createFactoryConfiguration("Some_Other_Source_disabled", null);
    verify(configAdmin, times(1)).createFactoryConfiguration("Csw_Federated_Source", null);
    verify(newActiveConfig).update(captor.capture());
    List<Dictionary> values = captor.getAllValues();
    assertThat(values.size(), equalTo(1));
    Dictionary passedValues = values.get(0);
    assertThat(passedValues.get("attId"), equalTo("attValue"));
    assertCswProperties(passedValues);
}
Also used : Dictionary(java.util.Dictionary) Configuration(org.osgi.service.cm.Configuration) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 77 with Dictionary

use of java.util.Dictionary in project ddf by codice.

the class SourceConfigurationHandlerTest method testDefaultConfigurationLocalNodeCreateNoTitle.

@Test
public void testDefaultConfigurationLocalNodeCreateNoTitle() throws Exception {
    ArgumentCaptor<Dictionary> captor = ArgumentCaptor.forClass(Dictionary.class);
    mcard.setAttribute(Metacard.TITLE, null);
    setupSerialExecutor();
    doReturn("Csw_Federated_Source_disabled").when(config).getFactoryPid();
    sch.handleEvent(createEvent);
    verify(configAdmin, times(1)).createFactoryConfiguration("Csw_Federated_Source_disabled", null);
    verify(config).update(captor.capture());
    Dictionary passedValues = captor.getValue();
    assertThat(passedValues.get("attId"), equalTo("attValue"));
    assertThat(passedValues.get("urlBindingName"), equalTo("cswUrl"));
    assertThat(passedValues.get("id"), equalTo("urn:uuid:2014ca7f59ac46f495e32b4a67a51276"));
    assertThat(passedValues.get("cswUrl"), equalTo("https://localhost:1234/mycsw/endpoint"));
    assertThat(passedValues.get("bindingType"), equalTo("CSW_2.0.2"));
    assertThat(passedValues.get("customSlot"), equalTo("customValue"));
}
Also used : Dictionary(java.util.Dictionary) Test(org.junit.Test)

Example 78 with Dictionary

use of java.util.Dictionary in project ddf by codice.

the class SourceConfigurationHandlerTest method testConfigurationCreateActivateConfigWithExistingMatchingActiveConfig.

@Test
public void testConfigurationCreateActivateConfigWithExistingMatchingActiveConfig() throws Exception {
    ArgumentCaptor<Dictionary> captor = ArgumentCaptor.forClass(Dictionary.class);
    mcard.setAttribute(RegistryObjectMetacardType.REGISTRY_IDENTITY_NODE, null);
    when(configAdmin.listConfigurations(anyString())).thenReturn(new Configuration[] { config });
    Hashtable<String, Object> props = new Hashtable<>();
    props.put("id", "TestRegNode");
    props.put("origConfig", "origConfigValue");
    props.put(RegistryConstants.CONFIGURATION_REGISTRY_ID_PROPERTY, "urn:uuid:2014ca7f59ac46f495e32b4a67a51276");
    props.put("bindingType", "CSW_2.0.2");
    when(config.getProperties()).thenReturn(props);
    when(config.getFactoryPid()).thenReturn("Csw_Federated_Source");
    sch.setActivateConfigurations(true);
    setupSerialExecutor();
    sch.handleEvent(createEvent);
    verify(config, never()).delete();
    verify(configAdmin, never()).createFactoryConfiguration("Csw_Federated_Source", null);
    verify(config).update(captor.capture());
    Dictionary passedValues = captor.getValue();
    assertCswProperties(passedValues);
    assertThat(passedValues.get("origConfig"), equalTo("origConfigValue"));
}
Also used : Dictionary(java.util.Dictionary) Hashtable(java.util.Hashtable) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 79 with Dictionary

use of java.util.Dictionary in project ddf by codice.

the class SourceConfigurationHandlerTest method testDefaultConfigurationLocalNodeCreate.

@Test
public void testDefaultConfigurationLocalNodeCreate() throws Exception {
    ArgumentCaptor<Dictionary> captor = ArgumentCaptor.forClass(Dictionary.class);
    setupSerialExecutor();
    doReturn("Csw_Federated_Source_disabled").when(config).getFactoryPid();
    sch.handleEvent(createEvent);
    verify(configAdmin, times(1)).createFactoryConfiguration("Csw_Federated_Source_disabled", null);
    verify(config).update(captor.capture());
    Dictionary passedValues = captor.getValue();
    assertThat(passedValues.get("attId"), equalTo("attValue"));
    assertCswProperties(passedValues);
}
Also used : Dictionary(java.util.Dictionary) Test(org.junit.Test)

Example 80 with Dictionary

use of java.util.Dictionary in project ddf by codice.

the class SourceConfigurationHandlerTest method testConfigurationUpdateActivateConfigWithExistingDifferentActiveConfig.

@Test
public void testConfigurationUpdateActivateConfigWithExistingDifferentActiveConfig() throws Exception {
    ArgumentCaptor<Dictionary> captor = ArgumentCaptor.forClass(Dictionary.class);
    mcard.setAttribute(RegistryObjectMetacardType.REGISTRY_IDENTITY_NODE, null);
    when(configAdmin.listConfigurations(anyString())).thenReturn(new Configuration[] { config });
    Hashtable<String, Object> props = new Hashtable<>();
    props.put("id", "TestRegNode");
    props.put("origConfig", "origConfigValue");
    props.put(RegistryConstants.CONFIGURATION_REGISTRY_ID_PROPERTY, "urn:uuid:2014ca7f59ac46f495e32b4a67a51276");
    props.put("bindingType", "SomeOtherBindingType");
    when(config.getProperties()).thenReturn(props);
    when(config.getFactoryPid()).thenReturn("Some_Other_Source");
    Configuration newConfig = mock(Configuration.class);
    doReturn(newConfig).when(configAdmin).createFactoryConfiguration("Csw_Federated_Source_disabled", null);
    doReturn("Csw_Federated_Source_disabled").when(newConfig).getFactoryPid();
    sch.setActivateConfigurations(true);
    setupSerialExecutor();
    sch.handleEvent(updateEvent);
    verify(configAdmin, times(1)).createFactoryConfiguration("Csw_Federated_Source_disabled", null);
    verify(newConfig).update(captor.capture());
    List<Dictionary> values = captor.getAllValues();
    assertThat(values.size(), equalTo(1));
    Dictionary passedValues = values.get(0);
    assertCswProperties(passedValues);
}
Also used : Dictionary(java.util.Dictionary) Configuration(org.osgi.service.cm.Configuration) Hashtable(java.util.Hashtable) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

Dictionary (java.util.Dictionary)198 Hashtable (java.util.Hashtable)91 Test (org.junit.Test)48 Configuration (org.osgi.service.cm.Configuration)33 BundleDescription (org.eclipse.osgi.service.resolver.BundleDescription)28 State (org.eclipse.osgi.service.resolver.State)28 Enumeration (java.util.Enumeration)27 Properties (java.util.Properties)27 BundleContext (org.osgi.framework.BundleContext)24 ArrayList (java.util.ArrayList)22 ServiceReference (org.osgi.framework.ServiceReference)21 HashMap (java.util.HashMap)20 ServiceRegistration (org.osgi.framework.ServiceRegistration)20 IOException (java.io.IOException)17 Map (java.util.Map)17 Bundle (org.osgi.framework.Bundle)16 LinkedHashMap (java.util.LinkedHashMap)13 List (java.util.List)13 Matchers.anyString (org.mockito.Matchers.anyString)11 MinionIdentity (org.opennms.minion.core.api.MinionIdentity)11