// 执行测试前先初始模拟对象 @Before public void before() { request = new MockHttpServletRequest(); response = new MockHttpServletResponse(); session = new MockHttpSession(); request.setCharacterEncoding("UTF-8"); }
@Test public void setCharacterEncodingThenContentType() { request.setCharacterEncoding("UTF-8"); request.setContentType("test/plain"); assertEquals("test/plain", request.getContentType()); assertEquals("test/plain;charset=UTF-8", request.getHeader("Content-Type")); assertEquals("UTF-8", request.getCharacterEncoding()); }
public void testResolveSimpleSitePath123() { httpServletRequest.setCharacterEncoding("ISO-8859-1"); httpServletRequest.setRequestURI("/site/123/Frontpage/"); SitePath sitePath = sitePathResolver.resolveSitePath(httpServletRequest); assertEquals(siteKey_123, sitePath.getSiteKey()); assertEquals("/Frontpage/", sitePath.getLocalPath().toString()); }
public void testResolveSimpleSitePathWithNoLocalPathAndNoEndSlash() { httpServletRequest.setCharacterEncoding("ISO-8859-1"); httpServletRequest.setRequestURI("/site/123"); SitePath sitePath = sitePathResolver.resolveSitePath(httpServletRequest); assertEquals(siteKey_123, sitePath.getSiteKey()); assertEquals("", sitePath.getLocalPath().toString()); }
@Before public void setUp() { mockMvc = MockMvcBuilders.webAppContextSetup(this.wac) .alwaysDo(MockMvcResultHandlers.print()) .build(); request = new MockHttpServletRequest(); request.setCharacterEncoding("UTF-8"); response = new MockHttpServletResponse(); }
@Before public void before() { factory = fixture.getFactory(); fixture.initSystemData(); fixture.createAndStoreUserAndUserGroup( "testuser", "testuser fullname", UserType.NORMAL, "testuserstore"); ServletRequestAttributes servletRequestAttributes = new ServletRequestAttributes(httpServletRequest); RequestContextHolder.setRequestAttributes(servletRequestAttributes); httpServletRequest.setCharacterEncoding("UTF-8"); ServletRequestAccessor.setRequest(httpServletRequest); loginUserInAdmin(fixture.findUserByName("testuser").getKey()); loginUserInPortal(fixture.findUserByName("testuser").getKey()); imageController.setGroupDao(groupDao); imageController.setContentDao(contentDao); imageController.setSecurityService(securityService); imageController.setImageService(imageService); imageController.setDisableParamEncoding(true); previewService = Mockito.mock(PreviewService.class); Mockito.when(previewService.isInPreview()).thenReturn(false); Mockito.when(previewService.getPreviewContext()).thenReturn(PreviewContext.NO_PREVIEW); site1 = factory.createSite("MySite", new Date(), null, "en"); fixture.save(site1); MenuItemEntity firstPage = createPage("Firstpage", null, "MySite"); fixture.save(firstPage); site1.setFirstPage(firstPage); fixture.flushAndClearHibernateSesssion(); fixture.save( factory.createContentHandler( "Image content", ContentHandlerName.IMAGE.getHandlerClassShortName())); fixture.save( factory.createContentType( "ImageContentType", ContentHandlerName.IMAGE.getHandlerClassShortName())); fixture.save(factory.createUnit("ImageUnit")); fixture.save( factory.createCategory( "ImageCategory", "ImageContentType", "ImageUnit", "testuser", "testuser")); fixture.save( factory.createCategoryAccessForUser("ImageCategory", "testuser", "read, create, approve")); fixture.flushAndClearHibernateSesssion(); }
@Before public void before() { fixture = new DomainFixture(hibernateTemplate); factory = new DomainFactory(fixture); fixture.initSystemData(); fixture.createAndStoreUserAndUserGroup( "testuser", "testuser fullname", UserType.NORMAL, "testuserstore"); httpServletRequest.setCharacterEncoding("UTF-8"); ServletRequestAccessor.setRequest(httpServletRequest); loginUserInPortal(fixture.findUserByName("testuser").getKey()); previewService = Mockito.mock(PreviewService.class); Mockito.when(previewService.isInPreview()).thenReturn(false); Mockito.when(previewService.getPreviewContext()).thenReturn(PreviewContext.NO_PREVIEW); imageController.setPreviewService(previewService); MockTimeService timeService = new MockTimeService(new DateTime(2011, 6, 27, 12, 0, 0, 0)); imageController.setTimeService(timeService); site1 = factory.createSite("MySite", new Date(), null, "en"); fixture.save(site1); MenuItemEntity firstPage = createPage("Firstpage", null, "MySite"); fixture.save(firstPage); site1.setFirstPage(firstPage); fixture.flushAndClearHibernateSesssion(); fixture.save( factory.createContentHandler( "Image content", ContentHandlerName.IMAGE.getHandlerClassShortName())); fixture.save( factory.createContentType( "ImageContentType", ContentHandlerName.IMAGE.getHandlerClassShortName())); fixture.save(factory.createUnit("ImageUnit")); fixture.save( factory.createCategory( "ImageCategory", "ImageContentType", "ImageUnit", "testuser", "testuser")); fixture.save( factory.createCategoryAccessForUser("ImageCategory", "testuser", "read, create, approve")); fixture.flushAndClearHibernateSesssion(); }
@BeforeClass public static void before() { request = new MockHttpServletRequest(); request.setCharacterEncoding("UTF-8"); response = new MockHttpServletResponse(); }