Search in sources :

Example 16 with AddressLabel

use of eu.ggnet.dwoss.customer.ee.entity.projection.AddressLabel in project dwoss by gg-net.

the class CustomerTestUtil method testGetViolationMessageSimpleBusinessCustomer.

@Test
public void testGetViolationMessageSimpleBusinessCustomer() {
    Customer simpleBusinessCustomer = makeValidSimpleBusiness();
    simpleBusinessCustomer.getCompanies().clear();
    assertThat(simpleBusinessCustomer.getViolationMessage()).as("SimpleBusinessCustomer without companies is invalid").isNotNull();
    simpleBusinessCustomer = makeValidSimpleBusiness();
    simpleBusinessCustomer.getContacts().add(makeValidContact());
    assertThat(simpleBusinessCustomer.getViolationMessage()).as("SimpleBusinessCustomer with a contact is invalid").isNotNull();
    simpleBusinessCustomer = makeValidSimpleBusiness();
    simpleBusinessCustomer.getAddressLabels().remove(simpleBusinessCustomer.getAddressLabels().stream().findAny().get());
    assertThat(simpleBusinessCustomer.getViolationMessage()).as("Removal of any AddressLabel from a SimpleBusinessCustomer results invalid").isNotNull();
    simpleBusinessCustomer = makeValidSimpleBusiness();
    simpleBusinessCustomer.getAddressLabels().add(new AddressLabel(simpleBusinessCustomer.getCompanies().get(0), null, simpleBusinessCustomer.getCompanies().get(0).getAddresses().get(0), SHIPPING));
    simpleBusinessCustomer.getAddressLabels().add(new AddressLabel(simpleBusinessCustomer.getCompanies().get(0), null, simpleBusinessCustomer.getCompanies().get(0).getAddresses().get(0), SHIPPING));
    assertThat(simpleBusinessCustomer.getViolationMessage()).as("Addition of two AddressLabels to a BusinessCustomer always results invalid").isNotNull();
    simpleBusinessCustomer = makeValidSimpleBusiness();
    Company invalidCompany = new Company("", 0, true, "634855");
    assertThat(invalidCompany.getViolationMessage()).as("Company without a Name is invalid").isNotNull();
    simpleBusinessCustomer.getCompanies().add(invalidCompany);
    assertThat(simpleBusinessCustomer.getViolationMessage()).as("Adding an invalid Company to a SimpleBusinessCustomer results invalid").isNotNull();
    simpleBusinessCustomer = makeValidSimpleBusiness();
    simpleBusinessCustomer.getCompanies().get(0).getContacts().get(0).getCommunications().clear();
    assertThat(simpleBusinessCustomer.getViolationMessage()).as("SimpleBusinessCustomer without Communications is invalid").isNotNull();
}
Also used : AddressLabel(eu.ggnet.dwoss.customer.ee.entity.projection.AddressLabel) Test(org.junit.Test)

Example 17 with AddressLabel

use of eu.ggnet.dwoss.customer.ee.entity.projection.AddressLabel in project dwoss by gg-net.

the class CustomerTestUtil method testGetSimpleViolationMessageSimpleBusinessCustomer.

@Test
public void testGetSimpleViolationMessageSimpleBusinessCustomer() {
    Customer simpleBusinessCustomer = makeValidSimpleBusiness();
    simpleBusinessCustomer.getContacts().add(makeValidContact());
    assertThat(simpleBusinessCustomer.getSimpleViolationMessage()).as("SimpleBusinessCustomer with a Contact is invalid").isNotNull();
    simpleBusinessCustomer = makeValidSimpleBusiness();
    Company validCompany = makeValidCompany();
    simpleBusinessCustomer.getCompanies().add(validCompany);
    assertThat(simpleBusinessCustomer.getSimpleViolationMessage()).as("SimpleBusinessCustomer with more than one Company is invalid").isNotNull();
    simpleBusinessCustomer = makeValidSimpleBusiness();
    simpleBusinessCustomer.getAddressLabels().clear();
    assertThat(simpleBusinessCustomer.getSimpleViolationMessage()).as("SimpleBusinessCustomer without AddressLabel of Type INVOICE is invalid").isNotNull();
    simpleBusinessCustomer = makeValidSimpleBusiness();
    AddressLabel addressLabel = new AddressLabel(simpleBusinessCustomer.getCompanies().stream().findAny().get(), null, simpleBusinessCustomer.getCompanies().stream().findAny().get().getAddresses().stream().findAny().get(), SHIPPING);
    simpleBusinessCustomer.getAddressLabels().add(addressLabel);
    assertThat(simpleBusinessCustomer.getSimpleViolationMessage()).as("SimpleBusinessCustomer with more than one AddressLabel is invalid").isNotNull();
    simpleBusinessCustomer = makeValidSimpleBusiness();
    simpleBusinessCustomer.getFlags().add(CustomerFlag.values()[(int) Math.random() * (CustomerFlag.values().length - 1)]);
    assertThat(simpleBusinessCustomer.getSimpleViolationMessage()).as("SimpleBusinessCustomer with a flag is invalid").isNotNull();
    simpleBusinessCustomer = makeValidSimpleBusiness();
    simpleBusinessCustomer.setKeyAccounter("keyAccouter");
    assertThat(simpleBusinessCustomer.getSimpleViolationMessage()).as("SimpleBusinessCustomer with a keyAccounter is invalid").isNotNull();
    simpleBusinessCustomer = makeValidSimpleBusiness();
    simpleBusinessCustomer.getMandatorMetadata().add(new MandatorMetadata());
    assertThat(simpleBusinessCustomer.getSimpleViolationMessage()).as("SimpleBusinessCustomer with MandatorMetadata is invalid").isNotNull();
    simpleBusinessCustomer = makeValidSimpleBusiness();
    simpleBusinessCustomer.getCompanies().get(0).getContacts().get(0).getCommunications().add(makeValidCommunication(FACEBOOK, "username"));
    assertThat(simpleBusinessCustomer.getSimpleViolationMessage()).as("SimpleBusinessCustomer with a FACEBOOK Communication is invalid").isNotNull();
    simpleBusinessCustomer = makeValidSimpleBusiness();
    simpleBusinessCustomer.getCompanies().get(0).getContacts().get(0).getCommunications().add(makeValidCommunication(FAX, "1345678"));
    assertThat(simpleBusinessCustomer.getSimpleViolationMessage()).as("SimpleBusinessCustomer with a FAX Communication is invalid").isNotNull();
    simpleBusinessCustomer = makeValidSimpleBusiness();
    simpleBusinessCustomer.getCompanies().get(0).getContacts().get(0).getCommunications().add(makeValidCommunication(ICQ, "12345678"));
    assertThat(simpleBusinessCustomer.getSimpleViolationMessage()).as("SimpleBusinessCustomer with an ICQ Communication is invalid").isNotNull();
    simpleBusinessCustomer = makeValidSimpleBusiness();
    simpleBusinessCustomer.getCompanies().get(0).getContacts().get(0).getCommunications().add(makeValidCommunication(SKYPE, "skypeUser16"));
    assertThat(simpleBusinessCustomer.getSimpleViolationMessage()).as("SimpleBusinessCustomer with a SKYPE Communication is invalid").isNotNull();
    simpleBusinessCustomer = makeValidSimpleBusiness();
    simpleBusinessCustomer.getCompanies().get(0).getContacts().get(0).getCommunications().clear();
    simpleBusinessCustomer.getCompanies().get(0).getCommunications().add(makeValidCommunication(Communication.Type.EMAIL, "testMail@gmx.net"));
    assertThat(simpleBusinessCustomer.getSimpleViolationMessage()).as("SimpleBusinessCustomer with it's Communication on it's Company is invalid").isNotNull();
    simpleBusinessCustomer = makeValidSimpleBusiness();
    simpleBusinessCustomer.getCompanies().get(0).getContacts().get(0).getCommunications().add(makeValidCommunication(Communication.Type.EMAIL, "testMail@gmx.net"));
    assertThat(simpleBusinessCustomer.getSimpleViolationMessage()).as("SimpleBusinessCustomer with two Communications of same allowed Type is invalid").isNotNull();
    simpleBusinessCustomer = makeValidSimpleBusiness();
    simpleBusinessCustomer.getCompanies().get(0).getContacts().get(0).getCommunications().add(makeValidCommunication(Communication.Type.PHONE, "0123456789"));
    simpleBusinessCustomer.getCompanies().get(0).getContacts().get(0).getCommunications().add(makeValidCommunication(Communication.Type.PHONE, "0987654321"));
    assertThat(simpleBusinessCustomer.getSimpleViolationMessage()).as("SimpleBusinessCustomer with two Communications of same allowed Type is invalid").isNotNull();
    simpleBusinessCustomer = makeValidSimpleBusiness();
    simpleBusinessCustomer.getCompanies().get(0).getContacts().get(0).getCommunications().add(makeValidCommunication(Communication.Type.MOBILE, "0123456789"));
    simpleBusinessCustomer.getCompanies().get(0).getContacts().get(0).getCommunications().add(makeValidCommunication(Communication.Type.MOBILE, "0987654321"));
    assertThat(simpleBusinessCustomer.getSimpleViolationMessage()).as("SimpleBusinessCustomer with two Communications of same allowed Type is invalid").isNotNull();
    simpleBusinessCustomer = makeValidSimpleBusiness();
    simpleBusinessCustomer.getCompanies().get(0).getContacts().add(makeValidSimpleConsumer().getContacts().get(0));
    assertThat(simpleBusinessCustomer.getSimpleViolationMessage()).as("SimpleBusinessCustomer with more than one Contact is invalid").isNotNull();
    simpleBusinessCustomer = makeValidSimpleBusiness();
    simpleBusinessCustomer.getCompanies().get(0).getCommunications().add(makeValidCommunication(MOBILE, "0123456789"));
    assertThat(simpleBusinessCustomer.getSimpleViolationMessage()).as("SimpleBusinessCustomer with a valid Communication on it's Company is invalid").isNotNull();
    simpleBusinessCustomer = makeValidSimpleBusiness();
    Address validAddress = new Address();
    validAddress.setIsoCountry(GERMANY);
    validAddress.setCity("Munich");
    validAddress.setStreet("Teststraße");
    validAddress.setZipCode("34243");
    simpleBusinessCustomer.getCompanies().get(0).getAddresses().add(validAddress);
    assertThat(simpleBusinessCustomer.getSimpleViolationMessage()).as("SimpleBusinessCustomer with more than one Address is invalid").isNotNull();
    simpleBusinessCustomer = makeValidSimpleBusiness();
    simpleBusinessCustomer.getCompanies().get(0).getContacts().get(0).getAddresses().add(validAddress);
    assertThat(simpleBusinessCustomer.getSimpleViolationMessage()).as("SimpleBusinessCustomer with more than one Address is invalid").isNotNull();
}
Also used : AddressLabel(eu.ggnet.dwoss.customer.ee.entity.projection.AddressLabel) Test(org.junit.Test)

Example 18 with AddressLabel

use of eu.ggnet.dwoss.customer.ee.entity.projection.AddressLabel in project dwoss by gg-net.

the class CustomerTestUtil method testGetSimpleViolationMessageSimpleConsumer.

@Test
public void testGetSimpleViolationMessageSimpleConsumer() {
    Customer simpleConsumer = makeValidSimpleConsumer();
    simpleConsumer.getContacts().add(makeValidContact());
    assertThat(simpleConsumer.getSimpleViolationMessage()).as("SimpleConsumer with more than one Contact violates SimpleConsumer's rules").isNotNull();
    simpleConsumer = makeValidSimpleConsumer();
    simpleConsumer.getAddressLabels().clear();
    assertThat(simpleConsumer.getSimpleViolationMessage()).as("SimpleConsumer without AddressLabel violates Customer's rules").isNotNull();
    simpleConsumer = makeValidSimpleConsumer();
    simpleConsumer.getAddressLabels().add(makeValidShippingAddressLabel());
    assertThat(simpleConsumer.getSimpleViolationMessage()).as("SimpleConsumer with more than one AddressLabel violates SimpleCustomer's rules").isNotNull();
    simpleConsumer = makeValidSimpleConsumer();
    simpleConsumer.getFlags().add(CustomerFlag.values()[(int) Math.random() * (CustomerFlag.values().length - 1)]);
    assertThat(simpleConsumer.getSimpleViolationMessage()).as("SimpleConsumer with a flag violates SimpleCustomer's Rules").isNotNull();
    simpleConsumer = makeValidSimpleConsumer();
    simpleConsumer.setKeyAccounter("keyAccounter");
    assertThat(simpleConsumer.getSimpleViolationMessage()).as("SimpleConsumer with keyAccounter violates SimpleCustomer's Rules").isNotNull();
    simpleConsumer = makeValidSimpleConsumer();
    simpleConsumer.getMandatorMetadata().add(new MandatorMetadata());
    assertThat(simpleConsumer.getSimpleViolationMessage()).as("SimpleConsumer with mandatorMetadata violates SimpleCustomer's Rules").isNotNull();
    simpleConsumer = makeValidSimpleConsumer();
    simpleConsumer.getAddressLabels().add(new AddressLabel(null, simpleConsumer.getContacts().get(0), simpleConsumer.getContacts().get(0).getAddresses().get(0), AddressType.SHIPPING));
    assertThat(simpleConsumer.getSimpleViolationMessage()).as("SimpleConsumer with two AddressLabels violates SimpleCustomer's Rules").isNotNull();
    simpleConsumer = makeValidSimpleConsumer();
    Address address = makeValidAddress();
    simpleConsumer.getContacts().get(0).getAddresses().add(address);
    assertThat(simpleConsumer.getSimpleViolationMessage()).as("SimpleConsumer with more than one Address violates SimpleCustomer's Rules").isNotNull();
    simpleConsumer = makeValidSimpleConsumer();
    Communication phone = new Communication(Type.PHONE, "36184165");
    Communication mobile = new Communication(Type.MOBILE, "64682552");
    Communication email = new Communication(Type.EMAIL, "email@mail.com");
    simpleConsumer.getContacts().get(0).getCommunications().addAll(Arrays.asList(phone, mobile, email));
    assertThat(simpleConsumer.getSimpleViolationMessage()).as("SimpleConsumer with more than three communications is invalid").isNotNull();
    simpleConsumer = makeValidSimpleConsumer();
    Communication skype = new Communication(Type.SKYPE, "skypeUser4832");
    simpleConsumer.getContacts().get(0).getCommunications().add(skype);
    assertThat(simpleConsumer.getSimpleViolationMessage()).as("SimpleConsumer with communication of type SKYPE is invalid").isNotNull();
    simpleConsumer = makeValidSimpleConsumer();
    simpleConsumer.getContacts().get(0).getCommunications().add(email);
    assertThat(simpleConsumer.getSimpleViolationMessage()).as("SimpleConsumer with two communications of same type is invalid").isNotNull();
    simpleConsumer = makeValidSimpleConsumer();
    simpleConsumer.getContacts().forEach(contact -> contact.getCommunications().clear());
    simpleConsumer.getContacts().get(0).getCommunications().add(email);
    assertThat(simpleConsumer.getContacts().isEmpty() && simpleConsumer.getCompanies().isEmpty()).as("either Contact or Company is set").isFalse();
    assertThat(simpleConsumer.getSimpleViolationMessage()).as("SimpleConsumer with one communication of type EMAIL is valid").isNull();
    Communication otherEmail = new Communication(Type.EMAIL, false);
    email.setIdentifier("otherEmail@mail.com");
    simpleConsumer.getContacts().get(0).getCommunications().add(otherEmail);
    assertThat(simpleConsumer.getSimpleViolationMessage()).as("SimpleConsumer with two communications of same type is invalid").isNotNull();
    simpleConsumer = makeValidSimpleConsumer();
    simpleConsumer.getContacts().forEach(contact -> contact.getCommunications().clear());
    simpleConsumer.getContacts().get(0).getCommunications().add(mobile);
    assertThat(simpleConsumer.getSimpleViolationMessage()).as("SimpleConsumer with one communication of type MOBILE is valid").isNull();
    Communication otherMobile = new Communication(Type.MOBILE, false);
    mobile.setIdentifier("16461385");
    simpleConsumer.getContacts().stream().findAny().get().getCommunications().add(otherMobile);
    assertThat(simpleConsumer.getSimpleViolationMessage()).as("SimpleConsumer with two communications of same type  is invalid").isNotNull();
    simpleConsumer = makeValidSimpleConsumer();
    simpleConsumer.getContacts().forEach(contact -> contact.getCommunications().clear());
    simpleConsumer.getContacts().get(0).getCommunications().add(phone);
    assertThat(simpleConsumer.getSimpleViolationMessage()).as("SimpleConsumer with one communication of type PHONE is valid").isNull();
    Communication otherPhone = new Communication(Type.PHONE, false);
    mobile.setIdentifier("6541351");
    simpleConsumer.getContacts().stream().findAny().get().getCommunications().add(otherPhone);
    assertThat(simpleConsumer.getSimpleViolationMessage()).as("SimpleConsumer with two communications of same type is invalid").isNotNull();
    simpleConsumer = makeValidSimpleConsumer();
}
Also used : AddressLabel(eu.ggnet.dwoss.customer.ee.entity.projection.AddressLabel) Test(org.junit.Test)

Example 19 with AddressLabel

use of eu.ggnet.dwoss.customer.ee.entity.projection.AddressLabel in project dwoss by gg-net.

the class CustomerTestUtil method makeValidInvoiceAddressLabel.

/**
 * Uses makeValidCompany, makeValidContact and makeValidAddress.
 *
 * @return Valid AddressLabel of Type INVOICE as in AddressLabel.getViolationMessage()
 */
public static AddressLabel makeValidInvoiceAddressLabel() {
    AddressLabel validAddressLabel = new AddressLabel(makeValidCompany(), makeValidContact(), makeValidAddress(), AddressType.INVOICE);
    assertThat(validAddressLabel.getViolationMessage()).as("valid validAddressLabel").isNull();
    return validAddressLabel;
}
Also used : AddressLabel(eu.ggnet.dwoss.customer.ee.entity.projection.AddressLabel)

Example 20 with AddressLabel

use of eu.ggnet.dwoss.customer.ee.entity.projection.AddressLabel in project dwoss by gg-net.

the class CustomerAgentBean method store.

@Override
public Reply<Customer> store(SimpleCustomer simpleCustomer) {
    L.warn("Simulating Store : " + simpleCustomer.toString());
    // convert the SimpleCustomer to a Customer
    boolean bussines = !StringUtils.isBlank(simpleCustomer.getCompanyName());
    Customer c = new Customer();
    Contact cont = new Contact();
    cont.setFirstName(simpleCustomer.getFirstName());
    cont.setLastName(simpleCustomer.getLastName());
    cont.setSex(simpleCustomer.getSex());
    cont.setTitle(simpleCustomer.getTitle());
    // Contact with only one Address
    Address a = new Address();
    a.setCity(simpleCustomer.getCity());
    a.setIsoCountry(new Locale(simpleCustomer.getIsoCountry().toLowerCase(), simpleCustomer.getIsoCountry().toUpperCase()));
    a.setStreet(simpleCustomer.getStreet());
    a.setZipCode(simpleCustomer.getZipCode());
    cont.getAddresses().add(a);
    // one Communication form eatch type email, phone, mobile allowed
    if (!StringUtils.isBlank(simpleCustomer.getEmail()))
        cont.getCommunications().add(new Communication(Type.EMAIL, simpleCustomer.getEmail()));
    if (!StringUtils.isBlank(simpleCustomer.getLandlinePhone()))
        cont.getCommunications().add(new Communication(Type.PHONE, simpleCustomer.getLandlinePhone()));
    if (!StringUtils.isBlank(simpleCustomer.getMobilePhone()))
        cont.getCommunications().add(new Communication(Type.MOBILE, simpleCustomer.getMobilePhone()));
    AddressLabel al;
    if (bussines) {
        Company comp = new Company();
        comp.setName(simpleCustomer.getCompanyName());
        comp.setTaxId(simpleCustomer.getTaxId());
        // The Address of the Company Contact has to match the Company Address
        comp.getAddresses().add(a);
        comp.getContacts().add(cont);
        // build AddressLabel
        al = new AddressLabel(comp, comp.getContacts().get(0), a, AddressType.INVOICE);
        c.getCompanies().add(comp);
    } else {
        c.getContacts().add(cont);
        al = new AddressLabel(null, cont, a, AddressType.INVOICE);
    }
    c.getAddressLabels().add(al);
    c.setSource(simpleCustomer.getSource());
    if (!c.isValid())
        return Reply.failure(c.getViolationMessage());
    return Reply.success(c);
}
Also used : SimpleCustomer(eu.ggnet.dwoss.customer.ee.entity.dto.SimpleCustomer) PicoCustomer(eu.ggnet.dwoss.customer.ee.entity.projection.PicoCustomer) AddressLabel(eu.ggnet.dwoss.customer.ee.entity.projection.AddressLabel)

Aggregations

AddressLabel (eu.ggnet.dwoss.customer.ee.entity.projection.AddressLabel)20 Test (org.junit.Test)7 InvoiceAddressLabelWithNullableShippingAddressLabel (eu.ggnet.dwoss.customer.ui.neo.PreferedAddressLabelsController.InvoiceAddressLabelWithNullableShippingAddressLabel)3 SimpleCustomer (eu.ggnet.dwoss.customer.ee.entity.dto.SimpleCustomer)2 PicoCustomer (eu.ggnet.dwoss.customer.ee.entity.projection.PicoCustomer)2 CustomerGenerator (eu.ggnet.dwoss.customer.ee.assist.gen.CustomerGenerator)1 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 Customer (eu.ggnet.dwoss.customer.ee.entity.Customer)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 InvalidationListener (javafx.beans.InvalidationListener)1 Observable (javafx.beans.Observable)1