Skip to content

Commit 5c19bd5

Browse files
ThreaTThreaT
authored andcommitted
Added acceptance tests prototype. Requires code review and bug fixing.
1 parent f431e4b commit 5c19bd5

File tree

4 files changed

+249
-28
lines changed

4 files changed

+249
-28
lines changed

‎pom.xml‎

Lines changed: 54 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<properties>
2222
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2323
<java.version>1.6</java.version>
24+
<cucumber.version>1.0.0.RC24</cucumber.version>
2425
</properties>
2526
<build>
2627
<plugins>
@@ -61,6 +62,28 @@
6162
</plugin>
6263
</plugins>
6364
</build>
65+
<dependencies>
66+
<!-- JUnit -->
67+
<dependency>
68+
<groupId>junit</groupId>
69+
<artifactId>junit</artifactId>
70+
<version>4.8.2</version>
71+
<scope>test</scope>
72+
</dependency>
73+
<!-- Cucumber -->
74+
<dependency>
75+
<groupId>info.cukes</groupId>
76+
<artifactId>cucumber-junit</artifactId>
77+
<version>1.0.0</version>
78+
<scope>test</scope>
79+
</dependency>
80+
<dependency>
81+
<groupId>info.cukes</groupId>
82+
<artifactId>cucumber-java</artifactId>
83+
<version>${cucumber.version}</version>
84+
<scope>test</scope>
85+
</dependency>
86+
</dependencies>
6487
<developers>
6588
<developer>
6689
<id>TooTallNate</id>
@@ -88,32 +111,35 @@
88111
</license>
89112
</licenses>
90113
<profiles>
91-
<profile>
92-
<id>release-sign-artifacts</id>
93-
<activation>
94-
<property><name>performRelease</name><value>true</value></property>
95-
</activation>
96-
<build>
97-
<plugins>
98-
<plugin>
99-
<groupId>org.apache.maven.plugins</groupId>
100-
<artifactId>maven-gpg-plugin</artifactId>
101-
<version>1.1</version>
102-
<executions>
103-
<execution>
104-
<id>sign-artifacts</id>
105-
<phase>verify</phase>
106-
<goals>
107-
<goal>sign</goal>
108-
</goals>
109-
</execution>
110-
</executions>
111-
<configuration>
112-
<keyname>[email protected]</keyname>
113-
</configuration>
114-
</plugin>
115-
</plugins>
116-
</build>
117-
</profile>
114+
<profile>
115+
<id>release-sign-artifacts</id>
116+
<activation>
117+
<property>
118+
<name>performRelease</name>
119+
<value>true</value>
120+
</property>
121+
</activation>
122+
<build>
123+
<plugins>
124+
<plugin>
125+
<groupId>org.apache.maven.plugins</groupId>
126+
<artifactId>maven-gpg-plugin</artifactId>
127+
<version>1.1</version>
128+
<executions>
129+
<execution>
130+
<id>sign-artifacts</id>
131+
<phase>verify</phase>
132+
<goals>
133+
<goal>sign</goal>
134+
</goals>
135+
</execution>
136+
</executions>
137+
<configuration>
138+
<keyname>[email protected]</keyname>
139+
</configuration>
140+
</plugin>
141+
</plugins>
142+
</build>
143+
</profile>
118144
</profiles>
119-
</project>
145+
</project>
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
packageorg.java_websocket;
2+
3+
importcucumber.annotation.en.Given;
4+
importcucumber.annotation.en.Then;
5+
importcucumber.annotation.en.When;
6+
importjava.net.InetSocketAddress;
7+
importjava.net.URI;
8+
importjava.net.UnknownHostException;
9+
importjava.util.Collections;
10+
importorg.java_websocket.client.WebSocketClient;
11+
importorg.java_websocket.drafts.Draft;
12+
importorg.java_websocket.drafts.Draft_17;
13+
importorg.java_websocket.handshake.ClientHandshake;
14+
importorg.java_websocket.handshake.ServerHandshake;
15+
importorg.java_websocket.server.WebSocketServer;
16+
importstaticorg.junit.Assert.assertTrue;
17+
18+
publicclassAutobahnClientScenario{
19+
20+
privateclassAutobahnServerextendsWebSocketServer{
21+
22+
publicAutobahnServer(intport, Draftd) throwsUnknownHostException{
23+
super(newInetSocketAddress(port), Collections.singletonList(d));
24+
}
25+
26+
@Override
27+
publicvoidonOpen(WebSocketconn, ClientHandshakehandshake){
28+
thrownewUnsupportedOperationException("Not supported yet.");
29+
}
30+
31+
@Override
32+
publicvoidonClose(WebSocketconn, intcode, Stringreason, booleanremote){
33+
thrownewUnsupportedOperationException("Not supported yet.");
34+
}
35+
36+
@Override
37+
publicvoidonMessage(WebSocketconn, Stringmessage){
38+
thrownewUnsupportedOperationException("Not supported yet.");
39+
}
40+
41+
@Override
42+
publicvoidonError(WebSocketconn, Exceptionex){
43+
thrownewUnsupportedOperationException("Not supported yet.");
44+
}
45+
46+
}
47+
48+
privateclassAutobahnClientextendsWebSocketClient{
49+
50+
publicAutobahnClient(Draftdraft, URIuri){
51+
super(uri, draft);
52+
}
53+
54+
@Override
55+
publicvoidonOpen(ServerHandshakehandshakedata){
56+
thrownewUnsupportedOperationException("Not supported yet.");
57+
}
58+
59+
@Override
60+
publicvoidonMessage(Stringmessage){
61+
thrownewUnsupportedOperationException("Not supported yet.");
62+
}
63+
64+
@Override
65+
publicvoidonClose(intcode, Stringreason, booleanremote){
66+
thrownewUnsupportedOperationException("Not supported yet.");
67+
}
68+
69+
@Override
70+
publicvoidonError(Exceptionex){
71+
thrownewUnsupportedOperationException("Not supported yet.");
72+
}
73+
}
74+
privateStringprotocol;
75+
privateStringhost;
76+
privateIntegerport;
77+
privateStringquery;
78+
privateDraftdraft;
79+
80+
@Given("^the Autobahn Server is running using Draft_(\\d+) on port (\\d+)$")
81+
publicvoidstartAutobahnServer() throwsUnknownHostException{
82+
newAutobahnServer(9003, newDraft_17()).start();
83+
}
84+
85+
@Given("^protocol is ws://$")
86+
publicvoidcreateProtocol(Stringprotocol){
87+
this.protocol = protocol;
88+
}
89+
90+
@Given("^the host is localhost:$")
91+
publicvoidcreateHost(Stringhost){
92+
this.host = host;
93+
}
94+
95+
@Given("^the port is (\\d*)$")
96+
publicvoidcreatePort(Integerport){
97+
this.port = port;
98+
}
99+
100+
@Given("^the query string is case=(\\d+)&agent=tootallnate/websocket$")
101+
publicvoidcreateQuery(Stringquery){
102+
this.query = query;
103+
}
104+
105+
@Given("^the draft is Draft_17")
106+
publicvoidcreateDraft(Draft_17draft_17){
107+
this.draft = draft_17;
108+
}
109+
110+
@When("^the client connects to the server")
111+
publicvoidconnectToServer(){
112+
AutobahnClientautobahnClient = newAutobahnClient(this.draft, URI.create(this.protocol + this.host + this.port + this.query));
113+
Threadthread = newThread(autobahnClient);
114+
thread.start();
115+
}
116+
117+
@Then("^the server response should contain (\\w*)$")
118+
publicvoidcheckMethod(Stringmethod){
119+
assertTrue(method.contains("GET"));
120+
}
121+
122+
@Then("^the response should contain case=(\\d+)&agent=tootallnate/websocket$")
123+
publicvoidcheckQuery(Stringquery){
124+
assertTrue(query.contains(this.query));
125+
}
126+
127+
@Then("^the response should contain HTTP/(\\d+).(\\d+)$")
128+
publicvoidcheckHttpVersion(Stringhttp_version){
129+
assertTrue(http_version.contains("HTTP/1.1"));
130+
}
131+
132+
@Then("^the response should contain Connection: Upgrade$")
133+
publicvoidcheckHandshake(Stringhandshake){
134+
assertTrue(handshake.contains("Connection: Upgrade"));
135+
}
136+
137+
@Then("^the response should contain localhost:$")
138+
publicvoidcheckHost(Stringhost){
139+
assertTrue(host.contains(this.host));
140+
}
141+
142+
@Then("^the response should contain Sec-WebSocket-Key:$")
143+
publicvoidcheckWebSocketKey(StringwebsocketKey){
144+
assertTrue(websocketKey.contains("Sec-WebSocket-Key:"));
145+
}
146+
147+
@Then("^the response should contain Sec-WebSocket-Version:$")
148+
publicvoidcheckWebSocketVersion(StringwebsocketVersion){
149+
assertTrue(websocketVersion.contains("Sec-WebSocket-Version:"));
150+
}
151+
@Then("^the response should contain Upgrade: websocket$")
152+
publicvoidcheckUpgradedProtocol(StringupgradedProtocol){
153+
assertTrue(upgradedProtocol.contains("Upgrade: websocket"));
154+
}
155+
156+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
packageorg.java_websocket;
2+
3+
importorg.junit.runner.RunWith;
4+
5+
importcucumber.junit.Cucumber;
6+
7+
@RunWith(Cucumber.class)
8+
publicclassAutobahnClientTest{
9+
10+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Feature: Client connects using Draft 17
2+
As an autobahn client
3+
I want to connect to a websocket server using draft 17
4+
So that I can send and receive messages
5+
6+
Scenario Outline: Client connection parameters are valid
7+
Given the Autobahn Server is running using Draft_17 on port 9003
8+
And protocol is <protocol>
9+
And the host is <host>
10+
And the port is <port>
11+
And the query string is <query>
12+
And the draft is Draft_17
13+
When the client connects to the server
14+
Then the server response should contain <method>
15+
And the response should contain <query>
16+
And the response should contain <http_version>
17+
And the response should contain <handshake>
18+
And the response should contain <host>
19+
And the response should contain <websocket_key>
20+
And the response should contain <websocket_version>
21+
And the response should contain <upgraded_protocol>
22+
23+
Examples:
24+
|protocol|host |port|query |method |http_version|handshake |websocket_key |websocket_version |upgraded_protocol |
25+
|ws:// |localhost:|9001|case=1&agent=tootallnate/websocket|GET |HTTP/1.1 |Connection: Upgrade|Sec-WebSocket-Key:|Sec-WebSocket-Version:|Upgrade: websocket|
26+
27+
28+
29+

0 commit comments

Comments
(0)