public class ProjectAttributes { | public class ProjectAttributes { | ||||
private final String projectVersion; | private final String projectVersion; | ||||
private final String codePeriodVersion; | |||||
@Nullable | |||||
private final String buildString; | private final String buildString; | ||||
public ProjectAttributes(@Nullable String projectVersion, String codePeriodVersion, String buildString) { | |||||
this.projectVersion = projectVersion; | |||||
this.codePeriodVersion = requireNonNull(codePeriodVersion, "codePeriod version can't be null"); | |||||
public ProjectAttributes(String projectVersion, @Nullable String buildString) { | |||||
this.projectVersion = requireNonNull(projectVersion, "project version can't be null"); | |||||
this.buildString = buildString; | this.buildString = buildString; | ||||
} | } | ||||
public ProjectAttributes(ProjectAttributes projectAttributes) { | public ProjectAttributes(ProjectAttributes projectAttributes) { | ||||
this.projectVersion = projectAttributes.projectVersion; | this.projectVersion = projectAttributes.projectVersion; | ||||
this.codePeriodVersion = projectAttributes.codePeriodVersion; | |||||
this.buildString = projectAttributes.buildString; | this.buildString = projectAttributes.buildString; | ||||
} | } | ||||
public Optional<String> getProjectVersion() { | |||||
return Optional.ofNullable(projectVersion); | |||||
} | |||||
public String getCodePeriodVersion() { | |||||
return codePeriodVersion; | |||||
public String getProjectVersion() { | |||||
return projectVersion; | |||||
} | } | ||||
public Optional<String> getBuildString() { | public Optional<String> getBuildString() { | ||||
public String toString() { | public String toString() { | ||||
return "ProjectAttributes{" + | return "ProjectAttributes{" + | ||||
"projectVersion='" + projectVersion + '\'' + | "projectVersion='" + projectVersion + '\'' + | ||||
"codePeriodVersion='" + codePeriodVersion + '\'' + | |||||
"buildString='" + buildString + '\'' + | "buildString='" + buildString + '\'' + | ||||
'}'; | '}'; | ||||
} | } |
} | } | ||||
private static ProjectAttributes createProjectAttributes(ScannerReport.Metadata metadata, @Nullable SnapshotDto baseAnalysis) { | private static ProjectAttributes createProjectAttributes(ScannerReport.Metadata metadata, @Nullable SnapshotDto baseAnalysis) { | ||||
String projectVersion = trimToNull(metadata.getProjectVersion()); | |||||
String codePeriodVersion = computeCodePeriodVersion(metadata.getCodePeriodVersion(), projectVersion, baseAnalysis); | |||||
String projectVersion = computeProjectVersion(trimToNull(metadata.getProjectVersion()), baseAnalysis); | |||||
String buildString = trimToNull(metadata.getBuildString()); | String buildString = trimToNull(metadata.getBuildString()); | ||||
return new ProjectAttributes(projectVersion, codePeriodVersion, buildString); | |||||
return new ProjectAttributes(projectVersion, buildString); | |||||
} | } | ||||
private static String computeCodePeriodVersion(String rawCodePeriodVersion, @Nullable String projectVersion, @Nullable SnapshotDto baseAnalysis) { | |||||
String codePeriodVersion = trimToNull(rawCodePeriodVersion); | |||||
if (codePeriodVersion != null) { | |||||
return codePeriodVersion; | |||||
} | |||||
// support case (legacy but not forbidden) where only projectVersion is set | |||||
private static String computeProjectVersion(@Nullable String projectVersion, @Nullable SnapshotDto baseAnalysis) { | |||||
if (projectVersion != null) { | if (projectVersion != null) { | ||||
return projectVersion; | return projectVersion; | ||||
} | } | ||||
if (baseAnalysis != null) { | if (baseAnalysis != null) { | ||||
return firstNonNull(baseAnalysis.getCodePeriodVersion(), DEFAULT_PROJECT_VERSION); | |||||
return firstNonNull(baseAnalysis.getProjectVersion(), DEFAULT_PROJECT_VERSION); | |||||
} | } | ||||
return DEFAULT_PROJECT_VERSION; | return DEFAULT_PROJECT_VERSION; | ||||
} | } |
} | } | ||||
private Optional<Period> resolvePeriod(Component projectOrView) { | private Optional<Period> resolvePeriod(Component projectOrView) { | ||||
String currentVersion = projectOrView.getProjectAttributes().getCodePeriodVersion(); | |||||
String currentVersion = projectOrView.getProjectAttributes().getProjectVersion(); | |||||
Optional<String> propertyValue = configRepository.getConfiguration().get(LEAK_PERIOD) | Optional<String> propertyValue = configRepository.getConfiguration().get(LEAK_PERIOD) | ||||
.filter(t -> !t.isEmpty()); | .filter(t -> !t.isEmpty()); | ||||
checkPeriodProperty(propertyValue.isPresent(), "", "property is undefined or value is empty"); | checkPeriodProperty(propertyValue.isPresent(), "", "property is undefined or value is empty"); |
private SnapshotDto createAnalysis(String snapshotUuid, Component component) { | private SnapshotDto createAnalysis(String snapshotUuid, Component component) { | ||||
String componentUuid = component.getUuid(); | String componentUuid = component.getUuid(); | ||||
String codePeriodVersion = component.getType() == PROJECT ? component.getProjectAttributes().getCodePeriodVersion() : null; | |||||
String projectVersion = component.getType() == PROJECT ? component.getProjectAttributes().getProjectVersion().orElse(null) : null; | |||||
String projectVersion = component.getType() == PROJECT ? component.getProjectAttributes().getProjectVersion() : null; | |||||
String buildString = component.getType() == PROJECT ? component.getProjectAttributes().getBuildString().orElse(null) : null; | String buildString = component.getType() == PROJECT ? component.getProjectAttributes().getBuildString().orElse(null) : null; | ||||
return new SnapshotDto() | return new SnapshotDto() | ||||
.setUuid(snapshotUuid) | .setUuid(snapshotUuid) | ||||
.setCodePeriodVersion(codePeriodVersion) | |||||
.setProjectVersion(projectVersion) | .setProjectVersion(projectVersion) | ||||
.setBuildString(buildString) | .setBuildString(buildString) | ||||
.setComponentUuid(componentUuid) | .setComponentUuid(componentUuid) |
} | } | ||||
private void saveVersionEvent(DbSession session, Component component, Long analysisDate) { | private void saveVersionEvent(DbSession session, Component component, Long analysisDate) { | ||||
String codePeriodVersion = component.getProjectAttributes().getCodePeriodVersion(); | |||||
deletePreviousEventsHavingSameVersion(session, codePeriodVersion, component); | |||||
String projectVersion = component.getProjectAttributes().getProjectVersion(); | |||||
deletePreviousEventsHavingSameVersion(session, projectVersion, component); | |||||
dbClient.eventDao().insert(session, newBaseEvent(component, analysisDate) | dbClient.eventDao().insert(session, newBaseEvent(component, analysisDate) | ||||
.setName(codePeriodVersion) | |||||
.setName(projectVersion) | |||||
.setCategory(EventDto.CATEGORY_VERSION)); | .setCategory(EventDto.CATEGORY_VERSION)); | ||||
} | } | ||||
.setDefaultMessage(String.format("Alert on %s: %s", project.getName(), label)) | .setDefaultMessage(String.format("Alert on %s: %s", project.getName(), label)) | ||||
.setFieldValue("projectName", project.getName()) | .setFieldValue("projectName", project.getName()) | ||||
.setFieldValue("projectKey", project.getKey()) | .setFieldValue("projectKey", project.getKey()) | ||||
.setFieldValue("codePeriodVersion", project.getProjectAttributes().getCodePeriodVersion()) | |||||
.setFieldValue("projectVersion", project.getProjectAttributes().getProjectVersion()) | |||||
.setFieldValue("alertName", label) | .setFieldValue("alertName", label) | ||||
.setFieldValue("alertText", rawStatus.getText()) | .setFieldValue("alertText", rawStatus.getText()) | ||||
.setFieldValue("alertLevel", rawStatus.getStatus().toString()) | .setFieldValue("alertLevel", rawStatus.getStatus().toString()) |
NewIssuesNotification notification = newIssuesNotificationFactory | NewIssuesNotification notification = newIssuesNotificationFactory | ||||
.newNewIssuesNotification() | .newNewIssuesNotification() | ||||
.setProject(project.getKey(), project.getName(), getBranchName(), getPullRequest()) | .setProject(project.getKey(), project.getName(), getBranchName(), getPullRequest()) | ||||
.setCodePeriodVersion(project.getProjectAttributes().getCodePeriodVersion()) | |||||
.setProjectVersion(project.getProjectAttributes().getProjectVersion()) | |||||
.setAnalysisDate(new Date(analysisDate)) | .setAnalysisDate(new Date(analysisDate)) | ||||
.setStatistics(project.getName(), globalStatistics) | .setStatistics(project.getName(), globalStatistics) | ||||
.setDebt(Duration.create(globalStatistics.effort().getOnLeak())); | .setDebt(Duration.create(globalStatistics.effort().getOnLeak())); | ||||
.setAssignee(userDtoByUuid.get(assigneeUuid)); | .setAssignee(userDtoByUuid.get(assigneeUuid)); | ||||
myNewIssuesNotification | myNewIssuesNotification | ||||
.setProject(project.getKey(), project.getName(), getBranchName(), getPullRequest()) | .setProject(project.getKey(), project.getName(), getBranchName(), getPullRequest()) | ||||
.setCodePeriodVersion(project.getProjectAttributes().getCodePeriodVersion()) | |||||
.setProjectVersion(project.getProjectAttributes().getProjectVersion()) | |||||
.setAnalysisDate(new Date(analysisDate)) | .setAnalysisDate(new Date(analysisDate)) | ||||
.setStatistics(project.getName(), assigneeStatistics) | .setStatistics(project.getName(), assigneeStatistics) | ||||
.setDebt(Duration.create(assigneeStatistics.effort().getOnLeak())); | .setDebt(Duration.create(assigneeStatistics.effort().getOnLeak())); |
.setReportAttributes(ReportAttributes.newBuilder(dbKey.hashCode()).build()); | .setReportAttributes(ReportAttributes.newBuilder(dbKey.hashCode()).build()); | ||||
if (type == PROJECT) { | if (type == PROJECT) { | ||||
String buildString = randomAlphabetic(15); | String buildString = randomAlphabetic(15); | ||||
builder.setProjectAttributes(new ProjectAttributes(null, "version_1", buildString)); | |||||
builder.setProjectAttributes(new ProjectAttributes("version_1", buildString)); | |||||
} | } | ||||
return builder; | return builder; | ||||
} | } |
*/ | */ | ||||
package org.sonar.ce.task.projectanalysis.component; | package org.sonar.ce.task.projectanalysis.component; | ||||
import com.tngtech.java.junit.dataprovider.DataProvider; | |||||
import com.tngtech.java.junit.dataprovider.DataProviderRunner; | |||||
import com.tngtech.java.junit.dataprovider.UseDataProvider; | |||||
import java.util.Arrays; | import java.util.Arrays; | ||||
import java.util.EnumSet; | import java.util.EnumSet; | ||||
import java.util.HashMap; | import java.util.HashMap; | ||||
import java.util.Optional; | import java.util.Optional; | ||||
import java.util.Random; | import java.util.Random; | ||||
import java.util.function.Function; | import java.util.function.Function; | ||||
import javax.annotation.Nullable; | |||||
import org.junit.Rule; | import org.junit.Rule; | ||||
import org.junit.Test; | import org.junit.Test; | ||||
import org.junit.rules.ExpectedException; | import org.junit.rules.ExpectedException; | ||||
import org.junit.rules.ExternalResource; | import org.junit.rules.ExternalResource; | ||||
import org.junit.runner.RunWith; | |||||
import org.sonar.ce.task.projectanalysis.analysis.Branch; | import org.sonar.ce.task.projectanalysis.analysis.Branch; | ||||
import org.sonar.core.component.ComponentKeys; | import org.sonar.core.component.ComponentKeys; | ||||
import org.sonar.scanner.protocol.output.ScannerReport; | import org.sonar.scanner.protocol.output.ScannerReport; | ||||
import static org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType.UNRECOGNIZED; | import static org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType.UNRECOGNIZED; | ||||
import static org.sonar.scanner.protocol.output.ScannerReport.Component.newBuilder; | import static org.sonar.scanner.protocol.output.ScannerReport.Component.newBuilder; | ||||
@RunWith(DataProviderRunner.class) | |||||
public class ComponentTreeBuilderTest { | public class ComponentTreeBuilderTest { | ||||
private static final ComponentKeyGenerator KEY_GENERATOR = (projectKey, path) -> "generated_" | private static final ComponentKeyGenerator KEY_GENERATOR = (projectKey, path) -> "generated_" | ||||
private static final String NO_SCM_BASE_PATH = ""; | private static final String NO_SCM_BASE_PATH = ""; | ||||
// both no project as "" or null should be supported | // both no project as "" or null should be supported | ||||
private static final ProjectAttributes SOME_PROJECT_ATTRIBUTES = new ProjectAttributes( | private static final ProjectAttributes SOME_PROJECT_ATTRIBUTES = new ProjectAttributes( | ||||
new Random().nextBoolean() ? null : randomAlphabetic(12), | |||||
randomAlphabetic(20), randomAlphabetic(21)); | |||||
randomAlphabetic(20), new Random().nextBoolean() ? null : randomAlphabetic(12)); | |||||
@Rule | @Rule | ||||
public ExpectedException expectedException = ExpectedException.none(); | public ExpectedException expectedException = ExpectedException.none(); | ||||
} | } | ||||
@Test | @Test | ||||
@UseDataProvider("projectVersionOrNull") | |||||
public void by_default_project_fields_are_loaded_from_report(@Nullable String projectVersion) { | |||||
public void by_default_project_fields_are_loaded_from_report() { | |||||
String nameInReport = "the name"; | String nameInReport = "the name"; | ||||
String descriptionInReport = "the desc"; | String descriptionInReport = "the desc"; | ||||
String buildString = randomAlphabetic(21); | String buildString = randomAlphabetic(21); | ||||
.setRef(42) | .setRef(42) | ||||
.setName(nameInReport) | .setName(nameInReport) | ||||
.setDescription(descriptionInReport) | .setDescription(descriptionInReport) | ||||
.build(), NO_SCM_BASE_PATH, new ProjectAttributes(projectVersion, "6.5", buildString)); | |||||
.build(), NO_SCM_BASE_PATH, new ProjectAttributes("6.5", buildString)); | |||||
assertThat(root.getUuid()).isEqualTo("generated_K1_uuid"); | assertThat(root.getUuid()).isEqualTo("generated_K1_uuid"); | ||||
assertThat(root.getDbKey()).isEqualTo("generated_K1"); | assertThat(root.getDbKey()).isEqualTo("generated_K1"); | ||||
assertThat(root.getShortName()).isEqualTo(nameInReport); | assertThat(root.getShortName()).isEqualTo(nameInReport); | ||||
assertThat(root.getDescription()).isEqualTo(descriptionInReport); | assertThat(root.getDescription()).isEqualTo(descriptionInReport); | ||||
assertThat(root.getReportAttributes().getRef()).isEqualTo(42); | assertThat(root.getReportAttributes().getRef()).isEqualTo(42); | ||||
if (projectVersion == null) { | |||||
assertThat(root.getProjectAttributes().getProjectVersion()).isEmpty(); | |||||
} else { | |||||
assertThat(root.getProjectAttributes().getProjectVersion()).contains(projectVersion); | |||||
} | |||||
assertThat(root.getProjectAttributes().getCodePeriodVersion()).isEqualTo("6.5"); | |||||
assertThat(root.getProjectAttributes().getProjectVersion()).contains("6.5"); | |||||
assertThat(root.getProjectAttributes().getBuildString()).isEqualTo(Optional.of(buildString)); | assertThat(root.getProjectAttributes().getBuildString()).isEqualTo(Optional.of(buildString)); | ||||
assertThatFileAttributesAreNotSet(root); | assertThatFileAttributesAreNotSet(root); | ||||
} | } | ||||
@DataProvider | |||||
public static Object[][] projectVersionOrNull() { | |||||
return new Object[][] { | |||||
{null}, | |||||
{randomAlphabetic(15)} | |||||
}; | |||||
} | |||||
@Test | @Test | ||||
public void project_name_is_loaded_from_db_if_absent_from_report() { | public void project_name_is_loaded_from_db_if_absent_from_report() { | ||||
Component root = call(newBuilder() | Component root = call(newBuilder() |
.setPublicKey("PUBLIC_PROJECT_KEY") | .setPublicKey("PUBLIC_PROJECT_KEY") | ||||
.setUuid("PROJECT_UUID") | .setUuid("PROJECT_UUID") | ||||
.setName("Project Name") | .setName("Project Name") | ||||
.setCodePeriodVersion("1.0-SNAPSHOT") | |||||
.setProjectVersion("1.0-SNAPSHOT") | |||||
.build(); | .build(); | ||||
private final Type type; | private final Type type; | ||||
this.shortName = builder.shortName == null ? this.name : builder.shortName; | this.shortName = builder.shortName == null ? this.name : builder.shortName; | ||||
this.description = builder.description; | this.description = builder.description; | ||||
this.uuid = builder.uuid; | this.uuid = builder.uuid; | ||||
this.projectAttributes = Optional.ofNullable(builder.codePeriodVersion) | |||||
.map(t -> new ProjectAttributes(builder.projectVersion, t, builder.buildString)) | |||||
this.projectAttributes = Optional.ofNullable(builder.projectVersion) | |||||
.map(v -> new ProjectAttributes(v, builder.buildString)) | |||||
.orElse(null); | .orElse(null); | ||||
this.reportAttributes = ReportAttributes.newBuilder(builder.ref) | this.reportAttributes = ReportAttributes.newBuilder(builder.ref) | ||||
.build(); | .build(); | ||||
private String publicKey; | private String publicKey; | ||||
private String name; | private String name; | ||||
private String shortName; | private String shortName; | ||||
private String codePeriodVersion; | |||||
private String projectVersion; | private String projectVersion; | ||||
private String buildString; | private String buildString; | ||||
private String description; | private String description; | ||||
this.type = type; | this.type = type; | ||||
this.ref = ref; | this.ref = ref; | ||||
if (type == Type.PROJECT) { | if (type == Type.PROJECT) { | ||||
this.codePeriodVersion = "toBeDefined"; | |||||
this.projectVersion = "toBeDefined"; | |||||
} | } | ||||
} | } | ||||
return this; | return this; | ||||
} | } | ||||
public Builder setCodePeriodVersion(String s) { | |||||
checkArgument(type != Type.PROJECT ^ s != null, "CodePeriod version must and can only be set on Project"); | |||||
this.codePeriodVersion = s; | |||||
return this; | |||||
} | |||||
public Builder setProjectVersion(@Nullable String projectVersion) { | |||||
this.projectVersion = projectVersion; | |||||
public Builder setProjectVersion(@Nullable String s) { | |||||
checkProjectVersion(s); | |||||
this.projectVersion = s; | |||||
return this; | return this; | ||||
} | } | ||||
public Builder setBuildString(@Nullable String buildString) { | public Builder setBuildString(@Nullable String buildString) { | ||||
checkBuildString(buildString); | |||||
this.buildString = buildString; | this.buildString = buildString; | ||||
return this; | return this; | ||||
} | } | ||||
} | } | ||||
public ReportComponent build() { | public ReportComponent build() { | ||||
checkArgument(type != Type.PROJECT ^ this.codePeriodVersion != null, "CodePeriod version must and can only be set on Project"); | |||||
checkArgument(type == Type.PROJECT || this.buildString == null, "BuildString can only be set on Project"); | |||||
checkProjectVersion(this.projectVersion); | |||||
checkBuildString(this.buildString); | |||||
return new ReportComponent(this); | return new ReportComponent(this); | ||||
} | } | ||||
private void checkProjectVersion(@Nullable String s) { | |||||
checkArgument(type != Type.PROJECT ^ s != null, "Project version must and can only be set on Project"); | |||||
} | |||||
private void checkBuildString(@Nullable String s) { | |||||
checkArgument(type == Type.PROJECT || s == null, "BuildString can only be set on Project"); | |||||
} | |||||
} | } | ||||
} | } |
@RunWith(DataProviderRunner.class) | @RunWith(DataProviderRunner.class) | ||||
public class BuildComponentTreeStepTest { | public class BuildComponentTreeStepTest { | ||||
private static final String NO_SCANNER_PROJECT_VERSION = null; | private static final String NO_SCANNER_PROJECT_VERSION = null; | ||||
private static final String NO_SCANNER_CODE_PERIOD_VERSION = null; | |||||
private static final String NO_SCANNER_BUILD_STRING = null; | |||||
private static final int ROOT_REF = 1; | private static final int ROOT_REF = 1; | ||||
private static final int FILE_1_REF = 4; | private static final int FILE_1_REF = 4; | ||||
@Rule | @Rule | ||||
public DbTester dbTester = DbTester.create(System2.INSTANCE); | public DbTester dbTester = DbTester.create(System2.INSTANCE); | ||||
@Rule | @Rule | ||||
public BatchReportReaderRule reportReader = new BatchReportReaderRule().setMetadata(createReportMetadata(NO_SCANNER_PROJECT_VERSION, NO_SCANNER_CODE_PERIOD_VERSION)); | |||||
public BatchReportReaderRule reportReader = new BatchReportReaderRule().setMetadata(createReportMetadata(NO_SCANNER_PROJECT_VERSION, NO_SCANNER_BUILD_STRING)); | |||||
@Rule | @Rule | ||||
public MutableTreeRootHolderRule treeRootHolder = new MutableTreeRootHolderRule(); | public MutableTreeRootHolderRule treeRootHolder = new MutableTreeRootHolderRule(); | ||||
@Rule | @Rule | ||||
} | } | ||||
@Test | @Test | ||||
public void set_codePeriodVersion_to_not_provided_when_both_codePeriod_and_project_version_are_not_set_on_first_analysis() { | |||||
public void set_projectVersion_to_not_provided_when_not_set_on_first_analysis() { | |||||
setAnalysisMetadataHolder(); | setAnalysisMetadataHolder(); | ||||
reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY)); | reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY)); | ||||
underTest.execute(new TestComputationStepContext()); | underTest.execute(new TestComputationStepContext()); | ||||
assertThat(treeRootHolder.getReportTreeRoot().getProjectAttributes().getCodePeriodVersion()).isEqualTo("not provided"); | |||||
assertThat(treeRootHolder.getReportTreeRoot().getProjectAttributes().getProjectVersion()).isEqualTo("not provided"); | |||||
} | } | ||||
@Test | @Test | ||||
@UseDataProvider("oneParameterNullNonNullCombinations") | @UseDataProvider("oneParameterNullNonNullCombinations") | ||||
public void set_codePeriodVersion_to_previous_analysis_codePeriodVersion_when_both_codePeriod_and_project_version_are_not_set( | |||||
@Nullable String previousAnalysisCodePeriodVersion) { | |||||
public void set_projectVersion_to_previous_analysis_when_not_set(@Nullable String previousAnalysisProjectVersion) { | |||||
setAnalysisMetadataHolder(); | setAnalysisMetadataHolder(); | ||||
OrganizationDto organizationDto = dbTester.organizations().insert(); | OrganizationDto organizationDto = dbTester.organizations().insert(); | ||||
ComponentDto project = insertComponent(newPrivateProjectDto(organizationDto, "ABCD").setDbKey(REPORT_PROJECT_KEY)); | ComponentDto project = insertComponent(newPrivateProjectDto(organizationDto, "ABCD").setDbKey(REPORT_PROJECT_KEY)); | ||||
insertSnapshot(newAnalysis(project).setCodePeriodVersion(previousAnalysisCodePeriodVersion).setLast(true)); | |||||
insertSnapshot(newAnalysis(project).setProjectVersion(previousAnalysisProjectVersion).setLast(true)); | |||||
reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY)); | reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY)); | ||||
underTest.execute(new TestComputationStepContext()); | underTest.execute(new TestComputationStepContext()); | ||||
String codePeriodVersion = treeRootHolder.getReportTreeRoot().getProjectAttributes().getCodePeriodVersion(); | |||||
if (previousAnalysisCodePeriodVersion == null) { | |||||
assertThat(codePeriodVersion).isEqualTo("not provided"); | |||||
String projectVersion = treeRootHolder.getReportTreeRoot().getProjectAttributes().getProjectVersion(); | |||||
if (previousAnalysisProjectVersion == null) { | |||||
assertThat(projectVersion).isEqualTo("not provided"); | |||||
} else { | } else { | ||||
assertThat(codePeriodVersion).isEqualTo(previousAnalysisCodePeriodVersion); | |||||
assertThat(projectVersion).isEqualTo(previousAnalysisProjectVersion); | |||||
} | } | ||||
} | } | ||||
@Test | @Test | ||||
public void set_codePeriodVersion_to_projectVersion_when_codePeriodVersion_is_unset_and_projectVersion_is_set_on_first_analysis() { | |||||
public void set_projectVersion_when_it_is_set_on_first_analysis() { | |||||
String scannerProjectVersion = randomAlphabetic(12); | String scannerProjectVersion = randomAlphabetic(12); | ||||
setAnalysisMetadataHolder(); | setAnalysisMetadataHolder(); | ||||
reportReader.setMetadata(createReportMetadata(scannerProjectVersion, NO_SCANNER_CODE_PERIOD_VERSION)); | |||||
reportReader.setMetadata(createReportMetadata(scannerProjectVersion, NO_SCANNER_BUILD_STRING)); | |||||
reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY)); | reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY)); | ||||
underTest.execute(new TestComputationStepContext()); | underTest.execute(new TestComputationStepContext()); | ||||
assertThat(treeRootHolder.getReportTreeRoot().getProjectAttributes().getCodePeriodVersion()) | |||||
assertThat(treeRootHolder.getReportTreeRoot().getProjectAttributes().getProjectVersion()) | |||||
.isEqualTo(scannerProjectVersion); | .isEqualTo(scannerProjectVersion); | ||||
} | } | ||||
@Test | @Test | ||||
@UseDataProvider("oneParameterNullNonNullCombinations") | @UseDataProvider("oneParameterNullNonNullCombinations") | ||||
public void set_codePeriodVersion_to_projectVersion_when_codePeriodVersion_is_unset_and_projectVersion_is_set_on_later_analysis( | |||||
@Nullable String previousAnalysisCodePeriodVersion) { | |||||
public void set_projectVersion_when_it_is_set_on_later_analysis(@Nullable String previousAnalysisProjectVersion) { | |||||
String scannerProjectVersion = randomAlphabetic(12); | String scannerProjectVersion = randomAlphabetic(12); | ||||
setAnalysisMetadataHolder(); | setAnalysisMetadataHolder(); | ||||
reportReader.setMetadata(createReportMetadata(scannerProjectVersion, NO_SCANNER_CODE_PERIOD_VERSION)); | |||||
reportReader.setMetadata(createReportMetadata(scannerProjectVersion, NO_SCANNER_BUILD_STRING)); | |||||
OrganizationDto organizationDto = dbTester.organizations().insert(); | OrganizationDto organizationDto = dbTester.organizations().insert(); | ||||
ComponentDto project = insertComponent(newPrivateProjectDto(organizationDto, "ABCD").setDbKey(REPORT_PROJECT_KEY)); | ComponentDto project = insertComponent(newPrivateProjectDto(organizationDto, "ABCD").setDbKey(REPORT_PROJECT_KEY)); | ||||
insertSnapshot(newAnalysis(project).setCodePeriodVersion(previousAnalysisCodePeriodVersion).setLast(true)); | |||||
insertSnapshot(newAnalysis(project).setProjectVersion(previousAnalysisProjectVersion).setLast(true)); | |||||
reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY)); | reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY)); | ||||
underTest.execute(new TestComputationStepContext()); | underTest.execute(new TestComputationStepContext()); | ||||
assertThat(treeRootHolder.getReportTreeRoot().getProjectAttributes().getCodePeriodVersion()) | |||||
assertThat(treeRootHolder.getReportTreeRoot().getProjectAttributes().getProjectVersion()) | |||||
.isEqualTo(scannerProjectVersion); | .isEqualTo(scannerProjectVersion); | ||||
} | } | ||||
@Test | |||||
@UseDataProvider("oneParameterNullNonNullCombinations") | |||||
public void set_codePeriodVersion_to_codePeriodVersion_when_it_is_set_on_first_analysis(@Nullable String projectVersion) { | |||||
String scannerCodePeriodVersion = randomAlphabetic(12); | |||||
setAnalysisMetadataHolder(); | |||||
reportReader.setMetadata(createReportMetadata(projectVersion, scannerCodePeriodVersion)); | |||||
reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY)); | |||||
underTest.execute(new TestComputationStepContext()); | |||||
assertThat(treeRootHolder.getReportTreeRoot().getProjectAttributes().getCodePeriodVersion()) | |||||
.isEqualTo(scannerCodePeriodVersion); | |||||
} | |||||
@Test | |||||
@UseDataProvider("twoParametersNullNonNullCombinations") | |||||
public void set_codePeriodVersion_to_codePeriodVersion_when_it_is_set_on_later_analysis(@Nullable String projectVersion, @Nullable String previousAnalysisCodePeriodVersion) { | |||||
String scannerCodePeriodVersion = randomAlphabetic(12); | |||||
setAnalysisMetadataHolder(); | |||||
reportReader.setMetadata(createReportMetadata(projectVersion, scannerCodePeriodVersion)); | |||||
OrganizationDto organizationDto = dbTester.organizations().insert(); | |||||
ComponentDto project = insertComponent(newPrivateProjectDto(organizationDto, "ABCD").setDbKey(REPORT_PROJECT_KEY)); | |||||
insertSnapshot(newAnalysis(project).setCodePeriodVersion(previousAnalysisCodePeriodVersion).setLast(true)); | |||||
reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY)); | |||||
underTest.execute(new TestComputationStepContext()); | |||||
assertThat(treeRootHolder.getReportTreeRoot().getProjectAttributes().getCodePeriodVersion()) | |||||
.isEqualTo(scannerCodePeriodVersion); | |||||
} | |||||
@Test | |||||
@UseDataProvider("oneParameterNullNonNullCombinations") | |||||
public void set_projectVersion_to_null_when_projectVersion_is_unset_on_first_analysis(@Nullable String codePeriodVersion) { | |||||
setAnalysisMetadataHolder(); | |||||
reportReader.setMetadata(createReportMetadata(NO_SCANNER_PROJECT_VERSION, codePeriodVersion)); | |||||
reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY)); | |||||
underTest.execute(new TestComputationStepContext()); | |||||
assertThat(treeRootHolder.getReportTreeRoot().getProjectAttributes().getProjectVersion()).isEmpty(); | |||||
} | |||||
@Test | |||||
@UseDataProvider("twoParametersNullNonNullCombinations") | |||||
public void set_projectVersion_to_null_when_projectVersion_is_unset_on_later_analysis(@Nullable String codePeriodVersion, @Nullable String previousAnalysisCodePeriodVersion) { | |||||
setAnalysisMetadataHolder(); | |||||
reportReader.setMetadata(createReportMetadata(NO_SCANNER_PROJECT_VERSION, codePeriodVersion)); | |||||
OrganizationDto organizationDto = dbTester.organizations().insert(); | |||||
ComponentDto project = insertComponent(newPrivateProjectDto(organizationDto, "ABCD").setDbKey(REPORT_PROJECT_KEY)); | |||||
insertSnapshot(newAnalysis(project).setCodePeriodVersion(previousAnalysisCodePeriodVersion).setLast(true)); | |||||
reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY)); | |||||
underTest.execute(new TestComputationStepContext()); | |||||
assertThat(treeRootHolder.getReportTreeRoot().getProjectAttributes().getProjectVersion()).isEmpty(); | |||||
} | |||||
@Test | |||||
@UseDataProvider("oneParameterNullNonNullCombinations") | |||||
public void set_projectVersion_to_projectVersion_when_projectVersion_is_set_on_first_analysis(@Nullable String codePeriodVersion) { | |||||
String projectVersion = randomAlphabetic(7); | |||||
setAnalysisMetadataHolder(); | |||||
reportReader.setMetadata(createReportMetadata(projectVersion, codePeriodVersion)); | |||||
reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY)); | |||||
underTest.execute(new TestComputationStepContext()); | |||||
assertThat(treeRootHolder.getReportTreeRoot().getProjectAttributes().getProjectVersion()).contains(projectVersion); | |||||
} | |||||
@Test | |||||
@UseDataProvider("twoParametersNullNonNullCombinations") | |||||
public void set_projectVersion_to_projectVersion_when_projectVersion_is_set_on_later_analysis(@Nullable String codePeriodVersion, | |||||
@Nullable String previousAnalysisCodePeriodVersion) { | |||||
String projectVersion = randomAlphabetic(7); | |||||
setAnalysisMetadataHolder(); | |||||
reportReader.setMetadata(createReportMetadata(projectVersion, codePeriodVersion)); | |||||
OrganizationDto organizationDto = dbTester.organizations().insert(); | |||||
ComponentDto project = insertComponent(newPrivateProjectDto(organizationDto, "ABCD").setDbKey(REPORT_PROJECT_KEY)); | |||||
insertSnapshot(newAnalysis(project).setCodePeriodVersion(previousAnalysisCodePeriodVersion).setLast(true)); | |||||
reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY)); | |||||
underTest.execute(new TestComputationStepContext()); | |||||
assertThat(treeRootHolder.getReportTreeRoot().getProjectAttributes().getProjectVersion()).contains(projectVersion); | |||||
} | |||||
@Test | @Test | ||||
@UseDataProvider("oneParameterNullNonNullCombinations") | @UseDataProvider("oneParameterNullNonNullCombinations") | ||||
public void set_buildString(@Nullable String buildString) { | public void set_buildString(@Nullable String buildString) { | ||||
String projectVersion = randomAlphabetic(7); | String projectVersion = randomAlphabetic(7); | ||||
String codePeriodVersion = randomAlphabetic(8); | |||||
setAnalysisMetadataHolder(); | setAnalysisMetadataHolder(); | ||||
reportReader.setMetadata(createReportMetadata(projectVersion, codePeriodVersion, buildString)); | |||||
reportReader.setMetadata(createReportMetadata(projectVersion, buildString)); | |||||
reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY)); | reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY)); | ||||
underTest.execute(new TestComputationStepContext()); | underTest.execute(new TestComputationStepContext()); | ||||
}; | }; | ||||
} | } | ||||
@DataProvider | |||||
public static Object[][] twoParametersNullNonNullCombinations() { | |||||
return new Object[][] { | |||||
{null, null}, | |||||
{randomAlphabetic(7), null}, | |||||
{null, randomAlphabetic(8)}, | |||||
{randomAlphabetic(9), randomAlphabetic(10)} | |||||
}; | |||||
} | |||||
private void verifyComponent(Component component, Component.Type type, @Nullable Integer componentRef, int size) { | private void verifyComponent(Component component, Component.Type type, @Nullable Integer componentRef, int size) { | ||||
assertThat(component.getType()).isEqualTo(type); | assertThat(component.getType()).isEqualTo(type); | ||||
assertThat(component.getReportAttributes().getRef()).isEqualTo(componentRef); | assertThat(component.getReportAttributes().getRef()).isEqualTo(componentRef); | ||||
.setProject(Project.from(newPrivateProjectDto(newOrganizationDto()).setDbKey(REPORT_PROJECT_KEY))); | .setProject(Project.from(newPrivateProjectDto(newOrganizationDto()).setDbKey(REPORT_PROJECT_KEY))); | ||||
} | } | ||||
public static ScannerReport.Metadata createReportMetadata(@Nullable String projectVersion, @Nullable String scannerCodePeriodVersion) { | |||||
return createReportMetadata(projectVersion, scannerCodePeriodVersion, null); | |||||
} | |||||
public static ScannerReport.Metadata createReportMetadata(@Nullable String projectVersion, @Nullable String scannerCodePeriodVersion, @Nullable String buildString) { | |||||
public static ScannerReport.Metadata createReportMetadata(@Nullable String projectVersion, @Nullable String buildString) { | |||||
ScannerReport.Metadata.Builder builder = ScannerReport.Metadata.newBuilder() | ScannerReport.Metadata.Builder builder = ScannerReport.Metadata.newBuilder() | ||||
.setProjectKey(REPORT_PROJECT_KEY) | .setProjectKey(REPORT_PROJECT_KEY) | ||||
.setRootComponentRef(ROOT_REF); | .setRootComponentRef(ROOT_REF); | ||||
ofNullable(scannerCodePeriodVersion).ifPresent(builder::setCodePeriodVersion); | |||||
ofNullable(projectVersion).ifPresent(builder::setProjectVersion); | ofNullable(projectVersion).ifPresent(builder::setProjectVersion); | ||||
ofNullable(buildString).ifPresent(builder::setBuildString); | ofNullable(buildString).ifPresent(builder::setBuildString); | ||||
return builder.build(); | return builder.build(); |
SnapshotDto analysis1 = dbTester.components() | SnapshotDto analysis1 = dbTester.components() | ||||
.insertSnapshot(project, snapshot -> snapshot.setStatus(STATUS_UNPROCESSED).setCreatedAt(1226379600000L).setLast(false));// 2008-11-11 | .insertSnapshot(project, snapshot -> snapshot.setStatus(STATUS_UNPROCESSED).setCreatedAt(1226379600000L).setLast(false));// 2008-11-11 | ||||
SnapshotDto analysis2 = dbTester.components().insertSnapshot(project, | SnapshotDto analysis2 = dbTester.components().insertSnapshot(project, | ||||
snapshot -> snapshot.setStatus(STATUS_PROCESSED).setCodePeriodVersion("not provided").setCreatedAt(1226379600000L).setLast(false));// 2008-11-29 | |||||
snapshot -> snapshot.setStatus(STATUS_PROCESSED).setProjectVersion("not provided").setCreatedAt(1226379600000L).setLast(false));// 2008-11-29 | |||||
dbTester.events().insertEvent(newEvent(analysis1).setName("not provided").setCategory(CATEGORY_VERSION).setDate(analysis1.getCreatedAt())); | dbTester.events().insertEvent(newEvent(analysis1).setName("not provided").setCategory(CATEGORY_VERSION).setDate(analysis1.getCreatedAt())); | ||||
dbTester.events().insertEvent(newEvent(analysis2).setName("not provided").setCategory(CATEGORY_VERSION).setDate(analysis2.getCreatedAt())); | dbTester.events().insertEvent(newEvent(analysis2).setName("not provided").setCategory(CATEGORY_VERSION).setDate(analysis2.getCreatedAt())); | ||||
when(analysisMetadataHolder.getAnalysisDate()).thenReturn(november30th2008.getTime()); | when(analysisMetadataHolder.getAnalysisDate()).thenReturn(november30th2008.getTime()); | ||||
} | } | ||||
@Test | @Test | ||||
public void feed_period_parameter_as_null_when_manual_baseline_has_same_project_and_codePeriod_version() { | |||||
public void feed_period_parameter_as_null_when_manual_baseline_has_same_project_version() { | |||||
String version = randomAlphabetic(12); | String version = randomAlphabetic(12); | ||||
OrganizationDto organization = dbTester.organizations().insert(); | OrganizationDto organization = dbTester.organizations().insert(); | ||||
ComponentDto project = dbTester.components().insertMainBranch(organization); | ComponentDto project = dbTester.components().insertMainBranch(organization); | ||||
SnapshotDto manualBaselineAnalysis = dbTester.components().insertSnapshot(project, t -> t.setCodePeriodVersion(version).setProjectVersion(version)); | |||||
SnapshotDto manualBaselineAnalysis = dbTester.components().insertSnapshot(project, t -> t.setProjectVersion(version).setProjectVersion(version)); | |||||
dbTester.components().setManualBaseline(project, manualBaselineAnalysis); | dbTester.components().setManualBaseline(project, manualBaselineAnalysis); | ||||
when(analysisMetadataHolder.getBranch()).thenReturn(branchOf(project)); | when(analysisMetadataHolder.getBranch()).thenReturn(branchOf(project)); | ||||
setupRoot(project); | setupRoot(project); | ||||
} | } | ||||
@Test | @Test | ||||
public void feed_no_period_parameter_as_projectVersion_when_manual_baseline_has_project_version_and_other_codePeriod_version() { | |||||
String codePeriodVersion = randomAlphabetic(12); | |||||
String projectVersion = randomAlphabetic(15); | |||||
OrganizationDto organization = dbTester.organizations().insert(); | |||||
ComponentDto project = dbTester.components().insertMainBranch(organization); | |||||
SnapshotDto manualBaselineAnalysis = dbTester.components().insertSnapshot(project, t -> t.setCodePeriodVersion(codePeriodVersion).setProjectVersion(projectVersion)); | |||||
dbTester.components().setManualBaseline(project, manualBaselineAnalysis); | |||||
when(analysisMetadataHolder.getBranch()).thenReturn(branchOf(project)); | |||||
setupRoot(project); | |||||
settings.setProperty("sonar.leak.period", "ignored"); | |||||
underTest.execute(new TestComputationStepContext()); | |||||
assertPeriod(LEAK_PERIOD_MODE_MANUAL_BASELINE, null, manualBaselineAnalysis.getCreatedAt(), manualBaselineAnalysis.getUuid()); | |||||
} | |||||
@Test | |||||
public void feed_no_period_parameter_as_projectVersion_when_manual_baseline_has_project_version_and_no_codePeriod_version() { | |||||
public void feed_no_period_parameter_as_projectVersion_when_manual_baseline_has_project_version() { | |||||
String projectVersion = randomAlphabetic(15); | String projectVersion = randomAlphabetic(15); | ||||
OrganizationDto organization = dbTester.organizations().insert(); | OrganizationDto organization = dbTester.organizations().insert(); | ||||
ComponentDto project = dbTester.components().insertMainBranch(organization); | ComponentDto project = dbTester.components().insertMainBranch(organization); | ||||
} | } | ||||
@Test | @Test | ||||
@UseDataProvider("projectAndCodePeriodVersionsCombinations") | |||||
public void feed_no_period_parameter_as_version_event_version_when_manual_baseline_has_one_over_any_other_version( | |||||
@Nullable String codePeriodVersion, @Nullable String projectVersion) { | |||||
@UseDataProvider("projectVersionNullOrNot") | |||||
public void feed_no_period_parameter_as_version_event_version_when_manual_baseline_has_one(@Nullable String projectVersion) { | |||||
String eventVersion = randomAlphabetic(15); | String eventVersion = randomAlphabetic(15); | ||||
OrganizationDto organization = dbTester.organizations().insert(); | OrganizationDto organization = dbTester.organizations().insert(); | ||||
ComponentDto project = dbTester.components().insertMainBranch(organization); | ComponentDto project = dbTester.components().insertMainBranch(organization); | ||||
SnapshotDto manualBaselineAnalysis = dbTester.components().insertSnapshot(project, t -> t.setCodePeriodVersion(codePeriodVersion).setProjectVersion(projectVersion)); | |||||
SnapshotDto manualBaselineAnalysis = dbTester.components().insertSnapshot(project, t -> t.setProjectVersion(projectVersion)); | |||||
dbTester.events().insertEvent(EventTesting.newEvent(manualBaselineAnalysis).setCategory(CATEGORY_VERSION).setName(eventVersion)); | dbTester.events().insertEvent(EventTesting.newEvent(manualBaselineAnalysis).setCategory(CATEGORY_VERSION).setName(eventVersion)); | ||||
dbTester.components().setManualBaseline(project, manualBaselineAnalysis); | dbTester.components().setManualBaseline(project, manualBaselineAnalysis); | ||||
when(analysisMetadataHolder.getBranch()).thenReturn(branchOf(project)); | when(analysisMetadataHolder.getBranch()).thenReturn(branchOf(project)); | ||||
} | } | ||||
@DataProvider | @DataProvider | ||||
public static Object[][] projectAndCodePeriodVersionsCombinations() { | |||||
String codePeriodVersion = randomAlphabetic(12); | |||||
String projectVersion = randomAlphabetic(15); | |||||
public static Object[][] projectVersionNullOrNot() { | |||||
return new Object[][] { | return new Object[][] { | ||||
{null, null}, | |||||
{codePeriodVersion, null}, | |||||
{codePeriodVersion, projectVersion}, | |||||
{projectVersion, projectVersion}, | |||||
{null, projectVersion} | |||||
{null}, | |||||
{randomAlphabetic(15)}, | |||||
}; | }; | ||||
} | } | ||||
public void fail_with_MessageException_if_string_is_not_an_existing_version_event(String propertyValue) { | public void fail_with_MessageException_if_string_is_not_an_existing_version_event(String propertyValue) { | ||||
OrganizationDto organization = dbTester.organizations().insert(); | OrganizationDto organization = dbTester.organizations().insert(); | ||||
ComponentDto project = dbTester.components().insertMainBranch(organization); | ComponentDto project = dbTester.components().insertMainBranch(organization); | ||||
SnapshotDto analysis1 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setCodePeriodVersion("0.9").setLast(false)); // 2008-11-11 | |||||
SnapshotDto analysis2 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226494680000L).setCodePeriodVersion("1.0").setLast(false)); // 2008-11-12 | |||||
SnapshotDto analysis3 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227157200000L).setCodePeriodVersion("1.1").setLast(false)); // 2008-11-20 | |||||
SnapshotDto analysis4 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227358680000L).setCodePeriodVersion("1.1").setLast(false)); // 2008-11-22 | |||||
SnapshotDto analysis5 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227934800000L).setCodePeriodVersion("1.1").setLast(true)); // 2008-11-29 | |||||
SnapshotDto analysis1 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setProjectVersion("0.9").setLast(false)); // 2008-11-11 | |||||
SnapshotDto analysis2 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226494680000L).setProjectVersion("1.0").setLast(false)); // 2008-11-12 | |||||
SnapshotDto analysis3 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227157200000L).setProjectVersion("1.1").setLast(false)); // 2008-11-20 | |||||
SnapshotDto analysis4 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227358680000L).setProjectVersion("1.1").setLast(false)); // 2008-11-22 | |||||
SnapshotDto analysis5 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227934800000L).setProjectVersion("1.1").setLast(true)); // 2008-11-29 | |||||
dbTester.events().insertEvent(newEvent(analysis1).setName("0.9").setCategory(CATEGORY_VERSION).setDate(analysis1.getCreatedAt())); | dbTester.events().insertEvent(newEvent(analysis1).setName("0.9").setCategory(CATEGORY_VERSION).setDate(analysis1.getCreatedAt())); | ||||
dbTester.events().insertEvent(newEvent(analysis2).setName("1.0").setCategory(CATEGORY_VERSION).setDate(analysis2.getCreatedAt())); | dbTester.events().insertEvent(newEvent(analysis2).setName("1.0").setCategory(CATEGORY_VERSION).setDate(analysis2.getCreatedAt())); | ||||
dbTester.events().insertEvent(newEvent(analysis5).setName("1.1").setCategory(CATEGORY_VERSION).setDate(analysis4.getCreatedAt())); | dbTester.events().insertEvent(newEvent(analysis5).setName("1.1").setCategory(CATEGORY_VERSION).setDate(analysis4.getCreatedAt())); | ||||
public void feed_period_by_previous_version() { | public void feed_period_by_previous_version() { | ||||
OrganizationDto organization = dbTester.organizations().insert(); | OrganizationDto organization = dbTester.organizations().insert(); | ||||
ComponentDto project = dbTester.components().insertMainBranch(organization); | ComponentDto project = dbTester.components().insertMainBranch(organization); | ||||
SnapshotDto analysis1 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setCodePeriodVersion("0.9").setLast(false)); // 2008-11-11 | |||||
SnapshotDto analysis2 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226494680000L).setCodePeriodVersion("1.0").setLast(false)); // 2008-11-12 | |||||
SnapshotDto analysis3 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227157200000L).setCodePeriodVersion("1.1").setLast(false)); // 2008-11-20 | |||||
SnapshotDto analysis4 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227358680000L).setCodePeriodVersion("1.1").setLast(false)); // 2008-11-22 | |||||
SnapshotDto analysis5 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227934800000L).setCodePeriodVersion("1.1").setLast(true)); // 2008-11-29 | |||||
SnapshotDto analysis1 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setProjectVersion("0.9").setLast(false)); // 2008-11-11 | |||||
SnapshotDto analysis2 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226494680000L).setProjectVersion("1.0").setLast(false)); // 2008-11-12 | |||||
SnapshotDto analysis3 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227157200000L).setProjectVersion("1.1").setLast(false)); // 2008-11-20 | |||||
SnapshotDto analysis4 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227358680000L).setProjectVersion("1.1").setLast(false)); // 2008-11-22 | |||||
SnapshotDto analysis5 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227934800000L).setProjectVersion("1.1").setLast(true)); // 2008-11-29 | |||||
dbTester.events().insertEvent(newEvent(analysis1).setName("0.9").setCategory(CATEGORY_VERSION).setDate(analysis1.getCreatedAt())); | dbTester.events().insertEvent(newEvent(analysis1).setName("0.9").setCategory(CATEGORY_VERSION).setDate(analysis1.getCreatedAt())); | ||||
dbTester.events().insertEvent(newEvent(analysis2).setName("1.0").setCategory(CATEGORY_VERSION).setDate(analysis2.getCreatedAt())); | dbTester.events().insertEvent(newEvent(analysis2).setName("1.0").setCategory(CATEGORY_VERSION).setDate(analysis2.getCreatedAt())); | ||||
dbTester.events().insertEvent(newEvent(analysis5).setName("1.1").setCategory(CATEGORY_VERSION).setDate(analysis4.getCreatedAt())); | dbTester.events().insertEvent(newEvent(analysis5).setName("1.1").setCategory(CATEGORY_VERSION).setDate(analysis4.getCreatedAt())); | ||||
public void feed_period_by_previous_version_with_previous_version_deleted() { | public void feed_period_by_previous_version_with_previous_version_deleted() { | ||||
OrganizationDto organization = dbTester.organizations().insert(); | OrganizationDto organization = dbTester.organizations().insert(); | ||||
ComponentDto project = dbTester.components().insertMainBranch(organization); | ComponentDto project = dbTester.components().insertMainBranch(organization); | ||||
SnapshotDto analysis1 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setCodePeriodVersion("0.9").setLast(false)); // 2008-11-11 | |||||
SnapshotDto analysis2 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226494680000L).setCodePeriodVersion("1.0").setLast(false)); // 2008-11-12 | |||||
SnapshotDto analysis3 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227157200000L).setCodePeriodVersion("1.1").setLast(false)); // 2008-11-20 | |||||
SnapshotDto analysis1 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setProjectVersion("0.9").setLast(false)); // 2008-11-11 | |||||
SnapshotDto analysis2 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226494680000L).setProjectVersion("1.0").setLast(false)); // 2008-11-12 | |||||
SnapshotDto analysis3 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227157200000L).setProjectVersion("1.1").setLast(false)); // 2008-11-20 | |||||
dbTester.events().insertEvent(newEvent(analysis1).setName("0.9").setCategory(CATEGORY_VERSION)); | dbTester.events().insertEvent(newEvent(analysis1).setName("0.9").setCategory(CATEGORY_VERSION)); | ||||
// The "1.0" version was deleted from the history | // The "1.0" version was deleted from the history | ||||
dbTester.events().insertEvent(newEvent(analysis3).setName("1.1").setCategory(CATEGORY_VERSION)); | dbTester.events().insertEvent(newEvent(analysis3).setName("1.1").setCategory(CATEGORY_VERSION)); | ||||
public void feed_period_by_previous_version_with_first_analysis_when_no_previous_version_found() { | public void feed_period_by_previous_version_with_first_analysis_when_no_previous_version_found() { | ||||
OrganizationDto organization = dbTester.organizations().insert(); | OrganizationDto organization = dbTester.organizations().insert(); | ||||
ComponentDto project = dbTester.components().insertMainBranch(organization); | ComponentDto project = dbTester.components().insertMainBranch(organization); | ||||
SnapshotDto analysis1 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setCodePeriodVersion("1.1").setLast(false)); // 2008-11-11 | |||||
SnapshotDto analysis2 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227934800000L).setCodePeriodVersion("1.1").setLast(true)); // 2008-11-29 | |||||
SnapshotDto analysis1 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setProjectVersion("1.1").setLast(false)); // 2008-11-11 | |||||
SnapshotDto analysis2 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227934800000L).setProjectVersion("1.1").setLast(true)); // 2008-11-29 | |||||
dbTester.events().insertEvent(newEvent(analysis2).setName("1.1").setCategory(CATEGORY_VERSION)); | dbTester.events().insertEvent(newEvent(analysis2).setName("1.1").setCategory(CATEGORY_VERSION)); | ||||
when(system2Mock.now()).thenReturn(november30th2008.getTime()); | when(system2Mock.now()).thenReturn(november30th2008.getTime()); | ||||
when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(false); | when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(false); | ||||
public void feed_period_by_previous_version_with_first_analysis_when_previous_snapshot_is_the_last_one() { | public void feed_period_by_previous_version_with_first_analysis_when_previous_snapshot_is_the_last_one() { | ||||
OrganizationDto organization = dbTester.organizations().insert(); | OrganizationDto organization = dbTester.organizations().insert(); | ||||
ComponentDto project = dbTester.components().insertMainBranch(organization); | ComponentDto project = dbTester.components().insertMainBranch(organization); | ||||
SnapshotDto analysis = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setCodePeriodVersion("0.9").setLast(true)); // 2008-11-11 | |||||
SnapshotDto analysis = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setProjectVersion("0.9").setLast(true)); // 2008-11-11 | |||||
dbTester.events().insertEvent(newEvent(analysis).setName("0.9").setCategory(CATEGORY_VERSION)); | dbTester.events().insertEvent(newEvent(analysis).setName("0.9").setCategory(CATEGORY_VERSION)); | ||||
when(system2Mock.now()).thenReturn(november30th2008.getTime()); | when(system2Mock.now()).thenReturn(november30th2008.getTime()); | ||||
when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(false); | when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(false); | ||||
public void feed_period_by_version() { | public void feed_period_by_version() { | ||||
OrganizationDto organization = dbTester.organizations().insert(); | OrganizationDto organization = dbTester.organizations().insert(); | ||||
ComponentDto project = dbTester.components().insertMainBranch(organization); | ComponentDto project = dbTester.components().insertMainBranch(organization); | ||||
SnapshotDto analysis1 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setCodePeriodVersion("0.9").setLast(false)); // 2008-11-11 | |||||
SnapshotDto analysis2 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226494680000L).setCodePeriodVersion("1.0").setLast(false)); // 2008-11-12 | |||||
SnapshotDto analysis3 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227157200000L).setCodePeriodVersion("1.1").setLast(false)); // 2008-11-20 | |||||
SnapshotDto analysis4 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227358680000L).setCodePeriodVersion("1.1").setLast(false)); // 2008-11-22 | |||||
SnapshotDto analysis5 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227934800000L).setCodePeriodVersion("1.1").setLast(true)); // 2008-11-29 | |||||
SnapshotDto analysis1 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setProjectVersion("0.9").setLast(false)); // 2008-11-11 | |||||
SnapshotDto analysis2 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226494680000L).setProjectVersion("1.0").setLast(false)); // 2008-11-12 | |||||
SnapshotDto analysis3 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227157200000L).setProjectVersion("1.1").setLast(false)); // 2008-11-20 | |||||
SnapshotDto analysis4 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227358680000L).setProjectVersion("1.1").setLast(false)); // 2008-11-22 | |||||
SnapshotDto analysis5 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227934800000L).setProjectVersion("1.1").setLast(true)); // 2008-11-29 | |||||
dbTester.events().insertEvent(newEvent(analysis1).setName("0.9").setCategory(CATEGORY_VERSION)); | dbTester.events().insertEvent(newEvent(analysis1).setName("0.9").setCategory(CATEGORY_VERSION)); | ||||
dbTester.events().insertEvent(newEvent(analysis2).setName("1.0").setCategory(CATEGORY_VERSION)); | dbTester.events().insertEvent(newEvent(analysis2).setName("1.0").setCategory(CATEGORY_VERSION)); | ||||
dbTester.events().insertEvent(newEvent(analysis5).setName("1.1").setCategory(CATEGORY_VERSION)); | dbTester.events().insertEvent(newEvent(analysis5).setName("1.1").setCategory(CATEGORY_VERSION)); | ||||
public void feed_period_by_version_with_only_one_existing_version() { | public void feed_period_by_version_with_only_one_existing_version() { | ||||
OrganizationDto organization = dbTester.organizations().insert(); | OrganizationDto organization = dbTester.organizations().insert(); | ||||
ComponentDto project = dbTester.components().insertMainBranch(organization); | ComponentDto project = dbTester.components().insertMainBranch(organization); | ||||
SnapshotDto analysis1 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setCodePeriodVersion("0.9").setLast(true)); // 2008-11-11 | |||||
SnapshotDto analysis1 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setProjectVersion("0.9").setLast(true)); // 2008-11-11 | |||||
dbTester.events().insertEvent(newEvent(analysis1).setName("0.9").setCategory(CATEGORY_VERSION)); | dbTester.events().insertEvent(newEvent(analysis1).setName("0.9").setCategory(CATEGORY_VERSION)); | ||||
when(system2Mock.now()).thenReturn(november30th2008.getTime()); | when(system2Mock.now()).thenReturn(november30th2008.getTime()); | ||||
when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(false); | when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(false); | ||||
} | } | ||||
private void setupRoot(ComponentDto project, String version) { | private void setupRoot(ComponentDto project, String version) { | ||||
treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setUuid(project.uuid()).setKey(project.getKey()).setCodePeriodVersion(version).build()); | |||||
treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setUuid(project.uuid()).setKey(project.getKey()).setProjectVersion(version).build()); | |||||
when(configurationRepository.getConfiguration()).thenReturn(settings.asConfig()); | when(configurationRepository.getConfiguration()).thenReturn(settings.asConfig()); | ||||
} | } | ||||
private static final long NOW = 1225630680000L; | private static final long NOW = 1225630680000L; | ||||
private static final ReportComponent ROOT = builder(PROJECT, 1) | private static final ReportComponent ROOT = builder(PROJECT, 1) | ||||
.setUuid("ABCD") | .setUuid("ABCD") | ||||
.setCodePeriodVersion("version_1") | |||||
.setProjectVersion("version_1") | |||||
.addChildren( | .addChildren( | ||||
builder(DIRECTORY, 2) | builder(DIRECTORY, 2) | ||||
.setUuid("BCDE") | .setUuid("BCDE") | ||||
when(system2.now()).thenReturn(NOW); | when(system2.now()).thenReturn(NOW); | ||||
Component project = builder(PROJECT, 1) | Component project = builder(PROJECT, 1) | ||||
.setUuid("ABCD") | .setUuid("ABCD") | ||||
.setCodePeriodVersion("1.0") | |||||
.setProjectVersion("1.0") | |||||
.addChildren( | .addChildren( | ||||
builder(DIRECTORY, 2) | builder(DIRECTORY, 2) | ||||
.setUuid("BCDE") | .setUuid("BCDE") | ||||
Component project = builder(PROJECT, 1) | Component project = builder(PROJECT, 1) | ||||
.setUuid(projectDto.uuid()) | .setUuid(projectDto.uuid()) | ||||
.setCodePeriodVersion("1.5-SNAPSHOT") | |||||
.setProjectVersion("1.5-SNAPSHOT") | |||||
.addChildren( | .addChildren( | ||||
builder(DIRECTORY, 2) | builder(DIRECTORY, 2) | ||||
.setUuid("BCDE") | .setUuid("BCDE") |
import static org.sonar.ce.task.projectanalysis.measure.Measure.Level.OK; | import static org.sonar.ce.task.projectanalysis.measure.Measure.Level.OK; | ||||
public class QualityGateEventsStepTest { | public class QualityGateEventsStepTest { | ||||
private static final String PROJECT_VERSION = new Random().nextBoolean() ? null : randomAlphabetic(19); | |||||
private static final String PROJECT_VERSION = randomAlphabetic(19); | |||||
private static final ReportComponent PROJECT_COMPONENT = ReportComponent.builder(Component.Type.PROJECT, 1) | private static final ReportComponent PROJECT_COMPONENT = ReportComponent.builder(Component.Type.PROJECT, 1) | ||||
.setUuid("uuid 1") | .setUuid("uuid 1") | ||||
.setKey("key 1") | .setKey("key 1") | ||||
.setCodePeriodVersion("V1.9") | |||||
.setProjectVersion(PROJECT_VERSION) | .setProjectVersion(PROJECT_VERSION) | ||||
.setBuildString("V1.9") | |||||
.addChildren(ReportComponent.builder(Component.Type.DIRECTORY, 2).build()) | .addChildren(ReportComponent.builder(Component.Type.DIRECTORY, 2).build()) | ||||
.build(); | .build(); | ||||
private static final String INVALID_ALERT_STATUS = "trololo"; | private static final String INVALID_ALERT_STATUS = "trololo"; | ||||
assertThat(notification.getType()).isEqualTo("alerts"); | assertThat(notification.getType()).isEqualTo("alerts"); | ||||
assertThat(notification.getFieldValue("projectKey")).isEqualTo(PROJECT_COMPONENT.getKey()); | assertThat(notification.getFieldValue("projectKey")).isEqualTo(PROJECT_COMPONENT.getKey()); | ||||
assertThat(notification.getFieldValue("projectName")).isEqualTo(PROJECT_COMPONENT.getName()); | assertThat(notification.getFieldValue("projectName")).isEqualTo(PROJECT_COMPONENT.getName()); | ||||
assertThat(notification.getFieldValue("codePeriodVersion")).isEqualTo(PROJECT_COMPONENT.getProjectAttributes().getCodePeriodVersion()); | |||||
assertThat(notification.getFieldValue("projectVersion")).isEqualTo(PROJECT_COMPONENT.getProjectAttributes().getProjectVersion()); | |||||
assertThat(notification.getFieldValue("branch")).isNull(); | assertThat(notification.getFieldValue("branch")).isNull(); | ||||
assertThat(notification.getFieldValue("alertLevel")).isEqualTo(rawAlterStatus.name()); | assertThat(notification.getFieldValue("alertLevel")).isEqualTo(rawAlterStatus.name()); | ||||
assertThat(notification.getFieldValue("alertName")).isEqualTo(expectedLabel); | assertThat(notification.getFieldValue("alertName")).isEqualTo(expectedLabel); | ||||
assertThat(notification.getType()).isEqualTo("alerts"); | assertThat(notification.getType()).isEqualTo("alerts"); | ||||
assertThat(notification.getFieldValue("projectKey")).isEqualTo(PROJECT_COMPONENT.getKey()); | assertThat(notification.getFieldValue("projectKey")).isEqualTo(PROJECT_COMPONENT.getKey()); | ||||
assertThat(notification.getFieldValue("projectName")).isEqualTo(PROJECT_COMPONENT.getName()); | assertThat(notification.getFieldValue("projectName")).isEqualTo(PROJECT_COMPONENT.getName()); | ||||
assertThat(notification.getFieldValue("codePeriodVersion")).isEqualTo(PROJECT_COMPONENT.getProjectAttributes().getCodePeriodVersion()); | |||||
assertThat(notification.getFieldValue("projectVersion")).isEqualTo(PROJECT_COMPONENT.getProjectAttributes().getProjectVersion()); | |||||
assertThat(notification.getFieldValue("branch")).isNull(); | assertThat(notification.getFieldValue("branch")).isNull(); | ||||
assertThat(notification.getFieldValue("alertLevel")).isEqualTo(newQualityGateStatus.getStatus().name()); | assertThat(notification.getFieldValue("alertLevel")).isEqualTo(newQualityGateStatus.getStatus().name()); | ||||
assertThat(notification.getFieldValue("alertName")).isEqualTo(expectedLabel); | assertThat(notification.getFieldValue("alertName")).isEqualTo(expectedLabel); | ||||
assertThat(notification.getType()).isEqualTo("alerts"); | assertThat(notification.getType()).isEqualTo("alerts"); | ||||
assertThat(notification.getFieldValue("projectKey")).isEqualTo(PROJECT_COMPONENT.getKey()); | assertThat(notification.getFieldValue("projectKey")).isEqualTo(PROJECT_COMPONENT.getKey()); | ||||
assertThat(notification.getFieldValue("projectName")).isEqualTo(PROJECT_COMPONENT.getName()); | assertThat(notification.getFieldValue("projectName")).isEqualTo(PROJECT_COMPONENT.getName()); | ||||
assertThat(notification.getFieldValue("codePeriodVersion")).isEqualTo(PROJECT_COMPONENT.getProjectAttributes().getCodePeriodVersion()); | |||||
assertThat(notification.getFieldValue("projectVersion")).isEqualTo(PROJECT_COMPONENT.getProjectAttributes().getProjectVersion()); | |||||
assertThat(notification.getFieldValue("branch")).isEqualTo(branchName); | assertThat(notification.getFieldValue("branch")).isEqualTo(branchName); | ||||
reset(measureRepository, eventRepository, notificationService); | reset(measureRepository, eventRepository, notificationService); | ||||
assertThat(notification.getType()).isEqualTo("alerts"); | assertThat(notification.getType()).isEqualTo("alerts"); | ||||
assertThat(notification.getFieldValue("projectKey")).isEqualTo(PROJECT_COMPONENT.getKey()); | assertThat(notification.getFieldValue("projectKey")).isEqualTo(PROJECT_COMPONENT.getKey()); | ||||
assertThat(notification.getFieldValue("projectName")).isEqualTo(PROJECT_COMPONENT.getName()); | assertThat(notification.getFieldValue("projectName")).isEqualTo(PROJECT_COMPONENT.getName()); | ||||
assertThat(notification.getFieldValue("codePeriodVersion")).isEqualTo(PROJECT_COMPONENT.getProjectAttributes().getCodePeriodVersion()); | |||||
assertThat(notification.getFieldValue("projectVersion")).isEqualTo(PROJECT_COMPONENT.getProjectAttributes().getProjectVersion()); | |||||
assertThat(notification.getFieldValue("branch")).isEqualTo(null); | assertThat(notification.getFieldValue("branch")).isEqualTo(null); | ||||
reset(measureRepository, eventRepository, notificationService); | reset(measureRepository, eventRepository, notificationService); |
*/ | */ | ||||
package org.sonar.ce.task.projectanalysis.step; | package org.sonar.ce.task.projectanalysis.step; | ||||
import com.tngtech.java.junit.dataprovider.DataProvider; | |||||
import com.tngtech.java.junit.dataprovider.DataProviderRunner; | |||||
import com.tngtech.java.junit.dataprovider.UseDataProvider; | |||||
import java.util.List; | import java.util.List; | ||||
import java.util.Optional; | import java.util.Optional; | ||||
import javax.annotation.Nullable; | |||||
import org.junit.Before; | import org.junit.Before; | ||||
import org.junit.Rule; | import org.junit.Rule; | ||||
import org.junit.Test; | import org.junit.Test; | ||||
import org.junit.runner.RunWith; | |||||
import org.sonar.api.utils.DateUtils; | import org.sonar.api.utils.DateUtils; | ||||
import org.sonar.api.utils.System2; | import org.sonar.api.utils.System2; | ||||
import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule; | import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule; | ||||
import static org.sonar.core.config.CorePropertyDefinitions.LEAK_PERIOD_MODE_DATE; | import static org.sonar.core.config.CorePropertyDefinitions.LEAK_PERIOD_MODE_DATE; | ||||
import static org.sonar.core.config.CorePropertyDefinitions.LEAK_PERIOD_MODE_PREVIOUS_VERSION; | import static org.sonar.core.config.CorePropertyDefinitions.LEAK_PERIOD_MODE_PREVIOUS_VERSION; | ||||
@RunWith(DataProviderRunner.class) | |||||
public class ReportPersistAnalysisStepTest extends BaseStepTest { | public class ReportPersistAnalysisStepTest extends BaseStepTest { | ||||
private static final String PROJECT_KEY = "PROJECT_KEY"; | private static final String PROJECT_KEY = "PROJECT_KEY"; | ||||
} | } | ||||
@Test | @Test | ||||
@UseDataProvider("projectVersionOrNull") | |||||
public void persist_analysis(@Nullable String projectVersion) { | |||||
public void persist_analysis() { | |||||
String projectVersion = randomAlphabetic(10); | |||||
OrganizationDto organizationDto = dbTester.organizations().insert(); | OrganizationDto organizationDto = dbTester.organizations().insert(); | ||||
ComponentDto projectDto = ComponentTesting.newPrivateProjectDto(organizationDto, "ABCD").setDbKey(PROJECT_KEY).setName("Project"); | ComponentDto projectDto = ComponentTesting.newPrivateProjectDto(organizationDto, "ABCD").setDbKey(PROJECT_KEY).setName("Project"); | ||||
dbClient.componentDao().insert(dbTester.getSession(), projectDto); | dbClient.componentDao().insert(dbTester.getSession(), projectDto); | ||||
Component project = ReportComponent.builder(Component.Type.PROJECT, 1) | Component project = ReportComponent.builder(Component.Type.PROJECT, 1) | ||||
.setUuid("ABCD") | .setUuid("ABCD") | ||||
.setKey(PROJECT_KEY) | .setKey(PROJECT_KEY) | ||||
.setCodePeriodVersion("1.0") | |||||
.setProjectVersion(projectVersion) | .setProjectVersion(projectVersion) | ||||
.setBuildString(buildString) | .setBuildString(buildString) | ||||
.addChildren(directory) | .addChildren(directory) | ||||
SnapshotDto projectSnapshot = getUnprocessedSnapshot(projectDto.uuid()); | SnapshotDto projectSnapshot = getUnprocessedSnapshot(projectDto.uuid()); | ||||
assertThat(projectSnapshot.getUuid()).isEqualTo(ANALYSIS_UUID); | assertThat(projectSnapshot.getUuid()).isEqualTo(ANALYSIS_UUID); | ||||
assertThat(projectSnapshot.getComponentUuid()).isEqualTo(project.getUuid()); | assertThat(projectSnapshot.getComponentUuid()).isEqualTo(project.getUuid()); | ||||
assertThat(projectSnapshot.getCodePeriodVersion()).isEqualTo("1.0"); | |||||
assertThat(projectSnapshot.getProjectVersion()).isEqualTo(projectVersion); | assertThat(projectSnapshot.getProjectVersion()).isEqualTo(projectVersion); | ||||
assertThat(projectSnapshot.getBuildString()).isEqualTo(buildString); | assertThat(projectSnapshot.getBuildString()).isEqualTo(buildString); | ||||
assertThat(projectSnapshot.getLast()).isFalse(); | assertThat(projectSnapshot.getLast()).isFalse(); | ||||
assertThat(dbIdsRepository.getComponentId(file)).isEqualTo(fileDto.getId()); | assertThat(dbIdsRepository.getComponentId(file)).isEqualTo(fileDto.getId()); | ||||
} | } | ||||
@DataProvider | |||||
public static Object[][] projectVersionOrNull() { | |||||
return new Object[][] { | |||||
{null}, | |||||
{randomAlphabetic(17)} | |||||
}; | |||||
} | |||||
@Test | @Test | ||||
public void persist_snapshots_with_leak_period() { | public void persist_snapshots_with_leak_period() { | ||||
OrganizationDto organizationDto = dbTester.organizations().insert(); | OrganizationDto organizationDto = dbTester.organizations().insert(); |
private static final Component FILE = builder(Type.FILE, 11).build(); | private static final Component FILE = builder(Type.FILE, 11).build(); | ||||
private static final Component PROJECT = builder(Type.PROJECT, 1) | private static final Component PROJECT = builder(Type.PROJECT, 1) | ||||
.setCodePeriodVersion(randomAlphanumeric(10)) | |||||
.setProjectVersion(randomAlphanumeric(10)) | |||||
.addChildren(FILE).build(); | .addChildren(FILE).build(); | ||||
@Rule | @Rule | ||||
private NewIssuesNotification createNewIssuesNotificationMock() { | private NewIssuesNotification createNewIssuesNotificationMock() { | ||||
NewIssuesNotification notification = mock(NewIssuesNotification.class); | NewIssuesNotification notification = mock(NewIssuesNotification.class); | ||||
when(notification.setProject(any(), any(), any(), any())).thenReturn(notification); | when(notification.setProject(any(), any(), any(), any())).thenReturn(notification); | ||||
when(notification.setCodePeriodVersion(any())).thenReturn(notification); | |||||
when(notification.setProjectVersion(any())).thenReturn(notification); | |||||
when(notification.setAnalysisDate(any())).thenReturn(notification); | when(notification.setAnalysisDate(any())).thenReturn(notification); | ||||
when(notification.setStatistics(any(), any())).thenReturn(notification); | when(notification.setStatistics(any(), any())).thenReturn(notification); | ||||
when(notification.setDebt(any())).thenReturn(notification); | when(notification.setDebt(any())).thenReturn(notification); | ||||
MyNewIssuesNotification notification = mock(MyNewIssuesNotification.class); | MyNewIssuesNotification notification = mock(MyNewIssuesNotification.class); | ||||
when(notification.setAssignee(any(UserDto.class))).thenReturn(notification); | when(notification.setAssignee(any(UserDto.class))).thenReturn(notification); | ||||
when(notification.setProject(any(), any(), any(), any())).thenReturn(notification); | when(notification.setProject(any(), any(), any(), any())).thenReturn(notification); | ||||
when(notification.setCodePeriodVersion(any())).thenReturn(notification); | |||||
when(notification.setProjectVersion(any())).thenReturn(notification); | |||||
when(notification.setAnalysisDate(any())).thenReturn(notification); | when(notification.setAnalysisDate(any())).thenReturn(notification); | ||||
when(notification.setStatistics(any(), any())).thenReturn(notification); | when(notification.setStatistics(any(), any())).thenReturn(notification); | ||||
when(notification.setDebt(any())).thenReturn(notification); | when(notification.setDebt(any())).thenReturn(notification); |
SnapshotDto viewSnapshot = getUnprocessedSnapshot(viewDto.uuid()); | SnapshotDto viewSnapshot = getUnprocessedSnapshot(viewDto.uuid()); | ||||
assertThat(viewSnapshot.getUuid()).isEqualTo(ANALYSIS_UUID); | assertThat(viewSnapshot.getUuid()).isEqualTo(ANALYSIS_UUID); | ||||
assertThat(viewSnapshot.getComponentUuid()).isEqualTo(view.getUuid()); | assertThat(viewSnapshot.getComponentUuid()).isEqualTo(view.getUuid()); | ||||
assertThat(viewSnapshot.getCodePeriodVersion()).isNull(); | |||||
assertThat(viewSnapshot.getProjectVersion()).isNull(); | assertThat(viewSnapshot.getProjectVersion()).isNull(); | ||||
assertThat(viewSnapshot.getLast()).isFalse(); | assertThat(viewSnapshot.getLast()).isFalse(); | ||||
assertThat(viewSnapshot.getStatus()).isEqualTo("U"); | assertThat(viewSnapshot.getStatus()).isEqualTo("U"); |
import javax.annotation.Nullable; | import javax.annotation.Nullable; | ||||
import static com.google.common.base.Preconditions.checkArgument; | import static com.google.common.base.Preconditions.checkArgument; | ||||
import static org.apache.commons.lang.StringUtils.trimToNull; | |||||
public final class SnapshotDto { | public final class SnapshotDto { | ||||
public static final String STATUS_UNPROCESSED = "U"; | public static final String STATUS_UNPROCESSED = "U"; | ||||
public static final String STATUS_PROCESSED = "P"; | public static final String STATUS_PROCESSED = "P"; | ||||
public static final int MAX_VERSION_LENGTH = 100; | public static final int MAX_VERSION_LENGTH = 100; | ||||
public static final int MAX_BUILD_STRING_LENGTH = 100; | |||||
private Long id; | private Long id; | ||||
private String uuid; | private String uuid; | ||||
private Long buildDate; | private Long buildDate; | ||||
private String status = STATUS_UNPROCESSED; | private String status = STATUS_UNPROCESSED; | ||||
private Boolean last; | private Boolean last; | ||||
private String codePeriodVersion; | |||||
// maps to "version" column in the table | |||||
private String projectVersion; | private String projectVersion; | ||||
private String buildString; | private String buildString; | ||||
private String periodMode; | private String periodMode; | ||||
return this; | return this; | ||||
} | } | ||||
/** | |||||
* Version is only available on projects and modules | |||||
*/ | |||||
@CheckForNull | |||||
public String getCodePeriodVersion() { | |||||
return codePeriodVersion; | |||||
} | |||||
public SnapshotDto setCodePeriodVersion(@Nullable String codePeriodVersion) { | |||||
checkVersion(codePeriodVersion, "codePeriodVersion"); | |||||
this.codePeriodVersion = codePeriodVersion; | |||||
return this; | |||||
} | |||||
private static void checkVersion(@Nullable String version, String versionLabel) { | |||||
if (version != null) { | |||||
checkArgument(version.length() <= MAX_VERSION_LENGTH, | |||||
"%s length (%s) is longer than the maximum authorized (%s). '%s' was provided.", versionLabel, version.length(), MAX_VERSION_LENGTH, version); | |||||
private static void checkLength(int maxLength, @Nullable String s, String label) { | |||||
if (s != null) { | |||||
checkArgument(s.length() <= maxLength, | |||||
"%s length (%s) is longer than the maximum authorized (%s). '%s' was provided.", label, s.length(), maxLength, s); | |||||
} | } | ||||
} | } | ||||
/** | |||||
* Used by MyBatis | |||||
*/ | |||||
private void setRawCodePeriodVersion(@Nullable String codePeriodVersion) { | |||||
this.codePeriodVersion = codePeriodVersion; | |||||
} | |||||
public SnapshotDto setProjectVersion(@Nullable String projectVersion) { | public SnapshotDto setProjectVersion(@Nullable String projectVersion) { | ||||
checkVersion(projectVersion, "projectVersion"); | |||||
checkLength(MAX_VERSION_LENGTH, projectVersion, "projectVersion"); | |||||
this.projectVersion = projectVersion; | this.projectVersion = projectVersion; | ||||
return this; | return this; | ||||
} | } | ||||
* Used by MyBatis | * Used by MyBatis | ||||
*/ | */ | ||||
private void setRawProjectVersion(@Nullable String projectVersion) { | private void setRawProjectVersion(@Nullable String projectVersion) { | ||||
this.projectVersion = projectVersion; | |||||
this.projectVersion = trimToNull(projectVersion); | |||||
} | } | ||||
@CheckForNull | @CheckForNull | ||||
} | } | ||||
public SnapshotDto setBuildString(@Nullable String buildString) { | public SnapshotDto setBuildString(@Nullable String buildString) { | ||||
checkLength(MAX_BUILD_STRING_LENGTH, buildString, "buildString"); | |||||
this.buildString = buildString; | this.buildString = buildString; | ||||
return this; | return this; | ||||
} | } | ||||
/** | |||||
* Used by MyBatis | |||||
*/ | |||||
private void setRawBuildString(@Nullable String buildString) { | |||||
this.buildString = trimToNull(buildString); | |||||
} | |||||
public SnapshotDto setPeriodMode(@Nullable String p) { | public SnapshotDto setPeriodMode(@Nullable String p) { | ||||
periodMode = p; | periodMode = p; | ||||
return this; | return this; | ||||
Objects.equals(buildDate, that.buildDate) && | Objects.equals(buildDate, that.buildDate) && | ||||
Objects.equals(status, that.status) && | Objects.equals(status, that.status) && | ||||
Objects.equals(last, that.last) && | Objects.equals(last, that.last) && | ||||
Objects.equals(codePeriodVersion, that.codePeriodVersion) && | |||||
Objects.equals(projectVersion, that.projectVersion) && | Objects.equals(projectVersion, that.projectVersion) && | ||||
Objects.equals(buildString, that.buildString) && | |||||
Objects.equals(periodMode, that.periodMode) && | Objects.equals(periodMode, that.periodMode) && | ||||
Objects.equals(periodParam, that.periodParam) && | Objects.equals(periodParam, that.periodParam) && | ||||
Objects.equals(periodDate, that.periodDate); | Objects.equals(periodDate, that.periodDate); | ||||
@Override | @Override | ||||
public int hashCode() { | public int hashCode() { | ||||
return Objects.hash(id, uuid, componentUuid, createdAt, buildDate, status, last, codePeriodVersion, projectVersion, periodMode, periodParam, periodDate); | |||||
return Objects.hash(id, uuid, componentUuid, createdAt, buildDate, status, last, projectVersion, buildString, periodMode, periodParam, periodDate); | |||||
} | } | ||||
@Override | @Override | ||||
", buildDate=" + buildDate + | ", buildDate=" + buildDate + | ||||
", status='" + status + '\'' + | ", status='" + status + '\'' + | ||||
", last=" + last + | ", last=" + last + | ||||
", codePeriodVersion='" + codePeriodVersion + '\'' + | |||||
", projectVersion='" + projectVersion + '\'' + | ", projectVersion='" + projectVersion + '\'' + | ||||
", buildString='" + buildString + '\'' + | |||||
", periodMode='" + periodMode + '\'' + | ", periodMode='" + periodMode + '\'' + | ||||
", periodParam='" + periodParam + '\'' + | ", periodParam='" + periodParam + '\'' + | ||||
", periodDate=" + periodDate + | ", periodDate=" + periodDate + |
private Long createdAfter; | private Long createdAfter; | ||||
private Long createdBefore; | private Long createdBefore; | ||||
private String status; | private String status; | ||||
private String codePeriodVersion; | |||||
private String projectVersion; | |||||
private Boolean isLast; | private Boolean isLast; | ||||
private String sortField; | private String sortField; | ||||
private String sortOrder; | private String sortOrder; | ||||
} | } | ||||
@CheckForNull | @CheckForNull | ||||
public String getCodePeriodVersion() { | |||||
return codePeriodVersion; | |||||
public String getProjectVersion() { | |||||
return projectVersion; | |||||
} | } | ||||
public SnapshotQuery setCodePeriodVersion(@Nullable String codePeriodVersion) { | |||||
this.codePeriodVersion = codePeriodVersion; | |||||
public SnapshotQuery setProjectVersion(@Nullable String projectVersion) { | |||||
this.projectVersion = projectVersion; | |||||
return this; | return this; | ||||
} | } | ||||
s.build_date as buildDate, | s.build_date as buildDate, | ||||
s.status as status, | s.status as status, | ||||
s.islast as last, | s.islast as last, | ||||
s.version as rawCodePeriodVersion, | |||||
s.project_version as rawProjectVersion, | |||||
s.version as rawProjectVersion, | |||||
s.build_string as buildString, | s.build_string as buildString, | ||||
s.period1_mode as periodMode, | s.period1_mode as periodMode, | ||||
s.period1_param as periodParam, | s.period1_param as periodParam, | ||||
<if test="query.status != null"> | <if test="query.status != null"> | ||||
AND s.status=#{query.status,jdbcType=VARCHAR} | AND s.status=#{query.status,jdbcType=VARCHAR} | ||||
</if> | </if> | ||||
<if test="query.codePeriodVersion != null"> | |||||
AND s.version=#{query.codePeriodVersion,jdbcType=VARCHAR} | |||||
<if test="query.projectVersion != null"> | |||||
AND s.version=#{query.projectVersion,jdbcType=VARCHAR} | |||||
</if> | </if> | ||||
<if test="query.isLast != null"> | <if test="query.isLast != null"> | ||||
AND s.islast=#{query.isLast} | AND s.islast=#{query.isLast} | ||||
<update id="update" parameterType="Snapshot"> | <update id="update" parameterType="Snapshot"> | ||||
update snapshots | update snapshots | ||||
set version = #{codePeriodVersion, jdbcType=VARCHAR}, | |||||
set version = #{projectVersion, jdbcType=VARCHAR}, | |||||
status = #{status, jdbcType=VARCHAR} | status = #{status, jdbcType=VARCHAR} | ||||
where uuid = #{uuid,jdbcType=VARCHAR} | where uuid = #{uuid,jdbcType=VARCHAR} | ||||
</update> | </update> | ||||
status, | status, | ||||
islast, | islast, | ||||
version, | version, | ||||
project_version, | |||||
build_string, | build_string, | ||||
period1_mode, | period1_mode, | ||||
period1_param, | period1_param, | ||||
#{buildDate, jdbcType=BIGINT}, | #{buildDate, jdbcType=BIGINT}, | ||||
#{status, jdbcType=VARCHAR}, | #{status, jdbcType=VARCHAR}, | ||||
#{last, jdbcType=BOOLEAN}, | #{last, jdbcType=BOOLEAN}, | ||||
#{codePeriodVersion, jdbcType=VARCHAR}, | |||||
#{projectVersion, jdbcType=VARCHAR}, | #{projectVersion, jdbcType=VARCHAR}, | ||||
#{buildString, jdbcType=VARCHAR}, | #{buildString, jdbcType=VARCHAR}, | ||||
#{periodMode, jdbcType=VARCHAR}, | #{periodMode, jdbcType=VARCHAR}, |
*/ | */ | ||||
package org.sonar.db.component; | package org.sonar.db.component; | ||||
import com.tngtech.java.junit.dataprovider.DataProvider; | |||||
import com.tngtech.java.junit.dataprovider.DataProviderRunner; | |||||
import com.tngtech.java.junit.dataprovider.UseDataProvider; | |||||
import java.util.Arrays; | import java.util.Arrays; | ||||
import java.util.Date; | import java.util.Date; | ||||
import java.util.List; | import java.util.List; | ||||
import java.util.Optional; | import java.util.Optional; | ||||
import javax.annotation.Nullable; | |||||
import org.apache.commons.lang.StringUtils; | import org.apache.commons.lang.StringUtils; | ||||
import org.junit.Rule; | import org.junit.Rule; | ||||
import org.junit.Test; | import org.junit.Test; | ||||
import org.junit.rules.ExpectedException; | import org.junit.rules.ExpectedException; | ||||
import org.junit.runner.RunWith; | |||||
import org.sonar.api.utils.DateUtils; | import org.sonar.api.utils.DateUtils; | ||||
import org.sonar.api.utils.System2; | import org.sonar.api.utils.System2; | ||||
import org.sonar.db.DbClient; | import org.sonar.db.DbClient; | ||||
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; | import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; | ||||
import static org.apache.commons.lang.math.RandomUtils.nextLong; | import static org.apache.commons.lang.math.RandomUtils.nextLong; | ||||
import static org.assertj.core.api.Assertions.assertThat; | import static org.assertj.core.api.Assertions.assertThat; | ||||
import static org.assertj.core.api.Assertions.fail; | |||||
import static org.assertj.core.groups.Tuple.tuple; | import static org.assertj.core.groups.Tuple.tuple; | ||||
import static org.sonar.db.ce.CeActivityDto.Status.CANCELED; | import static org.sonar.db.ce.CeActivityDto.Status.CANCELED; | ||||
import static org.sonar.db.ce.CeActivityDto.Status.SUCCESS; | import static org.sonar.db.ce.CeActivityDto.Status.SUCCESS; | ||||
import static org.sonar.db.component.SnapshotQuery.SORT_ORDER.DESC; | import static org.sonar.db.component.SnapshotQuery.SORT_ORDER.DESC; | ||||
import static org.sonar.db.component.SnapshotTesting.newAnalysis; | import static org.sonar.db.component.SnapshotTesting.newAnalysis; | ||||
@RunWith(DataProviderRunner.class) | |||||
public class SnapshotDaoTest { | public class SnapshotDaoTest { | ||||
@Rule | @Rule | ||||
.setPeriodMode("days") | .setPeriodMode("days") | ||||
.setPeriodParam("30") | .setPeriodParam("30") | ||||
.setPeriodDate(1500000000001L) | .setPeriodDate(1500000000001L) | ||||
.setCodePeriodVersion("2.1-SNAPSHOT") | |||||
.setProjectVersion("2.1.0.2336") | |||||
.setProjectVersion("2.1.0") | |||||
.setBuildString("2.1.0.2336") | |||||
.setBuildDate(1500000000006L) | .setBuildDate(1500000000006L) | ||||
.setCreatedAt(1403042400000L)); | .setCreatedAt(1403042400000L)); | ||||
assertThat(result.getComponentUuid()).isEqualTo(project.uuid()); | assertThat(result.getComponentUuid()).isEqualTo(project.uuid()); | ||||
assertThat(result.getStatus()).isEqualTo("P"); | assertThat(result.getStatus()).isEqualTo("P"); | ||||
assertThat(result.getLast()).isTrue(); | assertThat(result.getLast()).isTrue(); | ||||
assertThat(result.getCodePeriodVersion()).isEqualTo("2.1-SNAPSHOT"); | |||||
assertThat(result.getProjectVersion()).isEqualTo("2.1.0.2336"); | |||||
assertThat(result.getProjectVersion()).isEqualTo("2.1.0"); | |||||
assertThat(result.getBuildString()).isEqualTo("2.1.0.2336"); | |||||
assertThat(result.getPeriodMode()).isEqualTo("days"); | assertThat(result.getPeriodMode()).isEqualTo("days"); | ||||
assertThat(result.getPeriodModeParameter()).isEqualTo("30"); | assertThat(result.getPeriodModeParameter()).isEqualTo("30"); | ||||
assertThat(result.getPeriodDate()).isEqualTo(1500000000001L); | assertThat(result.getPeriodDate()).isEqualTo(1500000000001L); | ||||
assertThat(result.getBuildDate()).isEqualTo(1500000000006L); | assertThat(result.getBuildDate()).isEqualTo(1500000000006L); | ||||
assertThat(result.getCreatedAt()).isEqualTo(1403042400000L); | assertThat(result.getCreatedAt()).isEqualTo(1403042400000L); | ||||
assertThat(result.getCodePeriodVersion()).isEqualTo("2.1-SNAPSHOT"); | |||||
assertThat(underTest.selectByUuid(db.getSession(), "DOES_NOT_EXIST").isPresent()).isFalse(); | assertThat(underTest.selectByUuid(db.getSession(), "DOES_NOT_EXIST").isPresent()).isFalse(); | ||||
} | } | ||||
assertThat(underTest.selectAnalysesByQuery(db.getSession(), new SnapshotQuery())).hasSize(6); | assertThat(underTest.selectAnalysesByQuery(db.getSession(), new SnapshotQuery())).hasSize(6); | ||||
assertThat(underTest.selectAnalysesByQuery(db.getSession(), new SnapshotQuery().setComponentUuid("ABCD").setSort(BY_DATE, ASC))) | assertThat(underTest.selectAnalysesByQuery(db.getSession(), new SnapshotQuery().setComponentUuid("ABCD").setSort(BY_DATE, ASC))) | ||||
.extracting(SnapshotDto::getId, SnapshotDto::getCodePeriodVersion, SnapshotDto::getProjectVersion) | |||||
.extracting(SnapshotDto::getId, SnapshotDto::getProjectVersion, SnapshotDto::getBuildString) | |||||
.containsOnly( | .containsOnly( | ||||
tuple(1L, "2.0-SNAPSHOT", "2.0.0.2363"), | tuple(1L, "2.0-SNAPSHOT", "2.0.0.2363"), | ||||
tuple(2L, "2.1-SNAPSHOT", "2.1.0.11"), | tuple(2L, "2.1-SNAPSHOT", "2.1.0.11"), | ||||
tuple(3L, "2.2-SNAPSHOT", "2.2.0.8869") | tuple(3L, "2.2-SNAPSHOT", "2.2.0.8869") | ||||
); | ); | ||||
assertThat(underTest.selectAnalysesByQuery(db.getSession(), new SnapshotQuery().setComponentUuid("ABCD").setSort(BY_DATE, DESC))) | assertThat(underTest.selectAnalysesByQuery(db.getSession(), new SnapshotQuery().setComponentUuid("ABCD").setSort(BY_DATE, DESC))) | ||||
.extracting(SnapshotDto::getId, SnapshotDto::getCodePeriodVersion, SnapshotDto::getProjectVersion) | |||||
.extracting(SnapshotDto::getId, SnapshotDto::getProjectVersion, SnapshotDto::getBuildString) | |||||
.containsOnly( | .containsOnly( | ||||
tuple(3L, "2.2-SNAPSHOT", "2.2.0.8869"), | tuple(3L, "2.2-SNAPSHOT", "2.2.0.8869"), | ||||
tuple(2L, "2.1-SNAPSHOT", "2.1.0.11"), | tuple(2L, "2.1-SNAPSHOT", "2.1.0.11"), | ||||
.setPeriodMode("days") | .setPeriodMode("days") | ||||
.setPeriodParam("30") | .setPeriodParam("30") | ||||
.setPeriodDate(1500000000001L) | .setPeriodDate(1500000000001L) | ||||
.setCodePeriodVersion("2.1-SNAPSHOT") | |||||
.setProjectVersion("2.1-SNAPSHOT") | |||||
.setBuildDate(1500000000006L) | .setBuildDate(1500000000006L) | ||||
.setCreatedAt(1403042400000L)); | .setCreatedAt(1403042400000L)); | ||||
assertThat(dto.getPeriodDate()).isEqualTo(1500000000001L); | assertThat(dto.getPeriodDate()).isEqualTo(1500000000001L); | ||||
assertThat(dto.getBuildDate()).isEqualTo(1500000000006L); | assertThat(dto.getBuildDate()).isEqualTo(1500000000006L); | ||||
assertThat(dto.getCreatedAt()).isEqualTo(1403042400000L); | assertThat(dto.getCreatedAt()).isEqualTo(1403042400000L); | ||||
assertThat(dto.getCodePeriodVersion()).isEqualTo("2.1-SNAPSHOT"); | |||||
assertThat(dto.getProjectVersion()).isEqualTo("2.1-SNAPSHOT"); | |||||
} | |||||
@Test | |||||
@UseDataProvider("nullAndEmptyNonEmptyStrings") | |||||
public void insert_with_null_and_empty_and_non_empty_projectVersion(@Nullable String projectVersion) { | |||||
ComponentDto project = db.components().insertPrivateProject(); | |||||
SnapshotDto dto = underTest.insert(db.getSession(), newAnalysis(project).setProjectVersion(projectVersion)); | |||||
assertThat(dto.getProjectVersion()).isEqualTo(projectVersion); | |||||
} | |||||
@Test | |||||
@UseDataProvider("nullAndEmptyNonEmptyStrings") | |||||
public void insert_with_null_and_empty_and_non_empty_buildString(@Nullable String buildString) { | |||||
ComponentDto project = db.components().insertPrivateProject(); | |||||
SnapshotDto dto = underTest.insert(db.getSession(), newAnalysis(project).setBuildString(buildString)); | |||||
assertThat(dto.getBuildString()).isEqualTo(buildString); | |||||
} | |||||
@DataProvider | |||||
public static Object[][] nullAndEmptyNonEmptyStrings() { | |||||
return new Object[][] { | |||||
{null}, | |||||
{""}, | |||||
{randomAlphanumeric(7)}, | |||||
}; | |||||
} | } | ||||
@Test | @Test | ||||
db.commit(); | db.commit(); | ||||
analysis | analysis | ||||
.setComponentUuid("P42") | .setComponentUuid("P42") | ||||
.setCodePeriodVersion("5.6.3") | |||||
.setProjectVersion("5.6.3") | |||||
.setStatus(STATUS_UNPROCESSED); | .setStatus(STATUS_UNPROCESSED); | ||||
underTest.update(dbSession, analysis); | underTest.update(dbSession, analysis); | ||||
SnapshotDto result = underTest.selectByUuid(dbSession, "A1").get(); | SnapshotDto result = underTest.selectByUuid(dbSession, "A1").get(); | ||||
assertThat(result.getCodePeriodVersion()).isEqualTo("5.6.3"); | |||||
assertThat(result.getProjectVersion()).isEqualTo("5.6.3"); | |||||
assertThat(result.getStatus()).isEqualTo(STATUS_UNPROCESSED); | assertThat(result.getStatus()).isEqualTo(STATUS_UNPROCESSED); | ||||
assertThat(result.getComponentUuid()).isEqualTo("P1"); | assertThat(result.getComponentUuid()).isEqualTo("P1"); | ||||
} | } | ||||
@Test | |||||
public void snashotDto_can_hold_version_larger_than_100_read_from_database() { | |||||
SnapshotDto analysis = insertAnalysis("P1", "A1", STATUS_PROCESSED, false); | |||||
db.commit(); | |||||
String tooLongVersion = StringUtils.repeat("d", 200); | |||||
db.executeUpdateSql("update snapshots set version='" + tooLongVersion + "' where uuid='" + analysis.getUuid() + "'"); | |||||
db.commit(); | |||||
assertThat(underTest.selectByUuid(dbSession, analysis.getUuid()) | |||||
.map(SnapshotDto::getCodePeriodVersion)) | |||||
.contains(tooLongVersion); | |||||
} | |||||
private SnapshotDto insertAnalysis(String projectUuid, String uuid, String status, boolean isLastFlag) { | private SnapshotDto insertAnalysis(String projectUuid, String uuid, String status, boolean isLastFlag) { | ||||
SnapshotDto snapshot = newAnalysis(newPrivateProjectDto(OrganizationTesting.newOrganizationDto(), projectUuid)) | SnapshotDto snapshot = newAnalysis(newPrivateProjectDto(OrganizationTesting.newOrganizationDto(), projectUuid)) | ||||
.setLast(isLastFlag) | .setLast(isLastFlag) | ||||
.setComponentUuid("uuid_3") | .setComponentUuid("uuid_3") | ||||
.setStatus("P") | .setStatus("P") | ||||
.setLast(true) | .setLast(true) | ||||
.setCodePeriodVersion("2.1-SNAPSHOT") | |||||
.setProjectVersion("2.1-SNAPSHOT") | |||||
.setPeriodMode("days1") | .setPeriodMode("days1") | ||||
.setPeriodParam("30") | .setPeriodParam("30") | ||||
.setPeriodDate(1_500_000_000_001L) | .setPeriodDate(1_500_000_000_001L) |
.setBuildDate(parseDate("2014-07-02").getTime()) | .setBuildDate(parseDate("2014-07-02").getTime()) | ||||
.setComponentUuid("uuid_21") | .setComponentUuid("uuid_21") | ||||
.setLast(true) | .setLast(true) | ||||
.setCodePeriodVersion("1.0") | |||||
.setProjectVersion("1.0") | |||||
.setBuildString("1.0.1.123") | |||||
.setPeriodMode("mode1") | .setPeriodMode("mode1") | ||||
.setPeriodParam("param1") | .setPeriodParam("param1") | ||||
.setPeriodDate(parseDate("2014-06-01").getTime()); | .setPeriodDate(parseDate("2014-06-01").getTime()); | ||||
assertThat(snapshotDto.getBuildDate()).isEqualTo(parseDate("2014-07-02").getTime()); | assertThat(snapshotDto.getBuildDate()).isEqualTo(parseDate("2014-07-02").getTime()); | ||||
assertThat(snapshotDto.getComponentUuid()).isEqualTo("uuid_21"); | assertThat(snapshotDto.getComponentUuid()).isEqualTo("uuid_21"); | ||||
assertThat(snapshotDto.getLast()).isTrue(); | assertThat(snapshotDto.getLast()).isTrue(); | ||||
assertThat(snapshotDto.getCodePeriodVersion()).isEqualTo("1.0"); | |||||
assertThat(snapshotDto.getProjectVersion()).isEqualTo("1.0"); | |||||
assertThat(snapshotDto.getBuildString()).isEqualTo("1.0.1.123"); | |||||
assertThat(snapshotDto.getPeriodMode()).isEqualTo("mode1"); | assertThat(snapshotDto.getPeriodMode()).isEqualTo("mode1"); | ||||
assertThat(snapshotDto.getPeriodModeParameter()).isEqualTo("param1"); | assertThat(snapshotDto.getPeriodModeParameter()).isEqualTo("param1"); | ||||
assertThat(snapshotDto.getPeriodDate()).isEqualTo(parseDate("2014-06-01").getTime()); | assertThat(snapshotDto.getPeriodDate()).isEqualTo(parseDate("2014-06-01").getTime()); | ||||
} | } | ||||
@Test | @Test | ||||
public void fail_if_version_name_is_longer_then_100_characters() { | |||||
public void fail_if_projectVersion_is_longer_then_100_characters() { | |||||
SnapshotDto snapshotDto = new SnapshotDto(); | SnapshotDto snapshotDto = new SnapshotDto(); | ||||
snapshotDto.setCodePeriodVersion(null); | |||||
snapshotDto.setCodePeriodVersion("1.0"); | |||||
snapshotDto.setCodePeriodVersion(repeat("a", 100)); | |||||
snapshotDto.setProjectVersion(null); | |||||
snapshotDto.setProjectVersion("1.0"); | |||||
snapshotDto.setProjectVersion(repeat("a", 100)); | |||||
expectedException.expect(IllegalArgumentException.class); | expectedException.expect(IllegalArgumentException.class); | ||||
expectedException.expectMessage("codePeriodVersion" + | |||||
expectedException.expectMessage("projectVersion" + | |||||
" length (101) is longer than the maximum authorized (100). " + | " length (101) is longer than the maximum authorized (100). " + | ||||
"'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' was provided."); | "'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' was provided."); | ||||
snapshotDto.setCodePeriodVersion(repeat("a", 101)); | |||||
snapshotDto.setProjectVersion(repeat("a", 101)); | |||||
} | |||||
@Test | |||||
public void fail_if_buildString_is_longer_then_100_characters() { | |||||
SnapshotDto snapshotDto = new SnapshotDto(); | |||||
snapshotDto.setBuildString(null); | |||||
snapshotDto.setBuildString("1.0"); | |||||
snapshotDto.setBuildString(repeat("a", 100)); | |||||
expectedException.expect(IllegalArgumentException.class); | |||||
expectedException.expectMessage("buildString" + | |||||
" length (101) is longer than the maximum authorized (100). " + | |||||
"'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' was provided."); | |||||
snapshotDto.setBuildString(repeat("a", 101)); | |||||
} | } | ||||
} | } |
.setComponentUuid("abcd") | .setComponentUuid("abcd") | ||||
.setIsLast(true) | .setIsLast(true) | ||||
.setStatus("P") | .setStatus("P") | ||||
.setCodePeriodVersion("1.0") | |||||
.setProjectVersion("1.0") | |||||
.setCreatedAfter(10L) | .setCreatedAfter(10L) | ||||
.setCreatedBefore(20L) | .setCreatedBefore(20L) | ||||
.setSort(BY_DATE, ASC); | .setSort(BY_DATE, ASC); | ||||
assertThat(query.getComponentUuid()).isEqualTo("abcd"); | assertThat(query.getComponentUuid()).isEqualTo("abcd"); | ||||
assertThat(query.getIsLast()).isTrue(); | assertThat(query.getIsLast()).isTrue(); | ||||
assertThat(query.getStatus()).isEqualTo("P"); | assertThat(query.getStatus()).isEqualTo("P"); | ||||
assertThat(query.getCodePeriodVersion()).isEqualTo("1.0"); | |||||
assertThat(query.getProjectVersion()).isEqualTo("1.0"); | |||||
assertThat(query.getCreatedAfter()).isEqualTo(10L); | assertThat(query.getCreatedAfter()).isEqualTo(10L); | ||||
assertThat(query.getCreatedBefore()).isEqualTo(20L); | assertThat(query.getCreatedBefore()).isEqualTo(20L); | ||||
assertThat(query.getSortField()).isEqualTo("created_at"); | assertThat(query.getSortField()).isEqualTo("created_at"); |
.setComponentUuid(PROJECT_UUID) | .setComponentUuid(PROJECT_UUID) | ||||
.setStatus(STATUS_PROCESSED) | .setStatus(STATUS_PROCESSED) | ||||
.setLast(false) | .setLast(false) | ||||
.setCodePeriodVersion("V5") | |||||
.setProjectVersion("V5") | |||||
}; | }; | ||||
db.components().insertSnapshots(analyses); | db.components().insertSnapshots(analyses); | ||||
db.events().insertEvent(EventTesting.newEvent(analyses[4]) | db.events().insertEvent(EventTesting.newEvent(analyses[4]) |
created_at="1228172400001" | created_at="1228172400001" | ||||
build_date="1317247200000" | build_date="1317247200000" | ||||
version="2.0-SNAPSHOT" | version="2.0-SNAPSHOT" | ||||
project_version="2.0.0.2363" | |||||
build_string="2.0.0.2363" | |||||
/> | /> | ||||
<snapshots id="2" | <snapshots id="2" | ||||
uuid="u2" | uuid="u2" | ||||
created_at="1228172400002" | created_at="1228172400002" | ||||
build_date="1317247200000" | build_date="1317247200000" | ||||
version="2.1-SNAPSHOT" | version="2.1-SNAPSHOT" | ||||
project_version="2.1.0.11" | |||||
build_string="2.1.0.11" | |||||
/> | /> | ||||
<snapshots id="3" | <snapshots id="3" | ||||
uuid="u3" | uuid="u3" | ||||
created_at="1228172400003" | created_at="1228172400003" | ||||
build_date="1317247200000" | build_date="1317247200000" | ||||
version="2.2-SNAPSHOT" | version="2.2-SNAPSHOT" | ||||
project_version="2.2.0.8869" | |||||
build_string="2.2.0.8869" | |||||
/> | /> | ||||
<!-- PROJECT_ID = 2 --> | <!-- PROJECT_ID = 2 --> | ||||
created_at="1228172400000" | created_at="1228172400000" | ||||
build_date="1317247200000" | build_date="1317247200000" | ||||
version="2.1-SNAPSHOT" | version="2.1-SNAPSHOT" | ||||
project_version="2.1.0.66" | |||||
build_string="2.1.0.66" | |||||
/> | /> | ||||
<!-- Unprocessed snapshot --> | <!-- Unprocessed snapshot --> | ||||
<snapshots organization_uuid="org1" | <snapshots organization_uuid="org1" | ||||
created_at="1228172400000" | created_at="1228172400000" | ||||
build_date="1317247200000" | build_date="1317247200000" | ||||
version="2.1-SNAPSHOT" | version="2.1-SNAPSHOT" | ||||
project_version="2.1.0.1" | |||||
build_string="2.1.0.1" | |||||
/> | /> | ||||
<!-- PROJECT_ID = 3 - no last snapshot --> | <!-- PROJECT_ID = 3 - no last snapshot --> | ||||
created_at="1228172400000" | created_at="1228172400000" | ||||
build_date="1317247200000" | build_date="1317247200000" | ||||
version="2.1-SNAPSHOT" | version="2.1-SNAPSHOT" | ||||
project_version="2.1.0.5586" | |||||
build_string="2.1.0.5586" | |||||
/> | /> | ||||
<!-- PROJECT_ID = 4 - no snapshot --> | <!-- PROJECT_ID = 4 - no snapshot --> |
static final String FIELD_PROJECT_NAME = "projectName"; | static final String FIELD_PROJECT_NAME = "projectName"; | ||||
static final String FIELD_PROJECT_KEY = "projectKey"; | static final String FIELD_PROJECT_KEY = "projectKey"; | ||||
static final String FIELD_PROJECT_DATE = "projectDate"; | static final String FIELD_PROJECT_DATE = "projectDate"; | ||||
static final String FIELD_CODE_PERIOD_VERSION = "codePeriodVersion"; | |||||
static final String FIELD_PROJECT_VERSION = "projectVersion"; | |||||
static final String FIELD_ASSIGNEE = "assignee"; | static final String FIELD_ASSIGNEE = "assignee"; | ||||
static final String FIELD_BRANCH = "branch"; | static final String FIELD_BRANCH = "branch"; | ||||
static final String FIELD_PULL_REQUEST = "pullRequest"; | static final String FIELD_PULL_REQUEST = "pullRequest"; | ||||
if (pullRequest!= null) { | if (pullRequest!= null) { | ||||
message.append("Pull request: ").append(pullRequest).append(NEW_LINE); | message.append("Pull request: ").append(pullRequest).append(NEW_LINE); | ||||
} | } | ||||
String version = notification.getFieldValue(FIELD_CODE_PERIOD_VERSION); | |||||
String version = notification.getFieldValue(FIELD_PROJECT_VERSION); | |||||
if (version != null) { | if (version != null) { | ||||
message.append("Version: ").append(version).append(NEW_LINE); | message.append("Version: ").append(version).append(NEW_LINE); | ||||
} | } |
import static java.util.stream.Collectors.toMap; | import static java.util.stream.Collectors.toMap; | ||||
import static java.util.stream.Collectors.toSet; | import static java.util.stream.Collectors.toSet; | ||||
import static org.sonar.server.issue.notification.AbstractNewIssuesEmailTemplate.FIELD_BRANCH; | import static org.sonar.server.issue.notification.AbstractNewIssuesEmailTemplate.FIELD_BRANCH; | ||||
import static org.sonar.server.issue.notification.AbstractNewIssuesEmailTemplate.FIELD_CODE_PERIOD_VERSION; | |||||
import static org.sonar.server.issue.notification.AbstractNewIssuesEmailTemplate.FIELD_PROJECT_VERSION; | |||||
import static org.sonar.server.issue.notification.AbstractNewIssuesEmailTemplate.FIELD_PULL_REQUEST; | import static org.sonar.server.issue.notification.AbstractNewIssuesEmailTemplate.FIELD_PULL_REQUEST; | ||||
import static org.sonar.server.issue.notification.NewIssuesEmailTemplate.FIELD_PROJECT_DATE; | import static org.sonar.server.issue.notification.NewIssuesEmailTemplate.FIELD_PROJECT_DATE; | ||||
import static org.sonar.server.issue.notification.NewIssuesEmailTemplate.FIELD_PROJECT_KEY; | import static org.sonar.server.issue.notification.NewIssuesEmailTemplate.FIELD_PROJECT_KEY; | ||||
return this; | return this; | ||||
} | } | ||||
public NewIssuesNotification setCodePeriodVersion(@Nullable String version) { | |||||
public NewIssuesNotification setProjectVersion(@Nullable String version) { | |||||
if (version != null) { | if (version != null) { | ||||
setFieldValue(FIELD_CODE_PERIOD_VERSION, version); | |||||
setFieldValue(FIELD_PROJECT_VERSION, version); | |||||
} | } | ||||
return this; | return this; | ||||
} | } |
String projectId = notification.getFieldValue("projectId"); | String projectId = notification.getFieldValue("projectId"); | ||||
String projectKey = notification.getFieldValue("projectKey"); | String projectKey = notification.getFieldValue("projectKey"); | ||||
String projectName = notification.getFieldValue("projectName"); | String projectName = notification.getFieldValue("projectName"); | ||||
String projectVersion = notification.getFieldValue("codePeriodVersion"); | |||||
String projectVersion = notification.getFieldValue("projectVersion"); | |||||
String branchName = notification.getFieldValue("branch"); | String branchName = notification.getFieldValue("branch"); | ||||
String alertName = notification.getFieldValue("alertName"); | String alertName = notification.getFieldValue("alertName"); | ||||
String alertText = notification.getFieldValue("alertText"); | String alertText = notification.getFieldValue("alertText"); |
@Test | @Test | ||||
public void format_email_with_no_assignees_tags_nor_components() { | public void format_email_with_no_assignees_tags_nor_components() { | ||||
Notification notification = newNotification(32) | Notification notification = newNotification(32) | ||||
.setFieldValue("codePeriodVersion", "52.0"); | |||||
.setFieldValue("projectVersion", "52.0"); | |||||
EmailMessage message = underTest.format(notification); | EmailMessage message = underTest.format(notification); | ||||
@Test | @Test | ||||
public void format_email_with_issue_on_branch() { | public void format_email_with_issue_on_branch() { | ||||
Notification notification = newNotification(32) | Notification notification = newNotification(32) | ||||
.setFieldValue("codePeriodVersion", "52.0") | |||||
.setFieldValue("projectVersion", "52.0") | |||||
.setFieldValue("branch", "feature1"); | .setFieldValue("branch", "feature1"); | ||||
EmailMessage message = underTest.format(notification); | EmailMessage message = underTest.format(notification); |
@Test | @Test | ||||
public void format_email_with_all_fields_filled() { | public void format_email_with_all_fields_filled() { | ||||
Notification notification = newNotification(32) | Notification notification = newNotification(32) | ||||
.setFieldValue("codePeriodVersion", "42.1.1"); | |||||
.setFieldValue("projectVersion", "42.1.1"); | |||||
addAssignees(notification); | addAssignees(notification); | ||||
addRules(notification); | addRules(notification); | ||||
addTags(notification); | addTags(notification); | ||||
public void format_email_with_issue_on_branch_with_version() { | public void format_email_with_issue_on_branch_with_version() { | ||||
Notification notification = newNotification(32) | Notification notification = newNotification(32) | ||||
.setFieldValue("branch", "feature1") | .setFieldValue("branch", "feature1") | ||||
.setFieldValue("codePeriodVersion", "42.1.1"); | |||||
.setFieldValue("projectVersion", "42.1.1"); | |||||
EmailMessage message = template.format(notification); | EmailMessage message = template.format(notification); | ||||
public void set_project_version() { | public void set_project_version() { | ||||
String version = randomAlphanumeric(5); | String version = randomAlphanumeric(5); | ||||
underTest.setCodePeriodVersion(version); | |||||
underTest.setProjectVersion(version); | |||||
assertThat(underTest.getFieldValue(NewIssuesEmailTemplate.FIELD_CODE_PERIOD_VERSION)).isEqualTo(version); | |||||
assertThat(underTest.getFieldValue(NewIssuesEmailTemplate.FIELD_PROJECT_VERSION)).isEqualTo(version); | |||||
} | } | ||||
@Test | @Test | ||||
public void set_project_version_supports_null() { | public void set_project_version_supports_null() { | ||||
underTest.setCodePeriodVersion(null); | |||||
underTest.setProjectVersion(null); | |||||
assertThat(underTest.getFieldValue(NewIssuesEmailTemplate.FIELD_CODE_PERIOD_VERSION)).isNull(); | |||||
assertThat(underTest.getFieldValue(NewIssuesEmailTemplate.FIELD_PROJECT_VERSION)).isNull(); | |||||
} | } | ||||
@Test | @Test |
analysis -> { | analysis -> { | ||||
wsComponent.setAnalysisDate(formatDateTime(analysis.getCreatedAt())); | wsComponent.setAnalysisDate(formatDateTime(analysis.getCreatedAt())); | ||||
ofNullable(analysis.getPeriodDate()).ifPresent(leak -> wsComponent.setLeakPeriodDate(formatDateTime(leak))); | ofNullable(analysis.getPeriodDate()).ifPresent(leak -> wsComponent.setLeakPeriodDate(formatDateTime(leak))); | ||||
ofNullable(analysis.getCodePeriodVersion()).ifPresent(wsComponent::setVersion); | |||||
ofNullable(analysis.getProjectVersion()).ifPresent(wsComponent::setVersion); | |||||
}); | }); | ||||
if (QUALIFIERS_WITH_VISIBILITY.contains(dto.qualifier())) { | if (QUALIFIERS_WITH_VISIBILITY.contains(dto.qualifier())) { | ||||
wsComponent.setVisibility(Visibility.getLabel(dto.isPrivate())); | wsComponent.setVisibility(Visibility.getLabel(dto.isPrivate())); |
private EventDto insertDbEvent(DbSession dbSession, CreateEventRequest request, SnapshotDto analysis) { | private EventDto insertDbEvent(DbSession dbSession, CreateEventRequest request, SnapshotDto analysis) { | ||||
EventDto dbEvent = dbClient.eventDao().insert(dbSession, toDbEvent(request, analysis)); | EventDto dbEvent = dbClient.eventDao().insert(dbSession, toDbEvent(request, analysis)); | ||||
if (VERSION.equals(request.getCategory())) { | if (VERSION.equals(request.getCategory())) { | ||||
analysis.setCodePeriodVersion(request.getName()); | |||||
analysis.setProjectVersion(request.getName()); | |||||
dbClient.snapshotDao().update(dbSession, analysis); | dbClient.snapshotDao().update(dbSession, analysis); | ||||
} | } | ||||
dbSession.commit(); | dbSession.commit(); |
SnapshotDto analysis = dbClient.snapshotDao().selectByUuid(dbSession, dbEvent.getAnalysisUuid()) | SnapshotDto analysis = dbClient.snapshotDao().selectByUuid(dbSession, dbEvent.getAnalysisUuid()) | ||||
.orElseThrow(() -> new IllegalStateException(format("Analysis '%s' not found", dbEvent.getAnalysisUuid()))); | .orElseThrow(() -> new IllegalStateException(format("Analysis '%s' not found", dbEvent.getAnalysisUuid()))); | ||||
checkArgument(!analysis.getLast(), "Cannot delete the version event of last analysis"); | checkArgument(!analysis.getLast(), "Cannot delete the version event of last analysis"); | ||||
analysis.setCodePeriodVersion(null); | |||||
analysis.setProjectVersion(null); | |||||
dbClient.snapshotDao().update(dbSession, analysis); | dbClient.snapshotDao().update(dbSession, analysis); | ||||
} | } | ||||
dbClient.eventDao().delete(dbSession, dbEvent.getUuid()); | dbClient.eventDao().delete(dbSession, dbEvent.getUuid()); |
.setKey(dbAnalysis.getUuid()) | .setKey(dbAnalysis.getUuid()) | ||||
.setDate(formatDateTime(dbAnalysis.getCreatedAt())) | .setDate(formatDateTime(dbAnalysis.getCreatedAt())) | ||||
.setManualNewCodePeriodBaseline(searchData.getManualBaseline().filter(dbAnalysis.getUuid()::equals).isPresent()); | .setManualNewCodePeriodBaseline(searchData.getManualBaseline().filter(dbAnalysis.getUuid()::equals).isPresent()); | ||||
ofNullable(dbAnalysis.getCodePeriodVersion()).ifPresent(builder::setCodePeriodVersion); | |||||
ofNullable(dbAnalysis.getProjectVersion()).ifPresent(builder::setProjectVersion); | ofNullable(dbAnalysis.getProjectVersion()).ifPresent(builder::setProjectVersion); | ||||
ofNullable(dbAnalysis.getBuildString()).ifPresent(builder::setBuildString); | ofNullable(dbAnalysis.getBuildString()).ifPresent(builder::setBuildString); | ||||
dbClient.eventDao().update(dbSession, event.getUuid(), event.getName(), event.getDescription()); | dbClient.eventDao().update(dbSession, event.getUuid(), event.getName(), event.getDescription()); | ||||
if (VERSION.getLabel().equals(event.getCategory())) { | if (VERSION.getLabel().equals(event.getCategory())) { | ||||
SnapshotDto analysis = getAnalysis(dbSession, event); | SnapshotDto analysis = getAnalysis(dbSession, event); | ||||
analysis.setCodePeriodVersion(event.getName()); | |||||
analysis.setProjectVersion(event.getName()); | |||||
dbClient.snapshotDao().update(dbSession, analysis); | dbClient.snapshotDao().update(dbSession, analysis); | ||||
} | } | ||||
dbSession.commit(); | dbSession.commit(); |
List<Page> pages = pageRepository.getComponentPages(false, component.qualifier()); | List<Page> pages = pageRepository.getComponentPages(false, component.qualifier()); | ||||
writeExtensions(json, component, pages); | writeExtensions(json, component, pages); | ||||
if (analysis != null) { | if (analysis != null) { | ||||
json.prop("version", analysis.getCodePeriodVersion()) | |||||
json.prop("version", analysis.getProjectVersion()) | |||||
.prop("analysisDate", formatDateTime(new Date(analysis.getCreatedAt()))); | .prop("analysisDate", formatDateTime(new Date(analysis.getCreatedAt()))); | ||||
} | } | ||||
} | } |
ComponentDto module = db.components().insertComponent(newModuleDto(project)); | ComponentDto module = db.components().insertComponent(newModuleDto(project)); | ||||
ComponentDto directory = db.components().insertComponent(newDirectory(module, "dir")); | ComponentDto directory = db.components().insertComponent(newDirectory(module, "dir")); | ||||
ComponentDto file = db.components().insertComponent(newFileDto(directory)); | ComponentDto file = db.components().insertComponent(newFileDto(directory)); | ||||
db.components().insertSnapshot(project, s -> s.setCodePeriodVersion("1.1")); | |||||
db.components().insertSnapshot(project, s -> s.setProjectVersion("1.1")); | |||||
userSession.addProjectPermission(USER, project); | userSession.addProjectPermission(USER, project); | ||||
ShowWsResponse response = newRequest(null, file.getDbKey()); | ShowWsResponse response = newRequest(null, file.getDbKey()); | ||||
ComponentDto module = db.components().insertComponent(newModuleDto(branch)); | ComponentDto module = db.components().insertComponent(newModuleDto(branch)); | ||||
ComponentDto directory = db.components().insertComponent(newDirectory(module, "dir")); | ComponentDto directory = db.components().insertComponent(newDirectory(module, "dir")); | ||||
ComponentDto file = db.components().insertComponent(newFileDto(directory)); | ComponentDto file = db.components().insertComponent(newFileDto(directory)); | ||||
db.components().insertSnapshot(branch, s -> s.setCodePeriodVersion("1.1")); | |||||
db.components().insertSnapshot(branch, s -> s.setProjectVersion("1.1")); | |||||
ShowWsResponse response = ws.newRequest() | ShowWsResponse response = ws.newRequest() | ||||
.setParam(PARAM_COMPONENT, file.getKey()) | .setParam(PARAM_COMPONENT, file.getKey()) | ||||
ComponentDto module = db.components().insertComponent(newModuleDto(branch)); | ComponentDto module = db.components().insertComponent(newModuleDto(branch)); | ||||
ComponentDto directory = db.components().insertComponent(newDirectory(module, "dir")); | ComponentDto directory = db.components().insertComponent(newDirectory(module, "dir")); | ||||
ComponentDto file = db.components().insertComponent(newFileDto(directory)); | ComponentDto file = db.components().insertComponent(newFileDto(directory)); | ||||
db.components().insertSnapshot(branch, s -> s.setCodePeriodVersion("1.1")); | |||||
db.components().insertSnapshot(branch, s -> s.setProjectVersion("1.1")); | |||||
ShowWsResponse response = ws.newRequest() | ShowWsResponse response = ws.newRequest() | ||||
.setParam(PARAM_COMPONENT, file.getKey()) | .setParam(PARAM_COMPONENT, file.getKey()) | ||||
.setQualifier(Qualifiers.PROJECT) | .setQualifier(Qualifiers.PROJECT) | ||||
.setTagsString("language, plugin")); | .setTagsString("language, plugin")); | ||||
db.components().insertSnapshot(project, snapshot -> snapshot | db.components().insertSnapshot(project, snapshot -> snapshot | ||||
.setCodePeriodVersion("1.1") | |||||
.setProjectVersion("1.1") | |||||
.setCreatedAt(parseDateTime("2017-03-01T11:39:03+0100").getTime()) | .setCreatedAt(parseDateTime("2017-03-01T11:39:03+0100").getTime()) | ||||
.setPeriodDate(parseDateTime("2017-01-01T11:39:03+0100").getTime())); | .setPeriodDate(parseDateTime("2017-01-01T11:39:03+0100").getTime())); | ||||
ComponentDto directory = newDirectory(project, "AVIF-FfgA3Ax6PH2efPF", "src/main/java/com/sonarsource/markdown/impl") | ComponentDto directory = newDirectory(project, "AVIF-FfgA3Ax6PH2efPF", "src/main/java/com/sonarsource/markdown/impl") |
@Test | @Test | ||||
public void shouldFormatNewAlertWithoutVersion() { | public void shouldFormatNewAlertWithoutVersion() { | ||||
Notification notification = createNotification("Red (was Green)", "violations > 4", "ERROR", "true") | Notification notification = createNotification("Red (was Green)", "violations > 4", "ERROR", "true") | ||||
.setFieldValue("codePeriodVersion", null); | |||||
.setFieldValue("projectVersion", null); | |||||
EmailMessage message = template.format(notification); | EmailMessage message = template.format(notification); | ||||
assertThat(message.getMessageId(), is("alerts/45")); | assertThat(message.getMessageId(), is("alerts/45")); | ||||
.setFieldValue("projectName", "Foo") | .setFieldValue("projectName", "Foo") | ||||
.setFieldValue("projectKey", "org.sonar.foo:foo") | .setFieldValue("projectKey", "org.sonar.foo:foo") | ||||
.setFieldValue("projectId", "45") | .setFieldValue("projectId", "45") | ||||
.setFieldValue("codePeriodVersion", "V1-SNAP") | |||||
.setFieldValue("projectVersion", "V1-SNAP") | |||||
.setFieldValue("alertName", alertName) | .setFieldValue("alertName", alertName) | ||||
.setFieldValue("alertText", alertText) | .setFieldValue("alertText", alertText) | ||||
.setFieldValue("alertLevel", alertLevel) | .setFieldValue("alertLevel", alertLevel) |
call(VERSION.name(), "5.6.3", analysis.getUuid()); | call(VERSION.name(), "5.6.3", analysis.getUuid()); | ||||
Optional<SnapshotDto> newAnalysis = dbClient.snapshotDao().selectByUuid(dbSession, analysis.getUuid()); | Optional<SnapshotDto> newAnalysis = dbClient.snapshotDao().selectByUuid(dbSession, analysis.getUuid()); | ||||
assertThat(newAnalysis.get().getCodePeriodVersion()).isEqualTo("5.6.3"); | |||||
assertThat(newAnalysis.get().getProjectVersion()).isEqualTo("5.6.3"); | |||||
} | } | ||||
@Test | @Test | ||||
CreateEventResponse result = call(OTHER.name(), "Project Import", analysis.getUuid()); | CreateEventResponse result = call(OTHER.name(), "Project Import", analysis.getUuid()); | ||||
SnapshotDto newAnalysis = dbClient.snapshotDao().selectByUuid(dbSession, analysis.getUuid()).get(); | SnapshotDto newAnalysis = dbClient.snapshotDao().selectByUuid(dbSession, analysis.getUuid()).get(); | ||||
assertThat(analysis.getCodePeriodVersion()).isEqualTo(newAnalysis.getCodePeriodVersion()); | |||||
assertThat(analysis.getProjectVersion()).isEqualTo(newAnalysis.getProjectVersion()); | |||||
ProjectAnalyses.Event wsEvent = result.getEvent(); | ProjectAnalyses.Event wsEvent = result.getEvent(); | ||||
assertThat(wsEvent.getKey()).isNotEmpty(); | assertThat(wsEvent.getKey()).isNotEmpty(); | ||||
assertThat(wsEvent.getCategory()).isEqualTo(OTHER.name()); | assertThat(wsEvent.getCategory()).isEqualTo(OTHER.name()); |
@Test | @Test | ||||
public void delete_version_event() { | public void delete_version_event() { | ||||
ComponentDto project = db.components().insertPrivateProject(); | ComponentDto project = db.components().insertPrivateProject(); | ||||
SnapshotDto analysis = db.components().insertSnapshot(newAnalysis(project).setCodePeriodVersion("5.6.3").setLast(false)); | |||||
SnapshotDto analysis = db.components().insertSnapshot(newAnalysis(project).setProjectVersion("5.6.3").setLast(false)); | |||||
db.events().insertEvent(newEvent(analysis).setUuid("E1").setCategory(VERSION.getLabel())); | db.events().insertEvent(newEvent(analysis).setUuid("E1").setCategory(VERSION.getLabel())); | ||||
logInAsProjectAdministrator(project); | logInAsProjectAdministrator(project); | ||||
call("E1"); | call("E1"); | ||||
SnapshotDto newAnalysis = dbClient.snapshotDao().selectByUuid(dbSession, analysis.getUuid()).get(); | SnapshotDto newAnalysis = dbClient.snapshotDao().selectByUuid(dbSession, analysis.getUuid()).get(); | ||||
assertThat(newAnalysis.getCodePeriodVersion()).isNull(); | |||||
assertThat(newAnalysis.getProjectVersion()).isNull(); | |||||
} | } | ||||
@Test | @Test | ||||
public void fail_if_version_for_last_analysis() { | public void fail_if_version_for_last_analysis() { | ||||
ComponentDto project = db.components().insertPrivateProject(); | ComponentDto project = db.components().insertPrivateProject(); | ||||
SnapshotDto analysis = db.components().insertSnapshot(newAnalysis(project).setCodePeriodVersion("5.6.3").setLast(true)); | |||||
SnapshotDto analysis = db.components().insertSnapshot(newAnalysis(project).setProjectVersion("5.6.3").setLast(true)); | |||||
db.events().insertEvent(newEvent(analysis).setUuid("E1").setCategory(VERSION.getLabel())); | db.events().insertEvent(newEvent(analysis).setUuid("E1").setCategory(VERSION.getLabel())); | ||||
logInAsProjectAdministrator(project); | logInAsProjectAdministrator(project); | ||||
call("E1", "6.3"); | call("E1", "6.3"); | ||||
SnapshotDto updatedAnalysis = dbClient.snapshotDao().selectByUuid(dbSession, analysis.getUuid()).get(); | SnapshotDto updatedAnalysis = dbClient.snapshotDao().selectByUuid(dbSession, analysis.getUuid()).get(); | ||||
assertThat(updatedAnalysis.getCodePeriodVersion()).isEqualTo("6.3"); | |||||
assertThat(updatedAnalysis.getProjectVersion()).isEqualTo("6.3"); | |||||
} | } | ||||
@Test | @Test | ||||
call("E1", "6.3"); | call("E1", "6.3"); | ||||
SnapshotDto updatedAnalysis = dbClient.snapshotDao().selectByUuid(dbSession, analysis.getUuid()).get(); | SnapshotDto updatedAnalysis = dbClient.snapshotDao().selectByUuid(dbSession, analysis.getUuid()).get(); | ||||
assertThat(updatedAnalysis.getCodePeriodVersion()).isEqualTo("5.6"); | |||||
assertThat(updatedAnalysis.getProjectVersion()).isEqualTo("5.6"); | |||||
} | } | ||||
@Test | @Test | ||||
private SnapshotDto createAnalysisAndLogInAsProjectAdministrator(String version) { | private SnapshotDto createAnalysisAndLogInAsProjectAdministrator(String version) { | ||||
ComponentDto project = db.components().insertPrivateProject(); | ComponentDto project = db.components().insertPrivateProject(); | ||||
SnapshotDto analysis = db.components().insertSnapshot(newAnalysis(project).setCodePeriodVersion(version)); | |||||
SnapshotDto analysis = db.components().insertSnapshot(newAnalysis(project).setProjectVersion(version)); | |||||
logInAsProjectAdministrator(project); | logInAsProjectAdministrator(project); | ||||
return analysis; | return analysis; | ||||
} | } |
ComponentDto project = insertOrganizationAndProject(); | ComponentDto project = insertOrganizationAndProject(); | ||||
db.components().insertSnapshot(project, snapshot -> snapshot | db.components().insertSnapshot(project, snapshot -> snapshot | ||||
.setCreatedAt(parseDateTime("2015-04-22T11:44:00+0200").getTime()) | .setCreatedAt(parseDateTime("2015-04-22T11:44:00+0200").getTime()) | ||||
.setCodePeriodVersion("3.14")); | |||||
.setProjectVersion("3.14")); | |||||
userSession.addProjectPermission(UserRole.USER, project); | userSession.addProjectPermission(UserRole.USER, project); | ||||
init(); | init(); | ||||
componentDbTester.insertComponent(project); | componentDbTester.insertComponent(project); | ||||
SnapshotDto analysis = newAnalysis(project) | SnapshotDto analysis = newAnalysis(project) | ||||
.setCreatedAt(parseDateTime("2016-12-06T11:44:00+0200").getTime()) | .setCreatedAt(parseDateTime("2016-12-06T11:44:00+0200").getTime()) | ||||
.setCodePeriodVersion("6.3") | |||||
.setProjectVersion("6.3") | |||||
.setLast(true); | .setLast(true); | ||||
componentDbTester.insertSnapshot(analysis); | componentDbTester.insertSnapshot(analysis); | ||||
when(resourceTypes.get(project.qualifier())).thenReturn(DefaultResourceTypes.get().getRootType()); | when(resourceTypes.get(project.qualifier())).thenReturn(DefaultResourceTypes.get().getRootType()); |
@Deprecated | @Deprecated | ||||
String PROJECT_BRANCH_PROPERTY = "sonar.branch"; | String PROJECT_BRANCH_PROPERTY = "sonar.branch"; | ||||
String PROJECT_VERSION_PROPERTY = "sonar.projectVersion"; | String PROJECT_VERSION_PROPERTY = "sonar.projectVersion"; | ||||
String CODE_PERIOD_VERSION_PROPERTY = "sonar.codePeriodVersion"; | |||||
String BUILD_STRING_PROPERTY = "sonar.buildString"; | String BUILD_STRING_PROPERTY = "sonar.buildString"; | ||||
/** | /** |
import static java.lang.String.format; | import static java.lang.String.format; | ||||
import static org.sonar.api.CoreProperties.BUILD_STRING_PROPERTY; | import static org.sonar.api.CoreProperties.BUILD_STRING_PROPERTY; | ||||
import static org.sonar.api.CoreProperties.CODE_PERIOD_VERSION_PROPERTY; | |||||
import static org.sonar.api.CoreProperties.PROJECT_VERSION_PROPERTY; | import static org.sonar.api.CoreProperties.PROJECT_VERSION_PROPERTY; | ||||
/** | /** | ||||
private Date analysisDate; | private Date analysisDate; | ||||
private String projectVersion; | private String projectVersion; | ||||
private String codePeriodVersion; | |||||
private String buildString; | private String buildString; | ||||
public ProjectInfo(Configuration settings, Clock clock) { | public ProjectInfo(Configuration settings, Clock clock) { | ||||
return Optional.ofNullable(projectVersion); | return Optional.ofNullable(projectVersion); | ||||
} | } | ||||
public Optional<String> getCodePeriodVersion() { | |||||
return Optional.ofNullable(codePeriodVersion); | |||||
} | |||||
public Optional<String> getBuildString() { | public Optional<String> getBuildString() { | ||||
return Optional.ofNullable(buildString); | return Optional.ofNullable(buildString); | ||||
} | } | ||||
.map(StringUtils::trimToNull) | .map(StringUtils::trimToNull) | ||||
.filter(validateLengthLimit("project version")) | .filter(validateLengthLimit("project version")) | ||||
.orElse(null); | .orElse(null); | ||||
this.codePeriodVersion = settings.get(CODE_PERIOD_VERSION_PROPERTY) | |||||
.map(StringUtils::trimToNull) | |||||
.filter(validateLengthLimit("codePeriod version")) | |||||
.orElse(projectVersion); | |||||
this.buildString = settings.get(BUILD_STRING_PROPERTY) | this.buildString = settings.get(BUILD_STRING_PROPERTY) | ||||
.map(StringUtils::trimToNull) | .map(StringUtils::trimToNull) | ||||
.filter(validateLengthLimit("buildString")) | .filter(validateLengthLimit("buildString")) |
.setCrossProjectDuplicationActivated(cpdSettings.isCrossProjectDuplicationEnabled()) | .setCrossProjectDuplicationActivated(cpdSettings.isCrossProjectDuplicationEnabled()) | ||||
.setRootComponentRef(rootProject.scannerId()); | .setRootComponentRef(rootProject.scannerId()); | ||||
projectInfo.getProjectVersion().ifPresent(builder::setProjectVersion); | projectInfo.getProjectVersion().ifPresent(builder::setProjectVersion); | ||||
projectInfo.getCodePeriodVersion().ifPresent(builder::setCodePeriodVersion); | |||||
projectInfo.getBuildString().ifPresent(builder::setBuildString); | projectInfo.getBuildString().ifPresent(builder::setBuildString); | ||||
properties.organizationKey().ifPresent(builder::setOrganizationKey); | properties.organizationKey().ifPresent(builder::setOrganizationKey); |
} | } | ||||
@Test | @Test | ||||
@UseDataProvider("projectVersions") | |||||
public void getCodePeriodVersion_has_value_of_projectVersion_if_property_is_unset(@Nullable String projectVersion) { | |||||
@UseDataProvider("emptyOrNullString") | |||||
public void getProjectVersion_is_empty_if_property_is_empty_or_null(@Nullable String projectVersion) { | |||||
settings.setProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2017-01-01"); | settings.setProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2017-01-01"); | ||||
settings.setProperty(CoreProperties.PROJECT_VERSION_PROPERTY, projectVersion); | settings.setProperty(CoreProperties.PROJECT_VERSION_PROPERTY, projectVersion); | ||||
underTest.start(); | underTest.start(); | ||||
if (projectVersion == null) { | |||||
assertThat(underTest.getCodePeriodVersion()).isEmpty(); | |||||
} else { | |||||
assertThat(underTest.getCodePeriodVersion()).contains(projectVersion); | |||||
} | |||||
assertThat(underTest.getProjectVersion()).isEmpty(); | |||||
} | } | ||||
@Test | @Test | ||||
@UseDataProvider("projectVersions") | |||||
public void getCodePeriodVersion_is_empty_if_property_is_empty(@Nullable String projectVersion) { | |||||
public void getProjectVersion_contains_value_of_property() { | |||||
String value = RandomStringUtils.randomAlphabetic(10); | |||||
settings.setProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2017-01-01"); | settings.setProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2017-01-01"); | ||||
settings.setProperty(CoreProperties.PROJECT_VERSION_PROPERTY, projectVersion); | |||||
settings.setProperty(CoreProperties.CODE_PERIOD_VERSION_PROPERTY, ""); | |||||
settings.setProperty(CoreProperties.PROJECT_VERSION_PROPERTY, value); | |||||
underTest.start(); | underTest.start(); | ||||
if (projectVersion == null) { | |||||
assertThat(underTest.getCodePeriodVersion()).isEmpty(); | |||||
} else { | |||||
assertThat(underTest.getCodePeriodVersion()).contains(projectVersion); | |||||
} | |||||
assertThat(underTest.getProjectVersion()).contains(value); | |||||
} | } | ||||
@Test | @Test | ||||
@UseDataProvider("projectVersions") | |||||
public void getCodePeriodVersion_contains_value_of_property(@Nullable String projectVersion) { | |||||
String version = RandomStringUtils.randomAlphabetic(10); | |||||
@UseDataProvider("emptyOrNullString") | |||||
public void getBuildString_is_empty_if_property_is_empty_or_null(@Nullable String buildString) { | |||||
settings.setProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2017-01-01"); | settings.setProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2017-01-01"); | ||||
settings.setProperty(CoreProperties.PROJECT_VERSION_PROPERTY, projectVersion); | |||||
settings.setProperty(CoreProperties.CODE_PERIOD_VERSION_PROPERTY, version); | |||||
settings.setProperty(CoreProperties.BUILD_STRING_PROPERTY, buildString); | |||||
underTest.start(); | |||||
assertThat(underTest.getBuildString()).isEmpty(); | |||||
} | |||||
@Test | |||||
public void getBuildString_contains_value_of_property() { | |||||
String value = RandomStringUtils.randomAlphabetic(10); | |||||
settings.setProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2017-01-01"); | |||||
settings.setProperty(CoreProperties.BUILD_STRING_PROPERTY, value); | |||||
underTest.start(); | underTest.start(); | ||||
assertThat(underTest.getCodePeriodVersion()).contains(version); | |||||
assertThat(underTest.getBuildString()).contains(value); | |||||
} | } | ||||
@DataProvider | @DataProvider | ||||
public static Object[][] projectVersions() { | |||||
public static Object[][] emptyOrNullString() { | |||||
return new Object[][] { | return new Object[][] { | ||||
{""}, | |||||
{null}, | {null}, | ||||
{randomAlphabetic(12)} | |||||
}; | }; | ||||
} | } | ||||
} | } |
}; | }; | ||||
} | } | ||||
@Test | |||||
@UseDataProvider("codePeriodVersions") | |||||
public void write_codePeriod_version(@Nullable String codePeriodVersion, String expected) throws Exception { | |||||
when(projectInfo.getCodePeriodVersion()).thenReturn(Optional.ofNullable(codePeriodVersion)); | |||||
when(properties.organizationKey()).thenReturn(Optional.of("SonarSource")); | |||||
File outputDir = temp.newFolder(); | |||||
ScannerReportWriter writer = new ScannerReportWriter(outputDir); | |||||
underTest.publish(writer); | |||||
ScannerReportReader reader = new ScannerReportReader(outputDir); | |||||
ScannerReport.Metadata metadata = reader.readMetadata(); | |||||
assertThat(metadata.getCodePeriodVersion()).isEqualTo(expected); | |||||
} | |||||
@DataProvider | |||||
public static Object[][] codePeriodVersions() { | |||||
String randomVersion = randomAlphabetic(15); | |||||
return new Object[][] { | |||||
{null, ""}, | |||||
{"", ""}, | |||||
{"5.6.3", "5.6.3"}, | |||||
{randomVersion, randomVersion} | |||||
}; | |||||
} | |||||
@Test | @Test | ||||
@UseDataProvider("buildStrings") | @UseDataProvider("buildStrings") | ||||
public void write_buildString(@Nullable String buildString, String expected) throws Exception { | public void write_buildString(@Nullable String buildString, String expected) throws Exception { |
map<string, string> modules_project_relative_path_by_key = 15; | map<string, string> modules_project_relative_path_by_key = 15; | ||||
string projectVersion = 16; | string projectVersion = 16; | ||||
string codePeriodVersion = 17; | |||||
string buildString = 18; | |||||
string buildString = 17; | |||||
message QProfile { | message QProfile { | ||||
string key = 1; | string key = 1; |
optional string key = 1; | optional string key = 1; | ||||
optional string date = 2; | optional string date = 2; | ||||
repeated Event events = 3; | repeated Event events = 3; | ||||
optional string codePeriodVersion = 4; | |||||
optional string projectVersion = 5; | |||||
optional string projectVersion = 4; | |||||
optional string buildString = 5; | |||||
optional bool manualNewCodePeriodBaseline = 6; | optional bool manualNewCodePeriodBaseline = 6; | ||||
optional string buildString = 7; | |||||
} | } | ||||
message QualityGate { | message QualityGate { |