package edu.cmu.sv.ws.ssnoc.test;

import static com.eclipsesource.restfuse.Assert.*;

import edu.cmu.sv.ws.ssnoc.common.logging.Log;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.runner.RunWith;

import com.eclipsesource.restfuse.Destination;
import com.eclipsesource.restfuse.HttpJUnitRunner;
import com.eclipsesource.restfuse.MediaType;
import com.eclipsesource.restfuse.Method;
import com.eclipsesource.restfuse.Response;
import com.eclipsesource.restfuse.annotation.Context;
import com.eclipsesource.restfuse.annotation.HttpTest;


@RunWith(HttpJUnitRunner.class)
public class UserServiceIT {
	@Rule
	public Destination destination = new Destination(this,
			"http://localhost:8080/ssnoc");

	@Context
    public Response response;
    //List Users
	@HttpTest(method = Method.GET, path = "/users")
	public void testUsersFound() {
		assertOk(response);
	}
    //Failed Authenticate
	@HttpTest(method = Method.POST, path = "/user/IAManInvalidUser/authenticate", type = MediaType.APPLICATION_JSON,
			content = "{\"userName\":\"IAManInvalidUser\",\"password\":\"SOMEPASSWORD\"}")
	public void testInvalidLogin() {
		assertNotFound(response);
		String messg = response.getBody();
        Log.debug(messg);
		Assert.assertEquals("Unauthorized User: IAManInvalidUser", messg);
	}
	
    //signup
    @HttpTest(method = Method.POST, path = "/user/signup", type = MediaType.APPLICATION_JSON,
            content = "{\"userName\":\"user1\",\"password\":\"user1password\"}")
    public void testUser1Signup() {
        //assertCreated(response);
    }

    //Success Authenticate
    @HttpTest(method = Method.POST, path = "/user/user1/authenticate", type = MediaType.APPLICATION_JSON,
            content = "{\"userName\":\"user1\",\"password\":\"user1password\"}")
    public void testUser1SuccessLogin() {
        assertOk(response);
    }

    //new status
    // Post a message on public wall from a user
    @HttpTest(method = Method.POST, path = "/status/user1", type = MediaType.APPLICATION_JSON,
            content = "{\"statusCode\":\"Red\",\"location\":\"User1location\"}")
    public void testUser1StatusUpdate() {
        assertCreated(response);
    }

    //List Status by users
    @HttpTest(method = Method.GET, path = "/statuscrumbs/user1")
    public void testUser1Statuscrumb() {
        assertOk(response);
        String messg = response.getBody();
        Log.debug(messg);
    }

    //post on the wall
    @HttpTest(method = Method.POST, path = "/message/user1",  type = MediaType.APPLICATION_JSON,
            content = "{\"content\":\"USER1PostsOnWall\",\"location\":\"User1location\"}")
    public void testUser1WallPost() {
        assertCreated(response);
        String messg = response.getBody();
        Log.debug(messg);
    }

    // Retrieve all messages posted on public wall
    // get msgs from the wall
    @HttpTest(method = Method.GET, path = "/messages/wall")
    public void testGetWallPost() {
        assertOk(response);
        String messg = response.getBody();
        Log.debug(messg);
    }
    
    // Signup user2
    @HttpTest(method = Method.POST, path = "/user/signup", type = MediaType.APPLICATION_JSON,
            content = "{\"userName\":\"user2\",\"password\":\"user2\"}")
    public void testUser2Signup() {
        String messg = response.getBody();
        Log.debug(messg);
        //assertCreated(response);
    }
    
    // Post on the wall by user2
    @HttpTest(method = Method.POST, path = "/message/user2",  type = MediaType.APPLICATION_JSON,
            content = "{\"content\":\"USER2PostsOnWall\",\"location\":\"User2location\"}")
    public void testUSer2WallPost() {
        assertCreated(response);
        String messg = response.getBody();
        Log.debug(messg);
    }
    
    // Send a chat message to another user
    //post a private message to user2 (user) by test (user)
    @HttpTest(method = Method.POST, path = "/message/user1/user2",  type = MediaType.APPLICATION_JSON,
            content = "{\"content\":\"PrivateMsgToUser2\",\"location\":\"User1location\"}")
    public void testUser1PrivateMsg() {
        assertCreated(response);
        String messg = response.getBody();
        Log.debug(messg);
    }
    
    // Retrieve all chat messages between two users
    // get message from user1 and user2
    @HttpTest(method = Method.GET, path = "/messages/user1/user2")
    public void testUser2GetMsgByOtherUser() {
        assertOk(response);
        String messg = response.getBody();
        Log.debug(messg);
    }

    // Set a new status for user2
    @HttpTest(method = Method.POST, path = "/status/user2", type = MediaType.APPLICATION_JSON,
            content = "{\"statusCode\":\"Red\",\"location\":\"User2location\"}")
    public void testUser2SetStatusUpdate() {
        assertCreated(response);
    }


}

@@ -698,12 +698,12 @@
 ost:
-8080
+1234
 /ssn

Update UserServiceIT.java