1 package net.sf.msplice.model;
2
3 import net.sf.msplice.visitor.IVisitor;
4
5 import org.jmock.Mock;
6 import org.jmock.MockObjectTestCase;
7
8 public class BusinessPropertyTest extends MockObjectTestCase {
9
10 private BusinessProperty rootBusinessProperty = null;
11
12 private String childBusinessPropName = null;
13
14 private String nullBusinessPropName = null;
15
16 private BusinessProperty childBusinessProperty = null;
17
18 private BusinessProperty nullBusinessProperty = null;
19
20 private String childViewPropName = null;
21
22 private String nullViewPropName = null;
23
24 private ViewProperty childViewProperty = null;
25
26 private ViewProperty nullViewProperty = null;
27
28 @Override
29 protected void setUp() throws Exception {
30 super.setUp();
31
32 rootBusinessProperty = new BusinessProperty();
33
34 childBusinessPropName = "a-child";
35 nullBusinessPropName = null;
36
37 childBusinessProperty = new BusinessProperty();
38 childBusinessProperty.setName(childBusinessPropName);
39
40 nullBusinessProperty = null;
41
42 childViewPropName = "a-view-child";
43 nullViewPropName = null;
44
45 childViewProperty = new ViewProperty();
46 childViewProperty.setName(childViewPropName);
47
48 nullViewProperty = null;
49 }
50
51 public void testAddGetBusinessProperty() {
52
53 rootBusinessProperty.addBusinessProperty(childBusinessProperty);
54
55 BusinessProperty resultBusinessProperty = rootBusinessProperty
56 .getBusinessProperty(childBusinessProperty.getName());
57
58 assertEquals("Checking the returned child business property",
59 childBusinessProperty, resultBusinessProperty);
60 }
61
62 public void testPreemptBusinessProperty() {
63
64 rootBusinessProperty.addBusinessProperty(childBusinessProperty);
65
66 try {
67 rootBusinessProperty.addBusinessProperty(childBusinessProperty);
68 fail("Must throw a ModelRuntimeException on BusinessProperty clash");
69 } catch (ModelRuntimeException mre) {
70
71 }
72 }
73
74 public void testAddNullNameBusinessProperty() {
75
76 childBusinessProperty.setName(nullBusinessPropName);
77
78 try {
79 rootBusinessProperty.addBusinessProperty(childBusinessProperty);
80 fail("Must throw a ModelRuntimeException on missing BusinessProperty name");
81 } catch (ModelRuntimeException mre) {
82
83 }
84 }
85
86 public void testAddGetViewProperty() {
87
88 rootBusinessProperty.addViewProperty(childViewProperty);
89
90 ViewProperty resultViewProperty = rootBusinessProperty
91 .getViewProperty(childViewProperty.getName());
92
93 assertEquals("Checking the returned child view property",
94 childViewProperty, resultViewProperty);
95
96 }
97 public void testPreemptViewProperty() {
98
99 rootBusinessProperty.addViewProperty(childViewProperty);
100
101 try {
102 rootBusinessProperty.addViewProperty(childViewProperty);
103 fail("Must throw a ModelRuntimeException on ViewProperty clash");
104 } catch (ModelRuntimeException mre) {
105
106 }
107 }
108
109
110 public void testAddNullNameViewProperty() {
111
112 childViewProperty.setName(nullViewPropName);
113
114 try {
115 rootBusinessProperty.addViewProperty(childViewProperty);
116 fail("Must throw a ModelRuntimeException on missing View name");
117 } catch (ModelRuntimeException mre) {
118
119 }
120 }
121
122
123 public void testVisitor() throws Exception {
124
125
126 Mock mockVisitor = mock(IVisitor.class);
127
128
129 mockVisitor.expects(once()).method("visit").with(eq(rootBusinessProperty));
130
131 rootBusinessProperty.accept((IVisitor) mockVisitor.proxy());
132 }
133
134 }