### Question:
SkOCSPDataLoader extends SkDataLoader { @Override protected ServiceType getServiceType() { return isAiaOcsp ? ServiceType.AIA_OCSP : ServiceType.OCSP; } SkOCSPDataLoader(Configuration configuration); void setAsAiaOcsp(boolean isAiaOcsp);  }### Answer:
@Test public void getServiceType() { SkOCSPDataLoader dataLoader = new SkOCSPDataLoader(Configuration.of(TEST)); assertSame(ServiceType.OCSP, dataLoader.getServiceType()); }
@Test public void successfulResponseFromOCSPService() { instanceRule.stubFor(post("/").withHeader("User-Agent", equalTo(USER_AGENT_STRING)) .willReturn(WireMock.aResponse().withStatus(200).withBody(new byte[] {0, 1, 2, 3}))); ServiceAccessListener listener = Mockito.mock(ServiceAccessListener.class); SkOCSPDataLoader dataLoader = new SkOCSPDataLoader(Configuration.of(TEST)); dataLoader.setUserAgent(USER_AGENT_STRING); String serviceUrl = MOCK_PROXY_URL + instanceRule.port() + "/"; try (ServiceAccessScope scope = new ServiceAccessScope(listener)) { byte[] response = dataLoader.post(serviceUrl, new byte[] {1}); assertArrayEquals(new byte[] {0, 1, 2, 3}, response); } ServiceAccessEvent capturedEvent = verifyAndCaptureServiceAccessEvent(listener); assertEquals(MOCK_PROXY_URL + instanceRule.port() + "/", capturedEvent.getServiceUrl()); assertEquals(ServiceType.OCSP, capturedEvent.getServiceType()); assertTrue(capturedEvent.isSuccess()); }
@Test public void accessDeniedToOCSPService() { instanceRule.stubFor(post("/").withHeader("User-Agent", equalTo(USER_AGENT_STRING)) .willReturn(WireMock.aResponse().withStatus(403))); ServiceAccessListener listener = Mockito.mock(ServiceAccessListener.class); SkOCSPDataLoader dataLoader = new SkOCSPDataLoader(Configuration.of(TEST)); dataLoader.setUserAgent(USER_AGENT_STRING); String serviceUrl = MOCK_PROXY_URL + instanceRule.port() + "/"; try (ServiceAccessScope scope = new ServiceAccessScope(listener)) { dataLoader.post(serviceUrl, new byte[] {1}); fail("Expected to throw ServiceAccessDeniedException"); } catch (ServiceAccessDeniedException e) { assertSame(ServiceType.OCSP, e.getServiceType()); assertEquals("Access denied to OCSP service <" + serviceUrl + ">", e.getMessage()); } ServiceAccessEvent capturedEvent = verifyAndCaptureServiceAccessEvent(listener); assertEquals(MOCK_PROXY_URL + instanceRule.port() + "/", capturedEvent.getServiceUrl()); assertEquals(ServiceType.OCSP, capturedEvent.getServiceType()); assertFalse(capturedEvent.isSuccess()); }
@Test public void connectionToOCSPServiceTimedOut() { instanceRule.stubFor(post("/").withHeader("User-Agent", equalTo(USER_AGENT_STRING)) .willReturn(WireMock.aResponse().withFixedDelay(200))); ServiceAccessListener listener = Mockito.mock(ServiceAccessListener.class); SkOCSPDataLoader dataLoader = new SkOCSPDataLoader(Configuration.of(TEST)); dataLoader.setTimeoutSocket(100); dataLoader.setUserAgent(USER_AGENT_STRING); String serviceUrl = MOCK_PROXY_URL + instanceRule.port() + "/"; try (ServiceAccessScope scope = new ServiceAccessScope(listener)) { dataLoader.post(serviceUrl, new byte[] {1}); fail("Expected to throw ConnectionTimedOutException"); } catch (ConnectionTimedOutException e) { assertSame(ServiceType.OCSP, e.getServiceType()); assertEquals("Connection to OCSP service <" + serviceUrl + "> timed out", e.getMessage()); } ServiceAccessEvent capturedEvent = verifyAndCaptureServiceAccessEvent(listener); assertEquals(MOCK_PROXY_URL + instanceRule.port() + "/", capturedEvent.getServiceUrl()); assertEquals(ServiceType.OCSP, capturedEvent.getServiceType()); assertFalse(capturedEvent.isSuccess()); }