aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-server
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2019-08-06 14:05:00 -0500
committerSonarTech <sonartech@sonarsource.com>2019-09-24 20:21:13 +0200
commit14bd90f47ee950d4ee780cbd2a030cac5cb034c0 (patch)
tree1f1e18d6de8074f01f0670369e28e817f6490267 /server/sonar-server
parent09f8f0f6ca0fab099775351385b1dfbe96bc6e5f (diff)
downloadsonarqube-14bd90f47ee950d4ee780cbd2a030cac5cb034c0.tar.gz
sonarqube-14bd90f47ee950d4ee780cbd2a030cac5cb034c0.zip
SONAR-12364 Fix update of values
Diffstat (limited to 'server/sonar-server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/setting/ws/ShowNewCodePeriodAction.java2
-rw-r--r--server/sonar-server/src/main/resources/org/sonar/server/setting/ws/show_new_code_period-example.json0
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/setting/ws/ShowNewCodePeriodActionTest.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/setting/ws/UpdateNewCodePeriodActionTest.java43
4 files changed, 45 insertions, 2 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/setting/ws/ShowNewCodePeriodAction.java b/server/sonar-server/src/main/java/org/sonar/server/setting/ws/ShowNewCodePeriodAction.java
index 2c033bae81b..25b7eaa547d 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/setting/ws/ShowNewCodePeriodAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/setting/ws/ShowNewCodePeriodAction.java
@@ -70,7 +70,7 @@ public class ShowNewCodePeriodAction implements SettingsWsAction {
"<li>'Administer' rights on the specified component</li>" +
"</ul>")
.setSince("8.0")
- .setResponseExample(getClass().getResource("generate_secret_key-example.json"))
+ .setResponseExample(getClass().getResource("show_new_code_period-example.json"))
.setHandler(this);
action.createParam(PARAM_PROJECT)
diff --git a/server/sonar-server/src/main/resources/org/sonar/server/setting/ws/show_new_code_period-example.json b/server/sonar-server/src/main/resources/org/sonar/server/setting/ws/show_new_code_period-example.json
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/server/sonar-server/src/main/resources/org/sonar/server/setting/ws/show_new_code_period-example.json
diff --git a/server/sonar-server/src/test/java/org/sonar/server/setting/ws/ShowNewCodePeriodActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/setting/ws/ShowNewCodePeriodActionTest.java
index de1b36af126..926793a44d3 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/setting/ws/ShowNewCodePeriodActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/setting/ws/ShowNewCodePeriodActionTest.java
@@ -126,7 +126,7 @@ public class ShowNewCodePeriodActionTest {
}
@Test
- public void throw_NFE_if_no_project_permission() {
+ public void throw_FE_if_no_project_permission() {
ComponentDto project = componentDb.insertMainBranch();
expectedException.expect(ForbiddenException.class);
expectedException.expectMessage("Insufficient privileges");
diff --git a/server/sonar-server/src/test/java/org/sonar/server/setting/ws/UpdateNewCodePeriodActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/setting/ws/UpdateNewCodePeriodActionTest.java
index 740bf44d85d..23ff28ab461 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/setting/ws/UpdateNewCodePeriodActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/setting/ws/UpdateNewCodePeriodActionTest.java
@@ -325,7 +325,24 @@ public class UpdateNewCodePeriodActionTest {
.setParam("value", "5")
.execute();
assertTableContainsOnly(project.uuid(), null, NewCodePeriodType.NUMBER_OF_DAYS, "5");
+ }
+
+ @Test
+ public void set_project_twice_period_to_number_of_days() {
+ ComponentDto project = componentDb.insertMainBranch();
+ logInAsProjectAdministrator(project);
+ ws.newRequest()
+ .setParam("project", project.getKey())
+ .setParam("type", "previous_version")
+ .execute();
+ assertTableContainsOnly(project.uuid(), null, NewCodePeriodType.PREVIOUS_VERSION, null);
+ ws.newRequest()
+ .setParam("project", project.getKey())
+ .setParam("type", "number_of_days")
+ .setParam("value", "5")
+ .execute();
+ assertTableContainsOnly(project.uuid(), null, NewCodePeriodType.NUMBER_OF_DAYS, "5");
}
@Test
@@ -348,6 +365,32 @@ public class UpdateNewCodePeriodActionTest {
assertTableContainsOnly(project.uuid(), branch.uuid(), NewCodePeriodType.SPECIFIC_ANALYSIS, analysisBranch.getUuid());
}
+ @Test
+ public void set_branch_period_twice_to_analysis() {
+ ComponentDto project = componentDb.insertMainBranch();
+ ComponentDto branch = componentDb.insertProjectBranch(project, b -> b.setKey("branch"));
+
+ SnapshotDto analysisMaster = db.components().insertSnapshot(project);
+ SnapshotDto analysisBranch = db.components().insertSnapshot(branch);
+
+ logInAsProjectAdministrator(project);
+
+ ws.newRequest()
+ .setParam("project", project.getKey())
+ .setParam("type", "specific_analysis")
+ .setParam("branch", "branch")
+ .setParam("value", analysisBranch.getUuid())
+ .execute();
+
+ ws.newRequest()
+ .setParam("project", project.getKey())
+ .setParam("type", "previous_version")
+ .setParam("branch", "branch")
+ .execute();
+
+ assertTableContainsOnly(project.uuid(), branch.uuid(), NewCodePeriodType.PREVIOUS_VERSION, null);
+ }
+
private void assertTableContainsOnly(@Nullable String projectUuid, @Nullable String branchUuid, NewCodePeriodType type, @Nullable String value) {
assertThat(db.countRowsOfTable(dbSession, "new_code_periods")).isEqualTo(1);
assertThat(db.selectFirst(dbSession, "select project_uuid, branch_uuid, type, value from new_code_periods"))