Ejemplo n.º 1
1
 @Test
 public void postAccountTest() throws Exception {
   mockMvc
       .perform(
           MockMvcRequestBuilders.post("/account")
               .contentType(MediaType.APPLICATION_FORM_URLENCODED)
               .param("name", accountForm.getName())
               .param("surname", accountForm.getSurname())
               .param("address", accountForm.getAddress())
               .param("phone", accountForm.getPhone().toString())
               .param("iban", accountForm.getIban().toString())
               .param("balance", accountForm.getBalance().toString())
               .param("currency", accountForm.getCurrency()))
       .andExpect(MockMvcResultMatchers.status().isOk())
       .andExpect(MockMvcResultMatchers.view().name("account"))
       .andExpect(MockMvcResultMatchers.model().attributeExists("currencies"))
       .andReturn();
 }
Ejemplo n.º 2
0
  @Before
  public void setup() {

    MockitoAnnotations.initMocks(this);

    account =
        new Account(
            "john",
            "malkovich",
            "Ireland",
            new BigInteger("500600700"),
            new BigInteger("1234567890"),
            new BigDecimal(25),
            "EUR");

    accountForm = new AccountForm();
    accountForm.setName("john");
    accountForm.setSurname("malkovich");
    accountForm.setAddress("Ireland");
    accountForm.setPhone(new BigInteger("500600700"));
    accountForm.setIban(new BigInteger("1234567890"));
    accountForm.setBalance(new BigDecimal(25));
    accountForm.setCurrency("EUR");

    viewResolver = new InternalResourceViewResolver();
    viewResolver.setPrefix("/WEB-INF/views/");
    viewResolver.setSuffix(".jsp");

    mockMvc =
        MockMvcBuilders.standaloneSetup(accountController).setViewResolvers(viewResolver).build();
  }
Ejemplo n.º 3
0
 @Test
 public void postAccountExistsErrorTest() throws Exception {
   Mockito.doThrow(
           new AccountExistsException("Account already exists with iban : " + account.getIban()))
       .when(accountService)
       .createAccount(
           new Account(
               accountForm.getName(),
               accountForm.getSurname(),
               accountForm.getAddress(),
               accountForm.getPhone(),
               accountForm.getIban(),
               accountForm.getBalance(),
               accountForm.getCurrency()));
   accountController.createAccount(accountForm, bindingResult, model);
 }