package fr.insee.pogues.rest.test;

import javax.ws.rs.core.MediaType;

import org.apache.log4j.Logger;
import org.junit.Before;
import org.junit.Test;

import com.jayway.restassured.RestAssured;
import com.jayway.restassured.http.ContentType;

/**
 * Test Class used to test the REST Web Service PoguesUser, called by Pogues UI
 * 
 * @author I6VWID
 *
 */
public class TestPoguesUser {

	final static Logger logger = Logger.getLogger(TestPoguesUser.class);

	/**
	 * Setting up the RestAssured default URI
	 */
	@Before
	public void setUp() {
		logger.debug("Setting the RestAssured base Uri to http://localhost:8080 : for local tests");
		RestAssured.baseURI = "http://localhost:8080";
	}

	/**
	 * Dummy helloworld test, should return "Hello world"
	 */
	@Test
	public void helloworldTest() {
		logger.debug(
				"Dummy helloworld test : trying to reach /Pogues-BO/pogues/user/helloworld with Status = 200");
		RestAssured.expect().statusCode(200).contentType(ContentType.TEXT).when()
				.get("/Pogues-BO/pogues/user/helloworld");

	}
	
		
	/**
	 * getUserID test
	 */
	@Test
	public void getUserID() {
		logger.debug(
				"Trying to reach /Pogues-BO/pogues/user/id with Status = 200");
		RestAssured.expect().statusCode(200).contentType(MediaType.APPLICATION_JSON).when()
				.get("/Pogues-BO/pogues/user/id");

	}

	/**
	 * getPermissions test
	 */
	@Test
	public void getPermissions() {
		logger.debug(
				"Trying to reach /Pogues-BO/pogues/user/permissions with Status = 200");
		RestAssured.expect().statusCode(200).contentType(MediaType.APPLICATION_JSON).when()
				.get("/Pogues-BO/pogues/user/permissions");

	}

	

}

@@ -65,16 +65,126 @@
 aType;%0A%0A
+import com.jayway.restassured.authentication.FormAuthConfig;%0Aimport com.jayway.restassured.response.Response;%0A
 import o
@@ -232,16 +232,46 @@
 Before;%0A
+import org.junit.BeforeClass;%0A
 import o
@@ -593,16 +593,17 @@
 lass);%0A%0A
+%0A
 %09/**%0A%09 *
@@ -655,16 +655,21 @@
 %09@Before
+Class
 %0A%09public
@@ -665,24 +665,31 @@
 ass%0A%09public 
+static 
 void setUp()
@@ -835,17 +835,658 @@
 :8080%22;%0A
-%09
+        String sessionId;%0A        sessionId = RestAssured.expect().statusCode(200).log().all()%0A                .when().get(%22/%22).sessionId();%0A        RestAssured.expect().statusCode(302).log().all()%0A                .given().param(%22j_username%22, %22D5WQNO%22)%0A                .param(%22j_password%22, %22D5WQNO%22).cookie(%22JSESSIONID%22, sessionId)%0A                .post(%22j_security_check%22);%0A        sessionId = RestAssured.expect()%0A                .statusCode(404)%0A                .log().all()%0A                .given().cookie(%22JSESSIONID%22, sessionId)%0A                .when()%0A                .get().sessionId();%0A        RestAssured.sessionId = sessionId;%0A    
 %7D%0A%0A%09/**%0A
@@ -1783,34 +1783,24 @@
 %0A%09%09%09%09.get(%22/
-Pogues-BO/
 pogues/user/
@@ -2062,34 +2062,24 @@
 %0A%09%09%09%09.get(%22/
-Pogues-BO/
 pogues/user/
@@ -2247,34 +2247,40 @@
 Status = 200%22);%0A
-%09%09
+        
 RestAssured.expe
@@ -2287,92 +2287,145 @@
 ct()
-.statusCode(200).contentType(MediaType.APPLICATION_JSON).when()%0A%09%09%09%09.get(%22/Pogues-BO
+%0A                .statusCode(200)%0A                .contentType(MediaType.APPLICATION_JSON)%0A                .when()%0A                .get(%22
 /pog
@@ -2445,21 +2445,24 @@
 issions%22);%0A%0A
-%09
+    
 %7D%0A%0A%09%0A%0A%7D%0A

make test pass