Пример #1
0
  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();
  }
  // 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();
  }
Пример #3
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();
  }
Пример #4
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");
    }
  }
  /** 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();
  }
Пример #7
0
  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();
  }
  @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();
  }
Пример #10
0
  public void testNotYetRegistered() throws Exception {
    setRegisteredId(null);

    anticipateAfterPropertiesSet();

    m_mock.replayAll();

    m_frontEnd.afterPropertiesSet();

    assertFalse(m_frontEnd.isRegistered());

    m_mock.verifyAll();
  }
Пример #11
0
  public void testAlreadyRegistered() throws Exception {

    setRegistered();

    anticipateAfterPropertiesSet();

    m_mock.replayAll();

    m_frontEnd.afterPropertiesSet();

    assertTrue(m_frontEnd.isRegistered());

    m_mock.verifyAll();
  }
  @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());
  }
  @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());
  }
Пример #14
0
  public void testConfigCheck() throws Exception {

    setRegistered();

    anticipateAfterPropertiesSet();

    anticipateCheckConfig();

    m_mock.replayAll();

    m_frontEnd.afterPropertiesSet();

    m_frontEnd.checkConfig();

    m_mock.verifyAll();
  }
Пример #15
0
  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 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
  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
      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());
  }
Пример #19
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();
  }
Пример #20
0
  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 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());
  }
Пример #22
0
  @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();
  }
Пример #23
0
  @Override
  protected void setUp() throws Exception {

    m_backEnd = m_mock.createMock(PollerBackEnd.class);
    m_settings = m_mock.createMock(PollerSettings.class);
    m_pollService = m_mock.createMock(PollService.class);
    m_registrationListener = m_mock.createMock(PropertyChangeListener.class);
    m_polledServiceListener = m_mock.createMock(ServicePollStateChangedListener.class);
    m_configChangeListener = m_mock.createMock(ConfigurationChangedListener.class);

    setPollConfig(new DemoPollerConfiguration());
    m_oldPollerConfiguration = null;

    m_frontEnd = new DefaultPollerFrontEnd();

    m_frontEnd.setTimeAdjustment(new DefaultTimeAdjustment());

    //        ServerUnreachableAdaptor adaptor = new ServerUnreachableAdaptor();
    //        adaptor.setRemoteBackEnd(m_backEnd);
    //        m_frontEnd.setPollerBackEnd(adaptor);

    m_frontEnd.setPollerBackEnd(m_backEnd);

    m_frontEnd.setPollerSettings(m_settings);
    m_frontEnd.setPollService(m_pollService);

    m_frontEnd.addConfigurationChangedListener(m_configChangeListener);
    m_frontEnd.addPropertyChangeListener(m_registrationListener);
    m_frontEnd.addServicePollStateChangedListener(m_polledServiceListener);

    m_serviceStatus = PollStatus.available(1234.0);
  }
  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();
  }
Пример #25
0
  @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();
  }
Пример #26
0
  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());
  }
Пример #27
0
  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();
  }
Пример #28
0
  /** Add a dummy transaction manager that has mock calls to commit() and rollback() */
  private void setupTransactionManager() {
    PlatformTransactionManager m_transactionManager =
        m_easyMockUtils.createMock(PlatformTransactionManager.class);
    TransactionTemplate transactionTemplate = new TransactionTemplate(m_transactionManager);
    m_collectd.setTransactionTemplate(transactionTemplate);

    expect(m_transactionManager.getTransaction(isA(TransactionDefinition.class)))
        .andReturn(new SimpleTransactionStatus())
        .anyTimes();
    m_transactionManager.rollback(isA(TransactionStatus.class));
    expectLastCall().anyTimes();
    m_transactionManager.commit(isA(TransactionStatus.class));
    expectLastCall().anyTimes();
  }
Пример #29
0
  private void setupCollector(String svcName, boolean successfulInit)
      throws CollectionInitializationException {
    ServiceCollector svcCollector = m_easyMockUtils.createMock(ServiceCollector.class);
    if (successfulInit) {
      svcCollector.initialize(isA(CollectionAgent.class), isAMap(String.class, Object.class));
    }
    svcCollector.initialize(Collections.<String, String>emptyMap());
    MockServiceCollector.setDelegate(svcCollector);

    // Tell the config to use the MockServiceCollector for the specified service
    Collector collector = new Collector();
    collector.setService(svcName);
    collector.setClassName(MockServiceCollector.class.getName());

    m_collectdConfigFactory = m_easyMockUtils.createMock(CollectdConfigFactory.class);
    m_collectdConfig = m_easyMockUtils.createMock(CollectdConfiguration.class);
    expect(m_collectdConfigFactory.getCollectdConfig()).andReturn(m_collectdConfig).anyTimes();
    expect(m_collectdConfig.getCollectors())
        .andReturn(Collections.singletonList(collector))
        .anyTimes();
    expect(m_collectdConfig.getThreads()).andReturn(1).anyTimes();

    m_collectd.setCollectdConfigFactory(m_collectdConfigFactory);
  }
  @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());
  }