McpTestSuite.java
8.03 KB
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/*
* This software is in the public domain under CC0 1.0 Universal plus a
* Grant of Patent License.
*
* To the extent possible under law, author(s) have dedicated all
* copyright and related and neighboring rights to this software to the
* public domain worldwide. This software is distributed without any
* warranty.
*
* You should have received a copy of the CC0 Public Domain Dedication
* along with this software (see the LICENSE.md file). If not, see
* <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
package org.moqui.mcp.test;
import java.util.Properties
import java.io.FileInputStream
import java.io.File
/**
* MCP Test Suite - Main test runner
* Runs all MCP tests in a deterministic way
*/
class McpTestSuite {
private Properties config
private McpJavaClient client
McpTestSuite() {
loadConfiguration()
this.client = new McpJavaClient(
config.getProperty("test.mcp.url", "http://localhost:8080/mcp"),
config.getProperty("test.user", "john.sales"),
config.getProperty("test.password", "opencode")
)
}
/**
* Load test configuration
*/
void loadConfiguration() {
config = new Properties()
try {
def configFile = new File("test/resources/test-config.properties")
if (configFile.exists()) {
config.load(new FileInputStream(configFile))
println "📋 Loaded configuration from test-config.properties"
} else {
println "⚠️ Configuration file not found, using defaults"
setDefaultConfiguration()
}
} catch (Exception e) {
println "⚠️ Error loading configuration: ${e.message}"
setDefaultConfiguration()
}
}
/**
* Set default configuration values
*/
void setDefaultConfiguration() {
config.setProperty("test.user", "john.sales")
config.setProperty("test.password", "opencode")
config.setProperty("test.mcp.url", "http://localhost:8080/mcp")
config.setProperty("test.customer.firstName", "John")
config.setProperty("test.customer.lastName", "Doe")
config.setProperty("test.product.color", "blue")
config.setProperty("test.product.category", "PopCommerce")
}
/**
* Run all tests
*/
boolean runAllTests() {
println "🧪 MCP TEST SUITE"
println "=================="
println "Configuration:"
println " URL: ${config.getProperty("test.mcp.url")}"
println " User: ${config.getProperty("test.user")}"
println " Customer: ${config.getProperty("test.customer.firstName")} ${config.getProperty("test.customer.lastName")}"
println " Product Color: ${config.getProperty("test.product.color")}"
println ""
def startTime = System.currentTimeMillis()
def results = [:]
try {
// Initialize client
if (!client.initialize()) {
println "❌ Failed to initialize MCP client"
return false
}
// Run screen infrastructure tests
println "\n" + "="*50
println "SCREEN INFRASTRUCTURE TESTS"
println "="*50
def infraTest = new ScreenInfrastructureTest(client)
results.infrastructure = infraTest.runAllTests()
// Run catalog screen tests
println "\n" + "="*50
println "CATALOG SCREEN TESTS"
println "="*50
def catalogTest = new CatalogScreenTest(client)
results.catalog = catalogTest.runAllTests()
// Run PopCommerce workflow tests
println "\n" + "="*50
println "POPCOMMERCE WORKFLOW TESTS"
println "="*50
def workflowTest = new PopCommerceOrderTest(client)
results.workflow = workflowTest.runCompleteTest()
// Generate combined report
def endTime = System.currentTimeMillis()
def duration = endTime - startTime
generateCombinedReport(results, duration)
return results.infrastructure && results.catalog && results.workflow
} finally {
client.close()
}
}
/**
* Generate combined test report
*/
void generateCombinedReport(Map results, long duration) {
println "\n" + "="*60
println "📋 MCP TEST SUITE REPORT"
println "="*60
println "Duration: ${duration}ms (${Math.round(duration/1000)}s)"
println ""
def totalTests = results.size()
def passedTests = results.count { it.value }
results.each { testName, result ->
println "${result ? '✅' : '❌'} ${testName.toUpperCase()}: ${result ? 'PASSED' : 'FAILED'}"
}
println ""
println "Overall Result: ${passedTests}/${totalTests} test suites passed"
println "Success Rate: ${Math.round(passedTests/totalTests * 100)}%"
if (passedTests == totalTests) {
println "\n🎉 ALL TESTS PASSED! MCP screen infrastructure is working correctly."
} else {
println "\n⚠️ Some tests failed. Check the output above for details."
}
println "\n" + "="*60
}
/**
* Run individual test suites
*/
boolean runInfrastructureTests() {
try {
if (!client.initialize()) {
println "❌ Failed to initialize MCP client"
return false
}
def test = new ScreenInfrastructureTest(client)
return test.runAllTests()
} finally {
client.close()
}
}
boolean runWorkflowTests() {
try {
if (!client.initialize()) {
println "❌ Failed to initialize MCP client"
return false
}
def test = new PopCommerceOrderTest(client)
return test.runCompleteTest()
} finally {
client.close()
}
}
/**
* Main method with command line arguments
*/
static void main(String[] args) {
def suite = new McpTestSuite()
if (args.length == 0) {
// Run all tests
def success = suite.runAllTests()
System.exit(success ? 0 : 1)
} else {
// Run specific test suite
def testType = args[0].toLowerCase()
def success = false
switch (testType) {
case "infrastructure":
case "infra":
success = suite.runInfrastructureTests()
break
case "workflow":
case "popcommerce":
success = suite.runWorkflowTests()
break
case "help":
case "-h":
case "--help":
printUsage()
return
default:
println "❌ Unknown test type: ${testType}"
printUsage()
System.exit(1)
}
System.exit(success ? 0 : 1)
}
}
/**
* Print usage information
*/
static void printUsage() {
println "Usage: java McpTestSuite [test_type]"
println ""
println "Test types:"
println " infrastructure, infra - Run screen infrastructure tests only"
println " workflow, popcommerce - Run PopCommerce workflow tests only"
println " (no argument) - Run all tests"
println ""
println "Examples:"
println " java McpTestSuite"
println " java McpTestSuite infrastructure"
println " java McpTestSuite workflow"
}
}