aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java4
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java14
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java4
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/alm/ALM.java35
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmAppInstallDao.java106
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmAppInstallDto.java132
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmAppInstallMapper.java53
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmTesting.java29
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/alm/OrganizationAlmBindingDao.java97
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/alm/OrganizationAlmBindingDto.java138
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/alm/OrganizationAlmBindingMapper.java46
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationDao.java5
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationMapper.java3
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/alm/AlmAppInstallMapper.xml106
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/alm/OrganizationAlmBindingMapper.xml99
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml11
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/alm/AlmAppInstallDaoTest.java352
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/alm/OrganizationAlmBindingDaoTest.java222
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/DbTester.java7
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/alm/AlmDbTester.java62
20 files changed, 0 insertions, 1525 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java b/server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java
index 9baeac01d08..84799ca2387 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java
@@ -23,8 +23,6 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.sonar.core.platform.Module;
-import org.sonar.db.alm.AlmAppInstallDao;
-import org.sonar.db.alm.OrganizationAlmBindingDao;
import org.sonar.db.alm.pat.AlmPatDao;
import org.sonar.db.alm.setting.AlmSettingDao;
import org.sonar.db.alm.setting.ProjectAlmSettingDao;
@@ -121,7 +119,6 @@ public class DaoModule extends Module {
GroupDao.class,
GroupMembershipDao.class,
GroupPermissionDao.class,
- AlmAppInstallDao.class,
AlmSettingDao.class,
AlmPatDao.class,
ProjectAlmSettingDao.class,
@@ -134,7 +131,6 @@ public class DaoModule extends Module {
MetricDao.class,
NewCodePeriodDao.class,
NotificationQueueDao.class,
- OrganizationAlmBindingDao.class,
OrganizationDao.class,
PermissionTemplateCharacteristicDao.class,
PermissionTemplateDao.class,
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java b/server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java
index b63d1085963..30f0536b259 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java
@@ -21,8 +21,6 @@ package org.sonar.db;
import java.util.IdentityHashMap;
import java.util.Map;
-import org.sonar.db.alm.AlmAppInstallDao;
-import org.sonar.db.alm.OrganizationAlmBindingDao;
import org.sonar.db.alm.pat.AlmPatDao;
import org.sonar.db.alm.setting.AlmSettingDao;
import org.sonar.db.alm.setting.ProjectAlmSettingDao;
@@ -103,7 +101,6 @@ public class DbClient {
private final QualityProfileDao qualityProfileDao;
private final QualityProfileExportDao qualityProfileExportDao;
private final PropertiesDao propertiesDao;
- private final AlmAppInstallDao almAppInstallDao;
private final AlmSettingDao almSettingDao;
private final AlmPatDao almPatDao;
private final ProjectAlmSettingDao projectAlmSettingDao;
@@ -159,7 +156,6 @@ public class DbClient {
private final WebhookDao webhookDao;
private final WebhookDeliveryDao webhookDeliveryDao;
private final ProjectMappingsDao projectMappingsDao;
- private final OrganizationAlmBindingDao organizationAlmBindingDao;
private final NewCodePeriodDao newCodePeriodDao;
private final ProjectDao projectDao;
private final SessionTokensDao sessionTokensDao;
@@ -176,7 +172,6 @@ public class DbClient {
for (Dao dao : daos) {
map.put(dao.getClass(), dao);
}
- almAppInstallDao = getDao(map, AlmAppInstallDao.class);
almSettingDao = getDao(map, AlmSettingDao.class);
almPatDao = getDao(map, AlmPatDao.class);
projectAlmSettingDao = getDao(map, ProjectAlmSettingDao.class);
@@ -237,7 +232,6 @@ public class DbClient {
webhookDao = getDao(map, WebhookDao.class);
webhookDeliveryDao = getDao(map, WebhookDeliveryDao.class);
projectMappingsDao = getDao(map, ProjectMappingsDao.class);
- organizationAlmBindingDao = getDao(map, OrganizationAlmBindingDao.class);
internalComponentPropertiesDao = getDao(map, InternalComponentPropertiesDao.class);
newCodePeriodDao = getDao(map, NewCodePeriodDao.class);
projectDao = getDao(map, ProjectDao.class);
@@ -255,10 +249,6 @@ public class DbClient {
return database;
}
- public AlmAppInstallDao almAppInstallDao() {
- return almAppInstallDao;
- }
-
public AlmSettingDao almSettingDao() {
return almSettingDao;
}
@@ -517,10 +507,6 @@ public class DbClient {
return projectMappingsDao;
}
- public OrganizationAlmBindingDao organizationAlmBindingDao() {
- return organizationAlmBindingDao;
- }
-
public InternalComponentPropertiesDao internalComponentPropertiesDao() {
return internalComponentPropertiesDao;
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java b/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java
index c578a6b5028..42a3f7ae35f 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java
@@ -34,8 +34,6 @@ import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.apache.ibatis.session.TransactionIsolationLevel;
import org.sonar.api.Startable;
-import org.sonar.db.alm.AlmAppInstallMapper;
-import org.sonar.db.alm.OrganizationAlmBindingMapper;
import org.sonar.db.alm.pat.AlmPatMapper;
import org.sonar.db.alm.setting.AlmSettingMapper;
import org.sonar.db.alm.setting.ProjectAlmSettingMapper;
@@ -225,7 +223,6 @@ public class MyBatis implements Startable {
// keep them sorted alphabetically
Class<?>[] mappers = {
ActiveRuleMapper.class,
- AlmAppInstallMapper.class,
AlmPatMapper.class,
AlmSettingMapper.class,
AnalysisPropertiesMapper.class,
@@ -260,7 +257,6 @@ public class MyBatis implements Startable {
MetricMapper.class,
NewCodePeriodMapper.class,
NotificationQueueMapper.class,
- OrganizationAlmBindingMapper.class,
OrganizationMapper.class,
PermissionTemplateCharacteristicMapper.class,
PermissionTemplateMapper.class,
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/ALM.java b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/ALM.java
deleted file mode 100644
index 12dc7fd0d03..00000000000
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/ALM.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2020 SonarSource SA
- * mailto:info 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.db.alm;
-
-import java.util.Locale;
-
-public enum ALM {
- BITBUCKETCLOUD,
- GITHUB;
-
- public static ALM fromId(String almId) {
- return ALM.valueOf(almId.toUpperCase(Locale.ENGLISH));
- }
-
- public String getId() {
- return this.name().toLowerCase(Locale.ENGLISH);
- }
-}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmAppInstallDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmAppInstallDao.java
deleted file mode 100644
index c56a80a7404..00000000000
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmAppInstallDao.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2020 SonarSource SA
- * mailto:info 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.db.alm;
-
-import java.util.List;
-import java.util.Optional;
-import java.util.Set;
-import java.util.stream.Collectors;
-import javax.annotation.Nullable;
-import org.sonar.api.utils.System2;
-import org.sonar.core.util.UuidFactory;
-import org.sonar.db.Dao;
-import org.sonar.db.DbSession;
-import org.sonar.db.organization.OrganizationDto;
-
-import static com.google.common.base.Preconditions.checkArgument;
-import static java.util.Objects.requireNonNull;
-import static org.apache.commons.lang.StringUtils.isNotEmpty;
-import static org.sonar.db.DatabaseUtils.executeLargeInputs;
-
-/**
- * Store instances of installed app in external ALM like GitHub or Bitbucket Cloud.
- */
-public class AlmAppInstallDao implements Dao {
-
- private final System2 system2;
- private final UuidFactory uuidFactory;
-
- public AlmAppInstallDao(System2 system2, UuidFactory uuidFactory) {
- this.system2 = system2;
- this.uuidFactory = uuidFactory;
- }
-
- public Optional<AlmAppInstallDto> selectByUuid(DbSession dbSession, String uuid) {
- AlmAppInstallMapper mapper = getMapper(dbSession);
- return Optional.ofNullable(mapper.selectByUuid(uuid));
- }
-
- public Optional<AlmAppInstallDto> selectByOrganizationAlmId(DbSession dbSession, ALM alm, String organizationAlmId) {
- checkAlm(alm);
- checkOrganizationAlmId(organizationAlmId);
-
- AlmAppInstallMapper mapper = getMapper(dbSession);
- return Optional.ofNullable(mapper.selectByOrganizationAlmId(alm.getId(), organizationAlmId));
- }
-
- public Optional<AlmAppInstallDto> selectByOrganization(DbSession dbSession, OrganizationDto organization) {
- AlmAppInstallMapper mapper = getMapper(dbSession);
- return Optional.ofNullable(mapper.selectByOrganizationUuid(organization.getUuid()));
- }
-
- public List<AlmAppInstallDto> selectByOrganizations(DbSession dbSession, List<OrganizationDto> organizations) {
- Set<String> organizationUuids = organizations.stream().map(OrganizationDto::getUuid).collect(Collectors.toSet());
- return executeLargeInputs(organizationUuids, uuids -> getMapper(dbSession).selectByOrganizationUuids(uuids));
- }
-
- public void insertOrUpdate(DbSession dbSession, ALM alm, String organizationAlmId, @Nullable Boolean isOwnerUser, String installId, @Nullable String userExternalId) {
- checkAlm(alm);
- checkOrganizationAlmId(organizationAlmId);
- checkArgument(isNotEmpty(installId), "installId can't be null nor empty");
-
- AlmAppInstallMapper mapper = getMapper(dbSession);
- long now = system2.now();
-
- if (mapper.update(alm.getId(), organizationAlmId, isOwnerUser, installId, userExternalId, now) == 0) {
- mapper.insert(uuidFactory.create(), alm.getId(), organizationAlmId, isOwnerUser, installId, userExternalId, now);
- }
- }
-
- public void delete(DbSession dbSession, ALM alm, String organizationAlmId) {
- checkAlm(alm);
- checkOrganizationAlmId(organizationAlmId);
-
- AlmAppInstallMapper mapper = getMapper(dbSession);
- mapper.delete(alm.getId(), organizationAlmId);
- }
-
- private static void checkAlm(@Nullable ALM alm) {
- requireNonNull(alm, "alm can't be null");
- }
-
- private static void checkOrganizationAlmId(@Nullable String organizationAlmId) {
- checkArgument(isNotEmpty(organizationAlmId), "organizationAlmId can't be null nor empty");
- }
-
- private static AlmAppInstallMapper getMapper(DbSession dbSession) {
- return dbSession.getMapper(AlmAppInstallMapper.class);
- }
-}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmAppInstallDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmAppInstallDto.java
deleted file mode 100644
index 486a0b68078..00000000000
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmAppInstallDto.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2020 SonarSource SA
- * mailto:info 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.db.alm;
-
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-
-public class AlmAppInstallDto {
-
- /**
- * Technical unique identifier, can't be null
- */
- private String uuid;
- /**
- * Identifier of the ALM, like 'bitbucketcloud' or 'github', can't be null.
- * Note that the db column is named alm_id.
- *
- * @see ALM for the list of available values
- */
- private String rawAlm;
- /**
- * ALM specific identifier of the organization, like team or user uuid for Bitbucket Cloud or organization id for Github, can't be null.
- * Note that the column is badly named owner_id, in the first place it was only possible to install personal organizations.
- * The column name has been kept to prevent doing a db migration.
- */
- private String organizationAlmId;
- /**
- * ALM specific identifier of the app installation, can't be null
- */
- private String installId;
- /**
- * Is owner a user, can be null
- */
- private Boolean isOwnerUser;
- /**
- * The user ID provided by the ALM of the user who has installed the ALM installation. Can be null as some ALM doesn't provide this info. Max size is 255.
- */
- private String userExternalId;
-
- private long createdAt;
- private long updatedAt;
-
- public String getUuid() {
- return uuid;
- }
-
- public AlmAppInstallDto setUuid(String uuid) {
- this.uuid = uuid;
- return this;
- }
-
- public ALM getAlm() {
- return ALM.fromId(rawAlm);
- }
-
- public AlmAppInstallDto setAlm(ALM alm) {
- this.rawAlm = alm.getId();
- return this;
- }
-
- public String getOrganizationAlmId() {
- return organizationAlmId;
- }
-
- public AlmAppInstallDto setOrganizationAlmId(String organizationAlmId) {
- this.organizationAlmId = organizationAlmId;
- return this;
- }
-
- public String getInstallId() {
- return installId;
- }
-
- public AlmAppInstallDto setInstallId(String installId) {
- this.installId = installId;
- return this;
- }
-
- public boolean isOwnerUser() {
- return isOwnerUser;
- }
-
- public AlmAppInstallDto setIsOwnerUser(boolean isOwnerUser) {
- this.isOwnerUser = isOwnerUser;
- return this;
- }
-
- @CheckForNull
- public String getUserExternalId() {
- return userExternalId;
- }
-
- public AlmAppInstallDto setUserExternalId(@Nullable String userExternalId) {
- this.userExternalId = userExternalId;
- return this;
- }
-
- public long getCreatedAt() {
- return createdAt;
- }
-
- AlmAppInstallDto setCreatedAt(long createdAt) {
- this.createdAt = createdAt;
- return this;
- }
-
- public long getUpdatedAt() {
- return updatedAt;
- }
-
- AlmAppInstallDto setUpdatedAt(long updatedAt) {
- this.updatedAt = updatedAt;
- return this;
- }
-}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmAppInstallMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmAppInstallMapper.java
deleted file mode 100644
index 0d83728b238..00000000000
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmAppInstallMapper.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2020 SonarSource SA
- * mailto:info 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.db.alm;
-
-import java.util.Collection;
-import java.util.List;
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-import org.apache.ibatis.annotations.Param;
-
-public interface AlmAppInstallMapper {
-
- @CheckForNull
- AlmAppInstallDto selectByOrganizationAlmId(@Param("alm") String alm, @Param("organizationAlmId") String organizationAlmId);
-
- @CheckForNull
- AlmAppInstallDto selectByInstallationId(@Param("alm") String alm, @Param("installId") String installId);
-
- @CheckForNull
- AlmAppInstallDto selectByUuid(@Param("uuid") String uuid);
-
- @CheckForNull
- AlmAppInstallDto selectByOrganizationUuid(@Param("organizationUuid") String organizationUuid);
-
- List<AlmAppInstallDto> selectUnboundByUserExternalId(@Param("userExternalId") String userExternalId);
-
- void insert(@Param("uuid") String uuid, @Param("alm") String alm, @Param("organizationAlmId") String organizationAlmId,
- @Nullable @Param("isOwnerUser") Boolean isOwnerUser, @Param("installId") String installId, @Nullable @Param("userExternalId") String userExternalId, @Param("now") long now);
-
- int update(@Param("alm") String alm, @Param("organizationAlmId") String organizationAlmId,
- @Nullable @Param("isOwnerUser") Boolean isOwnerUser, @Param("installId") String installId, @Nullable @Param("userExternalId") String userExternalId, @Param("now") long now);
-
- void delete(@Param("alm") String alm, @Param("organizationAlmId") String organizationAlmId);
-
- List<AlmAppInstallDto> selectByOrganizationUuids(@Param("organizationUuids") Collection<String> organizationUuids);
-}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmTesting.java b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmTesting.java
deleted file mode 100644
index 0f142ff9a14..00000000000
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmTesting.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2020 SonarSource SA
- * mailto:info 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.db.alm;
-
-public class AlmTesting {
-
- private AlmTesting() {
- // only statics
- }
-
-
-}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/OrganizationAlmBindingDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/OrganizationAlmBindingDao.java
deleted file mode 100644
index 421ec3a45e7..00000000000
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/OrganizationAlmBindingDao.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2020 SonarSource SA
- * mailto:info 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.db.alm;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Optional;
-import org.sonar.api.utils.System2;
-import org.sonar.core.util.UuidFactory;
-import org.sonar.db.Dao;
-import org.sonar.db.DbSession;
-import org.sonar.db.organization.OrganizationDto;
-
-import static java.util.Optional.ofNullable;
-import static org.sonar.core.util.stream.MoreCollectors.toSet;
-import static org.sonar.db.DatabaseUtils.executeLargeInputs;
-
-public class OrganizationAlmBindingDao implements Dao {
-
- private final System2 system2;
- private final UuidFactory uuidFactory;
-
- public OrganizationAlmBindingDao(System2 system2, UuidFactory uuidFactory) {
- this.system2 = system2;
- this.uuidFactory = uuidFactory;
- }
-
- public Optional<OrganizationAlmBindingDto> selectByOrganization(DbSession dbSession, OrganizationDto organization) {
- return selectByOrganizationUuid(dbSession, organization.getUuid());
- }
-
- public Optional<OrganizationAlmBindingDto> selectByOrganizationUuid(DbSession dbSession, String organizationUuid) {
- return ofNullable(getMapper(dbSession).selectByOrganizationUuid(organizationUuid));
- }
-
- public List<OrganizationAlmBindingDto> selectByOrganizations(DbSession dbSession, Collection<OrganizationDto> organizations) {
- return selectByOrganizationUuids(dbSession, organizations.stream().map(OrganizationDto::getUuid).collect(toSet()));
- }
-
- public List<OrganizationAlmBindingDto> selectByOrganizationUuids(DbSession dbSession, Collection<String> organizationUuids) {
- return executeLargeInputs(organizationUuids, uuids -> getMapper(dbSession).selectByOrganizationUuids(uuids));
- }
-
- public Optional<OrganizationAlmBindingDto> selectByAlmAppInstall(DbSession dbSession, AlmAppInstallDto almAppInstall) {
- return ofNullable(getMapper(dbSession).selectByInstallationUuid(almAppInstall.getUuid()));
- }
-
- public List<OrganizationAlmBindingDto> selectByOrganizationAlmIds(DbSession dbSession, ALM alm, Collection<String> organizationAlmIds) {
- return executeLargeInputs(organizationAlmIds, o -> getMapper(dbSession).selectByOrganizationAlmIds(alm.getId(), o));
- }
-
- public void insert(DbSession dbSession, OrganizationDto organization, AlmAppInstallDto almAppInstall, String url, String userUuid, boolean membersSync) {
- long now = system2.now();
- getMapper(dbSession).insert(new OrganizationAlmBindingDto()
- .setUuid(uuidFactory.create())
- .setOrganizationUuid(organization.getUuid())
- .setAlmAppInstallUuid(almAppInstall.getUuid())
- .setAlmId(almAppInstall.getAlm())
- .setUrl(url)
- .setUserUuid(userUuid)
- .setMembersSyncEnabled(membersSync)
- .setCreatedAt(now));
- }
-
- public void deleteByOrganization(DbSession dbSession, OrganizationDto organization) {
- getMapper(dbSession).deleteByOrganizationUuid(organization.getUuid());
- }
-
- public void deleteByAlmAppInstall(DbSession dbSession, AlmAppInstallDto almAppInstall) {
- getMapper(dbSession).deleteByAlmAppInstallUuid(almAppInstall.getUuid());
- }
-
- public void updateMembersSync(DbSession dbSession, OrganizationAlmBindingDto orgAlmBinding, boolean enabled) {
- getMapper(dbSession).updateMembersSync(orgAlmBinding.getUuid(), enabled);
- }
-
- private static OrganizationAlmBindingMapper getMapper(DbSession dbSession) {
- return dbSession.getMapper(OrganizationAlmBindingMapper.class);
- }
-}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/OrganizationAlmBindingDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/OrganizationAlmBindingDto.java
deleted file mode 100644
index 7f851286934..00000000000
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/OrganizationAlmBindingDto.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2020 SonarSource SA
- * mailto:info 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.db.alm;
-
-import java.util.Arrays;
-
-/**
- * This DTO is used to link an {@link org.sonar.db.organization.OrganizationDto} to a {@link AlmAppInstallDto}
- */
-public class OrganizationAlmBindingDto {
-
- /**
- * Not empty. Max size is 40. Obviously it is unique.
- */
- private String uuid;
- /**
- * The UUID of the organization. Can't be null. Max size is 40.
- * It's unique, as an organization is only linked to one installation (at least for the moment).
- */
- private String organizationUuid;
- /**
- * The UUID of ALM installation. Can't be null. Max size is 40.
- * It's unique, as an installation is related to only one organization.
- */
- private String almAppInstallUuid;
- /**
- * The id of the ALM. Can't be null. Max size is 40.
- */
- private String rawAlmId;
- /**
- * The url of the ALM organization. Can't be null. Max size is 2000.
- */
- private String url;
- /**
- * The UUID of the user who has created the link between the organization and the ALM installation. Can't be null. Max size is 255.
- */
- private String userUuid;
- /**
- * If the members of the org are automatically sync with the ALM org
- */
- private boolean membersSyncEnabled;
- /**
- * Technical creation date
- */
- private long createdAt;
-
- public String getUuid() {
- return uuid;
- }
-
- OrganizationAlmBindingDto setUuid(String uuid) {
- this.uuid = uuid;
- return this;
- }
-
- public String getOrganizationUuid() {
- return organizationUuid;
- }
-
- public OrganizationAlmBindingDto setOrganizationUuid(String organizationUuid) {
- this.organizationUuid = organizationUuid;
- return this;
- }
-
- public String getAlmAppInstallUuid() {
- return almAppInstallUuid;
- }
-
- public OrganizationAlmBindingDto setAlmAppInstallUuid(String almAppInstallUuid) {
- this.almAppInstallUuid = almAppInstallUuid;
- return this;
- }
-
- public ALM getAlm() {
- return Arrays.stream(ALM.values())
- .filter(a -> a.getId().equals(rawAlmId))
- .findAny()
- .orElseThrow(() -> new IllegalStateException("ALM id " + rawAlmId + " is invalid"));
- }
-
- public OrganizationAlmBindingDto setAlmId(ALM alm) {
- this.rawAlmId = alm.getId();
- return this;
- }
-
- public String getUrl() {
- return url;
- }
-
- public OrganizationAlmBindingDto setUrl(String url) {
- this.url = url;
- return this;
- }
-
- public String getUserUuid() {
- return userUuid;
- }
-
- public OrganizationAlmBindingDto setUserUuid(String userUuid) {
- this.userUuid = userUuid;
- return this;
- }
-
- public boolean isMembersSyncEnable() {
- return membersSyncEnabled;
- }
-
- public OrganizationAlmBindingDto setMembersSyncEnabled(boolean membersSyncEnabled) {
- this.membersSyncEnabled = membersSyncEnabled;
- return this;
- }
-
- public long getCreatedAt() {
- return createdAt;
- }
-
- OrganizationAlmBindingDto setCreatedAt(long createdAt) {
- this.createdAt = createdAt;
- return this;
- }
-}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/OrganizationAlmBindingMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/OrganizationAlmBindingMapper.java
deleted file mode 100644
index 1ef4b91850a..00000000000
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/OrganizationAlmBindingMapper.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2020 SonarSource SA
- * mailto:info 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.db.alm;
-
-import java.util.Collection;
-import java.util.List;
-import javax.annotation.CheckForNull;
-import org.apache.ibatis.annotations.Param;
-
-public interface OrganizationAlmBindingMapper {
-
- @CheckForNull
- OrganizationAlmBindingDto selectByOrganizationUuid(@Param("organizationUuid") String organizationUuid);
-
- List<OrganizationAlmBindingDto> selectByOrganizationUuids(@Param("organizationUuids") Collection<String> organizationUuids);
-
- @CheckForNull
- OrganizationAlmBindingDto selectByInstallationUuid(@Param("installationUuid") String installationUuid);
-
- List<OrganizationAlmBindingDto> selectByOrganizationAlmIds(@Param("alm") String alm, @Param("organizationAlmIds") List<String> organizationAlmId);
-
- void insert(@Param("dto") OrganizationAlmBindingDto dto);
-
- void deleteByOrganizationUuid(@Param("organizationUuid") String organizationUuid);
-
- void deleteByAlmAppInstallUuid(@Param("almAppInstallUuid") String almAppInstallUuid);
-
- void updateMembersSync(@Param("uuid") String uuid, @Param("membersSyncEnabled") boolean membersSyncEnabled);
-}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationDao.java
index 8a71d78a42e..af5e2bed102 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationDao.java
@@ -27,7 +27,6 @@ import org.sonar.api.utils.System2;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
import org.sonar.db.Pagination;
-import org.sonar.db.alm.ALM;
import org.sonar.db.component.BranchType;
import org.sonar.db.permission.template.DefaultTemplates;
import org.sonar.db.property.InternalPropertiesDao;
@@ -97,10 +96,6 @@ public class OrganizationDao implements Dao {
return getMapper(dbSession).selectByPermission(userUuid, permission);
}
- public Optional<OrganizationDto> selectByOrganizationAlmId(DbSession dbSession, ALM alm, String organizationAlmId) {
- return Optional.ofNullable(getMapper(dbSession).selectByOrganizationAlmId(alm.getId(), organizationAlmId));
- }
-
public List<String> selectAllUuids(DbSession dbSession) {
return getMapper(dbSession).selectAllUuids();
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationMapper.java
index defe27ba197..24708e10d2d 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationMapper.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationMapper.java
@@ -40,9 +40,6 @@ public interface OrganizationMapper {
@CheckForNull
OrganizationDto selectByUuid(@Param("uuid") String uuid);
- @CheckForNull
- OrganizationDto selectByOrganizationAlmId(@Param("alm") String alm, @Param("organizationAlmId") String organizationAlmId);
-
List<OrganizationDto> selectByUuids(@Param("uuids") List<String> uuids);
List<OrganizationDto> selectByPermission(@Param("userUuid") String userUuid, @Param("permission") String permission);
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/alm/AlmAppInstallMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/alm/AlmAppInstallMapper.xml
deleted file mode 100644
index b7a8fcd42b3..00000000000
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/alm/AlmAppInstallMapper.xml
+++ /dev/null
@@ -1,106 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd">
-
-<mapper namespace="org.sonar.db.alm.AlmAppInstallMapper">
-
- <sql id="sqlColumns">
- aai.uuid,
- aai.alm_id as rawAlm,
- aai.owner_id as organizationAlmId,
- aai.is_owner_user as isOwnerUser,
- aai.install_id as installId,
- aai.user_external_id as userExternalId,
- aai.created_at as createdAt,
- aai.updated_at as updatedAt
- </sql>
-
- <select id="selectByOrganizationAlmId" parameterType="Map" resultType="org.sonar.db.alm.AlmAppInstallDto">
- select <include refid="sqlColumns" />
- from
- alm_app_installs aai
- where
- alm_id = #{alm, jdbcType=VARCHAR}
- and owner_id = #{organizationAlmId, jdbcType=VARCHAR}
- </select>
-
- <select id="selectByInstallationId" parameterType="Map" resultType="org.sonar.db.alm.AlmAppInstallDto">
- select <include refid="sqlColumns"/>
- from
- alm_app_installs aai
- where
- alm_id = #{alm, jdbcType=VARCHAR}
- and install_id = #{installId, jdbcType=VARCHAR}
- </select>
-
- <select id="selectByUuid" parameterType="Map" resultType="org.sonar.db.alm.AlmAppInstallDto">
- select <include refid="sqlColumns"/>
- from
- alm_app_installs aai
- where
- uuid = #{uuid, jdbcType=VARCHAR}
- </select>
-
- <select id="selectByOrganizationUuid" parameterType="Map" resultType="org.sonar.db.alm.AlmAppInstallDto">
- select <include refid="sqlColumns"/>
- from
- alm_app_installs aai
- inner join organization_alm_bindings oab on oab.alm_app_install_uuid = aai.uuid
- where
- oab.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
- </select>
-
- <select id="selectByOrganizationUuids" parameterType="String" resultType="org.sonar.db.alm.AlmAppInstallDto">
- select <include refid="sqlColumns"/>
- from
- alm_app_installs aai
- inner join organization_alm_bindings oab on oab.alm_app_install_uuid = aai.uuid
- where oab.organization_uuid in
- <foreach collection="organizationUuids" open="(" close=")" item="organizationUuid" separator=",">
- #{organizationUuid , jdbcType=VARCHAR}
- </foreach>
- </select>
-
- <insert id="insert" parameterType="Map" useGeneratedKeys="false">
- INSERT INTO alm_app_installs
- (
- uuid,
- alm_id,
- owner_id,
- is_owner_user,
- install_id,
- user_external_id,
- created_at,
- updated_at
- )
- VALUES (
- #{uuid, jdbcType=VARCHAR},
- #{alm, jdbcType=VARCHAR},
- #{organizationAlmId, jdbcType=VARCHAR},
- #{isOwnerUser, jdbcType=BOOLEAN},
- #{installId, jdbcType=VARCHAR},
- #{userExternalId, jdbcType=VARCHAR},
- #{now, jdbcType=BIGINT},
- #{now, jdbcType=BIGINT}
- )
- </insert>
-
- <update id="update" parameterType="map">
- update alm_app_installs set
- install_id = #{installId, jdbcType=VARCHAR},
- is_owner_user = #{isOwnerUser, jdbcType=BOOLEAN},
- user_external_id = #{userExternalId, jdbcType=VARCHAR},
- updated_at = #{now, jdbcType=BIGINT}
- where
- alm_id = #{alm, jdbcType=VARCHAR}
- and owner_id = #{organizationAlmId, jdbcType=VARCHAR}
- </update>
-
- <delete id="delete" parameterType="Map">
- delete from alm_app_installs
- where
- alm_id = #{alm, jdbcType=VARCHAR}
- and owner_id = #{organizationAlmId, jdbcType=VARCHAR}
- </delete>
-
-
-</mapper>
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/alm/OrganizationAlmBindingMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/alm/OrganizationAlmBindingMapper.xml
deleted file mode 100644
index 38af308113a..00000000000
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/alm/OrganizationAlmBindingMapper.xml
+++ /dev/null
@@ -1,99 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd">
-
-<mapper namespace="org.sonar.db.alm.OrganizationAlmBindingMapper">
-
- <sql id="columns">
- oab.uuid,
- oab.organization_uuid as organizationUuid,
- oab.alm_app_install_uuid as almAppInstallUuid,
- oab.alm_id as rawAlmId,
- oab.url,
- oab.user_uuid as userUuid,
- oab.members_sync_enabled as membersSyncEnabled,
- oab.created_at as createdAt
- </sql>
-
- <select id="selectByOrganizationUuid" parameterType="String" resultType="org.sonar.db.alm.OrganizationAlmBindingDto">
- select
- <include refid="columns"/>
- from
- organization_alm_bindings oab
- where
- oab.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
- </select>
-
- <select id="selectByOrganizationUuids" parameterType="String" resultType="org.sonar.db.alm.OrganizationAlmBindingDto">
- select
- <include refid="columns"/>
- from
- organization_alm_bindings oab
- where
- oab.organization_uuid in
- <foreach collection="organizationUuids" open="(" close=")" item="organizationUuid" separator=",">
- #{organizationUuid , jdbcType=VARCHAR}
- </foreach>
- </select>
-
- <select id="selectByInstallationUuid" parameterType="String" resultType="org.sonar.db.alm.OrganizationAlmBindingDto">
- select
- <include refid="columns"/>
- from
- organization_alm_bindings oab
- where
- oab.alm_app_install_uuid = #{installationUuid, jdbcType=VARCHAR}
- </select>
-
- <select id="selectByOrganizationAlmIds" parameterType="Map" resultType="org.sonar.db.alm.OrganizationAlmBindingDto">
- select
- <include refid="columns"/>
- from
- organization_alm_bindings oab
- inner join alm_app_installs aai on aai.uuid = oab.alm_app_install_uuid and aai.alm_id = oab.alm_id
- where
- aai.alm_id = #{alm, jdbcType=VARCHAR}
- and aai.owner_id in
- <foreach collection="organizationAlmIds" open="(" close=")" item="organizationAlmId" separator=",">
- #{organizationAlmId , jdbcType=VARCHAR}
- </foreach>
- </select>
-
- <insert id="insert" parameterType="Map" useGeneratedKeys="false">
- INSERT INTO organization_alm_bindings
- (
- uuid,
- organization_uuid,
- alm_app_install_uuid,
- alm_id,
- url,
- user_uuid,
- members_sync_enabled,
- created_at
- )
- VALUES (
- #{dto.uuid, jdbcType=VARCHAR},
- #{dto.organizationUuid, jdbcType=VARCHAR},
- #{dto.almAppInstallUuid, jdbcType=VARCHAR},
- #{dto.rawAlmId, jdbcType=VARCHAR},
- #{dto.url, jdbcType=VARCHAR},
- #{dto.userUuid, jdbcType=VARCHAR},
- #{dto.membersSyncEnabled, jdbcType=BOOLEAN},
- #{dto.createdAt, jdbcType=BIGINT}
- )
- </insert>
-
- <delete id="deleteByOrganizationUuid" parameterType="String">
- DELETE FROM organization_alm_bindings WHERE organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
- </delete>
-
- <delete id="deleteByAlmAppInstallUuid" parameterType="String">
- DELETE FROM organization_alm_bindings WHERE alm_app_install_uuid = #{almAppInstallUuid, jdbcType=VARCHAR}
- </delete>
-
- <update id="updateMembersSync" parameterType="map">
- update organization_alm_bindings set
- members_sync_enabled = #{membersSyncEnabled, jdbcType=BOOLEAN}
- where
- uuid = #{uuid, jdbcType=VARCHAR}
- </update>
-</mapper>
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml
index 884e30b9891..9a396e50ab9 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml
@@ -57,17 +57,6 @@
</foreach>
</select>
- <select id="selectByOrganizationAlmId" resultType="Organization">
- select
- <include refid="selectColumns"/>
- from organizations org
- inner join organization_alm_bindings oab on org.uuid=oab.organization_uuid
- inner join alm_app_installs aai on aai.uuid=oab.alm_app_install_uuid
- where
- aai.owner_id = #{organizationAlmId, jdbcType=VARCHAR} and
- aai.alm_id = #{alm, jdbcType=VARCHAR}
- </select>
-
<select id="countByQuery" resultType="int">
select count(org.uuid)
<include refid="sqlSelectByQuery" />
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/alm/AlmAppInstallDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/alm/AlmAppInstallDaoTest.java
deleted file mode 100644
index f9abbd8f5e8..00000000000
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/alm/AlmAppInstallDaoTest.java
+++ /dev/null
@@ -1,352 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2020 SonarSource SA
- * mailto:info 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.db.alm;
-
-import com.google.common.collect.ImmutableList;
-import java.util.Objects;
-import java.util.Optional;
-import org.assertj.core.api.AbstractAssert;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.sonar.api.utils.System2;
-import org.sonar.core.util.UuidFactory;
-import org.sonar.core.util.Uuids;
-import org.sonar.db.DbSession;
-import org.sonar.db.DbTester;
-import org.sonar.db.organization.OrganizationDto;
-
-import static java.util.Collections.emptyList;
-import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
-import static org.apache.commons.lang.RandomStringUtils.randomNumeric;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-import static org.sonar.db.alm.ALM.BITBUCKETCLOUD;
-import static org.sonar.db.alm.ALM.GITHUB;
-
-public class AlmAppInstallDaoTest {
-
- private static final String A_UUID = "abcde1234";
- private static final String A_UUID_2 = "xyz789";
- private static final String EMPTY_STRING = "";
- private static final String AN_ORGANIZATION_ALM_ID = "my_org_id";
- private static final String ANOTHER_ORGANIZATION_ALM_ID = "another_org";
- private static final long DATE = 1_600_000_000_000L;
- private static final long DATE_LATER = 1_700_000_000_000L;
- private static final String AN_INSTALL = "some install id";
- private static final String OTHER_INSTALL = "other install id";
-
- private System2 system2 = mock(System2.class);
-
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
- @Rule
- public DbTester db = DbTester.create(system2);
-
- private DbSession dbSession = db.getSession();
- private UuidFactory uuidFactory = mock(UuidFactory.class);
- private AlmAppInstallDao underTest = new AlmAppInstallDao(system2, uuidFactory);
-
- @Test
- public void selectByUuid() {
- when(uuidFactory.create()).thenReturn(A_UUID);
- when(system2.now()).thenReturn(DATE);
- String userUuid = Uuids.createFast();
- underTest.insertOrUpdate(dbSession, GITHUB, AN_ORGANIZATION_ALM_ID, true, AN_INSTALL, userUuid);
-
- assertThat(underTest.selectByUuid(dbSession, A_UUID).get())
- .extracting(AlmAppInstallDto::getUuid, AlmAppInstallDto::getAlm, AlmAppInstallDto::getInstallId, AlmAppInstallDto::getOrganizationAlmId, AlmAppInstallDto::getUserExternalId,
- AlmAppInstallDto::getCreatedAt, AlmAppInstallDto::getUpdatedAt)
- .contains(A_UUID, GITHUB, AN_ORGANIZATION_ALM_ID, AN_INSTALL, userUuid, DATE, DATE);
-
- assertThat(underTest.selectByUuid(dbSession, "foo")).isNotPresent();
- }
-
- @Test
- public void selectByOrganizationAlmId() {
- when(uuidFactory.create()).thenReturn(A_UUID);
- when(system2.now()).thenReturn(DATE);
- underTest.insertOrUpdate(dbSession, GITHUB, AN_ORGANIZATION_ALM_ID, true, AN_INSTALL, null);
-
- assertThat(underTest.selectByOrganizationAlmId(dbSession, GITHUB, AN_ORGANIZATION_ALM_ID).get())
- .extracting(AlmAppInstallDto::getUuid, AlmAppInstallDto::getAlm, AlmAppInstallDto::getInstallId, AlmAppInstallDto::getOrganizationAlmId,
- AlmAppInstallDto::getCreatedAt, AlmAppInstallDto::getUpdatedAt)
- .contains(A_UUID, GITHUB, AN_ORGANIZATION_ALM_ID, AN_INSTALL, DATE, DATE);
-
- assertThat(underTest.selectByOrganizationAlmId(dbSession, BITBUCKETCLOUD, AN_ORGANIZATION_ALM_ID)).isNotPresent();
- assertThat(underTest.selectByOrganizationAlmId(dbSession, GITHUB, "Unknown owner")).isNotPresent();
- }
-
- @Test
- public void selectByOwner_throws_NPE_when_alm_is_null() {
- expectAlmNPE();
-
- underTest.selectByOrganizationAlmId(dbSession, null, AN_ORGANIZATION_ALM_ID);
- }
-
- @Test
- public void selectByOwner_throws_IAE_when_organization_alm_id_is_null() {
- expectOrganizationAlmIdNullOrEmptyIAE();
-
- underTest.selectByOrganizationAlmId(dbSession, GITHUB, null);
- }
-
- @Test
- public void selectByOwner_throws_IAE_when_organization_alm_id_is_empty() {
- expectOrganizationAlmIdNullOrEmptyIAE();
-
- underTest.selectByOrganizationAlmId(dbSession, GITHUB, EMPTY_STRING);
- }
-
- @Test
- public void selectByOrganization() {
- OrganizationDto organization = db.organizations().insert();
- AlmAppInstallDto install = insertAlmAppInstall(organization);
- db.commit();
-
- assertThat(underTest.selectByOrganization(db.getSession(), organization).filter(o -> o.getAlm() == GITHUB).get().getUuid()).isEqualTo(install.getUuid());
- assertThat(underTest.selectByOrganization(db.getSession(), organization).filter(o -> o.getAlm() == BITBUCKETCLOUD)).isEmpty();
- assertThat(underTest.selectByOrganization(db.getSession(), new OrganizationDto().setUuid("other-organization")).filter(o -> o.getAlm() == GITHUB)).isEmpty();
- }
-
- @Test
- public void selectByOrganizations() {
- OrganizationDto org1 = db.organizations().insert();
- AlmAppInstallDto install1 = insertAlmAppInstall(org1);
- OrganizationDto org2 = db.organizations().insert();
- AlmAppInstallDto install2 = insertAlmAppInstall(org2);
- OrganizationDto org3 = db.organizations().insert();
- db.commit();
-
- assertThat(underTest.selectByOrganizations(db.getSession(), ImmutableList.of(org1, org2, org3)))
- .extracting(AlmAppInstallDto::getUuid)
- .containsOnly(install1.getUuid(), install2.getUuid());
- }
-
- @Test
- public void selectByOrganizations_return_empty_list_if_list_of_orgs_is_empty() {
- assertThat(underTest.selectByOrganizations(db.getSession(), emptyList())).isEmpty();
- }
-
- private AlmAppInstallDto insertAlmAppInstall(OrganizationDto organization) {
- String organizationAlmId = randomAlphanumeric(10);
- db.getDbClient().almAppInstallDao().insertOrUpdate(db.getSession(), ALM.GITHUB, organizationAlmId, false, randomNumeric(6), null);
- // could be improved, insertOrUpdate should return the DTO with its uuid
- Optional<AlmAppInstallDto> install = db.getDbClient().almAppInstallDao().selectByOrganizationAlmId(db.getSession(), ALM.GITHUB, organizationAlmId);
- db.getDbClient().organizationAlmBindingDao().insert(db.getSession(), organization, install.get(), "xxx", "xxx", true);
- return install.get();
- }
-
- @Test
- public void insert_throws_NPE_if_alm_is_null() {
- expectAlmNPE();
-
- underTest.insertOrUpdate(dbSession, null, AN_ORGANIZATION_ALM_ID, true, AN_INSTALL, null);
- }
-
- @Test
- public void insert_throws_IAE_if_organization_alm_id_is_null() {
- expectOrganizationAlmIdNullOrEmptyIAE();
-
- underTest.insertOrUpdate(dbSession, GITHUB, null, true, AN_INSTALL, null);
- }
-
- @Test
- public void insert_throws_IAE_if_organization_alm_id_is_empty() {
- expectOrganizationAlmIdNullOrEmptyIAE();
-
- underTest.insertOrUpdate(dbSession, GITHUB, EMPTY_STRING, true, AN_INSTALL, null);
- }
-
- @Test
- public void insert_throws_IAE_if_install_id_is_null() {
- expectInstallIdNullOrEmptyIAE();
-
- underTest.insertOrUpdate(dbSession, GITHUB, AN_ORGANIZATION_ALM_ID, true, null, null);
- }
-
- @Test
- public void insert_throws_IAE_if_install_id_is_empty() {
- expectInstallIdNullOrEmptyIAE();
-
- underTest.insertOrUpdate(dbSession, GITHUB, AN_ORGANIZATION_ALM_ID, true, EMPTY_STRING, null);
- }
-
- @Test
- public void insert() {
- when(uuidFactory.create()).thenReturn(A_UUID);
- when(system2.now()).thenReturn(DATE);
- String userUuid = Uuids.createFast();
- underTest.insertOrUpdate(dbSession, GITHUB, AN_ORGANIZATION_ALM_ID, true, AN_INSTALL, userUuid);
-
- assertThatAlmAppInstall(GITHUB, AN_ORGANIZATION_ALM_ID)
- .hasInstallId(AN_INSTALL)
- .hasUserExternalId(userUuid)
- .hasCreatedAt(DATE)
- .hasUpdatedAt(DATE);
- }
-
- @Test
- public void delete() {
- when(uuidFactory.create()).thenReturn(A_UUID);
- when(system2.now()).thenReturn(DATE);
- underTest.insertOrUpdate(dbSession, GITHUB, AN_ORGANIZATION_ALM_ID, true, AN_INSTALL, null);
-
- underTest.delete(dbSession, GITHUB, AN_ORGANIZATION_ALM_ID);
-
- assertThatAlmAppInstall(GITHUB, AN_ORGANIZATION_ALM_ID).doesNotExist();
- }
-
- @Test
- public void delete_does_not_fail() {
- assertThatAlmAppInstall(GITHUB, AN_ORGANIZATION_ALM_ID).doesNotExist();
-
- underTest.delete(dbSession, GITHUB, AN_ORGANIZATION_ALM_ID);
- }
-
- @Test
- public void update() {
- when(uuidFactory.create()).thenReturn(A_UUID);
- when(system2.now()).thenReturn(DATE);
- String userExternalId1 = randomAlphanumeric(10);
- underTest.insertOrUpdate(dbSession, GITHUB, AN_ORGANIZATION_ALM_ID, true, AN_INSTALL, userExternalId1);
-
- when(system2.now()).thenReturn(DATE_LATER);
- String userExternalId2 = randomAlphanumeric(10);
- underTest.insertOrUpdate(dbSession, GITHUB, AN_ORGANIZATION_ALM_ID, true, OTHER_INSTALL, userExternalId2);
-
- assertThatAlmAppInstall(GITHUB, AN_ORGANIZATION_ALM_ID)
- .hasInstallId(OTHER_INSTALL)
- .hasUserExternalId(userExternalId2)
- .hasCreatedAt(DATE)
- .hasUpdatedAt(DATE_LATER);
- }
-
- @Test
- public void putMultiple() {
- when(system2.now()).thenReturn(DATE);
- when(uuidFactory.create())
- .thenReturn(A_UUID)
- .thenReturn(A_UUID_2);
- String userExternalId1 = randomAlphanumeric(10);
- String userExternalId2 = randomAlphanumeric(10);
- underTest.insertOrUpdate(dbSession, GITHUB, AN_ORGANIZATION_ALM_ID, true, AN_INSTALL, userExternalId1);
- underTest.insertOrUpdate(dbSession, GITHUB, ANOTHER_ORGANIZATION_ALM_ID, false, OTHER_INSTALL, userExternalId2);
-
- assertThatAlmAppInstall(GITHUB, AN_ORGANIZATION_ALM_ID)
- .hasInstallId(AN_INSTALL)
- .hasOwnerUser(true)
- .hasUserExternalId(userExternalId1)
- .hasCreatedAt(DATE)
- .hasUpdatedAt(DATE);
-
- assertThatAlmAppInstall(GITHUB, ANOTHER_ORGANIZATION_ALM_ID)
- .hasInstallId(OTHER_INSTALL)
- .hasOwnerUser(false)
- .hasUserExternalId(userExternalId2)
- .hasCreatedAt(DATE)
- .hasUpdatedAt(DATE);
- }
-
- private void expectAlmNPE() {
- expectedException.expect(NullPointerException.class);
- expectedException.expectMessage("alm can't be null");
- }
-
- private void expectOrganizationAlmIdNullOrEmptyIAE() {
- expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("organizationAlmId can't be null nor empty");
- }
-
- private void expectInstallIdNullOrEmptyIAE() {
- expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("installId can't be null nor empty");
- }
-
- private AlmAppInstallAssert assertThatAlmAppInstall(ALM alm, String organizationAlmId) {
- return new AlmAppInstallAssert(db, dbSession, alm, organizationAlmId);
- }
-
- private static class AlmAppInstallAssert extends AbstractAssert<AlmAppInstallAssert, AlmAppInstallDto> {
-
- private AlmAppInstallAssert(DbTester dbTester, DbSession dbSession, ALM alm, String organizationAlmId) {
- super(asAlmAppInstall(dbTester, dbSession, alm, organizationAlmId), AlmAppInstallAssert.class);
- }
-
- private static AlmAppInstallDto asAlmAppInstall(DbTester db, DbSession dbSession, ALM alm, String organizationAlmId) {
- Optional<AlmAppInstallDto> almAppInstall = db.getDbClient().almAppInstallDao().selectByOrganizationAlmId(dbSession, alm, organizationAlmId);
- return almAppInstall.orElse(null);
- }
-
- public void doesNotExist() {
- isNull();
- }
-
- AlmAppInstallAssert hasInstallId(String expected) {
- isNotNull();
-
- if (!Objects.equals(actual.getInstallId(), expected)) {
- failWithMessage("Expected ALM App Install to have column INSTALL_ID to be <%s> but was <%s>", expected, actual.getInstallId());
- }
- return this;
- }
-
- AlmAppInstallAssert hasOwnerUser(boolean expected) {
- isNotNull();
-
- if (!Objects.equals(actual.isOwnerUser(), expected)) {
- failWithMessage("Expected ALM App Install to have column IS_OWNER_USER to be <%s> but was <%s>", expected, actual.isOwnerUser());
- }
- return this;
- }
-
- AlmAppInstallAssert hasUserExternalId(String expected) {
- isNotNull();
-
- if (!Objects.equals(actual.getUserExternalId(), expected)) {
- failWithMessage("Expected ALM App Install to have column USER_EXTERNAL_ID to be <%s> but was <%s>", expected, actual.getUserExternalId());
- }
- return this;
- }
-
- AlmAppInstallAssert hasCreatedAt(long expected) {
- isNotNull();
-
- if (!Objects.equals(actual.getCreatedAt(), expected)) {
- failWithMessage("Expected ALM App Install to have column CREATED_AT to be <%s> but was <%s>", expected, actual.getCreatedAt());
- }
-
- return this;
- }
-
- AlmAppInstallAssert hasUpdatedAt(long expected) {
- isNotNull();
-
- if (!Objects.equals(actual.getUpdatedAt(), expected)) {
- failWithMessage("Expected ALM App Install to have column UPDATED_AT to be <%s> but was <%s>", expected, actual.getUpdatedAt());
- }
-
- return this;
- }
-
- }
-
-}
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/alm/OrganizationAlmBindingDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/alm/OrganizationAlmBindingDaoTest.java
deleted file mode 100644
index d52eb9ad89a..00000000000
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/alm/OrganizationAlmBindingDaoTest.java
+++ /dev/null
@@ -1,222 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2020 SonarSource SA
- * mailto:info 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.db.alm;
-
-import java.util.List;
-import java.util.Optional;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.api.utils.System2;
-import org.sonar.api.impl.utils.TestSystem2;
-import org.sonar.core.util.UuidFactory;
-import org.sonar.db.DbTester;
-import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.user.UserDto;
-
-import static java.util.Arrays.asList;
-import static java.util.Collections.singletonList;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.groups.Tuple.tuple;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-import static org.sonar.db.alm.ALM.BITBUCKETCLOUD;
-import static org.sonar.db.alm.ALM.GITHUB;
-
-public class OrganizationAlmBindingDaoTest {
-
- private static final long NOW = 1_600_000_000_000L;
-
- private System2 system2 = new TestSystem2().setNow(NOW);
-
- @Rule
- public DbTester db = DbTester.create(system2);
-
- private UuidFactory uuidFactory = mock(UuidFactory.class);
-
- private OrganizationAlmBindingDao underTest = new OrganizationAlmBindingDao(system2, uuidFactory);
-
- @Test
- public void selectByOrganization() {
- OrganizationDto organization = db.organizations().insert();
- AlmAppInstallDto almAppInstall = db.alm().insertAlmAppInstall();
- OrganizationAlmBindingDto dto = db.alm().insertOrganizationAlmBinding(organization, almAppInstall, true);
-
- Optional<OrganizationAlmBindingDto> result = underTest.selectByOrganization(db.getSession(), organization);
-
- assertThat(result).isPresent();
- assertThat(result.get())
- .extracting(OrganizationAlmBindingDto::getUuid, OrganizationAlmBindingDto::getOrganizationUuid, OrganizationAlmBindingDto::getAlmAppInstallUuid,
- OrganizationAlmBindingDto::getUrl, OrganizationAlmBindingDto::getAlm,
- OrganizationAlmBindingDto::getUserUuid, OrganizationAlmBindingDto::getCreatedAt)
- .containsExactlyInAnyOrder(dto.getUuid(), organization.getUuid(), dto.getAlmAppInstallUuid(),
- dto.getUrl(), GITHUB,
- dto.getUserUuid(), NOW);
- }
-
- @Test
- public void selectByOrganization_returns_empty_when_organization_is_not_bound_to_installation() {
- OrganizationDto organization = db.organizations().insert();
- AlmAppInstallDto almAppInstall = db.alm().insertAlmAppInstall();
- db.alm().insertOrganizationAlmBinding(organization, almAppInstall, true);
- // No binding on other installation
- OrganizationDto otherOrganization = db.organizations().insert();
-
- Optional<OrganizationAlmBindingDto> result = underTest.selectByOrganization(db.getSession(), otherOrganization);
-
- assertThat(result).isEmpty();
- }
-
- @Test
- public void selectByOrganizationUuid() {
- OrganizationDto organization = db.organizations().insert();
- AlmAppInstallDto almAppInstall = db.alm().insertAlmAppInstall();
- OrganizationAlmBindingDto dto = db.alm().insertOrganizationAlmBinding(organization, almAppInstall, true);
-
- assertThat(underTest.selectByOrganizationUuid(db.getSession(), organization.getUuid()).get())
- .extracting(OrganizationAlmBindingDto::getUuid, OrganizationAlmBindingDto::getOrganizationUuid, OrganizationAlmBindingDto::getAlmAppInstallUuid,
- OrganizationAlmBindingDto::getUrl, OrganizationAlmBindingDto::getAlm,
- OrganizationAlmBindingDto::getUserUuid, OrganizationAlmBindingDto::getCreatedAt)
- .containsExactlyInAnyOrder(dto.getUuid(), organization.getUuid(), dto.getAlmAppInstallUuid(),
- dto.getUrl(), GITHUB,
- dto.getUserUuid(), NOW);
-
- assertThat(underTest.selectByOrganizationUuid(db.getSession(), "unknown")).isNotPresent();
- }
-
- @Test
- public void selectByOrganizations() {
- OrganizationDto organization1 = db.organizations().insert();
- OrganizationAlmBindingDto organizationAlmBinding1 = db.alm().insertOrganizationAlmBinding(organization1, db.alm().insertAlmAppInstall(), true);
- OrganizationDto organization2 = db.organizations().insert();
- OrganizationAlmBindingDto organizationAlmBinding2 = db.alm().insertOrganizationAlmBinding(organization2, db.alm().insertAlmAppInstall(), true);
- OrganizationDto organizationNotBound = db.organizations().insert();
-
- assertThat(underTest.selectByOrganizations(db.getSession(), asList(organization1, organization2, organizationNotBound)))
- .extracting(OrganizationAlmBindingDto::getUuid, OrganizationAlmBindingDto::getOrganizationUuid)
- .containsExactlyInAnyOrder(
- tuple(organizationAlmBinding1.getUuid(), organization1.getUuid()),
- tuple(organizationAlmBinding2.getUuid(), organization2.getUuid()));
-
- assertThat(underTest.selectByOrganizations(db.getSession(), singletonList(organizationNotBound))).isEmpty();
- }
-
- @Test
- public void selectByAlmAppInstall() {
- OrganizationDto organization = db.organizations().insert();
- AlmAppInstallDto almAppInstall = db.alm().insertAlmAppInstall();
- OrganizationAlmBindingDto dto = db.alm().insertOrganizationAlmBinding(organization, almAppInstall, true);
-
- Optional<OrganizationAlmBindingDto> result = underTest.selectByAlmAppInstall(db.getSession(), almAppInstall);
-
- assertThat(result.get())
- .extracting(OrganizationAlmBindingDto::getUuid, OrganizationAlmBindingDto::getOrganizationUuid, OrganizationAlmBindingDto::getAlmAppInstallUuid,
- OrganizationAlmBindingDto::getUrl, OrganizationAlmBindingDto::getAlm,
- OrganizationAlmBindingDto::getUserUuid, OrganizationAlmBindingDto::getCreatedAt)
- .containsExactlyInAnyOrder(dto.getUuid(), organization.getUuid(), dto.getAlmAppInstallUuid(),
- dto.getUrl(), GITHUB,
- dto.getUserUuid(), NOW);
- }
-
- @Test
- public void selectByAlmAppInstall_returns_empty_when_installation_is_not_bound_to_organization() {
- OrganizationDto organization = db.organizations().insert();
- AlmAppInstallDto almAppInstall = db.alm().insertAlmAppInstall();
- db.alm().insertOrganizationAlmBinding(organization, almAppInstall, true);
- // No binding on other organization
- AlmAppInstallDto otherAlmAppInstall = db.alm().insertAlmAppInstall();
-
- Optional<OrganizationAlmBindingDto> result = underTest.selectByAlmAppInstall(db.getSession(), otherAlmAppInstall);
-
- assertThat(result).isEmpty();
- }
-
- @Test
- public void selectByOrganizationAlmIds() {
- AlmAppInstallDto gitHubInstall1 = db.alm().insertAlmAppInstall(a -> a.setAlm(GITHUB));
- OrganizationAlmBindingDto organizationAlmBinding1 = db.alm().insertOrganizationAlmBinding(db.organizations().insert(), gitHubInstall1, true);
- AlmAppInstallDto gitHubInstall2 = db.alm().insertAlmAppInstall(a -> a.setAlm(GITHUB));
- OrganizationAlmBindingDto organizationAlmBinding2 = db.alm().insertOrganizationAlmBinding(db.organizations().insert(), gitHubInstall2, true);
- AlmAppInstallDto bitBucketInstall = db.alm().insertAlmAppInstall(a -> a.setAlm(BITBUCKETCLOUD));
- OrganizationAlmBindingDto organizationAlmBinding3 = db.alm().insertOrganizationAlmBinding(db.organizations().insert(), bitBucketInstall, true);
-
- List<OrganizationAlmBindingDto> result = underTest.selectByOrganizationAlmIds(db.getSession(), GITHUB,
- asList(gitHubInstall1.getOrganizationAlmId(), gitHubInstall2.getOrganizationAlmId(), bitBucketInstall.getOrganizationAlmId(), "unknown"));
-
- assertThat(result).extracting(OrganizationAlmBindingDto::getUuid)
- .containsExactlyInAnyOrder(organizationAlmBinding1.getUuid(), organizationAlmBinding2.getUuid());
- }
-
- @Test
- public void insert() {
- when(uuidFactory.create()).thenReturn("ABCD");
- OrganizationDto organization = db.organizations().insert();
- UserDto user = db.users().insertUser();
- AlmAppInstallDto almAppInstall = db.alm().insertAlmAppInstall();
-
- underTest.insert(db.getSession(), organization, almAppInstall, "http://myorg.com", user.getUuid(), true);
-
- assertThat(underTest.selectByOrganizationUuid(db.getSession(), organization.getUuid()).get())
- .extracting(OrganizationAlmBindingDto::getUuid, OrganizationAlmBindingDto::getOrganizationUuid, OrganizationAlmBindingDto::getAlmAppInstallUuid,
- OrganizationAlmBindingDto::getAlm,
- OrganizationAlmBindingDto::getUrl, OrganizationAlmBindingDto::getUserUuid, OrganizationAlmBindingDto::isMembersSyncEnable, OrganizationAlmBindingDto::getCreatedAt)
- .containsExactlyInAnyOrder("ABCD", organization.getUuid(), almAppInstall.getUuid(), GITHUB, "http://myorg.com", user.getUuid(), true, NOW);
- }
-
- @Test
- public void deleteByOrganization() {
- OrganizationDto organization = db.organizations().insert();
- AlmAppInstallDto almAppInstall = db.alm().insertAlmAppInstall();
- db.alm().insertOrganizationAlmBinding(organization, almAppInstall, true);
- OrganizationDto otherOrganization = db.organizations().insert();
- AlmAppInstallDto otherAlmAppInstall = db.alm().insertAlmAppInstall();
- db.alm().insertOrganizationAlmBinding(otherOrganization, otherAlmAppInstall, true);
-
- underTest.deleteByOrganization(db.getSession(), organization);
-
- assertThat(underTest.selectByOrganization(db.getSession(), organization)).isNotPresent();
- assertThat(underTest.selectByOrganization(db.getSession(), otherOrganization)).isPresent();
- }
-
- @Test
- public void deleteByAlmAppInstall() {
- OrganizationDto organization = db.organizations().insert();
- AlmAppInstallDto almAppInstall = db.alm().insertAlmAppInstall();
- db.alm().insertOrganizationAlmBinding(organization, almAppInstall, true);
- OrganizationDto otherOrganization = db.organizations().insert();
- AlmAppInstallDto otherAlmAppInstall = db.alm().insertAlmAppInstall();
- db.alm().insertOrganizationAlmBinding(otherOrganization, otherAlmAppInstall, true);
-
- underTest.deleteByAlmAppInstall(db.getSession(), almAppInstall);
-
- assertThat(underTest.selectByOrganization(db.getSession(), organization)).isNotPresent();
- assertThat(underTest.selectByOrganization(db.getSession(), otherOrganization)).isPresent();
- }
-
- @Test
- public void updateMembersSync() {
- OrganizationDto organization = db.organizations().insert();
- AlmAppInstallDto almAppInstall = db.alm().insertAlmAppInstall();
- OrganizationAlmBindingDto orgAlmBindingDto = db.alm().insertOrganizationAlmBinding(organization, almAppInstall, true);
-
- underTest.updateMembersSync(db.getSession(), orgAlmBindingDto, false);
-
- assertThat(db.getDbClient().organizationAlmBindingDao().selectByOrganization(db.getSession(), organization).get().isMembersSyncEnable()).isFalse();
- }
-}
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/DbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/DbTester.java
index b4f72ec2483..01b9afd9bab 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/DbTester.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/DbTester.java
@@ -32,7 +32,6 @@ import org.picocontainer.containers.TransientPicoContainer;
import org.sonar.api.utils.System2;
import org.sonar.core.util.SequenceUuidFactory;
import org.sonar.core.util.UuidFactory;
-import org.sonar.db.alm.AlmDbTester;
import org.sonar.db.alm.integration.pat.AlmPatsDbTester;
import org.sonar.db.almsettings.AlmSettingsDbTester;
import org.sonar.db.component.ComponentDbTester;
@@ -98,7 +97,6 @@ public class DbTester extends AbstractDbTester<TestDbImpl> {
private final PluginDbTester pluginDbTester;
private final WebhookDbTester webhookDbTester;
private final WebhookDeliveryDbTester webhookDeliveryDbTester;
- private final AlmDbTester almDbTester;
private final InternalComponentPropertyDbTester internalComponentPropertyTester;
private final AlmSettingsDbTester almSettingsDbTester;
private final AlmPatsDbTester almPatsDbtester;
@@ -127,7 +125,6 @@ public class DbTester extends AbstractDbTester<TestDbImpl> {
this.pluginDbTester = new PluginDbTester(this);
this.webhookDbTester = new WebhookDbTester(this);
this.webhookDeliveryDbTester = new WebhookDeliveryDbTester(this);
- this.almDbTester = new AlmDbTester(this);
this.internalComponentPropertyTester = new InternalComponentPropertyDbTester(this);
this.newCodePeriodTester = new NewCodePeriodDbTester(this);
this.almSettingsDbTester = new AlmSettingsDbTester(this);
@@ -295,10 +292,6 @@ public class DbTester extends AbstractDbTester<TestDbImpl> {
return webhookDeliveryDbTester;
}
- public AlmDbTester alm() {
- return almDbTester;
- }
-
public InternalComponentPropertyDbTester internalComponentProperties() {
return internalComponentPropertyTester;
}
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/alm/AlmDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/alm/AlmDbTester.java
deleted file mode 100644
index 596e0c44611..00000000000
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/alm/AlmDbTester.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2020 SonarSource SA
- * mailto:info 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.db.alm;
-
-import java.util.Arrays;
-import java.util.function.Consumer;
-import org.apache.commons.lang.math.RandomUtils;
-import org.sonar.db.DbTester;
-import org.sonar.db.component.ComponentDto;
-import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.user.UserDto;
-
-import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
-import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
-import static org.sonar.db.alm.ALM.GITHUB;
-
-public class AlmDbTester {
-
- private final DbTester db;
-
- public AlmDbTester(DbTester db) {
- this.db = db;
- }
-
- public OrganizationAlmBindingDto insertOrganizationAlmBinding(OrganizationDto organization, AlmAppInstallDto almAppInstall, boolean membersSync) {
- UserDto user = db.users().insertUser();
- db.getDbClient().organizationAlmBindingDao().insert(db.getSession(), organization, almAppInstall, randomAlphabetic(10), user.getUuid(), membersSync);
- db.commit();
- return db.getDbClient().organizationAlmBindingDao().selectByOrganization(db.getSession(), organization).get();
- }
-
- @SafeVarargs
- public final AlmAppInstallDto insertAlmAppInstall(Consumer<AlmAppInstallDto>... dtoPopulators) {
- AlmAppInstallDto dto = new AlmAppInstallDto()
- .setAlm(GITHUB)
- .setInstallId(randomAlphanumeric(10))
- .setOrganizationAlmId(Integer.toString(RandomUtils.nextInt()))
- .setIsOwnerUser(false)
- .setUserExternalId(randomAlphanumeric(10));
- Arrays.stream(dtoPopulators).forEach(dtoPopulator -> dtoPopulator.accept(dto));
- db.getDbClient().almAppInstallDao().insertOrUpdate(db.getSession(), dto.getAlm(), dto.getOrganizationAlmId(), dto.isOwnerUser(), dto.getInstallId(), dto.getUserExternalId());
- db.commit();
- return db.getDbClient().almAppInstallDao().selectByOrganizationAlmId(db.getSession(), dto.getAlm(), dto.getOrganizationAlmId()).get();
- }
-}