Пример #1
0
 /** Test of run method, of class ISPController. */
 @Test
 public void testRun() {
   System.out.println("testRun");
   instance.start();
   assert (instance.isAlive());
   instance.exit();
   sleepMillis(1_500);
   assert (!instance.isAlive());
 }
Пример #2
0
  /** Test if a record is registered when the controller is temporarily down. */
  @Test
  public void testControllerDownRegistration() {
    System.out.println("testControllerDownRegistration");
    List<String> hosts = new ArrayList();
    hosts.add("uva.nl");

    instance.doInBackground(hosts);
    sleepMillis(120);
    instance.stopTemporarily();
    sleepMillis(1_500);
    assertFalse(instance.isBusyCheckingConnections());
    instance.restart(hosts);
    sleepMillis(1_500);
    assertTrue(
        "The controller is NOT checking connections now", instance.isBusyCheckingConnections());
    OutageListItem lastOutage = instance.getLastOutage();
    assertTrue("No outages were registered", null != lastOutage);
    assertTrue(
        "The actual last outage is " + lastOutage, lastOutage.getOutageCause() == CONTROLLERDOWN);
    instance.exit();
    sleepMillis(1_500);
    if (instance.getSessionData().saveData()) {
      LOGGER.info("Session data is saved at exiting the application.");
    } else {
      LOGGER.error("Session data is NOT saved at exiting the application.");
    }

    LOGGER.info("Load data");
    instance.initWithPreviousSessionData();
    assertTrue(
        "The actual last outage is " + lastOutage, lastOutage.getOutageCause() == CONTROLLERDOWN);
  }
Пример #3
0
 @After
 public void tearDown() {
   System.out.println("tearDown");
   instance.exit();
   sleepMillis(1_500);
   if (instance.isAlive()) {
     LOGGER.warn("The controller thread is still running!");
   } else {
     LOGGER.info("The controller thread has exited.");
   }
 }
Пример #4
0
  /** Test of doInBackground method, of class ISPController with non-valid URL. */
  @Test
  public void testDoInBackground2() {
    System.out.println("testDoInBackground2");

    List<String> hosts = new ArrayList();
    hosts.add("willnotconnect.com");

    instance.doInBackground(hosts);
    sleepMillis(1_500);
    assertTrue(instance.getSessionData().failedChecks > 0);
  }
Пример #5
0
  /** Test of doInBackground method, of class ISPController with valid URL. */
  @Test
  public void testDoInBackground1() {
    System.out.println("testDoInBackground1");

    List<String> hosts = new ArrayList();
    hosts.add("uva.nl");

    instance.doInBackground(hosts);
    sleepMillis(1_500);
    assertTrue(instance.getSessionData().successfulChecks > 0);
  }
Пример #6
0
  /** Test of exit method, of class ISPController. */
  @Test
  public void testExit() {
    System.out.println("testExit");

    List<String> hosts = new ArrayList();
    hosts.add("uva.nl");

    instance.doInBackground(hosts);
    sleepMillis(120);
    instance.exit();
    sleepMillis(1_500);
    assertFalse(instance.isRunning());
    assertFalse(instance.isAlive());
  }
Пример #7
0
  /** Test of stopTemporarily method, of class ISPController. */
  @Test
  public void testStopTemporarily() {
    System.out.println("testStopTemporarily");

    List<String> hosts = new ArrayList();
    hosts.add("uva.nl");

    instance.doInBackground(hosts);
    sleepMillis(120);
    assertTrue(
        "The controller is NOT checking connections now", instance.isBusyCheckingConnections());
    instance.stopTemporarily();
    sleepMillis(1_100);
    assertFalse(instance.isBusyCheckingConnections());
  }
Пример #8
0
 /** Test of isRunning method, of class ISPController. */
 @Test
 public void testIsRunning() {
   System.out.println("testIsRunning");
   boolean expResult = false;
   boolean result = instance.isRunning();
   assertEquals(expResult, result);
 }
Пример #9
0
  /** Test if a record is registered when service is restarted. */
  @Test
  public void testServiceInterruptedRegistration() {
    System.out.println("testServiceInterruptedRegistration");
    List<String> hosts = new ArrayList();
    hosts.add("uva.nl");

    instance.doInBackground(hosts);
    sleepMillis(120);
    assertTrue(
        "The controller is NOT checking connections now", instance.isBusyCheckingConnections());
    OutageListItem lastOutage = instance.getLastOutage();
    LOGGER.info("Outage = {}", lastOutage);
    assertTrue("No outages were registered", null != lastOutage);
    assertTrue(
        "The actual last outage is " + lastOutage, lastOutage.getOutageCause() == SERVICEDOWN);
  }
Пример #10
0
 /** Test of checkISP method, of class ISPController with non-valid URL. */
 @Test
 public void testCheckISP2() {
   System.out.println("testCheckISP2");
   List<String> hURLs = new ArrayList();
   hURLs.add("willnotconnect.com");
   boolean expResult = false;
   boolean result = instance.checkISP(hURLs);
   assertEquals(expResult, result);
 }
Пример #11
0
 /** Test of checkISP method, of class ISPController with valid URL. */
 @Test
 public void testCheckISP1() {
   System.out.println("testCheckISP1");
   List<String> hURLs = new ArrayList();
   hURLs.add("uva.nl");
   boolean expResult = true;
   boolean result = instance.checkISP(hURLs);
   assertEquals(expResult, result);
 }
Пример #12
0
  /**
   * Test if a record is registered when the ISP can not be reached due to an internal network
   * failure.
   */
  @Test
  public void testInternalInterruptedRegistration() {
    System.out.println("testInternalInterruptedRegistration");
    List<String> hosts = new ArrayList();
    hosts.add("uva.nl");
    instance.setRouterAddress("192.168.0.6");
    instance.simulateCannotReachRouter(true);

    instance.doInBackground(hosts);
    sleepMillis(120);
    assertTrue(
        "The controller is NOT checking connections now", instance.isBusyCheckingConnections());
    instance.simulateFailure(true);
    sleepMillis(6_000);
    instance.simulateFailure(false);
    sleepMillis(6_000);
    OutageListItem lastOutage = instance.getLastOutage();
    LOGGER.info("Outage = {}", lastOutage);
    assertTrue("No outages were registered", null != lastOutage);
    assertTrue("The actual last outage is " + lastOutage, lastOutage.getOutageCause() == INTERNAL);
  }
Пример #13
0
 @Before
 public void setUp() {
   System.out.println("setUp");
   instance = new ISPController();
   LOGGER.info("New Controller instance instantiated.");
   setSessionsDataFileNameForTest();
   // copy a test file to the test directory (will be overwritten)
   File resourcesDirectory = new File("src/test/resources");
   File source = new File(resourcesDirectory, "MonitorISPData.bin");
   Path sourcePath = source.toPath();
   // copy the test file to the test directory with the same name as the source
   try {
     Files.copy(sourcePath, getTestHomeDir().resolve(source.getName()), REPLACE_EXISTING);
     LOGGER.info("Fresh test session data copied");
   } catch (IOException ex) {
     LOGGER.error("File copy failed with exception {}", ex);
   }
   // Must load the session data explicit as Homepage is not doing it.
   if (instance.initWithPreviousSessionData()) {
     LOGGER.info("Preset previous session test data are used for initialization.");
   } else {
     LOGGER.info("Preset previous session test data could not be read, defaults are set");
   }
 }