org.springframework.mock.web.MockHttpSession Java Examples
The following examples show how to use
org.springframework.mock.web.MockHttpSession.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractWebApiTest.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testGetAll() throws Exception { Map<Class<? extends IdentifiableObject>, IdentifiableObject> defaultObjectMap = manager.getDefaults(); IdentifiableObject defaultTestObject = defaultObjectMap.get( testClass ); int valueToTest = defaultTestObject != null ? 5 : 4; manager.save( createTestObject( testClass, 'A' ) ); manager.save( createTestObject( testClass, 'B' ) ); manager.save( createTestObject( testClass, 'C' ) ); manager.save( createTestObject( testClass, 'D' ) ); MockHttpSession session = getSession( "ALL" ); List<FieldDescriptor> fieldDescriptors = new ArrayList<>(); fieldDescriptors.addAll( ResponseDocumentation.pager() ); fieldDescriptors.add( fieldWithPath( schema.getPlural() ).description( schema.getPlural() ) ); mvc.perform( get( schema.getRelativeApiEndpoint() ).session( session ).accept( TestUtils.APPLICATION_JSON_UTF8 ) ) .andExpect( status().isOk() ) .andExpect( content().contentTypeCompatibleWith( TestUtils.APPLICATION_JSON_UTF8 ) ) .andExpect( jsonPath( "$." + schema.getPlural() ).isArray() ) .andExpect( jsonPath( "$." + schema.getPlural() + ".length()" ).value( valueToTest ) ) .andDo( documentPrettyPrint( schema.getPlural() + "/all", responseFields( fieldDescriptors.toArray( new FieldDescriptor[fieldDescriptors.size()] ) ) ) ); }
Example #2
Source File: AbstractWebApiTest.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testUpdate() throws Exception { MockHttpSession session = getSession( "ALL" ); T object = createTestObject( testClass, 'A' ); manager.save( object ); object.setHref( "updatedHref" ); mvc.perform( put( schema.getRelativeApiEndpoint() + "/" + object.getUid() ) .session( session ) .contentType( TestUtils.APPLICATION_JSON_UTF8 ) .content( TestUtils.convertObjectToJsonBytes( object ) ) ) .andExpect( status().is( updateStatus ) ) .andDo( documentPrettyPrint( schema.getPlural() + "/update" ) ); }
Example #3
Source File: OAuth20CallbackAuthorizeControllerTests.java From springboot-shiro-cas-mybatis with MIT License | 6 votes |
@Test public void verifyOK() throws Exception { final MockHttpServletRequest mockRequest = new MockHttpServletRequest( "GET", CONTEXT + OAuthConstants.CALLBACK_AUTHORIZE_URL); mockRequest.addParameter(OAuthConstants.TICKET, SERVICE_TICKET); final MockHttpSession mockSession = new MockHttpSession(); mockSession.putValue(OAuthConstants.OAUTH20_CALLBACKURL, REDIRECT_URI); mockSession.putValue(OAuthConstants.OAUTH20_SERVICE_NAME, SERVICE_NAME); mockRequest.setSession(mockSession); final MockHttpServletResponse mockResponse = new MockHttpServletResponse(); final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController(); oauth20WrapperController.afterPropertiesSet(); final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse); assertEquals(OAuthConstants.CONFIRM_VIEW, modelAndView.getViewName()); final Map<String, Object> map = modelAndView.getModel(); assertEquals(SERVICE_NAME, map.get("serviceName")); assertEquals(REDIRECT_URI + "?" + OAuthConstants.CODE + "=" + SERVICE_TICKET, map.get("callbackUrl")); }
Example #4
Source File: LockExceptionControllerDocumentation.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testAddLockException() throws Exception { MockHttpSession session = getSession( "ALL" ); PeriodType periodType = periodService.getPeriodTypeByName( "Monthly" ); Period period = createPeriod( periodType, getDate( 2016, 12, 1 ), getDate( 2016, 12, 31 ) ); manager.save( period ); OrganisationUnit orgUnit = createOrganisationUnit( 'B' ); manager.save( orgUnit ); DataSet dataSet = createDataSet( 'A', periodType ); dataSet.addOrganisationUnit( orgUnit ); manager.save( dataSet ); String postUrl = "/lockExceptions?ou=" + orgUnit.getUid() + "&pe=201612&ds=" + dataSet.getUid(); mvc.perform( post( postUrl ).session( session ).accept( TestUtils.APPLICATION_JSON_UTF8 ) ) .andExpect( status().is( 201 ) ) .andExpect( content().contentTypeCompatibleWith( TestUtils.APPLICATION_JSON_UTF8 ) ) .andDo( documentPrettyPrint( "lockExceptions/add" ) ); }
Example #5
Source File: ServiceVersionControllerTest.java From AthenaServing with Apache License 2.0 | 6 votes |
/** * 新增版本 * * @throws Exception */ @Test public void test_service_version_1_add() throws Exception { AddServiceVersionRequestBody body = new AddServiceVersionRequestBody(); body.setServiceId("3785028614114770944"); body.setVersion("1.0.0.1.fsghdjftj"); body.setDesc("1.0.0.1描述"); String result = this.mockMvc.perform(MockMvcRequestBuilders.post("/api/v1/service/version/add") .content(JSON.toJSONString(body)) .contentType(MediaType.APPLICATION_JSON) .session((MockHttpSession) Utils.getLoginSession(this.mockMvc)) .accept(MediaType.APPLICATION_JSON)) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Utils.assertResult(result); }
Example #6
Source File: HtmlUnitRequestBuilder.java From spring-analysis-note with MIT License | 6 votes |
private MockHttpSession httpSession(MockHttpServletRequest request, final String sessionid) { MockHttpSession session; synchronized (this.sessions) { session = this.sessions.get(sessionid); if (session == null) { session = new HtmlUnitMockHttpSession(request, sessionid); session.setNew(true); synchronized (this.sessions) { this.sessions.put(sessionid, session); } addSessionCookie(request, sessionid); } else { session.setNew(false); } } return session; }
Example #7
Source File: ServiceControllerTest.java From AthenaServing with Apache License 2.0 | 6 votes |
/** * 新增服务 * * @throws Exception */ @Test public void test_service_1_add() throws Exception { AddServiceRequestBody body = new AddServiceRequestBody(); body.setName("service4"); body.setDesc("服务4描述"); body.setClusterId("3717225558505947136"); String result = this.mockMvc.perform(MockMvcRequestBuilders.post("/api/v1/service/add") .content(JSON.toJSONString(body)) .contentType(MediaType.APPLICATION_JSON) .session((MockHttpSession) Utils.getLoginSession(this.mockMvc)) .accept(MediaType.APPLICATION_JSON)) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Utils.assertResult(result); }
Example #8
Source File: AbstractLoginTest.java From kafka-webview with MIT License | 6 votes |
/** * Attempt to login with invalid credentials. */ @Test public void test_invalidLoginAuthentication() throws Exception { for (final InvalidCredentialsTestCase testCase : getInvalidCredentials()) { // Attempt to login now final MvcResult result = mockMvc .perform(post("/login") .with(anonymous()) .with(csrf()) .param("email", testCase.getUsername()) .param("password", testCase.getPassword())) //.andDo(print()) .andExpect(status().is3xxRedirection()) .andExpect(redirectedUrl("/login?error=true")) .andReturn(); final MockHttpSession session = (MockHttpSession) result.getRequest().getSession(false); assertNotNull(session); assertNull("Should have no security context", session.getValue("SPRING_SECURITY_CONTEXT")); } }
Example #9
Source File: ClusterControllerTest.java From AthenaServing with Apache License 2.0 | 6 votes |
/** * 新增集群 * * @throws Exception */ @Test public void test_cluster_1_add() throws Exception { AddClusterRequestBody body = new AddClusterRequestBody(); body.setProjectId("3717225241441730560"); body.setName("cluster1"); body.setDesc("集群1描述"); String result = this.mockMvc.perform(MockMvcRequestBuilders.post("/api/v1/cluster/add") .content(JSON.toJSONString(body)) .contentType(MediaType.APPLICATION_JSON) .session((MockHttpSession) Utils.getLoginSession(this.mockMvc)) .accept(MediaType.APPLICATION_JSON)) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Utils.assertResult(result); }
Example #10
Source File: RedirectionSecurityIntegrationTest.java From tutorials with MIT License | 6 votes |
@Test public void givenAccessSecuredResource_whenAuthenticated_thenRedirectedBack() throws Exception { MockHttpServletRequestBuilder securedResourceAccess = get("/secured"); MvcResult unauthenticatedResult = mvc.perform(securedResourceAccess) .andExpect(status().is3xxRedirection()) .andReturn(); MockHttpSession session = (MockHttpSession) unauthenticatedResult.getRequest() .getSession(); String loginUrl = unauthenticatedResult.getResponse() .getRedirectedUrl(); mvc.perform(post(loginUrl).param("username", userDetails.getUsername()) .param("password", userDetails.getPassword()) .session(session) .with(csrf())) .andExpect(status().is3xxRedirection()) .andExpect(redirectedUrlPattern("**/secured")) .andReturn(); mvc.perform(securedResourceAccess.session(session)) .andExpect(status().isOk()); }
Example #11
Source File: ProjectControllerTest.java From AthenaServing with Apache License 2.0 | 6 votes |
/** * 编辑项目 * * @throws Exception */ @Test public void test_project_2_edit() throws Exception { EditProjectRequestBody body = new EditProjectRequestBody(); body.setId("3714708188751200256"); body.setDesc("修改项目后的描述"); String result = this.mockMvc.perform(MockMvcRequestBuilders.post("/api/v1/project/edit") .content(JSON.toJSONString(body)) .contentType(MediaType.APPLICATION_JSON) .session((MockHttpSession) Utils.getLoginSession(this.mockMvc)) .accept(MediaType.APPLICATION_JSON)) .andExpect(MockMvcResultMatchers.status().isOk()) .andDo(MockMvcResultHandlers.print()) .andReturn().getResponse().getContentAsString(); Utils.assertResult(result); }
Example #12
Source File: DataElementControllerDocumentation.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testCreateValidation() throws Exception { MockHttpSession session = getSession( "F_DATAELEMENT_PUBLIC_ADD" ); DataElement de = createDataElement( 'A' ); de.setName( null ); mvc.perform( post( "/dataElements" ) .session( session ) .contentType( TestUtils.APPLICATION_JSON_UTF8 ) .content( TestUtils.convertObjectToJsonBytes( de ) ) ) ; de = manager.getByName( DataElement.class, "DataElementA" ); assertNull( de ); }
Example #13
Source File: CommonTestSupport.java From spring-boot-security-saml-sample with Apache License 2.0 | 6 votes |
public MockHttpSession mockAnonymousHttpSession() { MockHttpSession mockSession = new MockHttpSession(); SecurityContext mockSecurityContext = mock(SecurityContext.class); AnonymousAuthenticationToken principal = new AnonymousAuthenticationToken( ANONYMOUS_USER_KEY, ANONYMOUS_USER_PRINCIPAL, AUTHORITIES); when(mockSecurityContext.getAuthentication()).thenReturn(principal); SecurityContextHolder.setContext(mockSecurityContext); mockSession.setAttribute( HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY, mockSecurityContext); return mockSession; }
Example #14
Source File: OAuth20CallbackAuthorizeControllerTests.java From cas4.0.x-server-wechat with Apache License 2.0 | 6 votes |
@Test public void testOKWithState() throws Exception { final MockHttpServletRequest mockRequest = new MockHttpServletRequest( "GET", CONTEXT + OAuthConstants.CALLBACK_AUTHORIZE_URL); mockRequest.addParameter(OAuthConstants.TICKET, SERVICE_TICKET); final MockHttpSession mockSession = new MockHttpSession(); mockSession.putValue(OAuthConstants.OAUTH20_CALLBACKURL, REDIRECT_URI); mockSession.putValue(OAuthConstants.OAUTH20_SERVICE_NAME, SERVICE_NAME); mockSession.putValue(OAuthConstants.OAUTH20_STATE, STATE); mockRequest.setSession(mockSession); final MockHttpServletResponse mockResponse = new MockHttpServletResponse(); final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController(); oauth20WrapperController.afterPropertiesSet(); final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse); assertEquals(OAuthConstants.CONFIRM_VIEW, modelAndView.getViewName()); final Map<String, Object> map = modelAndView.getModel(); assertEquals(SERVICE_NAME, map.get("serviceName")); assertEquals(REDIRECT_URI + "?" + OAuthConstants.CODE + "=" + SERVICE_TICKET + "&" + OAuthConstants.STATE + "=" + STATE, map.get("callbackUrl")); }
Example #15
Source File: AttributeControllerDocumentation.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void testGetByIdOk() throws Exception { InputStream input = new ClassPathResource( "attribute/SQLViewAttribute.json" ).getInputStream(); MockHttpSession session = getSession( "ALL" ); MvcResult postResult = mvc.perform( post( schema.getRelativeApiEndpoint() ) .session( session ) .contentType( TestUtils.APPLICATION_JSON_UTF8 ) .content( ByteStreams.toByteArray( input ) ) ) .andExpect( status().is( createdStatus ) ).andReturn(); Set<FieldDescriptor> fieldDescriptors = TestUtils.getFieldDescriptors( schema ); String uid = TestUtils.getCreatedUid( postResult.getResponse().getContentAsString() ); mvc.perform( get( schema.getRelativeApiEndpoint() + "/{id}", uid ).session( session ).accept( MediaType.APPLICATION_JSON ) ) .andExpect( status().isOk() ) .andExpect( content().contentTypeCompatibleWith( MediaType.APPLICATION_JSON ) ) .andExpect( jsonPath( "$.name" ).value( "sqlViewAttribute") ) .andDo( documentPrettyPrint( schema.getPlural() + "/id", responseFields( fieldDescriptors.toArray( new FieldDescriptor[fieldDescriptors.size()] ) ) ) ); }
Example #16
Source File: ServiceConfigControllerTest.java From AthenaServing with Apache License 2.0 | 6 votes |
/** * 批量推送配置 * * @throws Exception */ @Test public void test_service_config_5_batchPush() throws Exception { BatchPushServiceConfigRequestBody body = new BatchPushServiceConfigRequestBody(); List<String> ids = new ArrayList<>(); ids.add("3717226752750125056"); ids.add("3717226752750125057"); ids.add("3717226752750125058"); body.setIds(ids); List<String> regionIds = new ArrayList<>(); regionIds.add("3717224882795184128"); regionIds.add("3717225000453799936"); body.setRegionIds(regionIds); String result = this.mockMvc.perform(MockMvcRequestBuilders.post("/api/v1/service/config/batchPush") .content(JSON.toJSONString(body)) .contentType(MediaType.APPLICATION_JSON) .session((MockHttpSession) Utils.getLoginSession(this.mockMvc)) .accept(MediaType.APPLICATION_JSON)) .andExpect(MockMvcResultMatchers.status().isOk()) .andDo(MockMvcResultHandlers.print()) .andReturn().getResponse().getContentAsString(); Utils.assertResult(result); }
Example #17
Source File: QuickStartControllerTest.java From AthenaServing with Apache License 2.0 | 6 votes |
/** * 新增服务配置 * * @throws Exception */ @Test public void test_quick_start_3_addserviceConfig() throws Exception { ClassPathResource classPathResource1 = new ClassPathResource("config/application.yml"); MockMultipartFile multipartFile1 = new MockMultipartFile("file", "application.yml", "application/octet-stream", classPathResource1.getInputStream()); // ClassPathResource classPathResource2 = new ClassPathResource("2.yml"); // MockMultipartFile multipartFile2 = new MockMultipartFile("file", "2.yml", "application/octet-stream", classPathResource2.getInputStream()); // // ClassPathResource classPathResource3 = new ClassPathResource("3.yml"); // MockMultipartFile multipartFile3 = new MockMultipartFile("file", "3.yml", "application/octet-stream", classPathResource3.getInputStream()); String result = this.mockMvc.perform(MockMvcRequestBuilders.fileUpload("/api/v1/quickStart/addServiceConfig") .file(multipartFile1) // .file(multipartFile2) // .file(multipartFile3) .param("project", "测试项目") .param("cluster", "测试集群") .param("service", "测试服务") .param("version", "测试版本") .param("desc", "测试服务配置") .contentType(MediaType.MULTIPART_FORM_DATA) .session((MockHttpSession) Utils.getLoginSession(this.mockMvc)) .accept(MediaType.APPLICATION_JSON)).andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Utils.assertResult(result); }
Example #18
Source File: CustomAuditEventRepositoryIntTest.java From okta-jhipster-microservices-oauth-example with Apache License 2.0 | 6 votes |
@Test public void testAddEventWithWebAuthenticationDetails() { HttpSession session = new MockHttpSession(null, "test-session-id"); MockHttpServletRequest request = new MockHttpServletRequest(); request.setSession(session); request.setRemoteAddr("1.2.3.4"); WebAuthenticationDetails details = new WebAuthenticationDetails(request); Map<String, Object> data = new HashMap<>(); data.put("test-key", details); AuditEvent event = new AuditEvent("test-user", "test-type", data); customAuditEventRepository.add(event); List<PersistentAuditEvent> persistentAuditEvents = persistenceAuditEventRepository.findAll(); assertThat(persistentAuditEvents).hasSize(1); PersistentAuditEvent persistentAuditEvent = persistentAuditEvents.get(0); assertThat(persistentAuditEvent.getData().get("remoteAddress")).isEqualTo("1.2.3.4"); assertThat(persistentAuditEvent.getData().get("sessionId")).isEqualTo("test-session-id"); }
Example #19
Source File: HttpSessionChallengeRepositoryTest.java From webauthn4j-spring-security with Apache License 2.0 | 6 votes |
@Test public void saveChallenge_test_with_null() { MockHttpSession session = new MockHttpSession(); MockHttpServletRequest prevRequest = new MockHttpServletRequest(); prevRequest.setSession(session); MockHttpServletRequest request = new MockHttpServletRequest(); request.setSession(session); Challenge challenge = target.generateChallenge(); target.saveChallenge(challenge, prevRequest); target.saveChallenge(null, request); Challenge loadedChallenge = target.loadChallenge(request); assertThat(loadedChallenge).isNull(); }
Example #20
Source File: ApiVersionMethodTest.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testMethodAllExcludeV32() throws Exception { MockHttpSession session = getSession( "ALL" ); String endpoint = "/method/testAllExcludeV32"; mvc.perform( get( endpoint ).session( session ) ) .andExpect( status().isNotFound() ); mvc.perform( get( "/32" + endpoint ).session( session ) ) .andExpect( status().isNotFound() ); mvc.perform( get( "/32" + endpoint + "/a" ).session( session ) ) .andExpect( status().isNotFound() ); mvc.perform( get( "/32" + endpoint + "/b" ).session( session ) ) .andExpect( status().isNotFound() ); mvc.perform( get( "/31" + endpoint + "/a" ).session( session ) ) .andExpect( status().isOk() ); mvc.perform( get( "/31" + endpoint + "/b" ).session( session ) ) .andExpect( status().isOk() ); }
Example #21
Source File: TrackControllerTest.java From AthenaServing with Apache License 2.0 | 6 votes |
/** * 查询最近的配置推送轨迹列表 * * @throws Exception */ @Test public void test_track_1_config_lastestList() throws Exception { String result = this.mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/track/config/lastestList") .param("project", "测试项目") .param("cluster", "测试集群") .param("service", "测试服务") .param("version", "测试版本") .param("filterGray", "-1") .contentType(MediaType.APPLICATION_JSON) .session((MockHttpSession) Utils.getLoginSession(this.mockMvc)) .accept(MediaType.APPLICATION_JSON)) .andExpect(MockMvcResultMatchers.status().isOk()) .andDo(MockMvcResultHandlers.print()) .andReturn().getResponse().getContentAsString(); Utils.assertResult(result); }
Example #22
Source File: CustomAuditEventRepositoryIT.java From java-microservices-examples with Apache License 2.0 | 6 votes |
@Test public void testAddEventWithWebAuthenticationDetails() { HttpSession session = new MockHttpSession(null, "test-session-id"); MockHttpServletRequest request = new MockHttpServletRequest(); request.setSession(session); request.setRemoteAddr("1.2.3.4"); WebAuthenticationDetails details = new WebAuthenticationDetails(request); Map<String, Object> data = new HashMap<>(); data.put("test-key", details); AuditEvent event = new AuditEvent("test-user", "test-type", data); customAuditEventRepository.add(event); List<PersistentAuditEvent> persistentAuditEvents = persistenceAuditEventRepository.findAll(); assertThat(persistentAuditEvents).hasSize(1); PersistentAuditEvent persistentAuditEvent = persistentAuditEvents.get(0); assertThat(persistentAuditEvent.getData().get("remoteAddress")).isEqualTo("1.2.3.4"); assertThat(persistentAuditEvent.getData().get("sessionId")).isEqualTo("test-session-id"); }
Example #23
Source File: TrackControllerTest.java From AthenaServing with Apache License 2.0 | 6 votes |
/** * 批量删除配置推送轨迹 * * @throws Exception */ @Test public void test_track_4_config_batch_delete() throws Exception { IdsRequestBody body = new IdsRequestBody(); List<String> ids = new ArrayList<>(); ids.add("3717229385577660416"); ids.add("3717548557121617920"); body.setIds(ids); String result = this.mockMvc.perform(MockMvcRequestBuilders.post("/api/v1/track/config/batchDelete") .content(JSON.toJSONString(body)) .contentType(MediaType.APPLICATION_JSON) .session((MockHttpSession) Utils.getLoginSession(this.mockMvc)) .accept(MediaType.APPLICATION_JSON)) .andExpect(MockMvcResultMatchers.status().isOk()) .andDo(MockMvcResultHandlers.print()) .andReturn().getResponse().getContentAsString(); Utils.assertResult(result); }
Example #24
Source File: CustomAuditEventRepositoryIntTest.java From ehcache3-samples with Apache License 2.0 | 6 votes |
@Test public void testAddEventWithWebAuthenticationDetails() { HttpSession session = new MockHttpSession(null, "test-session-id"); MockHttpServletRequest request = new MockHttpServletRequest(); request.setSession(session); request.setRemoteAddr("1.2.3.4"); WebAuthenticationDetails details = new WebAuthenticationDetails(request); Map<String, Object> data = new HashMap<>(); data.put("test-key", details); AuditEvent event = new AuditEvent("test-user", "test-type", data); customAuditEventRepository.add(event); List<PersistentAuditEvent> persistentAuditEvents = persistenceAuditEventRepository.findAll(); assertThat(persistentAuditEvents).hasSize(1); PersistentAuditEvent persistentAuditEvent = persistentAuditEvents.get(0); assertThat(persistentAuditEvent.getData().get("remoteAddress")).isEqualTo("1.2.3.4"); assertThat(persistentAuditEvent.getData().get("sessionId")).isEqualTo("test-session-id"); }
Example #25
Source File: GrayConfigControllerTest.java From AthenaServing with Apache License 2.0 | 6 votes |
/** * 查询最近的配置列表 * * @throws Exception */ @Test public void test_gray_config_1_lastestList() throws Exception { String result = this.mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/grayConfig/lastestList") .param("project", "project3") .param("cluster", "cluster1") .param("service", "service1") .param("version", "1.0.0.1") .param("gray", "test1") .contentType(MediaType.APPLICATION_JSON) .session((MockHttpSession) Utils.getLoginSession(this.mockMvc)) .accept(MediaType.APPLICATION_JSON)) .andExpect(MockMvcResultMatchers.status().isOk()) .andDo(MockMvcResultHandlers.print()) .andReturn().getResponse().getContentAsString(); Utils.assertResult(result); }
Example #26
Source File: GrayConfigControllerTest.java From AthenaServing with Apache License 2.0 | 6 votes |
/** * 编辑配置 * * @throws Exception */ @Test public void test_gray_config_2_edit() throws Exception { EditServiceConfigRequestBody body = new EditServiceConfigRequestBody(); body.setId("3782760274025512960"); body.setContent("testAgin"); body.setDesc("修改灰度配置后的描述"); String result = this.mockMvc.perform(MockMvcRequestBuilders.post("/api/v1/grayConfig/edit") .content(JSON.toJSONString(body)) .contentType(MediaType.APPLICATION_JSON) .session((MockHttpSession) Utils.getLoginSession(this.mockMvc)) .accept(MediaType.APPLICATION_JSON)) .andExpect(MockMvcResultMatchers.status().isOk()) .andDo(MockMvcResultHandlers.print()) .andReturn().getResponse().getContentAsString(); Utils.assertResult(result); }
Example #27
Source File: AttributeControllerDocumentation.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void testDeleteByIdOk() throws Exception { InputStream input = new ClassPathResource( "attribute/SQLViewAttribute.json" ).getInputStream(); MockHttpSession session = getSession( "ALL" ); MvcResult postResult = mvc.perform( post( schema.getRelativeApiEndpoint() ) .session( session ) .contentType( TestUtils.APPLICATION_JSON_UTF8 ) .content( ByteStreams.toByteArray( input ) ) ) .andExpect( status().is( createdStatus ) ).andReturn(); String uid = TestUtils.getCreatedUid( postResult.getResponse().getContentAsString() ); mvc.perform( delete( schema.getRelativeApiEndpoint() + "/{id}", uid ).session( session ).accept( MediaType.APPLICATION_JSON ) ) .andExpect( status().is( deleteStatus ) ) .andDo( documentPrettyPrint( schema.getPlural() + "/delete" ) ); }
Example #28
Source File: CustomAuditEventRepositoryIntTest.java From e-commerce-microservice with Apache License 2.0 | 6 votes |
@Test public void testAddEventWithWebAuthenticationDetails() { HttpSession session = new MockHttpSession(null, "test-session-id"); MockHttpServletRequest request = new MockHttpServletRequest(); request.setSession(session); request.setRemoteAddr("1.2.3.4"); WebAuthenticationDetails details = new WebAuthenticationDetails(request); Map<String, Object> data = new HashMap<>(); data.put("test-key", details); AuditEvent event = new AuditEvent("test-user", "test-type", data); customAuditEventRepository.add(event); List<PersistentAuditEvent> persistentAuditEvents = persistenceAuditEventRepository.findAll(); assertThat(persistentAuditEvents).hasSize(1); PersistentAuditEvent persistentAuditEvent = persistentAuditEvents.get(0); assertThat(persistentAuditEvent.getData().get("remoteAddress")).isEqualTo("1.2.3.4"); assertThat(persistentAuditEvent.getData().get("sessionId")).isEqualTo("test-session-id"); }
Example #29
Source File: AttributeControllerDocumentation.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void testCreate() throws Exception { InputStream input = new ClassPathResource( "attribute/SQLViewAttribute.json" ).getInputStream(); MockHttpSession session = getSession( "ALL" ); Set<FieldDescriptor> fieldDescriptors = TestUtils.getFieldDescriptors( schema ); mvc.perform( post( schema.getRelativeApiEndpoint() ) .session( session ) .contentType( TestUtils.APPLICATION_JSON_UTF8 ) .content( ByteStreams.toByteArray( input ) ) ) .andExpect( status().is( createdStatus ) ) .andDo( documentPrettyPrint( schema.getPlural() + "/create", requestFields( fieldDescriptors.toArray( new FieldDescriptor[fieldDescriptors.size()] ) ) ) ); }
Example #30
Source File: CustomAuditEventRepositoryIntTest.java From okta-jhipster-microservices-oauth-example with Apache License 2.0 | 6 votes |
@Test public void testAddEventWithWebAuthenticationDetails() { HttpSession session = new MockHttpSession(null, "test-session-id"); MockHttpServletRequest request = new MockHttpServletRequest(); request.setSession(session); request.setRemoteAddr("1.2.3.4"); WebAuthenticationDetails details = new WebAuthenticationDetails(request); Map<String, Object> data = new HashMap<>(); data.put("test-key", details); AuditEvent event = new AuditEvent("test-user", "test-type", data); customAuditEventRepository.add(event); List<PersistentAuditEvent> persistentAuditEvents = persistenceAuditEventRepository.findAll(); assertThat(persistentAuditEvents).hasSize(1); PersistentAuditEvent persistentAuditEvent = persistentAuditEvents.get(0); assertThat(persistentAuditEvent.getData().get("remoteAddress")).isEqualTo("1.2.3.4"); assertThat(persistentAuditEvent.getData().get("sessionId")).isEqualTo("test-session-id"); }