better display labels and less columns in tables (deliberately not yet in SepaMandate*)

This commit is contained in:
Michael Hoennig 2019-04-27 11:30:15 +02:00
parent b9a7c33c6a
commit 3b0d46a4c8
31 changed files with 316 additions and 112 deletions

View File

@ -4,6 +4,7 @@ import org.hostsharing.hsadminng.domain.Asset;
import org.hostsharing.hsadminng.repository.AssetRepository; import org.hostsharing.hsadminng.repository.AssetRepository;
import org.hostsharing.hsadminng.service.dto.AssetDTO; import org.hostsharing.hsadminng.service.dto.AssetDTO;
import org.hostsharing.hsadminng.service.mapper.AssetMapper; import org.hostsharing.hsadminng.service.mapper.AssetMapper;
import org.hostsharing.hsadminng.web.rest.errors.BadRequestAlertException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
@ -23,11 +24,12 @@ public class AssetService implements IdToDtoResolver<AssetDTO> {
private final Logger log = LoggerFactory.getLogger(AssetService.class); private final Logger log = LoggerFactory.getLogger(AssetService.class);
private final EntityManager em;
private final AssetRepository assetRepository; private final AssetRepository assetRepository;
private final AssetMapper assetMapper; private final AssetMapper assetMapper;
private final AssetValidator assetValidator; private final AssetValidator assetValidator;
private final EntityManager em;
public AssetService(final EntityManager em, final AssetRepository assetRepository, final AssetMapper assetMapper, final AssetValidator assetValidator) { public AssetService(final EntityManager em, final AssetRepository assetRepository, final AssetMapper assetMapper, final AssetValidator assetValidator) {
this.em = em; this.em = em;
@ -86,6 +88,7 @@ public class AssetService implements IdToDtoResolver<AssetDTO> {
*/ */
public void delete(Long id) { public void delete(Long id) {
log.debug("Request to delete Asset : {}", id); log.debug("Request to delete Asset : {}", id);
assetRepository.deleteById(id);
throw new BadRequestAlertException("Asset transactions are immutable", Asset.ENTITY_NAME, "assetTransactionImmutable");
} }
} }

View File

@ -12,6 +12,7 @@ import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.persistence.EntityManager;
import java.util.Optional; import java.util.Optional;
/** /**
@ -23,15 +24,19 @@ public class MembershipService implements IdToDtoResolver<MembershipDTO> {
private final Logger log = LoggerFactory.getLogger(MembershipService.class); private final Logger log = LoggerFactory.getLogger(MembershipService.class);
private final EntityManager em;
private final MembershipValidator membershipValidator; private final MembershipValidator membershipValidator;
private final MembershipRepository membershipRepository; private final MembershipRepository membershipRepository;
private final MembershipMapper membershipMapper; private final MembershipMapper membershipMapper;
public MembershipService(final MembershipValidator membershipValidator, public MembershipService(final EntityManager em,
final MembershipValidator membershipValidator,
final MembershipRepository membershipRepository, final MembershipRepository membershipRepository,
final MembershipMapper membershipMapper) { final MembershipMapper membershipMapper) {
this.em = em;
this.membershipValidator = membershipValidator; this.membershipValidator = membershipValidator;
this.membershipRepository = membershipRepository; this.membershipRepository = membershipRepository;
this.membershipMapper = membershipMapper; this.membershipMapper = membershipMapper;
@ -50,6 +55,8 @@ public class MembershipService implements IdToDtoResolver<MembershipDTO> {
Membership membership = membershipMapper.toEntity(membershipDTO); Membership membership = membershipMapper.toEntity(membershipDTO);
membership = membershipRepository.save(membership); membership = membershipRepository.save(membership);
em.flush();
em.refresh(membership);
return membershipMapper.toDto(membership); return membershipMapper.toDto(membership);
} }

View File

@ -12,6 +12,7 @@ import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.persistence.EntityManager;
import java.util.Optional; import java.util.Optional;
/** /**
@ -23,13 +24,16 @@ public class ShareService implements IdToDtoResolver<ShareDTO> {
private final Logger log = LoggerFactory.getLogger(ShareService.class); private final Logger log = LoggerFactory.getLogger(ShareService.class);
private final EntityManager em;
private final ShareRepository shareRepository; private final ShareRepository shareRepository;
private final ShareMapper shareMapper; private final ShareMapper shareMapper;
private final ShareValidator shareValidator; private final ShareValidator shareValidator;
public ShareService(ShareRepository shareRepository, ShareMapper shareMapper, ShareValidator shareValidator) { public ShareService(final EntityManager em, final ShareRepository shareRepository, final ShareMapper shareMapper, final ShareValidator shareValidator) {
this.em = em;
this.shareRepository = shareRepository; this.shareRepository = shareRepository;
this.shareMapper = shareMapper; this.shareMapper = shareMapper;
this.shareValidator = shareValidator; this.shareValidator = shareValidator;
@ -48,6 +52,8 @@ public class ShareService implements IdToDtoResolver<ShareDTO> {
Share share = shareMapper.toEntity(shareDTO); Share share = shareMapper.toEntity(shareDTO);
share = shareRepository.save(share); share = shareRepository.save(share);
em.flush();
em.refresh(share);
return shareMapper.toDto(share); return shareMapper.toDto(share);
} }

View File

@ -47,8 +47,8 @@ public class AssetDTO implements Serializable, AccessMappings {
@AccessFor(init = Role.ADMIN, update = Role.ADMIN, read = {Role.CONTRACTUAL_CONTACT, Role.FINANCIAL_CONTACT}) @AccessFor(init = Role.ADMIN, update = Role.ADMIN, read = {Role.CONTRACTUAL_CONTACT, Role.FINANCIAL_CONTACT})
private Long membershipId; private Long membershipId;
@AccessFor(init = Role.ANYBODY, update = Role.ANYBODY, read = {Role.CONTRACTUAL_CONTACT, Role.FINANCIAL_CONTACT}) @AccessFor(init=Role.ANYBODY, update = Role.ANYBODY, read = {Role.CONTRACTUAL_CONTACT, Role.FINANCIAL_CONTACT})
private String membershipDisplayReference; private String membershipDisplayLabel;
public Long getId() { public Long getId() {
return id; return id;
@ -106,12 +106,12 @@ public class AssetDTO implements Serializable, AccessMappings {
this.membershipId = membershipId; this.membershipId = membershipId;
} }
public String getMembershipDisplayReference() { public String getMembershipDisplayLabel() {
return membershipDisplayReference; return membershipDisplayLabel;
} }
public void setMembershipDisplayReference(String membershipDisplayReference) { public void setMembershipDisplayLabel(String membershipDisplayLabel) {
this.membershipDisplayReference = membershipDisplayReference; this.membershipDisplayLabel = membershipDisplayLabel;
} }
@Override @Override
@ -145,7 +145,7 @@ public class AssetDTO implements Serializable, AccessMappings {
", amount=" + getAmount() + ", amount=" + getAmount() +
", remark='" + getRemark() + "'" + ", remark='" + getRemark() + "'" +
", membership=" + getMembershipId() + ", membership=" + getMembershipId() +
", membership='" + getMembershipDisplayReference() + "'" + ", membership='" + getMembershipDisplayLabel() + "'" +
"}"; "}";
} }

View File

@ -85,6 +85,9 @@ public class CustomerDTO extends FluentBuilder<CustomerDTO> implements AccessMap
@AccessFor(init = Role.ADMIN, update = Role.SUPPORTER, read = Role.SUPPORTER) @AccessFor(init = Role.ADMIN, update = Role.SUPPORTER, read = Role.SUPPORTER)
private String remark; private String remark;
@AccessFor(init=Role.ANYBODY, update=Role.ANYBODY, read = Role.ANY_CUSTOMER_USER)
private String displayLabel;
public Long getId() { public Long getId() {
return id; return id;
} }
@ -213,6 +216,14 @@ public class CustomerDTO extends FluentBuilder<CustomerDTO> implements AccessMap
this.remark = remark; this.remark = remark;
} }
public String getDisplayLabel() {
return displayLabel;
}
public void setDisplayLabel(final String displayLabel) {
this.displayLabel = displayLabel;
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) { if (this == o) {

View File

@ -46,8 +46,11 @@ public class MembershipDTO extends FluentBuilder<MembershipDTO> implements Seria
@AccessFor(init = Role.ADMIN, read = {Role.CONTRACTUAL_CONTACT, Role.FINANCIAL_CONTACT}) @AccessFor(init = Role.ADMIN, read = {Role.CONTRACTUAL_CONTACT, Role.FINANCIAL_CONTACT})
private String customerPrefix; private String customerPrefix;
@AccessFor(read = {Role.CONTRACTUAL_CONTACT, Role.FINANCIAL_CONTACT}) @AccessFor(init = Role.ANYBODY, update = Role.ANYBODY, read = Role.FINANCIAL_CONTACT)
private String membershipDisplayReference; private String displayLabel;
@AccessFor(init = Role.ANYBODY, update = Role.ANYBODY, read = Role.FINANCIAL_CONTACT)
private String customerDisplayLabel;
public Long getId() { public Long getId() {
return id; return id;
@ -113,12 +116,20 @@ public class MembershipDTO extends FluentBuilder<MembershipDTO> implements Seria
this.customerPrefix = customerPrefix; this.customerPrefix = customerPrefix;
} }
private String getMembershipDisplayReference() { public String getDisplayLabel() {
return membershipDisplayReference; return displayLabel;
} }
public void setMembershipDisplayReference(final String membershipDisplayReference) { public void setDisplayLabel(final String displayLabel) {
this.membershipDisplayReference = membershipDisplayReference; this.displayLabel = displayLabel;
}
public String getCustomerDisplayLabel() {
return customerDisplayLabel;
}
public void setCustomerDisplayLabel(final String customerDisplayLabel) {
this.customerDisplayLabel = customerDisplayLabel;
} }
@Override @Override

View File

@ -48,7 +48,7 @@ public class ShareDTO implements Serializable {
private Long membershipId; private Long membershipId;
@AccessFor(read = {Role.CONTRACTUAL_CONTACT, Role.FINANCIAL_CONTACT}) @AccessFor(read = {Role.CONTRACTUAL_CONTACT, Role.FINANCIAL_CONTACT})
private String membershipDisplayReference; private String membershipDisplayLabel;
public Long getId() { public Long getId() {
return id; return id;
@ -106,12 +106,12 @@ public class ShareDTO implements Serializable {
this.membershipId = membershipId; this.membershipId = membershipId;
} }
public String getMembershipDisplayReference() { public String getMembershipDisplayLabel() {
return membershipDisplayReference; return membershipDisplayLabel;
} }
public void setMembershipDisplayReference(String membershipDisplayReference) { public void setMembershipDisplayLabel(String membershipDisplayLabel) {
this.membershipDisplayReference = membershipDisplayReference; this.membershipDisplayLabel = membershipDisplayLabel;
} }
@Override @Override
@ -145,7 +145,7 @@ public class ShareDTO implements Serializable {
", quantity=" + getQuantity() + ", quantity=" + getQuantity() +
", remark='" + getRemark() + "'" + ", remark='" + getRemark() + "'" +
", membership=" + getMembershipId() + ", membership=" + getMembershipId() +
", membership='" + getMembershipDisplayReference() + "'" + ", membership='" + getMembershipDisplayLabel() + "'" +
"}"; "}";
} }
} }

View File

@ -1,16 +1,12 @@
package org.hostsharing.hsadminng.service.mapper; package org.hostsharing.hsadminng.service.mapper;
import org.hostsharing.hsadminng.domain.Asset; import org.hostsharing.hsadminng.domain.Asset;
import org.hostsharing.hsadminng.domain.Customer;
import org.hostsharing.hsadminng.domain.Membership;
import org.hostsharing.hsadminng.service.dto.AssetDTO; import org.hostsharing.hsadminng.service.dto.AssetDTO;
import org.mapstruct.AfterMapping; import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.Mapping; import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget; import org.mapstruct.MappingTarget;
import java.util.Objects;
/** /**
* Mapper for the entity Asset and its DTO AssetDTO. * Mapper for the entity Asset and its DTO AssetDTO.
*/ */
@ -18,19 +14,12 @@ import java.util.Objects;
public interface AssetMapper extends EntityMapper<AssetDTO, Asset> { public interface AssetMapper extends EntityMapper<AssetDTO, Asset> {
@Mapping(source = "membership.id", target = "membershipId") @Mapping(source = "membership.id", target = "membershipId")
@Mapping(target = "membershipDisplayReference", ignore = true) @Mapping(target = "membershipDisplayLabel", ignore = true)
AssetDTO toDto(Asset asset); AssetDTO toDto(Asset asset);
@AfterMapping @AfterMapping
default void setMembershipDisplayReference(final @MappingTarget AssetDTO dto, final Asset entity) { default void setMembershipDisplayLabel(final @MappingTarget AssetDTO dto, final Asset entity) {
// TODO: rather use method extracted from MembershipMaper.setMembershipDisplayReference() to avoid duplicate code dto.setMembershipDisplayLabel(MembershipMapper.displayLabel(entity.getMembership()));
final Membership membership = entity.getMembership();
final Customer customer = membership.getCustomer();
dto.setMembershipDisplayReference(customer.getReference()
+ ":" + customer.getPrefix()
+ " [" + customer.getName() + "] "
+ membership.getAdmissionDocumentDate().toString() + " - "
+ Objects.toString(membership.getCancellationDocumentDate(), ""));
} }
@Mapping(source = "membershipId", target = "membership") @Mapping(source = "membershipId", target = "membership")

View File

@ -1,9 +1,11 @@
package org.hostsharing.hsadminng.service.mapper; package org.hostsharing.hsadminng.service.mapper;
import org.hostsharing.hsadminng.domain.*; import org.hostsharing.hsadminng.domain.Customer;
import org.hostsharing.hsadminng.service.dto.CustomerDTO; import org.hostsharing.hsadminng.service.dto.CustomerDTO;
import org.mapstruct.AfterMapping;
import org.mapstruct.*; import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
/** /**
* Mapper for the entity Customer and its DTO CustomerDTO. * Mapper for the entity Customer and its DTO CustomerDTO.
@ -11,6 +13,18 @@ import org.mapstruct.*;
@Mapper(componentModel = "spring", uses = {}) @Mapper(componentModel = "spring", uses = {})
public interface CustomerMapper extends EntityMapper<CustomerDTO, Customer> { public interface CustomerMapper extends EntityMapper<CustomerDTO, Customer> {
static String displayLabel(Customer customer) {
return customer.getName()
+ " [" + customer.getReference() + ":" + customer.getPrefix() +"]";
}
@Mapping(target = "displayLabel", ignore = true)
CustomerDTO toDto(Customer customer);
@AfterMapping
default void setDisplayLabel(final @MappingTarget CustomerDTO dto, final Customer entity) {
dto.setDisplayLabel(displayLabel(entity));
}
@Mapping(target = "memberships", ignore = true) @Mapping(target = "memberships", ignore = true)
@Mapping(target = "sepamandates", ignore = true) @Mapping(target = "sepamandates", ignore = true)

View File

@ -16,21 +16,25 @@ import java.util.Objects;
@Mapper(componentModel = "spring", uses = {CustomerMapper.class}) @Mapper(componentModel = "spring", uses = {CustomerMapper.class})
public interface MembershipMapper extends EntityMapper<MembershipDTO, Membership> { public interface MembershipMapper extends EntityMapper<MembershipDTO, Membership> {
static String displayLabel(final Membership entity) {
final Customer customer = entity.getCustomer();
return CustomerMapper.displayLabel(customer) + " "
+ Objects.toString(entity.getAdmissionDocumentDate(), "") + " - "
+ Objects.toString(entity.getCancellationDocumentDate(), "...");
}
@Mapping(source = "customer.id", target = "customerId") @Mapping(source = "customer.id", target = "customerId")
@Mapping(source = "customer.prefix", target = "customerPrefix") @Mapping(source = "customer.prefix", target = "customerPrefix")
@Mapping(target = "membershipDisplayReference", ignore = true) @Mapping(target = "displayLabel", ignore = true)
@Mapping(target = "customerDisplayLabel", ignore = true)
MembershipDTO toDto(Membership membership); MembershipDTO toDto(Membership membership);
// TODO BLOG HOWTO: multi-field display reference for selection lists // TODO BLOG HOWTO: multi-field display reference for selection lists
// also change the filed in the option list in *-update.html // also change the filed in the option list in *-update.html
@AfterMapping @AfterMapping
default void setMembershipDisplayReference(final @MappingTarget MembershipDTO dto, final Membership entity) { default void setMembershipDisplayLabel(final @MappingTarget MembershipDTO dto, final Membership entity) {
final Customer customer = entity.getCustomer(); dto.setDisplayLabel(displayLabel(entity));
dto.setMembershipDisplayReference(customer.getReference() dto.setCustomerDisplayLabel(CustomerMapper.displayLabel(entity.getCustomer()));
+ ":" + customer.getPrefix()
+ " [" + customer.getName() + "] "
+ Objects.toString(entity.getAdmissionDocumentDate()) + " - "
+ Objects.toString(entity.getCancellationDocumentDate(), ""));
} }
@Mapping(target = "shares", ignore = true) @Mapping(target = "shares", ignore = true)

View File

@ -2,8 +2,10 @@ package org.hostsharing.hsadminng.service.mapper;
import org.hostsharing.hsadminng.domain.Share; import org.hostsharing.hsadminng.domain.Share;
import org.hostsharing.hsadminng.service.dto.ShareDTO; import org.hostsharing.hsadminng.service.dto.ShareDTO;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.Mapping; import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
/** /**
* Mapper for the entity Share and its DTO ShareDTO. * Mapper for the entity Share and its DTO ShareDTO.
@ -12,9 +14,14 @@ import org.mapstruct.Mapping;
public interface ShareMapper extends EntityMapper<ShareDTO, Share> { public interface ShareMapper extends EntityMapper<ShareDTO, Share> {
@Mapping(source = "membership.id", target = "membershipId") @Mapping(source = "membership.id", target = "membershipId")
@Mapping(source = "membership.admissionDocumentDate", target = "membershipDisplayReference") @Mapping(target = "membershipDisplayLabel", ignore = true)
ShareDTO toDto(Share share); ShareDTO toDto(Share share);
@AfterMapping
default void setMembershipDisplayLabel(final @MappingTarget ShareDTO dto, final Share entity) {
dto.setMembershipDisplayLabel(MembershipMapper.displayLabel(entity.getMembership()));
}
@Mapping(source = "membershipId", target = "membership") @Mapping(source = "membershipId", target = "membership")
Share toEntity(ShareDTO shareDTO); Share toEntity(ShareDTO shareDTO);

View File

@ -1,7 +1,7 @@
<div class="row justify-content-center"> <div class="row justify-content-center">
<div class="col-8"> <div class="col-8">
<div *ngIf="asset"> <div *ngIf="asset">
<h2><span jhiTranslate="hsadminNgApp.asset.detail.title">Asset</span> {{asset.id}}</h2> <h2><span jhiTranslate="hsadminNgApp.asset.detail.title">Asset</span>: #{{asset.id}} - {{asset.membershipDisplayLabel}}</h2>
<hr> <hr>
<jhi-alert-error></jhi-alert-error> <jhi-alert-error></jhi-alert-error>
<dl class="row-md jh-entity-details"> <dl class="row-md jh-entity-details">
@ -28,7 +28,7 @@
<dt><span jhiTranslate="hsadminNgApp.asset.membership">Membership</span></dt> <dt><span jhiTranslate="hsadminNgApp.asset.membership">Membership</span></dt>
<dd> <dd>
<div *ngIf="asset.membershipId"> <div *ngIf="asset.membershipId">
<a [routerLink]="['/membership', asset.membershipId, 'view']">{{asset.membershipDisplayReference}}</a> <a [routerLink]="['/membership', asset.membershipId, 'view']">{{asset.membershipDisplayLabel}}</a>
</div> </div>
</dd> </dd>
</dl> </dl>

View File

@ -89,7 +89,7 @@
<label class="form-control-label" jhiTranslate="hsadminNgApp.asset.membership" for="field_membership">Membership</label> <label class="form-control-label" jhiTranslate="hsadminNgApp.asset.membership" for="field_membership">Membership</label>
<select class="form-control" id="field_membership" name="membership" [(ngModel)]="asset.membershipId" required> <select class="form-control" id="field_membership" name="membership" [(ngModel)]="asset.membershipId" required>
<option *ngIf="!editForm.value.membership" [ngValue]="null" selected></option> <option *ngIf="!editForm.value.membership" [ngValue]="null" selected></option>
<option [ngValue]="membershipOption.id" *ngFor="let membershipOption of memberships; trackBy: trackMembershipById">{{membershipOption.membershipDisplayReference}}</option> <option [ngValue]="membershipOption.id" *ngFor="let membershipOption of memberships; trackBy: trackMembershipById">{{membershipOption.displayLabel}}</option>
</select> </select>
</div> </div>
<div [hidden]="!(editForm.controls.membership?.dirty && editForm.controls.membership?.invalid)"> <div [hidden]="!(editForm.controls.membership?.dirty && editForm.controls.membership?.invalid)">

View File

@ -19,8 +19,7 @@
<th jhiSortBy="valueDate"><span jhiTranslate="hsadminNgApp.asset.valueDate">Value Date</span> <fa-icon [icon]="'sort'"></fa-icon></th> <th jhiSortBy="valueDate"><span jhiTranslate="hsadminNgApp.asset.valueDate">Value Date</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="action"><span jhiTranslate="hsadminNgApp.asset.action">Action</span> <fa-icon [icon]="'sort'"></fa-icon></th> <th jhiSortBy="action"><span jhiTranslate="hsadminNgApp.asset.action">Action</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="amount"><span jhiTranslate="hsadminNgApp.asset.amount">Amount</span> <fa-icon [icon]="'sort'"></fa-icon></th> <th jhiSortBy="amount"><span jhiTranslate="hsadminNgApp.asset.amount">Amount</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="remark"><span jhiTranslate="hsadminNgApp.asset.remark">Remark</span> <fa-icon [icon]="'sort'"></fa-icon></th> <th jhiSortBy="membershipDisplayLabel"><span jhiTranslate="hsadminNgApp.asset.membership">Membership</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="membershipDisplayReference"><span jhiTranslate="hsadminNgApp.asset.membership">Membership</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th></th> <th></th>
</tr> </tr>
</thead> </thead>
@ -31,10 +30,9 @@
<td>{{asset.valueDate | date:'mediumDate'}}</td> <td>{{asset.valueDate | date:'mediumDate'}}</td>
<td jhiTranslate="{{'hsadminNgApp.AssetAction.' + asset.action}}">{{asset.action}}</td> <td jhiTranslate="{{'hsadminNgApp.AssetAction.' + asset.action}}">{{asset.action}}</td>
<td>{{asset.amount}}</td> <td>{{asset.amount}}</td>
<td>{{asset.remark}}</td>
<td> <td>
<div *ngIf="asset.membershipId"> <div *ngIf="asset.membershipId">
<a [routerLink]="['../membership', asset.membershipId , 'view' ]" >{{asset.membershipDisplayReference}}</a> <a [routerLink]="['../membership', asset.membershipId , 'view' ]" >{{asset.membershipDisplayLabel}}</a>
</div> </div>
</td> </td>
<td class="text-right"> <td class="text-right">

View File

@ -1,7 +1,7 @@
<div class="row justify-content-center"> <div class="row justify-content-center">
<div class="col-8"> <div class="col-8">
<div *ngIf="customer"> <div *ngIf="customer">
<h2><span jhiTranslate="hsadminNgApp.customer.detail.title">Customer</span> {{customer.id}}</h2> <h2><span jhiTranslate="hsadminNgApp.customer.detail.title">Customer</span>: {{customer.displayLabel}}</h2>
<hr> <hr>
<jhi-alert-error></jhi-alert-error> <jhi-alert-error></jhi-alert-error>
<dl class="row-md jh-entity-details"> <dl class="row-md jh-entity-details">

View File

@ -18,18 +18,7 @@
<th jhiSortBy="reference"><span jhiTranslate="hsadminNgApp.customer.reference">Reference</span> <fa-icon [icon]="'sort'"></fa-icon></th> <th jhiSortBy="reference"><span jhiTranslate="hsadminNgApp.customer.reference">Reference</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="prefix"><span jhiTranslate="hsadminNgApp.customer.prefix">Prefix</span> <fa-icon [icon]="'sort'"></fa-icon></th> <th jhiSortBy="prefix"><span jhiTranslate="hsadminNgApp.customer.prefix">Prefix</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="name"><span jhiTranslate="hsadminNgApp.customer.name">Name</span> <fa-icon [icon]="'sort'"></fa-icon></th> <th jhiSortBy="name"><span jhiTranslate="hsadminNgApp.customer.name">Name</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="kind"><span jhiTranslate="hsadminNgApp.customer.kind">Kind</span> <fa-icon [icon]="'sort'"></fa-icon></th> <th jhiSortBy="kind"><span jhiTranslate="hsadminNgApp.customer.kind">Kind</span> <fa-icon [icon]="'sort'"></fa-icon></thn></th>
<th jhiSortBy="birthDate"><span jhiTranslate="hsadminNgApp.customer.birthDate">Birth Date</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="birthPlace"><span jhiTranslate="hsadminNgApp.customer.birthPlace">Birth Place</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="registrationCourt"><span jhiTranslate="hsadminNgApp.customer.registrationCourt">Registration Court</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="registrationNumber"><span jhiTranslate="hsadminNgApp.customer.registrationNumber">Registration Number</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="vatRegion"><span jhiTranslate="hsadminNgApp.customer.vatRegion">Vat Region</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="vatNumber"><span jhiTranslate="hsadminNgApp.customer.vatNumber">Vat Number</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="contractualSalutation"><span jhiTranslate="hsadminNgApp.customer.contractualSalutation">Contractual Salutation</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="contractualAddress"><span jhiTranslate="hsadminNgApp.customer.contractualAddress">Contractual Address</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="billingSalutation"><span jhiTranslate="hsadminNgApp.customer.billingSalutation">Billing Salutation</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="billingAddress"><span jhiTranslate="hsadminNgApp.customer.billingAddress">Billing Address</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="remark"><span jhiTranslate="hsadminNgApp.customer.remark">Remark</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th></th> <th></th>
</tr> </tr>
</thead> </thead>
@ -40,17 +29,6 @@
<td>{{customer.prefix}}</td> <td>{{customer.prefix}}</td>
<td>{{customer.name}}</td> <td>{{customer.name}}</td>
<td jhiTranslate="{{'hsadminNgApp.CustomerKind.' + customer.kind}}">{{customer.kind}}</td> <td jhiTranslate="{{'hsadminNgApp.CustomerKind.' + customer.kind}}">{{customer.kind}}</td>
<td>{{customer.birthDate | date:'mediumDate'}}</td>
<td>{{customer.birthPlace}}</td>
<td>{{customer.registrationCourt}}</td>
<td>{{customer.registrationNumber}}</td>
<td jhiTranslate="{{'hsadminNgApp.VatRegion.' + customer.vatRegion}}">{{customer.vatRegion}}</td>
<td>{{customer.vatNumber}}</td>
<td>{{customer.contractualSalutation}}</td>
<td>{{customer.contractualAddress}}</td>
<td>{{customer.billingSalutation}}</td>
<td>{{customer.billingAddress}}</td>
<td>{{customer.remark}}</td>
<td class="text-right"> <td class="text-right">
<div class="btn-group flex-btn-group-container"> <div class="btn-group flex-btn-group-container">
<button type="submit" <button type="submit"

View File

@ -1,7 +1,7 @@
<div class="row justify-content-center"> <div class="row justify-content-center">
<div class="col-8"> <div class="col-8">
<div *ngIf="membership"> <div *ngIf="membership">
<h2><span jhiTranslate="hsadminNgApp.membership.detail.title">Membership</span> {{membership.id}}</h2> <h2><span jhiTranslate="hsadminNgApp.membership.detail.title">Membership</span>: {{membership.displayLabel}}</h2>
<hr> <hr>
<jhi-alert-error></jhi-alert-error> <jhi-alert-error></jhi-alert-error>
<dl class="row-md jh-entity-details"> <dl class="row-md jh-entity-details">
@ -28,7 +28,7 @@
<dt><span jhiTranslate="hsadminNgApp.membership.customer">Customer</span></dt> <dt><span jhiTranslate="hsadminNgApp.membership.customer">Customer</span></dt>
<dd> <dd>
<div *ngIf="membership.customerId"> <div *ngIf="membership.customerId">
<a [routerLink]="['/customer', membership.customerId, 'view']">{{membership.customerPrefix}}</a> <a [routerLink]="['/customer', membership.customerId, 'view']">{{membership.customerDisplayLabel}}</a>
</div> </div>
</dd> </dd>
</dl> </dl>

View File

@ -77,7 +77,7 @@
<label class="form-control-label" jhiTranslate="hsadminNgApp.membership.customer" for="field_customer">Customer</label> <label class="form-control-label" jhiTranslate="hsadminNgApp.membership.customer" for="field_customer">Customer</label>
<select class="form-control" id="field_customer" name="customer" [(ngModel)]="membership.customerId" required> <select class="form-control" id="field_customer" name="customer" [(ngModel)]="membership.customerId" required>
<option *ngIf="!editForm.value.customer" [ngValue]="null" selected></option> <option *ngIf="!editForm.value.customer" [ngValue]="null" selected></option>
<option [ngValue]="customerOption.id" *ngFor="let customerOption of customers; trackBy: trackCustomerById">{{customerOption.prefix}}</option> <option [ngValue]="customerOption.id" *ngFor="let customerOption of customers; trackBy: trackCustomerById">{{customerOption.displayLabel}}</option>
</select> </select>
</div> </div>
<div [hidden]="!(editForm.controls.customer?.dirty && editForm.controls.customer?.invalid)"> <div [hidden]="!(editForm.controls.customer?.dirty && editForm.controls.customer?.invalid)">

View File

@ -19,7 +19,6 @@
<th jhiSortBy="cancellationDocumentDate"><span jhiTranslate="hsadminNgApp.membership.cancellationDocumentDate">Cancellation Document Date</span> <fa-icon [icon]="'sort'"></fa-icon></th> <th jhiSortBy="cancellationDocumentDate"><span jhiTranslate="hsadminNgApp.membership.cancellationDocumentDate">Cancellation Document Date</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="memberFromDate"><span jhiTranslate="hsadminNgApp.membership.memberFromDate">Member From Date</span> <fa-icon [icon]="'sort'"></fa-icon></th> <th jhiSortBy="memberFromDate"><span jhiTranslate="hsadminNgApp.membership.memberFromDate">Member From Date</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="memberUntilDate"><span jhiTranslate="hsadminNgApp.membership.memberUntilDate">Member Until Date</span> <fa-icon [icon]="'sort'"></fa-icon></th> <th jhiSortBy="memberUntilDate"><span jhiTranslate="hsadminNgApp.membership.memberUntilDate">Member Until Date</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="remark"><span jhiTranslate="hsadminNgApp.membership.remark">Remark</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="customerPrefix"><span jhiTranslate="hsadminNgApp.membership.customer">Customer</span> <fa-icon [icon]="'sort'"></fa-icon></th> <th jhiSortBy="customerPrefix"><span jhiTranslate="hsadminNgApp.membership.customer">Customer</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th></th> <th></th>
</tr> </tr>
@ -28,13 +27,12 @@
<tr *ngFor="let membership of memberships ;trackBy: trackId"> <tr *ngFor="let membership of memberships ;trackBy: trackId">
<td><a [routerLink]="['/membership', membership.id, 'view' ]">{{membership.id}}</a></td> <td><a [routerLink]="['/membership', membership.id, 'view' ]">{{membership.id}}</a></td>
<td>{{membership.admissionDocumentDate | date:'mediumDate'}}</td> <td>{{membership.admissionDocumentDate | date:'mediumDate'}}</td>
<td>{{membership.cancellationDocumentDate | date:'mediumDate'}}</td> <td>{{membership.cancellationDocumentDate | date:'mediumDsate'}}</td>
<td>{{membership.memberFromDate | date:'mediumDate'}}</td> <td>{{membership.memberFromDate | date:'mediumDate'}}</td>
<td>{{membership.memberUntilDate | date:'mediumDate'}}</td> <td>{{membership.memberUntilDate | date:'mediumDate'}}</td>
<td>{{membership.remark}}</td>
<td> <td>
<div *ngIf="membership.customerId"> <div *ngIf="membership.customerId">
<a [routerLink]="['../customer', membership.customerId , 'view' ]" >{{membership.customerPrefix}}</a> <a [routerLink]="['../customer', membership.customerId , 'view' ]" >{{membership.customerDisplayLabel}}</a>
</div> </div>
</td> </td>
<td class="text-right"> <td class="text-right">

View File

@ -1,7 +1,7 @@
<div class="row justify-content-center"> <div class="row justify-content-center">
<div class="col-8"> <div class="col-8">
<div *ngIf="share"> <div *ngIf="share">
<h2><span jhiTranslate="hsadminNgApp.share.detail.title">Share</span> {{share.id}}</h2> <h2><span jhiTranslate="hsadminNgApp.share.detail.title">Share</span>: #{{share.id}} - {{share.membershipDisplayLabel}}</h2>
<hr> <hr>
<jhi-alert-error></jhi-alert-error> <jhi-alert-error></jhi-alert-error>
<dl class="row-md jh-entity-details"> <dl class="row-md jh-entity-details">
@ -28,7 +28,7 @@
<dt><span jhiTranslate="hsadminNgApp.share.membership">Membership</span></dt> <dt><span jhiTranslate="hsadminNgApp.share.membership">Membership</span></dt>
<dd> <dd>
<div *ngIf="share.membershipId"> <div *ngIf="share.membershipId">
<a [routerLink]="['/membership', share.membershipId, 'view']">{{share.membershipDisplayReference}}</a> <a [routerLink]="['/membership', share.membershipId, 'view']">{{share.membershipDisplayLabel}}</a>
</div> </div>
</dd> </dd>
</dl> </dl>

View File

@ -85,7 +85,7 @@
<label class="form-control-label" jhiTranslate="hsadminNgApp.share.membership" for="field_membership">Membership</label> <label class="form-control-label" jhiTranslate="hsadminNgApp.share.membership" for="field_membership">Membership</label>
<select class="form-control" id="field_membership" name="membership" [(ngModel)]="share.membershipId" required> <select class="form-control" id="field_membership" name="membership" [(ngModel)]="share.membershipId" required>
<option *ngIf="!editForm.value.membership" [ngValue]="null" selected></option> <option *ngIf="!editForm.value.membership" [ngValue]="null" selected></option>
<option [ngValue]="membershipOption.id" *ngFor="let membershipOption of memberships; trackBy: trackMembershipById">{{membershipOption.admissionDocumentDate}}</option> <option [ngValue]="membershipOption.id" *ngFor="let membershipOption of memberships; trackBy: trackMembershipById">{{membershipOption.displayLabel}}</option>
</select> </select>
</div> </div>
<div [hidden]="!(editForm.controls.membership?.dirty && editForm.controls.membership?.invalid)"> <div [hidden]="!(editForm.controls.membership?.dirty && editForm.controls.membership?.invalid)">

View File

@ -19,8 +19,7 @@
<th jhiSortBy="valueDate"><span jhiTranslate="hsadminNgApp.share.valueDate">Value Date</span> <fa-icon [icon]="'sort'"></fa-icon></th> <th jhiSortBy="valueDate"><span jhiTranslate="hsadminNgApp.share.valueDate">Value Date</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="action"><span jhiTranslate="hsadminNgApp.share.action">Action</span> <fa-icon [icon]="'sort'"></fa-icon></th> <th jhiSortBy="action"><span jhiTranslate="hsadminNgApp.share.action">Action</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="quantity"><span jhiTranslate="hsadminNgApp.share.quantity">Quantity</span> <fa-icon [icon]="'sort'"></fa-icon></th> <th jhiSortBy="quantity"><span jhiTranslate="hsadminNgApp.share.quantity">Quantity</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="remark"><span jhiTranslate="hsadminNgApp.share.remark">Remark</span> <fa-icon [icon]="'sort'"></fa-icon></th> <th jhiSortBy="membershipDisplayLabel"><span jhiTranslate="hsadminNgApp.share.membership">Membership</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th jhiSortBy="membershipDisplayReference"><span jhiTranslate="hsadminNgApp.share.membership">Membership</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th></th> <th></th>
</tr> </tr>
</thead> </thead>
@ -31,10 +30,9 @@
<td>{{share.valueDate | date:'mediumDate'}}</td> <td>{{share.valueDate | date:'mediumDate'}}</td>
<td jhiTranslate="{{'hsadminNgApp.ShareAction.' + share.action}}">{{share.action}}</td> <td jhiTranslate="{{'hsadminNgApp.ShareAction.' + share.action}}">{{share.action}}</td>
<td>{{share.quantity}}</td> <td>{{share.quantity}}</td>
<td>{{share.remark}}</td>
<td> <td>
<div *ngIf="share.membershipId"> <div *ngIf="share.membershipId">
<a [routerLink]="['../membership', share.membershipId , 'view' ]" >{{share.membershipDisplayReference}}</a> <a [routerLink]="['../membership', share.membershipId , 'view' ]" >{{share.membershipDisplayLabel}}</a>
</div> </div>
</td> </td>
<td class="text-right"> <td class="text-right">

View File

@ -16,8 +16,8 @@ export interface IAsset {
action?: AssetAction; action?: AssetAction;
amount?: number; amount?: number;
remark?: string; remark?: string;
membershipDisplayReference?: string;
membershipId?: number; membershipId?: number;
membershipDisplayLabel?: string;
} }
export class Asset implements IAsset { export class Asset implements IAsset {
@ -28,7 +28,7 @@ export class Asset implements IAsset {
public action?: AssetAction, public action?: AssetAction,
public amount?: number, public amount?: number,
public remark?: string, public remark?: string,
public membershipDisplayReference?: string, public membershipId?: number,
public membershipId?: number public membershipDisplayLabel?: string
) {} ) {}
} }

View File

@ -32,6 +32,7 @@ export interface ICustomer {
remark?: string; remark?: string;
memberships?: IMembership[]; memberships?: IMembership[];
sepamandates?: ISepaMandate[]; sepamandates?: ISepaMandate[];
displayLabel?: string;
} }
export class Customer implements ICustomer { export class Customer implements ICustomer {
@ -53,6 +54,7 @@ export class Customer implements ICustomer {
public billingAddress?: string, public billingAddress?: string,
public remark?: string, public remark?: string,
public memberships?: IMembership[], public memberships?: IMembership[],
public sepamandates?: ISepaMandate[] public sepamandates?: ISepaMandate[],
public displayLabel?: string
) {} ) {}
} }

View File

@ -13,7 +13,8 @@ export interface IMembership {
assets?: IAsset[]; assets?: IAsset[];
customerPrefix?: string; customerPrefix?: string;
customerId?: number; customerId?: number;
membershipDisplayReference?: string; membershipDisplayLabel?: string;
displayLabel?: string;
} }
export class Membership implements IMembership { export class Membership implements IMembership {
@ -28,6 +29,7 @@ export class Membership implements IMembership {
public assets?: IAsset[], public assets?: IAsset[],
public customerPrefix?: string, public customerPrefix?: string,
public customerId?: number, public customerId?: number,
public membershipDisplayReference?: string public displayLabel?: string,
public membershipDisplayLabel?: string
) {} ) {}
} }

View File

@ -12,7 +12,7 @@ export interface IShare {
action?: ShareAction; action?: ShareAction;
quantity?: number; quantity?: number;
remark?: string; remark?: string;
membershipDisplayReference?: string; membershipDisplayLabel?: string;
membershipId?: number; membershipId?: number;
} }
@ -24,7 +24,7 @@ export class Share implements IShare {
public action?: ShareAction, public action?: ShareAction,
public quantity?: number, public quantity?: number,
public remark?: string, public remark?: string,
public membershipDisplayReference?: string, public membershipDisplayLabel?: string,
public membershipId?: number public membershipId?: number
) {} ) {}
} }

View File

@ -0,0 +1,167 @@
package org.hostsharing.hsadminng.service;
import org.apache.commons.lang3.RandomUtils;
import org.hostsharing.hsadminng.domain.Asset;
import org.hostsharing.hsadminng.domain.enumeration.AssetAction;
import org.hostsharing.hsadminng.repository.AssetRepository;
import org.hostsharing.hsadminng.service.dto.AssetDTO;
import org.hostsharing.hsadminng.service.mapper.AssetMapper;
import org.hostsharing.hsadminng.web.rest.errors.BadRequestAlertException;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import javax.persistence.EntityManager;
import java.math.BigDecimal;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowableOfType;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.*;
// HINT: In IntelliJ IDEA such unit test classes can be created with Shift-Ctrl-T.
// Do not forget to amend the class name (.e.g. ...UnitTest / ...IntTest)!
public class AssetServiceUnitTest {
@Rule
public MockitoRule mockitoRule = MockitoJUnit.rule();
@Mock
private EntityManager em;
@Mock
private AssetRepository assetRepository;
@Mock
private AssetValidator assetValidator; // needed for @InjectMocks assetService
@Mock
private AssetMapper assetMapper;
@InjectMocks
private AssetService assetService;
// HINT: Click outside of any test method (e.g. here) and use Ctrl-Shift-F10
// to run all tests from this test class. Use Ctrl-F5 to run the last execution again;
// 'execution' here can also apply to running the application, whatever ran last.
// HINT: In IntelliJ IDEA such test methods can be created with Alt-Insert.
@Test
public void deleteIsRejectedForAssetTransactions() {
// when
final Throwable throwException = catchThrowableOfType(() -> assetService.delete(RandomUtils.nextLong()), BadRequestAlertException.class);
// then
// HINT: When using auto-import for assertions (e.g. via Alt-Enter in IntelliJ IDEA),
// beware to use the correct candidate from org.assertj.core.api.Assertions.
assertThat(throwException).isEqualToComparingFieldByField(
new BadRequestAlertException("Asset transactions are immutable", "asset", "assetTransactionImmutable"));
}
@Test
public void saveShouldPersistValidTransactions() {
// given
final AssetDTO givenAssetDTO = givenAssetDTO(null, AssetAction.PAYMENT, anyPositiveAmout());
// HINT: given(...)...will...() can't be used for void methods, in that case use Mockito's do...() methods
doNothing().when(assetValidator).validate(givenAssetDTO);
// when
final AssetDTO returnedAssetDto = assetService.save(givenAssetDTO);
// then
verify(em).flush();
verify(em).refresh(any(Asset.class));
assertThat(returnedAssetDto).isEqualToIgnoringGivenFields(givenAssetDTO, "id");
}
@Test
public void saveShouldNotPersistInvalidTransactions() {
// given
final AssetDTO givenAssetDTO = givenAssetDTO(null, AssetAction.PAYMENT, anyNegativeAmount());
doThrow(new BadRequestAlertException("Some Dummy Test Violation", "asset", "assetInvalidTestDummy")).when(assetValidator).validate(givenAssetDTO);
// when
final Throwable throwException = catchThrowableOfType(() -> assetService.save(givenAssetDTO), BadRequestAlertException.class);
// then
assertThat(throwException).isEqualToComparingFieldByField(
new BadRequestAlertException("Some Dummy Test Violation", "asset", "assetInvalidTestDummy"));
}
@Test
public void saveShouldUpdateValidTransactions() {
// given
final AssetDTO givenAssetDTO = givenAssetDTO(anyNonNullId(), AssetAction.PAYMENT, anyPositiveAmout());
doNothing().when(assetValidator).validate(givenAssetDTO);
// when
final AssetDTO returnedAssetDto = assetService.save(givenAssetDTO);
// then
verify(em).flush();
verify(em).refresh(any(Asset.class));
assertThat(returnedAssetDto).isEqualToIgnoringGivenFields(givenAssetDTO, "id");
}
@Test
public void saveShouldNotUpdateInvalidTransactions() {
// given
final AssetDTO givenAssetDTO = givenAssetDTO(anyNonNullId(), AssetAction.PAYMENT, anyNegativeAmount());
// HINT: given(...) can't be used for void methods, in that case use Mockito's do...() methods
doThrow(new BadRequestAlertException("Some Dummy Test Violation", "asset", "assetInvalidTestDummy")).when(assetValidator).validate(givenAssetDTO);
// when
final Throwable throwException = catchThrowableOfType(() -> assetService.save(givenAssetDTO), BadRequestAlertException.class);
// then
assertThat(throwException).isEqualToComparingFieldByField(
new BadRequestAlertException("Some Dummy Test Violation", "asset", "assetInvalidTestDummy"));
}
// --- only test fixture code below ---
private long anyNonNullId() {
return RandomUtils.nextInt();
}
// HINT: This rather complicated setup indicates that the method AssetService::save breaks the single responsibility principle.
private AssetDTO givenAssetDTO(final Long id, final AssetAction givenAction, final BigDecimal givenQuantity) {
final AssetDTO givenAssetDTO = createAssetDTO(id, givenAction, givenQuantity);
// dto -> entity
final Asset givenAssetEntity = Mockito.mock(Asset.class);
given(assetMapper.toEntity(same(givenAssetDTO))).willReturn(givenAssetEntity);
// assetRepository.save(entity);
final Asset persistedAssetEntity = Mockito.mock(Asset.class);
given(assetRepository.save(same(givenAssetEntity))).willReturn(persistedAssetEntity);
// entity -> dto
AssetDTO persistedAssetDTO = createAssetDTO(id == null ? RandomUtils.nextLong() : id, givenAction, givenQuantity);
given(assetMapper.toDto(same(persistedAssetEntity))).willReturn(persistedAssetDTO);
return givenAssetDTO;
}
private AssetDTO createAssetDTO(Long id, AssetAction givenAction, BigDecimal givenAmount) {
final AssetDTO givenAssetDTO = new AssetDTO();
givenAssetDTO.setId(id);
givenAssetDTO.setAction(givenAction);
givenAssetDTO.setAmount(givenAmount);
return givenAssetDTO;
}
private BigDecimal anyPositiveAmout() {
return BigDecimal.valueOf(RandomUtils.nextInt()).add(new BigDecimal("0.1"));
}
private BigDecimal anyNegativeAmount() {
return anyPositiveAmout().negate();
}
}

View File

@ -15,12 +15,13 @@ import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule; import org.mockito.junit.MockitoRule;
import javax.persistence.EntityManager;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowableOfType; import static org.assertj.core.api.Assertions.catchThrowableOfType;
import static org.mockito.ArgumentMatchers.same; import static org.mockito.ArgumentMatchers.same;
import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.*;
import static org.mockito.Mockito.doThrow;
// HINT: In IntelliJ IDEA such unit test classes can be created with Shift-Ctrl-T. // HINT: In IntelliJ IDEA such unit test classes can be created with Shift-Ctrl-T.
@ -30,6 +31,9 @@ public class ShareServiceUnitTest {
@Rule @Rule
public MockitoRule mockitoRule = MockitoJUnit.rule(); public MockitoRule mockitoRule = MockitoJUnit.rule();
@Mock
private EntityManager em;
@Mock @Mock
private ShareRepository shareRepository; private ShareRepository shareRepository;
@ -70,6 +74,8 @@ public class ShareServiceUnitTest {
final ShareDTO returnedShareDto = shareService.save(givenShareDTO); final ShareDTO returnedShareDto = shareService.save(givenShareDTO);
// then // then
verify(em).flush();
verify(em).refresh(any(Share.class));
assertThat(returnedShareDto).isEqualToIgnoringGivenFields(givenShareDTO, "id"); assertThat(returnedShareDto).isEqualToIgnoringGivenFields(givenShareDTO, "id");
} }
@ -97,6 +103,8 @@ public class ShareServiceUnitTest {
final ShareDTO returnedShareDto = shareService.save(givenShareDTO); final ShareDTO returnedShareDto = shareService.save(givenShareDTO);
// then // then
verify(em).flush();
verify(em).refresh(any(Share.class));
assertThat(returnedShareDto).isEqualToIgnoringGivenFields(givenShareDTO, "id"); assertThat(returnedShareDto).isEqualToIgnoringGivenFields(givenShareDTO, "id");
} }

View File

@ -82,7 +82,8 @@ public class CustomerDTOUnitTest {
toJSonFieldDefinition("id", given.getId()) + "," + toJSonFieldDefinition("id", given.getId()) + "," +
toJSonFieldDefinition("reference", given.getReference()) + "," + toJSonFieldDefinition("reference", given.getReference()) + "," +
toJSonFieldDefinition("prefix", given.getPrefix()) + "," + toJSonFieldDefinition("prefix", given.getPrefix()) + "," +
toJSonFieldDefinition("name", given.getName()) + toJSonFieldDefinition("name", given.getName()) + "," +
toJSonFieldDefinition("displayLabel", given.getDisplayLabel()) +
"}"; "}";
assertEquals(expectedJSon, actual); assertEquals(expectedJSon, actual);
} }
@ -118,7 +119,7 @@ public class CustomerDTOUnitTest {
expected.setId(1234L); expected.setId(1234L);
expected.setContractualSalutation("Hallo Updated"); expected.setContractualSalutation("Hallo Updated");
expected.setBillingSalutation("Moin Updated"); expected.setBillingSalutation("Moin Updated");
assertThat(actual).isEqualToComparingFieldByField(expected); assertThat(actual).isEqualToIgnoringGivenFields(expected, "displayLabel");
} }
// --- only test fixture below --- // --- only test fixture below ---
@ -140,12 +141,11 @@ public class CustomerDTOUnitTest {
toJSonFieldDefinitionIfPresent("contractualAddress", dto.getContractualAddress()) + toJSonFieldDefinitionIfPresent("contractualAddress", dto.getContractualAddress()) +
toJSonFieldDefinitionIfPresent("billingSalutation", dto.getBillingSalutation()) + toJSonFieldDefinitionIfPresent("billingSalutation", dto.getBillingSalutation()) +
toJSonFieldDefinitionIfPresent("billingAddress", dto.getBillingAddress()) + toJSonFieldDefinitionIfPresent("billingAddress", dto.getBillingAddress()) +
toJSonFieldDefinitionIfPresent("remark", dto.getRemark()); toJSonFieldDefinitionIfPresent("remark", dto.getRemark()) +
toJSonFieldDefinitionIfPresent("displayLabel", dto.getDisplayLabel());
return "{" + json.substring(0, json.length() - 1) + "}"; return "{" + json.substring(0, json.length() - 1) + "}";
} }
private String toJSonFieldDefinition(String name, String value) { private String toJSonFieldDefinition(String name, String value) {
return inQuotes(name) + ":" + (value != null ? inQuotes(value) : "null"); return inQuotes(name) + ":" + (value != null ? inQuotes(value) : "null");
} }
@ -186,6 +186,7 @@ public class CustomerDTOUnitTest {
given.setBillingAddress("Noch eine Adresse"); given.setBillingAddress("Noch eine Adresse");
given.setBillingSalutation("Moin"); given.setBillingSalutation("Moin");
given.setRemark("Eine Bemerkung"); given.setRemark("Eine Bemerkung");
given.setDisplayLabel("Display Label");
return given; return given;
} }
} }

View File

@ -154,7 +154,7 @@ public class ShareDTOUnitTest {
givenDTO.setAction(ShareAction.SUBSCRIPTION); givenDTO.setAction(ShareAction.SUBSCRIPTION);
givenDTO.setQuantity(3); givenDTO.setQuantity(3);
givenDTO.setDocumentDate(LocalDate.parse("2019-04-22")); givenDTO.setDocumentDate(LocalDate.parse("2019-04-22"));
givenDTO.setMembershipDisplayReference("2019-04-21"); // TODO: why is this not a LocalDate? givenDTO.setMembershipDisplayLabel("2019-04-21"); // TODO: why is this not a LocalDate?
givenDTO.setValueDate(LocalDate.parse("2019-04-30")); givenDTO.setValueDate(LocalDate.parse("2019-04-30"));
givenDTO.setRemark("Some Remark"); givenDTO.setRemark("Some Remark");
return givenDTO; return givenDTO;

View File

@ -253,7 +253,7 @@ public class MembershipResourceIntTest {
.andExpect(jsonPath("$.[*].cancellationDocumentDate").value(hasItem(DEFAULT_CANCELLATION_DOCUMENT_DATE.toString()))) .andExpect(jsonPath("$.[*].cancellationDocumentDate").value(hasItem(DEFAULT_CANCELLATION_DOCUMENT_DATE.toString())))
.andExpect(jsonPath("$.[*].memberFromDate").value(hasItem(DEFAULT_MEMBER_FROM_DATE.toString()))) .andExpect(jsonPath("$.[*].memberFromDate").value(hasItem(DEFAULT_MEMBER_FROM_DATE.toString())))
.andExpect(jsonPath("$.[*].memberUntilDate").value(hasItem(DEFAULT_MEMBER_UNTIL_DATE.toString()))) .andExpect(jsonPath("$.[*].memberUntilDate").value(hasItem(DEFAULT_MEMBER_UNTIL_DATE.toString())))
.andExpect(jsonPath("$.[*].remark").value(hasItem(DEFAULT_REMARK.toString()))); .andExpect(jsonPath("$.[*].remark").value(hasItem(DEFAULT_REMARK)));
} }
@Test @Test
@ -271,7 +271,7 @@ public class MembershipResourceIntTest {
.andExpect(jsonPath("$.cancellationDocumentDate").value(DEFAULT_CANCELLATION_DOCUMENT_DATE.toString())) .andExpect(jsonPath("$.cancellationDocumentDate").value(DEFAULT_CANCELLATION_DOCUMENT_DATE.toString()))
.andExpect(jsonPath("$.memberFromDate").value(DEFAULT_MEMBER_FROM_DATE.toString())) .andExpect(jsonPath("$.memberFromDate").value(DEFAULT_MEMBER_FROM_DATE.toString()))
.andExpect(jsonPath("$.memberUntilDate").value(DEFAULT_MEMBER_UNTIL_DATE.toString())) .andExpect(jsonPath("$.memberUntilDate").value(DEFAULT_MEMBER_UNTIL_DATE.toString()))
.andExpect(jsonPath("$.remark").value(DEFAULT_REMARK.toString())); .andExpect(jsonPath("$.remark").value(DEFAULT_REMARK));
} }
@Test @Test