package org.dionysus;

import org.dionysus.config.ApplicationContext;
import org.dionysus.config.TestJPAEnvironment;
import org.dionysus.model.Conversation;
import org.dionysus.model.User;
import org.dionysus.service.ConversationService;
import org.dionysus.service.UserService;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;



@RunWith(SpringJUnit4ClassRunner.class)
@ActiveProfiles("test")
@ContextConfiguration(classes = { ApplicationContext.class,
		TestJPAEnvironment.class }, loader = AnnotationConfigContextLoader.class)
public class ConversationServiceTest {

	private User owner;
	private User userA;
	private User userB;
	
	@Autowired
	private UserService userService;
	
	@Autowired
	private ConversationService conversationService;
	
	@Before
	public void setUp() {
		owner = userService.save(new User("admin", "admin", "admin@dionysus.org"));
		userA = userService.save(new User("userA", "userA", "usera@dionysus.org"));
		userB = userService.save(new User("userB", "userB", "userb@dionysus.org"));
	}
	
	
	@Test
	public void testCreateConversation() {
		Conversation conv = conversationService.create("Test Conversation", owner);
		Assert.assertNotNull(conv.getId());
	}
	
	@Test
	public void testJoinAndLeaveConversation() {
		Conversation conv = conversationService.create("test conversation", owner);
		conversationService.joinConversation(conv.getId(), userA.getId());
		conversationService.joinConversation(conv.getId(), userB.getId());
		conv = conversationService.find(conv.getId());
		System.out.println(conv.getParticipants());
//		Assert.assertEquals(conv.getParticipants().size(), 1);
	}
}

@@ -1702,16 +1702,19 @@
 owner);%0A
+%09%09%0A
 %09%09conver
@@ -1898,26 +1898,27 @@
 ;%0A%09%09
-System.out.println
+Assert.assertEquals
 (con
@@ -1940,13 +1940,143 @@
 ts()
+.size(), 2);%0A%09%09%0A%09%09conversationService.leaveConversation(conv.getId(), userA.getId());%0A%09%09conv = conversationService.find(conv.getId()
 );%0A
-//
 %09%09As

update conversation service unit test