@Test
  public void createFixedLengthStringTlv() throws Exception {
    Tlv tlv0 = null;

    tlv0 = TlvUtil.createFixedLengthStringTlv((short) 0x0001, null, 2, "ISO-8859-1");
    Assert.assertEquals((short) 0x0001, tlv0.getTag());
    Assert.assertArrayEquals(HexUtil.toByteArray("0000"), tlv0.getValue());

    tlv0 = TlvUtil.createFixedLengthStringTlv((short) 0x0001, "", 2);
    Assert.assertEquals((short) 0x0001, tlv0.getTag());
    Assert.assertArrayEquals(HexUtil.toByteArray("0000"), tlv0.getValue());

    tlv0 = TlvUtil.createFixedLengthStringTlv((short) 0x0001, "1", 2, "ISO-8859-1");
    Assert.assertEquals((short) 0x0001, tlv0.getTag());
    Assert.assertArrayEquals(HexUtil.toByteArray("3100"), tlv0.getValue());

    tlv0 = TlvUtil.createFixedLengthStringTlv((short) 0x0001, "12", 2);
    Assert.assertEquals((short) 0x0001, tlv0.getTag());
    Assert.assertArrayEquals(HexUtil.toByteArray("3132"), tlv0.getValue());

    try {
      tlv0 = TlvUtil.createFixedLengthStringTlv((short) 0x0001, "12", 1, "ISO-8859-1");
      Assert.fail();
    } catch (TlvConvertException e) {
      // correct behavior
    }
  }
  @Test
  public void createNullTerminatedStringTlv() throws Exception {
    Tlv tlv0 = null;

    // null string should just be 0x00
    tlv0 = TlvUtil.createNullTerminatedStringTlv((short) 0x0001, null, "ISO-8859-1");
    Assert.assertEquals((short) 0x0001, tlv0.getTag());
    Assert.assertArrayEquals(HexUtil.toByteArray("00"), tlv0.getValue());

    tlv0 = TlvUtil.createNullTerminatedStringTlv((short) 0x0001, "", "ISO-8859-1");
    Assert.assertEquals((short) 0x0001, tlv0.getTag());
    Assert.assertArrayEquals(HexUtil.toByteArray("00"), tlv0.getValue());

    tlv0 = TlvUtil.createNullTerminatedStringTlv((short) 0x0001, "a");
    Assert.assertEquals((short) 0x0001, tlv0.getTag());
    Assert.assertArrayEquals(HexUtil.toByteArray("6100"), tlv0.getValue());

    tlv0 = TlvUtil.createNullTerminatedStringTlv((short) 0x0001, "c1net");
    Assert.assertEquals((short) 0x0001, tlv0.getTag());
    Assert.assertArrayEquals(HexUtil.toByteArray("63316e657400"), tlv0.getValue());
  }
  @Test
  public void serverSessionBindVersion35NormalizesTo34() throws Exception {
    DefaultSmppServer server0 = createSmppServer();
    server0.start();

    try {
      DefaultSmppClient client0 = new DefaultSmppClient();
      SmppSessionConfiguration sessionConfig0 = createDefaultConfiguration();

      // set to version 3.5
      sessionConfig0.setInterfaceVersion((byte) 0x35);

      // we will not use the proper method of binding since we need to
      // access the bind response to verify it's correct
      DefaultSmppSession session0 = client0.doOpen(sessionConfig0, new DefaultSmppSessionHandler());

      // create a bind request based on this config
      BaseBind bindRequest = client0.createBindRequest(sessionConfig0);

      // execute a bind request and wait for a bind response
      BaseBindResp bindResponse = session0.bind(bindRequest, 200);

      Thread.sleep(100);

      SmppServerSession serverSession0 = serverHandler.sessions.iterator().next();
      Assert.assertEquals(1, serverHandler.sessions.size());
      Assert.assertEquals(1, server0.getChannels().size());
      Assert.assertEquals(true, serverSession0.isBound());
      Assert.assertEquals(SmppBindType.TRANSCEIVER, serverSession0.getBindType());
      Assert.assertEquals(SmppSession.Type.SERVER, serverSession0.getLocalType());
      Assert.assertEquals(SmppSession.Type.CLIENT, serverSession0.getRemoteType());

      // verify "requested" version is 3.5
      Assert.assertEquals((byte) 0x35, serverSession0.getConfiguration().getInterfaceVersion());
      // verify the session interface version is normalized to 3.4
      Assert.assertEquals(SmppConstants.VERSION_3_4, serverSession0.getInterfaceVersion());
      Assert.assertEquals(true, serverSession0.areOptionalParametersSupported());

      // verify client session version settings are correct
      Assert.assertEquals((byte) 0x35, session0.getConfiguration().getInterfaceVersion());
      Assert.assertEquals((byte) 0x34, session0.getInterfaceVersion());
      Assert.assertEquals(true, session0.areOptionalParametersSupported());

      // verify 1 optional parameter was included in bind response
      Assert.assertEquals(1, bindResponse.getOptionalParameterCount());
      Assert.assertEquals("cloudhopper", bindResponse.getSystemId());

      Tlv scInterfaceVersion =
          bindResponse.getOptionalParameter(SmppConstants.TAG_SC_INTERFACE_VERSION);
      Assert.assertNotNull(scInterfaceVersion);
      Assert.assertEquals(SmppConstants.VERSION_3_4, scInterfaceVersion.getValueAsByte());

      serverSession0.close();
      Thread.sleep(200);
      Assert.assertEquals(0, serverHandler.sessions.size());
      Assert.assertEquals(0, server0.getChannels().size());
      Assert.assertEquals(false, serverSession0.isBound());
    } finally {
      server0.destroy();
    }
  }