KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > config > schema > repository > MockBeanRepository


1 /**
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.config.schema.repository;
5
6 import org.apache.xmlbeans.SchemaType;
7 import org.apache.xmlbeans.XmlException;
8 import org.apache.xmlbeans.XmlObject;
9
10 import com.tc.config.schema.listen.ConfigurationChangeListener;
11 import com.tc.config.schema.validate.ConfigurationValidator;
12
13 /**
14  * A mock {@link BeanRepository}, for use in tests.
15  */

16 public class MockBeanRepository implements MutableBeanRepository {
17
18   private int numEnsureBeanIsOfClasses;
19   private Class JavaDoc lastClass;
20   private RuntimeException JavaDoc exceptionOnEnsureBeanIsOfClass;
21
22   private int numBeans;
23   private XmlObject returnedBean;
24
25   private int numSetBeans;
26   private XmlObject lastSetBean;
27   private String JavaDoc lastSourceDescription;
28   private XmlException exceptionOnSetBean;
29
30   private int numAddListeners;
31   private ConfigurationChangeListener lastListener;
32
33   private int numAddValidators;
34   private ConfigurationValidator lastValidator;
35
36   private int numRootBeanSchemaTypes;
37   private SchemaType returnedRootBeanSchemaType;
38
39   public MockBeanRepository() {
40     this.returnedBean = null;
41     this.returnedRootBeanSchemaType = null;
42     this.exceptionOnEnsureBeanIsOfClass = null;
43     this.exceptionOnSetBean = null;
44
45     reset();
46   }
47
48   public void reset() {
49     this.numEnsureBeanIsOfClasses = 0;
50     this.lastClass = null;
51
52     this.numBeans = 0;
53
54     this.numSetBeans = 0;
55     this.lastSetBean = null;
56     this.lastSourceDescription = null;
57
58     this.numAddListeners = 0;
59     this.lastListener = null;
60
61     this.numAddValidators = 0;
62     this.lastValidator = null;
63
64     this.numRootBeanSchemaTypes = 0;
65   }
66
67   public void setExceptionOnEnsureBeanIsOfClass(RuntimeException JavaDoc exceptionOnEnsureBeanIsOfClass) {
68     this.exceptionOnEnsureBeanIsOfClass = exceptionOnEnsureBeanIsOfClass;
69   }
70
71   public void saveCopyOfBeanInAnticipationOfFutureMutation() {
72     // nothing here yet
73
}
74
75   public void didMutateBean() {
76     // nothing here yet
77
}
78
79   public void ensureBeanIsOfClass(Class JavaDoc theClass) {
80     ++this.numEnsureBeanIsOfClasses;
81     this.lastClass = theClass;
82     if (this.exceptionOnEnsureBeanIsOfClass != null) throw this.exceptionOnEnsureBeanIsOfClass;
83   }
84
85   public XmlObject bean() {
86     ++this.numBeans;
87     return this.returnedBean;
88   }
89
90   public void setBean(XmlObject bean, String JavaDoc sourceDescription) throws XmlException {
91     ++this.numSetBeans;
92     this.lastSetBean = bean;
93     this.lastSourceDescription = sourceDescription;
94     if (this.exceptionOnSetBean != null) throw this.exceptionOnSetBean;
95   }
96
97   public void addListener(ConfigurationChangeListener listener) {
98     ++this.numAddListeners;
99     this.lastListener = listener;
100   }
101
102   public void addValidator(ConfigurationValidator validator) {
103     ++this.numAddValidators;
104     this.lastValidator = validator;
105   }
106
107   public ConfigurationChangeListener getLastListener() {
108     return lastListener;
109   }
110
111   public XmlObject getLastSetBean() {
112     return lastSetBean;
113   }
114
115   public String JavaDoc getLastSourceDescription() {
116     return lastSourceDescription;
117   }
118
119   public ConfigurationValidator getLastValidator() {
120     return lastValidator;
121   }
122
123   public int getNumAddListeners() {
124     return numAddListeners;
125   }
126
127   public int getNumAddValidators() {
128     return numAddValidators;
129   }
130
131   public int getNumBeans() {
132     return numBeans;
133   }
134
135   public int getNumSetBeans() {
136     return numSetBeans;
137   }
138
139   public void setReturnedBean(XmlObject returnedBean) {
140     this.returnedBean = returnedBean;
141   }
142
143   public SchemaType rootBeanSchemaType() {
144     ++this.numRootBeanSchemaTypes;
145     return this.returnedRootBeanSchemaType;
146   }
147
148   public int getNumRootBeanSchemaTypes() {
149     return numRootBeanSchemaTypes;
150   }
151
152   public void setReturnedRootBeanSchemaType(SchemaType returnedRootBeanSchemaType) {
153     this.returnedRootBeanSchemaType = returnedRootBeanSchemaType;
154   }
155
156   public void setExceptionOnSetBean(XmlException exceptionOnSetBean) {
157     this.exceptionOnSetBean = exceptionOnSetBean;
158   }
159
160   public Class JavaDoc getLastClass() {
161     return lastClass;
162   }
163
164   public int getNumEnsureBeanIsOfClasses() {
165     return numEnsureBeanIsOfClasses;
166   }
167
168 }
169
Popular Tags