コード例 #1
0
 /**
  * Test method for {@link
  * KNXNetworkLinkFT12#removeLinkListener(tuwien.auto.calimero.link.NetworkLinkListener)}.
  */
 @Test
 public final void testRemoveLinkListener() {
   lnk.removeLinkListener(nll);
   lnk.removeLinkListener(nll);
   // should do nothing
   lnk.removeLinkListener(nll);
 }
コード例 #2
0
 /** Test method for {@link KNXNetworkLinkFT12#getName()}. */
 @Test
 public final void testGetName() {
   String n = lnk.getName();
   assertTrue(n.indexOf(Util.getSerialPortID()) > -1, Util.getSerialPortID());
   assertTrue(n.indexOf("link") > -1);
   lnk.close();
   n = lnk.getName();
   assertNotNull(n);
   assertTrue(n.indexOf("link") > -1);
 }
コード例 #3
0
 private void doSend(final byte[] nsdu)
     throws KNXLinkClosedException, InterruptedException, KNXTimeoutException {
   nll.con = null;
   lnk.sendRequest(new GroupAddress(0, 0, 1), Priority.LOW, nsdu);
   Thread.sleep(200);
   assertNotNull(nll.con);
 }
コード例 #4
0
 /** Test method for {@link KNXNetworkLinkFT12#getHopCount()}. */
 @Test
 public final void testGetHopCount() {
   assertEquals(6, lnk.getHopCount());
   lnk.setHopCount(7);
   assertEquals(7, lnk.getHopCount());
   try {
     lnk.setHopCount(-1);
     fail("negative hop count");
   } catch (final KNXIllegalArgumentException e) {
   }
   try {
     lnk.setHopCount(8);
     fail("hop count too big");
   } catch (final KNXIllegalArgumentException e) {
   }
 }
コード例 #5
0
 private void doSendWait(final byte[] nsdu) throws KNXLinkClosedException, KNXTimeoutException {
   nll.con = null;
   lnk.sendRequestWait(new GroupAddress(0, 0, 1), Priority.LOW, nsdu);
   // even in router mode, we still get tunnel ind., so always wait
   try {
     Thread.sleep(200);
   } catch (final InterruptedException e) {
   }
   assertNotNull(nll.con);
 }
コード例 #6
0
  /**
   * Test method for {@link
   * KNXNetworkLinkFT12#setKNXMedium(tuwien.auto.calimero.link.medium.KNXMediumSettings)}.
   */
  @Test
  public final void testSetKNXMedium() {
    try {
      lnk.setKNXMedium(new PLSettings());
      fail("different medium");
    } catch (final KNXIllegalArgumentException e) {
    }
    final class TPSettingsSubClass extends TPSettings {
      TPSettingsSubClass() {
        super();
      }
    }
    // replace basetype with subtype
    lnk.setKNXMedium(new TPSettingsSubClass());
    // replace subtype with its supertype
    lnk.setKNXMedium(new TPSettings());

    lnk.setKNXMedium(new TPSettings(new IndividualAddress(200)));
    assertEquals(200, lnk.getKNXMedium().getDeviceAddress().getRawAddress());
  }
コード例 #7
0
  /**
   * Test method for {@link KNXNetworkLinkFT12#send(tuwien.auto.calimero.cemi.CEMILData, boolean)}.
   *
   * @throws KNXLinkClosedException
   * @throws KNXTimeoutException
   */
  @Test
  public final void testSend() throws KNXTimeoutException, KNXLinkClosedException {
    nll.con = null;
    lnk.send(frame2, false);
    try {
      Thread.sleep(150);
    } catch (final InterruptedException e) {
    }
    assertNotNull(nll.con);

    lnk.send(frame3, false);
    try {
      Thread.sleep(150);
    } catch (final InterruptedException e) {
    }
    lnk.send(frame3, false);
    try {
      Thread.sleep(150);
    } catch (final InterruptedException e) {
    }
  }
コード例 #8
0
  /**
   * Test method for {@link KNXNetworkLinkFT12#sendRequest(KNXAddress,
   * tuwien.auto.calimero.Priority, byte[])}.
   *
   * @throws KNXLinkClosedException
   * @throws KNXTimeoutException
   * @throws InterruptedException on interrupted thread
   */
  @Test
  public final void testSendRequest()
      throws KNXTimeoutException, KNXLinkClosedException, InterruptedException {
    doSend(new byte[] {0, (byte) (0x80 | 1)});
    doSend(new byte[] {0, (byte) (0x80 | 0)});
    doSend(new byte[] {0, (byte) (0x80 | 1)});
    doSend(new byte[] {0, (byte) (0x80 | 0)});

    // send an extended PL frame
    try {
      lnk.sendRequestWait(
          new GroupAddress(0, 0, 1),
          Priority.LOW,
          new byte[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (byte) (0x80 | 0)});
    } catch (final KNXIllegalArgumentException e) {
    }
  }
コード例 #9
0
 /**
  * Test method for {@link KNXNetworkLinkFT12#close()}.
  *
  * @throws InterruptedException on interrupted thread
  * @throws KNXTimeoutException
  */
 @Test
 public final void testClose() throws InterruptedException, KNXTimeoutException {
   System.out.println(lnk.toString());
   assertTrue(lnk.isOpen());
   lnk.close();
   System.out.println(lnk.toString());
   // time for link event notifier
   Thread.sleep(50);
   assertTrue(nll.closed);
   assertFalse(lnk.isOpen());
   lnk.close();
   try {
     lnk.send(frame, false);
     fail("we are closed");
   } catch (final KNXLinkClosedException e) {
   }
   try {
     lnk.send(frame, false);
     fail("we are closed");
   } catch (final KNXLinkClosedException e) {
   }
 }
コード例 #10
0
  @BeforeEach
  void setUp() throws Exception {
    try {
      // prevents access problems with a just previously closed port
      Thread.sleep(50);
      lnk = new KNXNetworkLinkFT12(Util.getSerialPort(), TPSettings.TP1);
    } catch (final Exception e) {
      Util.tearDownLogging();
      throw e;
    }
    nll = new NLListenerImpl();
    lnk.addLinkListener(nll);

    frame =
        new CEMILData(
            CEMILData.MC_LDATA_REQ,
            new IndividualAddress(0),
            new GroupAddress(0, 0, 1),
            new byte[] {0, (byte) (0x80 | 1)},
            Priority.LOW);
    frame2 =
        new CEMILData(
            CEMILData.MC_LDATA_REQ,
            new IndividualAddress(0),
            new GroupAddress(0, 0, 1),
            new byte[] {0, (byte) (0x80 | 0)},
            Priority.URGENT,
            true,
            3);
    frame3 =
        new CEMILData(
            CEMILData.MC_LDATA_REQ,
            new IndividualAddress(0),
            new GroupAddress(0, 0, 3),
            new byte[] {0, (byte) (0x80 | 0)},
            Priority.NORMAL);
  }
コード例 #11
0
 /** Test method for {@link KNXNetworkLinkFT12#isOpen()}. */
 @Test
 public final void testIsOpen() {
   assertTrue(lnk.isOpen());
   lnk.close();
   assertFalse(lnk.isOpen());
 }
コード例 #12
0
 /**
  * Test method for {@link
  * KNXNetworkLinkFT12#addLinkListener(tuwien.auto.calimero.link.NetworkLinkListener)}.
  */
 @Test
 public final void testAddLinkListener() {
   lnk.addLinkListener(nll);
   lnk.addLinkListener(nll);
 }
コード例 #13
0
 /** Test method for {@link KNXNetworkLinkFT12#getKNXMedium()}. */
 @Test
 public final void testGetKNXMedium() {
   assertTrue(lnk.getKNXMedium() instanceof TPSettings);
   assertEquals(0, lnk.getKNXMedium().getDeviceAddress().getRawAddress());
 }
コード例 #14
0
 /**
  * Test method for {@link KNXNetworkLinkFT12#KNXNetworkLinkFT12(String,
  * tuwien.auto.calimero.link.medium.KNXMediumSettings)}.
  *
  * @throws KNXException
  */
 @Test
 public final void testKNXNetworkLinkFT12StringKNXMediumSettings() throws KNXException {
   lnk.close();
   lnk = new KNXNetworkLinkFT12(Util.getSerialPortID(), TPSettings.TP1);
   lnk.close();
 }
コード例 #15
0
 @AfterEach
 void tearDown() throws Exception {
   if (lnk != null) lnk.close();
 }