Search in sources :

Example 91 with MockMvc

use of org.springframework.test.web.servlet.MockMvc in project spring-framework by spring-projects.

the class HtmlUnitRequestBuilderTests method mergeParameter.

@Test
public void mergeParameter() throws Exception {
    String paramName = "PARENT";
    String paramValue = "VALUE";
    String paramValue2 = "VALUE2";
    MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new HelloController()).defaultRequest(get("/").param(paramName, paramValue, paramValue2)).build();
    MockHttpServletRequest performedRequest = mockMvc.perform(requestBuilder).andReturn().getRequest();
    assertThat(asList(performedRequest.getParameterValues(paramName)), contains(paramValue, paramValue2));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockMvc(org.springframework.test.web.servlet.MockMvc) Test(org.junit.Test)

Example 92 with MockMvc

use of org.springframework.test.web.servlet.MockMvc in project pact-jvm by DiUS.

the class MockMvcTarget method testInteraction.

/**
     * {@inheritDoc}
     */
@Override
public void testInteraction(final String consumerName, final Interaction interaction) {
    ProviderInfo provider = getProviderInfo();
    ConsumerInfo consumer = new ConsumerInfo(consumerName);
    provider.setVerificationType(PactVerification.ANNOTATED_METHOD);
    MockMvc mockMvc = standaloneSetup(controllers.toArray()).setControllerAdvice(controllerAdvice.toArray()).build();
    MvcProviderVerifier verifier = (MvcProviderVerifier) setupVerifier(interaction, provider, consumer);
    Map<String, Object> failures = new HashMap<>();
    for (int i = 0; i < runTimes; i++) {
        verifier.verifyResponseFromProvider(provider, interaction, interaction.getDescription(), failures, mockMvc);
    }
    try {
        if (!failures.isEmpty()) {
            verifier.displayFailures(failures);
            throw getAssertionError(failures);
        }
    } finally {
        verifier.finialiseReports();
    }
}
Also used : ConsumerInfo(au.com.dius.pact.provider.ConsumerInfo) ProviderInfo(au.com.dius.pact.provider.ProviderInfo) MvcProviderVerifier(au.com.dius.pact.provider.spring.MvcProviderVerifier) MockMvc(org.springframework.test.web.servlet.MockMvc)

Aggregations

MockMvc (org.springframework.test.web.servlet.MockMvc)92 Test (org.junit.Test)87 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)25 Todo (org.springframework.sync.Todo)16 List (java.util.List)15 TodoRepository (org.springframework.sync.TodoRepository)15 Filter (javax.servlet.Filter)13 MockServletContext (org.springframework.mock.web.MockServletContext)13 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)12 OncePerRequestFilter (org.springframework.web.filter.OncePerRequestFilter)9 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)5 MvcResult (org.springframework.test.web.servlet.MvcResult)5 Ignore (org.junit.Ignore)3 FilterChainProxy (org.springframework.security.web.FilterChainProxy)3 WebConnection (com.gargoylesoftware.htmlunit.WebConnection)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 HttpSession (javax.servlet.http.HttpSession)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)2