View Javadoc

1   /***
2    * Copyright 2009 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 test;
16  
17  import java.io.IOException;
18  
19  import javax.servlet.ServletException;
20  
21  import junit.framework.TestCase;
22  
23  import org.apache.log4j.Level;
24  import org.apache.log4j.Logger;
25  
26  import atg.nucleus.Nucleus;
27  import atg.nucleus.NucleusTestUtils;
28  import atg.nucleus.ServiceException;
29  import atg.repository.MutableRepository;
30  
31  /***
32   * This test is an example showing how to startup a Nucleus instance which resolves its configuration path (CONFIGPATH)
33   * from a set of modules within an ATG installation.
34   * This saves the test author from having to maintain separate copies of files which exist in the CONFIGPATH of a given module.
35   * The location of DYNAMO_HOME is determined by checking the following items in order for the first non-null value:
36   * <ul>
37   *  <li>System Property "atg.dynamo.root"
38   *  <li>Environment Variable "DYNAMO_ROOT"
39   *  <li>System Property "atg.dynamo.home"
40   *  <li>Environment Variable "DYNAMO_HOME"
41   * </ul>
42   * 
43   * @author adamb
44   *
45   */
46  public class StartWithModulesTest extends TestCase {
47    
48    Logger mLogger = Logger.getLogger(this.getClass());
49    Nucleus mNucleus = null;
50  
51    // ------------------------------------
52    /***
53     * Starts Nucleus. Fails the test if there is a problem starting Nucleus.
54     */
55    @Override
56    public void setUp() {
57      mLogger.log(Level.INFO, "Start Nucleus.");
58      try {
59        System.setProperty("derby.locks.deadlockTrace","true");
60        mNucleus = NucleusTestUtils.startNucleusWithModules(new String[] { "DAF.Deployment","DPS" },
61            this.getClass(),
62            this.getClass().getName(),
63            "/atg/deployment/DeploymentRepository");
64      } catch (ServletException e) {
65        fail(e.getMessage());
66      }
67  
68    }
69    
70    // ------------------------------------
71    /***
72     * If there is a running Nucleus, this method shuts it down.
73     * The test will fail if there is an error while shutting down Nucleus.
74     */
75    @Override
76    public void tearDown() {
77      mLogger.log(Level.INFO, "Stop Nucleus");
78      if (mNucleus != null) {
79        try {
80          NucleusTestUtils.shutdownNucleus(mNucleus);
81        } catch (ServiceException e) {
82          fail(e.getMessage());
83        } catch (IOException e) {
84          fail(e.getMessage());
85        }
86      }    
87    }
88    
89    // ----------------------------------------
90    /***
91     * Resolves a component that is defined within the ATG platform and is not specifically
92     * part of this test's configpath.
93     * Confirms that Nucleus can start given a set of modules and a properly set DYNAMO_HOME
94     * environment variable. (ex: DYNAMO_HOME=/home/user/ATG/ATG9.0/home)
95     */
96    public void testResolveComponentWithNucleus() {
97      assertNotNull(mNucleus);
98      MutableRepository catalog = (MutableRepository) mNucleus.resolveName("/atg/deployment/DeploymentRepository");
99      assertNotNull("DeploymentRepository should not be null.",catalog);
100     MutableRepository profile = (MutableRepository) mNucleus.resolveName("/atg/userprofiling/ProfileAdapterRepository");
101     // Good enough for this test.
102     // Don't want to disturb any data that might be in this repository.        
103   }
104     
105 }