*/
package org.sonar.core.resource;
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-
import java.util.Date;
public final class SnapshotDto {
+
+ private static final String INDEX_SHOULD_BE_IN_RANGE_FROM_1_TO_5 = "Index should be in range from 1 to 5";
+
private Long id;
private Long parentId;
private Long rootId;
+ private Long rootProjectId;
private Date date;
private Date buildDate;
private String version;
private String path;
private Integer depth;
- private Long rootProjectId;
private String period1Mode;
private String period2Mode;
return this;
}
- @CheckForNull
- public String getPeriod1Mode() {
- return period1Mode;
- }
-
- public SnapshotDto setPeriod1Mode(@Nullable String period1Mode) {
- this.period1Mode = period1Mode;
- return this;
- }
-
- @CheckForNull
- public String getPeriod2Mode() {
- return period2Mode;
- }
-
- public SnapshotDto setPeriod2Mode(@Nullable String period2Mode) {
- this.period2Mode = period2Mode;
- return this;
- }
-
- @CheckForNull
- public String getPeriod3Mode() {
- return period3Mode;
- }
-
- public SnapshotDto setPeriod3Mode(@Nullable String period3Mode) {
- this.period3Mode = period3Mode;
- return this;
- }
-
- @CheckForNull
- public String getPeriod4Mode() {
- return period4Mode;
- }
-
- public SnapshotDto setPeriod4Mode(@Nullable String period4Mode) {
- this.period4Mode = period4Mode;
- return this;
- }
-
- @CheckForNull
- public String getPeriod5Mode() {
- return period5Mode;
- }
-
- public SnapshotDto setPeriod5Mode(@Nullable String period5Mode) {
- this.period5Mode = period5Mode;
+ public SnapshotDto setPeriodMode(int index, String p) {
+ switch (index) {
+ case 1:
+ period1Mode = p;
+ break;
+ case 2:
+ period2Mode = p;
+ break;
+ case 3:
+ period3Mode = p;
+ break;
+ case 4:
+ period4Mode = p;
+ break;
+ case 5:
+ period5Mode = p;
+ break;
+ default:
+ throw new IndexOutOfBoundsException(INDEX_SHOULD_BE_IN_RANGE_FROM_1_TO_5);
+ }
return this;
}
case 5:
return period5Mode;
default:
- throw new IndexOutOfBoundsException("Index of periodMode is between 1 and 5");
+ throw new IndexOutOfBoundsException(INDEX_SHOULD_BE_IN_RANGE_FROM_1_TO_5);
}
}
- @CheckForNull
- public String getPeriod1Param() {
- return period1Param;
- }
-
- public SnapshotDto setPeriod1Param(@Nullable String period1Param) {
- this.period1Param = period1Param;
- return this;
- }
-
- @CheckForNull
- public String getPeriod2Param() {
- return period2Param;
- }
-
- public SnapshotDto setPeriod2Param(@Nullable String period2Param) {
- this.period2Param = period2Param;
- return this;
- }
-
- @CheckForNull
- public String getPeriod3Param() {
- return period3Param;
- }
-
- public SnapshotDto setPeriod3Param(@Nullable String period3Param) {
- this.period3Param = period3Param;
- return this;
- }
-
- @CheckForNull
- public String getPeriod4Param() {
- return period4Param;
- }
-
- public SnapshotDto setPeriod4Param(@Nullable String period4Param) {
- this.period4Param = period4Param;
- return this;
- }
-
- @CheckForNull
- public String getPeriod5Param() {
- return period5Param;
- }
-
- public SnapshotDto setPeriod5Param(@Nullable String period5Param) {
- this.period5Param = period5Param;
+ public SnapshotDto setPeriodParam(int index, String p) {
+ switch (index) {
+ case 1:
+ period1Param = p;
+ break;
+ case 2:
+ period2Param = p;
+ break;
+ case 3:
+ period3Param = p;
+ break;
+ case 4:
+ period4Param = p;
+ break;
+ case 5:
+ period5Param = p;
+ break;
+ default:
+ throw new IndexOutOfBoundsException(INDEX_SHOULD_BE_IN_RANGE_FROM_1_TO_5);
+ }
return this;
}
case 5:
return period5Param;
default:
- throw new IndexOutOfBoundsException("Index of periodModeParameter is between 1 and 5");
+ throw new IndexOutOfBoundsException(INDEX_SHOULD_BE_IN_RANGE_FROM_1_TO_5);
}
}
- @CheckForNull
- public Date getPeriod1Date() {
- return period1Date;
- }
-
- public SnapshotDto setPeriod1Date(@Nullable Date period1Date) {
- this.period1Date = period1Date;
- return this;
- }
-
- @CheckForNull
- public Date getPeriod2Date() {
- return period2Date;
- }
-
- public SnapshotDto setPeriod2Date(@Nullable Date period2Date) {
- this.period2Date = period2Date;
- return this;
- }
-
- @CheckForNull
- public Date getPeriod3Date() {
- return period3Date;
- }
-
- public SnapshotDto setPeriod3Date(@Nullable Date period3Date) {
- this.period3Date = period3Date;
- return this;
- }
-
- @CheckForNull
- public Date getPeriod4Date() {
- return period4Date;
- }
-
- public SnapshotDto setPeriod4Date(@Nullable Date period4Date) {
- this.period4Date = period4Date;
- return this;
- }
-
- @CheckForNull
- public Date getPeriod5Date() {
- return period5Date;
- }
-
- public SnapshotDto setPeriod5Date(@Nullable Date period5Date) {
- this.period5Date = period5Date;
+ public SnapshotDto setPeriodDate(int index, Date d) {
+ switch (index) {
+ case 1:
+ period1Date = d;
+ break;
+ case 2:
+ period2Date = d;
+ break;
+ case 3:
+ period3Date = d;
+ break;
+ case 4:
+ period4Date = d;
+ break;
+ case 5:
+ period5Date = d;
+ break;
+ default:
+ throw new IndexOutOfBoundsException(INDEX_SHOULD_BE_IN_RANGE_FROM_1_TO_5);
+ }
return this;
}
case 5:
return period5Date;
default:
- throw new IndexOutOfBoundsException("Index of periodDate is between 1 and 5");
+ throw new IndexOutOfBoundsException(INDEX_SHOULD_BE_IN_RANGE_FROM_1_TO_5);
}
}
+
}
import org.sonar.api.component.Component;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.resources.Scopes;
+import org.sonar.api.utils.DateUtils;
import org.sonar.core.component.ComponentDto;
import org.sonar.core.persistence.AbstractDaoTestCase;
import org.sonar.core.persistence.DbSession;
@Test
public void get_last_snapshot_by_resource_id() {
- setupData("fixture");
+ setupData("get_last_snapshot_by_resource_id");
SnapshotDto snapshotDto = dao.getLastSnapshotByResourceId(1L, session);
assertThat(snapshotDto.getId()).isEqualTo(1);
+ assertThat(snapshotDto.getPeriodMode(1)).isEqualTo("previous_analysis");
+ assertThat(snapshotDto.getPeriodModeParameter(1)).isNull();
+ assertThat(snapshotDto.getPeriodDate(1)).isNull();
+
+ assertThat(snapshotDto.getPeriodMode(2)).isEqualTo("days");
+ assertThat(snapshotDto.getPeriodModeParameter(2)).isEqualTo("30");
+ assertThat(snapshotDto.getPeriodDate(2)).isEqualTo(DateUtils.parseDate("2011-09-24"));
+
+ assertThat(snapshotDto.getPeriodMode(3)).isEqualTo("days");
+ assertThat(snapshotDto.getPeriodModeParameter(3)).isEqualTo("90");
+ assertThat(snapshotDto.getPeriodDate(3)).isEqualTo(DateUtils.parseDate("2011-07-26"));
+
+ assertThat(snapshotDto.getPeriodMode(4)).isEqualTo("previous_analysis");
+ assertThat(snapshotDto.getPeriodModeParameter(4)).isNull();
+ assertThat(snapshotDto.getPeriodDate(4)).isNull();
+
+ assertThat(snapshotDto.getPeriodMode(5)).isEqualTo("previous_version");
+ assertThat(snapshotDto.getPeriodModeParameter(5)).isNull();
+ assertThat(snapshotDto.getPeriodDate(5)).isNull();
+
snapshotDto = dao.getLastSnapshotByResourceId(2L, session);
assertThat(snapshotDto.getId()).isEqualTo(2L);
--- /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.core.resource;
+
+import org.junit.Test;
+import org.sonar.api.utils.DateUtils;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class SnapshotDtoTest {
+
+ @Test
+ public void test_getter_and_setter() throws Exception {
+ SnapshotDto snapshotDto = new SnapshotDto()
+ .setId(10L)
+ .setParentId(2L)
+ .setRootId(3L)
+ .setRootProjectId(20L)
+ .setDate(DateUtils.parseDate("2014-07-01"))
+ .setBuildDate(DateUtils.parseDate("2014-07-02"))
+ .setResourceId(21L)
+ .setLast(true)
+ .setScope("FIL")
+ .setQualifier("FIL")
+ .setVersion("1.0")
+ .setPath("3.2.")
+ .setDepth(1)
+ .setPeriodMode(1, "mode1")
+ .setPeriodMode(2, "mode2")
+ .setPeriodMode(3, "mode3")
+ .setPeriodMode(4, "mode4")
+ .setPeriodMode(5, "mode5")
+ .setPeriodParam(1, "param1")
+ .setPeriodParam(2, "param2")
+ .setPeriodParam(3, "param3")
+ .setPeriodParam(4, "param4")
+ .setPeriodParam(5, "param5")
+ .setPeriodDate(1, DateUtils.parseDate("2014-06-01"))
+ .setPeriodDate(2, DateUtils.parseDate("2014-06-02"))
+ .setPeriodDate(3, DateUtils.parseDate("2014-06-03"))
+ .setPeriodDate(4, DateUtils.parseDate("2014-06-04"))
+ .setPeriodDate(5, DateUtils.parseDate("2014-06-05"));
+
+ assertThat(snapshotDto.getId()).isEqualTo(10L);
+ assertThat(snapshotDto.getParentId()).isEqualTo(2L);
+ assertThat(snapshotDto.getRootId()).isEqualTo(3L);
+ assertThat(snapshotDto.getRootProjectId()).isEqualTo(20L);
+ assertThat(snapshotDto.getDate()).isEqualTo(DateUtils.parseDate("2014-07-01"));
+ assertThat(snapshotDto.getBuildDate()).isEqualTo(DateUtils.parseDate("2014-07-02"));
+ assertThat(snapshotDto.getResourceId()).isEqualTo(21L);
+ assertThat(snapshotDto.getLast()).isTrue();
+ assertThat(snapshotDto.getScope()).isEqualTo("FIL");
+ assertThat(snapshotDto.getQualifier()).isEqualTo("FIL");
+ assertThat(snapshotDto.getVersion()).isEqualTo("1.0");
+ assertThat(snapshotDto.getPath()).isEqualTo("3.2.");
+ assertThat(snapshotDto.getDepth()).isEqualTo(1);
+ assertThat(snapshotDto.getPeriodMode(1)).isEqualTo("mode1");
+ assertThat(snapshotDto.getPeriodMode(2)).isEqualTo("mode2");
+ assertThat(snapshotDto.getPeriodMode(3)).isEqualTo("mode3");
+ assertThat(snapshotDto.getPeriodMode(4)).isEqualTo("mode4");
+ assertThat(snapshotDto.getPeriodMode(5)).isEqualTo("mode5");
+ assertThat(snapshotDto.getPeriodModeParameter(1)).isEqualTo("param1");
+ assertThat(snapshotDto.getPeriodModeParameter(2)).isEqualTo("param2");
+ assertThat(snapshotDto.getPeriodModeParameter(3)).isEqualTo("param3");
+ assertThat(snapshotDto.getPeriodModeParameter(4)).isEqualTo("param4");
+ assertThat(snapshotDto.getPeriodModeParameter(5)).isEqualTo("param5");
+ assertThat(snapshotDto.getPeriodDate(1)).isEqualTo(DateUtils.parseDate("2014-06-01"));
+ assertThat(snapshotDto.getPeriodDate(2)).isEqualTo(DateUtils.parseDate("2014-06-02"));
+ assertThat(snapshotDto.getPeriodDate(3)).isEqualTo(DateUtils.parseDate("2014-06-03"));
+ assertThat(snapshotDto.getPeriodDate(4)).isEqualTo(DateUtils.parseDate("2014-06-04"));
+ assertThat(snapshotDto.getPeriodDate(5)).isEqualTo(DateUtils.parseDate("2014-06-05"));
+ }
+
+}
--- /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.
+ -->
+
+<dataset>
+
+ <!-- Struts projects is authorized for all user -->
+ <group_roles id="1" group_id="[null]" resource_id="1" role="user"/>
+
+
+ <!-- root project -->
+ <projects id="1" root_id="[null]" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Struts"
+ description="the description" long_name="Apache Struts"
+ enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]"/>
+ <snapshots id="1" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+ status="P" islast="[true]" purge_status="[null]"
+ period1_mode="previous_analysis" period1_param="[null]" period1_date="[null]"
+ period2_mode="days" period2_param="30" period2_date="2011-09-24"
+ period3_mode="days" period3_param="90" period3_date="2011-07-26"
+ period4_mode="previous_analysis" period4_param="[null]" period4_date="[null]"
+ period5_mode="previous_version" period5_param="[null]" period5_date="[null]"
+ depth="[null]" scope="PRJ" qualifier="TRK" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00"
+ version="[null]" path=""/>
+ <snapshots id="10" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+ status="P" islast="[false]" purge_status="[null]"
+ period1_mode="[null]" period1_param="[null]" period1_date="[null]"
+ period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+ period3_mode="[null]" period3_param="[null]" period3_date="[null]"
+ period4_mode="[null]" period4_param="[null]" period4_date="[null]"
+ period5_mode="[null]" period5_param="[null]" period5_date="[null]"
+ depth="[null]" scope="PRJ" qualifier="TRK" created_at="2008-12-01 13:58:00.00" build_date="2008-12-01 13:58:00.00"
+ version="[null]" path=""/>
+
+ <!-- module -->
+ <projects id="2" root_id="1" kee="org.struts:struts-core" name="Struts Core"
+ scope="PRJ" qualifier="BRC" long_name="Struts Core"
+ description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+ <snapshots id="2" project_id="2" parent_snapshot_id="1" root_project_id="1" root_snapshot_id="1"
+ status="P" islast="[true]" purge_status="[null]"
+ period1_mode="[null]" period1_param="[null]" period1_date="[null]"
+ period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+ period3_mode="[null]" period3_param="[null]" period3_date="[null]"
+ period4_mode="[null]" period4_param="[null]" period4_date="[null]"
+ period5_mode="[null]" period5_param="[null]" period5_date="[null]"
+ depth="[null]" scope="PRJ" qualifier="BRC" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00"
+ version="[null]" path="1."/>
+
+ <!-- directory -->
+ <projects long_name="org.struts" id="3" scope="DIR" qualifier="DIR" kee="org.struts:struts-core:src/org/struts"
+ name="src/org/struts" root_id="2"
+ description="[null]"
+ enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" path="src/org/struts"/>
+ <snapshots id="3" project_id="3" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="1"
+ status="P" islast="[true]" purge_status="[null]"
+ period1_mode="[null]" period1_param="[null]" period1_date="[null]"
+ period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+ period3_mode="[null]" period3_param="[null]" period3_date="[null]"
+ period4_mode="[null]" period4_param="[null]" period4_date="[null]"
+ period5_mode="[null]" period5_param="[null]" period5_date="[null]"
+ depth="[null]" scope="DIR" qualifier="PAC" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00"
+ version="[null]" path="1.2."/>
+
+ <!-- file -->
+ <projects long_name="org.struts.RequestContext" id="4" scope="FIL" qualifier="FIL" kee="org.struts:struts-core:src/org/struts/RequestContext.java"
+ name="RequestContext.java" root_id="2"
+ description="[null]"
+ enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" path="src/org/struts/RequestContext.java"/>
+
+ <snapshots id="4" project_id="4" parent_snapshot_id="3" root_project_id="1" root_snapshot_id="1"
+ status="P" islast="[true]" purge_status="[null]"
+ period1_mode="[null]" period1_param="[null]" period1_date="[null]"
+ period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+ period3_mode="[null]" period3_param="[null]" period3_date="[null]"
+ period4_mode="[null]" period4_param="[null]" period4_date="[null]"
+ period5_mode="[null]" period5_param="[null]" period5_date="[null]"
+ depth="[null]" scope="FIL" qualifier="CLA" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00"
+ version="[null]" path="1.2.3."/>
+
+
+</dataset>
addComponent();
when(resourceDao.getLastSnapshotByResourceId(eq(1L), eq(session))).thenReturn(
- new SnapshotDto().setPeriod1Mode("previous_analysis").setPeriod1Date(DateUtils.parseDate("2014-05-08"))
+ new SnapshotDto().setPeriodMode(1, "previous_analysis").setPeriodDate(1, DateUtils.parseDate("2014-05-08"))
);
when(periods.label(anyString(), anyString(), any(Date.class))).thenReturn("since previous analysis (May 08 2014)");
Date periodDate = DateUtils.parseDate("2014-05-08");
when(resourceDao.getLastSnapshotByResourceId(eq(1L), eq(session))).thenReturn(
- new SnapshotDto().setPeriod1Mode("previous_analysis").setPeriod1Date(periodDate)
+ new SnapshotDto().setPeriodMode(1, "previous_analysis").setPeriodDate(1, periodDate)
);
when(periods.label(anyString(), anyString(), any(Date.class))).thenReturn("since previous analysis (May 08 2014)");
private void addPeriod(){
Date periodDate = DateUtils.parseDate("2014-05-08");
when(resourceDao.getLastSnapshotByResourceId(eq(1L), eq(session))).thenReturn(
- new SnapshotDto().setPeriod1Mode("previous_analysis").setPeriod1Date(periodDate)
+ new SnapshotDto().setPeriodMode(1, "previous_analysis").setPeriodDate(1, periodDate)
);
when(periods.label(anyString(), anyString(), any(Date.class))).thenReturn("since previous analysis (May 08 2014)");
}