aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-10-29 14:49:50 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-10-29 15:59:53 +0100
commit4059a10684683984006ea33c68473f7a9d57063f (patch)
treecceb0c80068f34de6cd6d59d314bddf1d965f565 /server
parent527be82b07ecdca9eebaf0f97eb8bfa85616c379 (diff)
downloadsonarqube-4059a10684683984006ea33c68473f7a9d57063f.tar.gz
sonarqube-4059a10684683984006ea33c68473f7a9d57063f.zip
SONAR-5530 Remove AuthorizedComponentDto now useless with project uuid
Diffstat (limited to 'server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/batch/ProjectReferentialsAction.java3
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/component/ComponentCleanerService.java4
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/component/ComponentService.java17
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/component/db/ComponentDao.java27
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/AnalysisReportQueue.java2
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/permission/InternalPermissionService.java12
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualitygate/QualityGates.java4
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileProjectOperations.java8
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/batch/ProjectReferentialsActionTest.java6
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/component/ComponentServiceMediumTest.java11
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/component/db/ComponentDaoTest.java54
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/DbCleanerStepTest.java8
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/permission/InternalPermissionServiceTest.java38
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualitygate/QualityGatesTest.java4
14 files changed, 51 insertions, 147 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/batch/ProjectReferentialsAction.java b/server/sonar-server/src/main/java/org/sonar/server/batch/ProjectReferentialsAction.java
index 6988fda03b5..847393b0ec2 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/batch/ProjectReferentialsAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/batch/ProjectReferentialsAction.java
@@ -30,7 +30,6 @@ import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
import org.sonar.batch.protocol.input.ProjectReferentials;
import org.sonar.core.UtcDateUtils;
-import org.sonar.core.component.AuthorizedComponentDto;
import org.sonar.core.component.ComponentDto;
import org.sonar.core.permission.GlobalPermissions;
import org.sonar.core.persistence.DbSession;
@@ -119,7 +118,7 @@ public class ProjectReferentialsAction implements RequestHandler {
String profileName = request.param(PARAM_PROFILE);
String projectKey = null;
- AuthorizedComponentDto module = dbClient.componentDao().getNullableAuthorizedComponentByKey(projectOrModuleKey, session);
+ ComponentDto module = dbClient.componentDao().getNullableByKey(session, projectOrModuleKey);
// Current project can be null when analysing a new project
if (module != null) {
ComponentDto project = dbClient.componentDao().getNullableRootProjectByKey(projectOrModuleKey, session);
diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ComponentCleanerService.java b/server/sonar-server/src/main/java/org/sonar/server/component/ComponentCleanerService.java
index b37ea614293..3ae4301d7fa 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/component/ComponentCleanerService.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/component/ComponentCleanerService.java
@@ -22,7 +22,7 @@ package org.sonar.server.component;
import org.sonar.api.ServerComponent;
import org.sonar.api.resources.Scopes;
-import org.sonar.core.component.AuthorizedComponentDto;
+import org.sonar.core.component.ComponentDto;
import org.sonar.core.persistence.DbSession;
import org.sonar.core.purge.PurgeDao;
import org.sonar.server.db.DbClient;
@@ -40,7 +40,7 @@ public class ComponentCleanerService implements ServerComponent {
public void delete(String projectKey) {
DbSession session = dbClient.openSession(false);
try {
- AuthorizedComponentDto project = dbClient.componentDao().getAuthorizedComponentByKey(projectKey, session);
+ ComponentDto project = dbClient.componentDao().getByKey(session, projectKey);
if (!Scopes.PROJECT.equals(project.scope())) {
throw new IllegalArgumentException("Only project can be deleted");
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ComponentService.java b/server/sonar-server/src/main/java/org/sonar/server/component/ComponentService.java
index 225a41c9c37..b8c8f269394 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/component/ComponentService.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/component/ComponentService.java
@@ -22,7 +22,6 @@ package org.sonar.server.component;
import org.sonar.api.ServerComponent;
import org.sonar.api.web.UserRole;
-import org.sonar.core.component.AuthorizedComponentDto;
import org.sonar.core.component.ComponentDto;
import org.sonar.core.persistence.DbSession;
import org.sonar.core.preview.PreviewCache;
@@ -47,20 +46,20 @@ public class ComponentService implements ServerComponent {
this.previewCache = previewCache;
}
- public AuthorizedComponentDto getByKey(String key) {
+ public ComponentDto getByKey(String key) {
DbSession session = dbClient.openSession(false);
try {
- return dbClient.componentDao().getAuthorizedComponentByKey(key, session);
+ return dbClient.componentDao().getByKey(session, key);
} finally {
session.close();
}
}
@CheckForNull
- public AuthorizedComponentDto getNullableByKey(String key) {
+ public ComponentDto getNullableByKey(String key) {
DbSession session = dbClient.openSession(false);
try {
- return dbClient.componentDao().getNullableAuthorizedComponentByKey(key, session);
+ return dbClient.componentDao().getNullableByKey(session, key);
} finally {
session.close();
}
@@ -90,7 +89,7 @@ public class ComponentService implements ServerComponent {
DbSession session = dbClient.openSession(false);
try {
- AuthorizedComponentDto projectOrModule = getByKey(projectOrModuleKey);
+ ComponentDto projectOrModule = getByKey(projectOrModuleKey);
resourceKeyUpdaterDao.updateKey(projectOrModule.getId(), newKey);
session.commit();
@@ -106,7 +105,7 @@ public class ComponentService implements ServerComponent {
UserSession.get().checkProjectPermission(UserRole.ADMIN, projectKey);
DbSession session = dbClient.openSession(false);
try {
- AuthorizedComponentDto project = getByKey(projectKey);
+ ComponentDto project = getByKey(projectKey);
return resourceKeyUpdaterDao.checkModuleKeysBeforeRenaming(project.getId(), stringToReplace, replacementString);
} finally {
session.close();
@@ -118,12 +117,12 @@ public class ComponentService implements ServerComponent {
DbSession session = dbClient.openSession(false);
try {
- AuthorizedComponentDto project = getByKey(projectKey);
+ ComponentDto project = getByKey(projectKey);
resourceKeyUpdaterDao.bulkUpdateKey(project.getId(), stringToReplace, replacementString);
session.commit();
- AuthorizedComponentDto newProject = dbClient.componentDao().getAuthorizedComponentById(project.getId(), session);
+ ComponentDto newProject = dbClient.componentDao().getById(project.getId(), session);
previewCache.reportResourceModification(newProject.key());
session.commit();
diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/db/ComponentDao.java b/server/sonar-server/src/main/java/org/sonar/server/component/db/ComponentDao.java
index 8403037ada4..37e19057d60 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/component/db/ComponentDao.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/component/db/ComponentDao.java
@@ -22,7 +22,6 @@ package org.sonar.server.component.db;
import com.google.common.collect.Lists;
import org.sonar.api.ServerComponent;
import org.sonar.api.utils.System2;
-import org.sonar.core.component.AuthorizedComponentDto;
import org.sonar.core.component.ComponentDto;
import org.sonar.core.component.db.ComponentMapper;
import org.sonar.core.persistence.DaoComponent;
@@ -128,32 +127,6 @@ public class ComponentDao extends BaseDao<ComponentMapper, ComponentDto, String>
return mapper(session).findByKeys(keys);
}
- @CheckForNull
- public AuthorizedComponentDto getNullableAuthorizedComponentById(Long id, DbSession session) {
- return mapper(session).selectAuthorizedComponentById(id);
- }
-
- public AuthorizedComponentDto getAuthorizedComponentById(Long id, DbSession session) {
- AuthorizedComponentDto componentDto = getNullableAuthorizedComponentById(id, session);
- if (componentDto == null) {
- throw new NotFoundException(String.format("Project with id '%s' not found", id));
- }
- return componentDto;
- }
-
- @CheckForNull
- public AuthorizedComponentDto getNullableAuthorizedComponentByKey(String key, DbSession session) {
- return mapper(session).selectAuthorizedComponentByKey(key);
- }
-
- public AuthorizedComponentDto getAuthorizedComponentByKey(String key, DbSession session) {
- AuthorizedComponentDto componentDto = getNullableAuthorizedComponentByKey(key, session);
- if (componentDto == null) {
- throw new NotFoundException(String.format("Project with key '%s' not found", key));
- }
- return componentDto;
- }
-
@Override
@CheckForNull
protected ComponentDto doGetNullableByKey(DbSession session, String key) {
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/AnalysisReportQueue.java b/server/sonar-server/src/main/java/org/sonar/server/computation/AnalysisReportQueue.java
index 2f2f78a39ee..77593ec52f9 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/AnalysisReportQueue.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/AnalysisReportQueue.java
@@ -73,7 +73,7 @@ public class AnalysisReportQueue implements ServerComponent {
}
private void checkThatProjectExistsInDatabase(String projectKey, DbSession session) {
- dbClient.componentDao().getAuthorizedComponentByKey(projectKey, session);
+ dbClient.componentDao().getByKey(session, projectKey);
}
private AnalysisReportDto insertInDatabase(AnalysisReportDto reportTemplate, DbSession session) {
diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/InternalPermissionService.java b/server/sonar-server/src/main/java/org/sonar/server/permission/InternalPermissionService.java
index eda3b0b66af..378cc130935 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/permission/InternalPermissionService.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/permission/InternalPermissionService.java
@@ -26,7 +26,7 @@ import org.slf4j.LoggerFactory;
import org.sonar.api.ServerComponent;
import org.sonar.api.security.DefaultGroups;
import org.sonar.api.web.UserRole;
-import org.sonar.core.component.AuthorizedComponentDto;
+import org.sonar.core.component.ComponentDto;
import org.sonar.core.permission.GlobalPermissions;
import org.sonar.core.permission.PermissionFacade;
import org.sonar.core.persistence.DbSession;
@@ -108,7 +108,7 @@ public class InternalPermissionService implements ServerComponent {
DbSession session = dbClient.openSession(false);
try {
- AuthorizedComponentDto component = dbClient.componentDao().getAuthorizedComponentByKey(componentKey, session);
+ ComponentDto component = dbClient.componentDao().getByKey(session, componentKey);
ResourceDto provisioned = resourceDao.selectProvisionedProject(session, componentKey);
if (provisioned == null) {
checkProjectAdminPermission(componentKey);
@@ -123,7 +123,7 @@ public class InternalPermissionService implements ServerComponent {
}
}
- public void applyDefaultPermissionTemplate(DbSession session, AuthorizedComponentDto component) {
+ public void applyDefaultPermissionTemplate(DbSession session, ComponentDto component) {
permissionFacade.grantDefaultRoles(session, component.getId(), component.qualifier());
synchronizePermissions(session, component.key());
}
@@ -147,7 +147,7 @@ public class InternalPermissionService implements ServerComponent {
}
for (String componentKey : query.getSelectedComponents()) {
- AuthorizedComponentDto component = dbClient.componentDao().getAuthorizedComponentByKey(componentKey, session);
+ ComponentDto component = dbClient.componentDao().getByKey(session, componentKey);
permissionFacade.applyPermissionTemplate(session, query.getTemplateKey(), component.getId());
synchronizePermissions(session, component.uuid());
}
@@ -176,7 +176,7 @@ public class InternalPermissionService implements ServerComponent {
if (changed) {
String project = permissionChangeQuery.component();
if (project != null) {
- synchronizePermissions(session, dbClient.componentDao().getAuthorizedComponentByKey(project, session).uuid());
+ synchronizePermissions(session, dbClient.componentDao().getByKey(session, project).uuid());
}
session.commit();
}
@@ -253,7 +253,7 @@ public class InternalPermissionService implements ServerComponent {
if (componentKey == null) {
return null;
} else {
- AuthorizedComponentDto component = dbClient.componentDao().getAuthorizedComponentByKey(componentKey, session);
+ ComponentDto component = dbClient.componentDao().getByKey(session, componentKey);
return component.getId();
}
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualitygate/QualityGates.java b/server/sonar-server/src/main/java/org/sonar/server/qualitygate/QualityGates.java
index 871ba293139..5abcc46a1f3 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualitygate/QualityGates.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualitygate/QualityGates.java
@@ -30,7 +30,7 @@ import org.sonar.api.measures.Metric;
import org.sonar.api.measures.Metric.ValueType;
import org.sonar.api.measures.MetricFinder;
import org.sonar.api.web.UserRole;
-import org.sonar.core.component.AuthorizedComponentDto;
+import org.sonar.core.component.ComponentDto;
import org.sonar.core.permission.GlobalPermissions;
import org.sonar.core.persistence.DbSession;
import org.sonar.core.persistence.MyBatis;
@@ -360,7 +360,7 @@ public class QualityGates {
}
private void checkPermission(UserSession userSession, Long projectId, DbSession session) {
- AuthorizedComponentDto project = componentDao.getAuthorizedComponentById(projectId, session);
+ ComponentDto project = componentDao.getById(projectId, session);
if (!userSession.hasGlobalPermission(GlobalPermissions.QUALITY_PROFILE_ADMIN) && !userSession.hasProjectPermission(UserRole.ADMIN, project.key())) {
throw new ForbiddenException("Insufficient privileges");
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileProjectOperations.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileProjectOperations.java
index 2d5724b9383..c1c122c65a0 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileProjectOperations.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileProjectOperations.java
@@ -22,7 +22,7 @@ package org.sonar.server.qualityprofile;
import org.sonar.api.ServerComponent;
import org.sonar.api.web.UserRole;
-import org.sonar.core.component.AuthorizedComponentDto;
+import org.sonar.core.component.ComponentDto;
import org.sonar.core.permission.GlobalPermissions;
import org.sonar.core.persistence.DbSession;
import org.sonar.core.persistence.MyBatis;
@@ -55,7 +55,7 @@ public class QProfileProjectOperations implements ServerComponent {
}
void addProject(int profileId, long projectId, UserSession userSession, DbSession session) {
- AuthorizedComponentDto project = db.componentDao().getAuthorizedComponentById(projectId, session);
+ ComponentDto project = db.componentDao().getById(projectId, session);
checkPermission(userSession, project.key());
QualityProfileDto qualityProfile = findNotNull(profileId, session);
@@ -67,7 +67,7 @@ public class QProfileProjectOperations implements ServerComponent {
public void removeProject(int profileId, long projectId, UserSession userSession) {
DbSession session = db.openSession(false);
try {
- AuthorizedComponentDto project = db.componentDao().getAuthorizedComponentById(projectId, session);
+ ComponentDto project = db.componentDao().getById(projectId, session);
checkPermission(userSession, project.key());
QualityProfileDto qualityProfile = findNotNull(profileId, session);
@@ -81,7 +81,7 @@ public class QProfileProjectOperations implements ServerComponent {
public void removeProject(String language, long projectId, UserSession userSession) {
DbSession session = db.openSession(false);
try {
- AuthorizedComponentDto project = db.componentDao().getAuthorizedComponentById(projectId, session);
+ ComponentDto project = db.componentDao().getById(projectId, session);
checkPermission(userSession, project.key());
db.propertiesDao().deleteProjectProperty(QProfileProjectLookup.PROFILE_PROPERTY_PREFIX + language, project.getId(), session);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/batch/ProjectReferentialsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/batch/ProjectReferentialsActionTest.java
index 14185becbdf..7604621f580 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/batch/ProjectReferentialsActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/batch/ProjectReferentialsActionTest.java
@@ -99,9 +99,9 @@ public class ProjectReferentialsActionTest {
module = new ComponentDto().setKey("org.codehaus.sonar:sonar-server").setQualifier(Qualifiers.MODULE);
subModule = new ComponentDto().setKey("org.codehaus.sonar:sonar-server-dao").setQualifier(Qualifiers.MODULE);
- when(componentDao.getNullableAuthorizedComponentByKey(project.key(), session)).thenReturn(project);
- when(componentDao.getNullableAuthorizedComponentByKey(module.key(), session)).thenReturn(module);
- when(componentDao.getNullableAuthorizedComponentByKey(subModule.key(), session)).thenReturn(subModule);
+ when(componentDao.getNullableByKey(session, project.key())).thenReturn(project);
+ when(componentDao.getNullableByKey(session, module.key())).thenReturn(module);
+ when(componentDao.getNullableByKey(session, subModule.key())).thenReturn(subModule);
when(language.getKey()).thenReturn("java");
when(languages.all()).thenReturn(new Language[] {language});
diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ComponentServiceMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ComponentServiceMediumTest.java
index 6bbbeec965e..9fabffcd74b 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/component/ComponentServiceMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/component/ComponentServiceMediumTest.java
@@ -32,7 +32,6 @@ import org.sonar.core.permission.PermissionFacade;
import org.sonar.core.persistence.DbSession;
import org.sonar.core.rule.RuleDto;
import org.sonar.server.component.db.ComponentDao;
-import org.sonar.server.component.db.SnapshotDao;
import org.sonar.server.db.DbClient;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.issue.IssueTesting;
@@ -70,7 +69,6 @@ public class ComponentServiceMediumTest {
project = ComponentTesting.newProjectDto().setKey("sample:root");
tester.get(ComponentDao.class).insert(session, project);
- tester.get(SnapshotDao.class).insert(session, SnapshotTesting.createForProject(project));
// project can be seen by anyone
tester.get(PermissionFacade.class).insertGroupPermission(project.getId(), DefaultGroups.ANYONE, UserRole.USER, session);
@@ -113,7 +111,6 @@ public class ComponentServiceMediumTest {
public void update_project_key() throws Exception {
ComponentDto file = ComponentTesting.newFileDto(project).setKey("sample:root:src/File.xoo");
tester.get(ComponentDao.class).insert(session, file);
- tester.get(SnapshotDao.class).insert(session, SnapshotTesting.createForComponent(file, project));
IssueDto issue = IssueTesting.newDto(rule, file, project);
db.issueDao().insert(session, issue);
@@ -153,11 +150,9 @@ public class ComponentServiceMediumTest {
public void update_module_key() throws Exception {
ComponentDto module = ComponentTesting.newModuleDto(project).setKey("sample:root:module");
tester.get(ComponentDao.class).insert(session, module);
- tester.get(SnapshotDao.class).insert(session, SnapshotTesting.createForComponent(module, project));
ComponentDto file = ComponentTesting.newFileDto(module).setKey("sample:root:module:src/File.xoo");
tester.get(ComponentDao.class).insert(session, file);
- tester.get(SnapshotDao.class).insert(session, SnapshotTesting.createForComponent(file, project));
IssueDto issue = IssueTesting.newDto(rule, file, project);
db.issueDao().insert(session, issue);
@@ -219,11 +214,9 @@ public class ComponentServiceMediumTest {
public void check_module_keys_before_renaming() throws Exception {
ComponentDto module = ComponentTesting.newModuleDto(project).setKey("sample:root:module");
tester.get(ComponentDao.class).insert(session, module);
- tester.get(SnapshotDao.class).insert(session, SnapshotTesting.createForComponent(module, project));
ComponentDto file = ComponentTesting.newFileDto(module).setKey("sample:root:module:src/File.xoo");
tester.get(ComponentDao.class).insert(session, file);
- tester.get(SnapshotDao.class).insert(session, SnapshotTesting.createForComponent(file, project));
session.commit();
@@ -239,11 +232,9 @@ public class ComponentServiceMediumTest {
public void check_module_keys_before_renaming_return_duplicate_key() throws Exception {
ComponentDto module = ComponentTesting.newModuleDto(project).setKey("sample:root:module");
tester.get(ComponentDao.class).insert(session, module);
- tester.get(SnapshotDao.class).insert(session, SnapshotTesting.createForComponent(module, project));
ComponentDto module2 = ComponentTesting.newModuleDto(project).setKey("foo:module");
tester.get(ComponentDao.class).insert(session, module2);
- tester.get(SnapshotDao.class).insert(session, SnapshotTesting.createForComponent(module2, project));
session.commit();
@@ -265,11 +256,9 @@ public class ComponentServiceMediumTest {
public void bulk_update_project_key() throws Exception {
ComponentDto module = ComponentTesting.newModuleDto(project).setKey("sample:root:module");
tester.get(ComponentDao.class).insert(session, module);
- tester.get(SnapshotDao.class).insert(session, SnapshotTesting.createForComponent(module, project));
ComponentDto file = ComponentTesting.newFileDto(module).setKey("sample:root:module:src/File.xoo");
tester.get(ComponentDao.class).insert(session, file);
- tester.get(SnapshotDao.class).insert(session, SnapshotTesting.createForComponent(file, project));
IssueDto issue = IssueTesting.newDto(rule, file, project);
db.issueDao().insert(session, issue);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/db/ComponentDaoTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/db/ComponentDaoTest.java
index 8e9317c41af..f528bba8f5a 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/component/db/ComponentDaoTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/component/db/ComponentDaoTest.java
@@ -25,7 +25,6 @@ import org.junit.Before;
import org.junit.Test;
import org.sonar.api.utils.DateUtils;
import org.sonar.api.utils.System2;
-import org.sonar.core.component.AuthorizedComponentDto;
import org.sonar.core.component.ComponentDto;
import org.sonar.core.persistence.AbstractDaoTestCase;
import org.sonar.core.persistence.DbSession;
@@ -331,59 +330,6 @@ public class ComponentDaoTest extends AbstractDaoTestCase {
}
@Test
- public void get_nullable_authorized_component_by_id() {
- setupData("shared");
-
- AuthorizedComponentDto result = dao.getNullableAuthorizedComponentById(4L, session);
- assertThat(result).isNotNull();
- assertThat(result.getId()).isEqualTo(4);
- assertThat(result.getKey()).isEqualTo("org.struts:struts-core:src/org/struts/RequestContext.java");
- assertThat(result.qualifier()).isEqualTo("FIL");
- assertThat(result.scope()).isEqualTo("FIL");
-
- assertThat(dao.getNullableAuthorizedComponentById(111L, session)).isNull();
- }
-
- @Test
- public void get_authorized_component_by_id() {
- setupData("shared");
-
- assertThat(dao.getAuthorizedComponentById(4L, session)).isNotNull();
- }
-
- @Test(expected = NotFoundException.class)
- public void fail_to_get_authorized_component_by_id_when_project_not_found() {
- setupData("shared");
-
- dao.getAuthorizedComponentById(111L, session);
- }
-
- @Test
- public void get_nullable_authorized_component_by_key() {
- setupData("shared");
-
- AuthorizedComponentDto result = dao.getNullableAuthorizedComponentByKey("org.struts:struts-core:src/org/struts/RequestContext.java", session);
- assertThat(result).isNotNull();
- assertThat(result.key()).isEqualTo("org.struts:struts-core:src/org/struts/RequestContext.java");
-
- assertThat(dao.getNullableAuthorizedComponentByKey("unknown", session)).isNull();
- }
-
- @Test
- public void get_authorized_component_by_key() {
- setupData("shared");
-
- assertThat(dao.getAuthorizedComponentByKey("org.struts:struts-core:src/org/struts/RequestContext.java", session)).isNotNull();
- }
-
- @Test(expected = NotFoundException.class)
- public void fail_to_get_authorized_component_by_key_when_project_not_found() {
- setupData("shared");
-
- dao.getAuthorizedComponentByKey("unknown", session);
- }
-
- @Test
public void insert() {
when(system2.now()).thenReturn(DateUtils.parseDate("2014-06-18").getTime());
setupData("empty");
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/DbCleanerStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/DbCleanerStepTest.java
index ec6a4373d54..2c05a1a3045 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/DbCleanerStepTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/DbCleanerStepTest.java
@@ -22,15 +22,13 @@ package org.sonar.server.computation;
import org.junit.Before;
import org.junit.Test;
-import org.sonar.core.component.AuthorizedComponentDto;
+import org.sonar.core.component.ComponentDto;
import org.sonar.core.computation.db.AnalysisReportDto;
import org.sonar.core.computation.dbcleaner.DefaultPurgeTask;
import org.sonar.core.persistence.DbSession;
import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.*;
public class DbCleanerStepTest {
@@ -46,7 +44,7 @@ public class DbCleanerStepTest {
@Test
public void call_purge_method_of_the_purge_task() {
AnalysisReportDto report = mock(AnalysisReportDto.class);
- when(report.getProject()).thenReturn(mock(AuthorizedComponentDto.class));
+ when(report.getProject()).thenReturn(mock(ComponentDto.class));
sut.execute(mock(DbSession.class), report);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/InternalPermissionServiceTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/InternalPermissionServiceTest.java
index e9872ad3a1d..9ac51861ff4 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/permission/InternalPermissionServiceTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/permission/InternalPermissionServiceTest.java
@@ -170,7 +170,7 @@ public class InternalPermissionServiceTest {
@Test
public void add_component_user_permission() throws Exception {
ComponentDto project = ComponentTesting.newProjectDto().setId(10L).setKey("org.sample.Sample");
- when(componentDao.getAuthorizedComponentByKey("org.sample.Sample", session)).thenReturn(project);
+ when(componentDao.getByKey(session, "org.sample.Sample")).thenReturn(project);
params = buildPermissionChangeParams("user", null, "org.sample.Sample", "user");
setUpComponentUserPermissions("user", 10L, "codeviewer");
@@ -196,7 +196,7 @@ public class InternalPermissionServiceTest {
@Test
public void remove_component_user_permission() throws Exception {
ComponentDto project = ComponentTesting.newProjectDto().setId(10L).setKey("org.sample.Sample");
- when(componentDao.getAuthorizedComponentByKey("org.sample.Sample", session)).thenReturn(project);
+ when(componentDao.getByKey(session, "org.sample.Sample")).thenReturn(project);
params = buildPermissionChangeParams("user", null, "org.sample.Sample", "codeviewer");
setUpComponentUserPermissions("user", 10L, "codeviewer");
MockUserSession.set().setLogin("admin").addProjectPermissions(UserRole.ADMIN, "org.sample.Sample");
@@ -221,7 +221,7 @@ public class InternalPermissionServiceTest {
@Test
public void add_component_group_permission() throws Exception {
ComponentDto project = ComponentTesting.newProjectDto().setId(10L).setKey("org.sample.Sample");
- when(componentDao.getAuthorizedComponentByKey("org.sample.Sample", session)).thenReturn(project);
+ when(componentDao.getByKey(session, "org.sample.Sample")).thenReturn(project);
params = buildPermissionChangeParams(null, "group", "org.sample.Sample", "user");
setUpGlobalGroupPermissions("group", "codeviewer");
@@ -246,7 +246,7 @@ public class InternalPermissionServiceTest {
@Test
public void add_component_permission_to_anyone_group() throws Exception {
ComponentDto project = ComponentTesting.newProjectDto().setId(10L).setKey("org.sample.Sample");
- when(componentDao.getAuthorizedComponentByKey("org.sample.Sample", session)).thenReturn(project);
+ when(componentDao.getByKey(session, "org.sample.Sample")).thenReturn(project);
params = buildPermissionChangeParams(null, DefaultGroups.ANYONE, "org.sample.Sample", "user");
MockUserSession.set().setLogin("admin").addProjectPermissions(UserRole.ADMIN, "org.sample.Sample");
@@ -271,7 +271,7 @@ public class InternalPermissionServiceTest {
@Test
public void remove_component_group_permission() throws Exception {
ComponentDto project = ComponentTesting.newProjectDto().setId(10L).setKey("org.sample.Sample");
- when(componentDao.getAuthorizedComponentByKey("org.sample.Sample", session)).thenReturn(project);
+ when(componentDao.getByKey(session, "org.sample.Sample")).thenReturn(project);
params = buildPermissionChangeParams(null, "group", "org.sample.Sample", "codeviewer");
setUpComponentGroupPermissions("group", 10L, "codeviewer");
@@ -297,7 +297,7 @@ public class InternalPermissionServiceTest {
@Test
public void remove_component_permission_from_anyone_group() throws Exception {
ComponentDto project = ComponentTesting.newProjectDto().setId(10L).setKey("org.sample.Sample");
- when(componentDao.getAuthorizedComponentByKey("org.sample.Sample", session)).thenReturn(project);
+ when(componentDao.getByKey(session, "org.sample.Sample")).thenReturn(project);
params = buildPermissionChangeParams(null, DefaultGroups.ANYONE, "org.sample.Sample", "codeviewer");
setUpComponentGroupPermissions(DefaultGroups.ANYONE, 10L, "codeviewer");
@@ -323,7 +323,7 @@ public class InternalPermissionServiceTest {
@Test
public void skip_redundant_add_component_user_permission_change() throws Exception {
ComponentDto project = ComponentTesting.newProjectDto().setId(10L).setKey("org.sample.Sample");
- when(componentDao.getAuthorizedComponentByKey("org.sample.Sample", session)).thenReturn(project);
+ when(componentDao.getByKey(session, "org.sample.Sample")).thenReturn(project);
params = buildPermissionChangeParams("user", null, "org.sample.Sample", "codeviewer");
setUpComponentUserPermissions("user", 10L, "codeviewer");
@@ -349,7 +349,7 @@ public class InternalPermissionServiceTest {
@Test
public void skip_redundant_add_component_group_permission_change() throws Exception {
ComponentDto project = ComponentTesting.newProjectDto().setId(10L).setKey("org.sample.Sample");
- when(componentDao.getAuthorizedComponentByKey("org.sample.Sample", session)).thenReturn(project);
+ when(componentDao.getByKey(session, "org.sample.Sample")).thenReturn(project);
params = buildPermissionChangeParams(null, "group", "org.sample.Sample", "codeviewer");
setUpComponentGroupPermissions("group", 10L, "codeviewer");
@@ -407,7 +407,7 @@ public class InternalPermissionServiceTest {
public void fail_on_insufficient_project_rights() throws Exception {
try {
ComponentDto project = ComponentTesting.newProjectDto().setId(10L).setKey("org.sample.Sample");
- when(componentDao.getAuthorizedComponentByKey("org.sample.Sample", session)).thenReturn(project);
+ when(componentDao.getByKey(session, "org.sample.Sample")).thenReturn(project);
params = buildPermissionChangeParams(null, DefaultGroups.ANYONE, "org.sample.Sample", "user");
MockUserSession.set().setLogin("admin").addProjectPermissions(UserRole.ADMIN);
@@ -430,11 +430,11 @@ public class InternalPermissionServiceTest {
@Test
public void apply_permission_template_on_many_projects() throws Exception {
ComponentDto project1 = ComponentTesting.newProjectDto().setId(1L);
- when(componentDao.getAuthorizedComponentByKey("org.sample.Sample1", session)).thenReturn(project1);
+ when(componentDao.getByKey(session, "org.sample.Sample1")).thenReturn(project1);
ComponentDto project2 = ComponentTesting.newProjectDto().setId(2L);
- when(componentDao.getAuthorizedComponentByKey("org.sample.Sample2", session)).thenReturn(project2);
+ when(componentDao.getByKey(session, "org.sample.Sample2")).thenReturn(project2);
ComponentDto project3 = ComponentTesting.newProjectDto().setId(3L);
- when(componentDao.getAuthorizedComponentByKey("org.sample.Sample3", session)).thenReturn(project3);
+ when(componentDao.getByKey(session, "org.sample.Sample3")).thenReturn(project3);
params = Maps.newHashMap();
params.put("template_key", "my_template_key");
params.put("components", "org.sample.Sample1,org.sample.Sample2,org.sample.Sample3");
@@ -456,13 +456,13 @@ public class InternalPermissionServiceTest {
ComponentDto c1 = mock(ComponentDto.class);
when(c1.getId()).thenReturn(1L);
- when(componentDao.getAuthorizedComponentByKey("org.sample.Sample1", session)).thenReturn(c1);
+ when(componentDao.getByKey(session, "org.sample.Sample1")).thenReturn(c1);
ComponentDto c2 = mock(ComponentDto.class);
when(c2.getId()).thenReturn(2L);
- when(componentDao.getAuthorizedComponentByKey("org.sample.Sample2", session)).thenReturn(c2);
+ when(componentDao.getByKey(session, "org.sample.Sample2")).thenReturn(c1);
ComponentDto c3 = mock(ComponentDto.class);
when(c3.getId()).thenReturn(3L);
- when(componentDao.getAuthorizedComponentByKey("org.sample.Sample3", session)).thenReturn(c3);
+ when(componentDao.getByKey(session, "org.sample.Sample3")).thenReturn(c3);
params = Maps.newHashMap();
params.put("template_key", "my_template_key");
params.put("components", "org.sample.Sample1,org.sample.Sample2,org.sample.Sample3");
@@ -482,7 +482,7 @@ public class InternalPermissionServiceTest {
params.put("components", "org.sample.Sample");
ComponentDto project = ComponentTesting.newProjectDto().setId(1L).setKey("org.sample.Sample");
- when(componentDao.getAuthorizedComponentByKey("org.sample.Sample", session)).thenReturn(project);
+ when(componentDao.getByKey(session, "org.sample.Sample")).thenReturn(project);
service.applyPermissionTemplate(params);
@@ -516,7 +516,7 @@ public class InternalPermissionServiceTest {
when(mockComponent.qualifier()).thenReturn(qualifier);
MockUserSession.set().setLogin("admin").addProjectPermissions(UserRole.ADMIN, componentKey);
- when(componentDao.getAuthorizedComponentByKey(componentKey, session)).thenReturn(mockComponent);
+ when(componentDao.getByKey(session, componentKey)).thenReturn(mockComponent);
service.applyDefaultPermissionTemplate(componentKey);
verify(permissionFacade).grantDefaultRoles(session, componentId, qualifier);
@@ -533,7 +533,7 @@ public class InternalPermissionServiceTest {
when(mockComponent.getId()).thenReturn(componentId);
when(mockComponent.qualifier()).thenReturn(qualifier);
- when(componentDao.getAuthorizedComponentByKey(componentKey, session)).thenReturn(mockComponent);
+ when(componentDao.getByKey(session, componentKey)).thenReturn(mockComponent);
when(resourceDao.selectProvisionedProject(session, componentKey)).thenReturn(mock(ResourceDto.class));
service.applyDefaultPermissionTemplate(componentKey);
@@ -549,7 +549,7 @@ public class InternalPermissionServiceTest {
ComponentDto project = new ComponentDto().setId(componentId).setKey(componentKey).setQualifier(qualifier);
- when(componentDao.getAuthorizedComponentByKey(componentKey, session)).thenReturn(project);
+ when(componentDao.getByKey(session, componentKey)).thenReturn(project);
when(resourceDao.selectProvisionedProject(session, componentKey)).thenReturn(mock(ResourceDto.class));
service.applyDefaultPermissionTemplate(componentKey);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/QualityGatesTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/QualityGatesTest.java
index bfe3863e048..abb27e79fd2 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/QualityGatesTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/QualityGatesTest.java
@@ -35,7 +35,7 @@ import org.sonar.api.measures.Metric;
import org.sonar.api.measures.Metric.ValueType;
import org.sonar.api.measures.MetricFinder;
import org.sonar.api.web.UserRole;
-import org.sonar.core.component.AuthorizedComponentDto;
+import org.sonar.core.component.ComponentDto;
import org.sonar.core.permission.GlobalPermissions;
import org.sonar.core.persistence.DbSession;
import org.sonar.core.persistence.MyBatis;
@@ -99,7 +99,7 @@ public class QualityGatesTest {
@Before
public void initialize() {
- when(componentDao.getAuthorizedComponentById(anyLong(), eq(session))).thenReturn(new AuthorizedComponentDto().setId(1L).setKey(PROJECT_KEY));
+ when(componentDao.getById(anyLong(), eq(session))).thenReturn(new ComponentDto().setId(1L).setKey(PROJECT_KEY));
when(myBatis.openSession(false)).thenReturn(session);
qGates = new QualityGates(dao, conditionDao, metricFinder, propertiesDao, componentDao, myBatis);