@Override public void execute() { try { File file = new File(path); file.mkdir(); file = new File(path + config.getName() + extention); file.createNewFile(); JAXBContext jc = JAXBContext.newInstance(PrintConfiguration.class); JAXBElement<PrintConfiguration> je = new JAXBElement<PrintConfiguration>( new QName(xmlHeadName), PrintConfiguration.class, config); Marshaller marshaller = jc.createMarshaller(); OutputStream os = new FileOutputStream(path + config.getName() + extention); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(je, os); file = null; os = null; System.gc(); result = Boolean.TRUE; } catch (Exception ex) { Logger.getLogger(SavePrintConfigurationCommand.class.getName()).log(Level.SEVERE, null, ex); result = Boolean.FALSE; } }
/** Test of execute method, of class SaveExtruderConfigurationCommand. */ @Test public void SavePrintTest() throws IOException { String actual; String path = "./Database/Prints/" + print.getName() + ".xml"; SavePrintConfigurationCommand instance = new SavePrintConfigurationCommand(print); instance.execute(); assertTrue((Boolean) instance.getResult()); actual = FileUtils.readFileToString(new File(path)); actual = actual.substring(0, actual.length() - 1); if (!expected.equals(actual)) System.out.printf( "Test " + this.getClass().getName() + " expected: " + expected + "\nGot: " + actual); assertTrue(expected.equals(actual)); }