ComponentDto project = new ComponentDto()
.setId(1L)
.setKey("MyProject")
- .setProjectId(1L);
+ .setProjectId_unit_test_only(1L);
db.componentDao().insert(session, project);
// project can be seen by anyone
ComponentDto project = new ComponentDto()
.setId(1L)
.setKey("MyProject")
- .setProjectId(1L);
+ .setProjectId_unit_test_only(1L);
db.componentDao().insert(session, project);
session.commit();
ComponentDto project = new ComponentDto()
.setId(1L)
.setKey("MyProject")
- .setProjectId(1L);
+ .setProjectId_unit_test_only(1L);
db.componentDao().insert(session, project);
// project can be seen by anyone
db.issueAuthorizationDao().synchronizeAfter(session, new Date(0));
ComponentDto resource = new ComponentDto()
- .setProjectId(1L)
+ .setProjectId_unit_test_only(1L)
.setKey("MyComponent")
.setId(2L);
db.componentDao().insert(session, resource);
.setKey("MyProject")
.setScope(Scopes.PROJECT)
.setQualifier(Qualifiers.PROJECT)
- .setProjectId(1L);
+ .setProjectId_unit_test_only(1L);
db.componentDao().insert(session, project);
session.commit();
.setKey("MyProject")
.setScope(Scopes.PROJECT)
.setQualifier(Qualifiers.PROJECT)
- .setProjectId(1L);
+ .setProjectId_unit_test_only(1L);
db.componentDao().insert(session, project);
// project can be seen by anyone
.setKey("MyProject")
.setScope(Scopes.DIRECTORY)
.setQualifier(Qualifiers.DIRECTORY)
- .setProjectId(1L);
+ .setProjectId_unit_test_only(1L);
db.componentDao().insert(session, project);
session.commit();
public static SnapshotDto createForComponent(ComponentDto component) {
return new SnapshotDto()
.setResourceId(component.getId())
- .setRootProjectId(component.projectId())
+ .setRootProjectId(component.subProjectId())
.setLast(true);
}
ComponentDto file = new ComponentDto().setId(10L).setQualifier("FIL").setKey(COMPONENT_KEY).setName("Plugin.java")
.setLongName("src/main/java/org/sonar/api/Plugin.java")
- .setPath("src/main/java/org/sonar/api/Plugin.java").setSubProjectId(5L).setProjectId(1L);
+ .setPath("src/main/java/org/sonar/api/Plugin.java").setSubProjectId(5L).setProjectId_unit_test_only(1L);
when(componentDao.getNullableByKey(session, COMPONENT_KEY)).thenReturn(file);
when(componentDao.getById(5L, session)).thenReturn(new ComponentDto().setId(5L).setLongName("SonarQube :: Plugin API").setKey(SUB_PROJECT_KEY));
when(componentDao.getById(1L, session)).thenReturn(new ComponentDto().setId(1L).setLongName("SonarQube").setKey("org.codehaus.sonar:sonar"));
String componentKey = "org.codehaus.sonar:sonar";
MockUserSession.set().setLogin("john").addComponentPermission(UserRole.USER, componentKey, componentKey);
- ComponentDto file = new ComponentDto().setId(1L).setQualifier("TRK").setKey(componentKey).setName("SonarQube").setProjectId(1L);
+ ComponentDto file = new ComponentDto().setId(1L).setQualifier("TRK").setKey(componentKey).setName("SonarQube").setProjectId_unit_test_only(1L);
when(componentDao.getNullableByKey(session, componentKey)).thenReturn(file);
when(componentDao.getById(1L, session)).thenReturn(new ComponentDto().setId(1L).setLongName("SonarQube").setKey("org.codehaus.sonar:sonar"));
when(propertiesDao.selectByQuery(any(PropertyQuery.class), eq(session))).thenReturn(newArrayList(new PropertyDto()));
MockUserSession.set().setLogin("john").addComponentPermission(UserRole.USER, SUB_PROJECT_KEY, COMPONENT_KEY);
ComponentDto file = new ComponentDto().setId(10L).setQualifier("FIL").setKey(COMPONENT_KEY).setName("Plugin.java")
- .setPath("src/main/java/org/sonar/api/Plugin.java").setSubProjectId(1L).setProjectId(1L);
+ .setPath("src/main/java/org/sonar/api/Plugin.java").setSubProjectId(1L).setProjectId_unit_test_only(1L);
when(componentDao.getNullableByKey(session, COMPONENT_KEY)).thenReturn(file);
when(componentDao.getById(1L, session)).thenReturn(new ComponentDto().setId(1L).setLongName("SonarQube").setKey("org.codehaus.sonar:sonar"));
when(propertiesDao.selectByQuery(any(PropertyQuery.class), eq(session))).thenReturn(newArrayList(new PropertyDto()));
MockUserSession.set().addComponentPermission(UserRole.USER, SUB_PROJECT_KEY, componentKey);
ComponentDto file = new ComponentDto().setId(10L).setQualifier("UTS").setKey(componentKey).setName("PlanActionTest.java")
- .setPath("src/test/java/org/sonar/server/issue/PlanActionTest.java").setSubProjectId(5L).setProjectId(1L);
+ .setPath("src/test/java/org/sonar/server/issue/PlanActionTest.java").setSubProjectId(5L).setProjectId_unit_test_only(1L);
when(componentDao.getNullableByKey(session, componentKey)).thenReturn(file);
when(componentDao.getById(5L, session)).thenReturn(new ComponentDto().setId(5L).setLongName("SonarQube :: Plugin API").setKey(SUB_PROJECT_KEY));
when(componentDao.getById(1L, session)).thenReturn(new ComponentDto().setId(1L).setLongName("SonarQube").setKey("org.codehaus.sonar:sonar"));
private void addComponent() {
ComponentDto file = new ComponentDto().setId(10L).setQualifier("FIL").setKey(COMPONENT_KEY).setName("Plugin.java")
.setLongName("src/main/java/org/sonar/api/Plugin.java")
- .setPath("src/main/java/org/sonar/api/Plugin.java").setSubProjectId(5L).setProjectId(1L);
+ .setPath("src/main/java/org/sonar/api/Plugin.java").setSubProjectId(5L).setProjectId_unit_test_only(1L);
when(componentDao.getNullableByKey(session, COMPONENT_KEY)).thenReturn(file);
when(componentDao.getById(5L, session)).thenReturn(new ComponentDto().setId(5L).setLongName("SonarQube :: Plugin API").setKey(SUB_PROJECT_KEY));
when(componentDao.getById(1L, session)).thenReturn(new ComponentDto().setId(1L).setLongName("SonarQube").setKey("org.codehaus.sonar:sonar"));
@Test
public void write_duplications() throws Exception {
String key1 = "org.codehaus.sonar:sonar-ws-client:src/main/java/org/sonar/wsclient/services/PropertyDeleteQuery.java";
- ComponentDto file1 = new ComponentDto().setId(10L).setQualifier("FIL").setKey(key1).setLongName("PropertyDeleteQuery").setProjectId(1L).setSubProjectId(5L);
+ ComponentDto file1 = new ComponentDto().setId(10L).setQualifier("FIL").setKey(key1).setLongName("PropertyDeleteQuery").setProjectId_unit_test_only(1L).setSubProjectId(5L);
String key2 = "org.codehaus.sonar:sonar-ws-client:src/main/java/org/sonar/wsclient/services/PropertyUpdateQuery.java";
- ComponentDto file2 = new ComponentDto().setId(11L).setQualifier("FIL").setKey(key2).setLongName("PropertyUpdateQuery").setProjectId(1L).setSubProjectId(5L);
+ ComponentDto file2 = new ComponentDto().setId(11L).setQualifier("FIL").setKey(key2).setLongName("PropertyUpdateQuery").setProjectId_unit_test_only(1L).setSubProjectId(5L);
when(componentDao.getNullableByKey(session, key1)).thenReturn(file1);
when(componentDao.getNullableByKey(session, key2)).thenReturn(file2);
@Test
public void write_duplications_without_sub_project() throws Exception {
String key1 = "org.codehaus.sonar:sonar-ws-client:src/main/java/org/sonar/wsclient/services/PropertyDeleteQuery.java";
- ComponentDto file1 = new ComponentDto().setId(10L).setQualifier("FIL").setKey(key1).setLongName("PropertyDeleteQuery").setProjectId(1L);
+ ComponentDto file1 = new ComponentDto().setId(10L).setQualifier("FIL").setKey(key1).setLongName("PropertyDeleteQuery").setProjectId_unit_test_only(1L);
String key2 = "org.codehaus.sonar:sonar-ws-client:src/main/java/org/sonar/wsclient/services/PropertyUpdateQuery.java";
- ComponentDto file2 = new ComponentDto().setId(11L).setQualifier("FIL").setKey(key2).setLongName("PropertyUpdateQuery").setProjectId(1L);
+ ComponentDto file2 = new ComponentDto().setId(11L).setQualifier("FIL").setKey(key2).setLongName("PropertyUpdateQuery").setProjectId_unit_test_only(1L);
when(componentDao.getNullableByKey(session, key1)).thenReturn(file1);
when(componentDao.getNullableByKey(session, key2)).thenReturn(file2);
@Test
public void write_duplications_with_a_removed_component() throws Exception {
String key1 = "org.codehaus.sonar:sonar-ws-client:src/main/java/org/sonar/wsclient/services/PropertyDeleteQuery.java";
- ComponentDto file1 = new ComponentDto().setId(10L).setQualifier("FIL").setKey(key1).setLongName("PropertyDeleteQuery").setProjectId(1L);
+ ComponentDto file1 = new ComponentDto().setId(10L).setQualifier("FIL").setKey(key1).setLongName("PropertyDeleteQuery").setProjectId_unit_test_only(1L);
when(componentDao.getNullableByKey(session, key1)).thenReturn(file1);
when(componentDao.getNullableById(1L, session)).thenReturn(new ComponentDto().setId(1L).setKey("org.codehaus.sonar:sonar").setLongName("SonarQube"));
public void setUp() throws Exception {
// Current file
String key1 = "org.codehaus.sonar:sonar-plugin-api:src/main/java/org/sonar/api/utils/command/CommandExecutor.java";
- currentFile = new ComponentDto().setId(10L).setQualifier("FIL").setKey(key1).setLongName("CommandExecutor").setProjectId(1L);
+ currentFile = new ComponentDto().setId(10L).setQualifier("FIL").setKey(key1).setLongName("CommandExecutor").setProjectId_unit_test_only(1L);
when(componentDao.getNullableByKey(session, key1)).thenReturn(currentFile);
// File on same project
String key2 = "org.codehaus.sonar:sonar-plugin-api:src/main/java/com/sonar/orchestrator/util/CommandExecutor.java";
- fileOnSameProject = new ComponentDto().setId(11L).setQualifier("FIL").setKey(key2).setLongName("CommandExecutor").setProjectId(1L);
+ fileOnSameProject = new ComponentDto().setId(11L).setQualifier("FIL").setKey(key2).setLongName("CommandExecutor").setProjectId_unit_test_only(1L);
when(componentDao.getNullableByKey(session, key2)).thenReturn(fileOnSameProject);
// File on different project
String key3 = "com.sonarsource.orchestrator:sonar-orchestrator:src/main/java/com/sonar/orchestrator/util/CommandExecutor.java";
- fileOnDifferentProject = new ComponentDto().setId(12L).setQualifier("FIL").setKey(key3).setLongName("CommandExecutor").setProjectId(2L);
+ fileOnDifferentProject = new ComponentDto().setId(12L).setQualifier("FIL").setKey(key3).setLongName("CommandExecutor").setProjectId_unit_test_only(2L);
when(componentDao.getNullableByKey(session, key3)).thenReturn(fileOnDifferentProject);
parser = new DuplicationsParser(componentDao);
@Test
public void compare_duplications() throws Exception {
- ComponentDto currentFile = new ComponentDto().setId(11L).setProjectId(1L);
- ComponentDto fileOnSameProject = new ComponentDto().setId(12L).setProjectId(1L);
- ComponentDto fileOnDifferentProject = new ComponentDto().setId(13L).setProjectId(2L);
+ ComponentDto currentFile = new ComponentDto().setId(11L).setProjectId_unit_test_only(1L);
+ ComponentDto fileOnSameProject = new ComponentDto().setId(12L).setProjectId_unit_test_only(1L);
+ ComponentDto fileOnDifferentProject = new ComponentDto().setId(13L).setProjectId_unit_test_only(2L);
DuplicationsParser.DuplicationComparator comparator = new DuplicationsParser.DuplicationComparator(currentFile);
assertThat(comparator.compare(new DuplicationsParser.Duplication(fileOnDifferentProject, 5, 2), new DuplicationsParser.Duplication(fileOnSameProject, 2, 2))).isEqualTo(1);
// Files on 2 different projects
assertThat(comparator.compare(new DuplicationsParser.Duplication(fileOnDifferentProject, 5, 2),
- new DuplicationsParser.Duplication(new ComponentDto().setId(30L).setProjectId(3L), 2, 2))).isEqualTo(1);
+ new DuplicationsParser.Duplication(new ComponentDto().setId(30L).setProjectId_unit_test_only(3L), 2, 2))).isEqualTo(1);
// With null duplications
assertThat(comparator.compare(null, new DuplicationsParser.Duplication(fileOnSameProject, 2, 2))).isEqualTo(-1);
tester.get(SnapshotDao.class).insert(session, SnapshotTesting.createForComponent(project));
file = new ComponentDto()
- .setProjectId(project.getId())
.setSubProjectId(project.getId())
.setKey("MyComponent")
.setLongName("My Component");
tester.get(SnapshotDao.class).insert(session, SnapshotTesting.createForComponent(project));
file = new ComponentDto()
- .setProjectId(project.getId())
.setSubProjectId(project.getId())
.setKey("MyComponent")
.setLongName("My Component");
file = new ComponentDto()
.setId(2L)
- .setProjectId(project.getId())
+ .setProjectId_unit_test_only(project.getId())
.setSubProjectId(project.getId())
.setKey("MyComponent")
.setLongName("My Component");
ComponentDto project = new ComponentDto()
.setId(1L)
- .setKey("MyProject")
- .setProjectId(1L);
+ .setKey("MyProject");
tester.get(ComponentDao.class).insert(dbSession, project);
// project can be seen by anyone
dbClient.issueAuthorizationDao().synchronizeAfter(dbSession, new Date(0));
ComponentDto resource = new ComponentDto()
- .setProjectId(1L)
.setKey("MyComponent")
.setId(2L);
tester.get(ComponentDao.class).insert(dbSession, resource);
ComponentDto project = new ComponentDto()
.setId(1L)
.setKey("MyProject")
- .setProjectId(1L);
+ .setProjectId_unit_test_only(1L);
tester.get(ComponentDao.class).insert(dbSession, project);
ComponentDto resource = new ComponentDto()
.setId(2L)
.setKey("MyComponent")
- .setProjectId(1L);
+ .setProjectId_unit_test_only(1L);
tester.get(ComponentDao.class).insert(dbSession, resource);
IssueDto issue = new IssueDto().setId(1L)
public void synchronize() throws Exception {
project = new ComponentDto()
.setKey("Sample")
- .setProjectId(1L)
.setAuthorizationUpdatedAt(DateUtils.parseDate("2014-09-11"));
db.componentDao().insert(session, project);
public void delete_index() throws Exception {
project = new ComponentDto()
.setKey("Sample")
- .setProjectId(1L)
.setAuthorizationUpdatedAt(DateUtils.parseDate("2014-09-11"));
db.componentDao().insert(session, project);
project = new ComponentDto()
.setId(1L)
.setKey("MyProject")
- .setProjectId(1L);
+ .setProjectId_unit_test_only(1L);
tester.get(ComponentDao.class).insert(session, project);
resource = new ComponentDto()
- .setProjectId(1L)
+ .setProjectId_unit_test_only(1L)
.setKey("MyComponent")
.setId(2L);
tester.get(ComponentDao.class).insert(session, resource);
.setQualifier("FIL")
.setPath("src/main/xoo/sample/Sample.xoo")
.setSubProjectId(7L)
- .setProjectId(7L);
+ .setProjectId_unit_test_only(7L);
ComponentDto project = new ComponentDto()
.setId(7L)
.setLongName("Sample")
.setName("Sample")
.setQualifier("TRK")
- .setProjectId(7L);
+ .setProjectId_unit_test_only(7L);
result.addComponents(Lists.<Component>newArrayList(component, project));
result.addProjects(Lists.<Component>newArrayList(project));
.setQualifier("FIL")
.setPath("src/main/xoo/sample/Sample.xoo")
.setSubProjectId(8L)
- .setProjectId(7L);
+ .setProjectId_unit_test_only(7L);
// Sub project
ComponentDto subProject = new ComponentDto()
.setName("Sample Project :: Sample Module")
.setQualifier("BRC")
.setSubProjectId(7L)
- .setProjectId(7L);
+ .setProjectId_unit_test_only(7L);
// Project
ComponentDto project = new ComponentDto()
.setLongName("Sample Project")
.setName("Sample Project")
.setQualifier("TRK")
- .setProjectId(7L);
+ .setProjectId_unit_test_only(7L);
result.addComponents(Lists.<Component>newArrayList(component, subProject, project));
result.addProjects(Lists.<Component>newArrayList(project));
.setName("SonarQube :: Issue Client")
.setQualifier("FIL")
.setSubProjectId(1L)
- .setProjectId(1L);
+ .setProjectId_unit_test_only(1L);
when(componentDao.getNullableByKey(session, file.key())).thenReturn(file);
ComponentDto project = new ComponentDto()
.setKey("org.sonar.Sonar")
.setLongName("SonarQube")
.setName("SonarQube")
- .setProjectId(1L);
+ .setProjectId_unit_test_only(1L);
when(componentDao.getNullableById(file.projectId(), session)).thenReturn(project);
MockUserSession.set();
.setLongName("SonarQube :: Issue Client")
.setQualifier("FIL")
.setSubProjectId(2L)
- .setProjectId(1L);
+ .setProjectId_unit_test_only(1L);
when(componentDao.getNullableByKey(session, file.key())).thenReturn(file);
// Module
.setLongName("SonarQube :: Server")
.setQualifier("BRC")
.setSubProjectId(1L)
- .setProjectId(1L);
+ .setProjectId_unit_test_only(1L);
when(componentDao.getNullableById(file.subProjectId(), session)).thenReturn(module);
// Project
.setLongName("SonarQube :: Issue Client")
.setQualifier("FIL")
.setSubProjectId(2L)
- .setProjectId(1L);
+ .setProjectId_unit_test_only(1L);
when(componentDao.getNullableByKey(session, file.key())).thenReturn(file);
// Module
.setName("SonarQube :: Server")
.setQualifier("BRC")
.setSubProjectId(1L)
- .setProjectId(1L);
+ .setProjectId_unit_test_only(1L);
when(componentDao.getNullableById(file.subProjectId(), session)).thenReturn(module);
// Project
.setName("SonarQube :: Issue Client")
.setQualifier("FIL")
.setSubProjectId(1L)
- .setProjectId(1L);
+ .setProjectId_unit_test_only(1L);
when(componentDao.getNullableByKey(session, file.key())).thenReturn(file);
ComponentDto project = new ComponentDto()
.setKey("org.sonar.Sonar")
.setLongName("SonarQube")
.setName("SonarQube")
- .setProjectId(1L);
+ .setProjectId_unit_test_only(1L);
when(componentDao.getNullableById(file.projectId(), session)).thenReturn(project);
}
user = new UserDto().setLogin("john").setName("John");
db.userDao().insert(session, user);
- project = new ComponentDto().setKey("Sample").setProjectId(1L);
+ project = new ComponentDto().setKey("Sample").setProjectId_unit_test_only(1L);
db.componentDao().insert(session, project);
session.commit();
db.snapshotDao().insert(session, SnapshotTesting.createForComponent(project));
file = new ComponentDto()
- .setProjectId(project.getId())
+ .setProjectId_unit_test_only(project.getId())
.setKey("MyComponent");
tester.get(ComponentDao.class).insert(session, file);
db.snapshotDao().insert(session, SnapshotTesting.createForComponent(file));
return projectId;
}
- public ComponentDto setProjectId(Long projectId) {
+ /**
+ * Only for unit tests
+ */
+ public ComponentDto setProjectId_unit_test_only(Long projectId) {
this.projectId = projectId;
return this;
}
.setScope("FIL")
.setLanguage("java")
.setPath("src/org/struts/RequestContext.java")
- .setProjectId(2L)
+ .setProjectId_unit_test_only(2L)
.setSubProjectId(3L)
.setAuthorizationUpdatedAt(DateUtils.parseDate("2014-09-11"));