Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testcontainer #6988

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 0 additions & 84 deletions .oracle/oracle-init/fpsak.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,56 +28,6 @@ BEGIN
END;
/

DECLARE
userexists INTEGER;
BEGIN
SELECT count(*)
INTO userexists
FROM SYS.ALL_USERS
WHERE USERNAME = 'FPSAK_UNIT';
IF (userexists = 0)
THEN
EXECUTE IMMEDIATE ('CREATE USER FPSAK_UNIT IDENTIFIED BY fpsak_unit PROFILE DEFAULT ACCOUNT UNLOCK');
END IF;
END;
/

DECLARE
userexists INTEGER;
BEGIN
SELECT count(*)
INTO userexists
FROM SYS.ALL_USERS
WHERE USERNAME = 'FPSAK_HIST_UNIT';
IF (userexists = 0)
THEN
EXECUTE IMMEDIATE ('CREATE USER FPSAK_HIST_UNIT IDENTIFIED BY fpsak_hist_unit PROFILE DEFAULT ACCOUNT UNLOCK');
END IF;
END;
/

DECLARE
userexists INTEGER;
BEGIN
SELECT count(*)
INTO userexists
FROM SYS.ALL_USERS
WHERE USERNAME = 'VL_DBA';
IF (userexists = 0)
THEN
EXECUTE IMMEDIATE ('CREATE USER VL_DBA IDENTIFIED BY vl_dba PROFILE DEFAULT ACCOUNT UNLOCK');
END IF;
END;
/

-- 1 Role for vl_dba
GRANT DBA TO VL_DBA;
ALTER USER VL_DBA DEFAULT ROLE ALL;

-- 2 System Privileges for vl_dba
GRANT CREATE SESSION TO VL_DBA;
GRANT UNLIMITED TABLESPACE TO VL_DBA;

GRANT
CREATE SESSION,
ALTER SESSION,
Expand Down Expand Up @@ -108,36 +58,6 @@ GRANT
SELECT ANY TABLE
TO FPSAK_HIST;

GRANT
CREATE SESSION,
ALTER SESSION,
CONNECT,
RESOURCE,
CREATE MATERIALIZED VIEW,
CREATE JOB,
CREATE TABLE,
CREATE SYNONYM,
CREATE VIEW,
CREATE SEQUENCE,
UNLIMITED TABLESPACE,
SELECT ANY TABLE
TO FPSAK_UNIT;

GRANT
CREATE SESSION,
ALTER SESSION,
CONNECT,
RESOURCE,
CREATE MATERIALIZED VIEW,
CREATE JOB,
CREATE TABLE,
CREATE SYNONYM,
CREATE VIEW,
CREATE SEQUENCE,
UNLIMITED TABLESPACE,
SELECT ANY TABLE
TO FPSAK_HIST_UNIT;

-- Ikke endre rollenavn, den er referert i migreringsskriptene og skal finnes i alle miljøer inkl prod
DECLARE roleexists INTEGER;
BEGIN
Expand Down Expand Up @@ -167,10 +87,6 @@ END;
/

GRANT FPSAK_HIST_SKRIVE_ROLE TO FPSAK;
GRANT FPSAK_HIST_SKRIVE_ROLE TO FPSAK_UNIT;

ALTER USER FPSAK QUOTA UNLIMITED ON SYSTEM;
ALTER USER FPSAK_UNIT QUOTA UNLIMITED ON SYSTEM;

ALTER USER FPSAK_HIST QUOTA UNLIMITED ON SYSTEM;
ALTER USER FPSAK_HIST_UNIT QUOTA UNLIMITED ON SYSTEM;
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,21 @@

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

import no.nav.foreldrepenger.dbstoette.Databaseskjemainitialisering;
import no.nav.foreldrepenger.dbstoette.JpaExtension;

/**
* Sjekker alle entiteter er mappet korrekt. Ligger i web slik at den fanger
* alle orm filer lagt i ulike moduler.
*/
@ExtendWith(JpaExtension.class)
class EntityTest {

private static final EntityManagerFactory entityManagerFactory;
static {
// Kan ikke skrus på nå - trigger på CHAR kolonner som kunne vært VARCHAR. Må
// fikses først
// System.setProperty("hibernate.hbm2ddl.auto", "validate");
try {
// trenger å konfigurere opp jndi etc.
Databaseskjemainitialisering.settJdniOppslag();
} catch (Exception e) {
throw new ExceptionInInitializerError(e);
}
entityManagerFactory = Persistence.createEntityManagerFactory("pu-default");
}

Expand Down Expand Up @@ -103,7 +96,7 @@ public void skal_ha_registrert_alle_entiteter_i_orm_xml(Class<?> entityClass) {
}
}

@Disabled("Venter til etter migrering av aliased tables")
//@Disabled("Venter til etter migrering av aliased tables")
@ParameterizedTest
@MethodSource("parameters")
public void sjekk_felt_mapping_primitive_felt_i_entiteter_må_ha_not_nullable_i_db(Class<?> entityClass) throws Exception {
Expand Down Expand Up @@ -134,6 +127,7 @@ public void skal_ha_registrert_alle_entiteter_i_orm_xml(Class<?> entityClass) {
}
}

// TODO: Slå på og gjennomgå resultatene
@Disabled("Venter til etter migrering av aliased tables")
@ParameterizedTest
@MethodSource("parameters")
Expand Down Expand Up @@ -184,7 +178,7 @@ private String getNullability(String tableName, String columnName) {
.setParameter("col", columnName)
.getResultList();

return result.isEmpty() ? null : result.get(0);
return result.isEmpty() ? null : String.valueOf(result.get(0));
}

private String getTableName(Class<?> entityClass, Field field) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,20 @@
import jakarta.persistence.Persistence;
import jakarta.persistence.metamodel.Type;

import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

import no.nav.foreldrepenger.behandlingslager.diff.IndexKey;
import no.nav.foreldrepenger.dbstoette.Databaseskjemainitialisering;
import no.nav.foreldrepenger.dbstoette.JpaExtension;

/** Lagt til web for å sjekke orm filer fra alle moduler. */
@ExtendWith(JpaExtension.class)
class SjekkCollectionsOrderedIEntiteterTest {

private static final EntityManagerFactory entityManagerFactory;

static {
try {
Databaseskjemainitialisering.settJdniOppslag();
} catch (Exception e) {
throw new ExceptionInInitializerError(e);
}
entityManagerFactory = Persistence.createEntityManagerFactory("pu-default");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.PrePersist;
import jakarta.persistence.SequenceGenerator;
import jakarta.persistence.Table;

import org.hibernate.annotations.NaturalId;

@Entity(name = "BehandlingDvh")
@Table(name = "BEHANDLING_DVH")
@Table(name = "BEHANDLING_DVH", schema = "FPSAK_HIST")
public class BehandlingDvh implements Serializable {

private static final String PAPIR_SØKNAD = "1";
Expand Down
33 changes: 0 additions & 33 deletions migreringer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,37 +61,4 @@
</plugins>
</build>

<profiles>
<profile>
<id>migrerDb</id>
<activation>
<property>
<name>!skipTests</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>migrering</id>
<phase>test-compile</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>no.nav.foreldrepenger.dbstoette.Databaseskjemainitialisering</mainClass>
<classpathScope>test</classpathScope>
<cleanupDaemonThreads>false</cleanupDaemonThreads>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
89 changes: 89 additions & 0 deletions migreringer/src/main/resources/db/fpsak.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
ALTER SESSION SET CONTAINER=FREEPDB1;

DECLARE
userexists INTEGER;
BEGIN
SELECT count(*)
INTO userexists
FROM SYS.ALL_USERS
WHERE USERNAME = 'FPSAK';
IF (userexists = 0)
THEN
EXECUTE IMMEDIATE ('CREATE USER FPSAK IDENTIFIED BY fpsak PROFILE DEFAULT ACCOUNT UNLOCK');
END IF;
END;


DECLARE
userexists INTEGER;
BEGIN
SELECT count(*)
INTO userexists
FROM SYS.ALL_USERS
WHERE USERNAME = 'FPSAK_HIST';
IF (userexists = 0)
THEN
EXECUTE IMMEDIATE ('CREATE USER FPSAK_HIST IDENTIFIED BY fpsak_hist PROFILE DEFAULT ACCOUNT UNLOCK');
END IF;
END;

GRANT
CREATE SESSION,
ALTER SESSION,
CONNECT,
RESOURCE,
CREATE MATERIALIZED VIEW,
CREATE JOB,
CREATE TABLE,
CREATE SYNONYM,
CREATE VIEW,
CREATE SEQUENCE,
UNLIMITED TABLESPACE,
SELECT ANY TABLE
TO FPSAK;

GRANT
CREATE SESSION,
ALTER SESSION,
CONNECT,
RESOURCE,
CREATE MATERIALIZED VIEW,
CREATE JOB,
CREATE TABLE,
CREATE SYNONYM,
CREATE VIEW,
CREATE SEQUENCE,
UNLIMITED TABLESPACE,
SELECT ANY TABLE
TO FPSAK_HIST;

-- Ikke endre rollenavn, den er referert i migreringsskriptene og skal finnes i alle miljøer inkl prod
DECLARE roleexists INTEGER;
BEGIN
SELECT count(*)
INTO roleexists
FROM SYS.DBA_ROLES
WHERE ROLE = 'FPSAK_HIST_SKRIVE_ROLE';
IF (roleexists = 0)
THEN
EXECUTE IMMEDIATE ('CREATE ROLE FPSAK_HIST_SKRIVE_ROLE');
END IF;
END;

-- Ikke endre rollenavn, den er referert i migreringsskriptene og skal finnes i alle miljøer inkl prod
DECLARE roleexists INTEGER;
BEGIN
SELECT count(*)
INTO roleexists
FROM SYS.DBA_ROLES
WHERE ROLE = 'FPSAK_HIST_LESE_ROLE';
IF (roleexists = 0)
THEN
EXECUTE IMMEDIATE ('CREATE ROLE FPSAK_HIST_LESE_ROLE');
END IF;
END;

GRANT FPSAK_HIST_SKRIVE_ROLE TO FPSAK;

ALTER USER FPSAK QUOTA UNLIMITED ON SYSTEM;
ALTER USER FPSAK_HIST QUOTA UNLIMITED ON SYSTEM;
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.testcontainers.oracle.OracleContainer;
import org.testcontainers.utility.DockerImageName;
import org.testcontainers.utility.MountableFile;

import no.nav.foreldrepenger.dbstoette.Databaseskjemainitialisering;
import no.nav.foreldrepenger.dbstoette.TestDatabaseInit;

/**
* Tester at alle migreringer følger standarder for navn og god praksis.
Expand All @@ -29,9 +32,12 @@ class SjekkDbStrukturTest {

@BeforeAll
public static void setup() {
Databaseskjemainitialisering.migrerUnittestSkjemaer();
ds = Databaseskjemainitialisering.initUnitTestDataSource();
schema = Databaseskjemainitialisering.DEFAULTDS_USER;
schema = TestDatabaseInit.DEFAULT_DS_SCHEMA;
var testDatabase = new OracleContainer(DockerImageName.parse(TestDatabaseInit.TEST_DB_CONTAINER))
.withCopyFileToContainer(MountableFile.forHostPath(TestDatabaseInit.DB_SETUP_SCRIPT_PATH), "/docker-entrypoint-initdb.d/init.sql")
.withReuse(true);
testDatabase.start();
ds = TestDatabaseInit.settOppDatasourceOgMigrer(testDatabase.getJdbcUrl(), "fpsak", "fpsak", schema);
}

@Test
Expand All @@ -48,7 +54,8 @@ void sjekk_at_alle_tabeller_er_dokumentert() throws Exception {
try (var conn = ds.getConnection(); var stmt = conn.prepareStatement(sql); var rs = stmt.executeQuery()) {

while (rs.next()) {
avvik.add(rs.getString(1));
if (!"flyway_schema_history".equals(rs.getString(1)))
avvik.add(rs.getString(1));
}

}
Expand Down Expand Up @@ -81,7 +88,8 @@ AND upper(t.column_name) NOT IN ('OPPRETTET_TID','ENDRET_TID','OPPRETTET_AV','EN
try (var conn = ds.getConnection(); var stmt = conn.prepareStatement(sql); var rs = stmt.executeQuery()) {

while (rs.next()) {
avvik.add("\n" + rs.getString(1));
if (!rs.getString(1).startsWith("flyway_schema_history"))
avvik.add("\n" + rs.getString(1));
}

}
Expand Down
Loading
Loading