001: /**
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */package com.tc.config.schema.repository;
004:
005: import org.apache.xmlbeans.SchemaType;
006: import org.apache.xmlbeans.XmlException;
007: import org.apache.xmlbeans.XmlObject;
008:
009: import com.tc.config.schema.listen.ConfigurationChangeListener;
010: import com.tc.config.schema.validate.ConfigurationValidator;
011:
012: /**
013: * A mock {@link BeanRepository}, for use in tests.
014: */
015: public class MockBeanRepository implements MutableBeanRepository {
016:
017: private int numEnsureBeanIsOfClasses;
018: private Class lastClass;
019: private RuntimeException exceptionOnEnsureBeanIsOfClass;
020:
021: private int numBeans;
022: private XmlObject returnedBean;
023:
024: private int numSetBeans;
025: private XmlObject lastSetBean;
026: private String lastSourceDescription;
027: private XmlException exceptionOnSetBean;
028:
029: private int numAddListeners;
030: private ConfigurationChangeListener lastListener;
031:
032: private int numAddValidators;
033: private ConfigurationValidator lastValidator;
034:
035: private int numRootBeanSchemaTypes;
036: private SchemaType returnedRootBeanSchemaType;
037:
038: public MockBeanRepository() {
039: this .returnedBean = null;
040: this .returnedRootBeanSchemaType = null;
041: this .exceptionOnEnsureBeanIsOfClass = null;
042: this .exceptionOnSetBean = null;
043:
044: reset();
045: }
046:
047: public void reset() {
048: this .numEnsureBeanIsOfClasses = 0;
049: this .lastClass = null;
050:
051: this .numBeans = 0;
052:
053: this .numSetBeans = 0;
054: this .lastSetBean = null;
055: this .lastSourceDescription = null;
056:
057: this .numAddListeners = 0;
058: this .lastListener = null;
059:
060: this .numAddValidators = 0;
061: this .lastValidator = null;
062:
063: this .numRootBeanSchemaTypes = 0;
064: }
065:
066: public void setExceptionOnEnsureBeanIsOfClass(
067: RuntimeException exceptionOnEnsureBeanIsOfClass) {
068: this .exceptionOnEnsureBeanIsOfClass = exceptionOnEnsureBeanIsOfClass;
069: }
070:
071: public void saveCopyOfBeanInAnticipationOfFutureMutation() {
072: // nothing here yet
073: }
074:
075: public void didMutateBean() {
076: // nothing here yet
077: }
078:
079: public void ensureBeanIsOfClass(Class theClass) {
080: ++this .numEnsureBeanIsOfClasses;
081: this .lastClass = theClass;
082: if (this .exceptionOnEnsureBeanIsOfClass != null)
083: throw this .exceptionOnEnsureBeanIsOfClass;
084: }
085:
086: public XmlObject bean() {
087: ++this .numBeans;
088: return this .returnedBean;
089: }
090:
091: public void setBean(XmlObject bean, String sourceDescription)
092: throws XmlException {
093: ++this .numSetBeans;
094: this .lastSetBean = bean;
095: this .lastSourceDescription = sourceDescription;
096: if (this .exceptionOnSetBean != null)
097: throw this .exceptionOnSetBean;
098: }
099:
100: public void addListener(ConfigurationChangeListener listener) {
101: ++this .numAddListeners;
102: this .lastListener = listener;
103: }
104:
105: public void addValidator(ConfigurationValidator validator) {
106: ++this .numAddValidators;
107: this .lastValidator = validator;
108: }
109:
110: public ConfigurationChangeListener getLastListener() {
111: return lastListener;
112: }
113:
114: public XmlObject getLastSetBean() {
115: return lastSetBean;
116: }
117:
118: public String getLastSourceDescription() {
119: return lastSourceDescription;
120: }
121:
122: public ConfigurationValidator getLastValidator() {
123: return lastValidator;
124: }
125:
126: public int getNumAddListeners() {
127: return numAddListeners;
128: }
129:
130: public int getNumAddValidators() {
131: return numAddValidators;
132: }
133:
134: public int getNumBeans() {
135: return numBeans;
136: }
137:
138: public int getNumSetBeans() {
139: return numSetBeans;
140: }
141:
142: public void setReturnedBean(XmlObject returnedBean) {
143: this .returnedBean = returnedBean;
144: }
145:
146: public SchemaType rootBeanSchemaType() {
147: ++this .numRootBeanSchemaTypes;
148: return this .returnedRootBeanSchemaType;
149: }
150:
151: public int getNumRootBeanSchemaTypes() {
152: return numRootBeanSchemaTypes;
153: }
154:
155: public void setReturnedRootBeanSchemaType(
156: SchemaType returnedRootBeanSchemaType) {
157: this .returnedRootBeanSchemaType = returnedRootBeanSchemaType;
158: }
159:
160: public void setExceptionOnSetBean(XmlException exceptionOnSetBean) {
161: this .exceptionOnSetBean = exceptionOnSetBean;
162: }
163:
164: public Class getLastClass() {
165: return lastClass;
166: }
167:
168: public int getNumEnsureBeanIsOfClasses() {
169: return numEnsureBeanIsOfClasses;
170: }
171:
172: }
|