aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v62/CreateDefaultOrganizationTest.java100
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v63/MakeColumnGuardedOfOrganizationsNotNullableTest.java19
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/step/LoadPeriodsStepTest/no_previous_version.xml1
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/step/LoadPeriodsStepTest/previous_version_deleted.xml1
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/step/LoadPeriodsStepTest/previous_version_is_last_one.xml1
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/step/LoadPeriodsStepTest/shared.xml1
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/load_component_id_from_db.xml1
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/load_project_id_from_db.xml1
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_insert_new_issues.xml1
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_update_issues.xml1
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/source/ws/HashActionTest/no_source.xml1
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/source/ws/HashActionTest/shared.xml1
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/source/ws/HashActionTest/show_hashes_on_test_file.xml1
-rw-r--r--sonar-db/src/main/java/org/sonar/db/organization/OrganizationDto.java50
-rw-r--r--sonar-db/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml3
-rw-r--r--sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql2
-rw-r--r--sonar-db/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java40
-rw-r--r--sonar-db/src/test/resources/org/sonar/db/component/ComponentDaoTest/selectForIndexing.xml1
-rw-r--r--sonar-db/src/test/resources/org/sonar/db/component/ComponentDaoTest/shared.xml1
-rw-r--r--sonar-db/src/test/resources/org/sonar/db/component/ComponentDaoWithDuplicatedKeysTest/schema.sql1
20 files changed, 172 insertions, 56 deletions
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v62/CreateDefaultOrganizationTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v62/CreateDefaultOrganizationTest.java
index e142e7a4fe6..819dd109a42 100644
--- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v62/CreateDefaultOrganizationTest.java
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v62/CreateDefaultOrganizationTest.java
@@ -19,6 +19,9 @@
*/
package org.sonar.server.platform.db.migration.version.v62;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
import java.sql.SQLException;
import org.junit.Rule;
import org.junit.Test;
@@ -26,9 +29,9 @@ import org.junit.rules.ExpectedException;
import org.sonar.api.utils.System2;
import org.sonar.core.util.UuidFactory;
import org.sonar.db.DbTester;
-import org.sonar.db.organization.OrganizationDto;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -48,7 +51,7 @@ public class CreateDefaultOrganizationTest {
private CreateDefaultOrganization underTest = new CreateDefaultOrganization(dbTester.database(), system2, uuidFactory);
@Test
- public void execute_insert_data_in_organizations_and_internal_properties_when_it_does_not_exist() throws SQLException {
+ public void execute_insert_data_in_organizations_and_internal_properties_when_it_does_not_exist() throws Exception {
long now = 1_222_999L;
String uuid = "a uuid";
when(system2.now()).thenReturn(now);
@@ -56,21 +59,30 @@ public class CreateDefaultOrganizationTest {
underTest.execute();
- OrganizationDto organizationDto = dbTester.getDbClient().organizationDao().selectByKey(dbTester.getSession(), DEFAULT_ORGANIZATION_KEY).get();
- assertThat(organizationDto.getUuid()).isEqualTo(uuid);
- assertThat(organizationDto.getKey()).isEqualTo(DEFAULT_ORGANIZATION_KEY);
- assertThat(organizationDto.getName()).isEqualTo(DEFAULT_ORGANIZATION_NAME);
- assertThat(organizationDto.getDescription()).isNull();
- assertThat(organizationDto.getUrl()).isNull();
- assertThat(organizationDto.getAvatarUrl()).isNull();
- assertThat(organizationDto.getCreatedAt()).isEqualTo(now);
- assertThat(organizationDto.getUpdatedAt()).isEqualTo(now);
+ try (Connection connection = dbTester.openConnection();
+ PreparedStatement preparedStatement = createSelectStatementByKey(connection, DEFAULT_ORGANIZATION_KEY);
+ ResultSet resultSet = preparedStatement.executeQuery()) {
+ if (resultSet.next()) {
+ assertThat(resultSet.getString(1)).isEqualTo(uuid);
+ assertThat(resultSet.getString(2)).isEqualTo(DEFAULT_ORGANIZATION_KEY);
+ assertThat(resultSet.getString(3)).isEqualTo(DEFAULT_ORGANIZATION_NAME);
+ assertThat(resultSet.getString(4)).isNull();
+ assertThat(resultSet.getString(5)).isNull();
+ assertThat(resultSet.getString(6)).isNull();
+ assertThat(resultSet.getLong(7)).isEqualTo(now);
+ assertThat(resultSet.getLong(8)).isEqualTo(now);
+
+ assertThat(resultSet.next()).isFalse();
+ } else {
+ fail("Can't retrieve organization " + uuid);
+ }
+ }
verifyInternalProperty(uuid);
}
@Test
- public void execute_inserts_internal_property_if_default_organization_already_exists() throws SQLException {
+ public void execute_inserts_internal_property_if_default_organization_already_exists() throws Exception {
long past = 2_999_033L;
String uuid = "uuidAAAA";
insertExistingOrganization(uuid, past);
@@ -91,7 +103,7 @@ public class CreateDefaultOrganizationTest {
}
@Test
- public void execute_has_no_effect_if_organization_and_internal_property_already_exist() throws SQLException {
+ public void execute_has_no_effect_if_organization_and_internal_property_already_exist() throws Exception {
long past = 2_999_033L;
String uuid = "uuidAAAA";
insertExistingOrganization(uuid, past);
@@ -120,25 +132,51 @@ public class CreateDefaultOrganizationTest {
dbTester.commit();
}
- private void insertExistingOrganization(String uuid, long past) {
- when(system2.now()).thenReturn(past);
- dbTester.getDbClient().organizationDao().insert(dbTester.getSession(),
- new OrganizationDto()
- .setUuid(uuid)
- .setKey(DEFAULT_ORGANIZATION_KEY)
- .setName("whatever"));
- dbTester.commit();
+ private void insertExistingOrganization(String uuid, long past) throws Exception {
+ try (Connection connection = dbTester.openConnection();
+ PreparedStatement preparedStatement = connection.prepareStatement("insert into organizations (uuid,kee,name,created_at,updated_at) values (?,?,?,?,?)")) {
+ preparedStatement.setString(1, uuid);
+ preparedStatement.setString(2, DEFAULT_ORGANIZATION_KEY);
+ preparedStatement.setString(3, "whatever");
+ preparedStatement.setLong(4, past);
+ preparedStatement.setLong(5, past);
+ preparedStatement.execute();
+ if (!connection.getAutoCommit()) {
+ connection.commit();
+ }
+ }
+ }
+
+ private void verifyExistingOrganization(String uuid, long past) throws Exception {
+ try (Connection connection = dbTester.openConnection();
+ PreparedStatement preparedStatement = createSelectStatementByUuid(connection, uuid);
+ ResultSet resultSet = preparedStatement.executeQuery()) {
+ if (resultSet.next()) {
+ assertThat(resultSet.getString(1)).isEqualTo(uuid);
+ assertThat(resultSet.getString(2)).isEqualTo(DEFAULT_ORGANIZATION_KEY);
+ assertThat(resultSet.getString(3)).isEqualTo("whatever");
+ assertThat(resultSet.getString(4)).isNull();
+ assertThat(resultSet.getString(5)).isNull();
+ assertThat(resultSet.getString(6)).isNull();
+ assertThat(resultSet.getLong(7)).isEqualTo(past);
+ assertThat(resultSet.getLong(8)).isEqualTo(past);
+
+ assertThat(resultSet.next()).isFalse();
+ } else {
+ fail("Can't retrieve organization " + uuid);
+ }
+ }
+ }
+
+ private PreparedStatement createSelectStatementByUuid(Connection connection, String uuid) throws SQLException {
+ PreparedStatement preparedStatement = connection.prepareStatement("select uuid,kee,name,description,url,avatar_url,created_at,updated_at from organizations where uuid=?");
+ preparedStatement.setString(1, uuid);
+ return preparedStatement;
}
- private void verifyExistingOrganization(String uuid, long past) {
- OrganizationDto organizationDto = dbTester.getDbClient().organizationDao().selectByKey(dbTester.getSession(), DEFAULT_ORGANIZATION_KEY).get();
- assertThat(organizationDto.getUuid()).isEqualTo(uuid);
- assertThat(organizationDto.getKey()).isEqualTo(DEFAULT_ORGANIZATION_KEY);
- assertThat(organizationDto.getName()).isEqualTo("whatever");
- assertThat(organizationDto.getDescription()).isNull();
- assertThat(organizationDto.getUrl()).isNull();
- assertThat(organizationDto.getAvatarUrl()).isNull();
- assertThat(organizationDto.getCreatedAt()).isEqualTo(past);
- assertThat(organizationDto.getUpdatedAt()).isEqualTo(past);
+ private PreparedStatement createSelectStatementByKey(Connection connection, String kee) throws SQLException {
+ PreparedStatement preparedStatement = connection.prepareStatement("select uuid,kee,name,description,url,avatar_url,created_at,updated_at from organizations where kee=?");
+ preparedStatement.setString(1, kee);
+ return preparedStatement;
}
}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v63/MakeColumnGuardedOfOrganizationsNotNullableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v63/MakeColumnGuardedOfOrganizationsNotNullableTest.java
index b60f8971570..6ea86eb2425 100644
--- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v63/MakeColumnGuardedOfOrganizationsNotNullableTest.java
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v63/MakeColumnGuardedOfOrganizationsNotNullableTest.java
@@ -1,3 +1,22 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
package org.sonar.server.platform.db.migration.version.v63;
import java.sql.SQLException;
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/step/LoadPeriodsStepTest/no_previous_version.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/step/LoadPeriodsStepTest/no_previous_version.xml
index 0d3e4cf9395..74978f0071c 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/step/LoadPeriodsStepTest/no_previous_version.xml
+++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/step/LoadPeriodsStepTest/no_previous_version.xml
@@ -3,6 +3,7 @@
<organizations uuid="org1"
kee="org1_key"
name="org1_name"
+ guarded="[false]"
created_at="1000"
updated_at="2000"/>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/step/LoadPeriodsStepTest/previous_version_deleted.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/step/LoadPeriodsStepTest/previous_version_deleted.xml
index ce221c0ad9b..afc4f39f650 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/step/LoadPeriodsStepTest/previous_version_deleted.xml
+++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/step/LoadPeriodsStepTest/previous_version_deleted.xml
@@ -3,6 +3,7 @@
<organizations uuid="org1"
kee="org1_key"
name="org1_name"
+ guarded="[false]"
created_at="1000"
updated_at="2000"/>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/step/LoadPeriodsStepTest/previous_version_is_last_one.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/step/LoadPeriodsStepTest/previous_version_is_last_one.xml
index fa4f2dd141f..78f7b2d2e4f 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/step/LoadPeriodsStepTest/previous_version_is_last_one.xml
+++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/step/LoadPeriodsStepTest/previous_version_is_last_one.xml
@@ -3,6 +3,7 @@
<organizations uuid="org1"
kee="org1_key"
name="org1_name"
+ guarded="[false]"
created_at="1000"
updated_at="2000"/>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/step/LoadPeriodsStepTest/shared.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/step/LoadPeriodsStepTest/shared.xml
index 8707b71e42a..df806896d91 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/step/LoadPeriodsStepTest/shared.xml
+++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/step/LoadPeriodsStepTest/shared.xml
@@ -3,6 +3,7 @@
<organizations uuid="org1"
kee="org1_key"
name="org1_name"
+ guarded="[false]"
created_at="1000"
updated_at="2000"/>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/load_component_id_from_db.xml b/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/load_component_id_from_db.xml
index 9403a26202f..912630ef352 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/load_component_id_from_db.xml
+++ b/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/load_component_id_from_db.xml
@@ -3,6 +3,7 @@
<organizations uuid="org1"
kee="org1_key"
name="org1_name"
+ guarded="[false]"
created_at="1000"
updated_at="2000"/>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/load_project_id_from_db.xml b/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/load_project_id_from_db.xml
index 733373d875e..a2f644868a2 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/load_project_id_from_db.xml
+++ b/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/load_project_id_from_db.xml
@@ -3,6 +3,7 @@
<organizations uuid="org1"
kee="org1_key"
name="org1_name"
+ guarded="[false]"
created_at="1000"
updated_at="2000"/>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_insert_new_issues.xml b/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_insert_new_issues.xml
index 9403a26202f..912630ef352 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_insert_new_issues.xml
+++ b/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_insert_new_issues.xml
@@ -3,6 +3,7 @@
<organizations uuid="org1"
kee="org1_key"
name="org1_name"
+ guarded="[false]"
created_at="1000"
updated_at="2000"/>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_update_issues.xml b/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_update_issues.xml
index 619981235dd..f5fd1163000 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_update_issues.xml
+++ b/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_update_issues.xml
@@ -3,6 +3,7 @@
<organizations uuid="org1"
kee="org1_key"
name="org1_name"
+ guarded="[false]"
created_at="1000"
updated_at="2000"/>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/source/ws/HashActionTest/no_source.xml b/server/sonar-server/src/test/resources/org/sonar/server/source/ws/HashActionTest/no_source.xml
index 4f4626059be..666faef4814 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/source/ws/HashActionTest/no_source.xml
+++ b/server/sonar-server/src/test/resources/org/sonar/server/source/ws/HashActionTest/no_source.xml
@@ -3,6 +3,7 @@
<organizations uuid="org1"
kee="org1_key"
name="org1_name"
+ guarded="[false]"
created_at="1000"
updated_at="2000"/>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/source/ws/HashActionTest/shared.xml b/server/sonar-server/src/test/resources/org/sonar/server/source/ws/HashActionTest/shared.xml
index 921f35fb471..1c8ccadae3b 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/source/ws/HashActionTest/shared.xml
+++ b/server/sonar-server/src/test/resources/org/sonar/server/source/ws/HashActionTest/shared.xml
@@ -3,6 +3,7 @@
<organizations uuid="org1"
kee="org1_key"
name="org1_name"
+ guarded="[false]"
created_at="1000"
updated_at="2000"/>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/source/ws/HashActionTest/show_hashes_on_test_file.xml b/server/sonar-server/src/test/resources/org/sonar/server/source/ws/HashActionTest/show_hashes_on_test_file.xml
index 2f0a227126a..e63a709b461 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/source/ws/HashActionTest/show_hashes_on_test_file.xml
+++ b/server/sonar-server/src/test/resources/org/sonar/server/source/ws/HashActionTest/show_hashes_on_test_file.xml
@@ -3,6 +3,7 @@
<organizations uuid="org1"
kee="org1_key"
name="org1_name"
+ guarded="[false]"
created_at="1000"
updated_at="2000"/>
diff --git a/sonar-db/src/main/java/org/sonar/db/organization/OrganizationDto.java b/sonar-db/src/main/java/org/sonar/db/organization/OrganizationDto.java
index 095f40e7ef2..2644132fc40 100644
--- a/sonar-db/src/main/java/org/sonar/db/organization/OrganizationDto.java
+++ b/sonar-db/src/main/java/org/sonar/db/organization/OrganizationDto.java
@@ -34,6 +34,10 @@ public class OrganizationDto {
private String url;
/** avatar url can be null */
private String avatarUrl;
+ /**
+ * Flag indicated whether being root is required to be able to delete this organization.
+ */
+ private boolean guarded = false;
private long createdAt;
private long updatedAt;
@@ -64,24 +68,6 @@ public class OrganizationDto {
return this;
}
- public long getCreatedAt() {
- return createdAt;
- }
-
- public OrganizationDto setCreatedAt(long createdAt) {
- this.createdAt = createdAt;
- return this;
- }
-
- public long getUpdatedAt() {
- return updatedAt;
- }
-
- public OrganizationDto setUpdatedAt(long updatedAt) {
- this.updatedAt = updatedAt;
- return this;
- }
-
public String getDescription() {
return description;
}
@@ -109,6 +95,33 @@ public class OrganizationDto {
return this;
}
+ public boolean isGuarded() {
+ return guarded;
+ }
+
+ public OrganizationDto setGuarded(boolean guarded) {
+ this.guarded = guarded;
+ return this;
+ }
+
+ public long getCreatedAt() {
+ return createdAt;
+ }
+
+ public OrganizationDto setCreatedAt(long createdAt) {
+ this.createdAt = createdAt;
+ return this;
+ }
+
+ public long getUpdatedAt() {
+ return updatedAt;
+ }
+
+ public OrganizationDto setUpdatedAt(long updatedAt) {
+ this.updatedAt = updatedAt;
+ return this;
+ }
+
@Override
public String toString() {
return "OrganizationDto{" +
@@ -118,6 +131,7 @@ public class OrganizationDto {
", description='" + description + '\'' +
", url='" + url + '\'' +
", avatarUrl='" + avatarUrl + '\'' +
+ ", guarded=" + guarded +
", createdAt=" + createdAt +
", updatedAt=" + updatedAt +
'}';
diff --git a/sonar-db/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml b/sonar-db/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml
index 5b5a44ce526..fa7e3d41862 100644
--- a/sonar-db/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml
+++ b/sonar-db/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml
@@ -9,6 +9,7 @@
org.description as "description",
org.url as "url",
org.avatar_url as "avatarUrl",
+ org.guarded as "guarded",
org.created_at as "createdAt",
org.updated_at as "updatedAt"
</sql>
@@ -130,6 +131,7 @@
description,
url,
avatar_url,
+ guarded,
created_at,
updated_at
)
@@ -141,6 +143,7 @@
#{organization.description, jdbcType=VARCHAR},
#{organization.url, jdbcType=VARCHAR},
#{organization.avatarUrl, jdbcType=VARCHAR},
+ #{organization.guarded, jdbcType=BOOLEAN},
#{organization.createdAt, jdbcType=BIGINT},
#{organization.updatedAt, jdbcType=BIGINT}
)
diff --git a/sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql b/sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql
index 00d131c627c..9ebdb68b1c9 100644
--- a/sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql
+++ b/sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql
@@ -530,7 +530,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1512');
INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, EXTERNAL_IDENTITY, EXTERNAL_IDENTITY_PROVIDER, USER_LOCAL, CRYPTED_PASSWORD, SALT, IS_ROOT, CREATED_AT, UPDATED_AT) VALUES (1, 'admin', 'Administrator', '', 'admin', 'sonarqube', true, 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', true, '1418215735482', '1418215735482');
ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2;
-INSERT INTO ORGANIZATIONS (UUID, KEE, NAME, CREATED_AT, UPDATED_AT) VALUES ('AVdqnciQUUs7Zd3KPvFD', 'default-organization', 'Default Organization', '1474962596482', '1474962596482');
+INSERT INTO ORGANIZATIONS (UUID, KEE, NAME, GUARDED, CREATED_AT, UPDATED_AT) VALUES ('AVdqnciQUUs7Zd3KPvFD', 'default-organization', 'Default Organization', false, '1474962596482', '1474962596482');
INSERT INTO INTERNAL_PROPERTIES (KEE, IS_EMPTY, TEXT_VALUE, CREATED_AT) VALUES ('organization.default', false, 'AVdqnciQUUs7Zd3KPvFD', '1474962596482');
INSERT INTO GROUPS(ID, ORGANIZATION_UUID, NAME, DESCRIPTION, CREATED_AT, UPDATED_AT) VALUES (1, 'AVdqnciQUUs7Zd3KPvFD', 'sonar-administrators', 'System administrators', '2011-09-26 22:27:51.0', '2011-09-26 22:27:51.0');
diff --git a/sonar-db/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java b/sonar-db/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java
index 23bcce30f66..5a2df5b94c4 100644
--- a/sonar-db/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java
+++ b/sonar-db/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java
@@ -39,6 +39,8 @@ import org.sonar.api.utils.System2;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
+import org.sonar.db.dialect.Dialect;
+import org.sonar.db.dialect.Oracle;
import org.sonar.db.user.GroupDto;
import org.sonar.db.user.UserDto;
@@ -62,16 +64,18 @@ public class OrganizationDaoTest {
.setName("the name 1")
.setDescription("the description 1")
.setUrl("the url 1")
- .setAvatarUrl("the avatar url 1");
+ .setAvatarUrl("the avatar url 1")
+ .setGuarded(false);
private static final OrganizationDto ORGANIZATION_DTO_2 = new OrganizationDto()
.setUuid("uuid 2")
.setKey("the_key 2")
.setName("the name 2")
.setDescription("the description 2")
.setUrl("the url 2")
- .setAvatarUrl("the avatar url 2");
- public static final String PERMISSION_1 = "foo";
- public static final String PERMISSION_2 = "bar";
+ .setAvatarUrl("the avatar url 2")
+ .setGuarded(true);
+ private static final String PERMISSION_1 = "foo";
+ private static final String PERMISSION_2 = "bar";
private System2 system2 = mock(System2.class);
@@ -117,12 +121,21 @@ public class OrganizationDaoTest {
assertThat(row.get("avatarUrl")).isEqualTo(ORGANIZATION_DTO_1.getAvatarUrl());
assertThat(row.get("createdAt")).isEqualTo(ORGANIZATION_DTO_1.getCreatedAt());
assertThat(row.get("updatedAt")).isEqualTo(ORGANIZATION_DTO_1.getUpdatedAt());
+ assertThat(row.get("guarded")).isEqualTo(toBool(ORGANIZATION_DTO_1.isGuarded()));
assertThat(row.get("defaultTemplate")).isNull();
assertThat(row.get("projectDefaultTemplate")).isNull();
assertThat(row.get("viewDefaultTemplate")).isNull();
}
@Test
+ public void insert_persists_boolean_property_guarded_of_OrganizationDto() {
+ insertOrganization(ORGANIZATION_DTO_2);
+
+ Map<String, Object> row = selectSingleRow();
+ assertThat(row.get("guarded")).isEqualTo(toBool(ORGANIZATION_DTO_2.isGuarded()));
+ }
+
+ @Test
public void description_url_and_avatarUrl_are_optional() {
when(system2.now()).thenReturn(SOME_DATE);
insertOrganization(copyOf(ORGANIZATION_DTO_1).setDescription(null).setUrl(null).setAvatarUrl(null));
@@ -134,6 +147,7 @@ public class OrganizationDaoTest {
assertThat(row.get("description")).isNull();
assertThat(row.get("url")).isNull();
assertThat(row.get("avatarUrl")).isNull();
+ assertThat(row.get("guarded")).isEqualTo(toBool(ORGANIZATION_DTO_1.isGuarded()));
assertThat(row.get("createdAt")).isEqualTo(SOME_DATE);
assertThat(row.get("updatedAt")).isEqualTo(SOME_DATE);
assertThat(row.get("defaultTemplate")).isNull();
@@ -141,6 +155,14 @@ public class OrganizationDaoTest {
assertThat(row.get("viewDefaultTemplate")).isNull();
}
+ private Object toBool(boolean guarded) {
+ Dialect dialect = dbTester.database().getDialect();
+ if (dialect.getId().equals(Oracle.ID)) {
+ return guarded ? 1L : 0L;
+ }
+ return guarded;
+ }
+
@Test
public void insert_fails_if_row_with_uuid_already_exists() {
insertOrganization(ORGANIZATION_DTO_1);
@@ -836,6 +858,7 @@ public class OrganizationDaoTest {
" name," +
" default_perm_template_project," +
" default_perm_template_view," +
+ " guarded," +
" created_at," +
" updated_at" +
" )" +
@@ -847,6 +870,7 @@ public class OrganizationDaoTest {
" ?," +
" ?," +
" ?," +
+ " ?," +
" ?" +
" )")) {
preparedStatement.setString(1, organizationUuid);
@@ -854,8 +878,9 @@ public class OrganizationDaoTest {
preparedStatement.setString(3, organizationUuid);
preparedStatement.setString(4, project);
preparedStatement.setString(5, view);
- preparedStatement.setLong(6, 1000L);
- preparedStatement.setLong(7, 2000L);
+ preparedStatement.setBoolean(6, false);
+ preparedStatement.setLong(7, 1000L);
+ preparedStatement.setLong(8, 2000L);
preparedStatement.execute();
} catch (SQLException e) {
throw new RuntimeException("dirty insert failed", e);
@@ -878,6 +903,7 @@ public class OrganizationDaoTest {
assertThat(dto.getName()).isEqualTo(ORGANIZATION_DTO_1.getName());
assertThat(dto.getDescription()).isEqualTo(ORGANIZATION_DTO_1.getDescription());
assertThat(dto.getUrl()).isEqualTo(ORGANIZATION_DTO_1.getUrl());
+ assertThat(dto.isGuarded()).isEqualTo(ORGANIZATION_DTO_1.isGuarded());
assertThat(dto.getAvatarUrl()).isEqualTo(ORGANIZATION_DTO_1.getAvatarUrl());
assertThat(dto.getCreatedAt()).isEqualTo(ORGANIZATION_DTO_1.getCreatedAt());
assertThat(dto.getUpdatedAt()).isEqualTo(ORGANIZATION_DTO_1.getUpdatedAt());
@@ -889,6 +915,7 @@ public class OrganizationDaoTest {
assertThat(dto.getName()).isEqualTo(expected.getName());
assertThat(dto.getDescription()).isEqualTo(expected.getDescription());
assertThat(dto.getUrl()).isEqualTo(expected.getUrl());
+ assertThat(dto.isGuarded()).isEqualTo(expected.isGuarded());
assertThat(dto.getAvatarUrl()).isEqualTo(expected.getAvatarUrl());
assertThat(dto.getCreatedAt()).isEqualTo(expected.getCreatedAt());
assertThat(dto.getUpdatedAt()).isEqualTo(expected.getUpdatedAt());
@@ -897,6 +924,7 @@ public class OrganizationDaoTest {
private Map<String, Object> selectSingleRow() {
List<Map<String, Object>> rows = dbTester.select("select" +
" uuid as \"uuid\", kee as \"key\", name as \"name\", description as \"description\", url as \"url\", avatar_url as \"avatarUrl\"," +
+ " guarded as \"guarded\"," +
" created_at as \"createdAt\", updated_at as \"updatedAt\"," +
" default_perm_template_project as \"projectDefaultPermTemplate\"," +
" default_perm_template_view as \"viewDefaultPermTemplate\"" +
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ComponentDaoTest/selectForIndexing.xml b/sonar-db/src/test/resources/org/sonar/db/component/ComponentDaoTest/selectForIndexing.xml
index 7c4f24eda93..596dd4eec2f 100644
--- a/sonar-db/src/test/resources/org/sonar/db/component/ComponentDaoTest/selectForIndexing.xml
+++ b/sonar-db/src/test/resources/org/sonar/db/component/ComponentDaoTest/selectForIndexing.xml
@@ -3,6 +3,7 @@
<organizations uuid="org1"
kee="org1_key"
name="org1_name"
+ guarded="[false]"
created_at="1000"
updated_at="1000"/>
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ComponentDaoTest/shared.xml b/sonar-db/src/test/resources/org/sonar/db/component/ComponentDaoTest/shared.xml
index f3656c5ba02..9456f3b138b 100644
--- a/sonar-db/src/test/resources/org/sonar/db/component/ComponentDaoTest/shared.xml
+++ b/sonar-db/src/test/resources/org/sonar/db/component/ComponentDaoTest/shared.xml
@@ -3,6 +3,7 @@
<organizations uuid="org1"
kee="org1_key"
name="org1_name"
+ guarded="[false]"
created_at="1000"
updated_at="1000"/>
diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ComponentDaoWithDuplicatedKeysTest/schema.sql b/sonar-db/src/test/resources/org/sonar/db/component/ComponentDaoWithDuplicatedKeysTest/schema.sql
index 678afc9442f..dc2e084f3b9 100644
--- a/sonar-db/src/test/resources/org/sonar/db/component/ComponentDaoWithDuplicatedKeysTest/schema.sql
+++ b/sonar-db/src/test/resources/org/sonar/db/component/ComponentDaoWithDuplicatedKeysTest/schema.sql
@@ -5,6 +5,7 @@ CREATE TABLE "ORGANIZATIONS" (
"DESCRIPTION" VARCHAR(256),
"URL" VARCHAR(256),
"AVATAR_URL" VARCHAR(256),
+ "GUARDED" BOOLEAN NOT NULL,
"CREATED_AT" BIGINT NOT NULL,
"UPDATED_AT" BIGINT NOT NULL
);