<commit_before>package edu.cmu.sv.ws.ssnoc.rest;

import static org.junit.Assert.*;

import java.sql.SQLException;
import java.util.List;

import javax.ws.rs.core.Response;

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

import edu.cmu.sv.ws.ssnoc.common.exceptions.ServiceException;
import edu.cmu.sv.ws.ssnoc.data.util.DBUtils;
import edu.cmu.sv.ws.ssnoc.dto.Message;
import edu.cmu.sv.ws.ssnoc.dto.User;

public class MessageServiceTest {
	
	@Before
	public void setup() throws Exception {
		DBUtils.setTestMode(true);
		DBUtils.initializeDatabase();
		DBUtils.truncateDatabase();
	}

	@Test
	public void testPostingOnWall(){
		User u = new User();
		u.setUserName("Nikhil");
		u.setPassword("<PASSWORD>");
		u.setAccountStatus("Active");
		u.setCreatedAt("2014-01-01 01:01");
		u.setPrivilegeLevel("Citizen");
		
		UserService user = new UserService();
		user.addUser(u);
		MessageService input = new MessageService();
		Message message = new Message();
		message.setAuthor("Nikhil");
		message.setContent("Message");
		message.setMessageID(1);
		message.setMessageType("WALL");
		message.setPostedAt("2014-01-01 01:01");
		Response r = input.postMessageOnPublicWall("Nikhil", message);
		assertEquals(201, r.getStatus());
		Message m = (Message)r.getEntity();
		assertEquals("Nikhil", m.getAuthor());
	}	
	
	@Test
	public void testPostingOnWallIfUserIsNull(){
		MessageService input = new MessageService();
		Message message = new Message();
		message.setAuthor("Nikhil");
		message.setContent("Message");
		message.setMessageID(1);
		message.setMessageType("WALL");
		message.setPostedAt("2014-01-01 01:01");
		Response r = input.postMessageOnPublicWall("Nikhil", message);
		assertEquals(400, r.getStatus());
	}	
	
	@Test
	public void testPostingOnWallIfMessageIsNull(){
		User u = new User();
		u.setUserName("Nikhil");
		u.setPassword("<PASSWORD>");
		u.setAccountStatus("Active");
		u.setCreatedAt("2014-01-01 01:01");
		u.setPrivilegeLevel("Citizen");
		
		UserService user = new UserService();
		user.addUser(u);
		MessageService input = new MessageService();
		Message message = null;
		Exception result = null;
		try{
			Response r = input.postMessageOnPublicWall("Nikhil", message);
		}catch(Exception e){
			result = e;
		}
		assertTrue(result instanceof ServiceException);
	}	
	
	@Test
	public void testPostingOnWallIfDateIsInvalid(){
		User u = new User();
		u.setUserName("Nikhil");
		u.setPassword("<PASSWORD>");
		u.setAccountStatus("Active");<commit_msg>updating test<commit_after>package edu.cmu.sv.ws.ssnoc.rest;

import static org.junit.Assert.*;

import java.sql.SQLException;
import java.util.List;

import javax.ws.rs.core.Response;

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

import edu.cmu.sv.ws.ssnoc.common.exceptions.ServiceException;
import edu.cmu.sv.ws.ssnoc.data.util.DBUtils;
import edu.cmu.sv.ws.ssnoc.dto.Message;
import edu.cmu.sv.ws.ssnoc.dto.User;

public class MessageServiceTest {
	
	@Before
	public void setup() throws Exception {
		DBUtils.setTestMode(true);
		DBUtils.initializeDatabase();
		DBUtils.truncateDatabase();
	}

	@Test
	public void testPostingOnWall(){
		User u = new User();
		u.setUserName("Nikhil");
		u.setPassword("<PASSWORD>");
		u.setAccountStatus("Active");
		u.setCreatedAt("2014-01-01 01:01");
		u.setPrivilegeLevel("Citizen");
		
		UserService user = new UserService();
		user.addUser(u);
		MessageService input = new MessageService();
		Message message = new Message();
		message.setAuthor("Nikhil");
		message.setContent("Message");
		message.setMessageID(1);
		message.setMessageType("WALL");
		message.setPostedAt("2014-01-01 01:01");
		Response r = input.postMessageOnPublicWall("Nikhil", message);
		assertEquals(201, r.getStatus());
		Message m = (Message)r.getEntity();
		assertEquals("Nikhil", m.getAuthor());
	}	
	
	@Test
	public void testPostingOnWallIfUserIsNull(){
		MessageService input = new MessageService();
		Message message = new Message();
		message.setAuthor("Nikhil");
		message.setContent("Message");
		message.setMessageID(1);
		message.setMessageType("WALL");
		message.setPostedAt("2014-01-01 01:01");
		Response r = input.postMessageOnPublicWall("Nikhil", message);
		assertEquals(400, r.getStatus());
	}	
	
	@Test
	public void testPostingOnWallIfMessageIsNull(){
		User u = new User();
		u.setUserName("Nikhil");
		u.setPassword("<PASSWORD>");
		u.setAccountStatus("Active");
		u.setCreatedAt("2014-01-01 01:01");
		u.setPrivilegeLevel("Citizen");
		
		UserService user = new UserService();
		user.addUser(u);
		MessageService input = new MessageService();
		Message message = null;
		Response r = input.postMessageOnPublicWall("Nikhil", message);
		assertEquals(400, r.getStatus());
	}	
	
	@Test
	public void testPostingOnWallIfDateIsInvalid(){
		User u = new User();
		u.setUserName("Nikhil");
		u.setPassword("<PASSWORD>");
		u.setAccountStatus("Active");
{'fraction_non_alphanumeric': 0.14964028776978416, 'fraction_numerical': 0.023638232271325797, 'mean_word_length': 5.074906367041199, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1462113', 'n_tokens_mistral': 1868, 'n_tokens_neox': 1667, 'n_words': 301}