package fr.openwide.maven.artifact.notifier.core.test;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;

import fr.openwide.maven.artifact.notifier.core.business.user.model.User;
import fr.openwide.maven.artifact.notifier.core.business.user.model.UserGroup;
import fr.openwide.maven.artifact.notifier.core.business.user.service.IUserGroupService;
import fr.openwide.maven.artifact.notifier.core.business.user.service.IUserService;
import fr.openwide.maven.artifact.notifier.core.test.config.spring.MavenArtifactNotifierCoreTestCommonConfig;
import fr.openwide.core.jpa.exception.SecurityServiceException;
import fr.openwide.core.jpa.exception.ServiceException;
import fr.openwide.core.jpa.junit.AbstractTestCase;
import fr.openwide.core.jpa.security.business.authority.model.Authority;
import fr.openwide.core.jpa.security.business.authority.service.IAuthorityService;
import fr.openwide.core.jpa.security.business.authority.util.CoreAuthorityConstants;

@ContextConfiguration(classes = MavenArtifactNotifierCoreTestCommonConfig.class)
public abstract class AbstractMavenArtifactNotifierTestCase extends AbstractTestCase {

	@Autowired
	protected IUserService userService;
	
	@Autowired
	protected IUserGroupService userGroupService;
	
	@Autowired
	protected IAuthorityService authorityService;

	@Override
	public void init() throws ServiceException, SecurityServiceException {
		super.init();
		initAuthorities();
	}

	@Override
	protected void cleanAll() throws ServiceException, SecurityServiceException {
		cleanUsers();
		cleanUserGroups();
		cleanAuthorities();
	}

	protected void cleanUsers() throws ServiceException, SecurityServiceException {
		for (User user : userService.list()) {
			userService.delete(user);
		}
	}

	protected void cleanUserGroups() throws ServiceException, SecurityServiceException {
		for (UserGroup userGroup : userGroupService.list()) {
			userGroupService.delete(userGroup);
		}
	}

	protected void cleanAuthorities() throws ServiceException, SecurityServiceException {
		for (Authority authority : authorityService.list()) {
			authorityService.delete(authority);
		}
	}

	private void initAuthorities() throws ServiceException, SecurityServiceException {
		authorityService.create(new Authority(CoreAuthorityConstants.ROLE_AUTHENTICATED));
	}
}

@@ -179,444 +179,8 @@
 n;%0A%0A
-import fr.openwide.maven.artifact.notifier.core.business.user.model.User;%0Aimport fr.openwide.maven.artifact.notifier.core.business.user.model.UserGroup;%0Aimport fr.openwide.maven.artifact.notifier.core.business.user.service.IUserGroupService;%0Aimport fr.openwide.maven.artifact.notifier.core.business.user.service.IUserService;%0Aimport fr.openwide.maven.artifact.notifier.core.test.config.spring.MavenArtifactNotifierCoreTestCommonConfig;%0A
 impo
@@ -231,32 +231,32 @@
 rviceException;%0A
+
 import fr.openwi
@@ -347,16 +347,85 @@
 stCase;%0A
+import fr.openwide.core.jpa.more.business.parameter.model.Parameter;%0A
 import f
@@ -656,16 +656,546 @@
 nstants;
+%0Aimport fr.openwide.maven.artifact.notifier.core.business.parameter.service.IParameterService;%0Aimport fr.openwide.maven.artifact.notifier.core.business.user.model.User;%0Aimport fr.openwide.maven.artifact.notifier.core.business.user.model.UserGroup;%0Aimport fr.openwide.maven.artifact.notifier.core.business.user.service.IUserGroupService;%0Aimport fr.openwide.maven.artifact.notifier.core.business.user.service.IUserService;%0Aimport fr.openwide.maven.artifact.notifier.core.test.config.spring.MavenArtifactNotifierCoreTestCommonConfig;
 %0A%0A@Conte
@@ -1355,16 +1355,77 @@
 stCase %7B
+%0A%09%0A%09@Autowired%0A%09protected IParameterService parameterService;
 %0A%0A%09@Auto
@@ -1804,16 +1804,37 @@
 ption %7B%0A
+%09%09cleanParameters();%0A
 %09%09cleanU
@@ -1858,24 +1858,24 @@
 erGroups();%0A
-
 %09%09cleanAutho
@@ -1886,16 +1886,206 @@
 es();%0A%09%7D
+%0A%09%0A%09protected void cleanParameters() throws ServiceException, SecurityServiceException %7B%0A%09%09for (Parameter parameter : parameterService.list()) %7B%0A%09%09%09parameterService.delete(parameter);%0A%09%09%7D%0A%09%7D
 %0A%0A%09prote

clean up the Parameters, now that we use them