11package io .contract_testing .contractcase ;
22
3- import io .contract_testing .contractcase .case_boundary .BoundaryResult ;
4- import io .contract_testing .contractcase .case_boundary .IInvokeCoreTest ;
5- import io .contract_testing .contractcase .case_boundary .IRunTestCallback ;
3+ import io .contract_testing .contractcase .case_boundary .BoundaryCrashMessage ;
64import io .contract_testing .contractcase .client .InternalVerifierClient ;
75import io .contract_testing .contractcase .client .MaintainerLog ;
6+ import io .contract_testing .contractcase .edge .ConnectorExceptionMapper ;
7+ import io .contract_testing .contractcase .edge .ConnectorFailure ;
8+ import io .contract_testing .contractcase .edge .ConnectorFailureKindConstants ;
9+ import io .contract_testing .contractcase .edge .ConnectorResult ;
10+ import io .contract_testing .contractcase .edge .ConnectorResultTypeConstants ;
11+ import io .contract_testing .contractcase .edge .InvokeCoreTest ;
12+ import io .contract_testing .contractcase .edge .RunTestCallback ;
13+ import java .util .ArrayList ;
814import java .util .List ;
915import org .jetbrains .annotations .NotNull ;
1016
1117public class ContractVerifier {
1218
1319 private final InternalVerifierClient verifier ;
1420
21+ private final List <ConnectorFailure > failures = new ArrayList <>();
22+
1523 public ContractVerifier (ContractCaseConfig config ) {
1624 LogPrinter logPrinter = new LogPrinter ();
1725
@@ -20,22 +28,51 @@ public ContractVerifier(ContractCaseConfig config) {
2028 verification = new InternalVerifierClient (
2129 BoundaryConfigMapper .map (config , "VERIFICATION" ),
2230 // TODO: Move the runTestCallback into the internals, maybe?
23- new IRunTestCallback () {
31+ new RunTestCallback () {
2432 @ Override
25- public @ NotNull BoundaryResult runTest (@ NotNull String testName ,
26- @ NotNull IInvokeCoreTest invoker ) {
33+ public @ NotNull ConnectorResult runTest (@ NotNull String testName ,
34+ @ NotNull InvokeCoreTest invoker ) {
2735 // TODO replace this with something that knows about JUnit
2836 try {
29- MaintainerLog .log ("Invoking verifier" );
37+ MaintainerLog .log ("Invoking verifier for: " + testName );
3038 var result = invoker .verify ();
31- MaintainerLog .log ("Verifier result was: " + result );
39+
40+ // TODO: Replace this with something that knows what to do with these results
41+ if (result .getResultType ().equals (ConnectorResultTypeConstants .RESULT_SUCCESS )) {
42+ MaintainerLog .log ("" );
43+ MaintainerLog .log ("[SUCCESS] " + testName );
44+ MaintainerLog .log ("" );
45+
46+ } else {
47+ var failure = ((ConnectorFailure ) result );
48+ failures .add (failure );
49+ var kind = failure .getKind ();
50+ if (kind .equals (ConnectorFailureKindConstants .CASE_CORE_ERROR )) {
51+ System .err .println (
52+ BoundaryCrashMessage .CRASH_MESSAGE_START
53+ + "\n \n "
54+ + failure .getMessage ()
55+ + "\n "
56+ + failure .getLocation ()
57+ + "\n \n "
58+ + BoundaryCrashMessage .CRASH_MESSAGE_END );
59+ } else if (kind .equals (ConnectorFailureKindConstants .CASE_CONFIGURATION_ERROR )) {
60+ MaintainerLog .log ("" );
61+ MaintainerLog .log ("[CONFIGURATION ERROR] " + failure .getMessage ());
62+ MaintainerLog .log ("" );
63+ } else {
64+ MaintainerLog .log ("" );
65+ MaintainerLog .log ("[OTHER ERROR] " + failure .getMessage ());
66+ MaintainerLog .log ("" );
67+ }
68+ }
3269 return result ;
3370 } catch (Exception e ) {
34- return BoundaryExceptionMapper .map (e );
71+ return ConnectorExceptionMapper .map (e );
3572 }
3673 }
3774
38- }, logPrinter , logPrinter , new BoundaryVersionGenerator ().getVersions ()
75+ }, logPrinter , new BoundaryVersionGenerator ().getVersions ()
3976 );
4077 } catch (Throwable e ) {
4178 BoundaryCrashReporter .handleAndRethrow (e );
@@ -60,5 +97,13 @@ public void runVerification(ContractCaseConfig configOverrides) {
6097 } catch (Throwable e ) {
6198 BoundaryCrashReporter .handleAndRethrow (e );
6299 }
100+ if (!failures .isEmpty ()) {
101+ try {
102+ BoundaryResultMapper .mapVoid (ConnectorResult .toBoundaryResult (failures .get (0 )));
103+ } catch (Throwable e ) {
104+ BoundaryCrashReporter .handleAndRethrow (e );
105+ }
106+
107+ }
63108 }
64109}
0 commit comments