当前位置: 首页>>代码示例>>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;未经允许,请勿转载。