aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorJacek <52388493+jacek-poreda-sonarsource@users.noreply.github.com>2019-09-02 16:38:21 +0200
committerSonarTech <sonartech@sonarsource.com>2019-09-24 20:21:16 +0200
commit1bd13d06f1600169edb47200f6531ae6dfef66f2 (patch)
tree96112dc8ef3048b2a959f9a729c41bae90df149e /server
parent7243267d22b36aea1ea6614f4dff11b58aba5e12 (diff)
downloadsonarqube-1bd13d06f1600169edb47200f6531ae6dfef66f2.tar.gz
sonarqube-1bd13d06f1600169edb47200f6531ae6dfef66f2.zip
Fix new code period set action with specific analysis for CE (#2051)
Diffstat (limited to 'server')
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/SetAction.java14
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/UnsetAction.java5
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/newcodeperiod/ws/SetActionTest.java42
3 files changed, 42 insertions, 19 deletions
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/SetAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/SetAction.java
index 80f8634cbaf..3837853b3f4 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/SetAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/SetAction.java
@@ -20,6 +20,10 @@
package org.sonar.server.newcodeperiod.ws;
import com.google.common.base.Preconditions;
+import java.util.EnumSet;
+import java.util.Locale;
+import java.util.Set;
+import javax.annotation.Nullable;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
@@ -40,11 +44,6 @@ import org.sonar.server.component.ComponentFinder;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.user.UserSession;
-import javax.annotation.Nullable;
-import java.util.EnumSet;
-import java.util.Locale;
-import java.util.Set;
-
import static com.google.common.base.Preconditions.checkArgument;
import static java.lang.String.format;
import static org.sonar.db.newcodeperiod.NewCodePeriodType.NUMBER_OF_DAYS;
@@ -111,7 +110,9 @@ public class SetAction implements NewCodePeriodsWsAction {
try (DbSession dbSession = dbClient.openSession(false)) {
String typeStr = request.mandatoryParam(PARAM_TYPE);
String valueStr = request.getParam(PARAM_VALUE).emptyAsNull().or(() -> null);
- NewCodePeriodType type = validateType(typeStr, projectStr == null, branchStr != null);
+ boolean isCommunityEdition = editionProvider.get().filter(t -> t == EditionProvider.Edition.COMMUNITY).isPresent();
+
+ NewCodePeriodType type = validateType(typeStr, projectStr == null, branchStr != null || isCommunityEdition);
NewCodePeriodDto dto = new NewCodePeriodDto();
dto.setType(type);
@@ -121,7 +122,6 @@ public class SetAction implements NewCodePeriodsWsAction {
projectBranch = getProject(dbSession, projectStr, branchStr);
userSession.checkComponentPermission(UserRole.ADMIN, projectBranch);
// in CE set main branch value instead of project value
- boolean isCommunityEdition = editionProvider.get().filter(t -> t == EditionProvider.Edition.COMMUNITY).isPresent();
if (branchStr != null || isCommunityEdition) {
dto.setBranchUuid(projectBranch.uuid());
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/UnsetAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/UnsetAction.java
index 0eb2f2ddef0..74338892126 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/UnsetAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/UnsetAction.java
@@ -19,6 +19,7 @@
*/
package org.sonar.server.newcodeperiod.ws;
+import javax.annotation.Nullable;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
@@ -35,8 +36,6 @@ import org.sonar.server.component.ComponentFinder;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.user.UserSession;
-import javax.annotation.Nullable;
-
import static com.google.common.base.Preconditions.checkArgument;
import static java.lang.String.format;
import static org.sonar.server.component.ComponentFinder.ParamNames.PROJECT_ID_AND_KEY;
@@ -90,7 +89,7 @@ public class UnsetAction implements NewCodePeriodsWsAction {
try (DbSession dbSession = dbClient.openSession(false)) {
String projectUuid = null;
String branchUuid = null;
- ComponentDto projectBranch = null;
+ ComponentDto projectBranch;
// in CE set main branch value instead of project value
boolean isCommunityEdition = editionProvider.get().filter(t -> t == EditionProvider.Edition.COMMUNITY).isPresent();
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/newcodeperiod/ws/SetActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/newcodeperiod/ws/SetActionTest.java
index be5fe9fffe6..2af0b3c2530 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/newcodeperiod/ws/SetActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/newcodeperiod/ws/SetActionTest.java
@@ -19,9 +19,15 @@
*/
package org.sonar.server.newcodeperiod.ws;
+import com.tngtech.java.junit.dataprovider.DataProvider;
+import com.tngtech.java.junit.dataprovider.DataProviderRunner;
+import com.tngtech.java.junit.dataprovider.UseDataProvider;
+import java.util.Optional;
+import javax.annotation.Nullable;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
import org.sonar.api.server.ws.WebService;
import org.sonar.api.utils.System2;
import org.sonar.api.web.UserRole;
@@ -42,16 +48,15 @@ import org.sonar.server.component.TestComponentFinder;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.tester.UserSessionRule;
+import org.sonar.server.ws.TestRequest;
import org.sonar.server.ws.WsActionTester;
-import javax.annotation.Nullable;
-import java.util.Optional;
-
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+@RunWith(DataProviderRunner.class)
public class SetActionTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
@@ -306,16 +311,35 @@ public class SetActionTest {
}
@Test
- public void never_set_project_value_in_community_edition() {
+ @UseDataProvider("provideNewCodePeriodTypeAndValue")
+ public void never_set_project_value_in_community_edition(NewCodePeriodType type, @Nullable String value) {
when(editionProvider.get()).thenReturn(Optional.of(EditionProvider.Edition.COMMUNITY));
ComponentDto project = componentDb.insertMainBranch();
+
+ if (value != null && NewCodePeriodType.SPECIFIC_ANALYSIS.equals(type)) {
+ db.components().insertSnapshot(project, snapshotDto -> snapshotDto.setUuid(value));
+ }
+
logInAsProjectAdministrator(project);
- ws.newRequest()
+ TestRequest request = ws.newRequest()
.setParam("project", project.getKey())
- .setParam("type", "number_of_days")
- .setParam("value", "5")
- .execute();
- assertTableContainsOnly(project.uuid(), project.uuid(), NewCodePeriodType.NUMBER_OF_DAYS, "5");
+ .setParam("type", type.name());
+
+ if (value != null) {
+ request.setParam("value", value);
+ }
+
+ request.execute();
+ assertTableContainsOnly(project.uuid(), project.uuid(), type, value);
+ }
+
+ @DataProvider
+ public static Object[][] provideNewCodePeriodTypeAndValue() {
+ return new Object[][]{
+ {NewCodePeriodType.NUMBER_OF_DAYS, "5"},
+ {NewCodePeriodType.SPECIFIC_ANALYSIS, "analysis-uuid"},
+ {NewCodePeriodType.PREVIOUS_VERSION, null}
+ };
}
@Test