use of eu.ggnet.dwoss.rules.AddressType.SHIPPING in project dwoss by gg-net.
the class CustomerTestUtil method testGetViolationMessageSimpleConsumer.
@Test
public void testGetViolationMessageSimpleConsumer() {
Customer simpleConsumer = makeValidSimpleConsumer();
simpleConsumer.getCompanies().add(makeValidCompany());
assertThat(simpleConsumer.getViolationMessage()).as("SimpleConsumer with company is not valid").isNotNull();
simpleConsumer.getCompanies().clear();
assertThat(simpleConsumer.getViolationMessage()).as("SimpleConsumer with contact and without company is valid").isNull();
simpleConsumer.getContacts().clear();
assertThat(simpleConsumer.getViolationMessage()).as("SimpleConsumer without contact is invalid").isNotNull();
simpleConsumer = makeValidSimpleConsumer();
simpleConsumer.getAddressLabels().remove(simpleConsumer.getAddressLabels().stream().filter(label -> label.getType() == AddressType.INVOICE).findAny().get());
assertThat(simpleConsumer.getViolationMessage()).as("Removal of any AddressLabel of type INVOICE from SimpleConsumer is invalid").isNotNull();
simpleConsumer = makeValidSimpleConsumer();
simpleConsumer.getAddressLabels().add(new AddressLabel(null, simpleConsumer.getContacts().get(0), simpleConsumer.getContacts().get(0).getAddresses().get(0), INVOICE));
assertThat(simpleConsumer.getViolationMessage()).as("SimpleConsumer with two addressLabels of type INVOICE is invalid").isNull();
simpleConsumer = makeValidSimpleConsumer();
simpleConsumer.getAddressLabels().add(new AddressLabel(null, simpleConsumer.getContacts().get(0), simpleConsumer.getContacts().get(0).getAddresses().get(0), SHIPPING));
assertThat(simpleConsumer.getViolationMessage()).as("SimpleConsumer with two AddressLabels of unequal types is valid").isNull();
simpleConsumer.getAddressLabels().add(new AddressLabel(null, simpleConsumer.getContacts().get(0), simpleConsumer.getContacts().get(0).getAddresses().get(0), SHIPPING));
assertThat(simpleConsumer.getViolationMessage()).as("SimpleConsumer with three AddressLabels is invalid").isNotNull();
simpleConsumer = makeValidSimpleConsumer();
simpleConsumer.getContacts().clear();
Contact invalidContact = new Contact(Sex.MALE, true, null, "invalid", "");
assertThat(invalidContact.getViolationMessage()).as("Contact without lastName is invalid").isNotNull();
simpleConsumer.getContacts().add(invalidContact);
assertThat(simpleConsumer.getViolationMessage()).as("SimpleConsumer with invalid contact is invalid").isNotNull();
simpleConsumer = makeValidSimpleConsumer();
simpleConsumer.getContacts().get(0).getAddresses().clear();
assertThat(simpleConsumer.getViolationMessage()).as("SimpleConsumer without Address is invalid").isNotNull();
simpleConsumer = makeValidSimpleConsumer();
simpleConsumer.getContacts().get(0).getCommunications().clear();
assertThat(simpleConsumer.getViolationMessage()).as("SimpleConsumer without communications is invalid").isNotNull();
simpleConsumer = makeValidSimpleConsumer();
Communication invalidEmailCommunication = new Communication(Type.EMAIL, false);
simpleConsumer.getContacts().get(0).getCommunications().clear();
simpleConsumer.getContacts().get(0).getCommunications().add(invalidEmailCommunication);
assertThat(simpleConsumer.getViolationMessage()).as("SimpleConsumer with invalid Communication is invalid").isNotNull();
simpleConsumer = makeValidSimpleConsumer();
Address invalidAddress = new Address();
invalidAddress.setIsoCountry(Locale.GERMANY);
invalidAddress.setCity("city");
invalidAddress.setStreet("street");
invalidAddress.setZipCode("");
assertThat(invalidAddress.getViolationMessage()).as("Invalid Address is invalid").isNotNull();
simpleConsumer.getContacts().get(0).getAddresses().clear();
simpleConsumer.getContacts().get(0).getAddresses().add(invalidAddress);
assertThat(simpleConsumer.getViolationMessage()).as("SimpleConsumer with invalid Address is invalid").isNotNull();
}
Aggregations