### Question:
AbstractMongoProcessor extends AbstractProcessor { @OnScheduled public final void createClient(ProcessContext context) throws IOException { if (mongoClient != null) { closeClient(); } getLogger().info("Creating MongoClient"); final SSLContextService sslService = context.getProperty(SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class); final String rawClientAuth = context.getProperty(CLIENT_AUTH).getValue(); final SSLContext sslContext; if (sslService != null) { final SSLContextService.ClientAuth clientAuth; if (StringUtils.isBlank(rawClientAuth)) { clientAuth = SSLContextService.ClientAuth.REQUIRED; } else { try { clientAuth = SSLContextService.ClientAuth.valueOf(rawClientAuth); } catch (final IllegalArgumentException iae) { throw new ProviderCreationException(String.format("Unrecognized client auth '%s'. Possible values are [%s]", rawClientAuth, StringUtils.join(SslContextFactory.ClientAuth.values(), ", "))); } } sslContext = sslService.createSSLContext(clientAuth); } else { sslContext = null; } try { final String uri = context.getProperty(URI).getValue(); if(sslContext == null) { mongoClient = new MongoClient(new MongoClientURI(uri)); } else { mongoClient = new MongoClient(new MongoClientURI(uri, getClientOptions(sslContext))); } } catch (Exception e) { getLogger().error("Failed to schedule {} due to {}", new Object[] { this.getClass().getName(), e }, e); throw e; } }  @OnScheduled final void createClient(ProcessContext context); @OnStopped final void closeClient(); static final PropertyDescriptor SSL_CONTEXT_SERVICE; static final PropertyDescriptor CLIENT_AUTH; }### Answer:
@Test public void testcreateClientWithSSL() throws Exception { SSLContextService sslService = mock(SSLContextService.class); SSLContext sslContext = mock(SSLContext.class); when(sslService.getIdentifier()).thenReturn("ssl-context"); when(sslService.createSSLContext(any(ClientAuth.class))).thenReturn(sslContext); testRunner.addControllerService("ssl-context", sslService); testRunner.enableControllerService(sslService); testRunner.setProperty(AbstractMongoProcessor.URI, "mongodb: testRunner.setProperty(AbstractMongoProcessor.SSL_CONTEXT_SERVICE, "ssl-context"); testRunner.assertValid(sslService); processor.createClient(testRunner.getProcessContext()); assertNotNull(processor.mongoClient); processor.mongoClient = null; testRunner.setProperty(AbstractMongoProcessor.CLIENT_AUTH, "WANT"); processor.createClient(testRunner.getProcessContext()); assertNotNull(processor.mongoClient); }
@Test(expected = ProviderCreationException.class) public void testcreateClientWithSSLBadClientAuth() throws Exception { SSLContextService sslService = mock(SSLContextService.class); SSLContext sslContext = mock(SSLContext.class); when(sslService.getIdentifier()).thenReturn("ssl-context"); when(sslService.createSSLContext(any(ClientAuth.class))).thenReturn(sslContext); testRunner.addControllerService("ssl-context", sslService); testRunner.enableControllerService(sslService); testRunner.setProperty(AbstractMongoProcessor.URI, "mongodb: testRunner.setProperty(AbstractMongoProcessor.SSL_CONTEXT_SERVICE, "ssl-context"); testRunner.assertValid(sslService); processor.createClient(testRunner.getProcessContext()); assertNotNull(processor.mongoClient); processor.mongoClient = null; testRunner.setProperty(AbstractMongoProcessor.CLIENT_AUTH, "BAD"); processor.createClient(testRunner.getProcessContext()); }