Skip to content
This repository has been archived by the owner on May 28, 2019. It is now read-only.

Commit

Permalink
Fixes #30 : using awaitility lib in order to wait until call
Browse files Browse the repository at this point in the history
  • Loading branch information
mgreau committed Mar 9, 2014
1 parent aad6702 commit c12822c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<asciidoctor.version>0.1.4</asciidoctor.version>
<!-- Target JavaEE 7 app server -->
<org.wildfly.version>8.0.0.Beta1</org.wildfly.version>
<org.wildfly.plugins.version>1.0.0.Beta1</org.wildfly.plugins.version>
<org.wildfly.plugins.version>1.0.1.Final</org.wildfly.plugins.version>

<!-- Tests -->
<org.jboss.arquillian.version>1.1.2.Final</org.jboss.arquillian.version>
Expand Down Expand Up @@ -232,6 +232,12 @@
<version>${undertow.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.awaitility</groupId>
<artifactId>awaitility</artifactId>
<version>1.3.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.mgreau.wwsmad.websocket;

import static com.jayway.awaitility.Awaitility.await;
import static com.jayway.awaitility.Awaitility.to;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
Expand Down Expand Up @@ -88,16 +92,13 @@ public void testNotificationWhenBecameAWriter() throws URISyntaxException,
+ writer + "\":\"" + writer + "\"}}}";

// notifOnOpen - notifWhenSend Adoc - output
MyBasicEndpointClient.latch = new CountDownLatch(5);

MyBasicEndpointClient endpoint = new MyBasicEndpointClient();
Session session = connectToServer(MyBasicEndpointClient.class, ADOC_URL
+ ADOC_ID);
assertNotNull(session);

session.getBasicRemote().sendText(data);
assertTrue("error on waiting...", MyBasicEndpointClient.latch.await(5, TimeUnit.SECONDS));
assertEquals("JSON not equals", JSONNotificationWhenBecameAWriter,
MyBasicEndpointClient.notificationMessage);
await().untilCall(to(endpoint).getNotificationMessage(), is(equalTo(JSONNotificationWhenBecameAWriter)));
}

/**
Expand All @@ -123,7 +124,7 @@ public Session connectToServer(Class<?> endpoint, String uriPart)
return container.connectToServer(endpoint, uri);
}

private String data = "{\"type\":\"adoc-for-html5\",\"source\":\"= Hello Test\\nDoc Writer <doc@example.com>\\nv1.0, 2013-11-11\\n:toc:\\n:numbered:\\n:source-highlighter: coderay\\n\\nAn introduction to http://asciidoc.orgdf[AsciiDoc].\\n\\n\\n\",\"writer\":\"@mgreau\"}";
private String data = "{\"type\":\"adoc-for-html5\",\"source\":\"Hello Test\",\"writer\":\"@mgreau\"}";

private String getNotificationOnOpenConnection(String nb){
return "{\"type\":\"notification\",\"adocId\":\""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,18 @@ public void processMessage(String message) {
latch.countDown();
if (message.contains("type\":\"output"))
outputMessage = message;
else if (message.contains("type\":\"adoc"))
else if (message.contains("type\":\"adoc-for-html5"))
adocMessage = message;
else
notificationMessage = message;
System.out.println("Message received: " + message.toString());

}

public String getNotificationMessage(){
return notificationMessage;
}

@OnError
public void onError(Throwable t) {
t.printStackTrace();
Expand Down

0 comments on commit c12822c

Please sign in to comment.