Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

changing rest urls to accomodate sessions

  • Loading branch information...
commit 9b84e2eb7a4467e9ce5f259a704d7fb557195753 1 parent 3d35cb5
jchoate authored
View
29 src/main/java/com/agile_coder/poker/server/rest/SessionRequestHandler.java
@@ -0,0 +1,29 @@
+/*
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ *
+ * Copyright @2011 the original author or authors.
+ */
+package com.agile_coder.poker.server.rest;
+
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+
+import com.agile_coder.poker.server.SessionManager;
+
+@Path("/")
+public class SessionRequestHandler {
+
+ @POST
+ public String createSession() {
+ int id = SessionManager.createSession();
+ return "{session: " + id + "}";
+ }
+}
View
3  src/main/java/com/agile_coder/poker/server/rest/ViewRequestHandler.java
@@ -23,7 +23,7 @@
import com.agile_coder.poker.server.model.Session;
-@Path("/")
+@Path("/status")
public class ViewRequestHandler {
@GET
@@ -38,4 +38,5 @@ public void resetSession() {
Session session = Session.getInstance();
session.reset();
}
+
}
View
20 src/main/java/com/agile_coder/poker/server/stories/steps/BaseSteps.java
@@ -17,10 +17,13 @@
import java.io.IOException;
+import net.sf.json.JSONObject;
+
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.PutMethod;
import org.jbehave.core.annotations.BeforeScenario;
@@ -67,6 +70,21 @@ protected void stopServer() {
while (server.isAlive()) {}
}
+ protected int createSession() throws IOException {
+ String createUrl = BASE_URL;
+ HttpClient client = new HttpClient();
+ PostMethod post = new PostMethod(createUrl);
+ String response;
+ try {
+ executeMethod(client, post);
+ response = post.getResponseBodyAsString();
+ } finally {
+ post.releaseConnection();
+ }
+ JSONObject obj = JSONObject.fromObject(response);
+ return obj.getInt("session");
+ }
+
protected int submitEstimate(String name, String vote) throws IOException {
String VOTE_URL = BASE_URL + "/" + name + "/" + vote;
HttpClient client = new HttpClient();
@@ -76,7 +94,7 @@ protected int submitEstimate(String name, String vote) throws IOException {
protected String getStatus() throws IOException {
HttpClient client = new HttpClient();
- GetMethod get = new GetMethod(BASE_URL);
+ GetMethod get = new GetMethod(BASE_URL + "/status");
int result;
String response;
try {
View
2  src/main/java/com/agile_coder/poker/server/stories/steps/ResetEstimatesSteps.java
@@ -38,7 +38,7 @@ public void reveal() throws IOException {
@When("I reset the estimates")
public void reset() throws IOException {
HttpClient client = new HttpClient();
- DeleteMethod delete = new DeleteMethod(BASE_URL);
+ DeleteMethod delete = new DeleteMethod(BASE_URL + "/status");
client.executeMethod(delete);
assertEquals(HttpStatus.SC_NO_CONTENT, delete.getStatusCode());
}
View
1  src/main/java/com/agile_coder/poker/server/stories/steps/SubmitStoryPointEstimateSteps.java
@@ -40,6 +40,7 @@ public void setupSession() throws IOException {
@When("I submit my estimate")
public void sendEstimate() throws IOException {
try {
+ // int sessionId = createSession();
result = submitEstimate(USER_NAME, "13");
} finally {
stopServer();
Please sign in to comment.
Something went wrong with that request. Please try again.