### Question:
ProxyConfigDtoService { public ProxyConfig getByCrn(String resourceCrn) { return convert(getProxyConfig(resourceCrn, proxyEndpoint::getByResourceCrn)); }  ProxyConfig getByCrn(String resourceCrn); Optional<ProxyConfig> getByCrnWithEnvironmentFallback(String resourceCrn, @Nonnull String environmentCrn); Optional<ProxyConfig> getByEnvironmentCrn(String environmentCrn);  }### Answer:
@Test void testGetWhenProxyConfigCouldBeFetched() { String name = "aProxyConfig"; String host = "https: Integer port = 8443; String decryptedSecretValue = "decrypted-secret-value"; SecretResponse secretResponse = new SecretResponse(); ProxyResponse proxyResponse = new ProxyResponse(); proxyResponse.setName(name); proxyResponse.setHost(host); proxyResponse.setPort(port); proxyResponse.setUserName(secretResponse); proxyResponse.setPassword(secretResponse); when(environmentServiceCrnClient.withCrn(anyString()).proxyV1Endpoint()).thenReturn(proxyEndpoint); when(proxyEndpoint.getByResourceCrn(anyString())).thenReturn(proxyResponse); when(secretService.getByResponse(any(SecretResponse.class))).thenReturn(decryptedSecretValue); ProxyConfig proxyConfig = underTest.getByCrn("crn:cdp:environments:us-west-1:cloudera:proxyconfig:a2f0bee2-059e-433f-a9d0-2893c53419ad"); verify(secretService, times(2)).getByResponse(secretResponse); assertEquals(proxyConfig.getName(), name); assertEquals(proxyConfig.getServerHost(), host); assertEquals(proxyConfig.getServerPort(), port); assertTrue(proxyConfig.getProxyAuthentication().isPresent()); assertEquals(proxyConfig.getProxyAuthentication().get().getUserName(), decryptedSecretValue); assertEquals(proxyConfig.getProxyAuthentication().get().getPassword(), decryptedSecretValue); }
@Test void testGetWhenProxyConfigCouldNotBeFetchedFromEnvironmentMS() { SecretResponse secretResponse = new SecretResponse(); when(environmentServiceCrnClient.withCrn(anyString()).proxyV1Endpoint()).thenReturn(proxyEndpoint); when(proxyEndpoint.getByResourceCrn(anyString())).thenThrow(new NotFoundException("The proxy config could not be found!")); CloudbreakServiceException exception = assertThrows(CloudbreakServiceException.class, () -> underTest.getByCrn( "crn:cdp:environments:us-west-1:cloudera:proxyconfig:a2f0bee2-059e-433f-a9d0-2893c53419ad")); verify(secretService, times(0)).getByResponse(secretResponse); assertEquals("Failed to get Proxy config from Environment service due to: 'The proxy config could not be found!' ", exception.getMessage()); }
@Test void testGetWhenSecretCouldNotBeFetchedFromVault() { String name = "aProxyConfig"; String host = "https: Integer port = 8443; SecretResponse secretResponse = new SecretResponse(); ProxyResponse proxyResponse = new ProxyResponse(); proxyResponse.setName(name); proxyResponse.setHost(host); proxyResponse.setPort(port); proxyResponse.setUserName(secretResponse); proxyResponse.setPassword(secretResponse); when(environmentServiceCrnClient.withCrn(anyString()).proxyV1Endpoint()).thenReturn(proxyEndpoint); when(proxyEndpoint.getByResourceCrn(anyString())).thenReturn(proxyResponse); when(secretService.getByResponse(any(SecretResponse.class))).thenThrow(new VaultException("Vault token is invalid!")); CloudbreakServiceException exception = assertThrows(CloudbreakServiceException.class, () -> underTest.getByCrn( "crn:cdp:environments:us-west-1:cloudera:proxyconfig:a2f0bee2-059e-433f-a9d0-2893c53419ad")); assertEquals("Failed to get Proxy config related secret due to: 'Vault token is invalid!' ", exception.getMessage()); }