ComponentDto module = ComponentTesting.newModuleDto(project);
tester.get(DbClient.class).componentDao().insert(dbSession, module);
- tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(module, project, projectSnapshot));
+ tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(module, projectSnapshot));
// Module properties
tester.get(DbClient.class).propertiesDao().setProperty(
ComponentDto module = ComponentTesting.newModuleDto(project);
tester.get(DbClient.class).componentDao().insert(dbSession, module);
- tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(module, project, projectSnapshot));
+ tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(module, projectSnapshot));
// No property on module -> should have the same as project
ComponentDto module = ComponentTesting.newModuleDto(project);
tester.get(DbClient.class).componentDao().insert(dbSession, module);
- SnapshotDto moduleSnapshot = SnapshotTesting.createForComponent(module, project, projectSnapshot);
+ SnapshotDto moduleSnapshot = SnapshotTesting.createForComponent(module, projectSnapshot);
tester.get(DbClient.class).snapshotDao().insert(dbSession, moduleSnapshot);
// Module properties
ComponentDto subModule = ComponentTesting.newModuleDto(module);
tester.get(DbClient.class).componentDao().insert(dbSession, subModule);
- tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(subModule, module, moduleSnapshot));
+ tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(subModule, moduleSnapshot));
// Sub module properties
tester.get(DbClient.class).propertiesDao().setProperty(
ComponentDto module1 = ComponentTesting.newModuleDto(project);
tester.get(DbClient.class).componentDao().insert(dbSession, module1);
- tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(module1, project, projectSnapshot));
+ tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(module1, projectSnapshot));
// Module 1 properties
tester.get(DbClient.class).propertiesDao().setProperty(new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR-SERVER").setResourceId(module1.getId()), dbSession);
ComponentDto module2 = ComponentTesting.newModuleDto(project);
tester.get(DbClient.class).componentDao().insert(dbSession, module2);
- tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(module2, project, projectSnapshot));
+ tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(module2, projectSnapshot));
// Module 2 property
tester.get(DbClient.class).propertiesDao().setProperty(new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR-APPLICATION").setResourceId(module2.getId()), dbSession);
ComponentDto module = ComponentTesting.newModuleDto(project);
tester.get(DbClient.class).componentDao().insert(dbSession, module);
- SnapshotDto moduleSnapshot = SnapshotTesting.createForComponent(module, project, projectSnapshot);
+ SnapshotDto moduleSnapshot = SnapshotTesting.createForComponent(module, projectSnapshot);
tester.get(DbClient.class).snapshotDao().insert(dbSession, moduleSnapshot);
// No module properties
ComponentDto subModule = ComponentTesting.newModuleDto(module);
tester.get(DbClient.class).componentDao().insert(dbSession, subModule);
- tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(subModule, module, moduleSnapshot));
+ tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(subModule, moduleSnapshot));
// Sub module properties
tester.get(DbClient.class).propertiesDao().setProperty(new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR").setResourceId(subModule.getId()), dbSession);
ComponentDto module = ComponentTesting.newModuleDto(project);
tester.get(DbClient.class).componentDao().insert(dbSession, module);
- SnapshotDto moduleSnapshot = SnapshotTesting.createForComponent(module, project, projectSnapshot);
+ SnapshotDto moduleSnapshot = SnapshotTesting.createForComponent(module, projectSnapshot);
tester.get(DbClient.class).snapshotDao().insert(dbSession, moduleSnapshot);
// Module property
ComponentDto subModule = ComponentTesting.newModuleDto(module);
tester.get(DbClient.class).componentDao().insert(dbSession, subModule);
- tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(subModule, module, moduleSnapshot));
+ tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(subModule, moduleSnapshot));
// Sub module properties
tester.get(DbClient.class).propertiesDao().setProperty(new PropertyDto().setKey("sonar.coverage.exclusions").setValue("**/*.java").setResourceId(subModule.getId()), dbSession);
ComponentDto module = ComponentTesting.newModuleDto(project);
tester.get(DbClient.class).componentDao().insert(dbSession, module);
- SnapshotDto moduleSnapshot = SnapshotTesting.createForComponent(module, project, projectSnapshot);
+ SnapshotDto moduleSnapshot = SnapshotTesting.createForComponent(module, projectSnapshot);
tester.get(DbClient.class).snapshotDao().insert(dbSession, moduleSnapshot);
// No module property
ComponentDto subModule = ComponentTesting.newModuleDto(module);
tester.get(DbClient.class).componentDao().insert(dbSession, subModule);
- tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(subModule, module, moduleSnapshot));
+ tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(subModule, moduleSnapshot));
// No sub module property
dbSession.commit();
ComponentDto module = ComponentTesting.newModuleDto(project);
tester.get(DbClient.class).componentDao().insert(dbSession, module);
- SnapshotDto moduleSnapshot = SnapshotTesting.createForComponent(module, project, projectSnapshot);
+ SnapshotDto moduleSnapshot = SnapshotTesting.createForComponent(module, projectSnapshot);
tester.get(DbClient.class).snapshotDao().insert(dbSession, moduleSnapshot);
// Module property
ComponentDto subModule = ComponentTesting.newModuleDto(module);
tester.get(DbClient.class).componentDao().insert(dbSession, subModule);
- tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(subModule, module, moduleSnapshot));
+ tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(subModule, moduleSnapshot));
// No sub module property
dbSession.commit();
public class ComponentTesting {
public static ComponentDto newFileDto(ComponentDto subProjectOrProject) {
- return new ComponentDto()
- .setUuid(Uuids.create())
- .setProjectUuid(subProjectOrProject.projectUuid())
- .setModuleUuid(subProjectOrProject.uuid())
- .setModuleUuidPath(subProjectOrProject.moduleUuidPath() == null ? subProjectOrProject.uuid() : subProjectOrProject.moduleUuidPath() + "." + subProjectOrProject.uuid())
- .setKey("file")
- .setName("File")
- .setLongName("File")
- .setParentProjectId(subProjectOrProject.getId())
- .setScope(Scopes.FILE)
- .setQualifier(Qualifiers.FILE)
- .setPath("src/main/xoo/org/sonar/samples/File.xoo")
- .setLanguage("xoo")
- .setEnabled(true);
+ return newFileDto(subProjectOrProject, Uuids.create());
}
public static ComponentDto newFileDto(ComponentDto module, String fileUuid) {
}
public static ComponentDto newProjectDto() {
- String uuid = Uuids.create();
- return new ComponentDto()
- .setUuid(uuid)
- .setProjectUuid(uuid)
- .setKey("project")
- .setName("Project")
- .setLongName("Project")
- .setParentProjectId(null)
- .setScope(Scopes.PROJECT)
- .setQualifier(Qualifiers.PROJECT)
- .setPath(null)
- .setLanguage(null)
- .setEnabled(true);
+ return newProjectDto(Uuids.create());
}
public static ComponentDto newProjectDto(String uuid) {
package org.sonar.server.component;
-import org.sonar.api.utils.DateUtils;
import org.sonar.core.component.ComponentDto;
import org.sonar.core.component.SnapshotDto;
/**
* Can be used for modules and files
*/
- public static SnapshotDto createForComponent(ComponentDto component, ComponentDto parentProject, SnapshotDto parentSnapshot) {
+ public static SnapshotDto createForComponent(ComponentDto component, SnapshotDto parentSnapshot) {
Long parentRootId = parentSnapshot.getRootId();
return new SnapshotDto()
.setResourceId(component.getId())
.setBuildDate(new Date());
}
- public static SnapshotDto defaultSnapshot() {
- return new SnapshotDto()
- .setResourceId(3L)
- .setRootProjectId(1L)
- .setParentId(2L)
- .setRootId(1L)
- .setStatus("P")
- .setLast(true)
- .setPurgeStatus(1)
- .setDepth(1)
- .setScope("DIR")
- .setQualifier("PAC")
- .setVersion("2.1-SNAPSHOT")
- .setPath("1.2.")
- .setPeriodMode(1, "days1")
- .setPeriodMode(2, "days2")
- .setPeriodMode(3, "days3")
- .setPeriodMode(4, "days4")
- .setPeriodMode(5, "days5")
- .setPeriodParam(1, "30")
- .setPeriodParam(2, "31")
- .setPeriodParam(3, "32")
- .setPeriodParam(4, "33")
- .setPeriodParam(5, "34")
- .setPeriodDate(1, DateUtils.parseDate("2011-09-24"))
- .setPeriodDate(2, DateUtils.parseDate("2011-09-25"))
- .setPeriodDate(3, DateUtils.parseDate("2011-09-26"))
- .setPeriodDate(4, DateUtils.parseDate("2011-09-27"))
- .setPeriodDate(5, DateUtils.parseDate("2011-09-28"))
- .setBuildDate(DateUtils.parseDate("2011-09-29"));
- }
}
import org.sonar.core.component.SnapshotDto;
import org.sonar.core.persistence.AbstractDaoTestCase;
import org.sonar.core.persistence.DbSession;
-import org.sonar.server.component.SnapshotTesting;
import java.util.Date;
import java.util.List;
import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import static org.sonar.server.component.SnapshotTesting.defaultSnapshot;
public class SnapshotDaoTest extends AbstractDaoTestCase {
@Test
public void is_last_snapshot_when_no_previous_snapshot() {
- SnapshotDto snapshot = SnapshotTesting.defaultSnapshot();
+ SnapshotDto snapshot = defaultSnapshot();
boolean isLast = sut.isLast(snapshot, null);
Date today = new Date();
Date yesterday = DateUtils.addDays(today, -1);
- SnapshotDto snapshot = SnapshotTesting.defaultSnapshot().setCreatedAt(today);
- SnapshotDto previousLastSnapshot = SnapshotTesting.defaultSnapshot().setCreatedAt(yesterday);
+ SnapshotDto snapshot = defaultSnapshot().setCreatedAt(today);
+ SnapshotDto previousLastSnapshot = defaultSnapshot().setCreatedAt(yesterday);
boolean isLast = sut.isLast(snapshot, previousLastSnapshot);
Date today = new Date();
Date yesterday = DateUtils.addDays(today, -1);
- SnapshotDto snapshot = SnapshotTesting.defaultSnapshot().setCreatedAt(yesterday);
- SnapshotDto previousLastSnapshot = SnapshotTesting.defaultSnapshot().setCreatedAt(today);
+ SnapshotDto snapshot = defaultSnapshot().setCreatedAt(yesterday);
+ SnapshotDto previousLastSnapshot = defaultSnapshot().setCreatedAt(today);
boolean isLast = sut.isLast(snapshot, previousLastSnapshot);
assertThat(isLast).isFalse();
}
+
+ private static SnapshotDto defaultSnapshot() {
+ return new SnapshotDto()
+ .setResourceId(3L)
+ .setRootProjectId(1L)
+ .setParentId(2L)
+ .setRootId(1L)
+ .setStatus("P")
+ .setLast(true)
+ .setPurgeStatus(1)
+ .setDepth(1)
+ .setScope("DIR")
+ .setQualifier("PAC")
+ .setVersion("2.1-SNAPSHOT")
+ .setPath("1.2.")
+ .setPeriodMode(1, "days1")
+ .setPeriodMode(2, "days2")
+ .setPeriodMode(3, "days3")
+ .setPeriodMode(4, "days4")
+ .setPeriodMode(5, "days5")
+ .setPeriodParam(1, "30")
+ .setPeriodParam(2, "31")
+ .setPeriodParam(3, "32")
+ .setPeriodParam(4, "33")
+ .setPeriodParam(5, "34")
+ .setPeriodDate(1, DateUtils.parseDate("2011-09-24"))
+ .setPeriodDate(2, DateUtils.parseDate("2011-09-25"))
+ .setPeriodDate(3, DateUtils.parseDate("2011-09-26"))
+ .setPeriodDate(4, DateUtils.parseDate("2011-09-27"))
+ .setPeriodDate(5, DateUtils.parseDate("2011-09-28"))
+ .setBuildDate(DateUtils.parseDate("2011-09-29"));
+ }
}
file = ComponentTesting.newFileDto(project).setKey("MyComponent");
tester.get(ComponentDao.class).insert(session, file);
- tester.get(SnapshotDao.class).insert(session, SnapshotTesting.createForComponent(file, project, projectSnapshot));
+ tester.get(SnapshotDao.class).insert(session, SnapshotTesting.createForComponent(file, projectSnapshot));
// project can be seen by anyone
session.commit();
file = ComponentTesting.newFileDto(project);
tester.get(ComponentDao.class).insert(session, file);
- tester.get(SnapshotDao.class).insert(session, SnapshotTesting.createForComponent(file, project, projectSnapshot));
+ tester.get(SnapshotDao.class).insert(session, SnapshotTesting.createForComponent(file, projectSnapshot));
// project can be seen by anyone
session.commit();
file = ComponentTesting.newFileDto(project);
tester.get(ComponentDao.class).insert(session, file);
- tester.get(SnapshotDao.class).insert(session, SnapshotTesting.createForComponent(file, project, projectSnapshot));
+ tester.get(SnapshotDao.class).insert(session, SnapshotTesting.createForComponent(file, projectSnapshot));
// workaround for the test to have sufficient privileges
.setScope("PRJ")
.setParentProjectId(project.getId());
db.componentDao().insert(session, module);
- db.snapshotDao().insert(session, SnapshotTesting.createForComponent(module, project, projectSnapshot));
+ db.snapshotDao().insert(session, SnapshotTesting.createForComponent(module, projectSnapshot));
ComponentDto file = ComponentTesting.newFileDto(module).setKey("FileLinkedToModule");
db.componentDao().insert(session, file);
- db.snapshotDao().insert(session, SnapshotTesting.createForComponent(file, project, projectSnapshot));
+ db.snapshotDao().insert(session, SnapshotTesting.createForComponent(file, projectSnapshot));
IssueDto issue = IssueTesting.newDto(rule, file, project);
db.issueDao().insert(session, issue);
file = ComponentTesting.newFileDto(project).setKey("MyComponent");
tester.get(ComponentDao.class).insert(session, file);
- db.snapshotDao().insert(session, SnapshotTesting.createForComponent(file, project, projectSnapshot));
+ db.snapshotDao().insert(session, SnapshotTesting.createForComponent(file, projectSnapshot));
session.commit();
// project can be seen by anyone
MockUserSession.set().setLogin("admin").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);