2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.workers;
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertFalse;
25 import static org.testng.AssertJUnit.assertTrue;
27 import jalview.api.AlignCalcManagerI;
28 import jalview.api.AlignCalcWorkerI;
29 import jalview.api.FeatureRenderer;
30 import jalview.datamodel.Alignment;
31 import jalview.datamodel.AlignmentAnnotation;
32 import jalview.datamodel.AlignmentI;
33 import jalview.datamodel.Annotation;
34 import jalview.datamodel.Sequence;
35 import jalview.datamodel.SequenceI;
36 import jalview.gui.AlignFrame;
37 import jalview.gui.JvOptionPane;
39 import java.util.Collections;
40 import java.util.List;
42 import org.testng.annotations.BeforeClass;
43 import org.testng.annotations.BeforeMethod;
44 import org.testng.annotations.Test;
46 public class AlignCalcManagerTest
49 @BeforeClass(alwaysRun = true)
50 public void setUpJvOptionPane()
52 JvOptionPane.setInteractiveMode(false);
53 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
56 private AlignFrame alignFrame;
59 * Test the method that removes a worker associated with an annotation,
60 * provided the worker is marked as 'deletable' (some workers should continue
61 * to run even when their results are no longer displayed)
63 @Test(groups = "Functional")
64 public void testRemoveWorkerForAnnotation()
66 AlignCalcManagerI acm = alignFrame.getViewport().getCalcManager();
67 final AlignmentAnnotation ann1 = new AlignmentAnnotation("Ann1",
68 "desc", new Annotation[] {});
69 final AlignmentAnnotation ann2 = new AlignmentAnnotation("Ann2",
70 "desc", new Annotation[] {});
73 * make two workers for ann1, one deletable, one not
74 * and no worker for ann2
76 AlignCalcWorkerI worker1 = makeWorker(ann1, true);
77 AlignCalcWorkerI worker2 = makeWorker(ann1, false);
80 * The new workers will get run each in their own thread.
81 * We can't tell here whether they have finished, or not yet started.
82 * They have to finish to be 'seen' by getRegisteredWorkersOfClass()
83 * registerWorker adds to the 'restartable' list but
84 * getRegisteredWorkers reads from the 'canUpdate' list
85 * (which is only updated after a worker has run) - why?
86 * So just give workers time to start and finish
93 } catch (InterruptedException e)
99 List<AlignCalcWorkerI> workers = acm
100 .getRegisteredWorkersOfClass(worker1.getClass());
101 assertEquals(2, workers.size());
102 assertTrue(workers.contains(worker1));
103 assertTrue(workers.contains(worker2));
104 assertFalse(acm.isDisabled(worker1));
105 assertFalse(acm.isDisabled(worker2));
108 * remove workers for ann2 (there aren't any)
110 acm.removeWorkerForAnnotation(ann2);
111 assertTrue(acm.getRegisteredWorkersOfClass(worker1.getClass())
113 assertTrue(acm.getRegisteredWorkersOfClass(worker1.getClass())
115 assertFalse(acm.isDisabled(worker1));
116 assertFalse(acm.isDisabled(worker2));
119 * remove worker2 for ann1
120 * - should delete worker1 but not worker2
122 acm.removeWorkerForAnnotation(ann1);
123 assertEquals(1, acm.getRegisteredWorkersOfClass(worker1.getClass())
125 assertTrue(acm.getRegisteredWorkersOfClass(worker1.getClass())
127 assertFalse(acm.isDisabled(worker1));
128 assertFalse(acm.isDisabled(worker2));
132 * Make a worker linked to the given annotation
138 AnnotationWorker makeWorker(final AlignmentAnnotation ann,
139 final boolean deletable)
141 AnnotationProviderI annotationProvider = new AnnotationProviderI()
144 public List<AlignmentAnnotation> calculateAnnotation(AlignmentI al,
147 return Collections.singletonList(ann);
150 return new AnnotationWorker(alignFrame.getViewport(),
151 alignFrame.alignPanel, annotationProvider)
154 public boolean isDeletable()
160 public boolean involves(AlignmentAnnotation ann1)
167 @BeforeMethod(alwaysRun = true)
170 AlignmentI al = new Alignment(new SequenceI[] { new Sequence("Seq1",
173 alignFrame = new AlignFrame(al, 3, 1);