List of usage examples for org.springframework.core.io Resource getFile
File getFile() throws IOException;
From source file:org.slc.sli.ingestion.tool.ValidationControllerTest.java
@Test public void testProcessInvalidZip() throws IOException, NoSuchFieldException, IllegalAccessException { ZipFileHandler handler = Mockito.mock(ZipFileHandler.class); Field zipField = validationController.getClass().getDeclaredField("zipFileHandler"); zipField.setAccessible(true);/* w ww. java 2s.c o m*/ zipField.set(validationController, handler); Resource zipFileResource = new ClassPathResource(zipFileName); File zipFile = zipFileResource.getFile(); ValidationController vc = Mockito.spy(validationController); ErrorReport er = Mockito.mock(ErrorReport.class); Field errorReport = validationController.getClass().getDeclaredField("errorReport"); errorReport.setAccessible(true); errorReport.set(null, er); Mockito.when(er.hasErrors()).thenReturn(true); Mockito.doReturn(zipFile).when(handler).handle(zipFile, er); vc.processZip(zipFile); Mockito.verify(vc, Mockito.never()).processControlFile(zipFile); }
From source file:se.inera.axel.shs.camel.DefaultCamelShsMessageConverterTest.java
@DirtiesContext @Test//ww w.j a va 2 s. c o m public void convertXmlFileToShsMessage() throws Exception { resultEndpoint.expectedMessageCount(1); Resource xmlResource = new ClassPathResource("se/inera/axel/shs/camel/xmlFile.xml"); File xmlFile = xmlResource.getFile(); Map<String, Object> headers = new HashMap<String, Object>(); headers.put(ShsHeaders.FROM, DEFAULT_TEST_FROM); headers.put(ShsHeaders.TO, DEFAULT_TEST_TO); headers.put(ShsHeaders.SUBJECT, DEFAULT_TEST_SUBJECT); headers.put(ShsHeaders.PRODUCT_ID, DEFAULT_TEST_PRODUCT_ID); headers.put(Exchange.CONTENT_TYPE, "text/xml"); headers.put(ShsHeaders.DATAPART_TYPE, "xml"); template.sendBodyAndHeaders("direct:camelToShsConverter", xmlFile, headers); resultEndpoint.assertIsSatisfied(); List<Exchange> exchanges = resultEndpoint.getExchanges(); Exchange exchange = exchanges.get(0); Message in = exchange.getIn(); ShsMessage shsMessage = in.getMandatoryBody(ShsMessage.class); List<DataPart> dataParts = shsMessage.getDataParts(); Assert.assertNotNull(dataParts); Assert.assertEquals(dataParts.size(), 1); DataPart dataPart = dataParts.get(0); Assert.assertEquals(dataPart.getFileName(), xmlFile.getName()); Assert.assertEquals(dataPart.getDataPartType(), "xml"); Assert.assertEquals((long) dataPart.getContentLength(), xmlFile.length()); }
From source file:org.mongeez.reader.FormattedJavascriptChangeSetReader.java
private void parseFileHeader(Resource file, String line) throws IOException, ParseException { if (line == null || !FILE_HEADER_PATTERN.matcher(line).matches()) { throw new ParseException(file.getFile().getPath() + " did not begin with the expected comment:\n" + LINE_COMMENT + FILE_HEADER, -1); }/*from w w w.j a v a2 s . c o m*/ }
From source file:org.slc.sli.ingestion.tool.ValidationControllerTest.java
@Test public void testValidatorValid() throws IOException, NoSuchFieldException, IllegalAccessException { Resource xmlResource = new ClassPathResource("test/InterchangeStudent.xml"); File xmlFile = xmlResource.getFile(); IngestionFileEntry ife = Mockito.mock(IngestionFileEntry.class); Mockito.when(ife.getFileName()).thenReturn("InterchangeStudent.xml"); Mockito.when(ife.getFile()).thenReturn(xmlFile); Mockito.when(ife.getFileType()).thenReturn(FileType.XML_STUDENT_PARENT_ASSOCIATION); Job job = BatchJob.createDefault("testJob"); job.addFile(ife);/*from ww w .jav a 2 s . c o m*/ Logger log = Mockito.mock(Logger.class); Field logField = validationController.getClass().getDeclaredField("logger"); logField.setAccessible(true); logField.set(null, log); validationController.processValidators(job); Mockito.verify(log, Mockito.atLeastOnce()).info("Processing of file: {} completed.", ife.getFileName()); }
From source file:slina.mb.utils.LogFileReaderImpl.java
public List<String> readFile(Resource resource) { List<String> lines = new ArrayList<String>(); try {/*from w w w . j a va2s. co m*/ long before = System.currentTimeMillis(); File file = resource.getFile(); BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file))); String line = reader.readLine(); while (line != null) { lines.add(line); line = reader.readLine(); } long after = System.currentTimeMillis(); reader.close(); LOGGER.info("conv. run took " + (after - before) + " ms, size = " + lines.size()); return lines; } catch (IOException e) { LOGGER.error(e); return lines; } }
From source file:uk.org.taverna.platform.OSGIFrameworkIT.java
public void testPrintConfig() throws IOException { Resource[] bundles = getTestBundles(); Resource[] testBundles = getTestFrameworkBundles(); StringBuilder sb = new StringBuilder(); StringBuilder sb2 = new StringBuilder(); System.out.println("mkdir platform"); System.out.println("mkdir platform/configuration"); sb2.append("cp "); sb.append("osgi.bundles="); boolean printComma = false; for (Resource resource : bundles) { if (printComma) { sb.append(", "); sb2.append(" "); }// w w w .ja v a 2 s . c o m sb.append(resource.getFilename() + "@start"); sb2.append(resource.getFile()); printComma = true; } for (Resource resource : testBundles) { if (!resource.getFilename().contains("test")) { if (printComma) { sb.append(", "); sb2.append(" "); } sb.append(resource.getFilename() + "@start"); sb2.append(resource.getFile()); printComma = true; } } sb2.append(" platform"); System.out.println("echo \"" + sb.toString() + "\" > platform/configuration/config.ini"); System.out.println(sb2.toString()); System.out.println("zip platform.zip platform/*"); }
From source file:architecture.ee.web.struts2.action.admin.ajax.TemplateFinderAction.java
public List<FileInfo> getTargetFiles() { Resource root = getTargetRootResource(); List<FileInfo> list = new ArrayList<FileInfo>(); boolean opt = useCustomizedTemplateSource(); try {//from w w w. j a v a2 s .com File file = root.getFile(); if (StringUtils.isEmpty(path)) { for (File f : file.listFiles()) { list.add(new FileInfo(file, f, opt)); } } else { File targetFile = getTargetResource().getFile(); for (File f : targetFile.listFiles()) { list.add(new FileInfo(file, f, opt)); } } } catch (IOException e) { log.error(e); } return list; }
From source file:org.paxml.core.PaxmlResource.java
public long getLastModified() { Resource res = getSpringResource(); if (!res.exists()) { return -1; }//w w w . j a v a 2s .c o m final File file; try { file = res.getFile(); } catch (IOException e) { return 0; } return file.lastModified(); }
From source file:at.gv.egiz.bku.spring.PKIProfileFactoryBean.java
protected File getDirectory(String url) throws IOException { Resource resource = resourceLoader.getResource(url); File path = resource.getFile(); if (!path.exists() && !path.isDirectory()) { throw new IOException("URL '" + url + "' is not a directory."); }//w w w .j ava 2s. c o m return path; }
From source file:org.slc.sli.ingestion.tool.ValidationControllerTest.java
@Test public void testValidatorInValid() throws IOException, NoSuchFieldException, IllegalAccessException { Resource xmlResource = new ClassPathResource("emptyXml/InterchangeStudent.xml"); File xmlFile = xmlResource.getFile(); IngestionFileEntry ife = Mockito.mock(IngestionFileEntry.class); Mockito.when(ife.getFileName()).thenReturn("InterchangeStudent.xml"); Mockito.when(ife.getFile()).thenReturn(xmlFile); Mockito.when(ife.getFileType()).thenReturn(FileType.XML_STUDENT_PARENT_ASSOCIATION); Job job = BatchJob.createDefault("testJob"); job.addFile(ife);//from ww w.j av a2 s. co m Logger log = Mockito.mock(Logger.class); Field logField = validationController.getClass().getDeclaredField("logger"); logField.setAccessible(true); logField.set(null, log); validationController.processValidators(job); Mockito.verify(log, Mockito.atLeastOnce()).info("Processing of file: {} resulted in errors.", ife.getFileName()); }