aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-server/src/test
diff options
context:
space:
mode:
authorJacek <52388493+jacek-poreda-sonarsource@users.noreply.github.com>2019-07-19 10:59:07 +0200
committerSonarTech <sonartech@sonarsource.com>2019-07-19 20:21:15 +0200
commit7d8052837730ed748a0dd48f647395a81e2a8d1e (patch)
tree1676547a19c68ccddc98dca78e4a94b9cb63fe67 /server/sonar-server/src/test
parentbd954c8e77d79eaf23d7c8d3b681fa9af634004c (diff)
downloadsonarqube-7d8052837730ed748a0dd48f647395a81e2a8d1e.tar.gz
sonarqube-7d8052837730ed748a0dd48f647395a81e2a8d1e.zip
SONAR-8115 Storing default qgate in table (blue green deploy safety) (#1925)
* add DDL for project_qgate table * support saving/update/delete to project quality gate and properties * add db migration tests
Diffstat (limited to 'server/sonar-server/src/test')
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/DeselectActionTest.java36
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/DestroyActionTest.java5
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/SelectActionTest.java53
3 files changed, 81 insertions, 13 deletions
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/DeselectActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/DeselectActionTest.java
index e3ced0d69dc..8ef3fedbd48 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/DeselectActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/DeselectActionTest.java
@@ -19,6 +19,7 @@
*/
package org.sonar.server.qualitygate.ws;
+import java.util.Optional;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -77,7 +78,7 @@ public class DeselectActionTest {
.setParam("organization", organization.getKey())
.execute();
- assertDeselected(project.getId());
+ assertDeselected(project);
}
@Test
@@ -93,7 +94,7 @@ public class DeselectActionTest {
.setParam("organization", organization.getKey())
.execute();
- assertDeselected(project.getId());
+ assertDeselected(project);
}
@Test
@@ -109,7 +110,7 @@ public class DeselectActionTest {
.setParam("organization", organization.getKey())
.execute();
- assertDeselected(project.getId());
+ assertDeselected(project);
}
@Test
@@ -125,7 +126,7 @@ public class DeselectActionTest {
.setParam("organization", organization.getKey())
.execute();
- assertDeselected(project.getId());
+ assertDeselected(project);
}
@Test
@@ -134,7 +135,6 @@ public class DeselectActionTest {
userSession.addPermission(ADMINISTER_QUALITY_GATES, organization);
QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
ComponentDto project = db.components().insertPrivateProject(organization);
- String gateId = valueOf(qualityGate.getId());
associateProjectToQualityGate(project, qualityGate);
// Another project
ComponentDto anotherProject = db.components().insertPrivateProject(organization);
@@ -145,8 +145,8 @@ public class DeselectActionTest {
.setParam("organization", organization.getKey())
.execute();
- assertDeselected(project.getId());
- assertSelected(gateId, anotherProject.getId());
+ assertDeselected(project);
+ assertSelected(qualityGate, anotherProject);
}
@Test
@@ -161,7 +161,7 @@ public class DeselectActionTest {
.setParam("projectKey", project.getKey())
.execute();
- assertDeselected(project.getId());
+ assertDeselected(project);
}
@Test
@@ -304,14 +304,26 @@ public class DeselectActionTest {
.setResourceId(project.getId())
.setValue(qualityGate.getId().toString())
.setKey(SONAR_QUALITYGATE_PROPERTY));
+ db.qualityGates().associateProjectToQualityGate(project, qualityGate);
db.commit();
}
- private void assertDeselected(long projectId) {
- assertThat(dbClient.propertiesDao().selectProjectProperty(projectId, SONAR_QUALITYGATE_PROPERTY)).isNull();
+ private void assertDeselected(ComponentDto project) {
+ Optional<String> qGateUuid = db.qualityGates().selectQGateUuidByComponentUuid(project.uuid());
+ assertThat(qGateUuid)
+ .isNotNull()
+ .isEmpty();
+
+ assertThat(dbClient.propertiesDao().selectProjectProperty(project.getId(), SONAR_QUALITYGATE_PROPERTY)).isNull();
}
- private void assertSelected(String qGateId, long projectId) {
- assertThat(dbClient.propertiesDao().selectProjectProperty(projectId, SONAR_QUALITYGATE_PROPERTY).getValue()).isEqualTo(qGateId);
+ private void assertSelected(QGateWithOrgDto qualityGate, ComponentDto project) {
+ Optional<String> qGateUuid = db.qualityGates().selectQGateUuidByComponentUuid(project.uuid());
+ assertThat(qGateUuid)
+ .isNotNull()
+ .isNotEmpty()
+ .hasValue(qualityGate.getUuid());
+ String qGateId = dbClient.propertiesDao().selectProjectProperty(project.getId(), SONAR_QUALITYGATE_PROPERTY).getValue();
+ assertThat(qGateId).isEqualTo(String.valueOf(qualityGate.getId()));
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/DestroyActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/DestroyActionTest.java
index f11a9191242..9fe569ccaf2 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/DestroyActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/DestroyActionTest.java
@@ -119,6 +119,11 @@ public class DestroyActionTest {
.isEmpty();
assertThat(db.getDbClient().propertiesDao().selectProjectProperties(prj2.getDbKey()))
.isEmpty();
+
+ assertThat(db.getDbClient().projectQgateAssociationDao().selectQGateUuidByComponentUuid(dbSession, prj1.uuid()))
+ .isEmpty();
+ assertThat(db.getDbClient().projectQgateAssociationDao().selectQGateUuidByComponentUuid(dbSession, prj2.uuid()))
+ .isEmpty();
}
@Test
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/SelectActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/SelectActionTest.java
index 4c53dcb6a7f..d38f148f5c8 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/SelectActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/SelectActionTest.java
@@ -19,6 +19,7 @@
*/
package org.sonar.server.qualitygate.ws;
+import java.util.Optional;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -106,6 +107,51 @@ public class SelectActionTest {
}
@Test
+ public void change_quality_gate_for_project() {
+ OrganizationDto organization = db.organizations().insert();
+ userSession.addPermission(ADMINISTER_QUALITY_GATES, organization);
+ QGateWithOrgDto initialQualityGate = db.qualityGates().insertQualityGate(organization);
+ QGateWithOrgDto secondQualityGate = db.qualityGates().insertQualityGate(organization);
+ ComponentDto project = db.components().insertPrivateProject(organization);
+
+ ws.newRequest()
+ .setParam("gateId", initialQualityGate.getId().toString())
+ .setParam("projectKey", project.getKey())
+ .setParam("organization", organization.getKey())
+ .execute();
+
+ ws.newRequest()
+ .setParam("gateId", secondQualityGate.getId().toString())
+ .setParam("projectKey", project.getKey())
+ .setParam("organization", organization.getKey())
+ .execute();
+
+ assertSelected(secondQualityGate, project);
+ }
+
+ @Test
+ public void select_same_quality_gate_for_project_twice() {
+ OrganizationDto organization = db.organizations().insert();
+ userSession.addPermission(ADMINISTER_QUALITY_GATES, organization);
+ QGateWithOrgDto initialQualityGate = db.qualityGates().insertQualityGate(organization);
+ ComponentDto project = db.components().insertPrivateProject(organization);
+
+ ws.newRequest()
+ .setParam("gateId", initialQualityGate.getId().toString())
+ .setParam("projectKey", project.getKey())
+ .setParam("organization", organization.getKey())
+ .execute();
+
+ ws.newRequest()
+ .setParam("gateId", initialQualityGate.getId().toString())
+ .setParam("projectKey", project.getKey())
+ .setParam("organization", organization.getKey())
+ .execute();
+
+ assertSelected(initialQualityGate, project);
+ }
+
+ @Test
public void project_admin() {
OrganizationDto organization = db.organizations().insert();
QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
@@ -179,7 +225,7 @@ public class SelectActionTest {
expectedException.expect(NotFoundException.class);
ws.newRequest()
- .setParam("gateId", String.valueOf("1"))
+ .setParam("gateId", "1")
.setParam("projectKey", project.getKey())
.setParam("organization", organization.getKey())
.execute();
@@ -296,6 +342,11 @@ public class SelectActionTest {
private void assertSelected(QualityGateDto qualityGate, ComponentDto project) {
assertThat(dbClient.propertiesDao().selectProjectProperty(project.getId(), SONAR_QUALITYGATE_PROPERTY).getValue()).isEqualTo(qualityGate.getId().toString());
+ Optional<String> qGateUuid = db.qualityGates().selectQGateUuidByComponentUuid(project.uuid());
+ assertThat(qGateUuid)
+ .isNotNull()
+ .isNotEmpty()
+ .hasValue(qualityGate.getUuid());
}
}