Skip to main content
summaryrefslogtreecommitdiffstats
blob: 58ed2c1cb49a72499a3f8764f6d6ecffa20f01ee (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*******************************************************************************
 * Copyright (c) 2004, 2007 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.client.integration.tests.suite;

import static org.junit.Assert.assertTrue;
import java.util.logging.Level;
import org.eclipse.osee.ats.config.demo.PopulateDemoActions;
import org.eclipse.osee.framework.core.client.ClientSessionManager;
import org.eclipse.osee.framework.core.client.OseeClientProperties;
import org.eclipse.osee.framework.core.client.OseeClientSession;
import org.eclipse.osee.framework.database.init.DatabaseInitializationOperation;
import org.eclipse.osee.framework.jdk.core.util.Lib;
import org.eclipse.osee.framework.jdk.core.util.OseeProperties;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.logging.SevereLoggingMonitor;
import org.eclipse.osee.framework.skynet.core.UserManager;
import org.eclipse.osee.framework.ui.skynet.render.RenderingUtil;
import org.eclipse.osee.support.test.util.DemoUsers;
import org.eclipse.osee.support.test.util.TestUtil;
import org.junit.Assert;
import org.junit.BeforeClass;

/**
 * @author Donald G. Dunne
 */
public class MasterTestSuite_DemoDbInit {
   private static boolean wasDbInitSuccessful = false;

   @BeforeClass
   public static void setup() throws Exception {
      OseeProperties.setIsInTest(true);
      assertTrue("Demo Application Server must be running",
         ClientSessionManager.getAuthenticationProtocols().contains("demo"));
      RenderingUtil.setPopupsAllowed(false);
   }

   @org.junit.Test
   public void testDemoDbInit() throws Exception {
      OseeLog.log(DatabaseInitializationOperation.class, Level.INFO, "Begin database initialization...");

      String lastAuthenticationProtocol = OseeClientProperties.getAuthenticationProtocol();
      try {
         SevereLoggingMonitor monitorLog = TestUtil.severeLoggingStart();
         OseeLog.registerLoggerListener(monitorLog);
         OseeClientProperties.setAuthenticationProtocol("trustAll");
         DatabaseInitializationOperation.executeWithoutPrompting("OSEE Demo Database");

         TestUtil.severeLoggingEnd(monitorLog);
         OseeLog.log(DatabaseInitializationOperation.class, Level.INFO, "Completed database initialization");
         wasDbInitSuccessful = true;
      } finally {
         OseeClientProperties.setAuthenticationProtocol(lastAuthenticationProtocol);
      }

      if (wasDbInitSuccessful) {
         ClientSessionManager.releaseSession();
         // Re-authenticate so we can continue
         ClientSessionManager.getSession();
      }
      OseeClientProperties.setInDbInit(false);

   }

   @org.junit.Test
   public void testPopulateDemoDb() {
      Assert.assertTrue("DbInit must be successful to continue", wasDbInitSuccessful);
      try {
         ClientSessionManager.releaseSession();
         // Re-authenticate so we can continue
         OseeClientSession session = ClientSessionManager.getSession();
         UserManager.releaseUser();

         Assert.assertEquals("Must run populate as Joe Smith", DemoUsers.Joe_Smith.getUserID(), session.getUserId());
         Assert.assertEquals("Must run populate as Joe Smith", DemoUsers.Joe_Smith.getUserID(),
            UserManager.getUser().getUserId());

         PopulateDemoActions populateDemoActions = new PopulateDemoActions(null);
         populateDemoActions.run(false);
      } catch (Exception ex) {
         Assert.fail(Lib.exceptionToString(ex));
      }
   }
}

Back to the top