/*
 * Copyright 2016 EPAM Systems
 * 
 * 
 * This file is part of EPAM Report Portal.
 * https://github.com/epam/ReportPortal
 * 
 * Report Portal is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Report Portal is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Report Portal.  If not, see <http://www.gnu.org/licenses/>.
 */ 

package com.epam.ta.reportportal.core.project;

import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import com.epam.ta.BaseTest;
import com.epam.ta.reportportal.core.project.impl.UpdateProjectHandler;
import com.epam.ta.reportportal.database.dao.ProjectRepository;
import com.epam.ta.reportportal.database.entity.Project;
import com.epam.ta.reportportal.database.fixture.SpringFixture;
import com.epam.ta.reportportal.database.fixture.SpringFixtureRule;
import com.epam.ta.reportportal.ws.model.project.ProjectConfiguration;
import com.epam.ta.reportportal.ws.model.project.UpdateProjectRQ;
import com.epam.ta.reportportal.ws.model.project.email.ProjectEmailConfig;

/**
 * @author Dzmitry_Kavalets
 */
@SpringFixture("unitTestsProjectTriggers")
public class UpdateProjectHandlerTest extends BaseTest {

	@Rule
	@Autowired
	public SpringFixtureRule dfRule;

	@Autowired
	private UpdateProjectHandler updateProjectHandler;

	@Autowired
	private ProjectRepository projectRepository;

	@Test
	public void checkEmptyEmailOptions() {
		String userName = "user1";
		UpdateProjectRQ updateProjectRQ = new UpdateProjectRQ();
		ProjectConfiguration configuration = new ProjectConfiguration();
		configuration.setEntry("INTERNAL");
		configuration.setStatisticCalculationStrategy("TEST_BASED");
		configuration.setProjectSpecific("DEFAULT");
		configuration.setEmailConfig(new ProjectEmailConfig());
		updateProjectRQ.setConfiguration(configuration);
		String project1 = "project1";
		updateProjectHandler.updateProject(project1, updateProjectRQ, userName);
		Project one = projectRepository.findOne(project1);
		Assert.assertNotNull(one.getConfiguration().getEmailConfig());
	}
}
@@ -828,16 +828,484 @@
 oject;%0A%0A
+import com.epam.ta.reportportal.auth.AuthConstants;%0Aimport com.epam.ta.reportportal.database.dao.UserRepository;%0Aimport com.epam.ta.reportportal.database.entity.user.User;%0Aimport com.epam.ta.reportportal.database.entity.user.UserType;%0Aimport com.epam.ta.reportportal.database.personal.PersonalProjectUtils;%0Aimport com.epam.ta.reportportal.exception.ReportPortalException;%0Aimport com.epam.ta.reportportal.ws.model.project.UnassignUsersRQ;%0Aimport org.hamcrest.Matchers;%0A
 import o
@@ -1321,16 +1321,16 @@
 Assert;%0A
-
 import o
@@ -1363,24 +1363,66 @@
 junit.Test;%0A
+import org.junit.rules.ExpectedException;%0A
 import org.s
@@ -2040,16 +2040,176 @@
 onfig;%0A%0A
+import java.util.Arrays;%0Aimport java.util.Collections;%0A%0Aimport static java.util.Collections.singletonList;%0Aimport static org.hamcrest.Matchers.containsString;%0A%0A
 /**%0A * @
@@ -2391,16 +2391,89 @@
 fRule;%0A%0A
+%09@Rule%0A%09public ExpectedException exception = ExpectedException.none();%0A%0A%0A
 %09@Autowi
@@ -2588,16 +2588,69 @@
 itory;%0A%0A
+%09@Autowired%0A%09private UserRepository userRepository;%0A%0A
 %09@Test%0A%09
@@ -3260,16 +3260,16 @@
 ject1);%0A
-
 %09%09Assert
@@ -3327,10 +3327,708 @@
 g());%0A%09%7D
+%0A%0A%09@Test%0A%09public void checkUnassignFromPersonal() %7B%0A%09%09User user = new User();%0A%09%09user.setEmail(%22checkUnassignFromPersonal@gmail.com%22);%0A%09%09user.setLogin(%22checkUnassignFromPersonal%22);%0A%09%09user.setType(UserType.INTERNAL);%0A%09%09Project project = PersonalProjectUtils.generatePersonalProject(user);%0A%09%09userRepository.save(user);%0A%09%09projectRepository.save(project);%0A%0A%09%09UnassignUsersRQ rq = new UnassignUsersRQ();%0A%09%09rq.setUsernames(singletonList(user.getLogin()));%0A%0A%09%09exception.expect(ReportPortalException.class);%0A%09%09exception.expectMessage(containsString(%22Unable to unassign user from his personal project%22));%0A%09%09updateProjectHandler.unassignUsers(project.getName(), AuthConstants.ADMINISTRATOR.getName(), rq);%0A%0A%09%7D
 %0A%7D

add unit test for unassigning