Search in sources :

Example 1 with INVOICE

use of eu.ggnet.dwoss.rules.AddressType.INVOICE 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();
}
Also used : Type(eu.ggnet.dwoss.customer.ee.entity.Communication.Type) Arrays(java.util.Arrays) AddressLabel(eu.ggnet.dwoss.customer.ee.entity.projection.AddressLabel) eu.ggnet.dwoss.customer.ee.entity(eu.ggnet.dwoss.customer.ee.entity) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Sex(eu.ggnet.dwoss.customer.ee.entity.Contact.Sex) Test(org.junit.Test) AddressType(eu.ggnet.dwoss.rules.AddressType) CustomerTestUtil(eu.ggnet.dwoss.customer.test.CustomerTestUtil) StringUtils(org.apache.commons.lang3.StringUtils) CustomerFlag(eu.ggnet.dwoss.rules.CustomerFlag) INVOICE(eu.ggnet.dwoss.rules.AddressType.INVOICE) GERMANY(java.util.Locale.GERMANY) Locale(java.util.Locale) SHIPPING(eu.ggnet.dwoss.rules.AddressType.SHIPPING) AddressLabel(eu.ggnet.dwoss.customer.ee.entity.projection.AddressLabel) Test(org.junit.Test)

Aggregations

eu.ggnet.dwoss.customer.ee.entity (eu.ggnet.dwoss.customer.ee.entity)1 Type (eu.ggnet.dwoss.customer.ee.entity.Communication.Type)1 Sex (eu.ggnet.dwoss.customer.ee.entity.Contact.Sex)1 AddressLabel (eu.ggnet.dwoss.customer.ee.entity.projection.AddressLabel)1 CustomerTestUtil (eu.ggnet.dwoss.customer.test.CustomerTestUtil)1 AddressType (eu.ggnet.dwoss.rules.AddressType)1 INVOICE (eu.ggnet.dwoss.rules.AddressType.INVOICE)1 SHIPPING (eu.ggnet.dwoss.rules.AddressType.SHIPPING)1 CustomerFlag (eu.ggnet.dwoss.rules.CustomerFlag)1 Arrays (java.util.Arrays)1 Locale (java.util.Locale)1 GERMANY (java.util.Locale.GERMANY)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Test (org.junit.Test)1