@Test public void request_content_image_that_binary_is_on_main_version() throws Exception { // setup: content byte[] bytes = loadImage("Arn.JPG"); ContentKey contentKey = createImageContent( "MyImage.jpg", 2, bytes, "ImageCategory", new DateTime(2011, 6, 27, 10, 0, 0, 0), null); // setup: draft version of content ContentEntity content = fixture.findContentByKey(contentKey); BinaryDataEntity binaryDataOfMainVersion = content.getMainVersion().getBinaryData("source"); // exercise & verify String imageRequestPath = "_image/" + contentKey + "/binary/" + binaryDataOfMainVersion.getKey() + ".jpg"; setPathInfoAndRequestURI(httpServletRequest, imageRequestPath); httpServletRequest.setParameter("_background", "0xffffff"); httpServletRequest.setParameter("_quality", "100"); imageController.handleRequestInternal(httpServletRequest, httpServletResponse); assertEquals(HttpServletResponse.SC_OK, httpServletResponse.getStatus()); assertTrue("Content Length", httpServletResponse.getContentLength() > 0); assertEquals("image/jpg", httpServletResponse.getContentType()); }
public void testCoverageContents() throws Exception { final Long processId = issueProcessAndWaitForTermination(); final String request = RESTLET_PATH + "/" + processId.longValue(); final MockHttpServletResponse response = getAsServletResponse(request); assertEquals(Status.SUCCESS_OK, Status.valueOf(response.getStatus())); assertEquals(MediaType.APPLICATION_ZIP, MediaType.valueOf(response.getContentType())); final ByteArrayInputStream responseStream = getBinaryInputStream(response); File dataDirectoryRoot = super.getTestData().getDataDirectoryRoot(); File file = new File(dataDirectoryRoot, "testCoverageContents.zip"); super.getTestData().copyTo(responseStream, file.getName()); ZipFile zipFile = new ZipFile(file); try { // TODO: change this expectation once we normalize the raster file name String rasterName = RASTER_LAYER.getPrefix() + ":" + RASTER_LAYER.getLocalPart() + ".tiff"; ZipEntry nextEntry = zipFile.getEntry(rasterName); assertNotNull(nextEntry); InputStream coverageInputStream = zipFile.getInputStream(nextEntry); // Use a file, geotiffreader might not work well reading out of a plain input stream File covFile = new File(file.getParentFile(), "coverage.tiff"); IOUtils.copy(coverageInputStream, covFile); GeoTiffReader geoTiffReader = new GeoTiffReader(covFile); GridCoverage2D coverage = geoTiffReader.read(null); CoordinateReferenceSystem crs = coverage.getCoordinateReferenceSystem(); assertEquals(CRS.decode("EPSG:4326", true), crs); } finally { zipFile.close(); } }
public void testSMDPrimitivesNoResult() throws Exception { // request setRequestContent("smd-6.txt"); this.request.addHeader("content-type", "application/json-rpc"); JSONInterceptor interceptor = new JSONInterceptor(); interceptor.setEnableSMD(true); SMDActionTest1 action = new SMDActionTest1(); this.invocation.setAction(action); // can't be invoked interceptor.intercept(this.invocation); assertFalse(this.invocation.isInvoked()); // asert values were passed properly assertEquals("string", action.getStringParam()); assertEquals(1, action.getIntParam()); assertEquals(true, action.isBooleanParam()); assertEquals('c', action.getCharParam()); assertEquals(2, action.getLongParam()); assertEquals(new Float(3.3), action.getFloatParam()); assertEquals(4.4, action.getDoubleParam()); assertEquals(5, action.getShortParam()); assertEquals(6, action.getByteParam()); String json = response.getContentAsString(); String normalizedActual = TestUtils.normalize(json, true); String normalizedExpected = TestUtils.normalize(JSONResultTest.class.getResource("smd-11.txt")); assertEquals(normalizedExpected, normalizedActual); assertEquals("application/json;charset=ISO-8859-1", response.getContentType()); }
public void testDownload() throws Exception { final Long processId = issueProcessAndWaitForTermination(); // zip extension is not required but should be handled final String request = RESTLET_PATH + "/" + processId.longValue() + ".zip"; final MockHttpServletResponse response = getAsServletResponse(request); assertEquals(Status.SUCCESS_OK, Status.valueOf(response.getStatus())); assertEquals(MediaType.APPLICATION_ZIP, MediaType.valueOf(response.getContentType())); assertEquals( "attachment; filename=\"test map.zip\"", response.getHeader("Content-Disposition")); final ByteArrayInputStream responseStream = getBinaryInputStream(response); final ZipInputStream zipIn = new ZipInputStream(responseStream); Set<String> expectedFiles = new HashSet<String>(); expectedFiles.add("README.txt"); expectedFiles.add(VECTOR_LAYER.getLocalPart() + ".shp"); expectedFiles.add(VECTOR_LAYER.getLocalPart() + ".cst"); expectedFiles.add(VECTOR_LAYER.getLocalPart() + ".prj"); expectedFiles.add(VECTOR_LAYER.getLocalPart() + ".dbf"); expectedFiles.add(VECTOR_LAYER.getLocalPart() + ".shx"); // TODO: change this expectation once we normalize the raster file name expectedFiles.add(RASTER_LAYER.getPrefix() + ":" + RASTER_LAYER.getLocalPart() + ".tiff"); Set<String> archivedFiles = new HashSet<String>(); ZipEntry nextEntry; while ((nextEntry = zipIn.getNextEntry()) != null) { archivedFiles.add(nextEntry.getName()); } assertEquals(expectedFiles, archivedFiles); }
@Test public void verifyOK() throws Exception { final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT + OAuthConstants.ACCESS_TOKEN_URL); mockRequest.setParameter(OAuthConstants.CLIENT_ID, CLIENT_ID); mockRequest.setParameter(OAuthConstants.REDIRECT_URI, REDIRECT_URI); mockRequest.setParameter(OAuthConstants.CLIENT_SECRET, CLIENT_SECRET); mockRequest.setParameter(OAuthConstants.CODE, CODE); final MockHttpServletResponse mockResponse = new MockHttpServletResponse(); ((OAuth20WrapperController) oauth20WrapperController) .getServicesManager() .save(getRegisteredService(REDIRECT_URI, CLIENT_SECRET)); final Map<String, Object> map = new HashMap<>(); map.put(NAME, VALUE); final List<String> list = Arrays.asList(VALUE, VALUE); map.put(NAME2, list); final Principal p = org.jasig.cas.authentication.TestUtils.getPrincipal(ID, map); final TicketGrantingTicketImpl impl = new TicketGrantingTicketImpl( TGT_ID, org.jasig.cas.authentication.TestUtils.getAuthentication(p), new NeverExpiresExpirationPolicy()); ((OAuth20WrapperController) oauth20WrapperController) .getTicketRegistry() .addTicket( new ServiceTicketImpl( CODE, impl, org.jasig.cas.authentication.TestUtils.getService(), false, new ExpirationPolicy() { private static final long serialVersionUID = -7321055962209199811L; @Override public boolean isExpired(final TicketState ticketState) { return false; } })); oauth20WrapperController.handleRequest(mockRequest, mockResponse); ((OAuth20WrapperController) oauth20WrapperController).getTicketRegistry().deleteTicket(CODE); assertEquals("text/plain", mockResponse.getContentType()); assertEquals(200, mockResponse.getStatus()); final String body = mockResponse.getContentAsString(); assertTrue( body.startsWith( OAuthConstants.ACCESS_TOKEN + '=' + TGT_ID + '&' + OAuthConstants.EXPIRES + '=')); // delta = 2 seconds final int delta = 2; final int timeLeft = Integer.parseInt(StringUtils.substringAfter(body, '&' + OAuthConstants.EXPIRES + '=')); assertTrue(timeLeft >= TIMEOUT - 10 - delta); }
@Test public void shouldReturnXmlAndErrorMessageWhenPostOfPipelineAsInvalidPartialXml() throws Exception { groupName = BasicPipelineConfigs.DEFAULT_GROUP; configHelper.addPipeline("pipeline", "stage", "build1", "build2"); String badXml = "<pipeline name=\"cruise\" labeltemplate=\"invalid\">\n" + " <materials>\n" + " <svn url=\"file:///tmp/foo\" checkexternals=\"true\" />\n" + " </materials>\n" + " <stage name=\"dev\">\n" + " <jobs>\n" + " <job name=\"linux\" />\n" + " <job name=\"windows\" />\n" + " </jobs>\n" + " </stage>\n" + "</pipeline>"; String md5 = goConfigDao.md5OfConfigFile(); ModelAndView mav = controller.postPipelineAsXmlPartial(0, groupName, badXml, md5, response); assertThat(response.getStatus(), is(SC_CONFLICT)); assertThat(response.getContentType(), is(RESPONSE_CHARSET_JSON)); Map<String, String> json = (Map) mav.getModel().get("json"); assertThat(json.get("result").toString(), containsString("Label is invalid")); assertThat(json.get("originalContent"), is(badXml)); }
@Test public void customContentType() throws Exception { registerAndRefreshContext("spring.groovy.template.contentType:application/json"); MockHttpServletResponse response = render("home"); String result = response.getContentAsString(); assertThat(result, containsString("home")); assertThat(response.getContentType(), equalTo("application/json;charset=UTF-8")); }
@Test public void includesViewResolution() throws Exception { registerAndRefreshContext(); MockHttpServletResponse response = render("includes"); String result = response.getContentAsString(); assertThat(result, containsString("here")); assertThat(response.getContentType(), equalTo("text/html;charset=UTF-8")); }
@Test public void testCascadeGetLegendGraphics() throws Exception { // setup the layer WMSLayer layer = createWMSLayer("image/png"); final byte[] responseBody = new String("Fake body").getBytes(); layer.setSourceHelper( new WMSHttpHelper() { @Override public GetMethod executeRequest( URL url, Map<String, String> queryParams, Integer backendTimeout) throws HttpException, IOException { GetMethod response = EasyMock.createMock(GetMethod.class); expect(response.getStatusCode()).andReturn(200); expect(response.getResponseBodyAsStream()) .andReturn(new ByteArrayInputStream(responseBody)); expect(response.getResponseCharSet()).andReturn("UTF-8"); expect(response.getResponseHeader("Content-Type")) .andReturn(new Header("Content-Type", "image/png")); response.releaseConnection(); expectLastCall(); replay(response); return response; } }); MockLockProvider lockProvider = new MockLockProvider(); layer.setLockProvider(lockProvider); // setup the conveyor tile final StorageBroker mockStorageBroker = EasyMock.createMock(StorageBroker.class); String layerId = layer.getName(); MockHttpServletRequest servletReq = new MockHttpServletRequest(); servletReq.setQueryString( "REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=20&HEIGHT=20&LAYER=topp:states"); MockHttpServletResponse servletResp = new MockHttpServletResponse(); long[] gridLoc = {0, 0, 0}; // x, y, level MimeType mimeType = layer.getMimeTypes().get(0); GridSet gridSet = gridSetBroker.WORLD_EPSG4326; String gridSetId = gridSet.getName(); ConveyorTile tile = new ConveyorTile( mockStorageBroker, layerId, gridSetId, gridLoc, mimeType, null, servletReq, servletResp); // proxy the request, and check the response layer.proxyRequest(tile); assertEquals(200, servletResp.getStatus()); assertEquals("Fake body", servletResp.getContentAsString()); assertEquals("image/png", servletResp.getContentType()); }
@Test public void localeViewResolution() throws Exception { LocaleContextHolder.setLocale(Locale.FRENCH); registerAndRefreshContext(); MockHttpServletResponse response = render("includes", Locale.FRENCH); String result = response.getContentAsString(); assertThat(result, containsString("voila")); assertThat(response.getContentType(), equalTo("text/html;charset=UTF-8")); }
@Test public void shouldPostGroupWithChangedNameAsPartialXml() throws Exception { configHelper.addPipelineWithGroup("group", "pipeline", "dev", "linux", "windows"); String newXml = RENAMED_GROUP; String md5 = goConfigDao.md5OfConfigFile(); ModelAndView mav = controller.postGroupAsXmlPartial("group", newXml, md5, response); assertThat(response.getStatus(), is(SC_OK)); assertThat(response.getContentType(), is(RESPONSE_CHARSET_JSON)); assertResponseMessage(mav, "Group changed successfully."); }
@Test public void testCommenceWithXml() throws Exception { request.addHeader("Accept", MediaType.APPLICATION_XML_VALUE); entryPoint.commence(request, response, new BadCredentialsException("Bad")); assertEquals(HttpServletResponse.SC_UNAUTHORIZED, response.getStatus()); assertEquals( "<oauth><error_description>Bad</error_description><error>unauthorized</error></oauth>", response.getContentAsString()); assertEquals(MediaType.APPLICATION_XML_VALUE, response.getContentType()); assertEquals(null, response.getErrorMessage()); }
@Test public void shouldPostStageAsPartialXml() throws Exception { configHelper.addPipeline("pipeline", "stage", "build1", "build2"); String newXml = NEW_STAGE; String md5 = goConfigDao.md5OfConfigFile(); ModelAndView mav = controller.postStageAsXmlPartial("pipeline", 0, newXml, md5, response); assertThat(response.getStatus(), is(SC_OK)); assertThat(response.getContentType(), is(RESPONSE_CHARSET_JSON)); Map json = (Map) mav.getModel().get("json"); new JsonTester(json).shouldContain("{ 'result' : 'Stage changed successfully.' }"); }
@Test public void testCommenceWithEmptyAccept() throws Exception { entryPoint.commence(request, response, new BadCredentialsException("Bad")); assertEquals(HttpServletResponse.SC_UNAUTHORIZED, response.getStatus()); assertEquals( "{\"error\":\"unauthorized\",\"error_description\":\"Bad\"}", response.getContentAsString()); assertTrue( MediaType.APPLICATION_JSON.isCompatibleWith(MediaType.valueOf(response.getContentType()))); assertEquals(null, response.getErrorMessage()); }
@Test public void testCommenceWithJson() throws Exception { request.addHeader("Accept", MediaType.APPLICATION_JSON_VALUE); entryPoint.commence(request, response, new BadCredentialsException("Bad")); assertEquals(HttpServletResponse.SC_UNAUTHORIZED, response.getStatus()); assertEquals( "{\"error\":\"unauthorized\",\"error_description\":\"Bad\"}", response.getContentAsString()); assertEquals(MediaType.APPLICATION_JSON_VALUE, response.getContentType()); assertEquals(null, response.getErrorMessage()); }
@Test public void shouldReturnXmlAndErrorMessageWhenInvalidPostOfStageAsPartialXml() throws Exception { configHelper.addPipeline("pipeline", "stage", "build1", "build2"); String md5 = goConfigDao.md5OfConfigFile(); ModelAndView mav = controller.postStageAsXmlPartial("pipeline", 4, NEW_STAGE, md5, response); assertThat(response.getStatus(), is(SC_NOT_FOUND)); assertThat(response.getContentType(), is(RESPONSE_CHARSET_JSON)); Map<String, Object> json = (Map) mav.getModel().get("json"); Map<String, Object> jsonMap = new LinkedHashMap<>(); jsonMap.put("result", "Stage does not exist."); jsonMap.put("originalContent", NEW_STAGE); assertThat(json, is(jsonMap)); }
@Test public void contentShouldIncludeMd5Checksum_forAgentLauncher() throws Exception { controller.downloadAgentLauncher(response); assertEquals("8443", response.getHeader("Cruise-Server-Ssl-Port")); assertEquals("application/octet-stream", response.getContentType()); try (InputStream stream = JarDetector.create(systemEnvironment, "agent-launcher.jar")) { assertEquals(md5DigestOfStream(stream), response.getHeader("Content-MD5")); } try (InputStream is = JarDetector.create(systemEnvironment, "agent-launcher.jar")) { assertTrue(Arrays.equals(IOUtils.toByteArray(is), response.getContentAsByteArray())); } }
@Test public void verifyNoGivenAccessToken() throws Exception { final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT + OAuthConstants.PROFILE_URL); final MockHttpServletResponse mockResponse = new MockHttpServletResponse(); oAuth20ProfileController.handleRequest(mockRequest, mockResponse); assertEquals(200, mockResponse.getStatus()); assertEquals(CONTENT_TYPE, mockResponse.getContentType()); assertEquals( "{\"error\":\"" + OAuthConstants.MISSING_ACCESS_TOKEN + "\"}", mockResponse.getContentAsString()); }
@Test public void verifyNoExistingAccessToken() throws Exception { final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT + OAuthConstants.PROFILE_URL); mockRequest.setParameter(OAuthConstants.ACCESS_TOKEN, "DOES NOT EXIST"); final MockHttpServletResponse mockResponse = new MockHttpServletResponse(); oAuth20ProfileController.handleRequest(mockRequest, mockResponse); assertEquals(200, mockResponse.getStatus()); assertEquals(CONTENT_TYPE, mockResponse.getContentType()); assertEquals( "{\"error\":\"" + OAuthConstants.EXPIRED_ACCESS_TOKEN + "\"}", mockResponse.getContentAsString()); }
@Test public void shouldReturnXmlAndErrorMessageWhenInvalidPostOfBuildAsPartialXml() throws Exception { configHelper.addPipeline("pipeline", "stage", "build1", "build2"); String newXml = "<job name=\"build3\" />"; String md5 = goConfigDao.md5OfConfigFile(); ModelAndView mav = controller.postBuildAsXmlPartial("pipeline", "stage", 4, newXml, md5, response); assertThat(response.getStatus(), is(SC_NOT_FOUND)); assertThat(response.getContentType(), is(RESPONSE_CHARSET_JSON)); Map json = (Map) mav.getModel().get("json"); new JsonTester(json) .shouldContain( "{ 'result' : 'Build does not exist.'," + " 'originalContent' : '" + newXml + "' }"); }
@Test public void shouldModifyExistingPipelineTemplateWhenPostedAsPartial() throws Exception { configHelper.addPipelineWithGroup( "some-group", "some-pipeline", "some-dev", "some-linux", "some-windows"); configHelper.addAgent("some-home", "UUID"); String newXml = NEW_TEMPLATES; String md5 = goConfigDao.md5OfConfigFile(); ModelAndView mav = controller.postGroupAsXmlPartial("Pipeline Templates", newXml, md5, response); assertResponseMessage(mav, "Template changed successfully."); assertThat(response.getStatus(), is(SC_OK)); assertThat(response.getContentType(), is(RESPONSE_CHARSET_JSON)); assertThat(configHelper.currentConfig().getTemplates().size(), is(1)); }
@Test public void shouldReturnAgentPluginsZipWhenRequested() throws Exception { File pluginZipFile = TestFileUtil.createTempFile("plugins.zip"); FileUtils.writeStringToFile(pluginZipFile, "content"); when(pluginsZip.md5()).thenReturn("md5"); when(systemEnvironment.get(SystemEnvironment.ALL_PLUGINS_ZIP_PATH)) .thenReturn(pluginZipFile.getAbsolutePath()); controller.downloadPluginsZip(response); String actual = response.getContentAsString(); assertEquals("application/octet-stream", response.getContentType()); assertEquals("content", actual); }
@Test public void testDownloadMultiLayer() throws Exception { String requestURL = "wms/kml?&layers=" + getLayerId(MockData.LAKES) + "," + getLayerId(MockData.FORESTS); MockHttpServletResponse response = getAsServletResponse(requestURL); assertEquals(KMLMapOutputFormat.MIME_TYPE, response.getContentType()); assertEquals( "attachment; filename=cite-Lakes_cite-Forests.kml", response.getHeader("Content-Disposition")); Document dom = dom(getBinaryInputStream(response)); print(dom); assertXpathEvaluatesTo("1", "count(kml:kml/kml:Document)", dom); assertXpathEvaluatesTo("2", "count(kml:kml/kml:Document/kml:NetworkLink)", dom); assertXpathEvaluatesTo("2", "count(kml:kml/kml:Document/kml:NetworkLink/kml:LookAt)", dom); }
@Test public void verifyOKWithAuthorizationHeader() throws Exception { final Map<String, Object> map = new HashMap<>(); map.put(NAME, VALUE); final List<String> list = Arrays.asList(VALUE, VALUE); map.put(NAME2, list); final Principal principal = org.jasig.cas.authentication.TestUtils.getPrincipal(ID, map); final Authentication authentication = new OAuthAuthentication(ZonedDateTime.now(), principal); final AccessTokenImpl accessToken = (AccessTokenImpl) accessTokenFactory.create(TestUtils.getService(), authentication); oAuth20ProfileController.getTicketRegistry().addTicket(accessToken); final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT + OAuthConstants.PROFILE_URL); mockRequest.addHeader("Authorization", OAuthConstants.BEARER_TOKEN + ' ' + accessToken.getId()); final MockHttpServletResponse mockResponse = new MockHttpServletResponse(); oAuth20ProfileController.handleRequest(mockRequest, mockResponse); assertEquals(200, mockResponse.getStatus()); assertEquals(CONTENT_TYPE, mockResponse.getContentType()); final ObjectMapper mapper = new ObjectMapper(); final String expected = "{\"id\":\"" + ID + "\",\"attributes\":[{\"" + NAME + "\":\"" + VALUE + "\"},{\"" + NAME2 + "\":[\"" + VALUE + "\",\"" + VALUE + "\"]}]}"; final JsonNode expectedObj = mapper.readTree(expected); final JsonNode receivedObj = mapper.readTree(mockResponse.getContentAsString()); assertEquals(expectedObj.get("id").asText(), receivedObj.get("id").asText()); final JsonNode expectedAttributes = expectedObj.get("attributes"); final JsonNode receivedAttributes = receivedObj.get("attributes"); assertEquals( expectedAttributes.findValue(NAME).asText(), receivedAttributes.findValue(NAME).asText()); assertEquals(expectedAttributes.findValues(NAME2), receivedAttributes.findValues(NAME2)); }
@Test public void shouldReturnXmlAndErrorMessageWhenPostOfStageAsInvalidPartialXml() throws Exception { configHelper.addPipeline("pipeline", "stage", "build1", "build2"); String badXml = "<;askldjfa;dsklfja;sdjas;lkdf"; String md5 = goConfigDao.md5OfConfigFile(); ModelAndView mav = controller.postStageAsXmlPartial("pipeline", 0, badXml, md5, response); assertThat(response.getStatus(), is(SC_CONFLICT)); assertThat(response.getContentType(), is(RESPONSE_CHARSET_JSON)); Map json = (Map) mav.getModel().get("json"); new JsonTester(json) .shouldContain( "{ 'result' : 'Error on line 1 of document : The markup in the document preceding the root element must be well-formed. Nested exception: The markup in the document preceding the root element must be well-formed.'," + " 'originalContent' : '" + badXml + "' }"); }
@Test public void testLaunchViewerIDVRequest() throws IOException { ViewerRequestParamsBean params = new ViewerRequestParamsBean(); params.setUrl( "http://localhost:9080/thredds/dodsC/gribCollection/GFS_CONUS_80km/files/GFS_CONUS_80km_20120227_0000.grib1"); params.setViewer("idv"); BindingResult result = new BeanPropertyBindingResult(params, "params"); MockHttpServletResponse res = new MockHttpServletResponse(); MockHttpServletRequest req = new MockHttpServletRequest(); req.setRequestURI( "/thredds/view/idv.jnlp?url=http://localhost:9080/thredds/dodsC/gribCollection/GFS_CONUS_80km/files/GFS_CONUS_80km_20120227_0000.grib1"); viewerController.launchViewer(params, result, res, req); assertEquals(200, res.getStatus()); assertEquals("application/x-java-jnlp-file", res.getContentType()); }
@Test public void request_content_image_with_label_small() throws Exception { byte[] bytes = loadImage("Arn.JPG"); ContentKey contentKey = createImageContent( "MyImage.jpg", 2, bytes, "ImageCategory", new DateTime(2011, 6, 27, 10, 0, 0, 0), null); String imageRequestPath = "_image/" + contentKey.toString() + "/label/small"; setPathInfoAndRequestURI(httpServletRequest, imageRequestPath); httpServletRequest.setParameter("_background", "0xffffff"); httpServletRequest.setParameter("_quality", "100"); imageController.handleRequestInternal(httpServletRequest, httpServletResponse); assertEquals("image/png", httpServletResponse.getContentType()); assertEquals(HttpServletResponse.SC_OK, httpServletResponse.getStatus()); }
@SuppressWarnings("unchecked") public void testSMDObjectsNoResult() throws Exception { // request setRequestContent("smd-7.txt"); this.request.addHeader("content-type", "application/json-rpc"); JSONInterceptor interceptor = new JSONInterceptor(); interceptor.setEnableSMD(true); SMDActionTest1 action = new SMDActionTest1(); this.invocation.setAction(action); // can't be invoked interceptor.intercept(this.invocation); assertFalse(this.invocation.isInvoked()); // asert values were passed properly Bean bean = action.getBeanParam(); assertNotNull(bean); assertTrue(bean.isBooleanField()); assertEquals(bean.getStringField(), "test"); assertEquals(bean.getIntField(), 10); assertEquals(bean.getCharField(), 's'); assertEquals(bean.getDoubleField(), 10.1); assertEquals(bean.getByteField(), 3); List list = action.getListParam(); assertNotNull(list); assertEquals("str0", list.get(0)); assertEquals("str1", list.get(1)); Map map = action.getMapParam(); assertNotNull(map); assertNotNull(map.get("a")); assertEquals(new Long(1), map.get("a")); assertNotNull(map.get("c")); List insideList = (List) map.get("c"); assertEquals(1.0d, insideList.get(0)); assertEquals(2.0d, insideList.get(1)); String json = response.getContentAsString(); String normalizedActual = TestUtils.normalize(json, true); String normalizedExpected = TestUtils.normalize(JSONResultTest.class.getResource("smd-11.txt")); assertEquals(normalizedExpected, normalizedActual); assertEquals("application/json;charset=ISO-8859-1", response.getContentType()); }
@Test public void testLaunchViewerToolsUIVRequest() throws IOException { ViewerRequestParamsBean params = new ViewerRequestParamsBean(); params.setViewer("ToolsUI"); params.setCatalog( "http://localhost:9080/thredds/catalog/gribCollection/GFS_CONUS_80km/files/catalog.xml"); params.setDataset("gribCollection/GFS_CONUS_80km/files/GFS_CONUS_80km_20120227_0000.grib1"); BindingResult result = new BeanPropertyBindingResult(params, "params"); MockHttpServletResponse res = new MockHttpServletResponse(); MockHttpServletRequest req = new MockHttpServletRequest(); req.setRequestURI( "/thredds/view/ToolsUI.jnlp?catalog=http://localhost:9080/thredds/catalog/gribCollection/GFS_CONUS_80km/files/catalog.xml&dataset=ncss_tests/files/GFS_CONUS_80km_20120227_0000.grib1"); viewerController.launchViewer(params, result, res, req); assertEquals(200, res.getStatus()); assertEquals("application/x-java-jnlp-file", res.getContentType()); }
/* Tests if service correctly dispatches the request. */ @Test public final void testService() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); MockServletConfig config = new MockServletConfig(); ContentModuleServlet servlet = new ContentModuleServlet(cache); servlet.init(config); request.setServletPath("/com/globant/katari/jsmodule/view/image/a.png"); request.setMethod("GET"); servlet.service(request, response); assertThat(response.getStatus(), is(200)); assertThat(response.getContentType(), is("image/png")); }