org.apache.commons.net.telnet.WindowSizeOptionHandler Java Examples

The following examples show how to use org.apache.commons.net.telnet.WindowSizeOptionHandler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TelnetHandlerTest.java    From aesh-readline with Apache License 2.0 6 votes vote down vote up
@Test
public void testAcceptNAWS() throws Exception {
  final AtomicReference<Boolean> serverValue = new AtomicReference<>();
  final AtomicReference<int[]> size = new AtomicReference<>();
  WindowSizeOptionHandler optionHandler = new WindowSizeOptionHandler(20, 10, false, false, true, false);
  testOptionValue(() -> new TelnetHandler() {
    @Override
    protected void onOpen(TelnetConnection conn) {
      conn.writeDoOption(Option.NAWS);
    }
    @Override
    protected void onNAWS(boolean naws) {
      serverValue.set(naws);
    }
    @Override
    protected void onSize(int width, int height) {
      size.set(new int[]{width, height});
      testComplete();
    }
  }, optionHandler);
  assertEquals(true, serverValue.get());
  assertEquals(true, optionHandler.getAcceptLocal());
  assertEquals(2, size.get().length);
  assertEquals(20, size.get()[0]);
  assertEquals(10, size.get()[1]);
}
 
Example #2
Source File: TelnetHandlerTest.java    From termd with Apache License 2.0 6 votes vote down vote up
@Test
public void testAcceptNAWS() throws Exception {
  final AtomicReference<Boolean> serverValue = new AtomicReference<>();
  final AtomicReference<int[]> size = new AtomicReference<>();
  WindowSizeOptionHandler optionHandler = new WindowSizeOptionHandler(20, 10, false, false, true, false);
  testOptionValue(() -> new TelnetHandler() {
    @Override
    protected void onOpen(TelnetConnection conn) {
      conn.writeDoOption(Option.NAWS);
    }
    @Override
    protected void onNAWS(boolean naws) {
      serverValue.set(naws);
    }
    @Override
    protected void onSize(int width, int height) {
      size.set(new int[]{width, height});
      testComplete();
    }
  }, optionHandler);
  assertEquals(true, serverValue.get());
  assertEquals(true, optionHandler.getAcceptLocal());
  assertEquals(2, size.get().length);
  assertEquals(20, size.get()[0]);
  assertEquals(10, size.get()[1]);
}
 
Example #3
Source File: TelnetHandlerTest.java    From termd with Apache License 2.0 5 votes vote down vote up
@Test
public void testRejectNAWS() throws Exception {
  final AtomicReference<Boolean> serverValue = new AtomicReference<Boolean>();
  WindowSizeOptionHandler optionHandler = new WindowSizeOptionHandler(20, 10, false, false, false, false);
  testOptionValue(new Supplier<TelnetHandler>() {
    @Override
    public TelnetHandler get() {
      return new TelnetHandler() {
        @Override
        protected void onOpen(TelnetConnection conn) {
          conn.writeDoOption(Option.NAWS);
        }
        @Override
        protected void onNAWS(boolean naws) {
          serverValue.set(naws);
          testComplete();
        }
        @Override
        protected void onSize(int width, int height) {
          super.onSize(width, height);
        }
      };
    }
  }, optionHandler);
  assertEquals(false, serverValue.get());
  assertEquals(false, optionHandler.getAcceptLocal());
}
 
Example #4
Source File: TelnetHandlerTest.java    From termd with Apache License 2.0 5 votes vote down vote up
@Test
public void testAcceptNAWS() throws Exception {
  final AtomicReference<Boolean> serverValue = new AtomicReference<Boolean>();
  final AtomicReference<int[]> size = new AtomicReference<int[]>();
  WindowSizeOptionHandler optionHandler = new WindowSizeOptionHandler(20, 10, false, false, true, false);
  testOptionValue(new Supplier<TelnetHandler>() {
    @Override
    public TelnetHandler get() {
      return new TelnetHandler() {
        @Override
        protected void onOpen(TelnetConnection conn) {
          conn.writeDoOption(Option.NAWS);
        }
        @Override
        protected void onNAWS(boolean naws) {
          serverValue.set(naws);
        }
        @Override
        protected void onSize(int width, int height) {
          size.set(new int[]{width, height});
          testComplete();
        }
      };
    }
  }, optionHandler);
  assertEquals(true, serverValue.get());
  assertEquals(true, optionHandler.getAcceptLocal());
  assertEquals(2, size.get().length);
  assertEquals(20, size.get()[0]);
  assertEquals(10, size.get()[1]);
}
 
Example #5
Source File: TelnetTermTest.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
@Test
public void testSizeHandler() throws Exception {
  final CountDownLatch latch1 = new CountDownLatch(1);
  final CountDownLatch latch2 = new CountDownLatch(1);
  server.start(() -> {
    final AtomicInteger count = new AtomicInteger();
    return new TelnetTtyConnection(false, false, StandardCharsets.UTF_8, conn -> {
      conn.setSizeHandler(size -> {
        switch (count.getAndIncrement()) {
          case 0:
            assertEquals(20, size.getWidth());
            assertEquals(10, size.getHeight());
            latch1.countDown();
            break;
          case 1:
            assertEquals(80, size.getWidth());
            assertEquals(24, size.getHeight());
            latch2.countDown();
            break;
          case 2:
            assertEquals(180, size.getWidth());
            assertEquals(160, size.getHeight());
            testComplete();
            break;
          default:
            fail("Was not expecting that");
        }
      });
    });
  });
  WindowSizeOptionHandler optionHandler = new WindowSizeOptionHandler(20, 10, false, false, true, false);
  client.setOptionHandler(optionHandler);
  client.connect("localhost", 4000);
  latch1.await(30, TimeUnit.SECONDS);
  client.writeDirectAndFlush(new byte[]{TelnetConnection.BYTE_IAC, TelnetConnection.BYTE_SB, 31, 0, 80, 0, 24, TelnetConnection.BYTE_IAC, TelnetConnection.BYTE_SE});
  latch2.await(30, TimeUnit.SECONDS);
  client.writeDirectAndFlush(new byte[]{TelnetConnection.BYTE_IAC, TelnetConnection.BYTE_SB, 31, 0, (byte) 180, 0, (byte) 160, TelnetConnection.BYTE_IAC, TelnetConnection.BYTE_SE});
  await();
}
 
Example #6
Source File: TelnetHandlerTest.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
@Test
public void testRejectNAWS() throws Exception {
  final AtomicReference<Boolean> serverValue = new AtomicReference<>();
  WindowSizeOptionHandler optionHandler = new WindowSizeOptionHandler(20, 10, false, false, false, false);
  testOptionValue(new Supplier<TelnetHandler>() {
    @Override
    public TelnetHandler get() {
      return new TelnetHandler() {
        @Override
        protected void onOpen(TelnetConnection conn) {
          conn.writeDoOption(Option.NAWS);
        }
        @Override
        protected void onNAWS(boolean naws) {
          serverValue.set(naws);
          testComplete();
        }
        @Override
        protected void onSize(int width, int height) {
          super.onSize(width, height);
        }
      };
    }
  }, optionHandler);
  assertEquals(false, serverValue.get());
  assertEquals(false, optionHandler.getAcceptLocal());
}
 
Example #7
Source File: TelnetTermServerTest.java    From vertx-shell with Apache License 2.0 5 votes vote down vote up
@Test
public void testWindowSize(TestContext context) throws Exception {
  Async async = context.async();
  startTelnet(context, term -> {
    context.assertEquals(-1, term.width());
    context.assertEquals(-1, term.height());
    term.resizehandler(v -> {
      context.assertEquals(10, term.width());
      context.assertEquals(20, term.height());
      async.complete();
    });
  });
  client.addOptionHandler(new WindowSizeOptionHandler(10, 20, false, false, true, false));
  client.connect("localhost", server.actualPort());
}
 
Example #8
Source File: TelnetTermServerTest.java    From vertx-shell with Apache License 2.0 5 votes vote down vote up
@Test
public void testOutBinaryTrue(TestContext context) throws Exception {
  startTelnet(context, new TelnetTermOptions().setOutBinary(true), term -> {
    term.write("\u20AC");
  });
  client.addOptionHandler(new WindowSizeOptionHandler(10, 20, false, false, true, false));
  client.connect("localhost", server.actualPort());
  InputStream in = client.getInputStream();
  context.assertEquals(226, in.read());
  context.assertEquals(130, in.read());
  context.assertEquals(172, in.read());
}
 
Example #9
Source File: TelnetTermServerTest.java    From vertx-shell with Apache License 2.0 5 votes vote down vote up
@Test
public void testOutBinaryFalse(TestContext context) throws Exception {
  byte[] expected = StandardCharsets.US_ASCII.encode("€").array();
  startTelnet(context, new TelnetTermOptions().setOutBinary(false), term -> {
    term.write("\u20AC");
  });
  client.addOptionHandler(new WindowSizeOptionHandler(10, 20, false, false, true, false));
  client.connect("localhost", server.actualPort());
  InputStream in = client.getInputStream();
  for (int i = 0;i < expected.length;i++) {
    context.assertEquals((int)expected[i], in.read());
  }
}
 
Example #10
Source File: TelnetTermTest.java    From termd with Apache License 2.0 5 votes vote down vote up
@Test
public void testSizeHandler() throws Exception {
  final CountDownLatch latch1 = new CountDownLatch(1);
  final CountDownLatch latch2 = new CountDownLatch(1);
  server.start(() -> {
    final AtomicInteger count = new AtomicInteger();
    return new TelnetTtyConnection(false, false, StandardCharsets.UTF_8, conn -> {
      conn.setSizeHandler(size -> {
        switch (count.getAndIncrement()) {
          case 0:
            assertEquals(20, size.x());
            assertEquals(10, size.y());
            latch1.countDown();
            break;
          case 1:
            assertEquals(80, size.x());
            assertEquals(24, size.y());
            latch2.countDown();
            break;
          case 2:
            assertEquals(180, size.x());
            assertEquals(160, size.y());
            testComplete();
            break;
          default:
            fail("Was not expecting that");
        }
      });
    });
  });
  WindowSizeOptionHandler optionHandler = new WindowSizeOptionHandler(20, 10, false, false, true, false);
  client.setOptionHandler(optionHandler);
  client.connect("localhost", 4000);
  latch1.await(30, TimeUnit.SECONDS);
  client.writeDirectAndFlush(new byte[]{TelnetConnection.BYTE_IAC, TelnetConnection.BYTE_SB, 31, 0, 80, 0, 24, TelnetConnection.BYTE_IAC, TelnetConnection.BYTE_SE});
  latch2.await(30, TimeUnit.SECONDS);
  client.writeDirectAndFlush(new byte[]{TelnetConnection.BYTE_IAC, TelnetConnection.BYTE_SB, 31, 0, (byte) 180, 0, (byte) 160, TelnetConnection.BYTE_IAC, TelnetConnection.BYTE_SE});
  await();
}
 
Example #11
Source File: TelnetHandlerTest.java    From termd with Apache License 2.0 5 votes vote down vote up
@Test
public void testRejectNAWS() throws Exception {
  final AtomicReference<Boolean> serverValue = new AtomicReference<>();
  WindowSizeOptionHandler optionHandler = new WindowSizeOptionHandler(20, 10, false, false, false, false);
  testOptionValue(new Supplier<TelnetHandler>() {
    @Override
    public TelnetHandler get() {
      return new TelnetHandler() {
        @Override
        protected void onOpen(TelnetConnection conn) {
          conn.writeDoOption(Option.NAWS);
        }
        @Override
        protected void onNAWS(boolean naws) {
          serverValue.set(naws);
          testComplete();
        }
        @Override
        protected void onSize(int width, int height) {
          super.onSize(width, height);
        }
      };
    }
  }, optionHandler);
  assertEquals(false, serverValue.get());
  assertEquals(false, optionHandler.getAcceptLocal());
}
 
Example #12
Source File: TelnetTtyTestBase.java    From termd with Apache License 2.0 4 votes vote down vote up
@Override
public void testSize() throws Exception {
  wsHandler = new WindowSizeOptionHandler(80, 24, false, false, true, true);
  client.setOptionHandler(wsHandler);
  super.testSize();
}
 
Example #13
Source File: TelnetTermTest.java    From termd with Apache License 2.0 4 votes vote down vote up
@Test
public void testSizeHandler() throws Exception {
  final CountDownLatch latch1 = new CountDownLatch(1);
  final CountDownLatch latch2 = new CountDownLatch(1);
  server.start(new Supplier<TelnetHandler>() {
    @Override
    public TelnetHandler get() {
      final AtomicInteger count = new AtomicInteger();
      return new TelnetTtyConnection(false, false, StandardCharsets.UTF_8, new Consumer<TtyConnection>() {
        @Override
        public void accept(TtyConnection conn) {
          conn.setSizeHandler(new Consumer<Vector>() {
            @Override
            public void accept(Vector size) {
              switch (count.getAndIncrement()) {
                case 0:
                  assertEquals(20, size.x());
                  assertEquals(10, size.y());
                  latch1.countDown();
                  break;
                case 1:
                  assertEquals(80, size.x());
                  assertEquals(24, size.y());
                  latch2.countDown();
                  break;
                case 2:
                  assertEquals(180, size.x());
                  assertEquals(160, size.y());
                  testComplete();
                  break;
                default:
                  fail("Was not expecting that");
              }
            }
          });
        }
      });
    }
  });
  WindowSizeOptionHandler optionHandler = new WindowSizeOptionHandler(20, 10, false, false, true, false);
  client.setOptionHandler(optionHandler);
  client.connect("localhost", 4000);
  latch1.await(30, TimeUnit.SECONDS);
  client.writeDirectAndFlush(new byte[]{TelnetConnection.BYTE_IAC, TelnetConnection.BYTE_SB, 31, 0, 80, 0, 24, TelnetConnection.BYTE_IAC, TelnetConnection.BYTE_SE});
  latch2.await(30, TimeUnit.SECONDS);
  client.writeDirectAndFlush(new byte[]{TelnetConnection.BYTE_IAC, TelnetConnection.BYTE_SB, 31, 0, (byte) 180, 0, (byte) 160, TelnetConnection.BYTE_IAC, TelnetConnection.BYTE_SE});
  await();
}
 
Example #14
Source File: TelnetTtyTestBase.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
@Override
public void testSize() throws Exception {
  wsHandler = new WindowSizeOptionHandler(80, 24, false, false, true, true);
  client.setOptionHandler(wsHandler);
  super.testSize();
}
 
Example #15
Source File: TelnetTtyTestBase.java    From termd with Apache License 2.0 4 votes vote down vote up
@Override
public void testSize() throws Exception {
  wsHandler = new WindowSizeOptionHandler(80, 24, false, false, true, true);
  client.setOptionHandler(wsHandler);
  super.testSize();
}