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

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.sql.Timestamp;
import java.util.List;

import javax.ws.rs.core.Response;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import edu.cmu.sv.ws.ssnoc.dto.Message;
import edu.cmu.sv.ws.ssnoc.dto.User;
import edu.cmu.sv.ws.ssnoc.rest.MessageService;
import edu.cmu.sv.ws.ssnoc.rest.MessagesService;
import edu.cmu.sv.ws.ssnoc.rest.UserService;

public class WallMessageTest {

	@Before
	public void setUp() throws Exception {
		User user = new User();
		user.setUserName("foo");
		user.setPassword("1234");
		
		UserService userService = new UserService();
		userService.addUser(user);
		
		//Message msg = new Message();
		
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testSendMessageToPublicWall() {
		Message msg = new Message();
		msg.setAuthor("foo");
		Timestamp postedAt = new Timestamp(1234);
		msg.setPostedAt(postedAt);
		msg.setContent("test test lloyd owes a me a beer");
		
		MessageService msgService = new MessageService();
		Response response = msgService.addWallMessage("foo", msg);
		assertEquals(((Message)response.getEntity()).getContent(), "test test lloyd owes a me a beer");
	}

	@Test
	public void testGetAllMessagesFromPublicWall() {
		Message msg = new Message();
		MessagesService msgsService = new MessagesService();
		MessageService msgService = new MessageService();
		System.out.println("t");
		//Add atleast 1 message
		msg.setAuthor("foo");
		Timestamp postedAt = new Timestamp(1234);
		msg.setPostedAt(postedAt);
		msg.setContent("test test lloyd owes a me a beer");
		
		Response response = msgService.addWallMessage("foo", msg);
		
		List<Message> messages = (List<Message>) msgsService.loadWallMessages();
		assertTrue(messages.size() != 0);
		for (Message m : messages) {
			assertTrue(m instanceof Message);
		}
	}
}

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

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import java.sql.Timestamp;
import java.util.List;

import javax.ws.rs.core.Response;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import edu.cmu.sv.ws.ssnoc.dto.Message;
import edu.cmu.sv.ws.ssnoc.dto.User;
import edu.cmu.sv.ws.ssnoc.rest.MessageService;
import edu.cmu.sv.ws.ssnoc.rest.MessagesService;
import edu.cmu.sv.ws.ssnoc.rest.UserService;

public class WallMessageTest {

	User user1 = new User();
	User user2 = new User();
	@Before
	public void setUp() throws Exception {
		UserService userService = new UserService();

		user1.setUserName("foo");
		user1.setPassword("1234");

		user2.setUserName("bar");
		user2.setPassword("1234");

		userService.addUser(user1);
		userService.addUser(user2);
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testSendMessageToPublicWall() {

		Message msg = new Message();
		msg.setAuthor("foo");
		Timestamp postedAt = new Timestamp(1234);
		msg.setPostedAt(postedAt);
		msg.setContent("testSendMessageToPublicWall");

		MessageService msgService = new MessageService();
		Response response = msgService.addWallMessage("foo", msg);
		assertEquals(((Message)response.getEntity()).getContent(), "testSendMessageToPublicWall");
	}

	@Test
	public void testGetAllMessagesFromPublicWall() {
		Message msg = new Message();
		MessagesService msgsService = new MessagesService();
		MessageService msgService = new MessageService();

		/*
		 * Add message with null usename
		 */
		assertNull(msgService.addWallMessage("", msg));

		/*
		 * Add atleast 1 message
		 */
		msg.setAuthor("foo");
		Timestamp postedAt = new Timestamp(1234);
		msg.setPostedAt(postedAt);
		msg.setContent("testGetAllMessagesFromPublicWall");

		msgService.addWallMessage("foo", msg);

		List<Message> messages = msgsService.loadWallMessages();
		assertTrue(messages.size() != 0);
		for (Message m : messages) {
			assertTrue(m instanceof Message);
		}
	}

	@Test
	public void testLoadMessageInfoByGivenID() {
		Message msg = new Message();
		MessageService msgService = new MessageService();

		msg.setAuthor("foo");
		Timestamp postedAt = new Timestamp(1234);
		msg.setPostedAt(postedAt);
		msg.setContent("testLoadMessageInfoByGivenID");

		msgService.addWallMessage("foo", msg);

		long id = 1;

		Message retreived = msgService.loadMessage(id);

		assertTrue(retreived instanceof Message);

	}

	@Test
	public void testSendPrivateMessageToAnotherUser() {
		Message msg = new Message();
		MessageService msgService = new MessageService();

		msg.setAuthor("");
		msg.setContent("");
		assertNull(msgService.postPrivateChatMessage(null, null, msg));

		msg.setAuthor("foo");
		Timestamp postedAt = new Timestamp(1234);
		msg.setPostedAt(postedAt);
		msg.setContent("testSendPrivateMessageToAnotherUser");

		Response resp = msgService.postPrivateChatMessage(user1.getUserName(), user2.getUserName(), msg);
		assertTrue(resp instanceof Response);
	}
}

Add test methods for Message Service