@@ -202,7 +202,6 @@ public void createApplication() {
202202
203203 } catch (AppException appException ) {
204204 appException .printStackTrace ();
205- //Assert.fail("unable to create application", appException);
206205 }
207206 }
208207
@@ -359,6 +358,63 @@ public void searchForExistingCredentialNull() {
359358 Assert .assertFalse (optionalClientAppCredential .isPresent ());
360359 }
361360
361+ @ Test
362+ public void getCredentialsToDeleteRemovesMissingApiKey () {
363+ ClientApplication actualApp = new ClientApplication ();
364+ actualApp .setId ("app-id" );
365+ APIKey actualApiKey = new APIKey ();
366+ actualApiKey .setApiKey ("api-key-1" );
367+ OAuth actualOAuth = new OAuth ();
368+ actualOAuth .setClientId ("oauth-client-1" );
369+ actualApp .setCredentials (List .of (actualApiKey , actualOAuth ));
370+
371+ ClientApplication desiredApp = new ClientApplication ();
372+ desiredApp .setId ("app-id" );
373+ OAuth desiredOAuth = new OAuth ();
374+ desiredOAuth .setClientId ("oauth-client-1" );
375+ desiredApp .setCredentials (List .of (desiredOAuth ));
376+
377+ List <ClientAppCredential > credentials2Delete = clientAppAdapter .getCredentialsToDelete (desiredApp , actualApp );
378+ Assert .assertEquals (credentials2Delete .size (), 1 );
379+ Assert .assertTrue (credentials2Delete .get (0 ) instanceof APIKey );
380+ }
381+
382+ @ Test
383+ public void getCredentialsToDeleteSkipsCredentialUpdate () {
384+ ClientApplication actualApp = new ClientApplication ();
385+ actualApp .setId ("app-id" );
386+ OAuth actualOAuth = new OAuth ();
387+ actualOAuth .setClientId ("oauth-client-1" );
388+ actualOAuth .setType ("public" );
389+ actualApp .setCredentials (List .of (actualOAuth ));
390+
391+ ClientApplication desiredApp = new ClientApplication ();
392+ desiredApp .setId ("app-id" );
393+ OAuth desiredOAuth = new OAuth ();
394+ desiredOAuth .setClientId ("oauth-client-1" );
395+ desiredOAuth .setType ("confidential" );
396+ desiredApp .setCredentials (List .of (desiredOAuth ));
397+
398+ List <ClientAppCredential > credentials2Delete = clientAppAdapter .getCredentialsToDelete (desiredApp , actualApp );
399+ Assert .assertTrue (credentials2Delete .isEmpty ());
400+ }
401+
402+ @ Test
403+ public void getCredentialDeleteEndpoint () throws AppException {
404+ OAuth oauth = new OAuth ();
405+ oauth .setClientId ("oauth-client-1" );
406+ Assert .assertEquals (clientAppAdapter .getCredentialDeleteEndpoint (oauth ), "oauth/oauth-client-1" );
407+
408+ ExtClients extClients = new ExtClients ();
409+ extClients .setId ("ext-id-1" );
410+ extClients .setClientId ("external-client-1" );
411+ Assert .assertEquals (clientAppAdapter .getCredentialDeleteEndpoint (extClients ), "extclients/ext-id-1" );
412+
413+ APIKey apiKey = new APIKey ();
414+ apiKey .setApiKey ("api-key-1" );
415+ Assert .assertEquals (clientAppAdapter .getCredentialDeleteEndpoint (apiKey ), "apikeys/api-key-1" );
416+ }
417+
362418 @ Test
363419 public void copyClientAppCredential () {
364420 ClientAppCredential clientAppCredential = new ExtClients ();
0 commit comments