@@ -114,7 +114,11 @@ public static void beforeClass() throws IOException, URISyntaxException, Interru
114114 /** before. */
115115 @ BeforeEach
116116 public void before () {
117+ Map <String , String > map = createEnvironment ();
118+ createHandler (map );
119+ }
117120
121+ private Map <String , String > createEnvironment () {
118122 Map <String , String > map = new HashMap <>();
119123 map .put ("CONSOLE_VERSION" , "0.1" );
120124 map .put ("REGION" , "us-east-1" );
@@ -132,7 +136,10 @@ public void before() {
132136 map .put ("DOMAIN" , "dev" );
133137 map .put ("COGNITO_USER_POOL_ID" , "us-east-2_blGeBpyLg" );
134138 map .put ("COGNITO_USER_POOL_CLIENT_ID" , "7223423m2pfgf34qnfokb2po2l" );
139+ return map ;
140+ }
135141
142+ private void createHandler (final Map <String , String > map ) {
136143 this .handler = new ConsoleInstallHandler (map , s3Connection , s3Connection ) {
137144
138145 @ Override
@@ -185,19 +192,16 @@ public void testHandleRequest01() throws Exception {
185192 this .logger .log ("sending SUCCESS to https://cloudformation-custom-resource" );
186193 this .logger .log ("Request Create was successful!" );
187194
188-
189- // replayAll();
190195 this .handler .handleRequest (input , this .context );
191196
192197 // then
193198 verifySendResponse (contentlength );
194- verifyConfigWritten ();
199+ verifyConfigWritten ("" );
195200 verifyCognitoConfig ();
196201
197202 assertTrue (connection .contains ("\" Status\" :\" SUCCESS\" " ));
198203 assertTrue (connection .contains ("\" Data\" :{\" Message\" :\" Request Create was successful!\" " ));
199204
200-
201205 assertEquals ("font/woff2" ,
202206 s3 .getObjectMetadata (CONSOLE_BUCKET , "0.1/font.woff2" , null ).getContentType ());
203207
@@ -252,7 +256,7 @@ public void testHandleRequest02() throws Exception {
252256
253257 // then
254258 verifySendResponse (contentlength );
255- verifyConfigWritten ();
259+ verifyConfigWritten ("" );
256260 verifyCognitoConfig ();
257261
258262 assertTrue (this .logger .containsString (
@@ -360,18 +364,95 @@ public void testHandleRequest04() throws Exception {
360364 assertTrue (connection .contains ("\" Status\" :\" FAILURE\" " ));
361365 }
362366
367+ /**
368+ * Test Handle Request 'CREATE'.
369+ *
370+ * @throws Exception Exception
371+ */
372+ @ Test
373+ public void testHandleRequest05 () throws Exception {
374+ // given
375+ String cognitoSingleSignOnUrl =
376+ "https://something.auth.us-east-2.amazoncognito.com/oauth2/authorize" ;
377+ Map <String , String > map = createEnvironment ();
378+ map .put ("COGNITO_SINGLE_SIGN_ON_URL" , cognitoSingleSignOnUrl );
379+ createHandler (map );
380+
381+ final int contentlength = 105 ;
382+ Map <String , Object > input = createInput ("Create" );
383+ input .put ("CONSOLE_BUCKET" , CONSOLE_BUCKET );
384+
385+ // when
386+ this .logger .log (
387+ "received input: {ResponseURL=https://cloudformation-custom-resource, RequestType=Create}" );
388+ this .logger .log ("unpacking formkiq-console/0.1/formkiq-console.zip "
389+ + "from bucket distrobucket to bucket destbucket" );
390+ this .logger .log ("sending SUCCESS to https://cloudformation-custom-resource" );
391+ this .logger .log ("Request Create was successful!" );
392+
393+ this .handler .handleRequest (input , this .context );
394+
395+ // then
396+ verifySendResponse (contentlength );
397+ verifyConfigWritten (cognitoSingleSignOnUrl );
398+ verifyCognitoConfig ();
399+
400+ assertTrue (connection .contains ("\" Status\" :\" SUCCESS\" " ));
401+ assertTrue (connection .contains ("\" Data\" :{\" Message\" :\" Request Create was successful!\" " ));
402+
403+ assertEquals ("font/woff2" ,
404+ s3 .getObjectMetadata (CONSOLE_BUCKET , "0.1/font.woff2" , null ).getContentType ());
405+
406+ assertEquals ("text/css" ,
407+ s3 .getObjectMetadata (CONSOLE_BUCKET , "0.1/test.css" , null ).getContentType ());
408+
409+ assertEquals ("application/vnd.ms-fontobject" ,
410+ s3 .getObjectMetadata (CONSOLE_BUCKET , "0.1/test.eot" , null ).getContentType ());
411+
412+ assertEquals ("image/x-icon" ,
413+ s3 .getObjectMetadata (CONSOLE_BUCKET , "0.1/test.ico" , null ).getContentType ());
414+
415+ assertTrue (s3 .getObjectMetadata (CONSOLE_BUCKET , "0.1/test.js" , null ).getContentType ()
416+ .endsWith ("/javascript" ));
417+
418+ assertEquals ("image/svg+xml" ,
419+ s3 .getObjectMetadata (CONSOLE_BUCKET , "0.1/test.svg" , null ).getContentType ());
420+
421+ assertEquals ("font/ttf" ,
422+ s3 .getObjectMetadata (CONSOLE_BUCKET , "0.1/test.ttf" , null ).getContentType ());
423+
424+ assertEquals ("text/plain" ,
425+ s3 .getObjectMetadata (CONSOLE_BUCKET , "0.1/test.txt" , null ).getContentType ());
426+
427+ assertEquals ("font/woff" ,
428+ s3 .getObjectMetadata (CONSOLE_BUCKET , "0.1/test.woff" , null ).getContentType ());
429+
430+ // given
431+ input = createInput ("Delete" );
432+ input .put ("CONSOLE_BUCKET" , CONSOLE_BUCKET );
433+
434+ // when
435+ this .handler .handleRequest (input , this .context );
436+
437+ // then
438+ assertTrue (s3 .listObjects (CONSOLE_BUCKET , null ).contents ().isEmpty ());
439+ }
440+
363441 /**
364442 * Verify Config File is written.
443+ *
444+ * @param cognitoSingleSignOnUrl {@link String}
365445 */
366- private void verifyConfigWritten () {
446+ private void verifyConfigWritten (final String cognitoSingleSignOnUrl ) {
447+
367448 String config = String .format ("{%n"
368449 + " \" documentApi\" : \" https://chartapi.24hourcharts.com.execute-api.us-east-1.amazonaws.com/prod/\" ,%n"
369450 + " \" userPoolId\" : \" us-east-2_blGeBpyLg\" ,%n"
370451 + " \" clientId\" : \" 7223423m2pfgf34qnfokb2po2l\" ,%n" + " \" consoleVersion\" : \" 0.1\" ,%n"
371452 + " \" brand\" : \" 24hourcharts\" ,%n" + " \" userAuthentication\" : \" cognito\" ,%n"
372453 + " \" authApi\" : \" https://auth.execute-api.us-east-1.amazonaws.com/prod/\" ,%n"
373- + " \" cognitoHostedUi\" : \" https://test2111111111111111.auth.us-east-2.amazoncognito.com\" %n"
374- + "}" );
454+ + " \" cognitoHostedUi\" : \" https://test2111111111111111.auth.us-east-2.amazoncognito.com\" , %n"
455+ + " \" cognitoSingleSignOnUrl \" : \" " + cognitoSingleSignOnUrl + " \" %n" + " }" );
375456
376457 assertTrue (this .logger .containsString ("writing Cognito config: " + config ));
377458 }
0 commit comments