@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)); }
@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(); }
@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); }
@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(); }
@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)); }
@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); }
@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(); }
@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(); }
@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)); }
@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(); }
@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); }
@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")); }
@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(); }
@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(); }
@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(); }
@Test public void testCorsFilterDeactivated() throws Exception { props.getCors().setAllowedOrigins(null); 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)); }
@Before public void setUp() { testController = Mockito.mock(TestController.class); this.mockMvc = MockMvcBuilders.standaloneSetup(testController) .setControllerAdvice(new RestfulExceptionHandler()) .build(); }
@Before public void setup() { MockitoAnnotations.initMocks(this); PrivilegeResource privilegeResource = new PrivilegeResource(); ReflectionTestUtils.setField(privilegeResource, "privilegeRepository", privilegeRepository); this.restPrivilegeMockMvc = MockMvcBuilders.standaloneSetup(privilegeResource) .setCustomArgumentResolvers(pageableArgumentResolver) .setMessageConverters(jacksonMessageConverter).build(); }
@Before public void setup() { MockitoAnnotations.initMocks(this); EventResource eventResource = new EventResource(eventService); this.restEventMockMvc = MockMvcBuilders.standaloneSetup(eventResource) .setCustomArgumentResolvers(pageableArgumentResolver) .setControllerAdvice(exceptionTranslator) .setMessageConverters(jacksonMessageConverter).build(); }
@Before public void setup() { MockitoAnnotations.initMocks(this); UserResource userResource = new UserResource(userRepository, mailService, userService, userSearchRepository); this.restUserMockMvc = MockMvcBuilders.standaloneSetup(userResource) .setCustomArgumentResolvers(pageableArgumentResolver) .setControllerAdvice(exceptionTranslator) .setMessageConverters(jacksonMessageConverter) .build(); }
@Before public void baseBefore() { this.mockMvc = MockMvcBuilders. webAppContextSetup(this.wac). build(); }
@Before public void setup() { MockitoAnnotations.initMocks(this); LogsResource logsResource = new LogsResource(); this.restLogsMockMvc = MockMvcBuilders .standaloneSetup(logsResource) .build(); }
@PostConstruct public void setup() { MockitoAnnotations.initMocks(this); CourseLevelSessionResource courseLevelSessionResource = new CourseLevelSessionResource(); ReflectionTestUtils.setField(courseLevelSessionResource, "courseLevelSessionRepository", courseLevelSessionRepository); this.restCourseLevelSessionMockMvc = MockMvcBuilders.standaloneSetup(courseLevelSessionResource) .setCustomArgumentResolvers(pageableArgumentResolver) .setMessageConverters(jacksonMessageConverter).build(); }
@Before public void setup() { MockitoAnnotations.initMocks(this); final CampagneResource campagneResource = new CampagneResource(campagneService); this.restCampagneMockMvc = MockMvcBuilders.standaloneSetup(campagneResource) .setCustomArgumentResolvers(pageableArgumentResolver) .setControllerAdvice(exceptionTranslator) .setConversionService(createFormattingConversionService()) .setMessageConverters(jacksonMessageConverter).build(); }
/** * Before each Test perform Mock Reset Assured Setup... * * @throws Exception */ @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); RestAssuredMockMvc.mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build(); RestAssuredMockMvc.enableLoggingOfRequestAndResponseIfValidationFails(); }
@Before public void setup() { this.mockMvc = MockMvcBuilders// .webAppContextSetup(webApplicationContext)// .apply(springSecurity()) .build(); }
@Before public void setup() { this.mockMvc = MockMvcBuilders .standaloneSetup(userController) .setCustomArgumentResolvers(pageableArgumentResolver) .build(); }
@Before public void setup() { SecurityContextHolder.clearContext(); AccountResource control = new AccountResource(); this.mock = MockMvcBuilders.standaloneSetup(control) .setControllerAdvice(new ExceptionTranslator()) .build(); }
@Before public void setup() { MockitoAnnotations.initMocks(this); TagResource tagResource = new TagResource(tagRepository, tagSearchRepository); this.restTagMockMvc = MockMvcBuilders.standaloneSetup(tagResource) .setCustomArgumentResolvers(pageableArgumentResolver) .setControllerAdvice(exceptionTranslator) .setMessageConverters(jacksonMessageConverter).build(); }
@Before public void setup() throws Exception { mockMvc = MockMvcBuilders.webAppContextSetup(applicationContext).build(); recipToken = TestUtil.getToken(mockMvc, "18217699894", "123456"); replaceToken = TestUtil.getToken(mockMvc, "18217699800", "123456"); adminToken = TestUtil.getToken(mockMvc, "18217699895", "123456"); System.out.println("收件人TOKEN:" + recipToken); System.out.println("代取人TOKEN:" + replaceToken); System.out.println("管理员TOKEN:" + adminToken); }
@Before public void setup() { MockitoAnnotations.initMocks(this); final TypeTestResource typeTestResource = new TypeTestResource(typeTestService); this.restTypeTestMockMvc = MockMvcBuilders.standaloneSetup(typeTestResource) .setCustomArgumentResolvers(pageableArgumentResolver) .setControllerAdvice(exceptionTranslator) .setConversionService(createFormattingConversionService()) .setMessageConverters(jacksonMessageConverter).build(); }
@Before public void setup() { mockMvc = MockMvcBuilders .webAppContextSetup(context) .apply(springSecurity()) .build(); }