+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-/*
-* SonarQube, open source software quality management tool.
-* Copyright (C) 2008-2014 SonarSource
-* mailto:contact AT sonarsource DOT com
-*
-* SonarQube is free software; you can redistribute it and/or
-* modify it under the terms of the GNU Lesser General Public
-* License as published by the Free Software Foundation; either
-* version 3 of the License, or (at your option) any later version.
-*
-* SonarQube 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
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public License
-* along with this program; if not, write to the Free Software Foundation,
-* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-*/
-
-package org.sonar.server.qualityprofile;
-
-//import org.junit.Before;
-//import org.junit.Test;
-//import org.junit.runner.RunWith;
-//import org.mockito.Mock;
-//import org.mockito.runners.MockitoJUnitRunner;
-//import org.sonar.core.persistence.DbSession;
-//import org.sonar.core.persistence.MyBatis;
-//import org.sonar.core.qualityprofile.db.QualityProfileDao;
-//import org.sonar.core.qualityprofile.db.QualityProfileDto;
-//import org.sonar.server.db.DbClient;
-//
-//import java.util.List;
-//
-//import static org.fest.assertions.Assertions.assertThat;
-//import static org.fest.assertions.Fail.fail;
-//import static org.mockito.Matchers.eq;
-//import static org.mockito.Mockito.verify;
-//import static org.mockito.Mockito.when;
-//
-//@RunWith(MockitoJUnitRunner.class)
-//public class QProfileLookupTest {
-//
-// @Mock
-// DbClient db;
-//
-// @Mock
-// DbSession session;
-//
-// @Mock
-// QualityProfileDao dao;
-//
-// QProfileLookup search;
-//
-// @Before
-// public void setUp() throws Exception {
-// when(myBatis.openSession(false)).thenReturn(session);
-// search = new QProfileLookup(myBatis, dao);
-// }
-//
-// @Test
-// public void find_by_id() throws Exception {
-// when(dao.selectById(1, session)).thenReturn(
-// new QualityProfileDto().setId(1).setName("Sonar Way with Findbugs").setLanguage("java").setParent("Sonar Way").setVersion(1).setUsed(false)
-// );
-//
-// QProfile qProfile = search.profile(1);
-// assertThat(qProfile.id()).isEqualTo(1);
-// assertThat(qProfile.name()).isEqualTo("Sonar Way with Findbugs");
-// assertThat(qProfile.language()).isEqualTo("java");
-// assertThat(qProfile.parent()).isEqualTo("Sonar Way");
-// assertThat(qProfile.version()).isEqualTo(1);
-// assertThat(qProfile.used()).isFalse();
-// }
-//
-// @Test
-// public void find_by_id_return_null_if_not_exists() throws Exception {
-// assertThat(search.profile(1)).isNull();
-// }
-//
-// @Test
-// public void find_by_name_and_language() throws Exception {
-// when(dao.selectByNameAndLanguage("Sonar Way", "java", session)).thenReturn(new QualityProfileDto().setId(1).setName("Sonar Way").setLanguage("java"));
-//
-// assertThat(search.profile("Sonar Way", "java")).isNotNull();
-// }
-//
-// @Test
-// public void find_by_name_and_language_return_null_if_not_exists() throws Exception {
-// assertThat(search.profile("Sonar Way", "java")).isNull();
-// }
-//
-// @Test
-// public void search_profiles() throws Exception {
-// when(dao.selectAll()).thenReturn(newArrayList(
-// new QualityProfileDto().setId(1).setName("Sonar Way with Findbugs").setLanguage("java").setParent("Sonar Way").setVersion(1).setUsed(false)
-// ));
-//
-// List<QProfile> result = search.allProfiles();
-// assertThat(result).hasSize(1);
-//
-// QProfile qProfile = result.get(0);
-// assertThat(qProfile.id()).isEqualTo(1);
-// assertThat(qProfile.name()).isEqualTo("Sonar Way with Findbugs");
-// assertThat(qProfile.language()).isEqualTo("java");
-// assertThat(qProfile.parent()).isEqualTo("Sonar Way");
-// assertThat(qProfile.version()).isEqualTo(1);
-// assertThat(qProfile.used()).isFalse();
-// }
-//
-// @Test
-// public void search_profiles_by_language() throws Exception {
-// search.profiles("java");
-// verify(dao).selectByLanguage("java");
-// }
-//
-// @Test
-// public void find_parent() throws Exception {
-// when(dao.selectByNameAndLanguage("Sonar Way", "java", session)).thenReturn(new QualityProfileDto().setId(1).setName("Sonar Way").setLanguage("java"));
-// search.parent(new QProfile().setName("Sonar Way with Findbugs").setLanguage("java").setParent("Sonar Way"));
-// verify(dao).selectByNameAndLanguage("Sonar Way", "java", session);
-// }
-//
-// @Test
-// public void find_parent_return_null_if_no_parent() throws Exception {
-// assertThat(search.parent(new QProfile().setName("Sonar Way with Findbugs").setLanguage("java").setParent(null))).isNull();
-// }
-//
-// @Test
-// public void find_parent_return_null_if_parent_not_exists() throws Exception {
-// when(dao.selectByNameAndLanguage("Sonar Way", "java")).thenReturn(null);
-// assertThat(search.parent(new QProfile().setName("Sonar Way with Findbugs").setLanguage("java").setParent("Sonar Way"))).isNull();
-// }
-//
-// @Test
-// public void search_children_profiles() throws Exception {
-// search.children(new QProfile().setName("Sonar Way").setLanguage("java"));
-// verify(dao).selectChildren("Sonar Way", "java", session);
-// }
-//
-// @Test
-// public void default_profile() throws Exception {
-// when(dao.selectDefaultProfile("java", "sonar.profile.java", session)).thenReturn(
-// new QualityProfileDto().setId(1).setName("Sonar Way with Findbugs").setLanguage("java").setParent("Sonar Way").setVersion(1).setUsed(false)
-// );
-//
-// assertThat(search.defaultProfile("java")).isNotNull();
-// }
-//
-// @Test
-// public void not_find_default_profile() throws Exception {
-// when(dao.selectDefaultProfile("java", "sonar.profile.java")).thenReturn(null);
-//
-// assertThat(search.defaultProfile("java")).isNull();
-// }
-//
-// @Test
-// public void search_ancestors() throws Exception {
-// when(dao.selectParent(eq(1), eq(session))).thenReturn(null);
-// when(dao.selectParent(eq(2), eq(session))).thenReturn(new QualityProfileDto().setId(1).setName("Parent").setLanguage("java"));
-// when(dao.selectParent(eq(3), eq(session))).thenReturn(new QualityProfileDto().setId(2).setName("Child").setLanguage("java").setParent("Parent"));
-//
-// List<QProfile> result = search.ancestors(new QProfile().setId(3).setName("Grandchild").setLanguage("java").setParent("Child"));
-// assertThat(result).hasSize(2);
-// }
-//
-// @Test
-// public void fail_to_get_ancestors_if_parent_cannot_be_found() throws Exception {
-// when(dao.selectParent(3)).thenReturn(null);
-//
-// try {
-// search.ancestors(new QProfile().setId(3).setName("Grandchild").setLanguage("java").setParent("Child"));
-// fail();
-// } catch (Exception e) {
-// assertThat(e).isInstanceOf(IllegalStateException.class);
-// }
-// }
-//
-//}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-///*
-// * SonarQube, open source software quality management tool.
-// * Copyright (C) 2008-2014 SonarSource
-// * mailto:contact AT sonarsource DOT com
-// *
-// * SonarQube is free software; you can redistribute it and/or
-// * modify it under the terms of the GNU Lesser General Public
-// * License as published by the Free Software Foundation; either
-// * version 3 of the License, or (at your option) any later version.
-// *
-// * SonarQube 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
-// * Lesser General Public License for more details.
-// *
-// * You should have received a copy of the GNU Lesser General Public License
-// * along with this program; if not, write to the Free Software Foundation,
-// * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-// */
-//
-//package org.sonar.server.qualityprofile;
-//
-//import com.google.common.collect.Maps;
-//import org.junit.Before;
-//import org.junit.Test;
-//import org.junit.runner.RunWith;
-//import org.mockito.ArgumentCaptor;
-//import org.mockito.Mock;
-//import org.mockito.invocation.InvocationOnMock;
-//import org.mockito.runners.MockitoJUnitRunner;
-//import org.mockito.stubbing.Answer;
-//import org.sonar.core.permission.GlobalPermissions;
-//import org.sonar.core.persistence.DbSession;
-//import org.sonar.core.persistence.MyBatis;
-//import org.sonar.core.preview.PreviewCache;
-//import org.sonar.core.properties.PropertiesDao;
-//import org.sonar.core.qualityprofile.db.QualityProfileDao;
-//import org.sonar.core.qualityprofile.db.QualityProfileDto;
-//import org.sonar.server.exceptions.BadRequestException;
-//import org.sonar.server.exceptions.ForbiddenException;
-//import org.sonar.server.exceptions.NotFoundException;
-//import org.sonar.server.user.MockUserSession;
-//import org.sonar.server.user.UserSession;
-//
-//import java.util.Collections;
-//
-//import static org.elasticsearch.common.collect.Lists.newArrayList;
-//import static org.fest.assertions.Assertions.assertThat;
-//import static org.fest.assertions.Fail.fail;
-//import static org.mockito.Matchers.any;
-//import static org.mockito.Matchers.anyString;
-//import static org.mockito.Matchers.eq;
-//import static org.mockito.Mockito.doAnswer;
-//import static org.mockito.Mockito.never;
-//import static org.mockito.Mockito.times;
-//import static org.mockito.Mockito.verify;
-//import static org.mockito.Mockito.verifyNoMoreInteractions;
-//import static org.mockito.Mockito.when;
-//
-//@RunWith(MockitoJUnitRunner.class)
-//public class QProfileOperationsTest {
-//
-// @Mock
-// MyBatis myBatis;
-//
-// @Mock
-// DbSession session;
-//
-// @Mock
-// QualityProfileDao qualityProfileDao;
-//
-// @Mock
-// PropertiesDao propertiesDao;
-//
-// @Mock
-// PreviewCache dryRunCache;
-//
-// @Mock
-// QProfileLookup profileLookup;
-//
-// @Mock
-// QProfileRepositoryExporter exporter;
-//
-// Integer currentId = 1;
-//
-// UserSession authorizedUserSession = MockUserSession.create().setLogin("nicolas").setName("Nicolas").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
-// UserSession unauthorizedUserSession = MockUserSession.create().setLogin("nicolas").setName("Nicolas");
-//
-// QProfileOperations operations;
-//
-// @Before
-// public void setUp() throws Exception {
-// when(myBatis.openSession(false)).thenReturn(session);
-//
-// doAnswer(new Answer() {
-// public Object answer(InvocationOnMock invocation) {
-// Object[] args = invocation.getArguments();
-// QualityProfileDto dto = (QualityProfileDto) args[1];
-// dto.setId(currentId++);
-// return null;
-// }
-// }).when(qualityProfileDao).insert(any(DbSession.class), any(QualityProfileDto.class));
-//
-// operations = new QProfileOperations(myBatis, qualityProfileDao, propertiesDao, exporter, dryRunCache, profileLookup);
-// }
-//
-// @Test
-// public void create_profile() throws Exception {
-// QProfileResult result = operations.newProfile("Default", "java", Maps.<String, String>newHashMap(), authorizedUserSession);
-// assertThat(result.profile().name()).isEqualTo("Default");
-// assertThat(result.profile().language()).isEqualTo("java");
-//
-// verify(qualityProfileDao).insert(eq(session), any(QualityProfileDto.class));
-//
-// ArgumentCaptor<QualityProfileDto> profileArgument = ArgumentCaptor.forClass(QualityProfileDto.class);
-// verify(qualityProfileDao).insert(eq(session), profileArgument.capture());
-// assertThat(profileArgument.getValue().getName()).isEqualTo("Default");
-// assertThat(profileArgument.getValue().getLanguage()).isEqualTo("java");
-// assertThat(profileArgument.getValue().getVersion()).isEqualTo(1);
-// assertThat(profileArgument.getValue().isUsed()).isFalse();
-//
-// verify(dryRunCache).reportGlobalModification(session);
-// verify(session).commit();
-// }
-//
-// @Test
-// public void fail_to_create_profile_without_profile_admin_permission() throws Exception {
-// try {
-// operations.newProfile("Default", "java", Maps.<String, String>newHashMap(), unauthorizedUserSession);
-// fail();
-// } catch (Exception e) {
-// assertThat(e).isInstanceOf(ForbiddenException.class);
-// }
-// verifyNoMoreInteractions(qualityProfileDao);
-// verify(session, never()).commit();
-// }
-//
-// @Test
-// public void fail_to_create_profile_if_already_exists() throws Exception {
-// when(qualityProfileDao.selectByNameAndLanguage(anyString(), anyString(), eq(session))).thenReturn(new QualityProfileDto());
-// try {
-// operations.newProfile("Default", "java", Maps.<String, String>newHashMap(), authorizedUserSession);
-// fail();
-// } catch (Exception e) {
-// assertThat(e).isInstanceOf(BadRequestException.class);
-// }
-// }
-//
-// @Test
-// public void rename_profile() throws Exception {
-// when(qualityProfileDao.selectById(1, session)).thenReturn(new QualityProfileDto().setId(1).setName("Old Default").setLanguage("java"));
-// when(profileLookup.children(any(QProfile.class), eq(session))).thenReturn(Collections.<QProfile>emptyList());
-//
-// operations.renameProfile(1, "Default profile", authorizedUserSession);
-//
-// ArgumentCaptor<QualityProfileDto> profileArgument = ArgumentCaptor.forClass(QualityProfileDto.class);
-// verify(qualityProfileDao).update(eq(session), profileArgument.capture());
-// assertThat(profileArgument.getValue().getId()).isEqualTo(1);
-// assertThat(profileArgument.getValue().getName()).isEqualTo("Default profile");
-// assertThat(profileArgument.getValue().getLanguage()).isEqualTo("java");
-//
-// verify(propertiesDao).updateProperties("sonar.profile.java", "Old Default", "Default profile", session);
-// verify(session).commit();
-// }
-//
-// @Test
-// public void fail_to_rename_profile_if_not_exists() throws Exception {
-// when(qualityProfileDao.selectById(1, session)).thenReturn(null);
-// try {
-// operations.renameProfile(1, "New Default", authorizedUserSession);
-// fail();
-// } catch (Exception e) {
-// assertThat(e).isInstanceOf(NotFoundException.class);
-// }
-// }
-//
-// @Test
-// public void fail_to_rename_profile_if_already_exists() throws Exception {
-// when(qualityProfileDao.selectById(1, session)).thenReturn(new QualityProfileDto().setId(1).setName("Default").setLanguage("java"));
-// when(qualityProfileDao.selectByNameAndLanguage(anyString(), anyString(), eq(session))).thenReturn(new QualityProfileDto());
-// try {
-// operations.renameProfile(1, "New Default", authorizedUserSession);
-// fail();
-// } catch (Exception e) {
-// assertThat(e).isInstanceOf(BadRequestException.class);
-// }
-// }
-//
-//
-// @Test
-// public void rename_children_profile() throws Exception {
-// QualityProfileDto profile = new QualityProfileDto().setId(1).setName("Old Default").setLanguage("java");
-// when(qualityProfileDao.selectById(1, session)).thenReturn(profile);
-// when(profileLookup.children(any(QProfile.class), eq(session))).thenReturn(newArrayList(
-// new QProfile().setId(2).setName("Child1").setLanguage("java").setParent("Old Default")
-// ));
-//
-// operations.renameProfile(1, "Default profile", authorizedUserSession);
-//
-// ArgumentCaptor<QualityProfileDto> profileArgument = ArgumentCaptor.forClass(QualityProfileDto.class);
-// // One call to update current profile and one other for child
-// verify(qualityProfileDao, times(2)).update(eq(session), profileArgument.capture());
-// assertThat(profileArgument.getAllValues()).hasSize(2);
-// QualityProfileDto child = profileArgument.getAllValues().get(1);
-// assertThat(child.getId()).isEqualTo(2);
-// assertThat(child.getParent()).isEqualTo("Default profile");
-//
-// verify(session).commit();
-// }
-//}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-/*
-* SonarQube, open source software quality management tool.
-* Copyright (C) 2008-2014 SonarSource
-* mailto:contact AT sonarsource DOT com
-*
-* SonarQube is free software; you can redistribute it and/or
-* modify it under the terms of the GNU Lesser General Public
-* License as published by the Free Software Foundation; either
-* version 3 of the License, or (at your option) any later version.
-*
-* SonarQube 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
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public License
-* along with this program; if not, write to the Free Software Foundation,
-* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-*/
-
-package org.sonar.server.qualityprofile;
-
-//import org.elasticsearch.common.collect.Sets;
-//import org.junit.Before;
-//import org.junit.Test;
-//import org.junit.runner.RunWith;
-//import org.mockito.Mock;
-//import org.mockito.runners.MockitoJUnitRunner;
-//import org.sonar.api.web.UserRole;
-//import org.sonar.core.component.ComponentDto;
-//import org.sonar.core.persistence.DbSession;
-//import org.sonar.core.persistence.MyBatis;
-//import org.sonar.core.properties.PropertiesDao;
-//import org.sonar.core.qualityprofile.db.QualityProfileDao;
-//import org.sonar.core.qualityprofile.db.QualityProfileDto;
-//import org.sonar.core.user.AuthorizationDao;
-//import org.sonar.server.exceptions.NotFoundException;
-//import org.sonar.server.user.MockUserSession;
-//
-//import static com.google.common.collect.Lists.newArrayList;
-//import static org.fest.assertions.Assertions.assertThat;
-//import static org.fest.assertions.Fail.fail;
-//import static org.mockito.Mockito.verify;
-//import static org.mockito.Mockito.when;
-//
-//@RunWith(MockitoJUnitRunner.class)
-//public class QProfileProjectLookupTest {
-//
-// @Mock
-// MyBatis myBatis;
-//
-// @Mock
-// DbSession session;
-//
-// @Mock
-// QualityProfileDao qualityProfileDao;
-//
-// @Mock
-// PropertiesDao propertiesDao;
-//
-// @Mock
-// AuthorizationDao authorizationDao;
-//
-// QProfileProjectLookup lookup;
-//
-// @Before
-// public void setUp() throws Exception {
-// when(myBatis.openSession(false)).thenReturn(session);
-// lookup = new QProfileProjectLookup(myBatis, qualityProfileDao, authorizationDao);
-// }
-//
-// @Test
-// public void search_projects() throws Exception {
-// int userId = 42;
-// MockUserSession.set().setUserId(userId);
-// QualityProfileDto qualityProfile = new QualityProfileDto().setId(1).setName("My profile").setLanguage("java");
-// when(qualityProfileDao.selectById(1, session)).thenReturn(qualityProfile);
-// String key1 = "org.codehaus.sonar:sonar1";
-// String key2 = "org.codehaus.sonar:sonar2";
-// when(qualityProfileDao.selectProjects("My profile", "sonar.profile.java", session)).thenReturn(newArrayList(
-// new ComponentDto().setId(1L).setKey(key1).setName("SonarQube One"),
-// new ComponentDto().setId(1L).setKey(key2).setName("SonarQube Two")));
-//
-// when(authorizationDao.selectAuthorizedRootProjectsKeys(userId, UserRole.USER)).thenReturn(Sets.newHashSet(key1));
-//
-// assertThat(lookup.projects(1)).hasSize(1);
-// }
-//
-// @Test
-// public void fail_to_search_projects_if_profile_not_found() throws Exception {
-// try {
-// when(qualityProfileDao.selectById(1, session)).thenReturn(null);
-// when(qualityProfileDao.selectProjects("My profile", "sonar.profile.java", session)).thenReturn(newArrayList(new ComponentDto().setId(1L).setKey("org.codehaus.sonar:sonar").setName("SonarQube")));
-// lookup.projects(1);
-// fail();
-// } catch (Exception e) {
-// assertThat(e).isInstanceOf(NotFoundException.class);
-// }
-// }
-//
-// @Test
-// public void count_projects() throws Exception {
-// lookup.countProjects(new QProfile().setId(1).setName("My profile").setLanguage("java"));
-// verify(qualityProfileDao).countProjects("My profile", "sonar.profile.java");
-// }
-//
-// @Test
-// public void search_profiles_from_project() throws Exception {
-// QualityProfileDto qualityProfile = new QualityProfileDto().setId(1).setName("My profile").setLanguage("java");
-// when(qualityProfileDao.selectByProjectAndLanguage(1L, "java", "sonar.profile.java")).thenReturn(qualityProfile);
-//
-// QProfile result = lookup.findProfileByProjectAndLanguage(1L, "java");
-// assertThat(result).isNotNull();
-// }
-//
-// @Test
-// public void return_null_when_no_profile_when_searching_for_profiles_from_project() throws Exception {
-// when(qualityProfileDao.selectByProjectAndLanguage(1L, "java", "sonar.profile.java")).thenReturn(null);
-//
-// QProfile result = lookup.findProfileByProjectAndLanguage(1L, "java");
-// assertThat(result).isNull();
-// }
-//
-//}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.qualityprofile;
-//
-//import org.junit.Before;
-//import org.junit.Test;
-//import org.junit.runner.RunWith;
-//import org.mockito.ArgumentCaptor;
-//import org.mockito.Mock;
-//import org.mockito.runners.MockitoJUnitRunner;
-//import org.sonar.core.component.ComponentDto;
-//import org.sonar.core.permission.GlobalPermissions;
-//import org.sonar.core.persistence.DbSession;
-//import org.sonar.core.persistence.MyBatis;
-//import org.sonar.core.properties.PropertiesDao;
-//import org.sonar.core.properties.PropertyDto;
-//import org.sonar.core.qualityprofile.db.QualityProfileDao;
-//import org.sonar.core.qualityprofile.db.QualityProfileDto;
-//import org.sonar.core.resource.ResourceDao;
-//import org.sonar.server.exceptions.ForbiddenException;
-//import org.sonar.server.exceptions.NotFoundException;
-//import org.sonar.server.user.MockUserSession;
-//import org.sonar.server.user.UserSession;
-//
-//import static org.fest.assertions.Assertions.assertThat;
-//import static org.fest.assertions.Fail.fail;
-//import static org.mockito.Matchers.eq;
-//import static org.mockito.Mockito.never;
-//import static org.mockito.Mockito.verify;
-//import static org.mockito.Mockito.verifyNoMoreInteractions;
-//import static org.mockito.Mockito.when;
-//
-//@RunWith(MockitoJUnitRunner.class)
-//public class QProfileProjectOperationsTest {
-//
-// @Mock
-// MyBatis myBatis;
-//
-// @Mock
-// DbSession session;
-//
-// @Mock
-// QualityProfileDao qualityProfileDao;
-//
-// @Mock
-// ResourceDao resourceDao;
-//
-// @Mock
-// PropertiesDao propertiesDao;
-//
-// QProfileProjectOperations service;
-//
-// UserSession authorizedSession = MockUserSession.create().setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
-//
-// @Before
-// public void setUp() throws Exception {
-// when(myBatis.openSession(false)).thenReturn(session);
-// service = new QProfileProjectOperations(myBatis, qualityProfileDao, resourceDao, propertiesDao);
-// }
-//
-// @Test
-// public void add_project() throws Exception {
-// QualityProfileDto qualityProfile = new QualityProfileDto().setId(1).setName("My profile").setLanguage("java");
-// when(qualityProfileDao.selectById(1, session)).thenReturn(qualityProfile);
-// ComponentDto project = new ComponentDto().setId(10L).setKey("org.codehaus.sonar:sonar").setName("SonarQube");
-// when(resourceDao.findById(10L, session)).thenReturn(project);
-//
-// service.addProject(1, 10L, authorizedSession);
-//
-// ArgumentCaptor<PropertyDto> argumentCaptor = ArgumentCaptor.forClass(PropertyDto.class);
-// verify(propertiesDao).setProperty(argumentCaptor.capture(), eq(session));
-// assertThat(argumentCaptor.getValue().getKey()).isEqualTo("sonar.profile.java");
-// assertThat(argumentCaptor.getValue().getValue()).isEqualTo("My profile");
-// assertThat(argumentCaptor.getValue().getResourceId()).isEqualTo(10);
-// verify(session).commit();
-// }
-//
-// @Test
-// public void fail_to_add_project_without_profile_admin_permission() throws Exception {
-// try {
-// QualityProfileDto qualityProfile = new QualityProfileDto().setId(1).setName("My profile").setLanguage("java");
-// when(qualityProfileDao.selectById(1, session)).thenReturn(qualityProfile);
-// ComponentDto project = new ComponentDto().setId(10L).setKey("org.codehaus.sonar:sonar").setName("SonarQube");
-// when(resourceDao.findById(10L, session)).thenReturn(project);
-//
-// service.addProject(1, 10L, MockUserSession.create());
-// fail();
-// } catch (Exception e) {
-// assertThat(e).isInstanceOf(ForbiddenException.class);
-// }
-// verifyNoMoreInteractions(propertiesDao);
-// verify(session, never()).commit();
-// }
-//
-// @Test
-// public void fail_to_add_project_if_profile_not_found() throws Exception {
-// try {
-// when(qualityProfileDao.selectById(1, session)).thenReturn(null);
-// ComponentDto project = new ComponentDto().setId(10L).setKey("org.codehaus.sonar:sonar").setName("SonarQube");
-// when(resourceDao.findById(10L, session)).thenReturn(project);
-//
-// service.addProject(1, 10L, authorizedSession);
-// fail();
-// } catch (Exception e) {
-// assertThat(e).isInstanceOf(NotFoundException.class);
-// }
-// verifyNoMoreInteractions(propertiesDao);
-// verify(session, never()).commit();
-// }
-//
-// @Test
-// public void fail_to_add_project_if_project_not_found() throws Exception {
-// try {
-// QualityProfileDto qualityProfile = new QualityProfileDto().setId(1).setName("My profile").setLanguage("java");
-// when(qualityProfileDao.selectById(1, session)).thenReturn(qualityProfile);
-// when(resourceDao.findById(10L, session)).thenReturn(null);
-//
-// service.addProject(1, 10L, authorizedSession);
-// fail();
-// } catch (Exception e) {
-// assertThat(e).isInstanceOf(NotFoundException.class);
-// }
-// verifyNoMoreInteractions(propertiesDao);
-// verify(session, never()).commit();
-// }
-//
-// @Test
-// public void remove_project_by_quality_profile() throws Exception {
-// QualityProfileDto qualityProfile = new QualityProfileDto().setId(1).setName("My profile").setLanguage("java");
-// when(qualityProfileDao.selectById(1, session)).thenReturn(qualityProfile);
-// ComponentDto project = new ComponentDto().setId(10L).setKey("org.codehaus.sonar:sonar").setName("SonarQube");
-// when(resourceDao.findById(10L, session)).thenReturn(project);
-//
-// service.removeProject(1, 10L, authorizedSession);
-//
-// verify(propertiesDao).deleteProjectProperty("sonar.profile.java", 10L, session);
-// verify(session).commit();
-// }
-//
-// @Test
-// public void remove_project_by_language() throws Exception {
-// ComponentDto project = new ComponentDto().setId(10L).setKey("org.codehaus.sonar:sonar").setName("SonarQube");
-// when(resourceDao.findById(10L, session)).thenReturn(project);
-//
-// service.removeProject("java", 10L, authorizedSession);
-//
-// verify(propertiesDao).deleteProjectProperty("sonar.profile.java", 10L, session);
-// verify(session).commit();
-// }
-//
-// @Test
-// public void remove_all_projects() throws Exception {
-// QualityProfileDto qualityProfile = new QualityProfileDto().setId(1).setName("My profile").setLanguage("java");
-// when(qualityProfileDao.selectById(1, session)).thenReturn(qualityProfile);
-//
-// service.removeAllProjects(1, authorizedSession);
-//
-// verify(propertiesDao).deleteProjectProperties("sonar.profile.java", "My profile", session);
-// verify(session).commit();
-// }
-//}