package at.fhj.swd14.pse.community;

import java.sql.Date;
import java.util.ArrayList;
import java.util.List;

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

import at.fhj.swd14.pse.converter.CommunityConverter;
import at.fhj.swd14.pse.user.User;
import at.fhj.swd14.pse.user.UserDto;
import at.fhj.swd14.pse.community.*;


public class CommunityConveterTest {
 
	Community  community;
	CommunityDto communityDto;
	UserDto userDao;
	User user;
	boolean state = false;
	User user_author;
	UserDto userdto_author;
	Date date = new Date(0);
	String description = "Communitytest";
	String name = "Test Name";
	
	@Before
	public void setup(){
		this.userdto_author = this.createUserDto((long) 1, "author@test.cu", "password_author", "salt");
		this.user_author =this.createUser((long) 1, "author@test.cu", "password_author", "salt");
		
		this.createCommunity();
		this.createCommunityDto();
	}
	
	@Test
	public void testCommunityToCommunityDto(){
		CommunityDto c = CommunityConverter.convert(this.community);
		assertCommunityDto(this.communityDto, c);
	}
	
//	@Test
//	public void testCommunityDtoToCommunity(){
//		Community c = CommunityConverter.convert(this.communityDto);
//		
//	}
	
	
	private void createCommunityDto(){
		this.communityDto = new CommunityDto((long) 1);
		this.communityDto.setActiveState(this.state);
		this.communityDto.setAllowedUsers(this.getUserDtoList());
		this.communityDto.setAuthor(this.userdto_author);
		this.communityDto.setCreateTime(this.date);
		this.communityDto.setDescription(this.description);
		this.communityDto.setName(this.name);
		this.communityDto.setPendingUsers(this.getUserDtoList());
		this.communityDto.setPublicState(this.state);
			
	}
	
	private void createCommunity(){
		this.community = new Community();
		this.community.setId((long) 1);
		this.community.setAllowedUsers(this.getUserDtoList());
		this.community.setAuthor(this.user_author);
		this.community.setName(this.name);
		this.community.setPublicState(this.state);

	}
	
	private List<UserDto> getUserDtoList(){
		
		List<UserDto> userDto = new ArrayList<>();
		userDto.add(this.createUserDto((long) 1, "mail_1@test.cu", "password_1", "salt"));
		userDto.add(this.createUserDto((long) 2, "mail_2@test.cu", "password_2", "salt"));
		
		return userDto;
	}
	
	
	private UserDto createUserDto(long id, String mail, String password, String salt){
		UserDto u = new UserDto();
		u.setId(id);
		u.setMail(mail);
		u.setPassword(password);
		u.setSalt(salt);
		
		return u;
	}
	
	private User createUser(long id, String mail, String password, String salt){
		User u = new User(id);
		u.setMail(mail);
		u.setPassword(password);
		u.setSalt(salt);
		
		return u;
	}
	
	private void assertCommunityDto(CommunityDto expected, CommunityDto actual){
		CommunityDtoTester.assertEquals(expected, actual);
		
	}
		
	
}

@@ -752,16 +752,17 @@
 author =
+ 
 this.cre
@@ -1004,22 +1004,16 @@
 ity);%0A%09%09
-assert
 Communit
@@ -1020,136 +1020,27 @@
 yDto
-(this.communityDto, c);%0A%09%7D%0A%09%0A//%09@Test%0A//%09public void testCommunityDtoToCommunity()%7B%0A//%09%09Community c = CommunityConverter.convert
+Tester.assertEquals
 (thi
@@ -1057,18 +1057,14 @@
 yDto
+, c
 );%0A
-//%09%09%0A//
 %09%7D%0A%09
@@ -1860,24 +1860,281 @@
 te);%0A%0A%09%7D%0A%09%0A%09
+private List%3CUser%3E getUserList()%7B%0A%09%09%0A%09%09List%3CUser%3E user = new ArrayList%3C%3E();%0A%09%09user.add(this.createUser((long) 1, %22mail_1@test.cu%22, %22password_1%22, %22salt%22));%0A%09%09user.add(this.createUser((long) 2, %22mail_2@test.cu%22, %22password_2%22, %22salt%22));%0A%09%09%0A%09%09return user;%0A%09%7D%0A%09%0A
 private List
@@ -2399,32 +2399,236 @@
 userDto;%0A%09%7D%0A%09%0A%09%0A
+%09%0A%09%0A%09private User createUse(long id, String mail, String password, String salt)%7B%0A%09%09User u = new User();%0A%09%09u.setId(id);%0A%09%09u.setMail(mail);%0A%09%09u.setPassword(password);%0A%09%09u.setSalt(salt);%0A%09%09%0A%09%09return u;%0A%09%7D%0A%09%0A
 %09private UserDto
@@ -2796,35 +2796,32 @@
 .setSalt(salt);%0A
-%09%09%0A
 %09%09return u;%0A%09%7D%0A%09
@@ -3011,150 +3011,6 @@
 %0A%09%7D%0A
-%09%0A%09private void assertCommunityDto(CommunityDto expected, CommunityDto actual)%7B%0A%09%09CommunityDtoTester.assertEquals(expected, actual);%0A%09%09%0A%09%7D%0A%09%09%0A%09%0A
 %7D%0A

Add CommunityConverterTest