Search in sources :

Example 11 with ForeignSource

use of org.opennms.netmgt.provision.persist.foreignsource.ForeignSource in project opennms by OpenNMS.

the class FastFilesystemForeignSourceRepositoryTest method testForeignSource.

@Test
public void testForeignSource() throws Exception {
    createRequisition();
    ForeignSource foreignSource = createForeignSource(m_defaultForeignSourceName);
    Set<ForeignSource> foreignSources = m_foreignSourceRepository.getForeignSources();
    assertEquals("number of foreign sources must be 1", 1, foreignSources.size());
    assertEquals("getAll() foreign source name must match", m_defaultForeignSourceName, foreignSources.iterator().next().getName());
    // check that the foreign source matches
    final ForeignSource newForeignSource = m_foreignSourceRepository.getForeignSource(m_defaultForeignSourceName);
    assertEquals(foreignSource.getName(), newForeignSource.getName());
    assertEquals(foreignSource.getDateStampAsDate(), newForeignSource.getDateStampAsDate());
    assertEquals(foreignSource.getDetectorNames(), newForeignSource.getDetectorNames());
    assertEquals(foreignSource.getScanInterval(), newForeignSource.getScanInterval());
}
Also used : ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) Test(org.junit.Test)

Example 12 with ForeignSource

use of org.opennms.netmgt.provision.persist.foreignsource.ForeignSource in project opennms by OpenNMS.

the class FastFilesystemForeignSourceRepositoryTest method testDefaultForeignSource.

@Test
public void testDefaultForeignSource() throws Exception {
    createRequisition();
    List<String> detectorList = Arrays.asList(new String[] { "DNS", "FTP", "HTTP", "HTTPS", "ICMP", "IMAP", "LDAP", "NRPE", "POP3", "SMTP", "SNMP", "SSH" });
    String uuid = UUID.randomUUID().toString();
    ForeignSource defaultForeignSource = m_foreignSourceRepository.getForeignSource(uuid);
    assertEquals("name must match requested foreign source repository name", uuid, defaultForeignSource.getName());
    assertEquals("scan-interval must be 1 day", 86400000, defaultForeignSource.getScanInterval().getMillis());
    assertEquals("foreign source must have no default policies", 0, defaultForeignSource.getPolicies().size());
    List<String> fsNames = new ArrayList<String>();
    for (PluginConfig config : defaultForeignSource.getDetectors()) {
        fsNames.add(config.getName());
    }
    assertEquals("detector list must match expected defaults", detectorList, fsNames);
    assertTrue("foreign source must be tagged as default", defaultForeignSource.isDefault());
}
Also used : PluginConfig(org.opennms.netmgt.provision.persist.foreignsource.PluginConfig) ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 13 with ForeignSource

use of org.opennms.netmgt.provision.persist.foreignsource.ForeignSource in project opennms by OpenNMS.

the class CachingForeignSourceRepositoryTest method testGetRequisition.

@Test
public void testGetRequisition() throws Exception {
    Requisition requisition = createRequisition();
    ForeignSource foreignSource = createForeignSource(m_defaultForeignSourceName);
    assertRequisitionsMatch("requisitions must match", m_foreignSourceRepository.getRequisition(m_defaultForeignSourceName), m_foreignSourceRepository.getRequisition(foreignSource));
    assertRequisitionsMatch("foreign source is the expected one", requisition, m_foreignSourceRepository.getRequisition(foreignSource));
}
Also used : ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) Test(org.junit.Test)

Example 14 with ForeignSource

use of org.opennms.netmgt.provision.persist.foreignsource.ForeignSource in project opennms by OpenNMS.

the class FastFilesystemForeignSourceRepositoryTest method testGetRequisition.

@Test
public void testGetRequisition() throws Exception {
    Requisition requisition = createRequisition();
    ForeignSource foreignSource = createForeignSource(m_defaultForeignSourceName);
    assertRequisitionsMatch("requisitions must match", m_foreignSourceRepository.getRequisition(m_defaultForeignSourceName), m_foreignSourceRepository.getRequisition(foreignSource));
    assertRequisitionsMatch("foreign source is the expected one", requisition, m_foreignSourceRepository.getRequisition(foreignSource));
}
Also used : ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) Test(org.junit.Test)

Example 15 with ForeignSource

use of org.opennms.netmgt.provision.persist.foreignsource.ForeignSource in project opennms by OpenNMS.

the class PersistenceSerializationTest method setUp.

@Before
public void setUp() throws Exception {
    MockLogAppender.setupLogging();
    fa = new FileAnticipator();
    fsr = new MockForeignSourceRepository();
    fsr.save(new ForeignSource("cheese"));
    fsr.flush();
    fs = fsr.getForeignSource("cheese");
    //        fs.setScanInterval(scanInterval)
    XMLGregorianCalendar cal = DatatypeFactory.newInstance().newXMLGregorianCalendar("2009-02-25T12:45:38.800-05:00");
    fs.setDateStamp(cal);
    List<PluginConfig> detectors = new ArrayList<PluginConfig>();
    final PluginConfig detector = new PluginConfig("food", "org.opennms.netmgt.provision.persist.detectors.FoodDetector");
    detector.addParameter("type", "cheese");
    detector.addParameter("density", "soft");
    detector.addParameter("sharpness", "mild");
    detectors.add(detector);
    fs.setDetectors(detectors);
    List<PluginConfig> policies = new ArrayList<PluginConfig>();
    PluginConfig policy = new PluginConfig("lower-case-node", "org.opennms.netmgt.provision.persist.policies.NodeCategoryPolicy");
    policy.addParameter("label", "~^[a-z]$");
    policy.addParameter("category", "Lower-Case-Nodes");
    policies.add(policy);
    policy = new PluginConfig("all-ipinterfaces", "org.opennms.netmgt.provision.persist.policies.InclusiveInterfacePolicy");
    policies.add(policy);
    policy = new PluginConfig("10-ipinterfaces", "org.opennms.netmgt.provision.persist.policies.MatchingInterfacePolicy");
    policy.addParameter("ipaddress", "~^10\\..*$");
    policies.add(policy);
    policy = new PluginConfig("cisco-snmp-interfaces", "org.opennms.netmgt.provision.persist.policies.MatchingSnmpInterfacePolicy");
    policy.addParameter("ifdescr", "~^(?i:LEC).*$");
    policies.add(policy);
    fs.setPolicies(policies);
    fsw = new ForeignSourceCollection();
    fsw.getForeignSources().addAll(fsr.getForeignSources());
    c = JAXBContext.newInstance(ForeignSourceCollection.class, ForeignSource.class);
    m = c.createMarshaller();
    XMLUnit.setIgnoreWhitespace(true);
    XMLUnit.setIgnoreAttributeOrder(true);
    XMLUnit.setNormalize(true);
}
Also used : PluginConfig(org.opennms.netmgt.provision.persist.foreignsource.PluginConfig) ForeignSourceCollection(org.opennms.netmgt.provision.persist.foreignsource.ForeignSourceCollection) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) ArrayList(java.util.ArrayList) FileAnticipator(org.opennms.test.FileAnticipator) Before(org.junit.Before)

Aggregations

ForeignSource (org.opennms.netmgt.provision.persist.foreignsource.ForeignSource)72 PluginConfig (org.opennms.netmgt.provision.persist.foreignsource.PluginConfig)31 Test (org.junit.Test)23 Requisition (org.opennms.netmgt.provision.persist.requisition.Requisition)11 Before (org.junit.Before)10 MockForeignSourceRepository (org.opennms.netmgt.provision.persist.MockForeignSourceRepository)9 ArrayList (java.util.ArrayList)8 Path (javax.ws.rs.Path)8 Transactional (org.springframework.transaction.annotation.Transactional)8 TreeSet (java.util.TreeSet)6 File (java.io.File)4 DELETE (javax.ws.rs.DELETE)4 Date (java.util.Date)3 Consumes (javax.ws.rs.Consumes)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 GET (javax.ws.rs.GET)2 POST (javax.ws.rs.POST)2 Produces (javax.ws.rs.Produces)2 DateTime (org.joda.time.DateTime)2 Duration (org.joda.time.Duration)2