public void testSetInitialPollTime() throws Exception {

    Date start = new Date(1200000000000L);

    setRegistered();

    anticipateAfterPropertiesSet();

    int polledServiceId = pollConfig().getFirstId();

    anticipateSetInitialPollTime();

    anticipateGetServicePollState();

    //      expect(m_settings.getMonitorId()).andReturn(1).atLeastOnce();

    //      anticipateNewConfig(pollConfig());

    //      expect(m_backEnd.pollerStarting(1, getPollerDetails())).andReturn(true);

    m_mock.replayAll();

    m_frontEnd.afterPropertiesSet();

    m_frontEnd.setInitialPollTime(polledServiceId, start);

    assertEquals(start, m_frontEnd.getServicePollState(polledServiceId).getNextPollTime());

    m_mock.verifyAll();
  }
Exemple #2
0
  public void testCreate() throws Exception {

    setupCollector("SNMP", false);
    setupTransactionManager();

    // Use a mock scheduler to track calls to the Collectd scheduler
    Scheduler m_scheduler = m_easyMockUtils.createMock(Scheduler.class);
    m_collectd.setScheduler(m_scheduler);

    // Expect one task to be scheduled
    m_scheduler.schedule(eq(0L), isA(ReadyRunnable.class));

    // Expect the scheduler to be started and stopped during Collectd
    // start() and stop()
    m_scheduler.start();
    m_scheduler.stop();

    m_easyMockUtils.replayAll();

    // Initialize Collectd
    m_collectd.afterPropertiesSet();

    // Start and stop collectd
    m_collectd.start();
    m_collectd.stop();

    m_easyMockUtils.verifyAll();
  }
Exemple #3
0
  public void testOneMatchingSpec() throws Exception {
    OnmsIpInterface iface = getInterface();

    setupCollector("SNMP", true);
    setupInterface(iface);
    setupTransactionManager();

    expect(m_collectdConfig.getPackages())
        .andReturn(Collections.singletonList(getCollectionPackageThatMatchesSNMP()));
    expect(m_collectdConfigFactory.interfaceInPackage(iface, getCollectionPackageThatMatchesSNMP()))
        .andReturn(true);

    m_easyMockUtils.replayAll();

    assertEquals("scheduler entry count", 0, m_scheduler.getEntryCount());

    m_collectd.afterPropertiesSet();

    m_collectd.start();

    m_scheduler.next();

    assertEquals("scheduler entry count", 1, m_scheduler.getEntryCount());

    m_scheduler.next();

    m_collectd.stop();

    m_easyMockUtils.verifyAll();
  }
  @Test
  public void testGetResourceByNodeSourceAndIndexGetLabelStringAttribute() throws IOException {
    try {
      System.setProperty("org.opennms.rrd.storeByForeignSource", "true");

      GenericIndexResourceType rt =
          new GenericIndexResourceType(
              m_resourceStorageDao, "foo", "Foo Resource", "${stringAttribute}", m_storageStrategy);

      File rrd = touch("snmp", "fs", "source1", "123", "foo", "1", RRD_FILE_NAME);
      m_fileAnticipator.tempFile(
          rrd.getParentFile(),
          RrdResourceAttributeUtils.STRINGS_PROPERTIES_FILE_NAME,
          "stringAttribute=hello!!!!");

      m_mocks.replayAll();
      OnmsResource resource = rt.getChildByName(getNodeResource("source1", "123"), "1");
      m_mocks.verifyAll();

      assertNotNull("resource", resource);
      assertEquals("resource label", "hello!!!!", resource.getLabel());
    } finally {
      System.setProperty("org.opennms.rrd.storeByForeignSource", "false");
    }
  }
  // TODO: Add test for exception on save of XML file
  @Test
  public void testAddServiceDatabase() throws Exception {
    expectUpdateEvent();
    m_mocks.replayAll();

    m_provisioner.addServiceDatabase(
        "MyDB",
        13,
        2001,
        54321,
        71,
        23456,
        "dbuser",
        "dbPasswd",
        "org.mydb.MyDriver",
        "jdbc://mydbhost:2");
    checkDatabaseConfiguration(
        "MyDB",
        "MyDB",
        13,
        2001,
        54321,
        71,
        23456,
        "dbuser",
        "dbPasswd",
        "org.mydb.MyDriver",
        "jdbc://mydbhost:2");

    m_mocks.verifyAll();
    verifyEvents();
  }
  /** This shouldn't trigger an OpenNMS event. */
  public void testRandomEvent() throws Exception {
    SecurityAuthenticationEventOnmsEventBuilder builder =
        new SecurityAuthenticationEventOnmsEventBuilder();
    builder.setEventProxy(m_eventProxy);
    builder.afterPropertiesSet();

    m_mocks.replayAll();
    builder.onApplicationEvent(new TestApplicationEvent("Hello!"));
    m_mocks.verifyAll();
  }
  @Test
  public void testAddServiceDNS() throws Exception {
    expectUpdateEvent();
    m_mocks.replayAll();

    m_provisioner.addServiceDNS("MyDNS", 11, 1111, 11111, 111, 111111, 101, "www.opennms.org");
    checkDNSConfiguration("MyDNS", "MyDNS", 11, 1111, 11111, 111, 111111, 101, "www.opennms.org");

    m_mocks.verifyAll();
    verifyEvents();
  }
  private void testAfterPropertiesSetWithRegisteredId(Integer registeredId) throws Exception {
    setRegisteredId(registeredId);

    anticipateAfterPropertiesSet();

    m_mock.replayAll();

    m_frontEnd.afterPropertiesSet();

    m_mock.verifyAll();
  }
  @Test
  public void testAddServiceTCP() throws Exception {
    expectUpdateEvent();
    m_mocks.replayAll();

    m_provisioner.addServiceTCP("MyTCP", 4, 44, 444, 4444, 44444, 404, "HELO");
    checkTCPConfiguration("MyTCP", "MyTCP", 4, 44, 444, 4444, 44444, 404, "HELO");

    m_mocks.verifyAll();
    verifyEvents();
  }
  public void testNotYetRegistered() throws Exception {
    setRegisteredId(null);

    anticipateAfterPropertiesSet();

    m_mock.replayAll();

    m_frontEnd.afterPropertiesSet();

    assertFalse(m_frontEnd.isRegistered());

    m_mock.verifyAll();
  }
  public void testAlreadyRegistered() throws Exception {

    setRegistered();

    anticipateAfterPropertiesSet();

    m_mock.replayAll();

    m_frontEnd.afterPropertiesSet();

    assertTrue(m_frontEnd.isRegistered());

    m_mock.verifyAll();
  }
  @Test
  public void testGetResourceByNodeAndIndexGetLabelIndexWithHexConversion() {
    GenericIndexResourceType rt =
        new GenericIndexResourceType(
            m_resourceStorageDao, "foo", "Foo Resource", "${hex(index)}", m_storageStrategy);

    touch("snmp", "1", "foo", "1.2.3.4.14.15", RRD_FILE_NAME);

    m_mocks.replayAll();
    OnmsResource resource = rt.getChildByName(getNodeResource(1), "1.2.3.4.14.15");
    m_mocks.verifyAll();

    assertNotNull("resource", resource);
    assertEquals("resource label", "01:02:03:04:0E:0F", resource.getLabel());
  }
  @Test
  public void testGetResourceByNodeAndIndexGetLabelIndex() {
    GenericIndexResourceType rt =
        new GenericIndexResourceType(
            m_resourceStorageDao, "foo", "Foo Resource", "${index}", m_storageStrategy);

    touch("snmp", "1", "foo", "1", RRD_FILE_NAME);

    m_mocks.replayAll();
    OnmsResource resource = rt.getChildByName(getNodeResource(1), "1");
    m_mocks.verifyAll();

    assertNotNull("resource", resource);
    assertEquals("resource label", "1", resource.getLabel());
  }
  public void testConfigCheck() throws Exception {

    setRegistered();

    anticipateAfterPropertiesSet();

    anticipateCheckConfig();

    m_mock.replayAll();

    m_frontEnd.afterPropertiesSet();

    m_frontEnd.checkConfig();

    m_mock.verifyAll();
  }
  public void testRegisterNewMonitor() throws Exception {

    anticipateAfterPropertiesSet();

    anticiapateRegister();

    m_mock.replayAll();

    m_frontEnd.afterPropertiesSet();

    assertFalse(m_frontEnd.isRegistered());

    m_frontEnd.register("OAK");

    assertTrue(m_frontEnd.isRegistered());

    m_mock.verifyAll();
  }
  @Test
  public void testGetResourceByNodeAndIndexGetLabelIndexWithBogusUseOfNforStartOfFirstSubIndex() {
    GenericIndexResourceType rt =
        new GenericIndexResourceType(
            m_resourceStorageDao,
            "foo",
            "Foo Resource",
            "Easy as ${subIndex(n, 3)}",
            m_storageStrategy);

    touch("snmp", "1", "foo", "3.1.2.3", RRD_FILE_NAME);

    m_mocks.replayAll();
    OnmsResource resource = rt.getChildByName(getNodeResource(1), "3.1.2.3");
    m_mocks.verifyAll();

    assertNotNull("resource", resource);
    assertEquals("resource label", "Easy as ${subIndex(n, 3)}", resource.getLabel());
  }
  @Test
  public void testGetResourceByNodeAndIndexGetLabelIndexWithDisplaySubStringOfDynamicLength() {
    GenericIndexResourceType rt =
        new GenericIndexResourceType(
            m_resourceStorageDao,
            "foo",
            "Foo Resource",
            "Easy as ${string(subIndex(0, n))}",
            m_storageStrategy);

    touch("snmp", "1", "foo", "3.112.105.101", RRD_FILE_NAME);

    m_mocks.replayAll();
    OnmsResource resource = rt.getChildByName(getNodeResource(1), "3.112.105.101");
    m_mocks.verifyAll();

    assertNotNull("resource", resource);
    assertEquals("resource label", "Easy as pie", resource.getLabel());
  }
  /** Test for enhancement in bug #2467. */
  @Test
  public void testGetResourceByNodeAndIndexGetLabelIndexWithSubStringAndHexConversion() {
    GenericIndexResourceType rt =
        new GenericIndexResourceType(
            m_resourceStorageDao,
            "foo",
            "Foo Resource",
            "MAC Address ${hex(subIndex(0, 6))} on interface ${subIndex(6, 1)}",
            m_storageStrategy);

    touch("snmp", "1", "foo", "0.21.109.80.9.66.4", RRD_FILE_NAME);

    m_mocks.replayAll();
    OnmsResource resource = rt.getChildByName(getNodeResource(1), "0.21.109.80.9.66.4");
    m_mocks.verifyAll();

    assertNotNull("resource", resource);
    assertEquals(
        "resource label", "MAC Address 00:15:6D:50:09:42 on interface 4", resource.getLabel());
  }
  @Test
  public void
      testGetResourceByNodeAndIndexGetLabelIndexWithSubStringAndDynSubStringAndDynSubStringAndSubStringToEnd() {
    GenericIndexResourceType rt =
        new GenericIndexResourceType(
            m_resourceStorageDao,
            "foo",
            "Foo Resource",
            "Easy as ${subIndex(0, 1)} and ${subIndex(1, n)} and ${subIndex(n, n)} and ${subIndex(n)}",
            m_storageStrategy);

    touch("snmp", "1", "foo", "3.3.1.2.3.3.4.5.6.0", RRD_FILE_NAME);

    m_mocks.replayAll();
    OnmsResource resource = rt.getChildByName(getNodeResource(1), "3.3.1.2.3.3.4.5.6.0");
    m_mocks.verifyAll();

    assertNotNull("resource", resource);
    assertEquals("resource label", "Easy as 3 and 1.2.3 and 4.5.6 and 0", resource.getLabel());
  }
Exemple #20
0
  /** @throws Exception */
  public void testNoMatchingSpecs() throws Exception {

    setupCollector("SNMP", false);
    expect(m_ipIfDao.findByServiceType("SNMP")).andReturn(new ArrayList<OnmsIpInterface>(0));
    setupTransactionManager();

    m_easyMockUtils.replayAll();

    m_collectd.afterPropertiesSet();

    m_collectd.start();

    m_scheduler.next();

    assertEquals(0, m_scheduler.getEntryCount());

    m_collectd.stop();

    m_easyMockUtils.verifyAll();
  }
  public void testStop() throws Exception {

    setRegistered();

    anticipateAfterPropertiesSet();

    anticipateStop();

    m_mock.replayAll();

    m_frontEnd.afterPropertiesSet();

    assertTrue(m_frontEnd.isStarted());

    m_frontEnd.stop();

    assertFalse(m_frontEnd.isStarted());

    m_mock.verifyAll();
  }
  @Test
  public void testAddServiceHTTPS() throws Exception {
    expectUpdateEvent();
    m_mocks.replayAll();

    m_provisioner.addServiceHTTPS(
        "MyHTTPS",
        33,
        3333,
        33333,
        333,
        333333,
        "opennms.com",
        313,
        "303",
        "Secure",
        "/secure.html",
        "user",
        "pw",
        "");
    checkHTTPSConfiguration(
        "MyHTTPS",
        "MyHTTPS",
        33,
        3333,
        33333,
        333,
        333333,
        "opennms.com",
        313,
        "303",
        "Secure",
        "/secure.html",
        "user",
        "pw",
        "");

    m_mocks.verifyAll();
    verifyEvents();
  }
  @Test
  public void testAddServiceHTTPNoResponseCode() throws Exception {
    expectUpdateEvent();
    m_mocks.replayAll();

    m_provisioner.addServiceHTTP(
        "MyHTTP",
        22,
        2222,
        22222,
        222,
        222222,
        "opennms.com",
        212,
        "",
        "Home",
        "/index.html",
        "user",
        "pw",
        "");
    checkHTTPConfiguration(
        "MyHTTP",
        "MyHTTP",
        22,
        2222,
        22222,
        222,
        222222,
        "opennms.com",
        212,
        null,
        "Home",
        "/index.html",
        "user",
        "pw",
        "");

    m_mocks.verifyAll();
    verifyEvents();
  }
  public void testAuthenticationFailureEvent() throws Exception {
    String userName = "******";
    String ip = "1.2.3.4";
    String sessionId = "it tastes just like our regular coffee";

    HttpServletRequest request = createMock(HttpServletRequest.class);
    HttpSession session = createMock(HttpSession.class);
    expect(request.getRemoteAddr()).andReturn(ip);
    expect(request.getSession(false)).andReturn(session);
    expect(session.getId()).andReturn(sessionId);

    replay(request, session);
    WebAuthenticationDetails details = new WebAuthenticationDetails(request);
    verify(request, session);

    org.springframework.security.core.Authentication authentication =
        new TestingDetailsAuthenticationToken(
            userName, "cheesiness", new GrantedAuthority[0], details);
    AuthenticationFailureBadCredentialsEvent authEvent =
        new AuthenticationFailureBadCredentialsEvent(
            authentication, new BadCredentialsException("you are bad!"));

    SecurityAuthenticationEventOnmsEventBuilder builder =
        new SecurityAuthenticationEventOnmsEventBuilder();
    builder.setEventProxy(m_eventProxy);
    builder.afterPropertiesSet();

    EventBuilder eventBuilder =
        new EventBuilder(SecurityAuthenticationEventOnmsEventBuilder.FAILURE_UEI, "OpenNMS.WebUI");
    eventBuilder.addParam("user", userName);
    eventBuilder.addParam("ip", ip);
    eventBuilder.addParam("exceptionName", authEvent.getException().getClass().getSimpleName());
    eventBuilder.addParam("exceptionMessage", authEvent.getException().getMessage());

    m_eventProxy.send(EventEquals.eqEvent(eventBuilder.getEvent()));

    m_mocks.replayAll();
    builder.onApplicationEvent(authEvent);
    m_mocks.verifyAll();
  }
  public void testPoll() throws Exception {

    setRegistered();

    anticipateAfterPropertiesSet();

    anticipatePollService();

    anticipateGetServicePollState();

    m_mock.replayAll();

    m_frontEnd.afterPropertiesSet();

    m_frontEnd.pollService(pollConfig().getFirstId());

    ServicePollState pollState = m_frontEnd.getServicePollState(pollConfig().getFirstId());

    m_mock.verifyAll();

    assertEquals(PollStatus.SERVICE_AVAILABLE, pollState.getLastPoll().getStatusCode());
  }
  public void testDisconnect() throws Exception {
    setRegistered();

    anticipateAfterPropertiesSet();

    setMonitorStatus(MonitorStatus.DISCONNECTED);

    anticipateCheckConfig();

    setMonitorStatus(MonitorStatus.STARTED);

    anticipateCheckConfig();

    m_mock.replayAll();

    m_frontEnd.afterPropertiesSet();

    m_frontEnd.checkConfig();

    m_frontEnd.checkConfig();

    m_mock.verifyAll();
  }
  @Test
  public void
      testGetResourceByNodeAndIndexGetLabelIndexWithSubStringAndTwoDisplaySubStringsOfDynamicLengthAndSubStringToEnd() {
    GenericIndexResourceType rt =
        new GenericIndexResourceType(
            m_resourceStorageDao,
            "foo",
            "Foo Resource",
            "Easy as ${subIndex(0, 1)} piece of ${string(subIndex(1, n))} or just under ${string(subIndex(n, n))} pieces of ${subIndex(n)}",
            m_storageStrategy);

    touch("snmp", "1", "foo", "1.3.112.105.101.2.80.105.3.1.4.1.5.9", RRD_FILE_NAME);

    m_mocks.replayAll();
    OnmsResource resource =
        rt.getChildByName(getNodeResource(1), "1.3.112.105.101.2.80.105.3.1.4.1.5.9");
    m_mocks.verifyAll();

    assertNotNull("resource", resource);
    assertEquals(
        "resource label",
        "Easy as 1 piece of pie or just under Pi pieces of 3.1.4.1.5.9",
        resource.getLabel());
  }
 public void replay() {
   m_easyMock.replayAll();
 }