|
| 1 | +package org.javaee8.sse.producer; |
| 2 | + |
| 3 | +import static org.jboss.shrinkwrap.api.ShrinkWrap.create; |
| 4 | + |
| 5 | +import java.io.IOException; |
| 6 | +import java.net.URL; |
| 7 | + |
| 8 | +import org.jboss.arquillian.container.test.api.Deployment; |
| 9 | +import org.jboss.arquillian.container.test.api.RunAsClient; |
| 10 | +import org.jboss.arquillian.junit.Arquillian; |
| 11 | +import org.jboss.arquillian.test.api.ArquillianResource; |
| 12 | +import org.jboss.shrinkwrap.api.spec.WebArchive; |
| 13 | +import org.junit.After; |
| 14 | +import org.junit.Before; |
| 15 | +import org.junit.Test; |
| 16 | +import org.junit.runner.RunWith; |
| 17 | + |
| 18 | +import javax.ws.rs.client.Client; |
| 19 | +import javax.ws.rs.client.ClientBuilder; |
| 20 | +import javax.ws.rs.client.WebTarget; |
| 21 | +import javax.ws.rs.core.Context; |
| 22 | +import javax.ws.rs.sse.SseEventSource; |
| 23 | + |
| 24 | +/** |
| 25 | + * @author Daniel Contreras |
| 26 | + */ |
| 27 | +//@RunWith(Arquillian.class) |
| 28 | +public class SseResourceTest { |
| 29 | +/* |
| 30 | + @ArquillianResource |
| 31 | + private URL base; |
| 32 | +
|
| 33 | + private Client sseClient; |
| 34 | + WebTarget target; |
| 35 | +
|
| 36 | + @Deployment |
| 37 | + public static WebArchive createDeployment() { |
| 38 | + return create(WebArchive.class) |
| 39 | + .addClass(SseResource.class); |
| 40 | + } |
| 41 | +
|
| 42 | + @Before |
| 43 | + public void setup() { |
| 44 | + System.out.println("01"); |
| 45 | + this.sseClient = ClientBuilder.newClient(); |
| 46 | + System.out.println("02"); |
| 47 | + } |
| 48 | +
|
| 49 | + @After |
| 50 | + public void teardown() { |
| 51 | +
|
| 52 | + } |
| 53 | +
|
| 54 | + @Test |
| 55 | + @RunAsClient |
| 56 | + public void testClient() throws IOException { |
| 57 | + System.out.println("Client"); |
| 58 | + System.out.println(base + "producer/register"); |
| 59 | + System.out.println(this.sseClient.getConfiguration().toString()); |
| 60 | + } |
| 61 | + |
| 62 | + @Test |
| 63 | + public void testServer() throws IOException { |
| 64 | + System.out.println("Server"); |
| 65 | + System.out.println(base + "producer/register"); |
| 66 | + //this.sseClient.target(base + "producer/register"); |
| 67 | + System.out.println(this.sseClient.getConfiguration().getProperties().toString()); |
| 68 | + System.out.println(this.sseClient.getConfiguration().getRuntimeType().toString()); |
| 69 | + System.out.println(this.sseClient.getConfiguration().getInstances().toArray().toString()); |
| 70 | + //this.sseClient.getHostnameVerifier(); |
| 71 | +
|
| 72 | + System.out.println(base + "producer/register"); |
| 73 | + WebTarget target = sseClient.target(base + "producer/register"); |
| 74 | + System.out.println("1"); |
| 75 | + try (SseEventSource source = SseEventSource.target(target).build()) { |
| 76 | + System.out.println("2"); |
| 77 | + source.register(System.out::println); |
| 78 | + System.out.println("3"); |
| 79 | + source.open(); |
| 80 | + System.out.println("5"); |
| 81 | + Thread.sleep(500); // Consume events for just 500 ms |
| 82 | +
|
| 83 | + } catch (Exception e) { |
| 84 | +
|
| 85 | + System.out.println("error!!!"); |
| 86 | + System.out.println(e.getMessage()); |
| 87 | +
|
| 88 | + } |
| 89 | +
|
| 90 | + } |
| 91 | +*/ |
| 92 | +} |
0 commit comments