@@ -377,6 +377,140 @@ public void testItCanHandleCastlabsErrorsWhileLinkingAnAccountToASubMerchant() t
377377mockServerClient .verify (expectedRequest ,VerificationTimes .once ());
378378 }
379379
380+ @ Test
381+ public void testItCanUpdateAuthorizationSettings ()throws Exception {
382+ final String merchantId ="merchX" ;
383+ final HttpRequest expectedRequest =
384+ request ().withMethod ("POST" ).withPath ("/frontend/rest/config/v1/" +merchantId +"/auth/settings" )
385+ .withQueryStringParameter ("ticket" ,exampleTicket )
386+ .withHeader ("accept" ,"application/json" )
387+ .withHeader ("content-type" ,"application/json" );
388+ mockServerClient .when (expectedRequest ).respond (response ().withStatusCode (200 ));
389+ UpdateAuthorizationSettingsRequest request =new UpdateAuthorizationSettingsRequest ();
390+ request .setMode ("UPFRONT" );
391+
392+ // Castlabs doesn't return any response body, so we're effectively asserting "No Exception" here
393+ castlabsClient .updateAuthorizationSettings (request ,"merchX" );
394+
395+ mockServerClient .verify (expectedRequest ,VerificationTimes .once ());
396+ }
397+
398+ @ Test
399+ public void testItCanHandleCastlabsErrorsWhileUpdatingAuthorizationSetting ()throws Exception {
400+ final String merchantId ="merchX" ;
401+ final HttpRequest expectedRequest =
402+ request ().withMethod ("POST" ).withPath ("/frontend/rest/config/v1/" +merchantId +"/auth/settings" )
403+ .withQueryStringParameter ("ticket" ,exampleTicket )
404+ .withHeader ("accept" ,"application/json" )
405+ .withHeader ("content-type" ,"application/json" );
406+ mockServerClient .when (expectedRequest ).respond (response ().withStatusCode (418 ).withBody ("I'm a teapot" ));
407+ UpdateAuthorizationSettingsRequest request =new UpdateAuthorizationSettingsRequest ();
408+ request .setMode ("UPFRONT" );
409+
410+ try {
411+ castlabsClient .updateAuthorizationSettings (request ,"merchX" );
412+ fail ("Expected a CastlabsException to be returned" );
413+ }catch (CastlabsException e ) {
414+ assertThat (e .getMessage (),StringContains .containsString ("418" ));
415+ assertThat (e .getMessage (),StringContains .containsString ("I'm a teapot" ));
416+ mockServerClient .verify (expectedRequest ,VerificationTimes .once ());
417+ }
418+
419+ mockServerClient .verify (expectedRequest ,VerificationTimes .once ());
420+ }
421+
422+ @ Test
423+ public void testItCanAddSharedSecret ()throws Exception {
424+ final String merchantId ="merchX" ;
425+ final HttpRequest expectedRequest =
426+ request ().withMethod ("POST" ).withPath ("/frontend/rest/config/v1/" +merchantId +"/upfront/secret/add" )
427+ .withQueryStringParameter ("ticket" ,exampleTicket )
428+ .withHeader ("accept" ,"application/json" )
429+ .withHeader ("content-type" ,"application/json" );
430+ mockServerClient .when (expectedRequest ).respond (response ().withStatusCode (200 ));
431+ SharedSecretRequest request =new SharedSecretRequest ();
432+ request .setEnabled (true );
433+ request .setDescription ("Test Shared Secret" );
434+ request .setSecret ("[shared_secret_bytes]" );
435+
436+ // Castlabs doesn't return any response body, so we're effectively asserting "No Exception" here
437+ castlabsClient .addSharedSecret (request ,"merchX" );
438+
439+ mockServerClient .verify (expectedRequest ,VerificationTimes .once ());
440+ }
441+
442+ @ Test
443+ public void testItCanHandleCastlabsErrorsWhileAddingSharedSecret ()throws Exception {
444+ final String merchantId ="merchX" ;
445+ final HttpRequest expectedRequest =
446+ request ().withMethod ("POST" ).withPath ("/frontend/rest/config/v1/" +merchantId +"/upfront/secret/add" )
447+ .withQueryStringParameter ("ticket" ,exampleTicket )
448+ .withHeader ("accept" ,"application/json" )
449+ .withHeader ("content-type" ,"application/json" );
450+ mockServerClient .when (expectedRequest ).respond (response ().withStatusCode (418 ).withBody ("I'm a teapot" ));
451+ SharedSecretRequest request =new SharedSecretRequest ();
452+ request .setEnabled (true );
453+ request .setDescription ("Test Shared Secret" );
454+ request .setSecret ("[shared_secret_bytes]" );
455+
456+ try {
457+ castlabsClient .addSharedSecret (request ,"merchX" );
458+ fail ("Expected a CastlabsException to be returned" );
459+ }catch (CastlabsException e ) {
460+ assertThat (e .getMessage (),StringContains .containsString ("418" ));
461+ assertThat (e .getMessage (),StringContains .containsString ("I'm a teapot" ));
462+ mockServerClient .verify (expectedRequest ,VerificationTimes .once ());
463+ }
464+
465+ mockServerClient .verify (expectedRequest ,VerificationTimes .once ());
466+ }
467+
468+ @ Test
469+ public void testItCanSetFairplayConfiguration ()throws Exception {
470+ final String merchantId ="merchX" ;
471+ final HttpRequest expectedRequest =
472+ request ().withMethod ("POST" ).withPath ("/frontend/rest/config/v1/" +merchantId +"/drm/fairplay" )
473+ .withQueryStringParameter ("ticket" ,exampleTicket )
474+ .withHeader ("accept" ,"application/json" )
475+ .withHeader ("content-type" ,"application/json" );
476+ mockServerClient .when (expectedRequest ).respond (response ().withStatusCode (200 ));
477+ FairplayRequest request =new FairplayRequest ();
478+ request .setProviderCertificate ("[PEM_encoded_certificate]" );
479+ request .setProviderPrivateKey ("[PEM_encoded_private_key]" );
480+ request .setApplicationSecretKey ("[HEX_encoded_secret_key]" );
481+
482+ // Castlabs doesn't return any response body, so we're effectively asserting "No Exception" here
483+ castlabsClient .setFairplayConfiguration (request ,"merchX" );
484+
485+ mockServerClient .verify (expectedRequest ,VerificationTimes .once ());
486+ }
487+
488+ @ Test
489+ public void testItCanHandleCastlabsErrorsWhileSettingFairplayConfiguration ()throws Exception {
490+ final String merchantId ="merchX" ;
491+ final HttpRequest expectedRequest =
492+ request ().withMethod ("POST" ).withPath ("/frontend/rest/config/v1/" +merchantId +"/drm/fairplay" )
493+ .withQueryStringParameter ("ticket" ,exampleTicket )
494+ .withHeader ("accept" ,"application/json" )
495+ .withHeader ("content-type" ,"application/json" );
496+ mockServerClient .when (expectedRequest ).respond (response ().withStatusCode (418 ).withBody ("I'm a teapot" ));
497+ FairplayRequest request =new FairplayRequest ();
498+ request .setProviderCertificate ("[PEM_encoded_certificate]" );
499+ request .setProviderPrivateKey ("[PEM_encoded_private_key]" );
500+ request .setApplicationSecretKey ("[HEX_encoded_secret_key]" );
501+
502+ try {
503+ castlabsClient .setFairplayConfiguration (request ,"merchX" );
504+ fail ("Expected a CastlabsException to be returned" );
505+ }catch (CastlabsException e ) {
506+ assertThat (e .getMessage (),StringContains .containsString ("418" ));
507+ assertThat (e .getMessage (),StringContains .containsString ("I'm a teapot" ));
508+ mockServerClient .verify (expectedRequest ,VerificationTimes .once ());
509+ }
510+
511+ mockServerClient .verify (expectedRequest ,VerificationTimes .once ());
512+ }
513+
380514private String getTestResourceAsString (String filename )throws IOException {
381515final String path =this .getClass ().getClassLoader ().getResource (filename ).getFile ();
382516return IOUtils .toString (new FileInputStream (path ));