### Question:
ClientRegistrationFilter implements Filter { @Override public Promise<Response, NeverThrowsException> filter(Context context, Request request, Handler next) { try { AttributesContext attributesContext = context.asContext(AttributesContext.class); final Issuer issuer = (Issuer) attributesContext.getAttributes().get(ISSUER_KEY); if (issuer != null) { ClientRegistration cr = heap.get(issuer.getName() + suffix, ClientRegistration.class); if (cr == null) { if (!config.isDefined("redirect_uris")) { throw new RegistrationException( "Cannot perform dynamic registration: 'redirect_uris' should be defined"); } if (issuer.getRegistrationEndpoint() == null) { throw new RegistrationException(format("Registration is not supported by the issuer '%s'", issuer)); } final JsonValue registeredClientConfiguration = performDynamicClientRegistration(context, config, issuer.getRegistrationEndpoint()); cr = heap.resolve( createClientRegistrationDeclaration(registeredClientConfiguration, issuer.getName()), ClientRegistration.class); } attributesContext.getAttributes().put(CLIENT_REG_KEY, cr); } else { throw new RegistrationException("Cannot retrieve issuer from the context"); } } catch (RegistrationException e) { return newResultPromise(newInternalServerError(e)); } catch (HeapException e) { return newResultPromise( newInternalServerError("Cannot inject inlined Client Registration declaration to heap", e)); } return next.handle(context, request); } ClientRegistrationFilter(final Handler registrationHandler,
                                    final JsonValue config,
                                    final Heap heap,
                                    final String suffix); @Override Promise<Response, NeverThrowsException> filter(Context context,
                                                          Request request,
                                                          Handler next);  }### Answer:
@Test public void shouldFailToPerformDynamicRegistrationWhenMissingRedirectUris() throws Exception { final JsonValue invalidConfig = json(object( field("contact", array("ve7jtb@example.org", "bjensen@example.org")), field("scopes", array("openid")))); attributesContext.getAttributes().put(ISSUER_KEY, new Issuer("myIssuer", issuerConfigWithAllRequestedEndpoints())); final Heap heap = mock(Heap.class); when(heap.get("myIssuer" + SUFFIX, ClientRegistration.class)).thenReturn(null); final ClientRegistrationFilter crf = new ClientRegistrationFilter(handler, invalidConfig, heap, SUFFIX); final Response response = crf.filter(context, new Request(), handler).get(); assertThat(response.getStatus()).isEqualTo(INTERNAL_SERVER_ERROR); assertThat(response.getEntity().getString()).contains("'redirect_uris' should be defined"); }
@Test public void shouldFailToPerformDynamicRegistrationWhenIssuerHasNoRegistrationEndpoint() throws Exception { attributesContext.getAttributes().put(ISSUER_KEY, new Issuer("myIssuer", issuerConfigWithNoRegistrationEndpoint())); final Heap heap = mock(Heap.class); when(heap.get("myIssuer" + SUFFIX, ClientRegistration.class)).thenReturn(null); final ClientRegistrationFilter crf = new ClientRegistrationFilter(handler, getMetadata(), heap, SUFFIX); final Response response = crf.filter(context, new Request(), handler).get(); assertThat(response.getStatus()).isEqualTo(INTERNAL_SERVER_ERROR); assertThat(response.getEntity().getString()).contains("Registration is not supported by the issuer"); }