List of usage examples for org.springframework.core.io ClassPathResource ClassPathResource
public ClassPathResource(String path)
From source file:org.terasoluna.gfw.functionaltest.app.download.DownloadTest.java
@Test public void test01_01_fileDownload() throws IOException { ResponseEntity<byte[]> response = restTemplate.getForEntity(applicationContextUrl + "/download/1_1", byte[].class); ClassPathResource images = new ClassPathResource("/image/Duke.png"); byte[] expected = StreamUtils.copyToByteArray(images.getInputStream()); HttpHeaders headers = response.getHeaders(); System.out.println("test01_01_fileDownload: X-Track=" + headers.getFirst("X-Track")); assertThat(headers.getFirst("Content-Disposition"), is("attachment; filename=Duke.png")); MediaType contentType = headers.getContentType(); assertThat(contentType.getType(), is("image")); assertThat(contentType.getSubtype(), is("png")); assertThat(response.getBody(), is(expected)); }
From source file:org.cloudfoundry.client.lib.SampleProjects.java
/** * Returns a spring application using a file with a non-ascii name. * * @return the non-ascii-file-name WAR file * @throws IOException//from w w w . java2s.c o m */ public static File nonAsciFileName() throws IOException { ClassPathResource cpr = new ClassPathResource("non-ascii-file-name.war"); File file = cpr.getFile(); assertTrue("Expected test app at " + file.getCanonicalPath(), file.exists()); return file; }
From source file:nl.surfnet.coin.teams.service.impl.GroupServiceBasicAuthentication10aTest.java
@Test public void testGetGroupMembersAvans() { super.setResponseResource(new ClassPathResource("avans-teammembers.json")); GroupMembersEntry entry = groupService.getGroupMembersEntry(provider, "personId", "urn:collab:group:avans.nl:testgroup", 2147483647, 0); assertEquals(12, entry.getEntry().size()); }
From source file:org.ngrinder.script.repository.FileEntryRepositoryTest.java
/** * Locate dumped user1 repo into tempdir * * @throws IOException/* w w w. j av a 2 s . c om*/ */ @Before public void before() throws IOException { File file = new File(System.getProperty("java.io.tmpdir"), "repo"); FileUtils.deleteQuietly(file); CompressionUtils.unzip(new ClassPathResource("TEST_USER.zip").getFile(), file); repo.setUserRepository(new File(file, getTestUser().getUserId())); }
From source file:io.lavagna.service.ExportImportServiceTest.java
@Test public void testImportAndExport() throws IOException { Path tmp = Files.createTempFile(null, null); try (InputStream is = new ClassPathResource("io/lavagna/export2.zip").getInputStream()) { Files.copy(is, tmp, StandardCopyOption.REPLACE_EXISTING); exportImportService.importData(false, tmp); // TODO additional checks exportImportService.exportData(new ByteArrayOutputStream()); } finally {/*from w ww.j a v a2 s . c om*/ if (tmp != null) { Files.deleteIfExists(tmp); } } }
From source file:guru.qas.martini.gherkin.DefaultMixologyTest.java
@Test public void testParameterization() throws IOException { Resource resource = new ClassPathResource("/subsystem/parameters.feature"); Iterable<Recipe> recipes = factory.get(resource); int recipeCount = Iterables.size(recipes); assertEquals(2, recipeCount, "wrong number of Recipe objects returned"); }
From source file:gov.nih.nci.integration.util.CommonsPropertyLoaderUtil.java
/** * Load properties from following locations in mentioned order * /* w ww. j a v a2s. c o m*/ * <pre> * #a)${user.home}/.integration/${ant.project.name}/${ant.project.name}.properties where ${user.home) is system property * #b)${app.home}/.integration/${ant.project.name} (where ${catalina.home) is a system property) * #c)classpath:${ant.project.name}.properties * </pre> * * @param projectName - project name * @param propertyFileName - property file name * @return properties if it can resolve any of the property file, exceptions if no property file is available */ public static Properties loadProperties(final String projectName, final String propertyFileName) { if (StringUtils.isEmpty(projectName) || StringUtils.isEmpty(propertyFileName)) { throw new IllegalArgumentException("Project name and property file name must not be null!"); } final String userHomePathToScan = String.format("user.home/.integration/%s/%s", projectName, propertyFileName); final String appHomePathToScan = String.format("app.home/.integration/%s/%s", projectName, propertyFileName); final Properties properties = new Properties(); // 1. first load property from classpath fillProperties(new ClassPathResource(propertyFileName), properties); // 2. now merge properties from tomcat fillPropertiesFromFileSystem(properties, APP_HOME, appHomePathToScan); // 3. finally merge properties from user.home fillPropertiesFromFileSystem(properties, USER_HOME, userHomePathToScan); for (Map.Entry<Object, Object> entry : properties.entrySet()) { LOG.debug(String.format("loaded property - %s:%s", entry.getKey(), entry.getValue())); } return properties; }
From source file:slina.mb.parsing.LogParserTests.java
@Test public void testLog4jFile() throws IOException { LogFileReader reader = new LogFileReaderImpl(); Resource res = new ClassPathResource(this.poolLog); File file = res.getFile();//w w w . j av a2 s . c o m String var = file.getAbsolutePath(); List<String> filelist = reader.readFile(var); assertTrue(filelist.size() > 0); System.out.println(filelist.size()); List<LogEvent> eventsList = this.stdLogParser.createLogEvents(2, filelist); assertTrue(eventsList.size() > 0); System.out.println(eventsList.size()); System.out.println("\n\n"); }
From source file:org.jasig.cas.adaptors.generic.FileAuthenticationHandlerTests.java
/** * @see junit.framework.TestCase#setUp() *///from www. j a v a2 s . co m protected void setUp() throws Exception { super.setUp(); this.authenticationHandler = new FileAuthenticationHandler(); this.authenticationHandler .setFileName(new ClassPathResource("org/jasig/cas/adaptors/generic/authentication.txt")); }
From source file:net.javacrumbs.springws.test.itest.InvalidMessagesTest.java
@Test @SuppressWarnings("unused") public void testInvalidResponse() throws IOException { WebServiceTemplate webServiceTemplate = new WebServiceTemplate(); webServiceTemplate.setCheckConnectionForFault(false); MockWebServiceMessageSender messageSender = new MockWebServiceMessageSender(); DefaultResponseGenerator responseGenerator = new DefaultResponseGenerator(); responseGenerator.setNeverCreateEnvelope(true); SimpleResourceLookup resourceLookup = new SimpleResourceLookup( new ClassPathResource("mock-responses/test/default-response-invalid.xml")); resourceLookup.setTemplateProcessor(new TemplateProcessor() { public Resource processTemplate(Resource resource, WebServiceMessage message) throws IOException { return resource; }/* www . j ava 2 s. co m*/ }); responseGenerator.setResourceLookup(resourceLookup); messageSender.setRequestProcessors(Arrays.asList(responseGenerator)); webServiceTemplate.setMessageSender(messageSender); Source source = getValidMessage().getPayloadSource(); StringResult result = new StringResult(); //TODO uncomment // webServiceTemplate.sendSourceAndReceiveToResult(TEST_URI.toString(), source, result); }