Skip to main content
summaryrefslogtreecommitdiffstats
blob: 67326b83b08f14d3e24b9dfcd50917370998b8a1 (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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*******************************************************************************
 * 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.ote.message;

import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.osee.ote.Configuration;
import org.eclipse.osee.ote.core.IUserSession;
import org.eclipse.osee.ote.core.ServiceUtility;
import org.eclipse.osee.ote.core.TestScript;
import org.eclipse.osee.ote.core.environment.TestEnvironment;
import org.eclipse.osee.ote.core.environment.interfaces.BasicTimeout;
import org.eclipse.osee.ote.core.environment.interfaces.IEnvironmentFactory;
import org.eclipse.osee.ote.core.environment.interfaces.ITimeout;
import org.eclipse.osee.ote.core.model.IModelManager;
import org.eclipse.osee.ote.message.instrumentation.IOInstrumentation;
import org.eclipse.osee.ote.message.interfaces.IMessageManager;
import org.eclipse.osee.ote.message.interfaces.ITestEnvironmentMessageSystemAccessor;

/**
 * @author Ryan D. Brooks
 * @author Robert A. Fisher
 * @author Andrew M. Finkbeiner
 */
public abstract class MessageSystemTestEnvironment extends TestEnvironment implements ITestEnvironmentMessageSystemAccessor, IMessageTestContext {
   protected URL[] clientClasses;
   private final List<IPreScriptInstantiation> preInstantiation = new ArrayList<>();
   protected boolean promptResponse = false;
   private IOInstrumentationDB ioInstrumentation;

   protected MessageSystemTestEnvironment(IEnvironmentFactory factory) {
      super(factory);
      getScriptCtrl().setScriptReady(false);
   }

   private void setupIOInstrumentation() {
      if (ioInstrumentation == null) {
         ioInstrumentation = new IOInstrumentationDB();
      }
   }

   public void envWait(int milliseconds) throws InterruptedException {
      envWait(new BasicTimeout(), milliseconds);
   }

   public void envWait(ITimeout obj, int milliseconds) throws InterruptedException {
      setTimerFor(obj, milliseconds);
      synchronized (obj) {
         obj.wait();
      }
   }

   @SuppressWarnings("rawtypes")
   @Override
   public IMessageManager getMsgManager() {
      return ServiceUtility.getService(IMessageManager.class, false);
   }

   public IModelManager getModelManager() {
      return ServiceUtility.getService(IModelManager.class, 5000);
   }

   /**
    * provides a way for sub classes to instantiate test scripts in their own way.
    */
   protected abstract TestScript instantiateScriptClass(Class<?> scriptClass, IUserSession connection) throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException;

   public abstract void singleStepEnv();

   @Override
   public void resetScriptLoader(Configuration configuration, String[] strings) throws Exception {
      getRuntimeManager().resetScriptLoader(configuration, strings);
   }

   public void addPreInstantiationListener(IPreScriptInstantiation listener) {
      preInstantiation.add(listener);
   }

   public void removePreInstantiationListener(IPreScriptInstantiation listener) {
      preInstantiation.remove(listener);
   }

   public void notifyPreInstantiationListeners() {
      for (IPreScriptInstantiation pre : preInstantiation) {
         pre.run();
      }
   }

   public IOInstrumentation getIOInstrumentation(String name) {
      setupIOInstrumentation();
      return ioInstrumentation.getIOInstrumentation(name);
   }

   public IOInstrumentation registerIOInstrumentation(String name, IOInstrumentation io) {
      setupIOInstrumentation();
      return ioInstrumentation.registerIOInstrumentation(name, io);
   }

   public void deregisterIOInstrumentation(String name) {
      setupIOInstrumentation();
      ioInstrumentation.unregisterIOInstrumentation(name);
   }

   public void addInstrumentationRegistrationListener(IInstrumentationRegistrationListener listener) {
      setupIOInstrumentation();
      ioInstrumentation.addRegistrationListener(listener);
   }

   public void removeInstrumentationRegistrationListener(IInstrumentationRegistrationListener listener) {
      setupIOInstrumentation();
      ioInstrumentation.removeRegistrationListener(listener);
   }

   public Class<?> loadClassFromMessageLoader(String path) throws ClassNotFoundException {
      return getRuntimeManager().loadFromRuntimeLibraryLoader(path);
   }
}

Back to the top