X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=system%2Fgeneral%2Fsrc%2Ftest%2Fjava%2Forg%2Fwamblee%2Fsystem%2Fcontainer%2FApplication.java;h=7df9585f10f8d5702117febc77d33a318ca8d66c;hb=8de36ff0206c996baf3ee4adc3e2293b12ff5f39;hp=e6b09215299cc376812a3cf5d438ee1fb905d8ee;hpb=0d8d8f24656e585ee75558cfd6a4c661f8f14985;p=utils diff --git a/system/general/src/test/java/org/wamblee/system/container/Application.java b/system/general/src/test/java/org/wamblee/system/container/Application.java index e6b09215..7df9585f 100644 --- a/system/general/src/test/java/org/wamblee/system/container/Application.java +++ b/system/general/src/test/java/org/wamblee/system/container/Application.java @@ -1,12 +1,12 @@ /* * 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. @@ -20,57 +20,84 @@ import org.wamblee.system.core.DefaultRequiredInterface; import org.wamblee.system.core.ProvidedInterface; import org.wamblee.system.core.RequiredInterface; import org.wamblee.system.core.Scope; + import org.wamblee.test.EventTracker; +/** + * + * @author $author$ + * @version $Revision$ + */ public class Application extends AbstractComponent { - public static RequiredInterface[] required(boolean aOptional, - String aPrefix) { - return new RequiredInterface[] { - new DefaultRequiredInterface(aPrefix + "string", String.class, - aOptional), - new DefaultRequiredInterface(aPrefix + "integer", - Integer.class, aOptional) }; - } - - public static RequiredInterface[] required(boolean aOptional) { - return required(aOptional, ""); - } - private EventTracker tracker; + private String string; + private Integer integer; + private double random; + /** + * Creates a new Application object. + */ public Application() { this("application"); } + /** + * Creates a new Application object. + * + */ public Application(String aName) { this(aName, ""); } + /** + * Creates a new Application object. + * + */ public Application(String aName, String aPrefix) { - super(aName, new ProvidedInterface[0], required(false, - aPrefix)); + super(aName, new ProvidedInterface[0], required(false, aPrefix)); random = Math.random(); } + /** + * Creates a new Application object. + * + */ public Application(boolean aIsOptinal) { super("application", new ProvidedInterface[0], required(true, "")); } + /** + * Creates a new Application object. + * + */ public Application(EventTracker aTracker) { this(); tracker = aTracker; } + public static RequiredInterface[] required(boolean aOptional, String aPrefix) { + return new RequiredInterface[] { + new DefaultRequiredInterface(aPrefix + "string", String.class, + aOptional), + new DefaultRequiredInterface(aPrefix + "integer", Integer.class, + aOptional) }; + } + + public static RequiredInterface[] required(boolean aOptional) { + return required(aOptional, ""); + } + @Override public Object doStart(Scope aScope) { track("start." + getName()); - string = aScope.getInterfaceImplementation(getRequiredInterfaces() - .get(0).getProvider(), String.class); + string = aScope.getInterfaceImplementation(getRequiredInterfaces().get( + 0).getProvider(), String.class); integer = aScope.getInterfaceImplementation(getRequiredInterfaces() - .get(1).getProvider(), Integer.class); + .get(1).getProvider(), Integer.class); + return random; } @@ -85,9 +112,10 @@ public class Application extends AbstractComponent { @Override public void doStop(Object aRuntime) { track("stop." + getName()); + if (random != (Double) aRuntime) { - throw new IllegalArgumentException("Wrong runtime: expected " - + random + " but got " + aRuntime); + throw new IllegalArgumentException("Wrong runtime: expected " + + random + " but got " + aRuntime); } } @@ -95,6 +123,7 @@ public class Application extends AbstractComponent { if (tracker == null) { return; } + tracker.eventOccurred(aString); } }