SecureServerExposerFactoryProvider { public SecureServerExposerFactory<T> get(T k8sEnv) { String envExposerImpl = k8sEnv.getAttributes().get(SECURE_EXPOSER_IMPL_PROPERTY); if (envExposerImpl != null) { if (factories.containsKey(envExposerImpl)) { return factories.get(envExposerImpl); } k8sEnv .getWarnings() .add( new WarningImpl( Warnings.UNKNOWN_SECURE_SERVER_EXPOSER_CONFIGURED_IN_WS_WARNING_CODE, format(unknownExposerErrorTemplate, envExposerImpl))); } return this.serverExposerFactory; } @Inject  SecureServerExposerFactoryProvider(
      @Named(SECURE_EXPOSER_IMPL_PROPERTY) String serverExposer,
      Map<String, SecureServerExposerFactory<T>> factories); SecureServerExposerFactory<T> get(T k8sEnv); static final String SECURE_EXPOSER_IMPL_PROPERTY; static final String UNKNOWN_EXPOSER_ERROR_TEMPLATE; }
@Test public void shouldReturnConfiguredSecureServerExposer() { SecureServerExposerFactoryProvider<KubernetesEnvironment> factoryProvider = new SecureServerExposerFactoryProvider<>(EXPOSER1, factories); SecureServerExposerFactory<KubernetesEnvironment> factory = factoryProvider.get(kubernetesEnvironment); assertSame(factory, secureServerExposer1); }
@Test public void shouldAddWarningIfSecureServerConfiguredInEnvironmentWasNotFound() { SecureServerExposerFactoryProvider<KubernetesEnvironment> factoryProvider = new SecureServerExposerFactoryProvider<>(EXPOSER1, factories); kubernetesEnvironment.setAttributes( ImmutableMap.of(SECURE_EXPOSER_IMPL_PROPERTY, NON_EXISTING_EXPOSER)); WarningImpl expectedWarning = new WarningImpl( UNKNOWN_SECURE_SERVER_EXPOSER_CONFIGURED_IN_WS_WARNING_CODE, format( UNKNOWN_EXPOSER_ERROR_TEMPLATE, NON_EXISTING_EXPOSER, String.join(", ", factories.keySet()))); SecureServerExposerFactory<KubernetesEnvironment> factory = factoryProvider.get(kubernetesEnvironment); assertSame(factory, secureServerExposer1); assertEquals(kubernetesEnvironment.getWarnings().size(), 1); assertEquals(kubernetesEnvironment.getWarnings().get(0), expectedWarning); }
@Test public void shouldReturnSecureServerExposerConfiguredInEnvironment() { SecureServerExposerFactoryProvider<KubernetesEnvironment> factoryProvider = new SecureServerExposerFactoryProvider<>(EXPOSER1, factories); kubernetesEnvironment.setAttributes(ImmutableMap.of(SECURE_EXPOSER_IMPL_PROPERTY, EXPOSER2)); SecureServerExposerFactory<KubernetesEnvironment> factory = factoryProvider.get(kubernetesEnvironment); assertSame(factory, secureServerExposer2); }