Skip to main content
summaryrefslogtreecommitdiffstats
blob: cdad9b74531e639b470bf4f57e24602fb9af7ce7 (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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package org.eclipse.osee.ote.core;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

import org.eclipse.osee.connection.service.IServiceConnector;
import org.eclipse.osee.ote.core.enums.PromptResponseType;
import org.eclipse.osee.ote.core.environment.TestEnvironment;
import org.eclipse.osee.ote.core.framework.prompt.InformationalPrompt;
import org.eclipse.osee.ote.core.framework.prompt.PassFailPromptImpl;
import org.eclipse.osee.ote.core.framework.prompt.PassFailPromptResult;
import org.eclipse.osee.ote.core.framework.prompt.ScriptPausePromptImpl;
import org.eclipse.osee.ote.core.framework.prompt.UserInputPromptImpl;
import org.eclipse.osee.ote.core.framework.prompt.YesNoPromptImpl;
import org.eclipse.osee.ote.core.framework.prompt.YesNoPromptResult;
import org.eclipse.osee.ote.core.log.record.AttentionRecord;
import org.eclipse.osee.ote.core.log.record.TestPointRecord;
import org.eclipse.osee.ote.core.log.record.TestRecord;
import org.eclipse.osee.ote.core.testPoint.CheckPoint;

class TestPromptImpl {

   private final Executor promptInitWorker;

   public TestPromptImpl() {
      promptInitWorker = Executors.newSingleThreadExecutor();
   }

   
   public String prompt(final TestPrompt prompt, final TestEnvironment environment, final TestScript test) throws InterruptedException {

      if (environment.isInBatchMode()) {
         promptInitWorker.execute(new Runnable() {
            @Override
            public void run() {
               try {
                  test.getUserSession().initiateInformationalPrompt(prompt.toString());
               } catch (Exception e) {
                  System.out.println(prompt.toString());
               }
            }
         });
         if (prompt.getType() == PromptResponseType.PASS_FAIL) {
            test.getLogger().log(
                  new TestPointRecord(environment, new CheckPoint(prompt.toString(), "PROMPT DURING BATCH", "N/A", false),
                        true));
         } else {
            test.getLogger().log(new AttentionRecord(environment, prompt.getType().name() + " : " + prompt.toString(), true));
         }
         return "";
      } else if (!environment.getRunManager().isCurrentThreadScript()){
         promptInitWorker.execute(new Runnable() {
            @Override
            public void run() {
               try {
                  test.getUserSession().initiateInformationalPrompt(prompt.toString());
               } catch (Exception e) {
                  System.out.println(prompt.toString());
               }
            }
         });
         if (prompt.getType() != PromptResponseType.NONE) {
            test.getLogger().log(new AttentionRecord(environment, String.format("ERROR: Blocking prompt type[%s] in non script thread[%s] message[%s]", prompt.getType().name(), Thread.currentThread().getName(), prompt.toString()), true));
         } else {
            test.getLogger().log(new AttentionRecord(environment, prompt.getType().name() + " : " + prompt.toString(), true));
         }
         return "";
      } else {
         try {
            final String returnValue;
            String logOutput;
            final TestRecord testRecord;
            final IServiceConnector connector = environment.getConnector();
            synchronized (test){
               switch (prompt.getType()) {
               case NONE:
                  InformationalPrompt infoPrompt = new InformationalPrompt(connector, "", prompt.toString());
                  infoPrompt.open(test.getUserSession(), promptInitWorker);
                  infoPrompt.close();
                  returnValue = "";
                  testRecord = new AttentionRecord(environment, String.format("PROMPT [%s]\n{\n%s\n}\n", PromptResponseType.NONE.name(), prompt.toString()), true);
                  break;
               case PASS_FAIL:
                  PassFailPromptImpl passFailPrompt = new PassFailPromptImpl(connector, test, "", prompt.toString());
                  PassFailPromptResult result = passFailPrompt.open(promptInitWorker);
                  returnValue = result.getText();
                  passFailPrompt.close();
                  testRecord =
                        new TestPointRecord(environment, new CheckPoint("Pass/Fail Prompt", prompt.toString(),
                              returnValue, result.isPass()), true);
                  break;
               case YES_NO:
                  YesNoPromptImpl yesNoPrompt = new YesNoPromptImpl(connector, test, "", prompt.toString());
                  YesNoPromptResult yesNo = yesNoPrompt.open(promptInitWorker);
                  if (yesNo.isYes()) {
                     returnValue = "YES";
                  } else {
                     returnValue = "NO";
                  }
                  logOutput =
                        String.format("PROMPT [%s]\n{\n%s\n}\n\tRETURN VALUE : %s", PromptResponseType.YES_NO.name(),
                              prompt.toString(), returnValue);
                  yesNoPrompt.close();
                  testRecord = new AttentionRecord(environment, logOutput, true);
                  break;
               case SCRIPT_PAUSE:
                  ScriptPausePromptImpl scriptPausePrompt =
                  new ScriptPausePromptImpl(connector, test, "", prompt.toString());
                  returnValue = scriptPausePrompt.open(promptInitWorker);
                  scriptPausePrompt.close();
                  if (returnValue != null && returnValue.length() > 0) {
                     logOutput =
                           String.format("PROMPT [%s]\n{\n%s\n}\n\tRETURN VALUE : %s", PromptResponseType.SCRIPT_PAUSE.name(),
                                 prompt.toString(), returnValue);
                  } else {
                     logOutput =
                           String.format("PROMPT [%s]\n{\n%s\n}\n", PromptResponseType.SCRIPT_PAUSE.name(), prompt.toString());
                  }

                  testRecord = new AttentionRecord(environment, logOutput, true);
                  ;
                  break;
               case USER_INPUT:
                  UserInputPromptImpl userInputPrompt = new UserInputPromptImpl(connector, test, "", prompt.toString());
                  returnValue = userInputPrompt.open(promptInitWorker);
                  userInputPrompt.close();
                  if (returnValue != null && returnValue.length() > 0) {
                     logOutput =
                           String.format("PROMPT [%s]\n{\n%s\n}\n\tRETURN VALUE : %s", PromptResponseType.USER_INPUT.name(),
                                 prompt.toString(), returnValue);
                  } else {
                     logOutput =
                           String.format("PROMPT [%s]\n{\n%s\n}\n", PromptResponseType.USER_INPUT.name(), prompt.toString());
                  }
                  testRecord = new AttentionRecord(environment, logOutput, true);
                  break;
               case SCRIPT_STEP:
                  returnValue = "";
                  testRecord =
                        new AttentionRecord(environment,
                              PromptResponseType.SCRIPT_STEP.name() + " : " + prompt.toString(), true);
                  break;
               case OFP_DEBUG_RESPONSE:
                  returnValue = "";
                  testRecord = null;
                  break;
               default:
                  returnValue = "";
                  testRecord = null;
               }
            }
            if (testRecord != null) {
               testRecord.setStackTrace(new Throwable());
               test.getLogger().log(testRecord);
            }
            return returnValue;
         } catch (InterruptedException e) {
            throw new InterruptedException();
         } catch (Exception e) {
            // what
         }
         return "";
      }

   }
}

Back to the top