本文整理汇总了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));
}
示例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);
}
示例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();
}
示例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));
}
示例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);
}
示例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();
}
示例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();
}
示例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));
}
示例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();
}
示例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);
}
示例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"));
}
示例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();
}
示例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();
}
示例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();
}