private byte[] pullRequestBinary;
/**
- * The baseline analysis that marks the start of New Code Period.
- * Either manually set by user, or else automatically set to the value computed during analysis.
- *
- * It may be null for projects which have never been analyzed since the column was introduced.
+ * The UUID of the analysis set by user as manual baseline for computation of the New Code Period, if any.
*/
@Nullable
- private String baselineAnalysisUuid;
-
- /**
- * Set to true if the user has manually specified a baseline analysis for the branch.
- *
- * It may be null for projects which have never been analyzed since the column was introduced.
- */
- @Nullable
- private Boolean baselineManual;
+ private String manualBaseline;
public String getUuid() {
return uuid;
}
@CheckForNull
- public String getBaselineAnalysisUuid() {
- return baselineAnalysisUuid;
- }
-
- private BranchDto setBaselineAnalysisUuid(@Nullable String baselineAnalysisUuid) {
- this.baselineAnalysisUuid = baselineAnalysisUuid;
- return this;
- }
-
- public boolean isBaselineManual() {
- return this.baselineManual != null && this.baselineManual;
- }
-
- private BranchDto setBaselineManual(@Nullable Boolean baselineManual) {
- this.baselineManual = baselineManual != null && baselineManual;
- return this;
+ public String getManualBaseline() {
+ return manualBaseline;
}
- public BranchDto setBaseline(@Nullable String baselineAnalysisUuid, @Nullable Boolean baselineManual) {
- this.baselineAnalysisUuid = baselineAnalysisUuid;
- this.baselineManual = baselineManual;
+ public BranchDto setManualBaseline(@Nullable String manualBaseline) {
+ this.manualBaseline = manualBaseline;
return this;
}
Objects.equals(kee, branchDto.kee) &&
branchType == branchDto.branchType &&
Objects.equals(mergeBranchUuid, branchDto.mergeBranchUuid) &&
- Objects.equals(baselineAnalysisUuid, branchDto.baselineAnalysisUuid) &&
- baselineManual == branchDto.baselineManual;
+ Objects.equals(manualBaseline, branchDto.manualBaseline);
}
@Override
sb.append(", keyType=").append(keyType);
sb.append(", branchType=").append(branchType);
sb.append(", mergeBranchUuid='").append(mergeBranchUuid).append('\'');
- sb.append(", baselineAnalysisUuid='").append(baselineAnalysisUuid).append('\'');
- sb.append(", baselineManual=").append(baselineManual);
+ sb.append(", manualBaseline='").append(manualBaseline).append('\'');
sb.append('}');
return sb.toString();
}
pb.branch_type as branchType,
pb.merge_branch_uuid as mergeBranchUuid,
pb.pull_request_binary as pullRequestBinary,
- pb.baseline_analysis_uuid as baselineAnalysisUuid,
- pb.baseline_manual as baselineManual
+ pb.manual_baseline_analysis_uuid as manualBaseline
</sql>
<insert id="insert" parameterType="map" useGeneratedKeys="false">
branch_type,
merge_branch_uuid,
pull_request_binary,
- baseline_analysis_uuid,
- baseline_manual,
+ manual_baseline_analysis_uuid,
created_at,
updated_at
) values (
#{dto.branchType, jdbcType=VARCHAR},
#{dto.mergeBranchUuid, jdbcType=VARCHAR},
#{dto.pullRequestBinary, jdbcType=BINARY},
- #{dto.baselineAnalysisUuid, jdbcType=VARCHAR},
- #{dto.baselineManual, jdbcType=BOOLEAN},
+ #{dto.manualBaseline, jdbcType=VARCHAR},
#{now, jdbcType=BIGINT},
#{now, jdbcType=BIGINT}
)
uuid = #{projectUuid, jdbcType=VARCHAR}
</update>
- <update id="updateBaseline" parameterType="map" useGeneratedKeys="false">
+ <update id="updateManualBaseline" parameterType="map" useGeneratedKeys="false">
update project_branches
set
- baseline_analysis_uuid = #{baselineAnalysisUuid, jdbcType=VARCHAR},
- baseline_manual = #{baselineManual, jdbcType=BOOLEAN},
+ manual_baseline_analysis_uuid = #{analysisUuid, jdbcType=VARCHAR},
updated_at = #{now, jdbcType=BIGINT}
where
uuid = #{uuid, jdbcType=VARCHAR}
and branch_type = 'LONG'
- and (baseline_analysis_uuid is null
- or baseline_analysis_uuid != #{baselineAnalysisUuid, jdbcType=VARCHAR}
- or baseline_manual != #{baselineManual, jdbcType=BOOLEAN})
</update>
<update id="update" parameterType="map" useGeneratedKeys="false">
import com.tngtech.java.junit.dataprovider.DataProviderRunner;
import com.tngtech.java.junit.dataprovider.UseDataProvider;
import java.util.Map;
+import javax.annotation.Nullable;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
+import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
import static org.apache.commons.lang.StringUtils.repeat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;
}
@Test
- public void insert_baseline_analysis() {
+ @UseDataProvider("nullOrEmptyOrValue")
+ public void insert_manual_baseline_analysis_uuid(@Nullable String manualBaselineAnalysisUuid) {
BranchDto dto = new BranchDto();
dto.setProjectUuid("U1");
dto.setUuid("U1");
dto.setBranchType(BranchType.LONG);
dto.setKey("foo");
+ dto.setManualBaseline(manualBaselineAnalysisUuid);
+
underTest.insert(dbSession, dto);
- assertThat(underTest.updateBaseline(dbSession, dto.getUuid(), "dfsf", false)).isEqualTo(1);
+ assertThat(underTest.selectByUuid(dbSession, dto.getUuid()).get().getManualBaseline()).isEqualTo(manualBaselineAnalysisUuid);
+ }
+
+ @DataProvider
+ public static Object[][] nullOrEmptyOrValue() {
+ return new Object[][] {
+ {null},
+ {""},
+ {randomAlphabetic(12)}
+ };
}
@Test
- public void update_baseline_on_analysis_uuid_change() {
+ @UseDataProvider("oldAndNewValuesCombinations")
+ public void update_manualBaselineAnalysisUuid_if_new_value_is_different(@Nullable String oldValue, @Nullable String newValue) {
BranchDto dto = new BranchDto();
dto.setProjectUuid("U1");
dto.setUuid("U1");
dto.setBranchType(BranchType.LONG);
dto.setKey("foo");
- dto.setBaseline("a-uuid", false);
+ dto.setManualBaseline(oldValue);
underTest.insert(dbSession, dto);
BranchDto otherDtoThatShouldNotChange = new BranchDto();
otherDtoThatShouldNotChange.setUuid("U2");
otherDtoThatShouldNotChange.setBranchType(BranchType.LONG);
otherDtoThatShouldNotChange.setKey("branch");
+ otherDtoThatShouldNotChange.setManualBaseline(oldValue);
underTest.insert(dbSession, otherDtoThatShouldNotChange);
- String newBaselineAnalysisUuid = dto.getBaselineAnalysisUuid() + "-mod";
- int updated = underTest.updateBaseline(dbSession, dto.getUuid(), newBaselineAnalysisUuid, dto.isBaselineManual());
- assertThat(updated).isEqualTo(1);
- BranchDto loaded = underTest.selectByUuid(dbSession, dto.getUuid()).get();
- assertThat(loaded.getBaselineAnalysisUuid()).isEqualTo(newBaselineAnalysisUuid);
- }
-
- @Test
- @UseDataProvider("trueAndFalse")
- public void update_baseline_on_mode_change(boolean initialMode) {
- BranchDto dto = new BranchDto();
- dto.setProjectUuid("U1");
- dto.setUuid("U1");
- dto.setBranchType(BranchType.LONG);
- dto.setKey("foo");
- dto.setBaseline("a-uuid", initialMode);
- underTest.insert(dbSession, dto);
-
- int updated = underTest.updateBaseline(dbSession, dto.getUuid(), dto.getBaselineAnalysisUuid(), !initialMode);
- assertThat(updated).isEqualTo(1);
- BranchDto loaded = underTest.selectByUuid(dbSession, dto.getUuid()).get();
- assertThat(loaded.isBaselineManual()).isEqualTo(!initialMode);
- }
-
- @Test
- @UseDataProvider("trueAndFalse")
- public void do_not_update_baseline_when_unchanged(boolean initialMode) {
- BranchDto dto = new BranchDto();
- dto.setProjectUuid("U1");
- dto.setUuid("U1");
- dto.setBranchType(BranchType.LONG);
- dto.setKey("foo");
- dto.setBaseline("a-uuid", initialMode);
- underTest.insert(dbSession, dto);
+ assertThat(underTest.updateManualBaseline(dbSession, dto.getUuid(), newValue)).isEqualTo(1);
- int updated = underTest.updateBaseline(dbSession, dto.getUuid(), dto.getBaselineAnalysisUuid(), initialMode);
- assertThat(updated).isZero();
+ assertThat(underTest.selectByUuid(dbSession, dto.getUuid()).get().getManualBaseline())
+ .isEqualTo(newValue);
+ assertThat(underTest.selectByUuid(dbSession, otherDtoThatShouldNotChange.getUuid()).get().getManualBaseline())
+ .isEqualTo(oldValue);
}
@DataProvider
- public static Object[][] trueAndFalse() {
+ public static Object[][] oldAndNewValuesCombinations() {
+ String value1 = randomAlphabetic(10);
+ String value2 = randomAlphabetic(20);
return new Object[][] {
- {true},
- {false},
+ {null, value1},
+ {value1, null},
+ {value1, value2},
+ {null, null},
+ {value1, value1}
};
}
@Test
- @UseDataProvider("modeAndNonLongBranchType")
- public void do_not_update_baseline_of_non_long_branches(boolean initialMode, BranchType branchType) {
- BranchDto dto = new BranchDto();
- dto.setProjectUuid("U1");
- dto.setUuid("U1");
- dto.setBranchType(branchType);
- dto.setKey("foo");
- dto.setBaseline("a-uuid", initialMode);
- underTest.insert(dbSession, dto);
-
- int updated = underTest.updateBaseline(dbSession, dto.getUuid(), dto.getBaselineAnalysisUuid() + "-mod", !initialMode);
- assertThat(updated).isZero();
+ @UseDataProvider("nonLongBranchType")
+ public void do_not_update_manual_baseline_of_non_long_branches(BranchType branchType) {
+ String analysisUuid = randomAlphabetic(12);
+ String otherAnalysisUuid = randomAlphabetic(12);
+ BranchDto noManualBaselineDto = ComponentTesting.newBranchDto(db.components().insertPrivateProject(), branchType);
+ BranchDto withManualBaselineDto = ComponentTesting.newBranchDto(db.components().insertPrivateProject(), branchType).setManualBaseline(analysisUuid);
+ underTest.insert(dbSession, noManualBaselineDto);
+ underTest.insert(dbSession, withManualBaselineDto);
+ dbSession.commit();
+
+ assertThat(underTest.updateManualBaseline(dbSession, noManualBaselineDto.getUuid(), null)).isZero();
+ assertThat(underTest.updateManualBaseline(dbSession, noManualBaselineDto.getUuid(), otherAnalysisUuid)).isZero();
+ assertThat(underTest.updateManualBaseline(dbSession, withManualBaselineDto.getUuid(), null)).isZero();
+ assertThat(underTest.updateManualBaseline(dbSession, withManualBaselineDto.getUuid(), otherAnalysisUuid)).isZero();
}
@DataProvider
- public static Object[][] modeAndNonLongBranchType() {
+ public static Object[][] nonLongBranchType() {
return new Object[][] {
- {true, BranchType.SHORT},
- {true, BranchType.PULL_REQUEST},
- {false, BranchType.SHORT},
- {false, BranchType.PULL_REQUEST},
+ {BranchType.SHORT},
+ {BranchType.PULL_REQUEST}
};
}
- @Test
- public void isBaselineManual_returns_false_when_column_is_null() {
- BranchDto dto = new BranchDto();
- dto.setProjectUuid("U1");
- dto.setUuid("U1");
- dto.setBranchType(BranchType.LONG);
- dto.setKey("foo");
- dto.setBaseline("a-uuid", true);
- underTest.insert(dbSession, dto);
- db.commit();
-
- db.executeUpdateSql("update project_branches set baseline_manual = null");
-
- BranchDto loaded = underTest.selectByUuid(dbSession, dto.getUuid()).get();
- assertThat(loaded.isBaselineManual()).isEqualTo(false);
- }
-
@Test
public void insert_branch_with_all_fields_and_max_length_values() {
BranchDto dto = new BranchDto();
featureBranch.setBranchType(BranchType.SHORT);
featureBranch.setKey("feature/foo");
featureBranch.setMergeBranchUuid("U3");
+ featureBranch.setManualBaseline("analysisUUID");
underTest.insert(dbSession, featureBranch);
// select the feature branch
assertThat(loaded.getProjectUuid()).isEqualTo(featureBranch.getProjectUuid());
assertThat(loaded.getBranchType()).isEqualTo(featureBranch.getBranchType());
assertThat(loaded.getMergeBranchUuid()).isEqualTo(featureBranch.getMergeBranchUuid());
+ assertThat(loaded.getManualBaseline()).isEqualTo(featureBranch.getManualBaseline());
// select a branch on another project with same branch name
assertThat(underTest.selectByBranchKey(dbSession, "U3", "feature/foo")).isEmpty();
pullRequest.setBranchType(BranchType.PULL_REQUEST);
pullRequest.setKey(pullRequestId);
pullRequest.setMergeBranchUuid("U3");
+ pullRequest.setManualBaseline("analysisUUID");
underTest.insert(dbSession, pullRequest);
// select the feature branch
assertThat(loaded.getProjectUuid()).isEqualTo(pullRequest.getProjectUuid());
assertThat(loaded.getBranchType()).isEqualTo(pullRequest.getBranchType());
assertThat(loaded.getMergeBranchUuid()).isEqualTo(pullRequest.getMergeBranchUuid());
+ assertThat(loaded.getManualBaseline()).isEqualTo(pullRequest.getManualBaseline());
// select a branch on another project with same branch name
assertThat(underTest.selectByPullRequestKey(dbSession, "U3", pullRequestId)).isEmpty();