Skip to content
Snippets Groups Projects
Unverified Commit 55bababc authored by Martin Weise's avatar Martin Weise
Browse files

WIP

- Fix some JUnit tests
parent 79baeae6
Branches
Tags
2 merge requests!163Relase 1.3.0,!155Added readme to authentication service and added eureka service
Showing
with 310 additions and 185 deletions
......@@ -9,9 +9,9 @@ import at.tuwien.entities.container.image.ContainerImage;
import at.tuwien.exception.*;
import at.tuwien.repository.jpa.ContainerRepository;
import at.tuwien.repository.jpa.ImageRepository;
import at.tuwien.repository.jpa.RealmRepository;
import at.tuwien.repository.jpa.UserRepository;
import lombok.extern.log4j.Log4j2;
import org.apache.http.auth.BasicUserPrincipal;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -20,7 +20,6 @@ import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import java.security.Principal;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
......@@ -47,12 +46,8 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
@Autowired
private ContainerService containerService;
@BeforeAll
public static void beforeAll() {
afterAll();
/* create networks */
DockerConfig.createAllNetworks();
}
@Autowired
private RealmRepository realmRepository;
@BeforeEach
public void beforeEach() {
......@@ -60,21 +55,9 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
/* create networks */
DockerConfig.createAllNetworks();
/* mock data */
USER_1.setAttributes(List.of());
userRepository.save(USER_1);
imageRepository.save(ContainerImage.builder()
.id(IMAGE_1_ID)
.repository(IMAGE_1_REPOSITORY)
.tag(IMAGE_1_TAG)
.hash(IMAGE_1_HASH)
.compiled(IMAGE_1_BUILT)
.dialect(IMAGE_1_DIALECT)
.jdbcMethod(IMAGE_1_JDBC)
.driverClass(IMAGE_1_DRIVER)
.size(IMAGE_1_SIZE)
.environment(IMAGE_1_ENV)
.defaultPort(IMAGE_1_PORT)
.build()) /* keep */;
userRepository.save(USER_1_SIMPLE);
imageRepository.save(IMAGE_1_SIMPLE);
realmRepository.save(REALM_DBREPO);
}
@AfterEach
......@@ -83,12 +66,6 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
DockerConfig.removeAllNetworks();
}
@AfterAll
public static void afterAll() {
DockerConfig.removeAllContainers();
DockerConfig.removeAllNetworks();
}
@Test
public void create_succeeds()
throws DockerClientException, ImageNotFoundException, ContainerAlreadyExistsException,
......@@ -98,10 +75,9 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
.tag(IMAGE_1_TAG)
.name(CONTAINER_1_NAME)
.build();
final Principal principal = new BasicUserPrincipal(USER_1_USERNAME);
/* test */
final Container container = containerService.create(request, principal);
final Container container = containerService.create(request, USER_1_PRINCIPAL);
assertEquals(CONTAINER_1_NAME, container.getName());
assertEquals(USER_1_USERNAME, container.getCreator().getUsername());
assertEquals(USER_1_USERNAME, container.getOwner().getUsername());
......@@ -115,14 +91,13 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
.tag(IMAGE_1_TAG)
.name(CONTAINER_1_NAME)
.build();
final Principal principal = new BasicUserPrincipal(USER_1_USERNAME);
/* mock */
containerRepository.save(CONTAINER_1);
containerRepository.save(CONTAINER_1_SIMPLE);
/* test */
assertThrows(ContainerAlreadyExistsException.class, () -> {
containerService.create(request, principal);
containerService.create(request, USER_1_PRINCIPAL);
});
}
......@@ -142,11 +117,10 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
.tag(IMAGE_2_TAG)
.name(CONTAINER_3_NAME)
.build();
final Principal principal = new BasicUserPrincipal(USER_1_USERNAME);
/* test */
assertThrows(ImageNotFoundException.class, () -> {
containerService.create(request, principal);
containerService.create(request, USER_1_PRINCIPAL);
});
}
......@@ -164,8 +138,8 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
ContainerAlreadyRunningException {
/* mock */
DockerConfig.createContainer(null, CONTAINER_1, CONTAINER_1_ENV);
containerRepository.save(CONTAINER_1);
DockerConfig.createContainer(null, CONTAINER_1_SIMPLE, CONTAINER_1_ENV);
containerRepository.save(CONTAINER_1_SIMPLE);
/* test */
containerService.start(CONTAINER_1_ID);
......@@ -176,9 +150,9 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
ContainerAlreadyStoppedException, InterruptedException {
/* mock */
DockerConfig.createContainer(null, CONTAINER_1, CONTAINER_1_ENV);
DockerConfig.startContainer(CONTAINER_1);
containerRepository.save(CONTAINER_1);
DockerConfig.createContainer(null, CONTAINER_1_SIMPLE, CONTAINER_1_ENV);
DockerConfig.startContainer(CONTAINER_1_SIMPLE);
containerRepository.save(CONTAINER_1_SIMPLE);
/* test */
containerService.stop(CONTAINER_1_ID);
......@@ -188,7 +162,7 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
public void change_startSavedButNotFound_fails() {
/* mock */
containerRepository.save(CONTAINER_1);
containerRepository.save(CONTAINER_1_SIMPLE);
/* test */
assertThrows(ContainerNotFoundException.class, () -> {
......@@ -200,7 +174,7 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
public void change_removeSavedButNotFound_fails() {
/* mock */
containerRepository.save(CONTAINER_1);
containerRepository.save(CONTAINER_1_SIMPLE);
/* test */
assertThrows(ContainerNotFoundException.class, () -> {
......@@ -212,8 +186,8 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
public void getAll_succeeds() {
/* mock */
containerRepository.save(CONTAINER_1);
containerRepository.save(CONTAINER_2);
containerRepository.save(CONTAINER_1_SIMPLE);
containerRepository.save(CONTAINER_2_SIMPLE);
/* test */
final List<Container> response = containerService.getAll(null);
......@@ -224,8 +198,8 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
public void getAll_limit_succeeds() {
/* mock */
containerRepository.save(CONTAINER_1);
containerRepository.save(CONTAINER_2);
containerRepository.save(CONTAINER_1_SIMPLE);
containerRepository.save(CONTAINER_2_SIMPLE);
/* test */
final List<Container> response = containerService.getAll(1);
......@@ -237,10 +211,10 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
ContainerNotFoundException, ContainerAlreadyRemovedException, InterruptedException {
/* mock */
DockerConfig.createContainer(null, CONTAINER_1, CONTAINER_1_ENV);
DockerConfig.startContainer(CONTAINER_1);
DockerConfig.stopContainer(CONTAINER_1);
containerRepository.save(CONTAINER_1);
DockerConfig.createContainer(null, CONTAINER_1_SIMPLE, CONTAINER_1_ENV);
DockerConfig.startContainer(CONTAINER_1_SIMPLE);
DockerConfig.stopContainer(CONTAINER_1_SIMPLE);
containerRepository.save(CONTAINER_1_SIMPLE);
/* test */
containerService.remove(CONTAINER_1_ID);
......@@ -259,9 +233,9 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
public void remove_stillRunning_fails() throws InterruptedException {
/* mock */
DockerConfig.createContainer(null, CONTAINER_1, CONTAINER_1_ENV);
DockerConfig.startContainer(CONTAINER_1);
containerRepository.save(CONTAINER_1);
DockerConfig.createContainer(null, CONTAINER_1_SIMPLE, CONTAINER_1_ENV);
DockerConfig.startContainer(CONTAINER_1_SIMPLE);
containerRepository.save(CONTAINER_1_SIMPLE);
/* test */
assertThrows(ContainerStillRunningException.class, () -> {
......@@ -273,9 +247,9 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
public void change_alreadyRunning_fails() throws InterruptedException {
/* mock */
DockerConfig.createContainer(null, CONTAINER_1, CONTAINER_1_ENV);
DockerConfig.startContainer(CONTAINER_1);
containerRepository.save(CONTAINER_1);
DockerConfig.createContainer(null, CONTAINER_1_SIMPLE, CONTAINER_1_ENV);
DockerConfig.startContainer(CONTAINER_1_SIMPLE);
containerRepository.save(CONTAINER_1_SIMPLE);
/* test */
assertThrows(ContainerAlreadyRunningException.class, () -> {
......@@ -299,10 +273,10 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
public void change_alreadyStopped_fails() throws InterruptedException {
/* mock */
DockerConfig.createContainer(null, CONTAINER_1, CONTAINER_1_ENV);
DockerConfig.startContainer(CONTAINER_1);
DockerConfig.stopContainer(CONTAINER_1);
containerRepository.save(CONTAINER_1);
DockerConfig.createContainer(null, CONTAINER_1_SIMPLE, CONTAINER_1_ENV);
DockerConfig.startContainer(CONTAINER_1_SIMPLE);
DockerConfig.stopContainer(CONTAINER_1_SIMPLE);
containerRepository.save(CONTAINER_1_SIMPLE);
/* test */
assertThrows(ContainerAlreadyStoppedException.class, () -> {
......@@ -314,8 +288,8 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
public void change_stopNeverStarted_fails() {
/* mock */
DockerConfig.createContainer(null, CONTAINER_1, CONTAINER_1_ENV);
containerRepository.save(CONTAINER_1);
DockerConfig.createContainer(null, CONTAINER_1_SIMPLE, CONTAINER_1_ENV);
containerRepository.save(CONTAINER_1_SIMPLE);
/* test */
assertThrows(ContainerAlreadyStoppedException.class, () -> {
......@@ -327,7 +301,7 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
public void change_stopSavedButNotFound_fails() {
/* mock */
containerRepository.save(CONTAINER_1);
containerRepository.save(CONTAINER_1_SIMPLE);
/* test */
assertThrows(ContainerNotFoundException.class, () -> {
......@@ -340,9 +314,9 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
ContainerNotRunningException {
/* mock */
DockerConfig.createContainer(null, CONTAINER_1, CONTAINER_1_ENV);
DockerConfig.startContainer(CONTAINER_1);
containerRepository.save(CONTAINER_1);
DockerConfig.createContainer(null, CONTAINER_1_SIMPLE, CONTAINER_1_ENV);
DockerConfig.startContainer(CONTAINER_1_SIMPLE);
containerRepository.save(CONTAINER_1_SIMPLE);
/* test */
final Container response = containerService.inspect(CONTAINER_1_ID);
......@@ -365,8 +339,8 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
public void inspect_notRunning_fails() {
/* mock */
DockerConfig.createContainer(null, CONTAINER_1, CONTAINER_1_ENV);
containerRepository.save(CONTAINER_1);
DockerConfig.createContainer(null, CONTAINER_1_SIMPLE, CONTAINER_1_ENV);
containerRepository.save(CONTAINER_1_SIMPLE);
/* test */
assertThrows(ContainerNotRunningException.class, () -> {
......
......@@ -47,20 +47,8 @@ public class ImageServiceIntegrationTest extends BaseUnitTest {
@BeforeEach
public void beforeEach() {
userRepository.save(USER_1);
imageRepository.save(ContainerImage.builder()
.id(IMAGE_1_ID)
.repository(IMAGE_1_REPOSITORY)
.tag(IMAGE_1_TAG)
.hash(IMAGE_1_HASH)
.compiled(IMAGE_1_BUILT)
.dialect(IMAGE_1_DIALECT)
.jdbcMethod(IMAGE_1_JDBC)
.driverClass(IMAGE_1_DRIVER)
.size(IMAGE_1_SIZE)
.environment(IMAGE_1_ENV)
.defaultPort(IMAGE_1_PORT)
.build()) /* keep */;
userRepository.save(USER_1_SIMPLE);
imageRepository.save(IMAGE_1_SIMPLE);
}
@Test
......
......@@ -38,8 +38,8 @@ public class PersistenceIntegrationTest extends BaseUnitTest {
@BeforeEach
public void beforeEach() {
userRepository.save(USER_1);
imageRepository.save(IMAGE_1);
userRepository.save(USER_1_SIMPLE);
imageRepository.save(IMAGE_1_SIMPLE);
}
@Test
......
package at.tuwien.repository.jpa;
import at.tuwien.entities.user.Realm;
import at.tuwien.entities.user.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.Optional;
@Repository
public interface RealmRepository extends JpaRepository<Realm, String> {
}
......@@ -7,7 +7,7 @@ import org.springframework.stereotype.Repository;
import java.util.Optional;
@Repository
public interface UserRepository extends JpaRepository<User, Long> {
public interface UserRepository extends JpaRepository<User, String> {
Optional<User> findByUsername(String username);
......
......@@ -12,7 +12,6 @@ import at.tuwien.entities.database.AccessType;
import at.tuwien.entities.database.DatabaseAccess;
import at.tuwien.exception.*;
import at.tuwien.repository.jpa.*;
import at.tuwien.test.BaseTest;
import com.rabbitmq.client.Channel;
import lombok.extern.log4j.Log4j2;
import org.junit.jupiter.api.*;
......@@ -86,11 +85,10 @@ public class AccessServiceIntegrationTest extends BaseUnitTest {
/* metadata database */
h2Utils.runScript("schema.sql");
imageRepository.save(IMAGE_1);
userRepository.save(USER_1);
userRepository.save(USER_2);
containerRepository.save(CONTAINER_1);
DATABASE_1.setCreator(USER_1);
databaseRepository.save(DATABASE_1);
userRepository.save(USER_1_SIMPLE);
userRepository.save(USER_2_SIMPLE);
containerRepository.save(CONTAINER_1_SIMPLE);
databaseRepository.save(DATABASE_1_SIMPLE);
}
@AfterEach
......@@ -104,12 +102,12 @@ public class AccessServiceIntegrationTest extends BaseUnitTest {
DatabaseNotFoundException, DatabaseMalformedException, InterruptedException {
/* mock */
DockerConfig.createContainer(BIND_WEATHER, CONTAINER_1, CONTAINER_1_ENV);
DockerConfig.startContainer(CONTAINER_1);
userRepository.save(USER_1);
userRepository.save(USER_2);
containerRepository.save(CONTAINER_1);
databaseRepository.save(DATABASE_1);
DockerConfig.createContainer(BIND_WEATHER, CONTAINER_1_SIMPLE, CONTAINER_1_ENV);
DockerConfig.startContainer(CONTAINER_1_SIMPLE);
userRepository.save(USER_1_SIMPLE);
userRepository.save(USER_2_SIMPLE);
containerRepository.save(CONTAINER_1_SIMPLE);
databaseRepository.save(DATABASE_1_SIMPLE);
/* test */
create_generic(AccessTypeDto.READ, AccessType.READ, USER_2_USERNAME, USER_2_ID);
......@@ -119,12 +117,12 @@ public class AccessServiceIntegrationTest extends BaseUnitTest {
public void create_multiple_fails() throws InterruptedException {
/* mock */
DockerConfig.createContainer(BIND_WEATHER, CONTAINER_1, CONTAINER_1_ENV);
DockerConfig.startContainer(CONTAINER_1);
userRepository.save(USER_1);
userRepository.save(USER_2);
containerRepository.save(CONTAINER_1);
databaseRepository.save(DATABASE_1);
DockerConfig.createContainer(BIND_WEATHER, CONTAINER_1_SIMPLE, CONTAINER_1_ENV);
DockerConfig.startContainer(CONTAINER_1_SIMPLE);
userRepository.save(USER_1_SIMPLE);
userRepository.save(USER_2_SIMPLE);
containerRepository.save(CONTAINER_1_SIMPLE);
databaseRepository.save(DATABASE_1_SIMPLE);
databaseAccessRepository.save(DATABASE_1_DEVELOPER_READ_ACCESS);
/* test */
......@@ -138,12 +136,12 @@ public class AccessServiceIntegrationTest extends BaseUnitTest {
DatabaseNotFoundException, DatabaseMalformedException, InterruptedException {
/* mock */
DockerConfig.createContainer(BIND_WEATHER, CONTAINER_1, CONTAINER_1_ENV);
DockerConfig.startContainer(CONTAINER_1);
userRepository.save(USER_1);
userRepository.save(USER_2);
containerRepository.save(CONTAINER_1);
databaseRepository.save(DATABASE_1);
DockerConfig.createContainer(BIND_WEATHER, CONTAINER_1_SIMPLE, CONTAINER_1_ENV);
DockerConfig.startContainer(CONTAINER_1_SIMPLE);
userRepository.save(USER_1_SIMPLE);
userRepository.save(USER_2_SIMPLE);
containerRepository.save(CONTAINER_1_SIMPLE);
databaseRepository.save(DATABASE_1_SIMPLE);
databaseAccessRepository.save(DATABASE_1_DEVELOPER_READ_ACCESS);
/* test */
......@@ -155,12 +153,12 @@ public class AccessServiceIntegrationTest extends BaseUnitTest {
DatabaseNotFoundException, DatabaseMalformedException, InterruptedException {
/* mock */
DockerConfig.createContainer(BIND_WEATHER, CONTAINER_1, CONTAINER_1_ENV);
DockerConfig.startContainer(CONTAINER_1);
userRepository.save(USER_1);
userRepository.save(USER_2);
containerRepository.save(CONTAINER_1);
databaseRepository.save(DATABASE_1);
DockerConfig.createContainer(BIND_WEATHER, CONTAINER_1_SIMPLE, CONTAINER_1_ENV);
DockerConfig.startContainer(CONTAINER_1_SIMPLE);
userRepository.save(USER_1_SIMPLE);
userRepository.save(USER_2_SIMPLE);
containerRepository.save(CONTAINER_1_SIMPLE);
databaseRepository.save(DATABASE_1_SIMPLE);
/* test */
update_generic(CONTAINER_1_ID, DATABASE_1_ID, AccessTypeDto.WRITE_OWN, AccessType.WRITE_OWN, USER_2_USERNAME, USER_2_ID);
......@@ -171,12 +169,12 @@ public class AccessServiceIntegrationTest extends BaseUnitTest {
DatabaseNotFoundException, DatabaseMalformedException, InterruptedException {
/* mock */
DockerConfig.createContainer(BIND_WEATHER, CONTAINER_1, CONTAINER_1_ENV);
DockerConfig.startContainer(CONTAINER_1);
userRepository.save(USER_1);
userRepository.save(USER_2);
containerRepository.save(CONTAINER_1);
databaseRepository.save(DATABASE_1);
DockerConfig.createContainer(BIND_WEATHER, CONTAINER_1_SIMPLE, CONTAINER_1_ENV);
DockerConfig.startContainer(CONTAINER_1_SIMPLE);
userRepository.save(USER_1_SIMPLE);
userRepository.save(USER_2_SIMPLE);
containerRepository.save(CONTAINER_1_SIMPLE);
databaseRepository.save(DATABASE_1_SIMPLE);
/* test */
update_generic(CONTAINER_1_ID, DATABASE_1_ID, AccessTypeDto.WRITE_ALL, AccessType.WRITE_ALL, USER_2_USERNAME, USER_2_ID);
......@@ -186,11 +184,11 @@ public class AccessServiceIntegrationTest extends BaseUnitTest {
public void update_userNotFound_fails() throws InterruptedException {
/* mock */
DockerConfig.createContainer(BIND_WEATHER, CONTAINER_1, CONTAINER_1_ENV);
DockerConfig.startContainer(CONTAINER_1);
userRepository.save(USER_1);
containerRepository.save(CONTAINER_1);
databaseRepository.save(DATABASE_1);
DockerConfig.createContainer(BIND_WEATHER, CONTAINER_1_SIMPLE, CONTAINER_1_ENV);
DockerConfig.startContainer(CONTAINER_1_SIMPLE);
userRepository.save(USER_1_SIMPLE);
containerRepository.save(CONTAINER_1_SIMPLE);
databaseRepository.save(DATABASE_1_SIMPLE);
/* test */
assertThrows(UserNotFoundException.class, () -> {
......@@ -204,11 +202,11 @@ public class AccessServiceIntegrationTest extends BaseUnitTest {
/* mock */
DockerConfig.createContainer(BIND_WEATHER, CONTAINER_2, CONTAINER_2_ENV);
DockerConfig.startContainer(CONTAINER_2);
userRepository.save(USER_1);
userRepository.save(USER_2);
containerRepository.save(CONTAINER_1);
userRepository.save(USER_1_SIMPLE);
userRepository.save(USER_2_SIMPLE);
containerRepository.save(CONTAINER_1_SIMPLE);
containerRepository.save(CONTAINER_2);
databaseRepository.save(DATABASE_1);
databaseRepository.save(DATABASE_1_SIMPLE);
/* test */
assertThrows(DatabaseNotFoundException.class, () -> {
......@@ -221,12 +219,12 @@ public class AccessServiceIntegrationTest extends BaseUnitTest {
DatabaseNotFoundException, DatabaseMalformedException, InterruptedException {
/* mock */
DockerConfig.createContainer(BIND_WEATHER, CONTAINER_1, CONTAINER_1_ENV);
DockerConfig.startContainer(CONTAINER_1);
userRepository.save(USER_1);
userRepository.save(USER_2);
containerRepository.save(CONTAINER_1);
databaseRepository.save(DATABASE_1);
DockerConfig.createContainer(BIND_WEATHER, CONTAINER_1_SIMPLE, CONTAINER_1_ENV);
DockerConfig.startContainer(CONTAINER_1_SIMPLE);
userRepository.save(USER_1_SIMPLE);
userRepository.save(USER_2_SIMPLE);
containerRepository.save(CONTAINER_1_SIMPLE);
databaseRepository.save(DATABASE_1_SIMPLE);
/* test */
accessService.delete(CONTAINER_1_ID, DATABASE_1_ID, USER_2_USERNAME);
......@@ -236,11 +234,11 @@ public class AccessServiceIntegrationTest extends BaseUnitTest {
public void delete_isOwner_fails() throws InterruptedException {
/* mock */
DockerConfig.createContainer(BIND_WEATHER, CONTAINER_1, CONTAINER_1_ENV);
DockerConfig.startContainer(CONTAINER_1);
userRepository.save(USER_1);
containerRepository.save(CONTAINER_1);
databaseRepository.save(DATABASE_1);
DockerConfig.createContainer(BIND_WEATHER, CONTAINER_1_SIMPLE, CONTAINER_1_ENV);
DockerConfig.startContainer(CONTAINER_1_SIMPLE);
userRepository.save(USER_1_SIMPLE);
containerRepository.save(CONTAINER_1_SIMPLE);
databaseRepository.save(DATABASE_1_SIMPLE);
/* test */
assertThrows(NotAllowedException.class, () -> {
......@@ -252,10 +250,10 @@ public class AccessServiceIntegrationTest extends BaseUnitTest {
public void delete_notExists_fails() throws InterruptedException {
/* mock */
DockerConfig.createContainer(BIND_WEATHER, CONTAINER_1, CONTAINER_1_ENV);
DockerConfig.startContainer(CONTAINER_1);
containerRepository.save(CONTAINER_1);
databaseRepository.save(DATABASE_1);
DockerConfig.createContainer(BIND_WEATHER, CONTAINER_1_SIMPLE, CONTAINER_1_ENV);
DockerConfig.startContainer(CONTAINER_1_SIMPLE);
containerRepository.save(CONTAINER_1_SIMPLE);
databaseRepository.save(DATABASE_1_SIMPLE);
/* test */
assertThrows(UserNotFoundException.class, () -> {
......
......@@ -7,6 +7,7 @@ import at.tuwien.config.*;
import at.tuwien.entities.database.Database;
import at.tuwien.repository.elastic.DatabaseIdxRepository;
import at.tuwien.repository.jpa.ContainerRepository;
import at.tuwien.repository.jpa.DatabaseRepository;
import at.tuwien.repository.jpa.ImageRepository;
import at.tuwien.repository.jpa.UserRepository;
import at.tuwien.service.impl.MariaDbServiceImpl;
......@@ -81,8 +82,8 @@ public class DatabaseServiceIntegrationElasticTest extends BaseUnitTest {
afterEach();
/* metadata database */
h2Utils.runScript("schema.sql");
imageRepository.save(IMAGE_1);
userRepository.save(USER_1);
imageRepository.save(IMAGE_1_SIMPLE);
userRepository.save(USER_1_SIMPLE);
}
@AfterEach
......@@ -96,8 +97,8 @@ public class DatabaseServiceIntegrationElasticTest extends BaseUnitTest {
/* mock */
DockerConfig.createContainer(null, CONTAINER_ELASTIC, CONTAINER_ELASTIC_ENV);
DockerConfig.startContainer(CONTAINER_ELASTIC);
DockerConfig.createContainer(BIND, CONTAINER_1, CONTAINER_1_ENV);
DockerConfig.startContainer(CONTAINER_1);
DockerConfig.createContainer(BIND, CONTAINER_1_SIMPLE, CONTAINER_1_ENV);
DockerConfig.startContainer(CONTAINER_1_SIMPLE);
when(databaseIdxRepository.save(any(DatabaseDto.class)))
.thenReturn(DATABASE_1_DTO);
......@@ -114,9 +115,9 @@ public class DatabaseServiceIntegrationElasticTest extends BaseUnitTest {
final Principal principal = new BasicUserPrincipal(USER_1_USERNAME);
/* mock */
containerRepository.save(CONTAINER_1);
containerRepository.save(CONTAINER_2);
containerRepository.save(CONTAINER_3);
containerRepository.save(CONTAINER_1_SIMPLE);
containerRepository.save(CONTAINER_2_SIMPLE);
containerRepository.save(CONTAINER_3_SIMPLE);
/* test */
final Database response = databaseService.create(containerId, createDto, principal);
......
......@@ -12,7 +12,6 @@ import at.tuwien.exception.QueryMalformedException;
import at.tuwien.repository.elastic.DatabaseIdxRepository;
import at.tuwien.repository.jpa.*;
import at.tuwien.service.impl.MariaDbServiceImpl;
import at.tuwien.test.BaseTest;
import com.rabbitmq.client.Channel;
import lombok.extern.log4j.Log4j2;
import org.apache.http.auth.BasicUserPrincipal;
......@@ -49,16 +48,16 @@ public class DatabaseServiceIntegrationTest extends BaseUnitTest {
private IndexConfig indexConfig;
@MockBean
private UserRepository userRepository;
private ContainerRepository containerRepository;
@MockBean
private ContainerRepository containerRepository;
private DatabaseIdxRepository databaseIdxRepository;
@MockBean
private MariaDbServiceImpl databaseService;
@MockBean
private DatabaseIdxRepository databaseIdxRepository;
private DatabaseRepository databaseRepository;
@Autowired
private MariaDbConfig mariaDbConfig;
......@@ -95,13 +94,15 @@ public class DatabaseServiceIntegrationTest extends BaseUnitTest {
public void create_succeeds() throws Exception {
/* mock */
DockerConfig.createContainer(BIND_MUSICOLOGY, CONTAINER_3, CONTAINER_3_ENV);
DockerConfig.startContainer(CONTAINER_3);
DockerConfig.createContainer(BIND_MUSICOLOGY, CONTAINER_3_SIMPLE, CONTAINER_3_ENV);
DockerConfig.startContainer(CONTAINER_3_SIMPLE);
MariaDbConfig.dropDatabase(CONTAINER_3_INTERNALNAME, DATABASE_3_INTERNALNAME, "root", "mariadb");
when(databaseIdxRepository.save(any(DatabaseDto.class)))
.thenReturn(DATABASE_1_DTO);
when(containerRepository.findById(CONTAINER_3_ID))
.thenReturn(Optional.of(CONTAINER_3));
when(databaseRepository.save(any(Database.class)))
.thenReturn(DATABASE_1);
/* test */
generic_create(CONTAINER_3_ID, DATABASE_3_CREATE, DATABASE_3);
......@@ -111,17 +112,20 @@ public class DatabaseServiceIntegrationTest extends BaseUnitTest {
public void create_inSequence_succeeds() throws Exception {
/* mock */
DockerConfig.createContainer(BIND_ZOO, CONTAINER_2, CONTAINER_2_ENV);
DockerConfig.startContainer(CONTAINER_2);
DockerConfig.createContainer(BIND_ZOO, CONTAINER_2_SIMPLE, CONTAINER_2_ENV);
DockerConfig.startContainer(CONTAINER_2_SIMPLE);
MariaDbConfig.dropDatabase(CONTAINER_2_INTERNALNAME, DATABASE_2_INTERNALNAME, "root", "mariadb");
DockerConfig.createContainer(BIND_MUSICOLOGY, CONTAINER_3, CONTAINER_3_ENV);
DockerConfig.startContainer(CONTAINER_3);
DockerConfig.createContainer(BIND_MUSICOLOGY, CONTAINER_3_SIMPLE, CONTAINER_3_ENV);
DockerConfig.startContainer(CONTAINER_3_SIMPLE);
MariaDbConfig.dropDatabase(CONTAINER_3_INTERNALNAME, DATABASE_3_INTERNALNAME, "root", "mariadb");
when(databaseIdxRepository.save(any(DatabaseDto.class)))
.thenReturn(DATABASE_2_DTO)
.thenReturn(DATABASE_3_DTO);
when(containerRepository.findById(CONTAINER_3_ID))
.thenReturn(Optional.of(CONTAINER_3));
.thenReturn(Optional.of(CONTAINER_3_SIMPLE));
when(databaseRepository.save(any(Database.class)))
.thenReturn(DATABASE_2)
.thenReturn(DATABASE_3);
/* test */
generic_create(CONTAINER_2_ID, DATABASE_2_CREATE, DATABASE_2);
......@@ -132,17 +136,20 @@ public class DatabaseServiceIntegrationTest extends BaseUnitTest {
public void create_outOfSequence_succeeds() throws Exception {
/* mock */
DockerConfig.createContainer(BIND_ZOO, CONTAINER_2, CONTAINER_2_ENV);
DockerConfig.startContainer(CONTAINER_2);
DockerConfig.createContainer(BIND_ZOO, CONTAINER_2_SIMPLE, CONTAINER_2_ENV);
DockerConfig.startContainer(CONTAINER_2_SIMPLE);
MariaDbConfig.dropDatabase(CONTAINER_2_INTERNALNAME, DATABASE_2_INTERNALNAME, "root", "mariadb");
DockerConfig.createContainer(BIND_MUSICOLOGY, CONTAINER_3, CONTAINER_3_ENV);
DockerConfig.startContainer(CONTAINER_3);
DockerConfig.createContainer(BIND_MUSICOLOGY, CONTAINER_3_SIMPLE, CONTAINER_3_ENV);
DockerConfig.startContainer(CONTAINER_3_SIMPLE);
MariaDbConfig.dropDatabase(CONTAINER_3_INTERNALNAME, DATABASE_3_INTERNALNAME, "root", "mariadb");
when(databaseIdxRepository.save(any(DatabaseDto.class)))
.thenReturn(DATABASE_3_DTO)
.thenReturn(DATABASE_2_DTO);
when(containerRepository.findById(CONTAINER_3_ID))
.thenReturn(Optional.of(CONTAINER_3));
when(databaseRepository.save(any(Database.class)))
.thenReturn(DATABASE_2)
.thenReturn(DATABASE_3);
/* test */
generic_create(CONTAINER_3_ID, DATABASE_3_CREATE, DATABASE_3);
......@@ -153,10 +160,12 @@ public class DatabaseServiceIntegrationTest extends BaseUnitTest {
public void create_queryStore_succeeds() throws SQLException, InterruptedException, QueryMalformedException {
/* mock */
DockerConfig.createContainer(BIND_MUSICOLOGY, CONTAINER_3, CONTAINER_3_ENV);
DockerConfig.startContainer(CONTAINER_3);
DockerConfig.createContainer(BIND_MUSICOLOGY, CONTAINER_3_SIMPLE, CONTAINER_3_ENV);
DockerConfig.startContainer(CONTAINER_3_SIMPLE);
when(containerRepository.findById(CONTAINER_3_ID))
.thenReturn(Optional.of(CONTAINER_3));
when(databaseRepository.save(any(Database.class)))
.thenReturn(DATABASE_3);
/* test */
generic_insert(QUERY_4_STATEMENT, 1L);
......@@ -167,10 +176,12 @@ public class DatabaseServiceIntegrationTest extends BaseUnitTest {
QueryMalformedException {
/* mock */
DockerConfig.createContainer(BIND_MUSICOLOGY, CONTAINER_3, CONTAINER_3_ENV);
DockerConfig.startContainer(CONTAINER_3);
DockerConfig.createContainer(BIND_MUSICOLOGY, CONTAINER_3_SIMPLE, CONTAINER_3_ENV);
DockerConfig.startContainer(CONTAINER_3_SIMPLE);
when(containerRepository.findById(CONTAINER_3_ID))
.thenReturn(Optional.of(CONTAINER_3));
when(databaseRepository.save(any(Database.class)))
.thenReturn(DATABASE_3);
/* test */
generic_insert(QUERY_4_STATEMENT, 1L);
......@@ -182,10 +193,12 @@ public class DatabaseServiceIntegrationTest extends BaseUnitTest {
public void create_systemProcedure_succeeds() throws SQLException, InterruptedException, QueryMalformedException {
/* mock */
DockerConfig.createContainer(BIND_MUSICOLOGY, CONTAINER_3, CONTAINER_3_ENV);
DockerConfig.startContainer(CONTAINER_3);
DockerConfig.createContainer(BIND_MUSICOLOGY, CONTAINER_3_SIMPLE, CONTAINER_3_ENV);
DockerConfig.startContainer(CONTAINER_3_SIMPLE);
when(containerRepository.findById(CONTAINER_3_ID))
.thenReturn(Optional.of(CONTAINER_3));
when(databaseRepository.save(any(Database.class)))
.thenReturn(DATABASE_3);
/* test */
generic_system_insert("root", "mariadb");
......@@ -195,10 +208,12 @@ public class DatabaseServiceIntegrationTest extends BaseUnitTest {
public void create_systemProcedure_fails() throws InterruptedException {
/* mock */
DockerConfig.createContainer(BIND_MUSICOLOGY, CONTAINER_3, CONTAINER_3_ENV);
DockerConfig.startContainer(CONTAINER_3);
DockerConfig.createContainer(BIND_MUSICOLOGY, CONTAINER_3_SIMPLE, CONTAINER_3_ENV);
DockerConfig.startContainer(CONTAINER_3_SIMPLE);
when(containerRepository.findById(CONTAINER_3_ID))
.thenReturn(Optional.of(CONTAINER_3));
when(databaseRepository.save(any(Database.class)))
.thenReturn(DATABASE_3);
/* test */
assertThrows(SQLException.class, () -> {
......@@ -210,10 +225,12 @@ public class DatabaseServiceIntegrationTest extends BaseUnitTest {
public void create_userProcedureRoot_succeeds() throws SQLException, InterruptedException, QueryMalformedException {
/* mock */
DockerConfig.createContainer(BIND_MUSICOLOGY, CONTAINER_3, CONTAINER_3_ENV);
DockerConfig.startContainer(CONTAINER_3);
DockerConfig.createContainer(BIND_MUSICOLOGY, CONTAINER_3_SIMPLE, CONTAINER_3_ENV);
DockerConfig.startContainer(CONTAINER_3_SIMPLE);
when(containerRepository.findById(CONTAINER_3_ID))
.thenReturn(Optional.of(CONTAINER_3));
when(databaseRepository.save(any(Database.class)))
.thenReturn(DATABASE_3);
/* test */
generic_user_insert("root", "mariadb");
......@@ -223,10 +240,12 @@ public class DatabaseServiceIntegrationTest extends BaseUnitTest {
public void create_userProcedureUser_succeeds() throws SQLException, InterruptedException, QueryMalformedException {
/* mock */
DockerConfig.createContainer(BIND_MUSICOLOGY, CONTAINER_3, CONTAINER_3_ENV);
DockerConfig.startContainer(CONTAINER_3);
DockerConfig.createContainer(BIND_MUSICOLOGY, CONTAINER_3_SIMPLE, CONTAINER_3_ENV);
DockerConfig.startContainer(CONTAINER_3_SIMPLE);
when(containerRepository.findById(CONTAINER_3_ID))
.thenReturn(Optional.of(CONTAINER_3));
when(databaseRepository.save(any(Database.class)))
.thenReturn(DATABASE_3);
/* test */
generic_user_insert("junit1", "junit1");
......
-- Modified for H2
-- Assume id=1 is invalid
-- Assume id=2 is still valid token
CREATE VIEW IF NOT EXISTS fda.mdb_invalid_tokens AS
(SELECT `id`, `token_hash`, `creator`, `created`, `expires`, `last_used` FROM fda.`mdb_tokens` WHERE `id` = 1);
\ No newline at end of file
......@@ -250,6 +250,20 @@ public abstract class BaseTest {
.emailVerified(USER_1_VERIFIED)
.enabled(USER_1_ENABLED)
.realmId(USER_1_REALM_ID)
.attributes(USER_1_ATTRIBUTES)
.build();
public final static User USER_1_SIMPLE = User.builder()
.id(USER_1_ID)
.username(USER_1_USERNAME)
.email(USER_1_EMAIL)
.databasePassword(USER_1_DATABASE_PASSWORD)
.firstname(USER_1_FIRSTNAME)
.lastname(USER_1_LASTNAME)
.emailVerified(USER_1_VERIFIED)
.enabled(USER_1_ENABLED)
.realmId(USER_1_REALM_ID)
.attributes(List.of() /* for jpa */)
.build();
public final static UserDto USER_1_DTO = UserDto.builder()
......@@ -354,6 +368,21 @@ public abstract class BaseTest {
.emailVerified(USER_2_VERIFIED)
.enabled(USER_2_ENABLED)
.realmId(USER_2_REALM_ID)
.attributes(USER_2_ATTRIBUTES)
.build();
public final static User USER_2_SIMPLE = User.builder()
.id(USER_2_ID)
.username(USER_2_USERNAME)
.email(USER_2_EMAIL)
.emailVerified(true)
.databasePassword(USER_2_DATABASE_PASSWORD)
.firstname(USER_2_FIRSTNAME)
.lastname(USER_2_LASTNAME)
.emailVerified(USER_2_VERIFIED)
.enabled(USER_2_ENABLED)
.realmId(USER_2_REALM_ID)
.attributes(List.of() /* for jpa */)
.build();
public final static UserDto USER_2_DTO = UserDto.builder()
......@@ -635,6 +664,21 @@ public abstract class BaseTest {
.dateFormats(List.of(IMAGE_DATE_1, IMAGE_DATE_2, IMAGE_DATE_3))
.build();
public final static ContainerImage IMAGE_1_SIMPLE = ContainerImage.builder()
.id(IMAGE_1_ID)
.repository(IMAGE_1_REPOSITORY)
.tag(IMAGE_1_TAG)
.hash(IMAGE_1_HASH)
.compiled(IMAGE_1_BUILT)
.dialect(IMAGE_1_DIALECT)
.jdbcMethod(IMAGE_1_JDBC)
.driverClass(IMAGE_1_DRIVER)
.size(IMAGE_1_SIZE)
.environment(List.of() /* for jpa */)
.defaultPort(IMAGE_1_PORT)
.environment(List.of() /* for jpa */)
.build();
public final static Long IMAGE_2_ID = 2L;
public final static String IMAGE_2_REPOSITORY = "mysql";
public final static String IMAGE_2_TAG = "8.0";
......@@ -717,6 +761,19 @@ public abstract class BaseTest {
.owner(USER_1)
.build();
public final static Container CONTAINER_1_SIMPLE = Container.builder()
.id(CONTAINER_1_ID)
.name(CONTAINER_1_NAME)
.internalName(CONTAINER_1_INTERNALNAME)
.imageId(IMAGE_1_ID)
.image(CONTAINER_1_IMAGE)
.hash(CONTAINER_1_HASH)
.created(CONTAINER_1_CREATED)
.ipAddress(CONTAINER_1_IP)
.creator(null /* for jpa */)
.owner(null /* for jpa */)
.build();
public final static Long CONTAINER_2_ID = 2L;
public final static String CONTAINER_2_HASH = "deadbeef";
public final static ContainerImage CONTAINER_2_IMAGE = IMAGE_1;
......@@ -741,6 +798,19 @@ public abstract class BaseTest {
.owner(USER_2)
.build();
public final static Container CONTAINER_2_SIMPLE = Container.builder()
.id(CONTAINER_2_ID)
.name(CONTAINER_2_NAME)
.internalName(CONTAINER_2_INTERNALNAME)
.imageId(IMAGE_1_ID)
.image(CONTAINER_2_IMAGE)
.hash(CONTAINER_2_HASH)
.created(CONTAINER_2_CREATED)
.ipAddress(CONTAINER_2_IP)
.creator(null /* for jpa */)
.owner(null /* for jpa */)
.build();
public final static Long CONTAINER_3_ID = 3L;
public final static String CONTAINER_3_HASH = "deadbeef";
public final static ContainerImage CONTAINER_3_IMAGE = IMAGE_1;
......@@ -765,6 +835,19 @@ public abstract class BaseTest {
.owner(USER_3)
.build();
public final static Container CONTAINER_3_SIMPLE = Container.builder()
.id(CONTAINER_3_ID)
.name(CONTAINER_3_NAME)
.internalName(CONTAINER_3_INTERNALNAME)
.imageId(IMAGE_1_ID)
.image(CONTAINER_3_IMAGE)
.hash(CONTAINER_3_HASH)
.created(CONTAINER_3_CREATED)
.ipAddress(CONTAINER_3_IP)
.creator(null /* for jpa */)
.owner(null /* for jpa */)
.build();
public final static Long CONTAINER_4_ID = 4L;
public final static String CONTAINER_4_HASH = "deadbeef";
public final static ContainerImage CONTAINER_4_IMAGE = IMAGE_1;
......@@ -861,6 +944,24 @@ public abstract class BaseTest {
.views(List.of())
.build();
public final static Database DATABASE_1_SIMPLE = Database.builder()
.id(DATABASE_1_ID)
.created(Instant.now().minus(1, HOURS))
.lastModified(Instant.now())
.isPublic(DATABASE_1_PUBLIC)
.name(DATABASE_1_NAME)
.description(DATABASE_1_DESCRIPTION)
.container(null /* for jpa */)
.internalName(DATABASE_1_INTERNALNAME)
.exchangeName(DATABASE_1_EXCHANGE)
.created(DATABASE_1_CREATED)
.lastModified(DATABASE_1_LAST_MODIFIED)
.creator(null /* for jpa */)
.owner(null /* for jpa */)
.tables(List.of() /* for jpa */)
.views(List.of() /* for jpa */)
.build();
public final static DatabaseDto DATABASE_1_DTO = DatabaseDto.builder()
.id(DATABASE_1_ID)
.created(Instant.now().minus(1, HOURS))
......@@ -960,6 +1061,24 @@ public abstract class BaseTest {
.views(List.of()) /* VIEW_4 */
.build();
public final static Database DATABASE_2_SIMPLE = Database.builder()
.id(DATABASE_2_ID)
.created(DATABASE_1_CREATED)
.lastModified(Instant.now())
.isPublic(DATABASE_2_PUBLIC)
.name(DATABASE_2_NAME)
.description(DATABASE_2_DESCRIPTION)
.container(null /* for jpa */)
.internalName(DATABASE_2_INTERNALNAME)
.exchangeName(DATABASE_2_EXCHANGE)
.created(DATABASE_2_CREATED)
.lastModified(DATABASE_2_LAST_MODIFIED)
.creator(null /* for jpa */)
.owner(null /* for jpa */)
.tables(List.of() /* for jpa */)
.views(List.of() /* for jpa */)
.build();
public final static DatabaseDto DATABASE_2_DTO = DatabaseDto.builder()
.id(DATABASE_2_ID)
.created(DATABASE_2_CREATED)
......@@ -1065,6 +1184,24 @@ public abstract class BaseTest {
.views(List.of()) /* VIEW_5 */
.build();
public final static Database DATABASE_3_SIMPLE = Database.builder()
.id(DATABASE_3_ID)
.created(Instant.now().minus(1, HOURS))
.lastModified(Instant.now())
.isPublic(DATABASE_3_PUBLIC)
.name(DATABASE_3_NAME)
.description(DATABASE_3_DESCRIPTION)
.container(null /* for jpa */)
.internalName(DATABASE_3_INTERNALNAME)
.exchangeName(DATABASE_3_EXCHANGE)
.created(DATABASE_3_CREATED)
.lastModified(DATABASE_3_LAST_MODIFIED)
.creator(null /* for jpa */)
.owner(null /* for jpa */)
.tables(List.of() /* for jpa */)
.views(List.of() /* for jpa */)
.build();
public final static DatabaseDto DATABASE_3_DTO = DatabaseDto.builder()
.id(DATABASE_3_ID)
.created(DATABASE_3_CREATED)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment