HibernateUserAdministrationTest now based on the component mechanism.
[utils] / system / general / src / test / java / org / wamblee / system / core / IntegerComponent.java
diff --git a/system/general/src/test/java/org/wamblee/system/core/IntegerComponent.java b/system/general/src/test/java/org/wamblee/system/core/IntegerComponent.java
new file mode 100644 (file)
index 0000000..0af4ae3
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2007 the original author or authors.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wamblee.system.core;
+
+import javax.sql.DataSource;
+
+import org.wamblee.system.core.AbstractComponent;
+import org.wamblee.system.core.DefaultProvidedInterface;
+import org.wamblee.system.core.ProvidedInterface;
+import org.wamblee.system.core.RequiredInterface;
+import org.wamblee.test.EventTracker;
+
+public class IntegerComponent extends AbstractComponent {
+
+       private static final ProvidedInterface[] provided(String aPrefix) {
+               return new ProvidedInterface[] {
+                               new DefaultProvidedInterface(aPrefix + "integer", Integer.class) };
+       }
+
+       private EventTracker<String> _tracker;
+       private double _random;
+
+       public IntegerComponent() {
+               this("environment");
+       }
+       
+       public IntegerComponent(String aName) {
+       this(aName, "");
+    }
+       
+       public IntegerComponent(String aName, String aPrefix) {
+        super(aName, provided(aPrefix), new RequiredInterface[0]);
+        _random = Math.random();
+    }
+
+
+
+       public IntegerComponent(EventTracker aTracker) {
+               this();
+               _tracker = aTracker;
+       }
+
+       public Integer getInteger() {
+               return 2;
+       }
+
+       @Override
+       protected Object doStart(Scope aScope) {
+               addInterface(getProvidedInterfaces()[1], getInteger(), aScope);
+               track("start." + getName());
+               return _random;
+       }
+
+       @Override
+       protected void doStop(Object aRuntime) {
+               track("stop." + getName());
+               if (_random != (Double) aRuntime) {
+                       throw new IllegalArgumentException("Wrong runtime: expected "
+                                       + _random + " but got " + aRuntime);
+               }
+       }
+
+       private void track(String aString) {
+               if (_tracker == null) {
+                       return;
+               }
+               _tracker.eventOccurred(aString);
+       }
+}