public void insert(DbSession dbSession, AlmPatDto almPatDto) {
String uuid = uuidFactory.create();
long now = system2.now();
- getMapper(dbSession).insert(almPatDto, uuid, now);
almPatDto.setUuid(uuid);
almPatDto.setCreatedAt(now);
almPatDto.setUpdatedAt(now);
+ getMapper(dbSession).insert(almPatDto);
}
public void update(DbSession dbSession, AlmPatDto almPatDto) {
long now = system2.now();
- getMapper(dbSession).update(almPatDto, now);
almPatDto.setUpdatedAt(now);
+ getMapper(dbSession).update(almPatDto);
}
public void delete(DbSession dbSession, AlmPatDto almPatDto) {
getMapper(dbSession).deleteByAlmSetting(almSetting.getUuid());
}
-
-
}
@CheckForNull
AlmPatDto selectByUserAndAlmSetting(@Param("userUuid") String userUuid, @Param("almSettingUuid") String almSettingUuid);
- void insert(@Param("dto") AlmPatDto almPatDto, @Param("uuid") String uuid, @Param("now") long now);
+ void insert(@Param("dto") AlmPatDto almPatDto);
- void update(@Param("dto") AlmPatDto almPatDto, @Param("now") long now);
+ void update(@Param("dto") AlmPatDto almPatDto);
void deleteByUuid(@Param("uuid") String uuid);
public void insert(DbSession dbSession, AlmSettingDto almSettingDto) {
String uuid = uuidFactory.create();
long now = system2.now();
- getMapper(dbSession).insert(almSettingDto, uuid, now);
almSettingDto.setUuid(uuid);
almSettingDto.setCreatedAt(now);
almSettingDto.setUpdatedAt(now);
+ getMapper(dbSession).insert(almSettingDto);
}
public Optional<AlmSettingDto> selectByUuid(DbSession dbSession, String uuid) {
return getMapper(dbSession).selectByAlm(alm.getId());
}
-
public List<AlmSettingDto> selectAll(DbSession dbSession) {
return getMapper(dbSession).selectAll();
}
- public void delete(DbSession dbSession, AlmSettingDto almSettingDto){
+ public void delete(DbSession dbSession, AlmSettingDto almSettingDto) {
getMapper(dbSession).deleteByKey(almSettingDto.getKey());
}
public void update(DbSession dbSession, AlmSettingDto almSettingDto) {
long now = system2.now();
- getMapper(dbSession).update(almSettingDto, now);
almSettingDto.setUpdatedAt(now);
+ getMapper(dbSession).update(almSettingDto);
}
}
List<AlmSettingDto> selectAll();
- void insert(@Param("dto") AlmSettingDto almSettingDto, @Param("uuid") String uuid, @Param("now") long now);
+ void insert(@Param("dto") AlmSettingDto almSettingDto);
- void update(@Param("dto") AlmSettingDto almSettingDto, @Param("now") long now);
+ void update(@Param("dto") AlmSettingDto almSettingDto);
void deleteByKey(@Param("key") String key);
}
updated_at
)
VALUES (
- #{uuid, jdbcType=VARCHAR},
+ #{dto.uuid, jdbcType=VARCHAR},
#{dto.personalAccessToken, jdbcType=VARCHAR},
#{dto.userUuid, jdbcType=VARCHAR},
#{dto.almSettingUuid, jdbcType=VARCHAR},
- #{now, jdbcType=BIGINT},
- #{now, jdbcType=BIGINT}
+ #{dto.createdAt, jdbcType=BIGINT},
+ #{dto.updatedAt, jdbcType=BIGINT}
)
</insert>
UPDATE alm_pats
<set>
pat = #{dto.personalAccessToken, jdbcType=VARCHAR},
- updated_at = #{now, jdbcType=BIGINT}
+ updated_at = #{dto.updatedAt, jdbcType=BIGINT}
</set>
<where>
uuid = #{dto.uuid, jdbcType=VARCHAR}
updated_at
)
VALUES (
- #{uuid, jdbcType=VARCHAR},
+ #{dto.uuid, jdbcType=VARCHAR},
#{dto.key, jdbcType=VARCHAR},
#{dto.rawAlm, jdbcType=VARCHAR},
#{dto.url, jdbcType=VARCHAR},
#{dto.appId, jdbcType=VARCHAR},
#{dto.privateKey, jdbcType=VARCHAR},
#{dto.personalAccessToken, jdbcType=VARCHAR},
- #{now, jdbcType=BIGINT},
- #{now, jdbcType=BIGINT}
+ #{dto.createdAt, jdbcType=BIGINT},
+ #{dto.updatedAt, jdbcType=BIGINT}
)
</insert>
app_id = #{dto.appId, jdbcType=VARCHAR},
private_key = #{dto.privateKey, jdbcType=VARCHAR},
pat = #{dto.personalAccessToken, jdbcType=VARCHAR},
- updated_at = #{now, jdbcType=BIGINT}
+ updated_at = #{dto.updatedAt, jdbcType=BIGINT}
</set>
<where>
uuid = #{dto.uuid, jdbcType=VARCHAR}
+++ /dev/null
-/*
- * 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.pat;
-
-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.db.DbSession;
-import org.sonar.db.DbTester;
-import org.sonar.db.alm.setting.AlmSettingDao;
-import org.sonar.db.alm.setting.AlmSettingDto;
-import org.sonar.db.user.UserDto;
-
-import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
-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.integration.pat.AlmPatsTesting.newAlmPatDto;
-import static org.sonar.db.almsettings.AlmSettingsTesting.newGithubAlmSettingDto;
-
-public class ALMPatDaoTest {
-
- private static final long NOW = 1000000L;
- private static final String A_UUID = "SOME_UUID";
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
- private System2 system2 = mock(System2.class);
- @Rule
- public DbTester db = DbTester.create(system2);
-
- private DbSession dbSession = db.getSession();
- private UuidFactory uuidFactory = mock(UuidFactory.class);
- private AlmPatDao underTest = new AlmPatDao(system2, uuidFactory);
- private AlmSettingDao almSettingDao = new AlmSettingDao(system2, uuidFactory);
-
- @Test
- public void selectByUuid() {
- when(uuidFactory.create()).thenReturn(A_UUID);
- when(system2.now()).thenReturn(NOW);
-
- AlmPatDto almPatDto = newAlmPatDto();
- underTest.insert(dbSession, almPatDto);
-
- assertThat(underTest.selectByUuid(dbSession, A_UUID).get())
- .extracting(AlmPatDto::getUuid, AlmPatDto::getPersonalAccessToken,
- AlmPatDto::getUserUuid, AlmPatDto::getAlmSettingUuid,
- AlmPatDto::getUpdatedAt, AlmPatDto::getCreatedAt)
- .containsExactly(A_UUID, almPatDto.getPersonalAccessToken(),
- almPatDto.getUserUuid(), almPatDto.getAlmSettingUuid(),
- NOW, NOW);
-
- assertThat(underTest.selectByUuid(dbSession, "foo")).isNotPresent();
- }
-
- @Test
- public void selectByAlmSetting() {
- when(uuidFactory.create()).thenReturn(A_UUID);
- when(system2.now()).thenReturn(NOW);
-
- AlmSettingDto almSetting = newGithubAlmSettingDto();
- almSettingDao.insert(dbSession, almSetting);
- AlmPatDto almPatDto = newAlmPatDto();
- almPatDto.setAlmSettingUuid(almSetting.getUuid());
-
- String userUuid = randomAlphanumeric(40);
- almPatDto.setUserUuid(userUuid);
- underTest.insert(dbSession, almPatDto);
-
- assertThat(underTest.selectByUserAndAlmSetting(dbSession, userUuid, almSetting).get())
- .extracting(AlmPatDto::getUuid, AlmPatDto::getPersonalAccessToken,
- AlmPatDto::getUserUuid, AlmPatDto::getAlmSettingUuid,
- AlmPatDto::getCreatedAt, AlmPatDto::getUpdatedAt)
- .containsExactly(A_UUID, almPatDto.getPersonalAccessToken(),
- userUuid, almSetting.getUuid(), NOW, NOW);
-
- assertThat(underTest.selectByUserAndAlmSetting(dbSession, randomAlphanumeric(40), newGithubAlmSettingDto())).isNotPresent();
- }
-
- @Test
- public void update() {
- when(uuidFactory.create()).thenReturn(A_UUID);
- when(system2.now()).thenReturn(NOW);
- AlmPatDto almPatDto = newAlmPatDto();
- underTest.insert(dbSession, almPatDto);
-
- String updated_pat = "updated pat";
- almPatDto.setPersonalAccessToken(updated_pat);
-
- when(system2.now()).thenReturn(NOW + 1);
- underTest.update(dbSession, almPatDto);
-
- AlmPatDto result = underTest.selectByUuid(dbSession, A_UUID).get();
- assertThat(result)
- .extracting(AlmPatDto::getUuid, AlmPatDto::getPersonalAccessToken,
- AlmPatDto::getUserUuid, AlmPatDto::getAlmSettingUuid,
- AlmPatDto::getCreatedAt, AlmPatDto::getUpdatedAt)
- .containsExactly(A_UUID, updated_pat, almPatDto.getUserUuid(),
- almPatDto.getAlmSettingUuid(),
- NOW, NOW + 1);
-
- }
-
- @Test
- public void delete() {
- when(uuidFactory.create()).thenReturn(A_UUID);
- when(system2.now()).thenReturn(NOW);
- AlmPatDto almPat = newAlmPatDto();
- underTest.insert(dbSession, almPat);
-
- underTest.delete(dbSession, almPat);
-
- assertThat(underTest.selectByUuid(dbSession, almPat.getUuid()).isPresent()).isFalse();
- }
-
- @Test
- public void deleteByUser() {
- when(uuidFactory.create()).thenReturn(A_UUID);
- when(system2.now()).thenReturn(NOW);
- UserDto userDto = db.users().insertUser();
- AlmPatDto almPat = newAlmPatDto();
- almPat.setUserUuid(userDto.getUuid());
- underTest.insert(dbSession, almPat);
-
- underTest.deleteByUser(dbSession, userDto);
-
- assertThat(underTest.selectByUuid(dbSession, almPat.getUuid()).isPresent()).isFalse();
- }
-
- @Test
- public void deleteByAlmSetting() {
- when(uuidFactory.create()).thenReturn(A_UUID);
- when(system2.now()).thenReturn(NOW);
- AlmSettingDto almSettingDto = db.almSettings().insertBitbucketAlmSetting();
- AlmPatDto almPat = newAlmPatDto();
- almPat.setAlmSettingUuid(almSettingDto.getUuid());
- underTest.insert(dbSession, almPat);
-
- underTest.deleteByAlmSetting(dbSession, almSettingDto);
-
- assertThat(underTest.selectByUuid(dbSession, almPat.getUuid()).isPresent()).isFalse();
- }
-
-}
--- /dev/null
+/*
+ * 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.pat;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.api.impl.utils.TestSystem2;
+import org.sonar.core.util.UuidFactory;
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
+import org.sonar.db.alm.setting.AlmSettingDao;
+import org.sonar.db.alm.setting.AlmSettingDto;
+import org.sonar.db.user.UserDto;
+
+import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
+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.integration.pat.AlmPatsTesting.newAlmPatDto;
+import static org.sonar.db.almsettings.AlmSettingsTesting.newGithubAlmSettingDto;
+
+public class AlmPatDaoTest {
+
+ private static final long NOW = 1000000L;
+ private static final String A_UUID = "SOME_UUID";
+ private TestSystem2 system2 = new TestSystem2().setNow(NOW);
+ @Rule
+ public DbTester db = DbTester.create(system2);
+
+ private DbSession dbSession = db.getSession();
+ private UuidFactory uuidFactory = mock(UuidFactory.class);
+ private AlmSettingDao almSettingDao = new AlmSettingDao(system2, uuidFactory);
+
+ private AlmPatDao underTest = new AlmPatDao(system2, uuidFactory);
+
+ @Test
+ public void selectByUuid() {
+ when(uuidFactory.create()).thenReturn(A_UUID);
+
+ AlmPatDto almPatDto = newAlmPatDto();
+ underTest.insert(dbSession, almPatDto);
+
+ assertThat(underTest.selectByUuid(dbSession, A_UUID).get())
+ .extracting(AlmPatDto::getUuid, AlmPatDto::getPersonalAccessToken,
+ AlmPatDto::getUserUuid, AlmPatDto::getAlmSettingUuid,
+ AlmPatDto::getUpdatedAt, AlmPatDto::getCreatedAt)
+ .containsExactly(A_UUID, almPatDto.getPersonalAccessToken(),
+ almPatDto.getUserUuid(), almPatDto.getAlmSettingUuid(),
+ NOW, NOW);
+
+ assertThat(underTest.selectByUuid(dbSession, "foo")).isNotPresent();
+ }
+
+ @Test
+ public void selectByAlmSetting() {
+ when(uuidFactory.create()).thenReturn(A_UUID);
+
+ AlmSettingDto almSetting = newGithubAlmSettingDto();
+ almSettingDao.insert(dbSession, almSetting);
+ AlmPatDto almPatDto = newAlmPatDto();
+ almPatDto.setAlmSettingUuid(almSetting.getUuid());
+
+ String userUuid = randomAlphanumeric(40);
+ almPatDto.setUserUuid(userUuid);
+ underTest.insert(dbSession, almPatDto);
+
+ assertThat(underTest.selectByUserAndAlmSetting(dbSession, userUuid, almSetting).get())
+ .extracting(AlmPatDto::getUuid, AlmPatDto::getPersonalAccessToken,
+ AlmPatDto::getUserUuid, AlmPatDto::getAlmSettingUuid,
+ AlmPatDto::getCreatedAt, AlmPatDto::getUpdatedAt)
+ .containsExactly(A_UUID, almPatDto.getPersonalAccessToken(),
+ userUuid, almSetting.getUuid(), NOW, NOW);
+
+ assertThat(underTest.selectByUserAndAlmSetting(dbSession, randomAlphanumeric(40), newGithubAlmSettingDto())).isNotPresent();
+ }
+
+ @Test
+ public void update() {
+ when(uuidFactory.create()).thenReturn(A_UUID);
+ AlmPatDto almPatDto = newAlmPatDto();
+ underTest.insert(dbSession, almPatDto);
+
+ String updated_pat = "updated pat";
+ almPatDto.setPersonalAccessToken(updated_pat);
+
+ system2.setNow(NOW + 1);
+ underTest.update(dbSession, almPatDto);
+
+ AlmPatDto result = underTest.selectByUuid(dbSession, A_UUID).get();
+ assertThat(result)
+ .extracting(AlmPatDto::getUuid, AlmPatDto::getPersonalAccessToken,
+ AlmPatDto::getUserUuid, AlmPatDto::getAlmSettingUuid,
+ AlmPatDto::getCreatedAt, AlmPatDto::getUpdatedAt)
+ .containsExactly(A_UUID, updated_pat, almPatDto.getUserUuid(),
+ almPatDto.getAlmSettingUuid(),
+ NOW, NOW + 1);
+ }
+
+ @Test
+ public void delete() {
+ when(uuidFactory.create()).thenReturn(A_UUID);
+ AlmPatDto almPat = newAlmPatDto();
+ underTest.insert(dbSession, almPat);
+
+ underTest.delete(dbSession, almPat);
+
+ assertThat(underTest.selectByUuid(dbSession, almPat.getUuid()).isPresent()).isFalse();
+ }
+
+ @Test
+ public void deleteByUser() {
+ when(uuidFactory.create()).thenReturn(A_UUID);
+ UserDto userDto = db.users().insertUser();
+ AlmPatDto almPat = newAlmPatDto();
+ almPat.setUserUuid(userDto.getUuid());
+ underTest.insert(dbSession, almPat);
+
+ underTest.deleteByUser(dbSession, userDto);
+
+ assertThat(underTest.selectByUuid(dbSession, almPat.getUuid()).isPresent()).isFalse();
+ }
+
+ @Test
+ public void deleteByAlmSetting() {
+ when(uuidFactory.create()).thenReturn(A_UUID);
+ AlmSettingDto almSettingDto = db.almSettings().insertBitbucketAlmSetting();
+ AlmPatDto almPat = newAlmPatDto();
+ almPat.setAlmSettingUuid(almSettingDto.getUuid());
+ underTest.insert(dbSession, almPat);
+
+ underTest.deleteByAlmSetting(dbSession, almSettingDto);
+
+ assertThat(underTest.selectByUuid(dbSession, almPat.getUuid()).isPresent()).isFalse();
+ }
+
+}
import java.util.List;
import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.sonar.api.utils.System2;
+import org.sonar.api.impl.utils.TestSystem2;
import org.sonar.core.util.UuidFactory;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
private static final long NOW = 1000000L;
private static final String A_UUID = "SOME_UUID";
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
- private System2 system2 = mock(System2.class);
+ private TestSystem2 system2 = new TestSystem2().setNow(NOW);
@Rule
public DbTester db = DbTester.create(system2);
private DbSession dbSession = db.getSession();
private UuidFactory uuidFactory = mock(UuidFactory.class);
+
private AlmSettingDao underTest = new AlmSettingDao(system2, uuidFactory);
@Test
public void selectByUuid() {
when(uuidFactory.create()).thenReturn(A_UUID);
- when(system2.now()).thenReturn(NOW);
AlmSettingDto almSettingDto = newGithubAlmSettingDto();
underTest.insert(dbSession, almSettingDto);
@Test
public void selectByKey() {
when(uuidFactory.create()).thenReturn(A_UUID);
- when(system2.now()).thenReturn(NOW);
AlmSettingDto almSettingDto = AlmSettingsTesting.newGithubAlmSettingDto();
underTest.insert(dbSession, almSettingDto);
@Test
public void selectByAlm() {
when(uuidFactory.create()).thenReturn(A_UUID);
- when(system2.now()).thenReturn(NOW);
AlmSettingDto gitHubAlmSetting1 = db.almSettings().insertGitHubAlmSetting();
AlmSettingDto gitHubAlmSetting2 = db.almSettings().insertGitHubAlmSetting();
AlmSettingDto azureAlmSetting2 = db.almSettings().insertAzureAlmSetting();
@Test
public void selectAll() {
when(uuidFactory.create()).thenReturn(A_UUID);
- when(system2.now()).thenReturn(NOW);
underTest.insert(dbSession, newGithubAlmSettingDto());
when(uuidFactory.create()).thenReturn(A_UUID + "bis");
underTest.insert(dbSession, newGithubAlmSettingDto());
@Test
public void update() {
when(uuidFactory.create()).thenReturn(A_UUID);
- when(system2.now()).thenReturn(NOW);
AlmSettingDto almSettingDto = newGithubAlmSettingDto();
underTest.insert(dbSession, almSettingDto);
almSettingDto.setPersonalAccessToken("updated pat");
almSettingDto.setKey("updated key");
- when(system2.now()).thenReturn(NOW + 1);
+ system2.setNow(NOW + 1);
underTest.update(dbSession, almSettingDto);
AlmSettingDto result = underTest.selectByUuid(dbSession, A_UUID).get();
@Test
public void delete() {
when(uuidFactory.create()).thenReturn(A_UUID);
- when(system2.now()).thenReturn(NOW);
AlmSettingDto almSettingDto = newGithubAlmSettingDto();
underTest.insert(dbSession, almSettingDto);
import java.util.Set;
import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.sonar.api.utils.System2;
+import org.sonar.api.impl.utils.TestSystem2;
import org.sonar.core.util.UuidFactory;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
private static final long A_DATE_LATER = 1_700_000_000_000L;
private static final String A_UUID = "SOME_UUID";
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
- private System2 system2 = mock(System2.class);
+ private TestSystem2 system2 = new TestSystem2().setNow(A_DATE);
@Rule
public DbTester db = DbTester.create(system2);
@Test
public void select_by_project() {
when(uuidFactory.create()).thenReturn(A_UUID);
- when(system2.now()).thenReturn(A_DATE);
AlmSettingDto githubAlmSettingDto = db.almSettings().insertGitHubAlmSetting();
ProjectDto project = db.components().insertPrivateProjectDto();
ProjectDto anotherProject = db.components().insertPrivateProjectDto();
@Test
public void select_by_alm_setting_and_slugs() {
when(uuidFactory.create()).thenReturn(A_UUID);
- when(system2.now()).thenReturn(A_DATE);
AlmSettingDto almSettingsDto = db.almSettings().insertBitbucketAlmSetting();
ProjectDto project = db.components().insertPrivateProjectDto();
ProjectAlmSettingDto bitbucketProjectAlmSettingDto = newBitbucketProjectAlmSettingDto(almSettingsDto, project);
@Test
public void select_with_no_slugs_return_empty() {
when(uuidFactory.create()).thenReturn(A_UUID);
- when(system2.now()).thenReturn(A_DATE);
AlmSettingDto almSettingsDto = db.almSettings().insertBitbucketAlmSetting();
assertThat(underTest.selectByAlmSettingAndSlugs(dbSession, almSettingsDto, new HashSet<>())).isEmpty();
@Test
public void update_existing_binding() {
when(uuidFactory.create()).thenReturn(A_UUID);
- when(system2.now()).thenReturn(A_DATE);
AlmSettingDto githubAlmSetting = db.almSettings().insertGitHubAlmSetting();
ProjectDto project = db.components().insertPrivateProjectDto();
ProjectAlmSettingDto projectAlmSettingDto = db.almSettings().insertGitHubProjectAlmSetting(githubAlmSetting, project);
AlmSettingDto anotherGithubAlmSetting = db.almSettings().insertGitHubAlmSetting();
- when(system2.now()).thenReturn(A_DATE_LATER);
+ system2.setNow(A_DATE_LATER);
ProjectAlmSettingDto newProjectAlmSettingDto = newGithubProjectAlmSettingDto(anotherGithubAlmSetting, project)
.setSummaryCommentEnabled(false);
underTest.insertOrUpdate(dbSession, newProjectAlmSettingDto);
@Test
public void deleteByProject() {
when(uuidFactory.create()).thenReturn(A_UUID);
- when(system2.now()).thenReturn(A_DATE);
AlmSettingDto githubAlmSetting = db.almSettings().insertGitHubAlmSetting();
ProjectDto project = db.components().insertPrivateProjectDto();
db.almSettings().insertGitHubProjectAlmSetting(githubAlmSetting, project);
@Test
public void deleteByAlmSetting() {
when(uuidFactory.create()).thenReturn(A_UUID);
- when(system2.now()).thenReturn(A_DATE);
AlmSettingDto githubAlmSetting = db.almSettings().insertGitHubAlmSetting();
ProjectDto project1 = db.components().insertPrivateProjectDto();
ProjectDto project2 = db.components().insertPrivateProjectDto();
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
-import java.sql.Connection;
-import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.stream.Stream;
import javax.annotation.CheckForNull;
import org.sonar.core.util.stream.MoreCollectors;
-import org.sonar.db.Database;
-import org.sonar.db.DatabaseUtils;
import org.sonar.db.dialect.Dialect;
import org.sonar.db.dialect.H2;
import org.sonar.db.dialect.MsSql;
this.tableName = validateTableName(tableName);
}
- public boolean tableExists(Database database) throws SQLException {
- try (Connection connection = database.getDataSource().getConnection()) {
- return DatabaseUtils.tableExists(tableName, connection);
- }
- }
-
public List<String> build() {
checkState(!columnDefs.isEmpty() || !pkColumnDefs.isEmpty(), "at least one column must be specified");
*/
package org.sonar.server.platform.db.migration.version.v80;
-import java.sql.Connection;
import java.sql.SQLException;
import org.sonar.db.Database;
-import org.sonar.db.DatabaseUtils;
import org.sonar.server.platform.db.migration.def.BigIntegerColumnDef;
import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
-
public class CreateNewCodePeriodTable extends DdlChange {
private static final String TABLE_NAME = "new_code_periods";
.setIsNullable(false)
.build();
-
public CreateNewCodePeriodTable(Database db) {
super(db);
}
@Override
public void execute(Context context) throws SQLException {
- if (tableExists()) {
- return;
- }
context.execute(new CreateTableBuilder(getDialect(), TABLE_NAME)
.addPkColumn(UUID_COLUMN)
.addColumn(PROJECT_UUID_COLUMN)
.build());
}
- private boolean tableExists() throws SQLException {
- try (Connection connection = getDatabase().getDataSource().getConnection()) {
- return DatabaseUtils.tableExists(TABLE_NAME, connection);
- }
- }
}
*/
package org.sonar.server.platform.db.migration.version.v80;
-import java.sql.Connection;
import java.sql.SQLException;
import org.sonar.db.Database;
-import org.sonar.db.DatabaseUtils;
import org.sonar.server.platform.db.migration.SupportsBlueGreen;
import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
@Override
public void execute(Context context) throws SQLException {
- if (tableExists()) {
- return;
- }
context.execute(new CreateTableBuilder(getDialect(), TABLE_NAME)
.addPkColumn(PROJECT_UUID_COLUMN)
.addColumn(QUALITY_GATE_UUID_COLUMN)
.addColumn(QUALITY_GATE_UUID_COLUMN)
.build());
}
-
- private boolean tableExists() throws SQLException {
- try (Connection connection = getDatabase().getDataSource().getConnection()) {
- return DatabaseUtils.tableExists(TABLE_NAME, connection);
- }
- }
}
*/
package org.sonar.server.platform.db.migration.version.v81;
-import java.sql.Connection;
import java.sql.SQLException;
import org.sonar.db.Database;
-import org.sonar.db.DatabaseUtils;
import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
import org.sonar.server.platform.db.migration.sql.CreateTableBuilder;
@Override
public void execute(Context context) throws SQLException {
- if (tableExists()) {
- return;
- }
context.execute(new CreateTableBuilder(getDialect(), TABLE_NAME)
.addPkColumn(newVarcharColumnDefBuilder()
.setColumnName("uuid")
.setUnique(true)
.build());
}
-
- private boolean tableExists() throws SQLException {
- try (Connection connection = getDatabase().getDataSource().getConnection()) {
- return DatabaseUtils.tableExists(TABLE_NAME, connection);
- }
- }
}
*/
package org.sonar.server.platform.db.migration.version.v81;
-import java.sql.Connection;
import java.sql.SQLException;
import org.sonar.db.Database;
-import org.sonar.db.DatabaseUtils;
import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
import org.sonar.server.platform.db.migration.sql.CreateTableBuilder;
@Override
public void execute(Context context) throws SQLException {
- if (tableExists()) {
- return;
- }
context.execute(new CreateTableBuilder(getDialect(), TABLE_NAME)
.addPkColumn(newVarcharColumnDefBuilder()
.setColumnName("uuid")
.setName("project_alm_settings_alm")
.build());
}
-
- private boolean tableExists() throws SQLException {
- try (Connection connection = getDatabase().getDataSource().getConnection()) {
- return DatabaseUtils.tableExists(TABLE_NAME, connection);
- }
- }
}
*/
package org.sonar.server.platform.db.migration.version.v82;
-import java.sql.Connection;
import java.sql.SQLException;
import org.sonar.db.Database;
-import org.sonar.db.DatabaseUtils;
import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
import org.sonar.server.platform.db.migration.sql.CreateTableBuilder;
@Override
public void execute(Context context) throws SQLException {
- if (tableExists()) {
- return;
- }
-
context.execute(new CreateTableBuilder(getDialect(), TABLE_NAME)
.addPkColumn(newVarcharColumnDefBuilder()
.setColumnName("uuid")
.setUnique(true)
.build());
}
-
- private boolean tableExists() throws SQLException {
- try (Connection connection = getDatabase().getDataSource().getConnection()) {
- return DatabaseUtils.tableExists(TABLE_NAME, connection);
- }
- }
}
*/
package org.sonar.server.platform.db.migration.version.v82;
-import java.sql.Connection;
import java.sql.SQLException;
import org.sonar.db.Database;
-import org.sonar.db.DatabaseUtils;
import org.sonar.server.platform.db.migration.def.BigIntegerColumnDef;
import org.sonar.server.platform.db.migration.def.BooleanColumnDef;
import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
@Override
public void execute(Context context) throws SQLException {
- if (tableExists()) {
- return;
- }
context.execute(new CreateTableBuilder(getDialect(), TABLE_NAME)
.withPkConstraintName("pk_new_projects")
.addPkColumn(UUID_COLUMN)
.addColumn(QUALIFIER_COLUMN)
.build());
}
-
- private boolean tableExists() throws SQLException {
- try (Connection connection = getDatabase().getDataSource().getConnection()) {
- return DatabaseUtils.tableExists(TABLE_NAME, connection);
- }
- }
}
dbTester.assertColumnDefinition(TABLE_NAME, "value", VARCHAR, 40, true);
dbTester.assertColumnDefinition(TABLE_NAME, "updated_at", BIGINT, 20, false);
dbTester.assertColumnDefinition(TABLE_NAME, "created_at", BIGINT, 20, false);
-
- //script should not fail if executed twice
- underTest.execute();
}
}
dbTester.assertColumnDefinition(TABLE_NAME, "project_uuid", VARCHAR, 40, false);
dbTester.assertColumnDefinition(TABLE_NAME, "quality_gate_uuid", VARCHAR, 40, false);
-
- //script should not fail if executed twice
- underTest.execute();
}
}
dbTester.assertColumnDefinition(TABLE_NAME, "pat", VARCHAR, 2000, true);
dbTester.assertColumnDefinition(TABLE_NAME, "updated_at", BIGINT, 20, false);
dbTester.assertColumnDefinition(TABLE_NAME, "created_at", BIGINT, 20, false);
-
- // script should not fail if executed twice
- underTest.execute();
}
}
dbTester.assertColumnDefinition(TABLE_NAME, "alm_slug", VARCHAR, 256, true);
dbTester.assertColumnDefinition(TABLE_NAME, "updated_at", BIGINT, 20, false);
dbTester.assertColumnDefinition(TABLE_NAME, "created_at", BIGINT, 20, false);
-
- // script should not fail if executed twice
- underTest.execute();
}
}
dbTester.assertColumnDefinition(TABLE_NAME, "alm_setting_uuid", VARCHAR, 40, false);
dbTester.assertColumnDefinition(TABLE_NAME, "updated_at", BIGINT, 20, false);
dbTester.assertColumnDefinition(TABLE_NAME, "created_at", BIGINT, 20, false);
-
- // script should not fail if executed twice
- underTest.execute();
}
}
dbTester.assertColumnDefinition(TABLE_NAME, "tags", VARCHAR, 500, true);
dbTester.assertColumnDefinition(TABLE_NAME, "created_at", BIGINT, null, true);
dbTester.assertColumnDefinition(TABLE_NAME, "updated_at", BIGINT, null, false);
-
- // script should not fail if executed twice
- underTest.execute();
}
}
import org.sonar.db.CoreDbTester;
public class RenameProjectsTableToComponentsTest {
- private static final String TABLE_NAME = "projects";
+ private static final String OLD_TABLE_NAME = "projects";
private static final String NEW_TABLE_NAME = "components";
@Rule
@Rule
public ExpectedException expectedException = ExpectedException.none();
- private CreateProjectsTable underTest = new CreateProjectsTable(dbTester.database());
+ private RenameProjectsTableToComponents underTest = new RenameProjectsTableToComponents(dbTester.database());
@Test
public void table_has_been_renamed() throws SQLException {
-
underTest.execute();
- dbTester.assertTableExists(TABLE_NAME);
- dbTester.assertPrimaryKey(TABLE_NAME, "pk_projects", "id");
-
- dbTester.assertIndex(TABLE_NAME, "PROJECTS_ORGANIZATION", "organization_uuid");
- dbTester.assertUniqueIndex(TABLE_NAME, "PROJECTS_KEE", "kee");
- dbTester.assertIndex(TABLE_NAME, "PROJECTS_ROOT_UUID", "root_uuid");
- dbTester.assertUniqueIndex(TABLE_NAME, "PROJECTS_UUID", "uuid");
- dbTester.assertIndex(TABLE_NAME, "PROJECTS_PROJECT_UUID", "project_uuid");
- dbTester.assertIndex(TABLE_NAME, "PROJECTS_MODULE_UUID", "module_uuid");
- dbTester.assertIndex(TABLE_NAME, "PROJECTS_QUALIFIER", "qualifier");
+ dbTester.assertTableDoesNotExist(OLD_TABLE_NAME);
- underTest.execute();
+ dbTester.assertTableExists(NEW_TABLE_NAME);
+ dbTester.assertPrimaryKey(NEW_TABLE_NAME, "pk_projects", "id");
- dbTester.assertTableExists(TABLE_NAME);
+ dbTester.assertIndex(NEW_TABLE_NAME, "PROJECTS_ORGANIZATION", "organization_uuid");
+ dbTester.assertUniqueIndex(NEW_TABLE_NAME, "PROJECTS_KEE", "kee");
+ dbTester.assertIndex(NEW_TABLE_NAME, "PROJECTS_ROOT_UUID", "root_uuid");
+ dbTester.assertUniqueIndex(NEW_TABLE_NAME, "PROJECTS_UUID", "uuid");
+ dbTester.assertIndex(NEW_TABLE_NAME, "PROJECTS_PROJECT_UUID", "project_uuid");
+ dbTester.assertIndex(NEW_TABLE_NAME, "PROJECTS_MODULE_UUID", "module_uuid");
+ dbTester.assertIndex(NEW_TABLE_NAME, "PROJECTS_QUALIFIER", "qualifier");
}
}