Fix sonar findings: dupplications (#1989)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -19,6 +19,8 @@ import org.junit.jupiter.api.extension.Extension;
|
||||
@Slf4j
|
||||
public class MsSqlTestDatabase extends AbstractSqlTestDatabase {
|
||||
|
||||
private static final String DATABASE_AND_SURROUNDINGS = ";database=";
|
||||
|
||||
public MsSqlTestDatabase(final DatasourceContext context) {
|
||||
super(context);
|
||||
}
|
||||
@@ -28,14 +30,14 @@ public class MsSqlTestDatabase extends AbstractSqlTestDatabase {
|
||||
final String uri = context.getDatasourceUrl();
|
||||
log.info("\033[0;33mCreating mssql schema {} \033[0m", context.getRandomSchemaName());
|
||||
|
||||
executeStatement(uri.split(";database=")[0], "CREATE DATABASE " + context.getRandomSchemaName() + ";");
|
||||
executeStatement(uri.split(DATABASE_AND_SURROUNDINGS)[0], "CREATE DATABASE " + context.getRandomSchemaName() + ";");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void dropRandomSchema() {
|
||||
final String uri = context.getDatasourceUrl();
|
||||
final String dbServerUri = uri.split(";database=")[0];
|
||||
final String dbServerUri = uri.split(DATABASE_AND_SURROUNDINGS)[0];
|
||||
log.info("\033[0;33mDropping mssql schema {} \033[0m", context.getRandomSchemaName());
|
||||
|
||||
// Needed to avoid the DROP is rejected with "database still in use"
|
||||
@@ -46,6 +48,6 @@ public class MsSqlTestDatabase extends AbstractSqlTestDatabase {
|
||||
@Override
|
||||
protected String getRandomSchemaUri() {
|
||||
final String uri = context.getDatasourceUrl();
|
||||
return uri.substring(0, uri.indexOf(';')) + ";database=" + context.getRandomSchemaName();
|
||||
return uri.substring(0, uri.indexOf(';')) + DATABASE_AND_SURROUNDINGS + context.getRandomSchemaName();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import org.junit.jupiter.api.extension.Extension;
|
||||
public class PostgreSqlTestDatabase extends AbstractSqlTestDatabase {
|
||||
|
||||
private static final String POSTGRESQL_URI_PATTERN = "jdbc:postgresql://{host}:{port}/{db}*";
|
||||
private static final String CURRENT_SCHEMA_AND_SURROUNDINGS = "?currentSchema=";
|
||||
|
||||
public PostgreSqlTestDatabase(final DatasourceContext context) {
|
||||
super(context);
|
||||
@@ -30,7 +31,7 @@ public class PostgreSqlTestDatabase extends AbstractSqlTestDatabase {
|
||||
@Override
|
||||
protected PostgreSqlTestDatabase createRandomSchema() {
|
||||
log.info("\033[0;33mCreating postgreSql schema {} \033[0m", context.getRandomSchemaName());
|
||||
final String uri = getBaseUri() + "?currentSchema=" + getSchemaName();
|
||||
final String uri = getBaseUri() + CURRENT_SCHEMA_AND_SURROUNDINGS + getSchemaName();
|
||||
executeStatement(uri, "CREATE SCHEMA " + context.getRandomSchemaName() + ";");
|
||||
return this;
|
||||
}
|
||||
@@ -38,13 +39,13 @@ public class PostgreSqlTestDatabase extends AbstractSqlTestDatabase {
|
||||
@Override
|
||||
protected void dropRandomSchema() {
|
||||
log.info("\033[0;33mDropping postgreSql schema {}\033[0m", context.getRandomSchemaName());
|
||||
final String uri = getBaseUri() + "?currentSchema=" + getSchemaName();
|
||||
final String uri = getBaseUri() + CURRENT_SCHEMA_AND_SURROUNDINGS + getSchemaName();
|
||||
executeStatement(uri, "DROP SCHEMA " + context.getRandomSchemaName() + " CASCADE;");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getRandomSchemaUri() {
|
||||
return getBaseUri() + "?currentSchema=" + context.getRandomSchemaName();
|
||||
return getBaseUri() + CURRENT_SCHEMA_AND_SURROUNDINGS + context.getRandomSchemaName();
|
||||
}
|
||||
|
||||
private String getBaseUri() {
|
||||
|
||||
@@ -137,6 +137,8 @@ public class TestdataFactory {
|
||||
|
||||
public static final String DEFAULT_COLOUR = "#000000";
|
||||
|
||||
private static final String SPACE_AND_DESCRIPTION = " description";
|
||||
|
||||
@Autowired
|
||||
private ControllerManagement controllerManagament;
|
||||
|
||||
@@ -1070,7 +1072,7 @@ public class TestdataFactory {
|
||||
public Rollout createRollout(final String prefix) {
|
||||
createTargets(quotaManagement.getMaxTargetsPerRolloutGroup() * quotaManagement.getMaxRolloutGroupsPerRollout(),
|
||||
prefix);
|
||||
return createRolloutByVariables(prefix, prefix + " description",
|
||||
return createRolloutByVariables(prefix, prefix + SPACE_AND_DESCRIPTION,
|
||||
quotaManagement.getMaxRolloutGroupsPerRollout(), "controllerId==" + prefix + "*",
|
||||
createDistributionSet(prefix), "50", "5");
|
||||
}
|
||||
@@ -1085,7 +1087,7 @@ public class TestdataFactory {
|
||||
final String prefix = RandomStringUtils.randomAlphanumeric(5);
|
||||
createTargets(quotaManagement.getMaxTargetsPerRolloutGroup() * quotaManagement.getMaxRolloutGroupsPerRollout(),
|
||||
prefix);
|
||||
return createRolloutByVariables(prefix, prefix + " description",
|
||||
return createRolloutByVariables(prefix, prefix + SPACE_AND_DESCRIPTION,
|
||||
quotaManagement.getMaxRolloutGroupsPerRollout(), "controllerId==" + prefix + "*",
|
||||
createDistributionSet(prefix), "50", "5");
|
||||
}
|
||||
@@ -1187,7 +1189,7 @@ public class TestdataFactory {
|
||||
public TargetType findOrCreateTargetType(final String targetTypeName) {
|
||||
return targetTypeManagement.getByName(targetTypeName)
|
||||
.orElseGet(() -> targetTypeManagement.create(entityFactory.targetType().create()
|
||||
.name(targetTypeName).description(targetTypeName + " description")
|
||||
.name(targetTypeName).description(targetTypeName + SPACE_AND_DESCRIPTION)
|
||||
.key(targetTypeName + " key").colour(DEFAULT_COLOUR)));
|
||||
}
|
||||
|
||||
@@ -1201,7 +1203,7 @@ public class TestdataFactory {
|
||||
*/
|
||||
public TargetType createTargetType(final String targetTypeName, final List<DistributionSetType> compatibleDsTypes) {
|
||||
return targetTypeManagement.create(entityFactory.targetType().create().name(targetTypeName)
|
||||
.description(targetTypeName + " description").colour(DEFAULT_COLOUR)
|
||||
.description(targetTypeName + SPACE_AND_DESCRIPTION).colour(DEFAULT_COLOUR)
|
||||
.compatible(compatibleDsTypes.stream().map(DistributionSetType::getId).collect(Collectors.toList())));
|
||||
}
|
||||
|
||||
@@ -1216,7 +1218,7 @@ public class TestdataFactory {
|
||||
final List<TargetTypeCreate> result = new ArrayList<>(count);
|
||||
for (int i = 0; i < count; i++) {
|
||||
result.add(entityFactory.targetType().create()
|
||||
.name(targetTypePrefix + i).description(targetTypePrefix + " description")
|
||||
.name(targetTypePrefix + i).description(targetTypePrefix + SPACE_AND_DESCRIPTION)
|
||||
.key(targetTypePrefix + i + " key").colour(DEFAULT_COLOUR));
|
||||
}
|
||||
return targetTypeManagement.create(result);
|
||||
|
||||
Reference in New Issue
Block a user