Search in sources :

Example 21 with AtmosphereRequest

use of org.atmosphere.runtime.AtmosphereRequest in project atmosphere by Atmosphere.

the class EncoderDecoderTest method testEncoder.

@Test
public void testEncoder() throws IOException, ServletException, InterruptedException {
    AtmosphereRequest request = new AtmosphereRequestImpl.Builder().pathInfo("/h").method("GET").build();
    AtmosphereResponse response = AtmosphereResponseImpl.newInstance();
    final AtomicReference<String> ref = new AtomicReference();
    response.asyncIOWriter(new AsyncIOWriterAdapter() {

        @Override
        public AsyncIOWriter write(AtmosphereResponse r, byte[] data) throws IOException {
            ref.set(new String(data));
            return this;
        }
    });
    framework.doCometSupport(request, response);
    assertNotNull(r.get());
    latch.get().await(5, TimeUnit.SECONDS);
    r.get().resume();
    assertNotNull(message.get());
    assertEquals(message.get(), "message");
    assertEquals(ref.get(), "message-yo!");
}
Also used : AtmosphereRequestImpl(org.atmosphere.runtime.AtmosphereRequestImpl) AtmosphereResponse(org.atmosphere.runtime.AtmosphereResponse) AtmosphereRequest(org.atmosphere.runtime.AtmosphereRequest) AtomicReference(java.util.concurrent.atomic.AtomicReference) AsyncIOWriterAdapter(org.atmosphere.runtime.AsyncIOWriterAdapter) AsyncIOWriter(org.atmosphere.runtime.AsyncIOWriter) IOException(java.io.IOException) Test(org.testng.annotations.Test)

Example 22 with AtmosphereRequest

use of org.atmosphere.runtime.AtmosphereRequest in project atmosphere by Atmosphere.

the class ManagedAtmosphereHandlerTest method testInjectAnnotation.

@Test
public void testInjectAnnotation() throws IOException, ServletException {
    AtmosphereRequest request = new AtmosphereRequestImpl.Builder().pathInfo("/injectAnnotation").method("GET").build();
    framework.doCometSupport(request, AtmosphereResponseImpl.newInstance());
    assertNotNull(r.get());
    r.get().resume();
    assertNotNull(message.get());
    assertEquals(message.get(), framework.metaBroadcaster().toString());
}
Also used : AtmosphereRequestImpl(org.atmosphere.runtime.AtmosphereRequestImpl) AtmosphereRequest(org.atmosphere.runtime.AtmosphereRequest) Test(org.testng.annotations.Test)

Example 23 with AtmosphereRequest

use of org.atmosphere.runtime.AtmosphereRequest in project atmosphere by Atmosphere.

the class ManagedAtmosphereHandlerTest method testPost.

@Test
public void testPost() throws IOException, ServletException {
    AtmosphereRequest request = new AtmosphereRequestImpl.Builder().pathInfo("/b").method("POST").body("test").build();
    framework.doCometSupport(request, AtmosphereResponseImpl.newInstance());
    assertNotNull(r.get());
    r.get().resume();
}
Also used : AtmosphereRequest(org.atmosphere.runtime.AtmosphereRequest) Test(org.testng.annotations.Test)

Example 24 with AtmosphereRequest

use of org.atmosphere.runtime.AtmosphereRequest in project atmosphere by Atmosphere.

the class ManagedAtmosphereHandlerTest method testSuspend.

@Test
public void testSuspend() throws IOException, ServletException {
    AtmosphereRequest request = new AtmosphereRequestImpl.Builder().pathInfo("/j").method("GET").build();
    request.header(X_ATMOSPHERE_TRANSPORT, LONG_POLLING_TRANSPORT);
    framework.doCometSupport(request, AtmosphereResponseImpl.newInstance());
    assertNotNull(r.get());
}
Also used : AtmosphereRequestImpl(org.atmosphere.runtime.AtmosphereRequestImpl) AtmosphereRequest(org.atmosphere.runtime.AtmosphereRequest) Test(org.testng.annotations.Test)

Example 25 with AtmosphereRequest

use of org.atmosphere.runtime.AtmosphereRequest in project atmosphere by Atmosphere.

the class ManagedAtmosphereHandlerTest method testPut.

@Test
public void testPut() throws IOException, ServletException {
    AtmosphereRequest request = new AtmosphereRequestImpl.Builder().pathInfo("/d").method("PUT").build();
    framework.doCometSupport(request, AtmosphereResponseImpl.newInstance());
    assertNotNull(r.get());
    r.get().resume();
}
Also used : AtmosphereRequestImpl(org.atmosphere.runtime.AtmosphereRequestImpl) AtmosphereRequest(org.atmosphere.runtime.AtmosphereRequest) Test(org.testng.annotations.Test)

Aggregations

AtmosphereRequest (org.atmosphere.runtime.AtmosphereRequest)76 Test (org.testng.annotations.Test)39 AtmosphereRequestImpl (org.atmosphere.runtime.AtmosphereRequestImpl)38 IOException (java.io.IOException)23 AtmosphereResourceImpl (org.atmosphere.runtime.AtmosphereResourceImpl)20 AtmosphereResponse (org.atmosphere.runtime.AtmosphereResponse)18 ServletException (javax.servlet.ServletException)10 AsynchronousProcessor (org.atmosphere.runtime.AsynchronousProcessor)8 AtmosphereFramework (org.atmosphere.runtime.AtmosphereFramework)7 AtmosphereResource (org.atmosphere.runtime.AtmosphereResource)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 AsyncIOWriter (org.atmosphere.runtime.AsyncIOWriter)6 SimpleBroadcaster (org.atmosphere.util.SimpleBroadcaster)6 BeforeMethod (org.testng.annotations.BeforeMethod)6 ArrayList (java.util.ArrayList)5 AtmosphereInterceptorWriter (org.atmosphere.runtime.AtmosphereInterceptorWriter)5 AtmosphereResourceEvent (org.atmosphere.runtime.AtmosphereResourceEvent)5 Reader (java.io.Reader)4 Enumeration (java.util.Enumeration)4 ServletConfig (javax.servlet.ServletConfig)4