66
66
import software .amazon .smithy .utils .IoUtils ;
67
67
import software .amazon .smithy .utils .MapUtils ;
68
68
import software .amazon .smithy .utils .Pair ;
69
- import software .amazon .smithy .utils .StringUtils ;
70
69
71
70
/**
72
71
* Generates HTTP protocol test cases to be run using Jest.
@@ -91,6 +90,7 @@ final class HttpProtocolTestGenerator implements Runnable {
91
90
private final ServiceShape service ;
92
91
private final SymbolProvider symbolProvider ;
93
92
private final Symbol serviceSymbol ;
93
+ private final SymbolProvider serverSymbolProvider ;
94
94
private final Set <String > additionalStubs = new TreeSet <>();
95
95
private final ProtocolGenerator protocolGenerator ;
96
96
@@ -105,6 +105,7 @@ final class HttpProtocolTestGenerator implements Runnable {
105
105
Model model ,
106
106
ShapeId protocol ,
107
107
SymbolProvider symbolProvider ,
108
+ SymbolProvider serverSymbolProvider ,
108
109
TypeScriptDelegator delegator ,
109
110
ProtocolGenerator protocolGenerator
110
111
) {
@@ -113,6 +114,7 @@ final class HttpProtocolTestGenerator implements Runnable {
113
114
this .protocol = protocol ;
114
115
this .service = settings .getService (model );
115
116
this .symbolProvider = symbolProvider ;
117
+ this .serverSymbolProvider = serverSymbolProvider ;
116
118
this .delegator = delegator ;
117
119
this .protocolGenerator = protocolGenerator ;
118
120
serviceSymbol = symbolProvider .toSymbol (service );
@@ -247,7 +249,7 @@ private void generateClientRequestTest(OperationShape operation, HttpRequestTest
247
249
}
248
250
249
251
private void generateServerRequestTest (OperationShape operation , HttpRequestTestCase testCase ) {
250
- Symbol operationSymbol = symbolProvider .toSymbol (operation );
252
+ Symbol operationSymbol = serverSymbolProvider .toSymbol (operation );
251
253
252
254
// Lowercase all the headers we're expecting as this is what we'll get.
253
255
Map <String , String > headers = testCase .getHeaders ().entrySet ().stream ()
@@ -260,9 +262,8 @@ private void generateServerRequestTest(OperationShape operation, HttpRequestTest
260
262
String testName = testCase .getId () + ":ServerRequest" ;
261
263
testCase .getDocumentation ().ifPresent (writer ::writeDocs );
262
264
writer .openBlock ("it($S, async () => {" , "});\n " , testName , () -> {
263
- // TODO: use the symbol provider when it's ready
264
- String serviceName = StringUtils .capitalize (service .getId ().getName ());
265
- String operationName = StringUtils .capitalize (operation .getId ().getName ());
265
+ Symbol serviceSymbol = serverSymbolProvider .toSymbol (service );
266
+ Symbol handlerSymbol = serviceSymbol .expectProperty ("handler" , Symbol .class );
266
267
Symbol inputType = operationSymbol .expectProperty ("inputType" , Symbol .class );
267
268
Symbol outputType = operationSymbol .expectProperty ("outputType" , Symbol .class );
268
269
@@ -274,18 +275,18 @@ private void generateServerRequestTest(OperationShape operation, HttpRequestTest
274
275
// We use a partial here so that we don't have to define the entire service, but still get the advantages
275
276
// the type checker, including excess property checking. Later on we'll use `as` to cast this to the
276
277
// full service so that we can actually use it.
277
- writer .addImport (serviceName + "Service" , null , "./server" );
278
- writer .openBlock ("const testService: Partial<$LService> = {" , "};" , serviceName , () -> {
278
+ writer .openBlock ("const testService: Partial<$T> = {" , "};" , serviceSymbol , () -> {
279
279
writer .addImport ("Operation" , "__Operation" , "@aws-smithy/server-common" );
280
- writer .write ("$L: testFunction as __Operation<$T, $T>," , operationName , inputType , outputType );
280
+ writer .write ("$L: testFunction as __Operation<$T, $T>," ,
281
+ operationSymbol .getName (), inputType , outputType );
281
282
});
282
283
283
- String getHandlerName = String . format ( "get%sServiceHandler" , serviceName );
284
+ String getHandlerName = "get" + handlerSymbol . getName ( );
284
285
writer .addImport (getHandlerName , getHandlerName ,
285
286
"./protocols/" + ProtocolGenerator .getSanitizedName (protocolGenerator .getName ()));
286
287
287
288
// Cast the service as any so TS will ignore the fact that the type being passed in is incomplete.
288
- writer .write ("const handler = $L(testService as $LService );" , getHandlerName , serviceName );
289
+ writer .write ("const handler = $L(testService as $T );" , getHandlerName , serviceSymbol );
289
290
290
291
// Construct a new http request according to the test case definition.
291
292
writer .openBlock ("const request = new HttpRequest({" , "});" , () -> {
0 commit comments