MfaProviderEndpoints implements ApplicationEventPublisherAware { @RequestMapping(value = "{id}", method = DELETE) public ResponseEntity<MfaProvider> deleteMfaProviderById(@PathVariable String id) { MfaProvider existing = mfaProviderProvisioning.retrieve(id, IdentityZoneHolder.get().getId()); MfaConfig currentMfaConfig = IdentityZoneHolder.get().getConfig().getMfaConfig(); if(currentMfaConfig.isEnabled() && currentMfaConfig.getProviderName().equals(existing.getName())) { throw new MfaAlreadyExistsException("MFA provider is currently active on zone: " + IdentityZoneHolder.get().getId() + ". Please deactivate it from the zone or set another MFA provider"); } publisher.publishEvent(new EntityDeletedEvent<>(existing, SecurityContextHolder.getContext().getAuthentication(), IdentityZoneHolder.getCurrentZoneId())); return new ResponseEntity<>(existing, HttpStatus.OK); }  @Override void setApplicationEventPublisher(ApplicationEventPublisher publisher); @RequestMapping(method = POST) ResponseEntity<MfaProvider> createMfaProvider(@RequestBody MfaProvider body); @RequestMapping(value = "{id}", method = PUT) ResponseEntity<MfaProvider> updateMfaProvider(); @RequestMapping(method = GET) ResponseEntity<List<MfaProvider>> retrieveMfaProviders(); @RequestMapping(value = "{id}", method = GET) ResponseEntity<MfaProvider> retrieveMfaProviderById(@PathVariable String id); @RequestMapping(value = "{id}", method = DELETE) ResponseEntity<MfaProvider> deleteMfaProviderById(@PathVariable String id); @ExceptionHandler(InvalidMfaProviderException.class) ResponseEntity<InvalidMfaProviderException> handleInvalidMfaProviderException(InvalidMfaProviderException e); @ExceptionHandler(MfaAlreadyExistsException.class) ResponseEntity<InvalidMfaProviderException> handleInvalidMfaProviderException(MfaAlreadyExistsException e); @ExceptionHandler(EmptyResultDataAccessException.class) ResponseEntity<EmptyResultDataAccessException> handleEmptyResultDataAccessException(EmptyResultDataAccessException e); @ExceptionHandler(MfaProviderUpdateIsNotAllowed.class) ResponseEntity<MfaProviderUpdateIsNotAllowed> handleMfaUpdatingNameOfActiveProvider(MfaProviderUpdateIsNotAllowed e); MfaProviderProvisioning getMfaProviderProvisioning(); void setMfaProviderProvisioning(MfaProviderProvisioning mfaProviderProvisioning); void setMfaProviderValidator(MfaProviderValidator mfaProviderValidator);  }
@Test public void testDeleteActiveProviderThrowsException() { MfaProvider<GoogleMfaProviderConfig> providerToDelete = constructGoogleProvider(); String id = new RandomValueStringGenerator(5).generate(); when(provisioning.retrieve(eq(id), anyString())).thenReturn(providerToDelete); IdentityZoneHolder.get().getConfig().getMfaConfig().setEnabled(true).setProviderName(providerToDelete.getName()); expection.expect(MfaAlreadyExistsException.class); expection.expectMessage("MFA provider is currently active on zone: " + IdentityZoneHolder.get().getId() + ". Please deactivate it from the zone or set another MFA provider"); endpoint.deleteMfaProviderById(id); IdentityZoneHolder.get().getConfig().getMfaConfig().setProviderName(null); }