RED-8670: integrate table inference from research #507
@ -10,10 +10,6 @@ import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.security.test.context.support.WithMockUser;
|
||||
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
|
||||
import com.iqser.red.service.peristence.v1.server.integration.client.CustomPermissionClient;
|
||||
import com.iqser.red.service.peristence.v1.server.integration.utils.AbstractPersistenceServerServiceTest;
|
||||
|
||||
@ -44,7 +44,7 @@ import lombok.SneakyThrows;
|
||||
public class DossierTemplateImportExportTest extends AbstractPersistenceServerServiceTest {
|
||||
|
||||
public static final String IMPORTED_TEMPLATE_NAME = "imported-template";
|
||||
public static final String USER_ID = "Deine Mutter";
|
||||
public static final String USER_ID = "NutzerIdentifikationsNummer";
|
||||
public static final String AFTER = "after";
|
||||
public static final String BEFORE = "before";
|
||||
|
||||
@ -70,9 +70,10 @@ public class DossierTemplateImportExportTest extends AbstractPersistenceServerSe
|
||||
|
||||
@Test
|
||||
@SneakyThrows
|
||||
// @DirtiesContext
|
||||
public void testImportExportRoundtrip() {
|
||||
|
||||
TenantContext.setTenantId("redaction");
|
||||
TenantContext.setTenantId(TENANT_1);
|
||||
Path outDir = Files.createTempDirectory(IMPORTED_TEMPLATE_NAME);
|
||||
|
||||
Path dossierTemplateExportArchive = new ClassPathResource("files/dossiertemplates/DossierTemplate.zip").getFile().toPath();
|
||||
@ -159,7 +160,7 @@ public class DossierTemplateImportExportTest extends AbstractPersistenceServerSe
|
||||
|
||||
|
||||
@Override
|
||||
public FileVisitResult preVisitDirectory(Path subDir, BasicFileAttributes attrs) throws IOException {
|
||||
public FileVisitResult preVisitDirectory(Path subDir, BasicFileAttributes attrs) {
|
||||
|
||||
contents.put(dir.relativize(subDir), new byte[0]);
|
||||
return FileVisitResult.CONTINUE;
|
||||
|
||||
@ -9,14 +9,17 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.repository.CommentRepository;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.repository.annotationentity.ResizeRedactionRepository;
|
||||
|
||||
import org.assertj.core.util.Lists;
|
||||
import org.bson.BsonArray;
|
||||
import org.bson.BsonDocument;
|
||||
import org.bson.BsonString;
|
||||
import org.checkerframework.checker.units.qual.A;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
@ -38,6 +41,7 @@ import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.StatementCallback;
|
||||
import org.springframework.jdbc.datasource.SingleConnectionDataSource;
|
||||
@ -50,8 +54,10 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
||||
import org.springframework.security.web.SecurityFilterChain;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.test.context.support.TestPropertySourceUtils;
|
||||
|
||||
import com.iqser.red.commons.jackson.ObjectMapperFactory;
|
||||
import com.iqser.red.service.peristence.v1.server.Application;
|
||||
@ -138,6 +144,9 @@ import lombok.extern.slf4j.Slf4j;
|
||||
@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT, properties = "spring-hibernate-query-utils.n-plus-one-queries-detection.error-level=INFO")
|
||||
public abstract class AbstractPersistenceServerServiceTest {
|
||||
|
||||
public static final String TENANT_1 = "redaction";
|
||||
public static final String TENANT_2 = "redaction2";
|
||||
|
||||
@MockBean
|
||||
protected Scheduler scheduler;
|
||||
@MockBean
|
||||
@ -273,7 +282,7 @@ public abstract class AbstractPersistenceServerServiceTest {
|
||||
@BeforeEach
|
||||
public void setupTenantContext() {
|
||||
|
||||
TenantContext.setTenantId("redaction");
|
||||
TenantContext.setTenantId(TENANT_1);
|
||||
}
|
||||
|
||||
|
||||
@ -289,7 +298,7 @@ public abstract class AbstractPersistenceServerServiceTest {
|
||||
|
||||
createTenants();
|
||||
|
||||
TenantContext.setTenantId("redaction");
|
||||
TenantContext.setTenantId(TENANT_1);
|
||||
|
||||
ApplicationConfig appConfig = ApplicationConfig.builder().downloadCleanupDownloadFilesHours(8).downloadCleanupNotDownloadFilesHours(72).softDeleteCleanupTime(96).build();
|
||||
applicationConfigService.saveApplicationConfiguration(MagicConverter.convert(appConfig, ApplicationConfigurationEntity.class));
|
||||
@ -346,9 +355,9 @@ public abstract class AbstractPersistenceServerServiceTest {
|
||||
if (tenantsClient.getTenants() == null || tenantsClient.getTenants().isEmpty()) {
|
||||
|
||||
var redactionTenant = new TenantResponse();
|
||||
redactionTenant.setTenantId("redaction");
|
||||
redactionTenant.setGuid("redaction");
|
||||
redactionTenant.setDisplayName("redaction");
|
||||
redactionTenant.setTenantId(TENANT_1);
|
||||
redactionTenant.setGuid(TENANT_1);
|
||||
redactionTenant.setDisplayName(TENANT_1);
|
||||
redactionTenant.setAuthDetails(new AuthDetails());
|
||||
redactionTenant.setDatabaseConnection(DatabaseConnection.builder()
|
||||
.driver("postgresql")
|
||||
@ -388,9 +397,9 @@ public abstract class AbstractPersistenceServerServiceTest {
|
||||
.build());
|
||||
|
||||
var redactionTenant2 = new TenantResponse();
|
||||
redactionTenant2.setTenantId("redaction2");
|
||||
redactionTenant2.setGuid("redaction2");
|
||||
redactionTenant2.setDisplayName("redaction2");
|
||||
redactionTenant2.setTenantId(TENANT_2);
|
||||
redactionTenant2.setGuid(TENANT_2);
|
||||
redactionTenant2.setDisplayName(TENANT_2);
|
||||
redactionTenant2.setAuthDetails(new AuthDetails());
|
||||
redactionTenant2.setDatabaseConnection(DatabaseConnection.builder()
|
||||
.driver("postgresql")
|
||||
@ -425,19 +434,19 @@ public abstract class AbstractPersistenceServerServiceTest {
|
||||
.username(MONGO_USERNAME)
|
||||
.password(encryptionDecryptionService.encrypt(MONGO_PASSWORD))
|
||||
.address(mongoDbContainer.getHost() + ":" + mongoDbContainer.getFirstMappedPort())
|
||||
.database("redaction2")
|
||||
.database(TENANT_2)
|
||||
.options("")
|
||||
.build());
|
||||
|
||||
when(tenantsClient.getTenant("redaction")).thenReturn(redactionTenant);
|
||||
when(tenantsClient.getTenant("redaction2")).thenReturn(redactionTenant2);
|
||||
when(tenantsClient.getTenant(TENANT_1)).thenReturn(redactionTenant);
|
||||
when(tenantsClient.getTenant(TENANT_2)).thenReturn(redactionTenant2);
|
||||
when(tenantsClient.getTenants()).thenReturn(List.of(redactionTenant, redactionTenant2));
|
||||
|
||||
try {
|
||||
tenantCreatedListener.createTenant(new TenantCreatedEvent("redaction"));
|
||||
tenantCreatedListener.createTenant(new TenantCreatedEvent("redaction2"));
|
||||
mongoTenantCreatedListener.createTenant(new MongoTenantCreatedEvent("redaction"));
|
||||
mongoTenantCreatedListener.createTenant(new MongoTenantCreatedEvent("redaction2"));
|
||||
tenantCreatedListener.createTenant(new TenantCreatedEvent(TENANT_1));
|
||||
tenantCreatedListener.createTenant(new TenantCreatedEvent(TENANT_2));
|
||||
mongoTenantCreatedListener.createTenant(new MongoTenantCreatedEvent(TENANT_1));
|
||||
mongoTenantCreatedListener.createTenant(new MongoTenantCreatedEvent(TENANT_2));
|
||||
} catch (Exception e) {
|
||||
|
||||
e.printStackTrace();
|
||||
@ -515,7 +524,6 @@ public abstract class AbstractPersistenceServerServiceTest {
|
||||
notificationPreferencesRepository.deleteAll();
|
||||
indexInformationRepository.deleteAll();
|
||||
applicationConfigRepository.deleteAll();
|
||||
|
||||
entityLogEntryDocumentRepository.deleteAll();
|
||||
entityLogDocumentRepository.deleteAll();
|
||||
|
||||
@ -526,8 +534,15 @@ public abstract class AbstractPersistenceServerServiceTest {
|
||||
@Slf4j
|
||||
static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
|
||||
|
||||
static AtomicInteger UniquePortFactory = new AtomicInteger(28081);
|
||||
|
||||
|
||||
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
|
||||
|
||||
ConfigurableEnvironment environment = configurableApplicationContext.getEnvironment();
|
||||
int port = UniquePortFactory.getAndIncrement();
|
||||
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(environment, "server.port=" + port);
|
||||
|
||||
var postgreSQLContainerMaster = SpringPostgreSQLTestContainer.getInstance().withDatabaseName("integration-tests-db-master").withUsername("sa").withPassword("sa");
|
||||
|
||||
postgreSQLContainerMaster.start();
|
||||
@ -537,8 +552,8 @@ public abstract class AbstractPersistenceServerServiceTest {
|
||||
|
||||
var mongoInstance = MongoDBTestContainer.getInstance();
|
||||
mongoInstance.start();
|
||||
createMongoDBDatabase(mongoInstance, "redaction");
|
||||
createMongoDBDatabase(mongoInstance, "redaction2");
|
||||
createMongoDBDatabase(mongoInstance, TENANT_1);
|
||||
createMongoDBDatabase(mongoInstance, TENANT_2);
|
||||
|
||||
log.info("Hosts are - Redis: {}, Postgres: {}, MongoDB: {}", redisContainer.getHost(), postgreSQLContainerMaster.getHost(), mongoInstance.getHost());
|
||||
|
||||
@ -553,37 +568,36 @@ public abstract class AbstractPersistenceServerServiceTest {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void createMongoDBDatabase(MongoDBTestContainer mongoDBTestContainer, String databaseName) {
|
||||
|
||||
private static void createMongoDBDatabase(MongoDBTestContainer mongoDBTestContainer, String databaseName) {
|
||||
try (MongoClient mongoClient = MongoClients.create(String.format("mongodb://%s:%s@%s:%s/",
|
||||
MONGO_USERNAME,
|
||||
MONGO_PASSWORD,
|
||||
mongoDBTestContainer.getHost(),
|
||||
mongoDBTestContainer.getFirstMappedPort()))) {
|
||||
MongoDatabase database = mongoClient.getDatabase(databaseName);
|
||||
BsonDocument createUserCommand = new BsonDocument();
|
||||
createUserCommand.append("createUser", new BsonString(MONGO_USERNAME));
|
||||
createUserCommand.append("pwd", new BsonString(MONGO_PASSWORD));
|
||||
BsonArray roles = new BsonArray();
|
||||
roles.add(new BsonDocument("role", new BsonString("dbOwner")).append("db", new BsonString(databaseName)));
|
||||
createUserCommand.append("roles", roles);
|
||||
|
||||
try (MongoClient mongoClient = MongoClients.create(String.format("mongodb://%s:%s@%s:%s/",
|
||||
MONGO_USERNAME,
|
||||
MONGO_PASSWORD,
|
||||
mongoDBTestContainer.getHost(),
|
||||
mongoDBTestContainer.getFirstMappedPort()))) {
|
||||
MongoDatabase database = mongoClient.getDatabase(databaseName);
|
||||
BsonDocument createUserCommand = new BsonDocument();
|
||||
createUserCommand.append("createUser", new BsonString(MONGO_USERNAME));
|
||||
createUserCommand.append("pwd", new BsonString(MONGO_PASSWORD));
|
||||
BsonArray roles = new BsonArray();
|
||||
roles.add(new BsonDocument("role", new BsonString("dbOwner")).append("db", new BsonString(databaseName)));
|
||||
createUserCommand.append("roles", roles);
|
||||
try {
|
||||
database.runCommand(createUserCommand);
|
||||
} catch (MongoCommandException mongoCommandException) {
|
||||
// ignore user already exists
|
||||
if (mongoCommandException.getErrorCode() != 51003) {
|
||||
throw mongoCommandException;
|
||||
}
|
||||
|
||||
try {
|
||||
database.runCommand(createUserCommand);
|
||||
} catch (MongoCommandException mongoCommandException) {
|
||||
// ignore user already exists
|
||||
if (mongoCommandException.getErrorCode() != 51003) {
|
||||
throw mongoCommandException;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableWebSecurity
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user