// Test selectedAll, deselect item, selectAll
 // SearchResultTree 6A - basic flow. SelectAll then deselect one itemNode and then selectAll
 // again.
 // Result: selectedDataSearchResult should contain all Patients and all other JTree items.
 @Test
 public void testUpdatedSelectedDataSearchResult6A() {
   resultTree.addDataSelectionListener(this);
   resultTree.selectAll(true);
   synchronized (this) {
     while (selectedDataSearchResult.getPatients().size() == 0) {
       try {
         this.wait();
       } catch (InterruptedException e1) {
         logger.error(e1, e1);
       }
     }
   }
   DefaultMutableTreeNode rootNode = resultTree.getRootNode();
   DefaultMutableTreeNode locationNode = (DefaultMutableTreeNode) rootNode.getChildAt(0);
   PatientNode patientNode1 = (PatientNode) locationNode.getChildAt(0);
   StudyNode studyNode1 = (StudyNode) patientNode1.getChildAt(0);
   SeriesNode seriesNode1 = (SeriesNode) studyNode1.getChildAt(0);
   ItemNode itemNode1 = (ItemNode) seriesNode1.getChildAt(0);
   resultTree.updateSelection(itemNode1, false);
   synchronized (this) {
     while (selectedDataSearchResult.getPatients().size() == 0) {
       try {
         this.wait();
       } catch (InterruptedException e1) {
         logger.error(e1, e1);
       }
     }
   }
   resultTree.selectAll(true);
   synchronized (this) {
     while (selectedDataSearchResult.getPatients().size() == 0) {
       try {
         this.wait();
       } catch (InterruptedException e1) {
         logger.error(e1, e1);
       }
     }
   }
   assertSelectAll(selectedDataSearchResult);
 }
 // SearchResultTree 1A - basic flow. One ItemNode selected.
 // Result: selectedDataSearchResult should contain one patient, one study, one series and one
 // selected itemNode.
 @Test
 public void testUpdatedSelectedDataSearchResult1A() {
   resultTree.addDataSelectionListener(this);
   DefaultMutableTreeNode rootNode = resultTree.getRootNode();
   DefaultMutableTreeNode locationNode = (DefaultMutableTreeNode) rootNode.getChildAt(0);
   PatientNode patientNode1 = (PatientNode) locationNode.getChildAt(0);
   StudyNode studyNode1 = (StudyNode) patientNode1.getChildAt(0);
   SeriesNode seriesNode1 = (SeriesNode) studyNode1.getChildAt(0);
   ItemNode itemNode1 = (ItemNode) seriesNode1.getChildAt(0);
   resultTree.updateSelection(itemNode1, true);
   synchronized (this) {
     while (selectedDataSearchResult.getPatients().size() == 0) {
       try {
         this.wait();
       } catch (InterruptedException e1) {
         logger.error(e1, e1);
       }
     }
   }
   List<Patient> patients = selectedDataSearchResult.getPatients();
   int numbOfPatients = patients.size();
   assertEquals(
       "Invalid number of patients. Expected: 1, actual: " + numbOfPatients, 1, numbOfPatients);
   if (numbOfPatients == 1) {
     Patient patient = patients.get(0);
     assertEquals(
         "Invalid patient. Expected id: 111, actual: " + patient.getPatientID(),
         "111",
         patient.getPatientID());
   }
   List<Study> studies = patients.get(0).getStudies();
   int numbOfStudies = studies.size();
   assertEquals(
       "Invalid number of studies. Expected: 1, actual: " + numbOfStudies, 1, numbOfStudies);
   if (numbOfStudies == 1) {
     Study study = studies.get(0);
     assertEquals(
         "Invalid study. Expected studyInstanceUID: 101.101, actual: "
             + study.getStudyInstanceUID(),
         "101.101",
         study.getStudyInstanceUID());
   }
   List<Series> series = studies.get(0).getSeries();
   int numbOfSeries = series.size();
   assertEquals("Invalid number of series. Expected: 1, actual: " + numbOfSeries, 1, numbOfSeries);
   if (numbOfSeries == 1) {
     Series oneSeries = series.get(0);
     assertEquals(
         "Invalid series. Expected seriesInstanceUID: 101.101.1, actual: "
             + oneSeries.getSeriesInstanceUID(),
         "101.101.1",
         oneSeries.getSeriesInstanceUID());
   }
   List<Item> items = series.get(0).getItems();
   int numbOfItems = items.size();
   assertEquals("Invalid number of items. Expected: 1, actual: " + numbOfItems, 1, numbOfItems);
   if (numbOfItems == 1) {
     Item item = items.get(0);
     assertEquals(
         "Invalid item. Expected item id: 101.101.1.000.000.1, actual: " + item.getItemID(),
         "101.101.1.000.000.1",
         item.getItemID());
   }
 }
 // SearchResultTree 3A - basic flow. One StudyNode selected.
 // Result: selectedDataSearchResult should contain one patient, one selected study, and Series and
 // items found in selected Study.
 @Test
 public void testUpdatedSelectedDataSearchResult3A() {
   resultTree.addDataSelectionListener(this);
   DefaultMutableTreeNode rootNode = resultTree.getRootNode();
   DefaultMutableTreeNode locationNode = (DefaultMutableTreeNode) rootNode.getChildAt(0);
   PatientNode patientNode1 = (PatientNode) locationNode.getChildAt(0);
   StudyNode studyNode2 = (StudyNode) patientNode1.getChildAt(1);
   resultTree.updateSelection(studyNode2, true);
   synchronized (this) {
     while (selectedDataSearchResult.getPatients().size() == 0) {
       try {
         this.wait();
       } catch (InterruptedException e1) {
         logger.error(e1, e1);
       }
     }
   }
   List<Patient> patients = selectedDataSearchResult.getPatients();
   int numbOfPatients = patients.size();
   assertEquals(
       "Invalid number of patients. Expected: 1, actual: " + numbOfPatients, 1, numbOfPatients);
   if (numbOfPatients == 1) {
     Patient patient = patients.get(0);
     assertEquals(
         "Invalid patient. Expected id: 111, actual: " + patient.getPatientID(),
         "111",
         patient.getPatientID());
   }
   List<Study> studies = patients.get(0).getStudies();
   int numbOfStudies = studies.size();
   assertEquals(
       "Invalid number of studies. Expected: 1, actual: " + numbOfStudies, 1, numbOfStudies);
   if (numbOfStudies == 1) {
     Study study = studies.get(0);
     assertEquals(
         "Invalid study. Expected studyInstanceUID: 202.202, actual: "
             + study.getStudyInstanceUID(),
         "202.202",
         study.getStudyInstanceUID());
   }
   List<Series> series = studies.get(0).getSeries();
   int numbOfSeries = series.size();
   assertEquals("Invalid number of series. Expected: 2, actual: " + numbOfSeries, 2, numbOfSeries);
   if (numbOfSeries == 2) {
     Series series2 = series.get(0);
     assertEquals(
         "Invalid series. Expected seriesInstanceUID: 202.202.1, actual: "
             + series2.getSeriesInstanceUID(),
         "202.202.1",
         series2.getSeriesInstanceUID());
     Series series3 = series.get(1);
     assertEquals(
         "Invalid series. Expected seriesInstanceUID: 303.303.1, actual: "
             + series3.getSeriesInstanceUID(),
         "303.303.1",
         series3.getSeriesInstanceUID());
   }
   List<Item> itemsSeries2 = series.get(0).getItems();
   int numbOfItemsSeries2 = itemsSeries2.size();
   assertEquals(
       "Invalid number of items. Expected: 2, actual: " + numbOfItemsSeries2,
       2,
       numbOfItemsSeries2);
   if (numbOfItemsSeries2 == 2) {
     Item item2 = itemsSeries2.get(0);
     assertEquals(
         "Invalid item. Expected item id: 202.202.1.000.000.1, actual: " + item2.getItemID(),
         "202.202.1.000.000.1",
         item2.getItemID());
     Item item3 = itemsSeries2.get(1);
     assertEquals(
         "Invalid item. Expected item id: 202.202.1.000.000.2, actual: " + item3.getItemID(),
         "202.202.1.000.000.2",
         item3.getItemID());
   }
   List<Item> itemsSeries3 = series.get(1).getItems();
   int numbOfItemsSeries3 = itemsSeries3.size();
   assertEquals(
       "Invalid number of items. Expected: 2, actual: " + numbOfItemsSeries3,
       2,
       numbOfItemsSeries3);
   if (numbOfItemsSeries3 == 2) {
     Item item4 = itemsSeries3.get(0);
     assertEquals(
         "Invalid item. Expected item id: 303.303.1.000.000.1, actual: " + item4.getItemID(),
         "303.303.1.000.000.1",
         item4.getItemID());
     Item item5 = itemsSeries3.get(1);
     assertEquals(
         "Invalid item. Expected item id: 303.303.1.000.000.2, actual: " + item5.getItemID(),
         "303.303.1.000.000.2",
         item5.getItemID());
   }
 }