make Hibernate sequence start above 1,000,000 to spare ids for sample data

This commit is contained in:
Michael Hoennig 2019-05-07 12:11:17 +02:00
parent a45e809228
commit 3228b0d0da
6 changed files with 293 additions and 21 deletions

View File

@ -7,7 +7,7 @@
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd"> http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<changeSet id="00000000000000" author="jhipster"> <changeSet id="00000000000000" author="jhipster">
<createSequence sequenceName="hibernate_sequence" startValue="1000" incrementBy="50"/> <createSequence sequenceName="hibernate_sequence" startValue="1000051" incrementBy="50"/>
</changeSet> </changeSet>
<!-- <!--

View File

@ -0,0 +1,76 @@
// Licensed under Apache-2.0
package org.hostsharing.hsadminng.repository;
import static org.assertj.core.api.Assertions.assertThat;
import org.hostsharing.hsadminng.HsadminNgApp;
import org.hostsharing.hsadminng.domain.Asset;
import org.hostsharing.hsadminng.domain.Customer;
import org.hostsharing.hsadminng.domain.Membership;
import org.hostsharing.hsadminng.domain.enumeration.AssetAction;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.time.LocalDate;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = HsadminNgApp.class)
@Transactional
public class AssetRepositoryIntTest {
@Autowired
private CustomerRepository customerRepository;
@Autowired
private MembershipRepository membershipRepository;
@Autowired
private AssetRepository assetRepository;
@Test
public void sequenceStartsAbove1000000ToSpareIdsForSampleData() {
// given
final Asset givenAsset = createArbitraryAsset();
// when
assetRepository.save(givenAsset);
// then
assertThat(givenAsset.getId()).isGreaterThan(1000000);
}
// --- only test fixture below ---
private Customer createPersistentCustomer() {
return customerRepository.save(CustomerRepositoryIntTest.createCustomer());
}
private Membership createPersistentMembership() {
return membershipRepository
.save(MembershipRepositoryIntTest.createMembership(createPersistentCustomer(), "2019-01-08", null));
}
static Asset createAsset(
final Membership membership,
final AssetAction action,
final String amount,
final String documentDate) {
final Asset asset = new Asset();
asset.setMembership(membership);
asset.setAction(action);
asset.setAmount(new BigDecimal(amount));
asset.setDocumentDate(LocalDate.parse(documentDate));
asset.setValueDate(LocalDate.parse(documentDate).plusDays(1));
return asset;
}
private Asset createArbitraryAsset() {
return createAsset(createPersistentMembership(), AssetAction.PAYMENT, "160.00", "2019-01-08");
}
}

View File

@ -0,0 +1,52 @@
// Licensed under Apache-2.0
package org.hostsharing.hsadminng.repository;
import static org.assertj.core.api.Assertions.assertThat;
import org.hostsharing.hsadminng.HsadminNgApp;
import org.hostsharing.hsadminng.domain.Customer;
import org.hostsharing.hsadminng.domain.enumeration.CustomerKind;
import org.hostsharing.hsadminng.domain.enumeration.VatRegion;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.RandomUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = HsadminNgApp.class)
@Transactional
public class CustomerRepositoryIntTest {
@Autowired
private CustomerRepository customerRepository;
@Test
public void sequenceStartsAbove1000000ToSpareIdsForSampleData() {
// given
final Customer givenCustomer = createCustomer();
// when
customerRepository.save(givenCustomer);
// then
assertThat(givenCustomer.getId()).isGreaterThan(1000000);
}
// --- only test fixture below ---
static Customer createCustomer() {
final Customer customer = new Customer();
customer.setPrefix(RandomStringUtils.randomAlphabetic(3).toLowerCase());
customer.setReference(RandomUtils.nextInt(10001, 19999));
customer.setName(RandomStringUtils.randomAlphabetic(10));
customer.setContractualAddress(RandomStringUtils.randomAlphabetic(10));
customer.setKind(CustomerKind.NATURAL);
customer.setVatRegion(VatRegion.DOMESTIC);
return customer;
}
}

View File

@ -6,11 +6,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import org.hostsharing.hsadminng.HsadminNgApp; import org.hostsharing.hsadminng.HsadminNgApp;
import org.hostsharing.hsadminng.domain.Customer; import org.hostsharing.hsadminng.domain.Customer;
import org.hostsharing.hsadminng.domain.Membership; import org.hostsharing.hsadminng.domain.Membership;
import org.hostsharing.hsadminng.domain.enumeration.CustomerKind;
import org.hostsharing.hsadminng.domain.enumeration.VatRegion;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.RandomUtils;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -31,10 +27,22 @@ public class MembershipRepositoryIntTest {
@Autowired @Autowired
private MembershipRepository membershipRepository; private MembershipRepository membershipRepository;
@Test
public void sequenceStartsAbove1000000ToSpareIdsForSampleData() {
// given
final Membership givenMembership = createMembership(createPersistentCustomer(), "2019-01-01", null);
// when
membershipRepository.save(givenMembership);
// then
assertThat(givenMembership.getId()).isGreaterThan(1000000);
}
@Test @Test
public void hasUncancelledMembershipForCustomerIsTrueForCustomerWithUncancelledMembership() { public void hasUncancelledMembershipForCustomerIsTrueForCustomerWithUncancelledMembership() {
// given // given
final Customer givenCustomerWithUncancelledMembership = createCustomerWithMembership("2011-08-18", null); final Customer givenCustomerWithUncancelledMembership = createPersistentCustomerWithMembership("2011-08-18", null);
// when // when
boolean actual = membershipRepository boolean actual = membershipRepository
@ -47,7 +55,7 @@ public class MembershipRepositoryIntTest {
@Test @Test
public void hasUncancelledMembershipForCustomerIsFalseForCustomerWithoutMembership() { public void hasUncancelledMembershipForCustomerIsFalseForCustomerWithoutMembership() {
// given // given
final Customer givenCustomerWithoutMembership = createCustomer(); final Customer givenCustomerWithoutMembership = createPersistentCustomer();
// when // when
boolean actual = membershipRepository.hasUncancelledMembershipForCustomer(givenCustomerWithoutMembership.getId()); boolean actual = membershipRepository.hasUncancelledMembershipForCustomer(givenCustomerWithoutMembership.getId());
@ -59,7 +67,9 @@ public class MembershipRepositoryIntTest {
@Test @Test
public void hasUncancelledMembershipForCustomerIsFalseForCustomerWithCancelledMembership() { public void hasUncancelledMembershipForCustomerIsFalseForCustomerWithCancelledMembership() {
// given // given
final Customer givenCustomerWithCancelledMembership = createCustomerWithMembership("2011-08-18", "2017-12-31"); final Customer givenCustomerWithCancelledMembership = createPersistentCustomerWithMembership(
"2011-08-18",
"2017-12-31");
// when // when
boolean actual = membershipRepository.hasUncancelledMembershipForCustomer(givenCustomerWithCancelledMembership.getId()); boolean actual = membershipRepository.hasUncancelledMembershipForCustomer(givenCustomerWithCancelledMembership.getId());
@ -70,20 +80,18 @@ public class MembershipRepositoryIntTest {
// --- only test fixture below --- // --- only test fixture below ---
private Customer createCustomer() { private Customer createPersistentCustomer() {
final Customer customer = new Customer(); return customerRepository.save(CustomerRepositoryIntTest.createCustomer());
customer.setPrefix(RandomStringUtils.randomAlphabetic(3).toLowerCase()); }
customer.setReference(RandomUtils.nextInt(10001, 19999));
customer.setName(RandomStringUtils.randomAlphabetic(10)); private Customer createPersistentCustomerWithMembership(final String from, final String to) {
customer.setContractualAddress(RandomStringUtils.randomAlphabetic(10)); final Customer customer = createPersistentCustomer();
customer.setKind(CustomerKind.NATURAL); final Membership membership = createMembership(customer, from, to);
customer.setVatRegion(VatRegion.DOMESTIC); membershipRepository.save(membership);
customerRepository.save(customer);
return customer; return customer;
} }
private Customer createCustomerWithMembership(final String from, final String to) { static Membership createMembership(final Customer customer, final String from, final String to) {
final Customer customer = createCustomer();
final Membership membership = new Membership(); final Membership membership = new Membership();
membership.setCustomer(customer); membership.setCustomer(customer);
membership.setMemberFromDate(LocalDate.parse(from)); membership.setMemberFromDate(LocalDate.parse(from));
@ -91,7 +99,6 @@ public class MembershipRepositoryIntTest {
membership.setMemberUntilDate(LocalDate.parse(to)); membership.setMemberUntilDate(LocalDate.parse(to));
} }
membership.setAdmissionDocumentDate(membership.getMemberFromDate().minusDays(7)); membership.setAdmissionDocumentDate(membership.getMemberFromDate().minusDays(7));
membershipRepository.save(membership); return membership;
return customer;
} }
} }

View File

@ -0,0 +1,62 @@
// Licensed under Apache-2.0
package org.hostsharing.hsadminng.repository;
import static org.assertj.core.api.Assertions.assertThat;
import org.hostsharing.hsadminng.HsadminNgApp;
import org.hostsharing.hsadminng.domain.Customer;
import org.hostsharing.hsadminng.domain.SepaMandate;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDate;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = HsadminNgApp.class)
@Transactional
public class SepaMandateRepositoryIntTest {
@Autowired
private CustomerRepository customerRepository;
@Autowired
private SepaMandateRepository sepaMandateRepository;
@Test
public void sequenceStartsAbove1000000ToSpareIdsForSampleData() {
// given
final SepaMandate givenSepaMandate = createSepaMandate(createPersistentCustomer(), "DUMMY_REF", "2019-01-08", null);
// when
sepaMandateRepository.save(givenSepaMandate);
// then
assertThat(givenSepaMandate.getId()).isGreaterThan(1000000);
}
// --- only test fixture below ---
private Customer createPersistentCustomer() {
return customerRepository.save(CustomerRepositoryIntTest.createCustomer());
}
static SepaMandate createSepaMandate(final Customer customer, final String reference, final String from, final String to) {
final SepaMandate sepaMandate = new SepaMandate();
sepaMandate.setCustomer(customer);
sepaMandate.setReference(reference);
sepaMandate.setIban("NL57ABNA2228161411");
sepaMandate.setBic("ABNANL2A");
sepaMandate.setGrantingDocumentDate(LocalDate.parse(from));
sepaMandate.setValidFromDate(LocalDate.parse(from).plusDays(1));
if (to != null) {
sepaMandate.setRevokationDocumentDate(LocalDate.parse(to));
sepaMandate.setValidUntilDate(LocalDate.parse(to).plusDays(7));
}
return sepaMandate;
}
}

View File

@ -0,0 +1,75 @@
// Licensed under Apache-2.0
package org.hostsharing.hsadminng.repository;
import static org.assertj.core.api.Assertions.assertThat;
import org.hostsharing.hsadminng.HsadminNgApp;
import org.hostsharing.hsadminng.domain.Customer;
import org.hostsharing.hsadminng.domain.Membership;
import org.hostsharing.hsadminng.domain.Share;
import org.hostsharing.hsadminng.domain.enumeration.ShareAction;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDate;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = HsadminNgApp.class)
@Transactional
public class ShareRepositoryIntTest {
@Autowired
private CustomerRepository customerRepository;
@Autowired
private MembershipRepository membershipRepository;
@Autowired
private ShareRepository shareRepository;
@Test
public void sequenceStartsAbove1000000ToSpareIdsForSampleData() {
// given
final Share givenShare = createArbitraryShare();
// when
shareRepository.save(givenShare);
// then
assertThat(givenShare.getId()).isGreaterThan(1000000);
}
// --- only test fixture below ---
private Customer createPersistentCustomer() {
return customerRepository.save(CustomerRepositoryIntTest.createCustomer());
}
private Membership createPersistentMembership() {
return membershipRepository
.save(MembershipRepositoryIntTest.createMembership(createPersistentCustomer(), "2019-01-08", null));
}
static Share createShare(
final Membership membership,
final ShareAction action,
final int quantity,
final String documentDate) {
final Share share = new Share();
share.setMembership(membership);
share.setAction(action);
share.setQuantity(quantity);
share.setDocumentDate(LocalDate.parse(documentDate));
share.setValueDate(LocalDate.parse(documentDate).plusDays(1));
return share;
}
private Share createArbitraryShare() {
return createShare(createPersistentMembership(), ShareAction.SUBSCRIPTION, 1, "2019-01-08");
}
}