private boolean refresh() { String url; if (urlField.getSelectedItem() == null) { url = urlField.getEditor().getItem().toString(); } else { url = urlField.getSelectedItem().toString(); } url = checkCatalogURLString(url); final InvCatalogFactory factory = InvCatalogFactory.getDefaultFactory(true); final InvCatalog catalog = factory.readXML(url); final List<InvDataset> datasets = catalog.getDatasets(); if (datasets.size() == 0) { JOptionPane.showMessageDialog(this, "Cannnot find THREDDS catalog service xml at '" + url + "'"); return false; } urlField.setSelectedItem(url); catalogTree.setNewRootDatasets(datasets); variableFilter.stopFiltering(); return true; }
@Test public void testWhetherRootNodeHasBeenExchanged() { //preparation final InvDatasetImpl fileDataset = createDataset(catalog, "second", "file"); final ArrayList<InvDataset> otherDatasets = new ArrayList<InvDataset>(); otherDatasets.add(fileDataset); //execution catalogTree.setNewRootDatasets(datasets); //verification final DefaultMutableTreeNode root = (DefaultMutableTreeNode) ((JTree) catalogTree.getComponent()).getModel().getRoot(); catalogTree.setNewRootDatasets(otherDatasets); final DefaultMutableTreeNode otherRoot = (DefaultMutableTreeNode) ((JTree) catalogTree.getComponent()).getModel().getRoot(); assertEquals(false, root.equals(otherRoot)); }
@Test public void testThatPreviousDatasetsHaveBeenRemoved() { //preparation catalogTree.setNewRootDatasets(datasets); final DefaultMutableTreeNode previousRootNode = (DefaultMutableTreeNode) ((JTree) catalogTree.getComponent()).getModel().getRoot(); final InvDatasetImpl fileDataset = createDataset(catalog, "second", "file"); final ArrayList<InvDataset> otherDatasets = new ArrayList<InvDataset>(); otherDatasets.add(fileDataset); //execution catalogTree.setNewRootDatasets(otherDatasets); //verification final DefaultMutableTreeNode newRootNode = (DefaultMutableTreeNode) ((JTree) catalogTree.getComponent()).getModel().getRoot(); assertNotSame(previousRootNode, newRootNode); }
@Test public void testAddingDapDataset() { //execution catalogTree.setNewRootDatasets(datasets); //verification assertEquals(true, ((JTree) catalogTree.getComponent()).getModel().getRoot() instanceof DefaultMutableTreeNode); final DefaultMutableTreeNode root = (DefaultMutableTreeNode) ((JTree) catalogTree.getComponent()).getModel().getRoot(); assertEquals(1, root.getChildCount()); assertEquals(true, CatalogTreeUtils.isDapNode(root.getChildAt(0))); assertEquals("first", ((DefaultMutableTreeNode) root.getChildAt(0)).getUserObject().toString()); }
@Test public void testGetLeaves() throws Exception { Assume.assumeTrue(!GraphicsEnvironment.isHeadless()); final CatalogTree catalogTree = new CatalogTree(null, new DefaultAppContext(""), null); List<InvDataset> datasets = new ArrayList<InvDataset>(); InvCatalog catalog = new InvCatalogImpl("catalogName", "1.0", new URI("http://x.y")); final InvDataset rootDataset = createDataset(catalog, "first", "OPENDAP"); rootDataset.getDatasets().add(createDataset(catalog, "second", "OPENDAP")); rootDataset.getDatasets().add(createDataset(catalog, "third", "OPENDAP")); datasets.add(rootDataset); catalogTree.setNewRootDatasets(datasets); OpendapLeaf[] leaves = catalogTree.getLeaves(); Arrays.sort(leaves, new Comparator<OpendapLeaf>() { @Override public int compare(OpendapLeaf o1, OpendapLeaf o2) { return o1.getName().compareTo(o2.getName()); } }); assertEquals(2, leaves.length); assertEquals("second", leaves[0].getName()); assertEquals("third", leaves[1].getName()); }
@Test public void testAddingDatasetWithDAPAccessAndOneWithFileAccessOnly_FileAccessOnlyResolvesToNodeWithFileAccess() { //preparation final InvDatasetImpl fileDataset = createDataset(catalog, "second", "file"); datasets.add(fileDataset); //execution catalogTree.setNewRootDatasets(datasets); //verification final DefaultMutableTreeNode root = (DefaultMutableTreeNode) ((JTree) catalogTree.getComponent()).getModel().getRoot(); assertEquals(2, root.getChildCount()); assertEquals(true, CatalogTreeUtils.isDapNode(root.getChildAt(0))); assertEquals(false, CatalogTreeUtils.isFileNode(root.getChildAt(0))); assertEquals(false, CatalogTreeUtils.isDapNode(root.getChildAt(1))); assertEquals(true, CatalogTreeUtils.isFileNode(root.getChildAt(1))); }