From cc2a17c81a98d22fedfe5a9d2fd10bacfe14391c Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Sat, 15 Apr 2017 15:54:42 +0200 Subject: [PATCH] Bugfixes nach CLI-basierten Integrationstest im TomEE2 --- .../de/hsadmin/bo/customer/MemberShare.java | 2 +- .../service/customer/MemberShareVO.java | 3 +- .../service/customer/MemberShareVOTest.java | 41 ++++++++++++++++--- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/cust-services/src/main/java/de/hsadmin/bo/customer/MemberShare.java b/cust-services/src/main/java/de/hsadmin/bo/customer/MemberShare.java index 73d0d12..20df8a1 100644 --- a/cust-services/src/main/java/de/hsadmin/bo/customer/MemberShare.java +++ b/cust-services/src/main/java/de/hsadmin/bo/customer/MemberShare.java @@ -93,7 +93,7 @@ public class MemberShare implements Serializable { @Override public String toString() { - return "MemberShare [id=" + id + ", customer=" + customer.getName() + ", date=" + date + ", action=" + action + return "MemberShare [id=" + id + ", customer=" + (customer!=null ? customer.getName() : null) + ", date=" + date + ", action=" + action + ", quantity=" + quantity + ", comment=" + comment + "]"; } } diff --git a/cust-services/src/main/java/de/hsadmin/service/customer/MemberShareVO.java b/cust-services/src/main/java/de/hsadmin/service/customer/MemberShareVO.java index d26abfb..c511716 100644 --- a/cust-services/src/main/java/de/hsadmin/service/customer/MemberShareVO.java +++ b/cust-services/src/main/java/de/hsadmin/service/customer/MemberShareVO.java @@ -10,7 +10,6 @@ import de.hsadmin.module.property.ReadWritePolicy; import de.hsadmin.module.property.Required; import de.hsadmin.module.property.Search; import de.hsadmin.module.property.SearchPolicy; -import de.hsadmin.module.property.mapping.DefaultEnumParameterMapMapper; import de.hsadmin.module.property.mapping.DefaultEnumPersistentObjectMapper; import de.hsadmin.module.property.mapping.DefaultStringParameterMapMapper; import de.hsadmin.module.property.mapping.Mapping; @@ -27,7 +26,7 @@ public class MemberShareVO extends AbstractVO implements ValueObject { private String customer; @Mapping(boMapping=DefaultEnumPersistentObjectMapper.class, - rpcMapping=DefaultEnumParameterMapMapper.class, + rpcMapping=DefaultStringParameterMapMapper.class, boMappingPath="customer.name") @ReadWrite(ReadWritePolicy.WRITEONCE) @Required(true) diff --git a/cust-services/src/test/java/de/hsadmin/service/customer/MemberShareVOTest.java b/cust-services/src/test/java/de/hsadmin/service/customer/MemberShareVOTest.java index 360f8b6..bcbd10a 100644 --- a/cust-services/src/test/java/de/hsadmin/service/customer/MemberShareVOTest.java +++ b/cust-services/src/test/java/de/hsadmin/service/customer/MemberShareVOTest.java @@ -1,21 +1,20 @@ package de.hsadmin.service.customer; +import static junitparams.JUnitParamsRunner.$; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; -import org.h2.command.ddl.CreateAggregate; - -import static junitparams.JUnitParamsRunner.$; - import org.joda.time.LocalDate; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; - +import de.hsadmin.bo.customer.MemberShare; +import de.hsadmin.bo.customer.MemberShareTest; import de.hsadmin.common.error.TechnicalException; import de.hsadmin.common.error.UserException; +import de.hsadmin.dao.customer.CustomerDaoTest; import de.hsadmin.module.impl.ValidationDelegate; import de.hsadmin.module.property.Property; import junitparams.JUnitParamsRunner; @@ -34,6 +33,8 @@ public class MemberShareVOTest { private static final int INITIAL_QUANTITY = 4; + private static final String INITIALIZED_MEMBER_SHARE_VO_AS_STRING = "MemberShareVO [customer=initCust, action=SUBSCRIPTION, date=Thu Dec 26 00:00:00 CET 1996, quantity=4, comment=initial comment]"; + private final ValidationDelegate validator = new ValidationDelegate(); @Rule @@ -51,7 +52,35 @@ public class MemberShareVOTest { // koennten auch andere Tests fehlschlagen. // Wenn Felder aus dem toString() herausgenommen werden, // koennten sogar andere Tests stillschweigend wirkungslos werden! - assertEquals("MemberShareVO [customer=initCust, action=SUBSCRIPTION, date=Thu Dec 26 00:00:00 CET 1996, quantity=4, comment=initial comment]", vo.toString()); + assertEquals(INITIALIZED_MEMBER_SHARE_VO_AS_STRING, vo.toString()); + } + + @Test + public void copyPropertiesFromPersistentObject() throws TechnicalException, UserException { + // given + MemberShare bo = MemberShareTest.createNewMemberShare(CustomerDaoTest.createNewCustomer(10001, "testCust")); + + // when + MemberShareVO vo = new MemberShareVO(); + vo.copyPropertiesFromPersistentObject(bo); + + // then + assertEquals("MemberShareVO [customer=testCust, action=SUBSCRIPTION, date=Thu Apr 13 00:00:00 CEST 2017, quantity=5, comment=test comment]", + vo.toString()); + } + + @Test + public void copyPropertiesToPersistentObject() throws TechnicalException, UserException { + // given + MemberShareVO vo = givenInitializedMemberShareVOForCustomer(INITIAL_CUSTOMER); + + // when + MemberShare bo = new MemberShare(); + vo.copyPropertiesToPersistentObject(bo); + + // then (Achtung: customer muss vom Service umkopiert werden) + assertEquals("MemberShare [id=0, customer=null, date=Thu Dec 26 00:00:00 CET 1996, action=SUBSCRIPTION, quantity=4, comment=initial comment]", + bo.toString()); } // --- generic tests ---