Project

General

Profile

6237-182-r14314.diff

Vladimir Tsichevski, 10/21/2022 12:41 PM

Download (198 KB)

View differences:

build.gradle 2022-10-09 08:30:26 +0000
103 103
**     OM  20220812 Upgraded mariadb JDBC driver from 2.7.3 to 3.0.7 GA.
104 104
**     TW  20220928 Changed junixsocket dependency to official repository, and upped its version to latest.
105 105
**     TW  20221007 Upgraded junixsocket to 2.5.2.
106
**     VVT 2022xxxx JUnit5 dependencies updated to support both existing tests and custom test engine.
107
**                  See #6237.
106 108
*/
107 109

  
108 110
/*
......
582 584
       aspectjCompile group: 'org.aspectj', name: 'aspectjweaver', version: aspectjVersion
583 585
    }
584 586

  
585
    fwdAllTest group: 'org.junit.platform', name: 'junit-platform-console-standalone', version: '1.7.1'
587
    // Adding JUnit5 jar both to client and server, so it will be also deployed to converted projects
588
    fwdClientServer group: 'org.junit.platform',
589
                    name: 'junit-platform-engine',
590
                    version: '1.9.0'
591

  
592
    fwdClientServer group: 'org.junit.platform',
593
                    name: 'junit-platform-suite-engine',
594
                    version: '1.9.0'
595
    fwdAllTest group: 'org.junit.platform',
596
                    name: 'junit-platform-console',
597
                    version: '1.9.0'
598
    fwdAllTest group: 'org.junit.platform',
599
                    name: 'junit-platform-engine',
600
                    version: '1.9.0'
586 601
}
587 602

  
588 603
// inject ant-optional dependencies to ant, this is needed for the antlr ant target
build.xml 2022-10-19 10:03:52 +0000
235 235
**                           projects that include admin need the src/com/goldencode tree to be in place. Ref #6214.
236 236
**     RFB 20221017          Move the p2jpl.jar out of the standard build, and into its own "p2jpl" target. This is
237 237
**                           the first step in that jar's deprecation. Remove the FontTable class, too. Ref #6664.
238
**     VVT 2022xxxx          Copy org.junit.platform.engine.TestEngine file to META-INF/services. See #6237.
238 239
-->
239 240

  
240 241
<!--
......
885 886
    <!-- Copy SPI descriptors to META-INF/services directory -->
886 887
    <copy todir="${build.home}/classes/META-INF/services">
887 888
      <fileset dir="${manifest.src}" includes="*Provider" />
889
      <fileset dir="${manifest.src}" includes="*TestEngine" />
888 890
    </copy>
889 891

  
890 892
    <!-- Copy aop.xml to META-INF directory for LTW-specific AOP jar -->
manifest/org.junit.platform.engine.TestEngine 2022-09-19 20:26:43 +0000
1
com.goldencode.p2j.testengine.FWDTestEngine
rules/annotations/annotations.xml 2022-09-30 11:50:03 +0000
263 263
**                           element.
264 264
**     VVT 20220913          OEUnit support: annotations/unit_test_support added. See #6237.
265 265
**     VVT 20220913          Prevent unsupported legacy annotations from going to Java code. See #6237.
266
**     VVT 20220914          Changes in revs. 14243,14241,14239 temporarily reverted until JUnit runtime
267
**                           support is added to client projects.
266
**     VVT 2022xxxx          Two more rulesets processed: unit_test_support and legacy_annotations_post.
267
**                           See #6237.
268 268
*/
269 269
 -->
270 270
 
......
678 678
   <rule-set name="annotations/method_defs" />
679 679
   <rule-set name="annotations/procedures" />
680 680
   <rule-set name="annotations/legacy_services" />
681
   <!-- <rule-set name="annotations/unit_test_support" /> -->
682
   <!-- <rule-set name="annotations/legacy_annotations_post" /> -->
681
   <rule-set name="annotations/unit_test_support" />
682
   <rule-set name="annotations/legacy_annotations_post" />
683 683
   <rule-set name="annotations/case_statements" />
684 684
   <rule-set name="annotations/input_output" />
685 685
   <rule-set name="annotations/assignment_style_stmt_rewriting" />
rules/annotations/legacy_services.rules 2022-09-30 11:51:48 +0000
21 21
** 005 VVT 20220913 OEUnit support: code removing all annotations removed. See #6237.
22 22
**     VVT 20220913 Prevent unsupported legacy annotations from going to Java code. See #6237.
23 23
**                  Use new create_java_annotation() function to create Java annotation nodes.
24
**     VVT 20220914 Changes in revs. 14243,14241,14239 temporarily reverted until JUnit runtime
25
**                  support is added to client projects.
24
**     VVT 2022xxxx Changes in revs. 14243,14241,14239 restored. See #6237.
26 25
*/
27 26
 -->
28 27
 
......
212 211
            <while>iter.hasNext()
213 212
               <action>prest = iter.next()</action>
214 213
               
215
               <action>ref = createProgressAst(prog.annotation, "@", pref)</action>
216
               <action>ref.putAnnotation("javaname", "LegacyServiceParameter")</action>
217
               <action>ref.putAnnotation("name", "LegacyServiceParameter")</action>
214
               
215
               <action>ref = execLib("create_java_annotation", pref, "LegacyServiceParameter", -1)</action>
218 216
               
219 217
               <rule>execLib("assign_field_int", ref, "ordinal", prest.ordinal())</rule>
220 218
               
......
308 306
            <rule>keep
309 307
               <action>hasSrvs = true</action>
310 308
               
311
               <action on="false">ref.remove()</action>
309
               <!-- Do NOT remove unsupported annotations here, they will be removed in legacy_annotations_post.rules -->
310
               <!-- <action on="false">ref.remove()</action> -->
312 311
            </rule>
313 312
         </while>
314 313
      </function>
......
343 342
         
344 343
         <action>hasSrvs = true</action>
345 344
         
346
         <action>ref = createProgressAst(prog.annotation, "@", copy, 1)</action>
347
         <action>ref.putAnnotation("javaname", "LegacyService")</action>
348
         <action>ref.putAnnotation("name", "LegacyService")</action>
345
         <action>ref = execLib("create_java_annotation", copy, "LegacyService", 1)</action>
349 346
         
350 347
         <action>execLib("assign_field", ref, "type", "SOAP")</action>
351 348
         <action>execLib("assign_field", ref, "namespace", soapOp.getNamespace())</action>
......
401 398
            <action>soapOp = iter.next()</action>
402 399
            <action>hasSrvs = true</action>
403 400

  
404
            <action>ref = createProgressAst(prog.annotation, "@", copy, 1)</action>
405
            <action>ref.putAnnotation("javaname", "LegacyService")</action>
406
            <action>ref.putAnnotation("name", "LegacyService")</action>
401
            <action>ref = execLib("create_java_annotation", copy, "LegacyService", 1)</action>
407 402
            
408 403
            <action>execLib("assign_field", ref, "type", "SOAP")</action>
409 404
            <action>execLib("assign_field", ref, "namespace", soapOp.getNamespace())</action>
......
419 414
      <rule>this.type == prog.class_def and srv.isWebHandler(oname)
420 415
         <action>hasSrvs = true</action>
421 416
         
422
         <action>ref = createProgressAst(prog.annotation, "@", copy, 1)</action>
423
         <action>ref.putAnnotation("javaname", "LegacyService")</action>
424
         <action>ref.putAnnotation("name", "LegacyService")</action>
417
         <action>ref = execLib("create_java_annotation", copy, "LegacyService", 1)</action>
425 418
         
426 419
         <rule>execLib("assign_field", ref, "name", srv.getSection(oname))</rule>
427 420
         <rule>execLib("assign_field", ref, "type", "WEBHANDLER")</rule>
......
432 425
         <while>iter.hasNext()
433 426
            <action>path = iter.next()</action>
434 427

  
435
            <action>ref = createProgressAst(prog.annotation, "@", pref)</action>
436
            <action>ref.putAnnotation("javaname", "LegacyWebPath")</action>
437
            <action>ref.putAnnotation("name", "LegacyWebPath")</action>
428
            <action>ref = execLib("create_java_annotation", pref, "LegacyWebPath", -1)</action>
438 429

  
439 430
            <action>execLib("assign_field", ref, "path", path.path())</action>
440 431
            <action>execLib("assign_field_int", ref, "order", path.order())</action>
rules/annotations/unit_test_support.rules 2022-10-19 16:43:27 +0000
9 9
** _#_ _I_ __Date__  ___________________________Description____________________________
10 10
** 001 VVT 20220913  Initial version
11 11
**     VVT 20220913  Prevent unsupported legacy annotations from going to Java code. See #6237.
12
**     VVT 2022xxxx Custom test engine annotations are now used instead of that
13
**                  from the Jupiter test engine. See #6237.
12 14
*/
13 15
 -->
14 16
<!--
......
65 67
-->
66 68
<rule-set>
67 69
   <worker class="com.goldencode.p2j.uast.ProgressPatternWorker" namespace="prog" />
70
   <worker class="com.goldencode.p2j.uast.UastHintsWorker"       namespace="hints" />
71
   <worker class="com.goldencode.p2j.convert.ExpressionConversionWorker" namespace="ecw" />
72
   
73
   <func-library access="private">
74
      <!-- FIXME: functions in this library are mostly copied from the legacy_services.rules.
75
           they should probably go to some public library -->
76
      <!--
77
          Create an assignment <attName>=
78
      -->
79
      <function name="assign_field_part">
80
         <!-- The parent node -->
81
         <parameter name="parent" type="com.goldencode.ast.Aast" />
82
         <!-- the left part attribute name -->
83
         <parameter name="attName" type="java.lang.String" />
84
         
85
         <return name="tref" type="com.goldencode.ast.Aast" />
86
         
87
         <variable name="chref" type="com.goldencode.ast.Aast" />
88
         
89
         <rule>tref = createProgressAst(prog.assign, "=", parent)</rule>
90
         
91
         <rule>chref = createProgressAst(prog.symbol, attName, tref)</rule>
92
         <rule>chref.putAnnotation("javaname", attName)</rule>
93
      </function>
94
   
95
      <!--
96
          Create an assignment <attName>=[
97
      -->
98
      <function name="assign_field_array">
99
         <parameter name="parent" type="com.goldencode.ast.Aast" />
100
         <parameter name="attName" type="java.lang.String" />
101
         
102
         <return name="tref" type="com.goldencode.ast.Aast" />
103
         
104
         <rule>tref = execLib("assign_field_part", parent, attName)</rule>
105
         <rule>tref = createProgressAst(prog.lbracket, "[", tref)</rule>
106
      </function>
107
   </func-library>
68 108
   <walk-rules>
69 109
      <rule>this.type == prog.annotation
70
            and parent.type == prog.method_def
110
            and (parent.type == prog.method_def
111
                 or parent.type == prog.procedure
112
                 or parent.type == prog.class_def)
113
            
114
         <!-- Get required unit test legacy type configuration (hints) -->
115
         <variable name="unitTestType" type="java.lang.String" />
116
         <action>unitTestType = hints.getUnitTestType()</action>
117
         <rule>unitTestType == null
118
            <action>compileError(223, "No unit test legacy type is configured")</action>
119
         </rule>
120
         
121
         <variable name="isABLUnit" type="java.lang.Boolean" />
122
         <action>isABLUnit = unitTestType.equals("ABLUnit")</action>
123

  
124
         <variable name="methodNode" type="com.goldencode.ast.Aast" />
125
         <action>methodNode = parent.firstChild</action>
126

  
127
         <!-- FIXME: Add similar support for procedures -->
71 128

  
72 129
         <!-- Get initial annotation name -->
73 130
         <variable name="annoName" type="java.lang.String" />
74 131
         <action>annoName = this.getAnnotation("javaname")</action>
75 132

  
133
         <action>printfln("method %s is ABL unit test type %s annoName @%s", methodNode.getAnnotation("name"), isABLUnit, annoName)</action>
134

  
76 135
         <variable name="newName" type="java.lang.String" />
77 136
         <action>newName = null</action>
78 137

  
79
         <!-- Replace OEUnit annotation names (made after JUnit 4) by JUnit 5 names -->
80
         <rule>annoName.equals("Test")
81
            <action>newName = "org.junit.jupiter.api.Test"</action>
82
            <rule on="false">annoName.equals("Before")
83
               <action>newName = "org.junit.jupiter.api.BeforeEach"</action>
84
               <rule on="false">annoName.equals("After")
85
                  <action>newName = "org.junit.jupiter.api.AfterEach"</action>
86
                  <rule on="false">annoName.equals("BeforeClass")
87
                     <action>newName = "org.junit.jupiter.api.BeforeAll"</action>
88
                     <rule on="false">annoName.equals("AfterClass")
89
                        <action>newName = "org.junit.jupiter.api.AfterAll"</action>
90
                        <rule on="false">annoName.equals("Ignore")
91
                           <action>newName = "org.junit.jupiter.api.Disabled"</action>
138
         <!-- Replace OEUnit/ABLUnit annotation names by corresponding JUnit5 names -->
139
         <rule>annoName.equalsIgnoreCase("Test")
140
            <action>newName = "com.goldencode.p2j.testengine.api.Test"</action>
141

  
142
            <!-- Note: the meaning of @Before and @After is opposite in ABLUnit and OEUnit -->
143
            <rule on="false">annoName.equalsIgnoreCase("Before")
144
               <rule>isABLUnit
145
                  <action>newName = "com.goldencode.p2j.testengine.api.BeforeAll"</action>
146
                  <action on="false">newName = "com.goldencode.p2j.testengine.api.BeforeEach"</action>
147
               </rule>
148
               <rule on="false">annoName.equalsIgnoreCase("After")
149
                  <rule>isABLUnit
150
                     <action>newName = "com.goldencode.p2j.testengine.api.AfterAll"</action>
151
                     <action on="false">newName = "com.goldencode.p2j.testengine.api.AfterEach"</action>
152
                  </rule>
153
                  <rule on="false">annoName.equalsIgnoreCase("BeforeClass")
154
                     <action>newName = "com.goldencode.p2j.testengine.api.BeforeAll"</action>
155
                     <rule on="false">annoName.equalsIgnoreCase("AfterClass")
156
                        <action>newName = "com.goldencode.p2j.testengine.api.AfterAll"</action>
157
                        <rule on="false">annoName.equalsIgnoreCase("Ignore")
158
                           <action>newName = "com.goldencode.p2j.testengine.api.Disabled"</action>
159
                        </rule>
160
                        <rule on="false">annoName.equalsIgnoreCase("Setup")
161
                           <action>newName = "com.goldencode.p2j.testengine.api.BeforeEach"</action>
162
                           <rule on="false">annoName.equalsIgnoreCase("TearDown")
163
                              <action>newName = "com.goldencode.p2j.testengine.api.AfterEach"</action>
164
                              <rule on="false">annoName.equalsIgnoreCase("Suite")
165
                                 <action>newName = "com.goldencode.p2j.testengine.api.Suite"</action>
166

  
167
                                 <rule on="false">annoName.equalsIgnoreCase("SelectClasses")
168
                                    <!-- Get the "value" attribute, convert the quoted comma-separated list of class
169
                                         names to nodes of prog.symbol type -->
170
                                    <action>newName = "com.goldencode.p2j.testengine.api.SelectClasses"</action>
171
                                    <variable name="ref" type="com.goldencode.ast.Aast" />
172
                                    <!-- Go to the second child, which must be attribute assignment -->
173
                                    <action>ref = copy.getChildAt(1)</action>
174
                                    <rule>ref == null
175
                                       <action>compileError(367, "@SelectClasses annotation must have a child")</action>
176
                                    </rule>
177
                                    <rule>ref.type == prog.assign
178
                                       <action on="false">compileError(367, "@SelectClasses children must have the assignment type")</action>
179
                                    </rule>
180
                                    <action>ref = ref.firstChild</action>
181
                                    <rule>ref.getAnnotation("javaname").equals("value")
182
                                       <action on="false">compileError(367, "@SelectClasses: attribute name must be 'value'")</action>
183
                                    </rule>
184
                                    <!-- Go to second child od ASSIGN, which must be a STRING literal -->
185
                                    <action>ref = ref.nextSibling</action>
186
                                    <rule>ref.type == prog.string and ref.getAnnotation("is-literal").equals("true")
187
                                       <action>compileError(367, "@SelectClasses attribute assignment right part must be a string literal")</action>
188
                                    </rule>
189
                                    <!-- Get the value of the "value" attribute ofthe annotation, strip surrounding quotes -->
190
                                    <variable name="classList" type="java.lang.String" />
191
                                    <action>classList = ecw.stripQuotes(ref.getText())</action>
192

  
193
                                    <!-- Now we can drop the original value -->
194
                                    <action>ref.getParent().remove()</action>
195
                                    
196
                                    <action>printfln("Classlist %s", classList)</action>
197

  
198
                                    <!-- Create a node of the array type -->
199
                                    <action>ref = execLib("assign_field_array", copy, "value")</action>
200
                                    <!-- Parse and convert the comma-separated list -->
201
                                    <variable name="classNameList" type="java.util.List" />
202
                                    <action>classNameList = createListFromObject(classList.split(","))</action>
203
                                    <variable name="classNames" type="java.util.Iterator" />
204
                                    <action>classNames = classNameList.iterator()</action>
205
                                    <while>classNames.hasNext()
206
                                       <variable name="className" type="java.lang.String" />
207
                                       <action>className = (#(java.lang.String)classNames.next()).trim()</action>
208
                                       <action>printfln("Class name '%s'", className)</action>                                       
209
                                       <action>createProgressAst(prog.symbol, sprintf("%s.class", className), ref)</action>
210
                                    </while>            
211
                                 </rule>
212
                              </rule>
213
                           </rule>
92 214
                        </rule>
93 215
                     </rule>
94 216
                  </rule>
95 217
               </rule>
96 218
            </rule>
97 219
         </rule>
98

  
99 220
         <rule>newName != null
100
           <!-- Write it back and mark "our" annotations as preserved -->
101
           <action>copy.putAnnotation("javaname", newName)</action>
102
           <action>copy.putAnnotation("fwd", true)</action>
221
            <action>printfln("newName %s", newName)</action>
222
            <!-- Write it back... -->
223
            <action>copy.putAnnotation("javaname", newName)</action>
224
            <!-- ...and mark "our" annotations as preserved -->
225
            <action>copy.putAnnotation("fwd", true)</action>
103 226
         </rule>
104 227
      </rule>
105 228
      
rules/convert/core_conversion.xml 2022-09-30 11:59:12 +0000
71 71
** 026 VVT 20220913          OEUnit support: convert/unit_test_support added. See #6237.
72 72
**     VVT 20220914          Changes in revs. 14243,14241,14239 temporarily reverted until JUnit runtime
73 73
**                           support is added to client projects.
74
**     VVT 2022xxxx          Changes in revs. 14243,14241,14239 restored. See #6237.
74 75
*/
75 76
 -->
76 77
 
......
184 185
        Progress source constructs into the equivalent Java constructs
185 186
        rooted in the Java AST -->
186 187
   <rule-set honor-hidden="true" input="tree" load-condition="runtime-query">
187
      <!-- <rule-set name="convert/unit_test_support" /> -->
188
      <rule-set name="convert/unit_test_support" />
188 189
      <rule-set name="convert/variable_definitions" />
189 190
      <!-- the order of the following rules is important - method_definitions' ascent-rules will
190 191
           emit the signature's parameter annotations -->
rules/convert/unit_test_support.rules 2022-10-18 18:36:43 +0000
9 9
** _#_ _I_ __Date__  ___________________________Description____________________________
10 10
** 001 VVT 20220913  Initial version
11 11
**     VVT 20220913  Prevent unsupported legacy annotations from going to Java code. See #6237.
12
**     VVT 2022xxxx  Custom test engine annotations are now used instead of that
13
**                   from the Jupiter test engine. See #6237.
12 14
*/
13 15
 -->
14 16
<!--
......
66 68
<rule-set>
67 69
   <worker class="com.goldencode.p2j.convert.ConverterHelper" namespace="help" />
68 70
   <worker class="com.goldencode.p2j.uast.ProgressPatternWorker" namespace="prog" />
71
   <worker class="com.goldencode.p2j.convert.ExpressionConversionWorker" namespace="ecw" />
72
   
69 73
   <variable name="hasJUnit5Annotations" type="java.lang.Boolean"/>
70 74

  
71 75
   <!-- Detect if any of JUnit 5 annotations exist in the tree -->
72 76
   <walk-rules>
73 77
      <rule>this.type == prog.annotation
74
            and parent.type == prog.method_def
78
            and (parent.type == prog.method_def or parent.type == prog.class_def)
75 79
         <variable name="annoName" type="java.lang.String" />
76 80
         <action>annoName = this.getAnnotation("javaname")</action>
77 81
         <rule>
78
            annoName.equals("org.junit.jupiter.api.Test") or
79
            annoName.equals("org.junit.jupiter.api.BeforeEach") or
80
            annoName.equals("org.junit.jupiter.api.AfterEach")  or
81
            annoName.equals("org.junit.jupiter.api.BeforeAll")  or
82
            annoName.equals("org.junit.jupiter.api.AfterAll")   or
83
            annoName.equals("org.junit.jupiter.api.Disabled")
82
            annoName.startsWith("com.goldencode.p2j.testengine.api.")
84 83
            <!-- Replace fully-qualified name by simple name -->
85
            <action>copy.putAnnotation("javaname", annoName.substring(22))</action>
84
            <action>copy.putAnnotation("javaname", annoName.substring(34))</action>
86 85
            <action>hasJUnit5Annotations = true</action>
87 86
         </rule>
88 87
      </rule>
88
      <rule>upPath("ANNOTATION/ASSIGN/LBRACKET")
89
            and this.type == prog.symbol
90
         <action>printfln("ANNOTATION/ASSIGN/LBRACKET text '%s'", this.getText())</action>
91
         <action>createJavaAst(java.reference, ecw.stripQuotes(this.getText()), getClosestPeerId())</action>
92
      </rule>
89 93
   </walk-rules>
90 94
   <post-rules>
91 95
      <rule>hasJUnit5Annotations == true
92
         <action>help.createImport("org.junit.jupiter.api.*")</action>
96
         <action>help.createImport("com.goldencode.p2j.testengine.api.*")</action>
93 97
         <action>hasJUnit5Annotations = false</action>
94 98
      </rule>
95 99
   </post-rules>
src/com/goldencode/p2j/cfg/Configuration.java 2022-09-30 11:47:48 +0000
75 75
**     CA  20220412          Added file-set support (either -Z command-line option or p2j.cfg.xml 
76 76
**                           configuration).
77 77
**     OM  20220421          Restored the ability to load the configuration file relative to P2J_HOME folder.
78
**     VVT 2022xxxx          Constant added: default legacy unit test framework type. See #6237. 
78 79
*/
79 80

  
80 81
/*
......
268 269
   /** Default configuration filename */
269 270
   public static final String DEF_CFG_FILE = "p2j.cfg.xml";
270 271
   
272
   /** Default legacy unit test type */
273
   public static final String DEF_UNIT_TEST_TYPE = "ABLUnit";
274
   
271 275
   /** Singleton instance. */
272 276
   private static volatile Configuration instance;
273 277
   
src/com/goldencode/p2j/main/ClientCore.java 2022-10-12 22:01:49 +0000
60 60
**     CA  20220208 Added -errorstack command-line option (client:cmd-line-option:error-stack).
61 61
**     SVL 20220620 "ininame" parameter handling moved earlier to TC.initializePost.
62 62
**     CA  20220918 Added socket trust store filename and password to the ClientParameters.
63
**     VVT 2022xxxx Native methods processInit and getPid made public to be accessible from
64
**                  FWD test engine. See #6237.
63 65
*/
64 66
/*
65 67
** This program is free software: you can redistribute it and/or modify
......
121 123
import java.util.logging.*;
122 124

  
123 125
import com.goldencode.p2j.cfg.*;
126
import com.goldencode.p2j.directory.*;
124 127
import com.goldencode.p2j.net.*;
125
import com.goldencode.p2j.directory.*;
128
import com.goldencode.p2j.net.Session;
126 129
import com.goldencode.p2j.security.SecurityManager;
130
import com.goldencode.p2j.ui.chui.*;
127 131
import com.goldencode.p2j.ui.client.*;
128 132
import com.goldencode.p2j.ui.client.driver.*;
129
import com.goldencode.p2j.ui.chui.ThinClient;
130 133
import com.goldencode.p2j.util.*;
131 134

  
132 135
/**
......
172 175
    *           <code>false</code> for the normal client JVM startup.
173 176
    * @param    diag
174 177
    *           Details about the driver state that can help diagnose server startup issues.
175
    *           
176 178
    * @throws Exception 
177 179
    */
178 180
   public static void start(BootstrapConfig config, boolean file, boolean single, Supplier<String> diag)
......
357 359
         // set up current user name for client session
358 360
         ThinClient.getInstance().setUserName(params.osUserName);
359 361

  
362
         
360 363
         // call the application
361 364
         running = main.standardEntry();
362 365
         
......
438 441
   /**
439 442
    * Native call to set up and redefine signal processing handlers.
440 443
    */
441
   private static native void processInit();
444
   public static native void processInit();
442 445
   
443 446
   /**
444 447
    * Native call to read the operating system pid for the current JVM process.
448
    * 
449
    * @return see above 
445 450
    */
446
   private static native long getPid();
451
   public static native long getPid();
447 452
   
448 453
   /**
449 454
    * Native call to read the operating system user name for the current JVM process.
455
    * 
456
    * @return see above 
450 457
    */
451
   private static native String getUserName();
458
   public static native String getUserName();
452 459
   
453 460
   /**
454 461
    * Initialize the logger if needed.
src/com/goldencode/p2j/main/StandardServer.java 2022-10-12 21:57:10 +0000
203 203
**                           allows a lazy registration of scopeables, to avoid the unnecessary overhead of
204 204
**                           processing all the scopeables for each and every block.
205 205
**     CA  20220906          Moved the interactive client cleaner to LogicalTerminal.registerCleaner().
206
**     VVT 2022xxxx          UnitTestEngine static network server registration added. See #6237.
206 207
*/
207 208

  
208 209
/*
......
264 265
import java.lang.reflect.*;
265 266
import java.util.*;
266 267
import java.util.concurrent.*;
267
import java.util.function.Supplier;
268
import java.util.function.*;
268 269
import java.util.logging.*;
270

  
269 271
import javax.servlet.*;
272

  
270 273
import org.eclipse.jetty.server.handler.*;
271 274
import org.eclipse.jetty.util.resource.Resource;
272 275
import org.eclipse.jetty.webapp.*;
276

  
273 277
import com.goldencode.ast.*;
274 278
import com.goldencode.p2j.*;
275 279
import com.goldencode.p2j.admin.*;
......
287 291
import com.goldencode.p2j.security.*;
288 292
import com.goldencode.p2j.security.SecurityManager;
289 293
import com.goldencode.p2j.soap.*;
294
import com.goldencode.p2j.testengine.*;
290 295
import com.goldencode.p2j.ui.*;
291 296
import com.goldencode.p2j.util.*;
292 297
import com.goldencode.p2j.util.ErrorManager;
......
992 997
      
993 998
      ifaces = new Class[] { ServerPropertiesInspector.class };
994 999
      RemoteObject.registerStaticNetworkServer(ifaces, ServerPropertiesDaemon.class);
995
      
1000
            
1001
      RemoteObject.registerStaticNetworkServer(new Class[] { UnitTestEngine.class }, UnitTestServer.class);
1002

  
996 1003
      AdminServerImpl.initialize();
997 1004
      
998 1005
      DirectoryManager.initServer();
......
1114 1121
    * @param   ds
1115 1122
    *          The directory service.
1116 1123
    */
1117
   private void initClassLoaders(DirectoryService ds)
1124
   private static void initClassLoaders(DirectoryService ds)
1118 1125
   {
1119 1126
      // initialize the class loaders for the jars defined in the directory
1120 1127
      String path = Utils.findDirectoryNodePath(ds,
src/com/goldencode/p2j/main/UnitTestDriver.java 2022-10-12 21:44:30 +0000
1
/**
2
 * 
3
 */
4
package com.goldencode.p2j.main;
5

  
6
import com.goldencode.p2j.cfg.*;
7

  
8
/**
9
 * The purpose of this class is to explore how to start client with no command line.
10
 */
11
public class UnitTestDriver
12
{
13

  
14
   /**
15
    * The main entry
16
    * 
17
    * @param args
18
    *        for now unused
19
    */
20
   public static void main(String[] args)
21
   {
22
      // process arguments: either config files of overrides
23
      // try standard configuration file if none is given
24
      BootstrapConfig bc = null;
25

  
26
      try
27
      {
28
         bc = new BootstrapConfig(null, null, null, null);
29
      }
30
      catch (ConfigurationException e)
31
      {
32
         e.printStackTrace();
33
         System.exit(1);
34
      }
35

  
36
      bc.setServer(false);
37

  
38
      String convo = null;
39

  
40
      try
41
      {
42
         convo = bc.getConfigItem("net", "queue", "conversation");
43
      }
44
      catch (ConfigurationException ce)
45
      {
46
         // ignore
47
      }
48

  
49
      // default to conversation mode if not specified
50
      if (convo == null)
51
      {
52
         bc.setConfigItem("net", "queue", "conversation", "true");
53
      }
54

  
55
      // either way, force start thread to false (this client is going to
56
      // use its main thread as the conversation thread so we don't need
57
      // to start one
58
      bc.setConfigItem("net", "queue", "start_thread", "false");
59

  
60
      bc.setConfigItem("net", "server", "host", "localhost");
61
      bc.setConfigItem("net", "connection", "secure", "false");
62
      bc.setConfigItem("net", "server", "secure_port", "4434");
63
      bc.setConfigItem("net", "server", "insecure_port", "4534");
64
      bc.setConfigItem("client", "driver", "type", "gui_swing");
65
      bc.setConfigItem("client", "driver", "theme",
66
               "com.goldencode.p2j.ui.client.gui.theme.Windows10Theme");
67

  
68
      // run the application
69
      try
70
      {
71
         //         if (config.getBoolean("net", "http_client", "disable_ssl_certificate_validation", false))
72
         //         {
73
         //            Utils.disableClientSSLCertificateValidation();
74
         //         }
75

  
76
         //         if (config.getBoolean("client", "mode", "broker", false))
77
         //         {
78
         //            setClientLog("broker");
79
         //            BrokerCore.start(config);
80
         //         }
81
         //         else
82
         //         {
83
         //            ClientCore.start(config, true, false, this::printDriverDetails);
84
         //         }
85

  
86
         ClientCore.start(bc, true, false, () -> "");
87
         // ensure that remaining non-daemon threads don't stop us from closing
88
         System.exit(0);
89
      }
90
      catch (Throwable thr)
91
      {
92
         // STOP conditions don't need to be reported, they are an expected
93
         // mechanism to terminate
94
         if (ClientCore.isCauseStop(thr))
95
         {
96
            System.exit(0);
97
         }
98

  
99
         thr.printStackTrace(System.err);
100
         System.err.flush();
101
         System.exit(-13);
102
      }
103

  
104
   }
105
}
src/com/goldencode/p2j/testengine/AbstractBranchTestDescriptor.java 2022-10-12 21:04:57 +0000
1
/*
2
** Module   : AbstractBranchTestDescriptor.java
3
** Abstract : Common accessor for non-terminal test descriptors
4
**
5
** Copyright (c) 2022, Golden Code Development Corporation.
6
**
7
** -#- -I- --Date-- ----------------Description----------------------
8
** 001 VVT 2022xxxx Created initial version.
9
*/
10
/*
11
** This program is free software: you can redistribute it and/or modify
12
** it under the terms of the GNU Affero General Public License as
13
** published by the Free Software Foundation, either version 3 of the
14
** License, or (at your option) any later version.
15
**
16
** This program is distributed in the hope that it will be useful,
17
** but WITHOUT ANY WARRANTY; without even the implied warranty of
18
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
** GNU Affero General Public License for more details.
20
**
21
** You may find a copy of the GNU Affero GPL version 3 at the following
22
** location: https://www.gnu.org/licenses/agpl-3.0.en.html
23
** 
24
** Additional terms under GNU Affero GPL version 3 section 7:
25
** 
26
**   Under Section 7 of the GNU Affero GPL version 3, the following additional
27
**   terms apply to the works covered under the License.  These additional terms
28
**   are non-permissive additional terms allowed under Section 7 of the GNU
29
**   Affero GPL version 3 and may not be removed by you.
30
** 
31
**   0. Attribution Requirement.
32
** 
33
**     You must preserve all legal notices or author attributions in the covered
34
**     work or Appropriate Legal Notices displayed by works containing the covered
35
**     work.  You may not remove from the covered work any author or developer
36
**     credit already included within the covered work.
37
** 
38
**   1. No License To Use Trademarks.
39
** 
40
**     This license does not grant any license or rights to use the trademarks
41
**     Golden Code, FWD, any Golden Code or FWD logo, or any other trademarks
42
**     of Golden Code Development Corporation. You are not authorized to use the
43
**     name Golden Code, FWD, or the names of any author or contributor, for
44
**     publicity purposes without written authorization.
45
** 
46
**   2. No Misrepresentation of Affiliation.
47
** 
48
**     You may not represent yourself as Golden Code Development Corporation or FWD.
49
** 
50
**     You may not represent yourself for publicity purposes as associated with
51
**     Golden Code Development Corporation, FWD, or any author or contributor to
52
**     the covered work, without written authorization.
53
** 
54
**   3. No Misrepresentation of Source or Origin.
55
** 
56
**     You may not represent the covered work as solely your work.  All modified
57
**     versions of the covered work must be marked in a reasonable way to make it
58
**     clear that the modified work is not originating from Golden Code Development
59
**     Corporation or FWD.  All modified versions must contain the notices of
60
**     attribution required in this license.
61
*/
62
package com.goldencode.p2j.testengine;
63

  
64
import java.io.*;
65
import java.util.*;
66

  
67
import org.junit.platform.commons.util.*;
68
import org.junit.platform.engine.*;
69

  
70
/**
71
 * This class provides common functions for branch test descriptors
72
 */
73
public abstract class AbstractBranchTestDescriptor
74
extends AbstractFWDTestDescriptor
75
{
76
   /** Child descriptors */
77
   private Set<TestDescriptor> children = Collections.synchronizedSet(new LinkedHashSet<>(16));
78

  
79
   /**
80
    * The constructor.
81
    * 
82
    * @param uniqueId
83
    *        this descriptor unique ID
84
    * @param displayName
85
    *        this descriptor display name
86
    */
87
   public AbstractBranchTestDescriptor(final UniqueId uniqueId, final String displayName)
88
   {
89
      super(uniqueId, displayName);
90
   }
91

  
92
   /**
93
    * Add a <em>child</em> to this descriptor.
94
    *
95
    * @param descriptor the child to add to this descriptor; never {@code null}
96
    */
97
   @Override
98
   public void addChild(final TestDescriptor descriptor)
99
   {
100
      Preconditions.notNull(descriptor, "child must not be null");
101

  
102
      descriptor.setParent(this);
103
      children.add(descriptor);
104
   }
105

  
106
   /**
107
    * Find the descriptor with the supplied unique ID.
108
    *
109
    * <p>The search algorithm begins with this descriptor and then searches
110
    * through its descendants.
111
    *
112
    * @param uniqueId the {@code UniqueId} to search for; never {@code null}
113
    */
114
   @Override
115
   public Optional<? extends TestDescriptor> findByUniqueId(final UniqueId uniqueId)
116
   {
117
      if (getUniqueId().equals(uniqueId))
118
      {
119
         return Optional.of(this);
120
      }
121

  
122
      return children.stream().map(child -> child.findByUniqueId(uniqueId))
123
               .filter(Optional::isPresent).findAny().orElse(Optional.empty());
124
   }
125

  
126
   /**
127
    * Get the immutable set of <em>children</em> of this descriptor.
128
    *
129
    * @return the set of children of this descriptor; neither {@code null}
130
    * nor mutable, but potentially empty
131
    * @see #getDescendants()
132
    */
133
   @Override
134
   public final Set<? extends TestDescriptor> getChildren()
135
   {
136
      return Collections.unmodifiableSet(children);
137
   }
138

  
139
   /**
140
   * Determine the {@link org.junit.platform.engine.TestDescriptor.Type} of this descriptor.
141
   *
142
   * @return the descriptor type; never {@code null}.
143
   * @see #isContainer()
144
   * @see #isTest()
145
   */
146
   @Override
147
   public Type getType()
148
   {
149
      return Type.CONTAINER;
150
   }
151

  
152
   /**
153
    * The object implements the readExternal method to restore its
154
    * contents by calling the methods of DataInput for primitive
155
    * types and readObject for objects, strings and arrays.  The
156
    * readExternal method must read the values in the same sequence
157
    * and with the same types as were written by writeExternal.
158
    *
159
    * @param in the stream to read data from in order to restore the object
160
    * @exception IOException if I/O errors occur
161
    * @exception ClassNotFoundException If the class for an object being
162
    *              restored cannot be found.
163
    */
164
   @Override
165
   public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
166
   {
167
      super.readExternal(in);
168
      
169
      children = (Set<TestDescriptor>) in.readObject();
170
      
171
      for(final TestDescriptor child : children)
172
      {
173
         child.setParent(this);
174
      }
175
   }
176

  
177
   /**
178
    * Remove a <em>child</em> from this descriptor.
179
    *
180
    * @param descriptor the child to remove from this descriptor; never
181
    * {@code null}
182
    */
183
   @Override
184
   public void removeChild(TestDescriptor descriptor)
185
   {
186
      Preconditions.notNull(descriptor, "child must not be null");
187

  
188
      children.remove(descriptor);
189
      descriptor.setParent(null);
190
   }
191

  
192
   /**
193
    * The object implements the writeExternal method to save its contents
194
    * by calling the methods of DataOutput for its primitive values or
195
    * calling the writeObject method of ObjectOutput for objects, strings,
196
    * and arrays.
197
    *
198
    * @serialData Overriding methods should use this tag to describe
199
    *             the data layout of this Externalizable object.
200
    *             List the sequence of element types and, if possible,
201
    *             relate the element to a public/protected field and/or
202
    *             method of this Externalizable class.
203
    *
204
    * @param out the stream to write the object to
205
    * @exception IOException Includes any I/O exceptions that may occur
206
    */
207
   @Override
208
   public void writeExternal(ObjectOutput out) throws IOException
209
   {
210
      super.writeExternal(out);
211
      
212
      out.writeObject(children);
213
   }
214

  
215
}
src/com/goldencode/p2j/testengine/AbstractClassTestDescriptor.java 2022-10-21 15:15:58 +0000
1
/*
2
** Module   : AbstractClassTestDescriptor.java
3
** Abstract : Common ancestor for legacy class and legacy procedure test descriptors.
4
**
5
** Copyright (c) 2022, Golden Code Development Corporation.
6
**
7
** -#- -I- --Date-- ----------------Description----------------------
8
** 001 VVT 2022xxxx Created initial version.
9
*/
10
/*
11
** This program is free software: you can redistribute it and/or modify
12
** it under the terms of the GNU Affero General Public License as
13
** published by the Free Software Foundation, either version 3 of the
14
** License, or (at your option) any later version.
15
**
16
** This program is distributed in the hope that it will be useful,
17
** but WITHOUT ANY WARRANTY; without even the implied warranty of
18
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
** GNU Affero General Public License for more details.
20
**
21
** You may find a copy of the GNU Affero GPL version 3 at the following
22
** location: https://www.gnu.org/licenses/agpl-3.0.en.html
23
** 
24
** Additional terms under GNU Affero GPL version 3 section 7:
25
** 
26
**   Under Section 7 of the GNU Affero GPL version 3, the following additional
27
**   terms apply to the works covered under the License.  These additional terms
28
**   are non-permissive additional terms allowed under Section 7 of the GNU
29
**   Affero GPL version 3 and may not be removed by you.
30
** 
31
**   0. Attribution Requirement.
32
** 
33
**     You must preserve all legal notices or author attributions in the covered
34
**     work or Appropriate Legal Notices displayed by works containing the covered
35
**     work.  You may not remove from the covered work any author or developer
36
**     credit already included within the covered work.
37
** 
38
**   1. No License To Use Trademarks.
39
** 
40
**     This license does not grant any license or rights to use the trademarks
41
**     Golden Code, FWD, any Golden Code or FWD logo, or any other trademarks
42
**     of Golden Code Development Corporation. You are not authorized to use the
43
**     name Golden Code, FWD, or the names of any author or contributor, for
44
**     publicity purposes without written authorization.
45
** 
46
**   2. No Misrepresentation of Affiliation.
47
** 
48
**     You may not represent yourself as Golden Code Development Corporation or FWD.
49
** 
50
**     You may not represent yourself for publicity purposes as associated with
51
**     Golden Code Development Corporation, FWD, or any author or contributor to
52
**     the covered work, without written authorization.
53
** 
54
**   3. No Misrepresentation of Source or Origin.
55
** 
56
**     You may not represent the covered work as solely your work.  All modified
57
**     versions of the covered work must be marked in a reasonable way to make it
58
**     clear that the modified work is not originating from Golden Code Development
59
**     Corporation or FWD.  All modified versions must contain the notices of
60
**     attribution required in this license.
61
*/
62
package com.goldencode.p2j.testengine;
63

  
64
import java.io.*;
65
import java.lang.reflect.*;
66
import java.util.*;
67

  
68
import org.junit.platform.engine.*;
69

  
70
import com.goldencode.util.*;
71

  
72
/**
73
 * Common ancestor for legacy class and legacy procedure test descriptors.
74
 */
75
public abstract class AbstractClassTestDescriptor
76
extends AbstractBranchTestDescriptor
77
{
78

  
79
   /**
80
    * Class methods marked to execute before all tests 
81
    */
82
   List<Method> afterAll;
83

  
84
   /**
85
    * Class methods marked to execute before all tests 
86
    */
87
   List<Method> beforeAll;
88

  
89
   /**
90
    * The Java class.
91
    */
92
   Class clazz;
93

  
94
   /**
95
    * Default constructor. Required for serialization. Not to be used in application code.
96
    */
97
   protected AbstractClassTestDescriptor()
98
   {
99
      super(null, null);
100

  
101
      this.clazz = null;
102
      this.beforeAll = null;
103
      this.afterAll = null;      
104
   }
105

  
106
   /**
107
    * The constructor.
108
    * 
109
    * @param clazz
110
    *        the Java class
111
    * @param parent
112
    *        the parent descriptor
113
    * @param test
114
    *        class methods marked as tests  
115
    * @param beforeEach
116
    *        class methods marked to execute before each test  
117
    * @param afterEach
118
    *        class methods marked to execute after each test  
119
    * @param beforeAll
120
    *        class methods marked to execute before all tests  
121
    * @param afterAll
122
    *        class methods marked to execute after all tests  
123
    */
124
   protected AbstractClassTestDescriptor(final Class<?> clazz, final TestDescriptor parent,
125
            final List<Method> test, final List<Method> beforeEach, final List<Method> afterEach,
126
            final List<Method> beforeAll, final List<Method> afterAll)
127
   {
128
      super(parent.getUniqueId().append("class", clazz.getName()), clazz.getSimpleName());
129

  
130
      this.clazz = clazz;
131
      this.beforeAll = beforeAll;
132
      this.afterAll = afterAll;
133
   }
134
   
135
   /**
136
    * Execute the <em>after</em> behavior of this node implementation.
137
    *
138
    * <p>This method will be called once <em>after</em> {@linkplain #executeImpl()
139
    * execution} of this node.
140
    * 
141
    * @throws Exception 
142
    * 
143
    */
144
   @Override
145
   public void afterImpl() throws Exception
146
   {
147
      callMethodsImpl(afterAll);
148
   }
149

  
150
   /**
151
    * Execute the <em>before</em> behavior of this node implementation.
152
    *
153
    * <p>This method will be called once <em>before</em> {@linkplain #executeImpl()
154
    * execution} of this node.
155
    * 
156
    * @throws Exception 
157
    *
158
    */
159
   @Override
160
   public void beforeImpl() throws Exception
161
   {
162
      callMethodsImpl(beforeAll);
163
   }
164

  
165
   /**
166
    * Print all class-specific fields.
167
    * 
168
    * @param printer
169
    *        the string printer to print into
170
    */
171
   @Override
172
   public void print(PrintHelper printer)
173
   {
174
      printer.print(clazz.getName());
175
   }
176

  
177
   /**
178
    * The object implements the readExternal method to restore its
179
    * contents by calling the methods of DataInput for primitive
180
    * types and readObject for objects, strings and arrays.  The
181
    * readExternal method must read the values in the same sequence
182
    * and with the same types as were written by writeExternal.
183
    *
184
    * @param in the stream to read data from in order to restore the object
185
    * @exception IOException if I/O errors occur
186
    * @exception ClassNotFoundException If the class for an object being
187
    *              restored cannot be found.
188
    */
189
   @Override
190
   public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
191
   {
192
      super.readExternal(in);
193
      
194
      clazz = (Class<?>) in.readObject();
195
      beforeAll = SerializationSupport.readMethods(in);
196
      afterAll = SerializationSupport.readMethods(in);
197
   }
198

  
199
   /**
200
    * The object implements the writeExternal method to save its contents
201
    * by calling the methods of DataOutput for its primitive values or
202
    * calling the writeObject method of ObjectOutput for objects, strings,
203
    * and arrays.
204
    *
205
    * @serialData Overriding methods should use this tag to describe
206
    *             the data layout of this Externalizable object.
207
    *             List the sequence of element types and, if possible,
208
    *             relate the element to a public/protected field and/or
209
    *             method of this Externalizable class.
210
    *
211
    * @param out the stream to write the object to
212
    * @exception IOException Includes any I/O exceptions that may occur
213
    */
214
   @Override
215
   public void writeExternal(ObjectOutput out) throws IOException
216
   {
217
      super.writeExternal(out);
218
      
219
      out.writeObject(clazz);
220
      SerializationSupport.writeMethods(beforeAll, out);
221
      SerializationSupport.writeMethods(afterAll, out);
222
   }
223

  
224
}
src/com/goldencode/p2j/testengine/AbstractFWDTestDescriptor.java 2022-10-21 15:16:19 +0000
1
/*
2
** Module   : AbstractDWDTestDescriptor.java
3
** Abstract : Common accessor for all test descriptors
4
**
5
** Copyright (c) 2022, Golden Code Development Corporation.
6
**
7
** -#- -I- --Date-- ----------------Description----------------------
8
** 001 VVT 2022xxxx Created initial version.
9
*/
10
/*
11
** This program is free software: you can redistribute it and/or modify
12
** it under the terms of the GNU Affero General Public License as
13
** published by the Free Software Foundation, either version 3 of the
14
** License, or (at your option) any later version.
15
**
16
** This program is distributed in the hope that it will be useful,
17
** but WITHOUT ANY WARRANTY; without even the implied warranty of
18
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
** GNU Affero General Public License for more details.
20
**
21
** You may find a copy of the GNU Affero GPL version 3 at the following
22
** location: https://www.gnu.org/licenses/agpl-3.0.en.html
23
** 
24
** Additional terms under GNU Affero GPL version 3 section 7:
25
** 
26
**   Under Section 7 of the GNU Affero GPL version 3, the following additional
27
**   terms apply to the works covered under the License.  These additional terms
28
**   are non-permissive additional terms allowed under Section 7 of the GNU
29
**   Affero GPL version 3 and may not be removed by you.
30
** 
31
**   0. Attribution Requirement.
32
** 
33
**     You must preserve all legal notices or author attributions in the covered
34
**     work or Appropriate Legal Notices displayed by works containing the covered
35
**     work.  You may not remove from the covered work any author or developer
36
**     credit already included within the covered work.
37
** 
38
**   1. No License To Use Trademarks.
39
** 
40
**     This license does not grant any license or rights to use the trademarks
41
**     Golden Code, FWD, any Golden Code or FWD logo, or any other trademarks
42
**     of Golden Code Development Corporation. You are not authorized to use the
43
**     name Golden Code, FWD, or the names of any author or contributor, for
44
**     publicity purposes without written authorization.
45
** 
46
**   2. No Misrepresentation of Affiliation.
47
** 
48
**     You may not represent yourself as Golden Code Development Corporation or FWD.
49
** 
50
**     You may not represent yourself for publicity purposes as associated with
51
**     Golden Code Development Corporation, FWD, or any author or contributor to
52
**     the covered work, without written authorization.
53
** 
54
**   3. No Misrepresentation of Source or Origin.
55
** 
56
**     You may not represent the covered work as solely your work.  All modified
57
**     versions of the covered work must be marked in a reasonable way to make it
58
**     clear that the modified work is not originating from Golden Code Development
59
**     Corporation or FWD.  All modified versions must contain the notices of
60
**     attribution required in this license.
61
*/
62
package com.goldencode.p2j.testengine;
63

  
64
import java.io.*;
65
import java.lang.reflect.*;
66
import java.util.*;
67

  
68
import org.junit.platform.engine.*;
69
import org.junit.platform.engine.support.hierarchical.*;
70

  
71
import com.goldencode.util.*;
72

  
73
/**
74
 * This class provides common functions for all FWD test descriptors:
75
 * 
76
 * <li>Stores unique ID, display name and parent reference.
77
 * <li>Serialization: FWD test descriptors travel over network, so they must be serializable.
78
 * <li>Implements {@link Node} interface: all methods are passed to a proxy to be executed on the server.
79
 */
80
public abstract class AbstractFWDTestDescriptor
81
implements Externalizable,
82
           TestDescriptor,
83
           Node<FWDEngineExecutionContext>,
84
           Printable
85
{
86

  
87
   /** This descriptor display name */
88
   private String displayName;
89

  
90
   /** The parent descriptor or {@code null} if this is the root (test engine) descriptor */
91
   private TestDescriptor parent;
92

  
93
   /** The descriptor unique ID */
94
   private UniqueId uniqueId;
95

  
96
   /**
97
    * The constructor.
98
    * 
99
    * @param uniqueId
100
    *        the descriptor unique ID
101
    * @param displayName
102
    *        the descriptor display name
103
    */
104
   public AbstractFWDTestDescriptor(final UniqueId uniqueId, final String displayName)
105
   {
106
      this.uniqueId = uniqueId;
107
      this.displayName = displayName;
108
   }
109

  
110
   /**
111
    * Default constructor. Must be used internally for serialization only.
112
    */
113
   protected AbstractFWDTestDescriptor()
114
   {
115
      this(null, null);
116
   }
117

  
118
   /**
119
    * Add a <em>child</em> to this descriptor.
120
    *
121
    * @param descriptor the child to add to this descriptor; never {@code null}
122
    */
123
   @Override
124
   public void addChild(TestDescriptor descriptor)
125
   {
126
      // Default is the terminal node implementation, must be re-defined for branch nodes
127
      throw new RuntimeException("Not supported");
128
   }
129

  
130
   /**
131
    * Execute the <em>after</em> behavior of this node.
132
    *
133
    * <p>This method will be called once <em>after</em> {@linkplain #execute
134
    * execution} of this node.
135
    *
136
    * @param context
137
    *        the context to execute in
138
    * 
139
    */
140
   @Override
141
   public void after(final FWDEngineExecutionContext context) throws Exception
142
   {
143
      context.unitTestSupport.after(getUniqueId());
144
   }
145

  
146
   /**
147
    * Execute the <em>after</em> behavior of this node implementation.
148
    *
149
    * <p>This method will be called once <em>after</em> {@linkplain #executeImpl()
150
    * execution} of this node.
151
    * 
152
    * @throws Exception 
153
    * 
154
    */
155
   public void afterImpl() throws Exception
156
   {
157
      // no-op
158
   }
159

  
160
   /**
161
    * Execute the <em>before</em> behavior of this node.
162
    *
163
    * <p>This method will be called once <em>before</em> {@linkplain #execute
164
    * execution} of this node.
165
    *
166
    * @param context
167
    *        the context to execute in
168
    * @return the new context to be used for children of this node; never
169
    * {@code null}
170
    */
171
   @Override
172
   public FWDEngineExecutionContext before(FWDEngineExecutionContext context) throws Exception
173
   {
174
      context.unitTestSupport.before(getUniqueId());
175

  
176
      return context;
177
   }
178

  
179
   /**
180
    * Execute the <em>before</em> behavior of this node implementation.
181
    *
182
    * <p>This method will be called once <em>before</em> {@linkplain #executeImpl()
183
    * execution} of this node.
184
    * 
185
    * @throws Exception 
186
    *
187
    */
188
   public void beforeImpl() throws Exception
189
   {
190
      // no-op
191
   }
192

  
193
   /**
194
    * Clean up the supplied {@code context} after execution.
195
    * 
196
    * Reset the test class instance.
197
    *
198
    * @param context
199
    *        the context to execute in
200
   
201
    * @see #prepare
202
    */
203
   @Override
204
   public void cleanUp(final FWDEngineExecutionContext context) throws Exception
205
   {
206
      context.unitTestSupport.cleanUp(getUniqueId());
207
   }
208

  
209
   /**
210
    * Clean up the supplied {@code context} after execution implementation.
211
    * 
212
    * Reset the test class instance.
213
    * 
214
    * @throws Exception 
215
    *
216
    * @see #prepare
217
    */
218
   public void cleanUpImpl() throws Exception
219
   {
220
      // no-op
221
   }
222

  
223
   /**
224
    * Indicates whether some other object is "equal to" this one.
225
    * <p>
226
    * The {@code equals} method implements an equivalence relation
227
    * on non-null object references:
228
    * <ul>
229
    * <li>It is <i>reflexive</i>: for any non-null reference value
230
    *     {@code x}, {@code x.equals(x)} should return
231
    *     {@code true}.
232
    * <li>It is <i>symmetric</i>: for any non-null reference values
233
    *     {@code x} and {@code y}, {@code x.equals(y)}
234
    *     should return {@code true} if and only if
235
    *     {@code y.equals(x)} returns {@code true}.
236
    * <li>It is <i>transitive</i>: for any non-null reference values
237
    *     {@code x}, {@code y}, and {@code z}, if
238
    *     {@code x.equals(y)} returns {@code true} and
239
    *     {@code y.equals(z)} returns {@code true}, then
240
    *     {@code x.equals(z)} should return {@code true}.
241
    * <li>It is <i>consistent</i>: for any non-null reference values
242
    *     {@code x} and {@code y}, multiple invocations of
243
    *     {@code x.equals(y)} consistently return {@code true}
244
    *     or consistently return {@code false}, provided no
245
    *     information used in {@code equals} comparisons on the
246
    *     objects is modified.
247
    * <li>For any non-null reference value {@code x},
248
    *     {@code x.equals(null)} should return {@code false}.
249
    * </ul>
250
    * <p>
251
    * The {@code equals} method for class {@code Object} implements
252
    * the most discriminating possible equivalence relation on objects;
253
    * that is, for any non-null reference values {@code x} and
254
    * {@code y}, this method returns {@code true} if and only
255
    * if {@code x} and {@code y} refer to the same object
256
    * ({@code x == y} has the value {@code true}).
257
    * <p>
258
    * Note that it is generally necessary to override the {@code hashCode}
259
    * method whenever this method is overridden, so as to maintain the
260
    * general contract for the {@code hashCode} method, which states
261
    * that equal objects must have equal hash codes.
262
    *
263
    * @param   obj   the reference object with which to compare.
264
    * @return  {@code true} if this object is the same as the obj
265
    *          argument; {@code false} otherwise.
266
    * @see     #hashCode()
267
    * @see     java.util.HashMap
268
    */
269
   @Override
270
   public final boolean equals(Object obj)
271
   {
272
      // Test descriptors are compared by their unique IDs.
273
      if (obj == null)
274
      {
275
         return false;
276
      }
277

  
278
      if (this.getClass() != obj.getClass())
279
      {
280
         return false;
281
      }
282

  
283
      return uniqueId.equals(((TestDescriptor) obj).getUniqueId());
284
   }
285

  
286
   /**
287
    * Execute the <em>behavior</em> of this node.
288
    *
289
    * <p>Containers typically do not implement this method since the
290
    * {@link HierarchicalTestEngine} handles execution of their children.
291
    *
292
    * <p>The supplied {@code dynamicTestExecutor} may be used to submit
293
    * additional dynamic tests for immediate execution.
294
    *
295
    * @param context
296
    *         the context to execute in
297
    * @param dynamicTestExecutor
298
    *        the executor to submit dynamic tests to
299
    *        
300
    * @return the new context to be used for children of this node and for the
301
    * <em>after</em> behavior of the parent of this node, if any
302
    */
303
   @Override
304
   public FWDEngineExecutionContext execute(final FWDEngineExecutionContext context,
305
            DynamicTestExecutor dynamicTestExecutor) throws Exception
306
   {
307
      context.unitTestSupport.execute(getUniqueId());
308

  
309
      return context;
310
   }
311

  
312
   /**
313
    * Execute the implementation <em>behavior</em> of this node.
314
    *
315
    * @throws Exception 
316
    *
317
    */
318
   public void executeImpl() throws Exception
319
   {
320
      // no-op
321
   }
322

  
323
   /**
324
    * Find the descriptor with the supplied unique ID.
325
    *
326
    * <p>The search algorithm begins with this descriptor and then searches
327
    * through its descendants.
328
    *
329
    * @param uniqueId the {@code UniqueId} to search for; never {@code null}
330
    */
331
   @Override
332
   public Optional<? extends TestDescriptor> findByUniqueId(final UniqueId uniqueId)
333
   {
334
      return Optional.of(this.uniqueId.equals(uniqueId) ? this : null);
335
   }
336

  
337
   /**
338
    * Get the immutable set of <em>children</em> of this descriptor.
339
    *
340
    * @return the set of children of this descriptor; neither {@code null}
341
    * nor mutable, but potentially empty
342
    * @see #getDescendants()
343
    */
344
   @Override
345
   public Set<? extends TestDescriptor> getChildren()
346
   {
347
      return Collections.emptySet();
348
   }
349

  
350
   /**
... This diff was truncated because it exceeds the maximum size that can be displayed.