@Test
  public void testHeartbeat() throws IOException, ServletException {
    // Open connection
    AtmosphereRequest request =
        new AtmosphereRequest.Builder().pathInfo("/heartbeat").method("GET").build();

    request.header(X_ATMOSPHERE_TRANSPORT, WEBSOCKET_TRANSPORT);
    framework.doCometSupport(request, AtmosphereResponse.newInstance());

    // Check suspend
    final AtmosphereResource res = r.get();
    assertNotNull(res);

    // Send heartbeat
    request =
        new AtmosphereRequest.Builder()
            .pathInfo("/heartbeat")
            .method("GET")
            .body(Heartbeat.paddingData)
            .build();
    request.header(X_ATMOSPHERE_TRANSPORT, WEBSOCKET_TRANSPORT);
    request.setAttribute(HeartbeatInterceptor.INTERCEPTOR_ADDED, "");
    res.initialize(
        res.getAtmosphereConfig(),
        res.getBroadcaster(),
        request,
        AtmosphereResponse.newInstance(),
        framework.getAsyncSupport(),
        res.getAtmosphereHandler());
    request.setAttribute(FrameworkConfig.INJECTED_ATMOSPHERE_RESOURCE, res);
    framework.doCometSupport(request, AtmosphereResponse.newInstance());
    assertNotNull(message.get());
    assertEquals(message.get(), Heartbeat.paddingData);
  }
  @Test
  public void testSuspend() throws IOException, ServletException {

    AtmosphereRequest request =
        new AtmosphereRequest.Builder().pathInfo("/j").method("GET").build();
    request.header(X_ATMOSPHERE_TRANSPORT, LONG_POLLING_TRANSPORT);
    framework.doCometSupport(request, AtmosphereResponse.newInstance());
    assertNotNull(r.get());
  }
  @Test
  public void testPut() throws IOException, ServletException {

    AtmosphereRequest request =
        new AtmosphereRequest.Builder().pathInfo("/d").method("PUT").build();
    framework.doCometSupport(request, AtmosphereResponse.newInstance());
    assertNotNull(r.get());
    r.get().resume();
  }
 @Test
 public void testInputStreamMessage() throws IOException, ServletException {
   AtmosphereRequest request =
       new AtmosphereRequest.Builder().pathInfo("/inputStreamInjection").method("GET").build();
   framework.doCometSupport(request, AtmosphereResponse.newInstance());
   assertNotNull(r.get());
   r.get().resume();
   assertNotNull(message.get());
   assertEquals(message.get(), "message");
 }
 @Test
 public void createTest() {
   AtmosphereResource r =
       AtmosphereResourceFactory.getDefault()
           .create(
               mock(AtmosphereConfig.class),
               mock(Broadcaster.class),
               AtmosphereResponse.newInstance().request(AtmosphereRequest.create()),
               mock(AsyncSupport.class),
               mock(AtmosphereHandler.class));
   assertNotNull(r);
 }
  @Test
  public void testOverrideBroadcaster() throws IOException, ServletException {
    framework.setDefaultBroadcasterClassName(SimpleBroadcaster.class.getName());

    AtmosphereRequest request =
        new AtmosphereRequest.Builder().pathInfo("/override").method("GET").build();
    request.header(X_ATMOSPHERE_TRANSPORT, LONG_POLLING_TRANSPORT);
    framework.doCometSupport(request, AtmosphereResponse.newInstance());

    assertNotNull(r.get());
    assertEquals(r.get().getBroadcaster().getClass().getName(), SimpleBroadcaster.class.getName());
  }
  @Test
  public void testOnClose() throws IOException, ServletException {
    framework.addAtmosphereHandler(
        "/a",
        new AbstractReflectorAtmosphereHandler() {
          @Override
          public void onRequest(AtmosphereResource resource) throws IOException {}

          @Override
          public void destroy() {}
        });

    AtmosphereRequest request = new AtmosphereRequest.Builder().pathInfo("/a").build();

    final AtomicReference<Boolean> closed = new AtomicReference<Boolean>();

    final AtmosphereResourceEventListener listener =
        new AtmosphereResourceEventListenerAdapter() {
          @Override
          public void onClose(AtmosphereResourceEvent event) {
            closed.set(true);
          }
        };

    framework.interceptor(
        new AtmosphereInterceptor() {
          @Override
          public void configure(AtmosphereConfig config) {}

          @Override
          public Action inspect(AtmosphereResource r) {
            r.addEventListener(listener).suspend();
            try {
              r.getBroadcaster().broadcast("void").get();
            } catch (InterruptedException e) {
            } catch (ExecutionException e) {
            }
            return Action.CONTINUE;
          }

          @Override
          public void postInspect(AtmosphereResource r) {
            try {
              r.close();
            } catch (IOException e) {
              e.printStackTrace();
            }
          }
        });
    framework.doCometSupport(request, AtmosphereResponse.newInstance());
    assertTrue(closed.get());
  }
  @Test
  public void testPriority() throws IOException, ServletException {

    AtmosphereRequest request =
        new AtmosphereRequest.Builder().pathInfo("/priority").method("GET").build();
    request.header(X_ATMOSPHERE_TRANSPORT, LONG_POLLING_TRANSPORT);
    framework.doCometSupport(request, AtmosphereResponse.newInstance());
    assertEquals(
        framework.getAtmosphereHandlers().get("/priority").interceptors.getFirst().toString(),
        "XXX");

    assertNotNull(r.get());
  }
 @Test
 public void notFoundTest() {
   for (int i = 0; i < 10; i++) {
     BroadcasterFactory.getDefault().get(String.valueOf(i));
   }
   AtmosphereResource r =
       AtmosphereResourceFactory.getDefault()
           .create(
               mock(AtmosphereConfig.class),
               BroadcasterFactory.getDefault().lookup("1"),
               AtmosphereResponse.newInstance().request(AtmosphereRequest.create()),
               mock(AsyncSupport.class),
               mock(AtmosphereHandler.class));
   assertNotNull(r);
   assertNull(AtmosphereResourceFactory.getDefault().find(r.uuid()));
 }
  @Test
  public void findTest() {
    Broadcaster b1 = BroadcasterFactory.getDefault().get("b1");
    Broadcaster b2 = BroadcasterFactory.getDefault().get("b2");
    AtmosphereResource r =
        AtmosphereResourceFactory.getDefault()
            .create(
                mock(AtmosphereConfig.class),
                b1,
                AtmosphereResponse.newInstance().request(AtmosphereRequest.create()),
                mock(AsyncSupport.class),
                mock(AtmosphereHandler.class));
    assertNotNull(r);

    b2.addAtmosphereResource(r);

    assertNotNull(AtmosphereResourceFactory.getDefault().find(r.uuid()));
  }