Package org.springframework.test.web.server

Examples of org.springframework.test.web.server.MockMvc.perform()


    MockMvc mockMvc =
      standaloneSetup(new PersonController())
        .setViewResolvers(cnViewResolver, new InternalResourceViewResolver())
        .build();

    mockMvc.perform(get("/person/Corea"))
      .andExpect(status().isOk())
      .andExpect(model().size(1))
      .andExpect(model().attributeExists("person"))
      .andExpect(forwardedUrl("person/show"));
View Full Code Here


      .andExpect(status().isOk())
      .andExpect(model().size(1))
      .andExpect(model().attributeExists("person"))
      .andExpect(forwardedUrl("person/show"));

    mockMvc.perform(get("/person/Corea").accept(MediaType.APPLICATION_JSON))
      .andExpect(status().isOk())
      .andExpect(content().mimeType(MediaType.APPLICATION_JSON))
      .andExpect(jsonPath("$.person.name").value("Corea"));

    mockMvc.perform(get("/person/Corea").accept(MediaType.APPLICATION_XML))
View Full Code Here

    mockMvc.perform(get("/person/Corea").accept(MediaType.APPLICATION_JSON))
      .andExpect(status().isOk())
      .andExpect(content().mimeType(MediaType.APPLICATION_JSON))
      .andExpect(jsonPath("$.person.name").value("Corea"));

    mockMvc.perform(get("/person/Corea").accept(MediaType.APPLICATION_XML))
      .andExpect(status().isOk())
      .andExpect(content().mimeType(MediaType.APPLICATION_XML))
      .andExpect(xpath("/person/name/text()").string(equalTo("Corea")));
  }
View Full Code Here

    }

    @Test
    public void testHandleLogin() throws Exception {
        MockMvc mockMvc = MockMvcBuilders.standaloneSetup(this.loginController).build();
        mockMvc.perform(post("/login").param("username", "john").param("password", "secret"))
                .andExpect(status().isOk())
                .andExpect(request().sessionAttribute(LoginController.ACCOUNT_ATTRIBUTE, this.account))
                .andExpect(redirectedUrl("/index.htm"));
    }
View Full Code Here

    SignedUpGateway gateway = mock(SignedUpGateway.class);   
    SignupController signupController = new SignupController(accountRepository, gateway);
   
    String signupJson = "{\"first-name\":\"Roy\",\"last-name\":\"Clarkson\",\"email\":\"roy@clarkson.com\",\"confirm-email\":\"roy@clarkson.com\",\"gender\":\"M\",\"birthdate\":{\"month\":7,\"day\":8,\"year\":1976},\"password\":\"letmein\"}";
    MockMvc mockMvc = standaloneSetup(signupController).build();
    mockMvc.perform(post("/signup").contentType(APPLICATION_JSON).body(signupJson.getBytes()))
        .andExpect(MockMvcResultMatchers.status().isCreated())
        .andExpect(MockMvcResultMatchers.jsonPath("message", Matchers.equalTo("Account created")));
  }
 
  @Test
View Full Code Here

    SignedUpGateway gateway = mock(SignedUpGateway.class);   
    SignupController signupController = new SignupController(accountRepository, gateway);
   
    String signupJson = "{\"first-name\":\"Roy\",\"last-name\":\"Clarkson\",\"email\":\"roy@clarkson.com\",\"confirm-email\":\"roy@clarkson.com\",\"gender\":\"M\",\"birthdate\":{\"month\":7,\"day\":8,\"year\":1976},\"password\":\"letmein\"}";
    MockMvc mockMvc = standaloneSetup(signupController).build();
    mockMvc.perform(post("/signup").contentType(APPLICATION_JSON).body(signupJson.getBytes()))
        .andExpect(MockMvcResultMatchers.status().isBadRequest())
        .andExpect(MockMvcResultMatchers.jsonPath("message", Matchers.equalTo("Account creation error")))
        .andExpect(MockMvcResultMatchers.jsonPath("errors[0].field", Matchers.equalTo("email")))
        .andExpect(MockMvcResultMatchers.jsonPath("errors[0].code", Matchers.equalTo("account.duplicateEmail")))
        .andExpect(MockMvcResultMatchers.jsonPath("errors[0].message", Matchers.equalTo("already on file")));
View Full Code Here

    SignedUpGateway gateway = mock(SignedUpGateway.class);   
    SignupController signupController = new SignupController(accountRepository, gateway);
   
    String signupJson = "{\"first-name\":null,\"last-name\":\"Clarkson\",\"email\":\"roy@clarkson.com\",\"confirm-email\":\"roy@clarkson.com\",\"gender\":\"M\",\"birthdate\":{\"month\":7,\"day\":8,\"year\":1976},\"password\":\"letmein\"}";
    MockMvc mockMvc = standaloneSetup(signupController).build();
    mockMvc.perform(post("/signup").contentType(APPLICATION_JSON).body(signupJson.getBytes()))
        .andExpect(MockMvcResultMatchers.status().isBadRequest())
        .andExpect(MockMvcResultMatchers.jsonPath("message", Matchers.equalTo("Validation error")))
        .andExpect(MockMvcResultMatchers.jsonPath("errors[0].field", Matchers.equalTo("firstName")))
        .andExpect(MockMvcResultMatchers.jsonPath("errors[0].code", Matchers.equalTo("NotEmpty")))
        .andExpect(MockMvcResultMatchers.jsonPath("errors[0].message", Matchers.equalTo("may not be empty")));
View Full Code Here

    SignedUpGateway gateway = mock(SignedUpGateway.class);   
    SignupController signupController = new SignupController(accountRepository, gateway);
   
    String signupJson = "{\"first-name\":\"Roy\",\"last-name\":\"Clarkson\",\"email\":\"roy@clarkson.com\",\"confirm-email\":\"rclarkson@vmware.com\",\"gender\":\"M\",\"birthdate\":{\"month\":7,\"day\":8,\"year\":1976},\"password\":\"letmein\"}";
    MockMvc mockMvc = standaloneSetup(signupController).build();
    mockMvc.perform(post("/signup").contentType(APPLICATION_JSON).body(signupJson.getBytes()))
        .andExpect(MockMvcResultMatchers.status().isBadRequest())
        .andExpect(MockMvcResultMatchers.jsonPath("message", Matchers.equalTo("Validation error")))
        .andExpect(MockMvcResultMatchers.jsonPath("errors[0].field", Matchers.equalTo("email")))
        .andExpect(MockMvcResultMatchers.jsonPath("errors[0].code", Matchers.equalTo("Confirm")))
        .andExpect(MockMvcResultMatchers.jsonPath("errors[0].message", Matchers.equalTo("does not match confirmation email")));
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.