1 | /** |
2 | * Copyright 2007 ATG DUST Project |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. |
6 | * |
7 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 |
8 | * |
9 | * Unless required by applicable law or agreed to in writing, software |
10 | * distributed under the License is distributed on an "AS IS" BASIS, |
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | * See the License for the specific language governing permissions and limitations under the License. |
13 | */ |
14 | |
15 | package com.mycompany; |
16 | |
17 | import atg.nucleus.GenericService; |
18 | import atg.nucleus.Nucleus; |
19 | import atg.nucleus.ServiceException; |
20 | import atg.nucleus.logging.ApplicationLogging; |
21 | |
22 | /** |
23 | * This is an example class created for the purpose of demonstrating how to |
24 | * write test code with DUST. |
25 | * |
26 | * Original file name src/main/java/com/mycompany/ToBeTested.java. Renamed it so |
27 | * we get consisting test class names. |
28 | * |
29 | * |
30 | * |
31 | * @author adamb |
32 | * @author robert |
33 | * |
34 | */ |
35 | public class SimpleComponent extends GenericService { |
36 | |
37 | public boolean isCleanStart = false; |
38 | |
39 | // ------------------------- |
40 | /** |
41 | * Called when this component is started. |
42 | */ |
43 | public void doStartService() throws ServiceException { |
44 | prepare(); |
45 | } |
46 | |
47 | // ------------------------- |
48 | /** |
49 | * Called when this component is shut down. |
50 | */ |
51 | public void doStopService() throws ServiceException { |
52 | isCleanStart = false; |
53 | } |
54 | |
55 | // ------------------------- |
56 | /** |
57 | * Checks that Nucleus is running, if its not, then throw a ServiceException. |
58 | * If Nucleus is running, the log an info message. |
59 | * |
60 | * @throws ServiceException |
61 | */ |
62 | public void prepare() throws ServiceException { |
63 | Nucleus n = Nucleus.getGlobalNucleus(); |
64 | if (n == null) { |
65 | throw new ServiceException("Nucleus is not running."); |
66 | } |
67 | else { |
68 | ((ApplicationLogging) n).logInfo("Prepared."); |
69 | } |
70 | isCleanStart = true; |
71 | } |
72 | } |