1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.javagen.funcgen.model;
17
18 import java.util.ArrayList;
19 import java.util.Collections;
20 import java.util.List;
21
22 import javax.xml.bind.annotation.XmlTransient;
23
24 import org.javagen.agile.core.model.AbstractModel;
25 import org.javagen.agile.core.model.Model;
26 import org.javagen.agile.core.visitor.DefaultVisitor;
27
28 /***
29 * Abstract Test container class.
30 *
31 * @author Richard Easterling
32 */
33 public abstract class TestHolder extends AbstractModel {
34
35 public TestHolder() {
36 super();
37 }
38
39 public void addTest(Test test) {
40 super.addChildModel(test);
41 }
42
43 /***
44 * Returns immediate child Tests instances.
45 */
46 @XmlTransient
47 public List<Test> getChildTests() {
48 List<Test> tests = new ArrayList<Test>();
49 for(Model child : getChildModels()) {
50 if (child instanceof Test)
51 tests.add( (Test)child );
52 }
53 return tests;
54 }
55
56 /***
57 * Collect all Test instances in tree including root node.
58 */
59 @XmlTransient
60 public List<Test> getAllTests() {
61 TestVisitor visitor = new TestVisitor();
62 visitor.gen(this);
63 return visitor.getTests();
64 }
65
66 /***
67 * Visitor to collect all Test instances in tree including root node.
68 */
69 static class TestVisitor extends DefaultVisitor {
70
71 List<Test> tests = new ArrayList<Test>();
72
73 public TestVisitor() {
74 this.setItinerary( Collections.singleton(Test.DEFAULT_MODEL_TYPE) );
75 }
76
77 public void visit(Model model) {
78 tests.add( (Test)model );
79 }
80
81 public List<Test> getTests() {
82 return tests;
83 }
84 }
85 }