當前位置: 首頁>>代碼示例>>Java>>正文


Java MockMvcBuilders類代碼示例

本文整理匯總了Java中org.springframework.test.web.servlet.setup.MockMvcBuilders的典型用法代碼示例。如果您正苦於以下問題:Java MockMvcBuilders類的具體用法?Java MockMvcBuilders怎麽用?Java MockMvcBuilders使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MockMvcBuilders類屬於org.springframework.test.web.servlet.setup包,在下文中一共展示了MockMvcBuilders類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testCorsFilterOnOtherPath

import org.springframework.test.web.servlet.setup.MockMvcBuilders; //導入依賴的package包/類
@Test
public void testCorsFilterOnOtherPath() throws Exception {
    props.getCors().setAllowedOrigins(Collections.singletonList("*"));
    props.getCors().setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE"));
    props.getCors().setAllowedHeaders(Collections.singletonList("*"));
    props.getCors().setMaxAge(1800L);
    props.getCors().setAllowCredentials(true);

    MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController())
        .addFilters(webConfigurer.corsFilter())
        .build();

    mockMvc.perform(
        get("/test/test-cors")
            .header(HttpHeaders.ORIGIN, "other.domain.com"))
        .andExpect(status().isOk())
        .andExpect(header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
}
 
開發者ID:xm-online,項目名稱:xm-uaa,代碼行數:19,代碼來源:WebConfigurerTest.java

示例2: setup

import org.springframework.test.web.servlet.setup.MockMvcBuilders; //導入依賴的package包/類
@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    String mockProfile[] = {"test"};
    JHipsterProperties.Ribbon ribbon = new JHipsterProperties.Ribbon();
    ribbon.setDisplayOnActiveProfiles(mockProfile);
    when(jHipsterProperties.getRibbon()).thenReturn(ribbon);

    String activeProfiles[] = {"test"};
    when(environment.getDefaultProfiles()).thenReturn(activeProfiles);
    when(environment.getActiveProfiles()).thenReturn(activeProfiles);

    ProfileInfoResource profileInfoResource = new ProfileInfoResource(environment, jHipsterProperties);
    this.restProfileMockMvc = MockMvcBuilders
        .standaloneSetup(profileInfoResource)
        .build();
}
 
開發者ID:IBM,項目名稱:Microservices-with-JHipster-and-Spring-Boot,代碼行數:18,代碼來源:ProfileInfoResourceIntTest.java

示例3: setup

import org.springframework.test.web.servlet.setup.MockMvcBuilders; //導入依賴的package包/類
@Before
public void setup() {
    log.info("Init setup");

    //  xmEntitySearchRepository.deleteAll();

    TenantContext.setCurrent("RESINTTEST");
    lepManager.beginThreadContext(ctx -> {
        ctx.setValue(XmLepConstants.CONTEXT_KEY_TENANT, TenantContext.getCurrent());
    });

    MockitoAnnotations.initMocks(this);
    CalendarResource calendarResource = new CalendarResource(calendarService);
    EventResource eventResource = new EventResource(eventService);
    XmEntityResource xmEntityResource = new XmEntityResource(xmEntityService, profileService, profileEventProducer);
    this.restXmEntityMockMvc = MockMvcBuilders.standaloneSetup(xmEntityResource, calendarResource, eventResource)
        .setCustomArgumentResolvers(pageableArgumentResolver)
        .setControllerAdvice(exceptionTranslator)
        .setValidator(validator)
        .setMessageConverters(jacksonMessageConverter).build();

    xmEntityIncoming = createEntityComplexIncoming(em);

}
 
開發者ID:xm-online,項目名稱:xm-ms-entity,代碼行數:25,代碼來源:XmEntityResourceExtendedIntTest.java

示例4: setup

import org.springframework.test.web.servlet.setup.MockMvcBuilders; //導入依賴的package包/類
@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    doNothing().when(mockMailService).sendActivationEmail((User) anyObject(), anyString());

    AccountResource accountResource = new AccountResource();
    ReflectionTestUtils.setField(accountResource, "userRepository", userRepository);
    ReflectionTestUtils.setField(accountResource, "userService", userService);
    ReflectionTestUtils.setField(accountResource, "mailService", mockMailService);

    AccountResource accountUserMockResource = new AccountResource();
    ReflectionTestUtils.setField(accountUserMockResource, "userRepository", userRepository);
    ReflectionTestUtils.setField(accountUserMockResource, "userService", mockUserService);
    ReflectionTestUtils.setField(accountUserMockResource, "mailService", mockMailService);

    this.restMvc = MockMvcBuilders.standaloneSetup(accountResource).build();
    this.restUserMockMvc = MockMvcBuilders.standaloneSetup(accountUserMockResource).build();
}
 
開發者ID:ugouku,項目名稱:shoucang,代碼行數:19,代碼來源:AccountResourceTest.java

示例5: processValidationErrorTest

import org.springframework.test.web.servlet.setup.MockMvcBuilders; //導入依賴的package包/類
@Test
public void processValidationErrorTest() throws Exception {
    UserJWTController control = new UserJWTController(null, null);
    MockMvc jwtMock = MockMvcBuilders.standaloneSetup(control)
        .setControllerAdvice(new ExceptionTranslator())
        .build();
    MvcResult res = jwtMock.perform(post("/api/authenticate")
        .contentType(MediaType.APPLICATION_JSON_UTF8)
        .accept(MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN, MediaType.ALL)
        .content("{\"username\":\"fakeUsernameTooLongfakeUsernameTooLongfakeUsernameTooLongfakeUsernameTooLong" +
            "\",\"password\":\"fakePassword\",\"rememberMe\":false}"))
        .andExpect(status().isBadRequest())
        .andReturn();

    assertThat(res.getResolvedException(), instanceOf(MethodArgumentNotValidException.class));
}
 
開發者ID:oktadeveloper,項目名稱:jhipster-microservices-example,代碼行數:17,代碼來源:ExceptionTranslatorTest.java

示例6: setup

import org.springframework.test.web.servlet.setup.MockMvcBuilders; //導入依賴的package包/類
@Before
public void setup() {

    TenantContext.setCurrent("RESINTTEST");

    MockitoAnnotations.initMocks(this);
    LocationResource locationResource = new LocationResource(locationRepository, locationSearchRepository);
    this.restLocationMockMvc = MockMvcBuilders.standaloneSetup(locationResource)
        .setCustomArgumentResolvers(pageableArgumentResolver)
        .setControllerAdvice(exceptionTranslator)
        .setValidator(validator)
        .setMessageConverters(jacksonMessageConverter).build();

    location = createEntity(em);

}
 
開發者ID:xm-online,項目名稱:xm-ms-entity,代碼行數:17,代碼來源:LocationResourceIntTest.java

示例7: setup

import org.springframework.test.web.servlet.setup.MockMvcBuilders; //導入依賴的package包/類
@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    final ProjectResource projectResource = new ProjectResource(projectService);
    this.restProjectMockMvc = MockMvcBuilders.standaloneSetup(projectResource)
        .setCustomArgumentResolvers(pageableArgumentResolver)
        .setControllerAdvice(exceptionTranslator)
        .setConversionService(createFormattingConversionService())
        .setMessageConverters(jacksonMessageConverter).build();
}
 
開發者ID:torgcrm,項目名稱:TorgCRM-Server,代碼行數:11,代碼來源:ProjectResourceIntTest.java

示例8: setup

import org.springframework.test.web.servlet.setup.MockMvcBuilders; //導入依賴的package包/類
@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    EntryResource entryResource = new EntryResource(entryRepository, entrySearchRepository);
    this.restEntryMockMvc = MockMvcBuilders.standaloneSetup(entryResource)
        .setCustomArgumentResolvers(pageableArgumentResolver)
        .setControllerAdvice(exceptionTranslator)
        .setMessageConverters(jacksonMessageConverter).build();
}
 
開發者ID:IBM,項目名稱:Microservices-with-JHipster-and-Spring-Boot,代碼行數:10,代碼來源:EntryResourceIntTest.java

示例9: testCorsFilterDeactivated2

import org.springframework.test.web.servlet.setup.MockMvcBuilders; //導入依賴的package包/類
@Test
public void testCorsFilterDeactivated2() throws Exception {
    props.getCors().setAllowedOrigins(new ArrayList<>());

    MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController())
        .addFilters(webConfigurer.corsFilter())
        .build();

    mockMvc.perform(
        get("/api/test-cors")
            .header(HttpHeaders.ORIGIN, "other.domain.com"))
        .andExpect(status().isOk())
        .andExpect(header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
}
 
開發者ID:xm-online,項目名稱:xm-ms-config,代碼行數:15,代碼來源:WebConfigurerTest.java

示例10: setup

import org.springframework.test.web.servlet.setup.MockMvcBuilders; //導入依賴的package包/類
@Before
public void setup() throws IOException {
    this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context).build();

    ClassPathResource pathfileRes = new ClassPathResource("application.yml");
    projectDir = pathfileRes.getFile().getParentFile().getParentFile().getParentFile();
}
 
開發者ID:sdcuike,項目名稱:spring-boot-oauth2-demo,代碼行數:8,代碼來源:SpringfoxConfigTest.java

示例11: setup

import org.springframework.test.web.servlet.setup.MockMvcBuilders; //導入依賴的package包/類
@Before
@SneakyThrows
public void setup() {
    TenantProperties properties = new TenantProperties();
    properties.setSocial(asList(
        new TenantProperties.Social("twitter", "xxx", "yyy", DEFAULT_DOMAIN),
        new TenantProperties.Social("facebook", "xxx", "yyy", DEFAULT_DOMAIN)
    ));
    tenantPropertiesService.onRefresh("/config/tenants/"+ DEFAULT_TENANT + "/uaa/uaa.yml",
        new ObjectMapper(new YAMLFactory()).writeValueAsString(properties));

    MockitoAnnotations.initMocks(this);
    SocialController socialController = new SocialController(socialService, providerSignInUtils,
        connectionFactoryLocator, usersConnectionRepository, signInAdapter, connectSupport, sessionStrategy, socialConfigRepository);
    this.restUserMockMvc = MockMvcBuilders.standaloneSetup(socialController)
        .setControllerAdvice(exceptionTranslator)
        .setMessageConverters(jacksonMessageConverter)
        .build();
    when(sessionStrategy.getAttribute(any(RequestAttributes.class), eq(ProviderSignInAttempt.SESSION_ATTRIBUTE)))
        .thenReturn(providerSignInAttempt);
    when(connection.fetchUserProfile())
        .thenReturn(new UserProfile("id", "name", "fname", "lname", "email", "username"));
    when(connection.createData()).thenReturn(
        new ConnectionData("twitter", "providerUserId", "displayName", "profileUrl", "imageUrl", "", "secret",
            "refreshToken", 1000L));
    Mockito.<Connection<?>>when(connectSupport.completeConnection(any(OAuth1ConnectionFactory.class), any()))
        .thenReturn(connection);
    Mockito.<Connection<?>>when(connectSupport.completeConnection(any(OAuth2ConnectionFactory.class), any()))
        .thenReturn(connection);
    when(connectSupport.buildOAuthUrl(any(), any(), any())).thenReturn("SomeCallbackUrl");
    Mockito.<Connection<?>>when(providerSignInAttempt.getConnection(any())).thenReturn(connection);
}
 
開發者ID:xm-online,項目名稱:xm-uaa,代碼行數:33,代碼來源:SocialControllerIntTest.java

示例12: testCorsFilterOnApiPath

import org.springframework.test.web.servlet.setup.MockMvcBuilders; //導入依賴的package包/類
@Test
public void testCorsFilterOnApiPath() throws Exception {
    props.getCors().setAllowedOrigins(Collections.singletonList("*"));
    props.getCors().setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE"));
    props.getCors().setAllowedHeaders(Collections.singletonList("*"));
    props.getCors().setMaxAge(1800L);
    props.getCors().setAllowCredentials(true);

    MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController())
        .addFilters(webConfigurer.corsFilter())
        .build();

    mockMvc.perform(
        options("/api/test-cors")
            .header(HttpHeaders.ORIGIN, "other.domain.com")
            .header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "POST"))
        .andExpect(status().isOk())
        .andExpect(header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, "other.domain.com"))
        .andExpect(header().string(HttpHeaders.VARY, "Origin"))
        .andExpect(header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS, "GET,POST,PUT,DELETE"))
        .andExpect(header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS, "true"))
        .andExpect(header().string(HttpHeaders.ACCESS_CONTROL_MAX_AGE, "1800"));

    mockMvc.perform(
        get("/api/test-cors")
            .header(HttpHeaders.ORIGIN, "other.domain.com"))
        .andExpect(status().isOk())
        .andExpect(header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, "other.domain.com"));
}
 
開發者ID:xm-online,項目名稱:xm-ms-entity,代碼行數:30,代碼來源:WebConfigurerIntTest.java

示例13: setup

import org.springframework.test.web.servlet.setup.MockMvcBuilders; //導入依賴的package包/類
@PostConstruct
public void setup() {
    MockitoAnnotations.initMocks(this);
    LevelResource levelResource = new LevelResource();
    ReflectionTestUtils.setField(levelResource, "levelRepository", levelRepository);
    this.restLevelMockMvc = MockMvcBuilders.standaloneSetup(levelResource)
        .setCustomArgumentResolvers(pageableArgumentResolver)
        .setMessageConverters(jacksonMessageConverter).build();
}
 
開發者ID:GastonMauroDiaz,項目名稱:buenojo,代碼行數:10,代碼來源:LevelResourceTest.java

示例14: setup

import org.springframework.test.web.servlet.setup.MockMvcBuilders; //導入依賴的package包/類
@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    AuditEventService auditEventService =
        new AuditEventService(auditEventRepository, auditEventConverter);
    AuditResource auditResource = new AuditResource(auditEventService);
    this.restAuditMockMvc = MockMvcBuilders.standaloneSetup(auditResource)
        .setCustomArgumentResolvers(pageableArgumentResolver)
        .setConversionService(formattingConversionService)
        .setMessageConverters(jacksonMessageConverter).build();
}
 
開發者ID:deepu105,項目名稱:spring-io,代碼行數:12,代碼來源:AuditResourceIntTest.java

示例15: setup

import org.springframework.test.web.servlet.setup.MockMvcBuilders; //導入依賴的package包/類
@PostConstruct
public void setup() {
    MockitoAnnotations.initMocks(this);
    CourseResource courseResource = new CourseResource();
    ReflectionTestUtils.setField(courseResource, "courseRepository", courseRepository);
    this.restCourseMockMvc = MockMvcBuilders.standaloneSetup(courseResource)
        .setCustomArgumentResolvers(pageableArgumentResolver)
        .setMessageConverters(jacksonMessageConverter).build();
}
 
開發者ID:GastonMauroDiaz,項目名稱:buenojo,代碼行數:10,代碼來源:CourseResourceTest.java


注:本文中的org.springframework.test.web.servlet.setup.MockMvcBuilders類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。