MemberShareVO erstellt
This commit is contained in:
parent
de7b440edf
commit
d7e5379948
@ -0,0 +1,90 @@
|
|||||||
|
package de.hsadmin.service.customer;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import de.hsadmin.common.error.TechnicalException;
|
||||||
|
import de.hsadmin.module.ValueObject;
|
||||||
|
import de.hsadmin.module.impl.AbstractVO;
|
||||||
|
import de.hsadmin.module.property.ReadWrite;
|
||||||
|
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.DefaultStringParameterMapMapper;
|
||||||
|
import de.hsadmin.module.property.mapping.Mapping;
|
||||||
|
import de.hsadmin.module.property.mapping.ReferredStringPersistentObjectMapper;
|
||||||
|
|
||||||
|
public class MemberShareVO extends AbstractVO implements ValueObject {
|
||||||
|
|
||||||
|
@Mapping(boMapping=ReferredStringPersistentObjectMapper.class,
|
||||||
|
rpcMapping=DefaultStringParameterMapMapper.class,
|
||||||
|
boMappingPath="customer.name")
|
||||||
|
@ReadWrite(ReadWritePolicy.WRITEONCE)
|
||||||
|
@Required(true)
|
||||||
|
@Search(SearchPolicy.EQUALS)
|
||||||
|
private String customer;
|
||||||
|
|
||||||
|
@ReadWrite(ReadWritePolicy.WRITEONCE)
|
||||||
|
@Required(true)
|
||||||
|
@Search(SearchPolicy.EQUALS)
|
||||||
|
private String action;
|
||||||
|
|
||||||
|
@ReadWrite(ReadWritePolicy.WRITEONCE)
|
||||||
|
@Required(true)
|
||||||
|
@Search(SearchPolicy.COMPARE)
|
||||||
|
private Date date;
|
||||||
|
|
||||||
|
@ReadWrite(ReadWritePolicy.WRITEONCE)
|
||||||
|
@Required(true)
|
||||||
|
@Search(SearchPolicy.COMPARE)
|
||||||
|
private Integer quantity;
|
||||||
|
|
||||||
|
@ReadWrite(ReadWritePolicy.WRITEONCE)
|
||||||
|
@Required(true)
|
||||||
|
@Search(SearchPolicy.LIKE)
|
||||||
|
private String comment;
|
||||||
|
|
||||||
|
public MemberShareVO() throws TechnicalException {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCustomer() {
|
||||||
|
return customer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCustomer(String customer) {
|
||||||
|
this.customer = customer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAction() {
|
||||||
|
return action;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAction(String action) {
|
||||||
|
this.action = action;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getDate() {
|
||||||
|
return date;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDate(Date date) {
|
||||||
|
this.date = date;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getQuantity() {
|
||||||
|
return quantity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setQuantity(Integer quantity) {
|
||||||
|
this.quantity = quantity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getComment() {
|
||||||
|
return comment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setComment(String comment) {
|
||||||
|
this.comment = comment;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,146 @@
|
|||||||
|
package de.hsadmin.service.customer;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
|
||||||
|
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.common.error.TechnicalException;
|
||||||
|
import de.hsadmin.common.error.UserException;
|
||||||
|
import de.hsadmin.module.impl.ValidationDelegate;
|
||||||
|
import de.hsadmin.module.property.Property;
|
||||||
|
import junitparams.JUnitParamsRunner;
|
||||||
|
import junitparams.Parameters;
|
||||||
|
|
||||||
|
@RunWith(JUnitParamsRunner.class)
|
||||||
|
public class MemberShareVOTest {
|
||||||
|
|
||||||
|
private static final String INITIAL_COMMENT = "initial comment";
|
||||||
|
|
||||||
|
private static final LocalDate INITIAL_DATE = new LocalDate(1996, 12, 26);
|
||||||
|
|
||||||
|
private static final String INITIAL_ACTION = "SUBSCRIPTION";
|
||||||
|
|
||||||
|
private static final String INITIAL_CUSTOMER = "initCust";
|
||||||
|
|
||||||
|
private static final int INITIAL_QUANTITY = 4;
|
||||||
|
|
||||||
|
private final ValidationDelegate<MemberShareVO> validator = new ValidationDelegate<MemberShareVO>();
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public final ExpectedException exception = ExpectedException.none();
|
||||||
|
|
||||||
|
// --- tests ---
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Parameters(method = "properties")
|
||||||
|
public void propertyIsRequired(final String propertyName) throws UserException, TechnicalException {
|
||||||
|
MemberShareVO initializedMemberShareVO = givenInitializedMemberShareVO();
|
||||||
|
initializedMemberShareVO.get(propertyName).setValue(null);
|
||||||
|
assertInitialPropertyValueIsNull(initializedMemberShareVO, propertyName);
|
||||||
|
assertPrototypeIsNotCreateable(initializedMemberShareVO, "MSG_REQUIRED_FIELD: " + propertyName);
|
||||||
|
}
|
||||||
|
public static Object[] properties() {
|
||||||
|
return $(
|
||||||
|
// nur die Properties auffuehren, die 'required' sind
|
||||||
|
"customer",
|
||||||
|
"action",
|
||||||
|
"date",
|
||||||
|
"quantity",
|
||||||
|
"comment"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Parameters(method = "propertiesWithInitialValues")
|
||||||
|
public void propertyIsCreatable(final String propertyName, final Object initialValue) throws UserException, TechnicalException {
|
||||||
|
MemberShareVO initializedMemberShareVO = givenInitializedMemberShareVO();
|
||||||
|
assertInitialPropertyValue(initializedMemberShareVO, propertyName, initialValue);
|
||||||
|
assertPrototypeIsCreateable(initializedMemberShareVO);
|
||||||
|
}
|
||||||
|
public static Object[] propertiesWithInitialValues() {
|
||||||
|
return $(
|
||||||
|
// nur die Properties auffuehren, die 'creatable' sind
|
||||||
|
$("customer", INITIAL_CUSTOMER),
|
||||||
|
$("action", INITIAL_ACTION),
|
||||||
|
$("date", INITIAL_DATE.toDate()),
|
||||||
|
$("quantity", + INITIAL_QUANTITY),
|
||||||
|
$("comment", INITIAL_COMMENT)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Parameters(method = "propertiesWithChangedValues")
|
||||||
|
public void propertyIsNotUpdateable(final String propertyName, final Object changedValue) throws UserException, TechnicalException {
|
||||||
|
MemberShareVO initializedMemberShareVO = givenInitializedMemberShareVO();
|
||||||
|
assertChangedPropertyValue(initializedMemberShareVO, propertyName, changedValue);
|
||||||
|
assertPrototypeIsNotUpdateable(initializedMemberShareVO, "MSG_NO_FIELD_WRITEACCESS: " + propertyName);
|
||||||
|
}
|
||||||
|
public static Object[] propertiesWithChangedValues() {
|
||||||
|
return $(
|
||||||
|
// nur die Properties auffuehren, die NICHT 'updateable' sind
|
||||||
|
$("customer", INITIAL_CUSTOMER + "Changed"),
|
||||||
|
$("action", "UN" + INITIAL_ACTION),
|
||||||
|
$("date", INITIAL_DATE.plusDays(1).toDate()),
|
||||||
|
$("quantity", + INITIAL_QUANTITY * 2),
|
||||||
|
$("comment", INITIAL_COMMENT + "Changed")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// === test fixture ===
|
||||||
|
|
||||||
|
private MemberShareVO givenInitializedMemberShareVO() throws TechnicalException, UserException {
|
||||||
|
MemberShareVO memberShareVO = new MemberShareVO();
|
||||||
|
memberShareVO.setCustomer(INITIAL_CUSTOMER);
|
||||||
|
memberShareVO.setAction(INITIAL_ACTION);
|
||||||
|
memberShareVO.setDate( INITIAL_DATE.toDate() );
|
||||||
|
memberShareVO.setQuantity(INITIAL_QUANTITY);
|
||||||
|
memberShareVO.setComment(INITIAL_COMMENT);
|
||||||
|
memberShareVO.initPropertyValues();
|
||||||
|
return memberShareVO;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertInitialPropertyValueIsNull(final MemberShareVO memberShareVO, final String propertyName) throws UserException, TechnicalException {
|
||||||
|
assertNull(memberShareVO.get(propertyName).getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertInitialPropertyValue(final MemberShareVO memberShareVO, final String propertyName, final Object expectedValue) throws UserException, TechnicalException {
|
||||||
|
assertEquals(expectedValue, memberShareVO.get(propertyName).getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T> void assertChangedPropertyValue(final MemberShareVO memberShareVO, final String propertyName, final T changedValue) throws UserException, TechnicalException {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Property<T> customerProp = (Property<T>) memberShareVO.get(propertyName);
|
||||||
|
customerProp.setValue(changedValue);
|
||||||
|
assertEquals(changedValue, customerProp.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertPrototypeIsCreateable(final MemberShareVO memberShareVO) throws UserException, TechnicalException {
|
||||||
|
validator.checkPrototypeIsCreateable(memberShareVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertPrototypeIsNotCreateable(final MemberShareVO someMemberShareVO, final String expectedMessage) throws UserException, TechnicalException {
|
||||||
|
exception.expect(UserException.class);
|
||||||
|
exception.expectMessage(expectedMessage);
|
||||||
|
validator.checkPrototypeIsCreateable(someMemberShareVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertPrototypeIsNotUpdateable(final MemberShareVO someMemberShareVO, final String expectedMessage) throws UserException, TechnicalException {
|
||||||
|
exception.expect(UserException.class);
|
||||||
|
exception.expectMessage(expectedMessage);
|
||||||
|
validator.checkPrototypeIsUpdateable(someMemberShareVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDate asDate(String input) {
|
||||||
|
return LocalDate.parse(input);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user