List of usage examples for org.springframework.core.io FileSystemResource FileSystemResource
public FileSystemResource(Path filePath)
From source file:com.google.code.maven.plugin.http.client.transformer.ResponseToFileResourceTest.java
@Test public void transformTest() throws Exception { String charset = "UTF-8"; HttpResponse response = createMock(HttpResponse.class);// HttpEntity entity = createMock(HttpEntity.class);// createMockBuilder(HttpEntity.class).createMock(); ResponseToFileResource transformer = new ResponseToFileResource(); transformer.setTarget(new FileSystemResource(new File("target/test-files/" + getClass().getSimpleName()))); ByteArrayInputStream in = new ByteArrayInputStream("Hello World".getBytes(charset)); expect(response.getEntity()).andReturn(entity); expect(entity.getContent()).andReturn(in); replay(response, entity);/* w ww . j a v a 2 s .c o m*/ transformer.transform(response); verify(response, entity); }
From source file:org.globus.security.filestore.TestFileBasedCRL.java
@Test public void testGetCrl() throws Exception { this.testCrl1.copyFileToTemp(); String tempFileName = this.testCrl1.getAbsoluteFilename(); ResourceCRL fileCrl = new ResourceCRL(new FileSystemResource(new File(tempFileName))); // assert (fileCrl != null); X509CRL crl = fileCrl.getCrl(); assert (crl != null); assertFalse(fileCrl.hasChanged());// ww w . j av a 2 s . co m crl = fileCrl.getCrl(); assert (crl != null); assertFalse(fileCrl.hasChanged()); this.testCrl1.modifyFile(); crl = fileCrl.getCrl(); assert (crl != null); assertTrue(fileCrl.hasChanged()); }
From source file:edu.colorado.orcid.TestSpringContext.java
@Test public void testLoadContext() throws Exception { GenericXmlApplicationContext context = new GenericXmlApplicationContext( new FileSystemResource("src/main/webapp/WEB-INF/spring-servlet.xml")); context.close();//from ww w.j av a2 s. c om }
From source file:org.broadleafcommerce.admin.util.controllers.RemoveFileController.java
private void checkDirectory(String basepath) { FileSystemResource dirResource = new FileSystemResource(basepath); if (dirResource.exists()) { File f = new File(basepath); if (!deleteDir(f)) { throw new RuntimeException("Could not delete directory or file: " + f.getAbsolutePath()); }//w w w .j a v a 2 s . co m } }
From source file:de.langmi.spring.batch.examples.complex.file.split.GetLineCountTaskletTest.java
@Test public void testExecute() throws Exception { // setup//from w w w. jav a 2 s. c o m tasklet = new GetLineCountTasklet(); tasklet.setResource(new FileSystemResource(INPUT)); StepExecution stepExecution = MetaDataInstanceFactory.createStepExecution(); // execute RepeatStatus status = tasklet.execute(new StepContribution(stepExecution), new ChunkContext(new StepContext(stepExecution))); // assertions assertEquals(RepeatStatus.FINISHED, status); assertEquals(EXPECTED_COUNT, stepExecution.getExecutionContext().get("line.count")); }
From source file:nl.flotsam.hamcrest.schema.relaxng.RelaxNGMatchers.java
/** * Creates a RelaxNG matcher based on a {@link File} object pointing to a RelaxNG schema. (XML Syntax) *///from w w w.j a va 2 s . c o m public static TypeSafeDiagnosingMatcher<Object> isValidatedBy(File file) { return isValidatedBy(new FileSystemResource(file)); }
From source file:org.globus.security.filestore.TestFileBasedSigningPolicy.java
@Test public void testSigningPolicy() throws Exception { this.testPolicy1.copyFileToTemp(); ResourceSigningPolicy filePolicy = new ResourceSigningPolicy( new FileSystemResource(testPolicy1.getAbsoluteFilename())); Collection<SigningPolicy> policies = filePolicy.getSigningPolicies(); assert (policies != null); assert (policies.size() == 2); // assert policy values here assertFalse(filePolicy.hasChanged()); policies = filePolicy.getSigningPolicies(); assert (policies != null); assertFalse(filePolicy.hasChanged()); testPolicy1.modifyFile();// w w w . ja v a 2 s . co m policies = filePolicy.getSigningPolicies(); assert (policies != null); assertTrue(filePolicy.hasChanged()); }
From source file:org.gwtwidgets.server.spring.test.ResourceLoaderSupport.java
@Override public Resource getResource(String arg) { Matcher matcher = serialisationPolicyPattern.matcher(arg); boolean serializationPolicyFound = matcher.find(); logger.debug("Looking up resource " + arg + " " + serializationPolicyFound); if (!serializationPolicyFound) return super.getResource(arg); String newResource = "target/webapp/static/" + matcher.group(2); logger.debug("Translating resource to " + newResource); return new FileSystemResource(newResource); }
From source file:org.apache.smscserver.test.spring.SpringConfigTest.java
public void test() throws Throwable { // FIXME: Hasan variable not expanded System.setProperty("SMSC_HOME", "./target/"); XmlBeanFactory factory = new XmlBeanFactory( new FileSystemResource("src/test/resources/spring-config/config-spring-1.xml")); DefaultSmscServer server = (DefaultSmscServer) factory.getBean("server"); Assert.assertEquals(500, server.getServerContext().getConnectionConfig().getMaxBinds()); Assert.assertEquals(124, server.getServerContext().getConnectionConfig().getMaxBindFailures()); Assert.assertEquals(125, server.getServerContext().getConnectionConfig().getBindFailureDelay()); Assert.assertEquals(4, server.getServerContext().getConnectionConfig().getMinThreads()); Assert.assertEquals(16, server.getServerContext().getConnectionConfig().getMaxThreads()); Assert.assertEquals(2, server.getServerContext().getDeliveryManagerConfig().getManagerThreads()); Assert.assertEquals(8, server.getServerContext().getDeliveryManagerConfig().getMinThreads()); Assert.assertEquals(24, server.getServerContext().getDeliveryManagerConfig().getMaxThreads()); Assert.assertEquals(1000, server.getServerContext().getSessionLockTimeout()); Map<String, Listener> listeners = server.getServerContext().getListeners(); Assert.assertEquals(3, listeners.size()); Listener listener = listeners.get("listener1"); Assert.assertNotNull(listener);/*from w w w. j ava 2s . c om*/ Assert.assertTrue(listener instanceof MyCustomListener); Assert.assertEquals(2223, listener.getPort()); listener = listeners.get("listener2"); Assert.assertNotNull(listener); Assert.assertTrue(listener instanceof MyCustomListener); Assert.assertEquals(2224, listener.getPort()); CommandFactory cf = server.getCommandFactory(); Assert.assertTrue(cf.getCommand(9) instanceof BindCommand); Assert.assertTrue(cf.getCommand(21) instanceof EnquireLinkCommand); Assert.assertEquals(2, server.getSmsclets().size()); Assert.assertEquals(123, ((TestSmsclet) server.getSmsclets().get("smsclet1")).getFoo()); Assert.assertEquals(223, ((TestSmsclet) server.getSmsclets().get("smsclet2")).getFoo()); Assert.assertNotNull(server.getServerContext().getMessageManager()); }
From source file:de.langmi.spring.batch.examples.readers.file.flatfileitemreader.FlatFileItemReaderTest.java
/** * Test should read succesfully./* w w w.j a v a2s . c o m*/ * * @throws Exception */ @Test public void testSuccessfulReading() throws Exception { // init reader reader.setLineMapper(new PassThroughLineMapper()); reader.setResource(new FileSystemResource(INPUT_FILE)); // open, provide "mock" ExecutionContext reader.open(MetaDataInstanceFactory.createStepExecution().getExecutionContext()); // read try { int count = 0; String line; while ((line = reader.read()) != null) { assertEquals(String.valueOf(count), line); count++; } assertEquals(EXPECTED_COUNT, count); } catch (Exception e) { throw e; } finally { reader.close(); } }