Example usage for org.springframework.validation BeanPropertyBindingResult addError

List of usage examples for org.springframework.validation BeanPropertyBindingResult addError

Introduction

In this page you can find the example usage for org.springframework.validation BeanPropertyBindingResult addError.

Prototype

@Override
    public void addError(ObjectError error) 

Source Link

Usage

From source file:fragment.web.TenantsControllerTest.java

@Test
public void testTenantCreationNegative() throws Exception {

    AccountType type = accountTypeDAO.find(4L);
    Tenant tenant = new Tenant("Acme Corp " + random.nextInt(), type, getRootUser(), randomAddress(), true,
            currencyValueService.locateBYCurrencyCode("USD"), getPortalUser());
    List<Country> countryList = countryDAO.findAll(null);
    Profile profile = profileDAO.find(8L);
    User user = new User("firstName", "lastName", "nageswarareddy.poli@citrix.com", "username14", "Portal123#",
            "91-9885098850", "GMT", null, profile, getRootUser());
    user.setAddress(randomAddress());//from   w ww .  ja v a  2s. co m
    tenant.setOwner(user);
    com.citrix.cpbm.access.User newUser = (com.citrix.cpbm.access.User) CustomProxy.newInstance(user);
    com.citrix.cpbm.access.Tenant newTenant = (com.citrix.cpbm.access.Tenant) CustomProxy.newInstance(tenant);
    TenantForm form = new TenantForm();
    form.setAccountTypeId("4");
    form.setUser(newUser);
    form.setTenant(newTenant);
    form.setCountryList(countryList);

    BeanPropertyBindingResult result = new BeanPropertyBindingResult(form, "validation");
    result.addError(new FieldError("Error", "Error", "Error"));
    String tenantCreation = controller.create(form, result, map, status, request);
    logger.debug("RESULT------------------------" + tenantCreation);
    Assert.assertFalse("verifying the form has zero error", tenantCreation.contains("0 errors"));
}