1 package test;
2
3 import java.io.IOException;
4
5 import javax.servlet.ServletException;
6
7 import org.apache.log4j.Level;
8 import org.apache.log4j.Logger;
9
10 import atg.nucleus.Nucleus;
11 import atg.nucleus.NucleusTestUtils;
12 import atg.nucleus.ServiceException;
13 import atg.repository.MutableRepository;
14 import junit.framework.TestCase;
15
16 /***
17 * Tests ProfileFormHandler using the config layer from the ATG build.
18 * @author adamb
19 *
20 */
21 public class ProfileFormHandlerTest extends TestCase {
22
23 public static final String PROFILE_ADAPTER_REPOSITORY_PATH = "/atg/userprofiling/ProfileAdapterRepository";
24 Logger mLogger = Logger.getLogger(this.getClass());
25 Nucleus mNucleus = null;
26
27
28 /***
29 * Starts Nucleus. Fails the test if there is a problem starting Nucleus.
30 */
31 @Override
32 public void setUp() {
33 mLogger.log(Level.INFO, "Start Nucleus.");
34 try {
35 System.setProperty("derby.locks.deadlockTrace","true");
36 mNucleus = NucleusTestUtils.startNucleusWithModules(new String[] { "DPS" },
37 this.getClass(),
38 this.getClass().getName(),
39 PROFILE_ADAPTER_REPOSITORY_PATH);
40 } catch (ServletException e) {
41 fail(e.getMessage());
42 }
43
44 }
45
46
47 /***
48 * If there is a running Nucleus, this method shuts it down.
49 * The test will fail if there is an error while shutting down Nucleus.
50 */
51 @Override
52 public void tearDown() {
53 mLogger.log(Level.INFO, "Stop Nucleus");
54 if (mNucleus != null) {
55 try {
56 NucleusTestUtils.shutdownNucleus(mNucleus);
57 } catch (ServiceException e) {
58 fail(e.getMessage());
59 } catch (IOException e) {
60 fail(e.getMessage());
61 }
62 }
63 }
64
65 /***
66 * TODO: Make it possible to resolve request scoped objects in a test.
67 * Ideally we setup a fake request and make all the code "just work".
68 * @throws Exception
69 */
70 public void testProfileFormHandler() throws Exception {
71 MutableRepository par = (MutableRepository) mNucleus.resolveName(PROFILE_ADAPTER_REPOSITORY_PATH);
72 assertNotNull(par);
73 }
74
75
76 }