PolicyErrorResponseAdapter extends AbstractErrorResponseAdapter<PolicyErrorResponse> implements PolicyAdapter<PolicyErrorResponse> { public static PolicyErrorResponseAdapter of(final HeaderTranslator headerTranslator, final ErrorRegistry<DittoRuntimeException> errorRegistry) { return new PolicyErrorResponseAdapter(requireNonNull(headerTranslator), errorRegistry); } private  PolicyErrorResponseAdapter(final HeaderTranslator headerTranslator,
            final ErrorRegistry<DittoRuntimeException> errorRegistry); static PolicyErrorResponseAdapter of(final HeaderTranslator headerTranslator,
            final ErrorRegistry<DittoRuntimeException> errorRegistry); @Override TopicPathBuilder getTopicPathBuilder(final PolicyErrorResponse errorResponse); @Override PolicyErrorResponse buildErrorResponse(final TopicPath topicPath, final DittoRuntimeException exception,
            final DittoHeaders dittoHeaders);  }
@Test public void testFromAdaptable() { final PolicyErrorResponse expected = PolicyErrorResponse.of(TestConstants.Policies.POLICY_ID, dittoRuntimeException); final TopicPath topicPath = TopicPath.newBuilder(TestConstants.Policies.POLICY_ID).policies().none().errors().build(); final JsonPointer path = JsonPointer.empty(); final Adaptable adaptable = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path) .withValue(dittoRuntimeException.toJson(FieldType.regularOrSpecial())) .build()) .withHeaders(TestConstants.HEADERS_V_2) .build(); final PolicyErrorResponse actual = underTest.fromAdaptable(adaptable); assertWithExternalHeadersThat(actual).isEqualTo(expected); }
@Test public void testToAdaptable() { final PolicyErrorResponse policyErrorResponse = PolicyErrorResponse.of(TestConstants.Policies.POLICY_ID, dittoRuntimeException); final TopicPath topicPath = TopicPath.newBuilder(TestConstants.Policies.POLICY_ID).policies().none().errors().build(); final JsonPointer path = JsonPointer.empty(); final Adaptable expected = Adaptable.newBuilder(topicPath) .withPayload(Payload.newBuilder(path) .withValue(dittoRuntimeException.toJson(FieldType.regularOrSpecial())) .withStatus(HttpStatusCode.UNAUTHORIZED) .build()) .withHeaders(TestConstants.HEADERS_V_2) .build(); final Adaptable actual = underTest.toAdaptable(policyErrorResponse, TopicPath.Channel.NONE); assertWithExternalHeadersThat(actual).isEqualTo(expected); }