Importer extends SwingWorker<Void, Void> { @Override public Void doInBackground() { setProgress(0); PersistenceProvider provider = PlatformAccess.getPlatform().getPersistenceProvider(); provider.startRelatedOperations(); boolean completed = false; try { importComponents(); completed = true; } finally { provider.completeRelatedOperations(completed); } return null; } Importer(List<File> files, String owner,	AbstractComponent selectedComponent, 
			        JProgressBar progressBar, JDialog jd);  Importer(List<File> files, String owner, AbstractComponent selectedComponent); @Override Void doInBackground(); @Override void done();  }
@Test (enabled=true, dataProvider="validData") public void testImport(String inputFilename, String expectedRootName, boolean cyclical, int numTopLevel) throws Exception { File file = new File(inputFilename); ArrayList<File> files = new ArrayList<File>(); files.add(file); componentA = createAbstractComponent("compA", "0"); componentA.save(); Assert.assertEquals(0, componentA.getComponents().size()); Importer importer = new Importer(files, "TheOwner", componentA); importer.doInBackground(); Assert.assertEquals(componentA.getComponents().size(), 1); Assert.assertEquals(componentA.getComponents().get(0) .getComponents().size(), 1); Assert.assertEquals(componentA.getComponents().get(0) .getComponents().get(0) .getComponents().size(), numTopLevel); AbstractComponent importedComp = componentA.getComponents().get(0) .getComponents().get(0) .getComponents().get(0); Assert.assertEquals(importedComp.getDisplayName(), expectedRootName); if (cyclical) { verifyCyclicalSave(componentA); } else { verifySave(componentA); } }
@Test public void testMultipleXMLFiles() { List<File> files = new ArrayList<File>(); File file = new File("src/test/resources/testData/testCanvas.xml"); files.add(file); file = new File("src/test/resources/testData/testLotsOfPUIs.xml"); files.add(file); file = new File("src/test/resources/testData/testBadAssocCompID.xml"); files.add(file); componentA = createAbstractComponent("compA", "0"); componentA.save(); Importer importer = new Importer(files, "TheOwner", componentA); importer.doInBackground(); Assert.assertEquals(componentA.getComponents().size(), 1); Assert.assertEquals(componentA.getComponents().get(0) .getComponents().size(), 3); for (AbstractComponent comp : componentA.getComponents().get(0).getComponents()) { Assert.assertEquals(comp.getComponents().size(), 1); } verifyCyclicalSave(componentA); }
@Test(enabled=true, dataProvider="invalidData") public void testInvalid(String invalidFile) { File file = new File(invalidFile); ArrayList<File> files = new ArrayList<File>(); files.add(file); componentA = createAbstractComponent("compA", "0"); componentA.save(); Importer importer = new Importer(files, "TheOwner", componentA); importer.doInBackground(); Assert.assertEquals(componentA.getComponents().size(), 0); }