package com.gentics.cailun.core.data.model;

import static org.junit.Assert.assertEquals;

import org.junit.Before;
import org.junit.Test;
import org.neo4j.graphdb.Transaction;
import org.springframework.beans.factory.annotation.Autowired;

import com.gentics.cailun.core.data.model.auth.Group;
import com.gentics.cailun.core.data.model.auth.User;
import com.gentics.cailun.core.repository.GroupRepository;
import com.gentics.cailun.test.AbstractDBTest;

public class GroupTest extends AbstractDBTest {

	@Autowired
	GroupRepository groupRepository;

	@Before
	public void setup() throws Exception {
		setupData();
	}

	@Test
	public void testUserGroup() {
		User user = new User("testuser");
		Group group = new Group("test group");
		try (Transaction tx = graphDb.beginTx()) {
			group.addUser(user);
			groupRepository.save(group);
			tx.success();
		}

		group = groupService.reload(group);
		assertEquals("The group should contain one member.", 1, group.getUsers().size());
		User userOfGroup = group.getUsers().iterator().next();
		assertEquals("Username did not match the expected one.", user.getUsername(), userOfGroup.getUsername());
	}

	@Test
	public void testRootGroupNode() {
		int nGroupsBefore = groupRepository.findRoot().getGroups().size();

		Group group = new Group("test group2");
		groupRepository.save(group);

		int nGroupsAfter = groupRepository.findRoot().getGroups().size();
		assertEquals(nGroupsBefore + 1, nGroupsAfter);
	}
}

@@ -795,24 +795,32 @@
 r(user);%0A%09%09%09
+group = 
 groupReposit
@@ -836,16 +836,16 @@
 group);%0A
-
 %09%09%09tx.su
@@ -982,16 +982,65 @@
 e());%0A%09%09
+%0A%09%09try (Transaction tx = graphDb.beginTx()) %7B%0A%09%09%09
 User use
@@ -1082,24 +1082,62 @@
 r().next();%0A
+%09%09%09neo4jTemplate.fetch(userOfGroup);%0A%09
 %09%09assertEqua
@@ -1231,16 +1231,37 @@
 ame());%0A
+%09%09%09tx.success();%0A%09%09%7D%0A
 %09%7D%0A%0A%09@Te
@@ -1410,16 +1410,62 @@
 oup2%22);%0A
+%09%09try (Transaction tx = graphDb.beginTx()) %7B%0A%09
 %09%09groupR
@@ -1486,16 +1486,37 @@
 (group);
+%0A%09%09%09tx.success();%0A%09%09%7D
 %0A%0A%09%09int 

Fix group test