@Test public void ambryIdConverterTest() throws Exception { Properties properties = new Properties(); VerifiableProperties verifiableProperties = new VerifiableProperties(properties); IdSigningService idSigningService = mock(IdSigningService.class); AmbryIdConverterFactory ambryIdConverterFactory = new AmbryIdConverterFactory(verifiableProperties, new MetricRegistry(), idSigningService); IdConverter idConverter = ambryIdConverterFactory.getIdConverter(); assertNotNull("No IdConverter returned", idConverter); String input = TestUtils.getRandomString(10); String inputWithLeadingSlash = "/" + input; reset(idSigningService); testConversion(idConverter, RestMethod.GET, null, input, input); verify(idSigningService, never()).parseSignedId(any()); reset(idSigningService); testConversion(idConverter, RestMethod.GET, null, input, inputWithLeadingSlash); verify(idSigningService, never()).parseSignedId(any()); String idFromParsedSignedId = "parsedId" + input; reset(idSigningService); when(idSigningService.isIdSigned(any())).thenReturn(true); when(idSigningService.parseSignedId(any())).thenReturn(new Pair<>(idFromParsedSignedId, Collections.emptyMap())); testConversion(idConverter, RestMethod.GET, null, idFromParsedSignedId, inputWithLeadingSlash); verify(idSigningService).parseSignedId(input); reset(idSigningService); when(idSigningService.isIdSigned(any())).thenReturn(true); when(idSigningService.parseSignedId(any())).thenThrow( new RestServiceException("expected", RestServiceErrorCode.InternalServerError)); testConversionFailure(idConverter, new MockRestRequest(MockRestRequest.DUMMY_DATA, null), input, RestServiceErrorCode.InternalServerError); verify(idSigningService).parseSignedId(input); reset(idSigningService); testConversion(idConverter, RestMethod.POST, null, inputWithLeadingSlash, input); verify(idSigningService, never()).getSignedId(any(), any()); String signedId = "signedId/" + input; reset(idSigningService); when(idSigningService.getSignedId(any(), any())).thenReturn(signedId); Map<String, String> signedIdMetadata = Collections.singletonMap("test-key", "test-value"); testConversion(idConverter, RestMethod.POST, signedIdMetadata, "/" + signedId, input); verify(idSigningService).getSignedId(input, signedIdMetadata); idConverter.close(); testConversionFailure(idConverter, new MockRestRequest(MockRestRequest.DUMMY_DATA, null), input, RestServiceErrorCode.ServiceUnavailable); }
@Override public IdConverter getIdConverter() { return new AmbryIdConverter(idSigningService, frontendMetrics); }
AmbryIdConverterFactory implements IdConverterFactory { @Override public IdConverter getIdConverter() { return new AmbryIdConverter(idSigningService, frontendMetrics); } }
AmbryIdConverterFactory implements IdConverterFactory { @Override public IdConverter getIdConverter() { return new AmbryIdConverter(idSigningService, frontendMetrics); } AmbryIdConverterFactory(VerifiableProperties verifiableProperties, MetricRegistry metricRegistry,
      IdSigningService idSigningService); }
AmbryIdConverterFactory implements IdConverterFactory { @Override public IdConverter getIdConverter() { return new AmbryIdConverter(idSigningService, frontendMetrics); } AmbryIdConverterFactory(VerifiableProperties verifiableProperties, MetricRegistry metricRegistry,
      IdSigningService idSigningService); @Override IdConverter getIdConverter(); }
AmbryIdConverterFactory implements IdConverterFactory { @Override public IdConverter getIdConverter() { return new AmbryIdConverter(idSigningService, frontendMetrics); } AmbryIdConverterFactory(VerifiableProperties verifiableProperties, MetricRegistry metricRegistry,
      IdSigningService idSigningService); @Override IdConverter getIdConverter();  }