Skip to content
Snippets Groups Projects
Verified Commit e023834c authored by Martin Weise's avatar Martin Weise
Browse files

Fixed the tests after ~8h

parent c65150f0
No related branches found
No related tags found
2 merge requests!163Relase 1.3.0,!159Large update
Showing
with 20 additions and 97 deletions
...@@ -2,6 +2,7 @@ package at.tuwien.service; ...@@ -2,6 +2,7 @@ package at.tuwien.service;
import at.tuwien.BaseUnitTest; import at.tuwien.BaseUnitTest;
import at.tuwien.config.ReadyConfig; import at.tuwien.config.ReadyConfig;
import at.tuwien.exception.ImageNotFoundException;
import at.tuwien.repository.jpa.ImageRepository; import at.tuwien.repository.jpa.ImageRepository;
import at.tuwien.repository.jpa.UserRepository; import at.tuwien.repository.jpa.UserRepository;
import at.tuwien.service.impl.ImageServiceImpl; import at.tuwien.service.impl.ImageServiceImpl;
...@@ -46,8 +47,8 @@ public class PersistenceIntegrationTest extends BaseUnitTest { ...@@ -46,8 +47,8 @@ public class PersistenceIntegrationTest extends BaseUnitTest {
public void delete_notExists_fails() { public void delete_notExists_fails() {
/* test */ /* test */
assertThrows(UnexpectedRollbackException.class, () -> { assertThrows(ImageNotFoundException.class, () -> {
imageService.delete(IMAGE_2_ID); imageService.delete(9999L);
}); });
} }
......
...@@ -10,7 +10,7 @@ spring.cloud.config.enabled = false ...@@ -10,7 +10,7 @@ spring.cloud.config.enabled = false
# disable datasource # disable datasource
# spring 6 fix https://github.com/h2database/h2database/issues/3363 # spring 6 fix https://github.com/h2database/h2database/issues/3363
spring.datasource.url=jdbc:h2:mem:testdb;NON_KEYWORDS=VALUE;DB_CLOSE_ON_EXIT=FALSE;INIT=CREATE SCHEMA IF NOT EXISTS FDA spring.datasource.url=jdbc:h2:mem:testdb;NON_KEYWORDS=VALUE,KEY;DB_CLOSE_ON_EXIT=FALSE;INIT=CREATE SCHEMA IF NOT EXISTS FDA
spring.datasource.driverClassName=org.h2.Driver spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa spring.datasource.username=sa
spring.datasource.password=password spring.datasource.password=password
......
...@@ -126,6 +126,9 @@ public class ImageServiceImpl implements ImageService { ...@@ -126,6 +126,9 @@ public class ImageServiceImpl implements ImageService {
@Override @Override
@Transactional @Transactional
public void delete(Long imageId) throws ImageNotFoundException { public void delete(Long imageId) throws ImageNotFoundException {
if (!imageRepository.existsById(imageId)) {
throw new ImageNotFoundException("Image with id " + imageId + " not found");
}
try { try {
imageRepository.deleteById(imageId); imageRepository.deleteById(imageId);
log.info("Deleted image {}", imageId); log.info("Deleted image {}", imageId);
......
...@@ -27,6 +27,7 @@ import org.springframework.http.HttpStatus; ...@@ -27,6 +27,7 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.security.test.context.support.WithAnonymousUser; import org.springframework.security.test.context.support.WithAnonymousUser;
import org.springframework.security.test.context.support.WithMockUser; import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.junit.jupiter.SpringExtension;
import java.security.Principal; import java.security.Principal;
......
...@@ -2,6 +2,7 @@ package at.tuwien.endpoint; ...@@ -2,6 +2,7 @@ package at.tuwien.endpoint;
import at.tuwien.BaseUnitTest; import at.tuwien.BaseUnitTest;
import at.tuwien.api.database.*; import at.tuwien.api.database.*;
import at.tuwien.config.H2Utils;
import at.tuwien.config.IndexConfig; import at.tuwien.config.IndexConfig;
import at.tuwien.config.ReadyConfig; import at.tuwien.config.ReadyConfig;
import at.tuwien.endpoints.DatabaseEndpoint; import at.tuwien.endpoints.DatabaseEndpoint;
...@@ -27,6 +28,7 @@ import org.springframework.http.ResponseEntity; ...@@ -27,6 +28,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.security.authentication.AuthenticationCredentialsNotFoundException; import org.springframework.security.authentication.AuthenticationCredentialsNotFoundException;
import org.springframework.security.test.context.support.WithAnonymousUser; import org.springframework.security.test.context.support.WithAnonymousUser;
import org.springframework.security.test.context.support.WithMockUser; import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.junit.jupiter.SpringExtension;
import java.security.Principal; import java.security.Principal;
......
...@@ -16,6 +16,7 @@ import org.springframework.boot.test.context.SpringBootTest; ...@@ -16,6 +16,7 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.junit.jupiter.SpringExtension;
import java.util.List; import java.util.List;
......
...@@ -71,9 +71,6 @@ public class AccessServiceIntegrationTest extends BaseUnitTest { ...@@ -71,9 +71,6 @@ public class AccessServiceIntegrationTest extends BaseUnitTest {
@Autowired @Autowired
private RealmRepository realmRepository; private RealmRepository realmRepository;
@Autowired
private H2Utils h2Utils;
private final static String BIND_WEATHER = new File("../../dbrepo-metadata-db/test/src/test/resources/weather").toPath().toAbsolutePath() + ":/docker-entrypoint-initdb.d"; private final static String BIND_WEATHER = new File("../../dbrepo-metadata-db/test/src/test/resources/weather").toPath().toAbsolutePath() + ":/docker-entrypoint-initdb.d";
@BeforeAll @BeforeAll
...@@ -93,7 +90,6 @@ public class AccessServiceIntegrationTest extends BaseUnitTest { ...@@ -93,7 +90,6 @@ public class AccessServiceIntegrationTest extends BaseUnitTest {
afterEach(); afterEach();
DockerConfig.createAllNetworks(); DockerConfig.createAllNetworks();
/* metadata database */ /* metadata database */
h2Utils.runScript("schema.sql");
realmRepository.save(REALM_DBREPO); realmRepository.save(REALM_DBREPO);
imageRepository.save(IMAGE_1); imageRepository.save(IMAGE_1);
userRepository.save(USER_1_SIMPLE); userRepository.save(USER_1_SIMPLE);
......
...@@ -78,8 +78,6 @@ public class DatabaseServiceComponentTest extends BaseUnitTest { ...@@ -78,8 +78,6 @@ public class DatabaseServiceComponentTest extends BaseUnitTest {
@BeforeEach @BeforeEach
public void beforeEach() { public void beforeEach() {
afterEach(); afterEach();
/* metadata database */
h2Utils.runScript("schema.sql");
} }
@AfterEach @AfterEach
......
...@@ -10,7 +10,7 @@ spring.cloud.config.enabled=false ...@@ -10,7 +10,7 @@ spring.cloud.config.enabled=false
# disable datasource # disable datasource
# spring 6 fix https://github.com/h2database/h2database/issues/3363 # spring 6 fix https://github.com/h2database/h2database/issues/3363
spring.datasource.url=jdbc:h2:mem:testdb;NON_KEYWORDS=VALUE;DB_CLOSE_ON_EXIT=FALSE;INIT=CREATE SCHEMA IF NOT EXISTS FDA spring.datasource.url=jdbc:h2:mem:testdb;NON_KEYWORDS=VALUE,KEY;DB_CLOSE_ON_EXIT=FALSE;INIT=CREATE SCHEMA IF NOT EXISTS FDA
spring.datasource.driverClassName=org.h2.Driver spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa spring.datasource.username=sa
spring.datasource.password=password spring.datasource.password=password
......
CREATE SCHEMA IF NOT EXISTS `fda`;
SET SCHEMA `fda`;
DROP TABLE IF EXISTS fda.mdb_concepts;
CREATE TABLE IF NOT EXISTS fda.mdb_concepts
(
uri VARCHAR(500) not null,
name VARCHAR(255),
created timestamp NOT NULL DEFAULT NOW(),
created_by bigint,
PRIMARY KEY (uri)
);
DROP TABLE IF EXISTS fda.mdb_units;
CREATE TABLE IF NOT EXISTS fda.mdb_units
(
uri VARCHAR(500) not null,
name VARCHAR(255),
created timestamp NOT NULL DEFAULT NOW(),
created_by bigint,
PRIMARY KEY (uri)
);
-- 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
...@@ -104,7 +104,7 @@ public class TableColumn implements Comparable<TableColumn> { ...@@ -104,7 +104,7 @@ public class TableColumn implements Comparable<TableColumn> {
@CreatedDate @CreatedDate
private Instant created; private Instant created;
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.MERGE) @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
@JoinTable(name = "mdb_columns_concepts", @JoinTable(name = "mdb_columns_concepts",
joinColumns = { joinColumns = {
@JoinColumn(name = "cid", referencedColumnName = "id", insertable = false, updatable = false), @JoinColumn(name = "cid", referencedColumnName = "id", insertable = false, updatable = false),
...@@ -114,7 +114,7 @@ public class TableColumn implements Comparable<TableColumn> { ...@@ -114,7 +114,7 @@ public class TableColumn implements Comparable<TableColumn> {
inverseJoinColumns = @JoinColumn(name = "uri", referencedColumnName = "uri")) inverseJoinColumns = @JoinColumn(name = "uri", referencedColumnName = "uri"))
private TableColumnConcept concept; private TableColumnConcept concept;
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.MERGE) @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
@JoinTable(name = "mdb_columns_units", @JoinTable(name = "mdb_columns_units",
joinColumns = { joinColumns = {
@JoinColumn(name = "cid", referencedColumnName = "id", insertable = false, updatable = false), @JoinColumn(name = "cid", referencedColumnName = "id", insertable = false, updatable = false),
......
package at.tuwien.entities.database.table.columns; package at.tuwien.entities.database.table.columns;
import lombok.*; import lombok.*;
import org.hibernate.annotations.JdbcTypeCode;
import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener; import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import jakarta.persistence.*;; import jakarta.persistence.*;;
import java.net.URI;
import java.sql.Types;
import java.time.Instant; import java.time.Instant;
import java.util.List; import java.util.List;
......
package at.tuwien.entities.database.table.columns; package at.tuwien.entities.database.table.columns;
import lombok.*; import lombok.*;
import org.hibernate.annotations.JdbcTypeCode;
import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener; import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import jakarta.persistence.*;; import jakarta.persistence.*;;
import java.net.URI;
import java.sql.Types;
import java.time.Instant; import java.time.Instant;
import java.util.List; import java.util.List;
...@@ -27,18 +30,6 @@ public class TableColumnUnit { ...@@ -27,18 +30,6 @@ public class TableColumnUnit {
@Column(name = "name", nullable = false) @Column(name = "name", nullable = false)
private String name; private String name;
@org.springframework.data.annotation.Transient
@ToString.Exclude
@OneToMany(fetch = FetchType.LAZY)
@JoinTable(name = "mdb_columns_units",
joinColumns = @JoinColumn(name = "uri", referencedColumnName = "uri", insertable = false, updatable = false),
inverseJoinColumns = {
@JoinColumn(name = "cid", referencedColumnName = "id", insertable = false, updatable = false),
@JoinColumn(name = "tid", referencedColumnName = "tid", insertable = false, updatable = false),
@JoinColumn(name = "cdbid", referencedColumnName = "cdbid", insertable = false, updatable = false)
})
private List<TableColumn> columns;
@Column(nullable = false, updatable = false, columnDefinition = "TIMESTAMP") @Column(nullable = false, updatable = false, columnDefinition = "TIMESTAMP")
@CreatedDate @CreatedDate
private Instant created; private Instant created;
......
...@@ -34,15 +34,6 @@ public class MetadataEndpointUnitTest extends BaseUnitTest { ...@@ -34,15 +34,6 @@ public class MetadataEndpointUnitTest extends BaseUnitTest {
@Autowired @Autowired
private MetadataEndpoint metadataEndpoint; private MetadataEndpoint metadataEndpoint;
@Autowired
private H2Utils h2Utils;
@BeforeEach
public void beforeEach() {
/* schema */
h2Utils.runScript("schema.sql");
}
@Test @Test
@WithAnonymousUser @WithAnonymousUser
public void identify_succeeds() { public void identify_succeeds() {
......
...@@ -46,13 +46,8 @@ public class IdentifierServiceIntegrationTest extends BaseUnitTest { ...@@ -46,13 +46,8 @@ public class IdentifierServiceIntegrationTest extends BaseUnitTest {
@Autowired @Autowired
private IdentifierService identifierService; private IdentifierService identifierService;
@Autowired
private H2Utils h2Utils;
@BeforeEach @BeforeEach
public void beforeEach() { public void beforeEach() {
/* schema */
h2Utils.runScript("schema.sql");
/* metadata database */ /* metadata database */
imageRepository.save(IMAGE_1_SIMPLE); imageRepository.save(IMAGE_1_SIMPLE);
realmRepository.save(REALM_DBREPO); realmRepository.save(REALM_DBREPO);
......
...@@ -45,13 +45,8 @@ public class MetadataServiceIntegrationTest extends BaseUnitTest { ...@@ -45,13 +45,8 @@ public class MetadataServiceIntegrationTest extends BaseUnitTest {
@Autowired @Autowired
private MetadataService metadataService; private MetadataService metadataService;
@Autowired
private H2Utils h2Utils;
@BeforeEach @BeforeEach
public void beforeEach() { public void beforeEach() {
/* schema */
h2Utils.runScript("schema.sql");
/* metadata database */ /* metadata database */
imageRepository.save(IMAGE_1_SIMPLE); imageRepository.save(IMAGE_1_SIMPLE);
realmRepository.save(REALM_DBREPO); realmRepository.save(REALM_DBREPO);
......
CREATE SCHEMA IF NOT EXISTS `fda`;
SET SCHEMA `fda`;
DROP TABLE IF EXISTS fda.mdb_concepts;
CREATE TABLE IF NOT EXISTS fda.mdb_concepts
(
uri VARCHAR(500) not null,
name VARCHAR(255),
created timestamp NOT NULL DEFAULT NOW(),
created_by bigint,
PRIMARY KEY (uri)
);
DROP TABLE IF EXISTS fda.mdb_units;
CREATE TABLE IF NOT EXISTS fda.mdb_units
(
uri VARCHAR(500) not null,
name VARCHAR(255),
created timestamp NOT NULL DEFAULT NOW(),
created_by bigint,
PRIMARY KEY (uri)
);
-- 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
...@@ -90,7 +90,6 @@ public class RabbitMqListenerIntegrationTest extends BaseUnitTest { ...@@ -90,7 +90,6 @@ public class RabbitMqListenerIntegrationTest extends BaseUnitTest {
@BeforeEach @BeforeEach
public void beforeEach() { public void beforeEach() {
/* metadata database */ /* metadata database */
h2Utils.runScript("schema.sql");
imageRepository.save(IMAGE_1_SIMPLE); imageRepository.save(IMAGE_1_SIMPLE);
realmRepository.save(REALM_DBREPO); realmRepository.save(REALM_DBREPO);
userRepository.save(USER_1_SIMPLE); userRepository.save(USER_1_SIMPLE);
......
...@@ -71,7 +71,6 @@ public class ViewRepositoryIntegrationTest extends BaseUnitTest { ...@@ -71,7 +71,6 @@ public class ViewRepositoryIntegrationTest extends BaseUnitTest {
@BeforeEach @BeforeEach
public void beforeEach() { public void beforeEach() {
h2Utils.runScript("schema.sql");
userRepository.save(USER_1); userRepository.save(USER_1);
imageRepository.save(IMAGE_1); imageRepository.save(IMAGE_1);
containerRepository.save(CONTAINER_1); containerRepository.save(CONTAINER_1);
......
...@@ -100,8 +100,6 @@ public class TableServiceIntegrationReadTest extends BaseUnitTest { ...@@ -100,8 +100,6 @@ public class TableServiceIntegrationReadTest extends BaseUnitTest {
@BeforeEach @BeforeEach
public void beforeEach() { public void beforeEach() {
/* metadata db */
h2Utils.runScript("schema.sql");
/* metadata db */ /* metadata db */
imageRepository.save(IMAGE_1); imageRepository.save(IMAGE_1);
realmRepository.save(REALM_DBREPO); realmRepository.save(REALM_DBREPO);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment