MemberAssetTest Ã+ bugfix in MemberAsset (database-mapping)

This commit is contained in:
Michael Hoennig 2017-04-16 11:55:26 +02:00
parent cc2a17c81a
commit 7894bc88aa
2 changed files with 48 additions and 6 deletions

View File

@ -24,7 +24,7 @@ public class MemberAsset implements Serializable {
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "member_share_id", columnDefinition = "integer") @Column(name = "member_asset_id", columnDefinition = "integer")
private long id; private long id;
@JoinColumn(name = "bp_id", columnDefinition = "integer", nullable = false) @JoinColumn(name = "bp_id", columnDefinition = "integer", nullable = false)
@ -36,7 +36,7 @@ public class MemberAsset implements Serializable {
private Date date; private Date date;
@Column(name="action", nullable = false) @Column(name="action", nullable = false)
private ShareAction action; private AssetAction action;
@Column(name="amount", nullable = false) @Column(name="amount", nullable = false)
private BigDecimal amount; private BigDecimal amount;
@ -76,16 +76,14 @@ public class MemberAsset implements Serializable {
this.date = date; this.date = date;
} }
public ShareAction getAction() { public AssetAction getAction() {
return action; return action;
} }
public void setAction(ShareAction action) { public void setAction(AssetAction action) {
this.action = action; this.action = action;
} }
public String getComment() { public String getComment() {
return comment; return comment;
} }
@ -94,4 +92,10 @@ public class MemberAsset implements Serializable {
this.comment = comment; this.comment = comment;
} }
@Override
public String toString() {
return "MemberAsset [id=" + id + ", customer=" + (customer!=null ? customer.getName() : null) + ", date=" + date + ", action=" + action
+ ", amount=" + amount + ", comment=" + comment + "]";
}
} }

View File

@ -0,0 +1,38 @@
package de.hsadmin.bo.customer;
import static org.junit.Assert.assertEquals;
import java.math.BigDecimal;
import org.joda.time.LocalDate;
import org.junit.Test;
import de.hsadmin.dao.customer.CustomerDaoTest;
import de.hsadmin.test.JpaBasedTest;
public class MemberAssetTest extends JpaBasedTest {
@Test
public void testMemberAssetAgainstDatabase() {
// given
Customer customer = store(CustomerDaoTest.createNewCustomer(10001, "testCust"));
// when
MemberAsset newEntity = store(createNewMemberAsset(customer));
MemberAsset foundEntity = getEM().find(MemberAsset.class, newEntity.getId());
// then
assertEquals(newEntity.toString(), foundEntity.toString());
}
public static MemberAsset createNewMemberAsset(final Customer customer) {
MemberAsset newEntity = new MemberAsset();
newEntity.setCustomer(customer);
newEntity.setAction(AssetAction.PAYMENT);
newEntity.setDate(new LocalDate(2017, 4, 13).toDate());
newEntity.setAmount(new BigDecimal("1234.56"));
newEntity.setComment("test comment");
return newEntity;
}
}