test legacy-id-triggers (#149)
Co-authored-by: Michael Hoennig <michael@hoennig.de> Reviewed-on: #149 Reviewed-by: Marc Sandlus <marc.sandlus@hostsharing.net>
This commit is contained in:
parent
c1d3d583e7
commit
9d251f88e9
23
.aliases
23
.aliases
@ -104,21 +104,32 @@ alias gw-check='. .aliases; . .tc-environment; gw test check -x pitest'
|
||||
# You can also re-run all these tests, which will take ~20min: `gw-test --all --rerun`
|
||||
# This will always use the environment from `.tc-environment`.
|
||||
#
|
||||
function _gwTest1() {
|
||||
echo
|
||||
printf -- '=%0.s' {1..80}; echo
|
||||
echo "RUNNING gw $@"
|
||||
printf -- '-%0.s' {1..80}; echo
|
||||
./gradlew "$@"
|
||||
printf -- '-%0.s' {1..80}; echo
|
||||
echo "DONE gw $@"
|
||||
}
|
||||
function _gwTest() {
|
||||
. .aliases;
|
||||
. .tc-environment;
|
||||
rm /tmp/gwTest.tmp
|
||||
if [ "$1" == "--all" ]; then
|
||||
shift # to remove the --all from $@
|
||||
# delierately in separate gradlew-calls to avoid Testcontains-PostgreSQL problem spillover
|
||||
./gradlew unitTest "$@" &&
|
||||
./gradlew officeIntegrationTest bookingIntegrationTest hostingIntegrationTest "$@" &&
|
||||
./gradlew scenarioTest "$@" &&
|
||||
./gradlew importOfficeData importHostingAssets "$@";
|
||||
time (_gwTest1 unitTest "$@" &&
|
||||
_gwTest1 officeIntegrationTest bookingIntegrationTest hostingIntegrationTest "$@" &&
|
||||
_gwTest1 scenarioTest "$@" &&
|
||||
_gwTest1 importOfficeData importHostingAssets "$@");
|
||||
elif [ $# -eq 0 ] || [[ $1 == -* ]]; then
|
||||
./gradlew test "$@";
|
||||
time _gwTest1 test "$@";
|
||||
else
|
||||
./gradlew "$@";
|
||||
time _gwTest1 "$@";
|
||||
fi
|
||||
printf -- '=%0.s' {1..80}; echo
|
||||
}
|
||||
alias gw-test=_gwTest
|
||||
|
||||
|
@ -4,13 +4,13 @@
|
||||
-- Once we don't need the external remote views anymore, create revert changesets.
|
||||
|
||||
-- ============================================================================
|
||||
--changeset michael.hoennig:hs-office-contact-MIGRATION-mapping endDelimiter:--//
|
||||
--changeset michael.hoennig:hs-office-contact-MIGRATION-legacy-mapping endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
CREATE TABLE hs_office.contact_legacy_id
|
||||
(
|
||||
uuid uuid NOT NULL REFERENCES hs_office.contact(uuid),
|
||||
contact_id integer NOT NULL
|
||||
uuid uuid PRIMARY KEY NOT NULL REFERENCES hs_office.contact(uuid),
|
||||
contact_id integer UNIQUE NOT NULL
|
||||
);
|
||||
--//
|
||||
|
||||
|
@ -4,13 +4,13 @@
|
||||
-- Once we don't need the external remote views anymore, create revert changesets.
|
||||
|
||||
-- ============================================================================
|
||||
--changeset michael.hoennig:hs-office-partner-MIGRATION-mapping endDelimiter:--//
|
||||
--changeset michael.hoennig:hs-office-partner-MIGRATION-legacy-mapping endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
CREATE TABLE hs_office.partner_legacy_id
|
||||
(
|
||||
uuid uuid NOT NULL REFERENCES hs_office.partner(uuid),
|
||||
bp_id integer NOT NULL
|
||||
uuid uuid PRIMARY KEY NOT NULL REFERENCES hs_office.partner(uuid),
|
||||
bp_id integer UNIQUE NOT NULL
|
||||
);
|
||||
--//
|
||||
|
||||
|
@ -4,13 +4,13 @@
|
||||
-- Once we don't need the external remote views anymore, create revert changesets.
|
||||
|
||||
-- ============================================================================
|
||||
--changeset michael.hoennig:hs-office-sepamandate-MIGRATION-mapping endDelimiter:--//
|
||||
--changeset michael.hoennig:hs-office-sepamandate-MIGRATION-legacy-mapping endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
CREATE TABLE hs_office.sepamandate_legacy_id
|
||||
(
|
||||
uuid uuid NOT NULL REFERENCES hs_office.sepamandate(uuid),
|
||||
sepa_mandate_id integer NOT NULL
|
||||
uuid uuid PRIMARY KEY NOT NULL REFERENCES hs_office.sepamandate(uuid),
|
||||
sepa_mandate_id integer UNIQUE NOT NULL
|
||||
);
|
||||
--//
|
||||
|
||||
|
@ -4,13 +4,13 @@
|
||||
-- Once we don't need the external remote views anymore, create revert changesets.
|
||||
|
||||
-- ============================================================================
|
||||
--changeset michael.hoennig:hs-office-coopshares-MIGRATION-mapping endDelimiter:--//
|
||||
--changeset michael.hoennig:hs-office-coopshares-MIGRATION-legacy-mapping endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
CREATE TABLE hs_office.coopsharetx_legacy_id
|
||||
(
|
||||
uuid uuid NOT NULL REFERENCES hs_office.coopsharetx(uuid),
|
||||
member_share_id integer NOT NULL
|
||||
uuid uuid PRIMARY KEY NOT NULL REFERENCES hs_office.coopsharetx(uuid),
|
||||
member_share_id integer UNIQUE NOT NULL
|
||||
);
|
||||
--//
|
||||
|
||||
|
@ -4,13 +4,13 @@
|
||||
-- Once we don't need the external remote views anymore, create revert changesets.
|
||||
|
||||
-- ============================================================================
|
||||
--changeset michael.hoennig:hs-office-coopassets-MIGRATION-mapping endDelimiter:--//
|
||||
--changeset michael.hoennig:hs-office-coopassets-MIGRATION-legacy-mapping endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
CREATE TABLE hs_office.coopassettx_legacy_id
|
||||
(
|
||||
uuid uuid NOT NULL REFERENCES hs_office.coopassettx(uuid),
|
||||
member_asset_id integer NOT NULL
|
||||
uuid uuid PRIMARY KEY NOT NULL REFERENCES hs_office.coopassettx(uuid),
|
||||
member_asset_id integer UNIQUE NOT NULL
|
||||
);
|
||||
--//
|
||||
|
||||
|
@ -4,13 +4,13 @@
|
||||
-- Once we don't need the external remote views anymore, create revert changesets.
|
||||
|
||||
-- ============================================================================
|
||||
--changeset hs-hosting-asset-MIGRATION-mapping:1 endDelimiter:--//
|
||||
--changeset hs-hosting-asset-MIGRATION-legacy-mapping:1 endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
CREATE TABLE hs_hosting.asset_legacy_id
|
||||
(
|
||||
uuid uuid NOT NULL REFERENCES hs_hosting.asset(uuid),
|
||||
legacy_id integer NOT NULL
|
||||
uuid uuid PRIMARY KEY NOT NULL REFERENCES hs_hosting.asset(uuid),
|
||||
legacy_id integer NOT NULL -- not unique because we sometimes create multiple asset types for the same legacy asset
|
||||
);
|
||||
--//
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
package net.hostsharing.hsadminng.hs.office.contact;
|
||||
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
|
||||
import net.hostsharing.hsadminng.mapper.Array;
|
||||
import net.hostsharing.hsadminng.rbac.grant.RawRbacGrantRepository;
|
||||
import net.hostsharing.hsadminng.rbac.role.RawRbacRoleRepository;
|
||||
import net.hostsharing.hsadminng.mapper.Array;
|
||||
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
|
||||
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
@ -12,8 +12,8 @@ import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
|
||||
import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
@ -29,7 +29,7 @@ import static net.hostsharing.hsadminng.rbac.test.JpaAttempt.attempt;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@DataJpaTest
|
||||
@Import( { Context.class, JpaAttempt.class })
|
||||
@Import({ Context.class, JpaAttempt.class })
|
||||
@Tag("officeIntegrationTest")
|
||||
class HsOfficeContactRbacRepositoryIntegrationTest extends ContextBasedTestWithCleanup {
|
||||
|
||||
@ -62,8 +62,9 @@ class HsOfficeContactRbacRepositoryIntegrationTest extends ContextBasedTestWithC
|
||||
|
||||
// when
|
||||
|
||||
final var result = attempt(em, () -> toCleanup(contactRepo.save(
|
||||
hsOfficeContact("a new contact", "contact-admin@www.example.com"))));
|
||||
final var result = attempt(
|
||||
em, () -> toCleanup(contactRepo.save(
|
||||
hsOfficeContact("a new contact", "contact-admin@www.example.com"))));
|
||||
|
||||
// then
|
||||
result.assertSuccessful();
|
||||
@ -79,14 +80,16 @@ class HsOfficeContactRbacRepositoryIntegrationTest extends ContextBasedTestWithC
|
||||
final var count = contactRepo.count();
|
||||
|
||||
// when
|
||||
final var result = attempt(em, () -> toCleanup(contactRepo.save(
|
||||
hsOfficeContact("another new contact", "another-new-contact@example.com"))));
|
||||
final var result = attempt(
|
||||
em, () -> toCleanup(contactRepo.save(
|
||||
hsOfficeContact("another new contact", "another-new-contact@example.com"))));
|
||||
|
||||
// then
|
||||
result.assertSuccessful();
|
||||
assertThat(result.returnedValue()).isNotNull().extracting(HsOfficeContactRbacEntity::getUuid).isNotNull();
|
||||
assertThatContactIsPersisted(result.returnedValue());
|
||||
assertThat(contactRepo.count()).isEqualTo(count + 1);
|
||||
assertHasLegacyId(result.returnedValue(), "contact_id");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -97,8 +100,9 @@ class HsOfficeContactRbacRepositoryIntegrationTest extends ContextBasedTestWithC
|
||||
final var initialGrantNames = distinctGrantDisplaysOf(rawGrantRepo.findAll());
|
||||
|
||||
// when
|
||||
attempt(em, () -> toCleanup(contactRepo.save(
|
||||
hsOfficeContact("another new contact", "another-new-contact@example.com")))
|
||||
attempt(
|
||||
em, () -> toCleanup(contactRepo.save(
|
||||
hsOfficeContact("another new contact", "another-new-contact@example.com")))
|
||||
).assumeSuccessful();
|
||||
|
||||
// then
|
||||
@ -300,10 +304,11 @@ class HsOfficeContactRbacRepositoryIntegrationTest extends ContextBasedTestWithC
|
||||
|
||||
private HsOfficeContactRbacEntity givenSomeTemporaryContact(final String createdByUser) {
|
||||
final var random = RandomStringUtils.randomAlphabetic(12);
|
||||
return givenSomeTemporaryContact(createdByUser, () ->
|
||||
hsOfficeContact(
|
||||
"some temporary contact #" + random,
|
||||
"some-temporary-contact" + random + "@example.com"));
|
||||
return givenSomeTemporaryContact(
|
||||
createdByUser, () ->
|
||||
hsOfficeContact(
|
||||
"some temporary contact #" + random,
|
||||
"some-temporary-contact" + random + "@example.com"));
|
||||
}
|
||||
|
||||
void exactlyTheseContactsAreReturned(final List<HsOfficeContactRbacEntity> actualResult, final String... contactCaptions) {
|
||||
|
@ -83,6 +83,7 @@ class HsOfficeCoopAssetsTransactionRepositoryIntegrationTest extends ContextBase
|
||||
assertThat(result.returnedValue()).isNotNull().extracting(HsOfficeCoopAssetsTransactionEntity::getUuid).isNotNull();
|
||||
assertThatCoopAssetsTransactionIsPersisted(result.returnedValue());
|
||||
assertThat(coopAssetsTransactionRepo.count()).isEqualTo(count + 1);
|
||||
assertHasLegacyId(result.returnedValue(), "member_asset_id");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -82,6 +82,7 @@ class HsOfficeCoopSharesTransactionRepositoryIntegrationTest extends ContextBase
|
||||
assertThat(result.returnedValue()).isNotNull().extracting(HsOfficeCoopSharesTransactionEntity::getUuid).isNotNull();
|
||||
assertThatCoopSharesTransactionIsPersisted(result.returnedValue());
|
||||
assertThat(coopSharesTransactionRepo.count()).isEqualTo(count + 1);
|
||||
assertHasLegacyId(result.returnedValue(), "member_share_id");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -98,6 +98,7 @@ class HsOfficePartnerRbacRepositoryIntegrationTest extends ContextBasedTestWithC
|
||||
assertThat(result.returnedValue()).isNotNull().extracting(HsOfficePartnerRbacEntity::getUuid).isNotNull();
|
||||
assertThatPartnerIsPersisted(result.returnedValue());
|
||||
assertThat(partnerRepo.count()).isEqualTo(count + 1);
|
||||
assertHasLegacyId(result.returnedValue(), "bp_id");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -89,6 +89,7 @@ class HsOfficeSepaMandateRepositoryIntegrationTest extends ContextBasedTestWithC
|
||||
assertThat(result.returnedValue()).isNotNull().extracting(HsOfficeSepaMandateEntity::getUuid).isNotNull();
|
||||
assertThatSepaMandateIsPersisted(result.returnedValue());
|
||||
assertThat(sepaMandateRepo.count()).isEqualTo(count + 1);
|
||||
assertHasLegacyId(result.returnedValue(), "sepa_mandate_id");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.hostsharing.hsadminng.rbac.context;
|
||||
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.persistence.BaseEntity;
|
||||
import net.hostsharing.hsadminng.rbac.grant.RbacGrantsDiagramService;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.TestInfo;
|
||||
@ -9,6 +10,7 @@ import org.springframework.context.annotation.Import;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
import jakarta.persistence.Table;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
@Import(RbacGrantsDiagramService.class)
|
||||
@ -59,7 +61,6 @@ public abstract class ContextBasedTest {
|
||||
""").executeUpdate();
|
||||
}
|
||||
|
||||
|
||||
protected void historicalContext(final Timestamp txTimestamp) {
|
||||
// set local cannot be used with query parameters
|
||||
em.createNativeQuery("""
|
||||
@ -70,4 +71,14 @@ public abstract class ContextBasedTest {
|
||||
""").executeUpdate();
|
||||
}
|
||||
|
||||
protected void assertHasLegacyId(final BaseEntity<?> entity, final String legacyIdColumnName) {
|
||||
final var table = entity.getClass().getAnnotation(Table.class);
|
||||
final var legacyIdTable = table.schema() + "." + table.name().replace("_rv", "") + "_legacy_id";
|
||||
|
||||
em.createNativeQuery("SELECT " + legacyIdColumnName +
|
||||
" FROM " + legacyIdTable +
|
||||
" WHERE uuid = '" + entity.getUuid() + "'", Long.class)
|
||||
.getSingleResult(); // fails if there is 0 or more than 1 result
|
||||
// that the legacyId is unique is checked by a DB constraint, if applicable
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user