HttpsEndpointPlugin implements IPlugin { @Override public void load() throws PluginException { try { IBootstrapItem<String> item = new BootstrapItem("CreateHttpsEndpoint"); item .process( () -> { try { initializeFieldNames(); IOC.register(Keys.getOrAdd(ISslEngineProvider.class.getCanonicalName()), new CreateNewInstanceStrategy( (args) -> { ISslEngineProvider sslContextProvider = new SslEngineProvider(); try { if (args != null && args.length > 0) { sslContextProvider.init((IObject) args[0]); } else { sslContextProvider.init(null); } } catch (SSLEngineProviderException e) { } return sslContextProvider; } ) ); IOC.register( Keys.getOrAdd(IEnvironmentHandler.class.getCanonicalName()), new CreateNewInstanceStrategy( (args) -> { IObject configuration = (IObject) args[0]; IQueue queue = null; Integer stackDepth = null; try { queue = (IQueue) configuration.getValue(queueFieldName); stackDepth = (Integer) configuration.getValue(stackDepthFieldName); return new EnvironmentHandler(queue, stackDepth); } catch (ReadValueException | InvalidArgumentException | ResolutionException e) { throw new RuntimeException(e); } } ) ); registerHttpsEndpoint(); IOC.register(Keys.getOrAdd(FileInputStream.class.getCanonicalName()), new CreateNewInstanceStrategy( (args) -> { try { return new FileInputStream((String) args[0]); } catch (FileNotFoundException e) { } return null; } )); IKey emptyIObjectKey = Keys.getOrAdd("EmptyIObject"); IOC.register(emptyIObjectKey, new CreateNewInstanceStrategy( (args) -> new DSObject() ) ); IKey channelHandlerNettyKey = Keys.getOrAdd("info.smart_tools.smartactors.http_endpoint.channel_handler_netty.ChannelHandlerNetty"); IOC.register(channelHandlerNettyKey, new CreateNewInstanceStrategy( (args) -> { ChannelHandlerNetty channelHandlerNetty = new ChannelHandlerNetty(); channelHandlerNetty.init((ChannelHandlerContext) args[0]); return channelHandlerNetty; } )); } catch (Exception e) { throw new RuntimeException(e); } } ); bootstrap.add(item); } catch (Exception e) { throw new PluginException("Can't load \"CreateHttpsEndpoint\" plugin", e); } } HttpsEndpointPlugin(final IBootstrap<IBootstrapItem<String>> bootstrap); @Override void load();  }
@Test public void checkLoadExecution() throws Exception { Checker checker = new Checker(); checker.item = new BootstrapItem("test"); IBootstrap<IBootstrapItem<String>> bootstrap = mock(IBootstrap.class); List<IBootstrapItem<String>> itemList = new ArrayList<>(); doAnswer(new Answer<Void>() { public Void answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); checker.item = (IBootstrapItem<String>) args[0]; itemList.add(checker.item); return null; } }) .when(bootstrap) .add(any(IBootstrapItem.class)); IPlugin plugin = new HttpsEndpointPlugin(bootstrap); plugin.load(); assertEquals(itemList.size(), 1); IBootstrapItem<String> item = itemList.get(0); item.executeProcess(); reset(bootstrap); }
@Test(expected = PluginException.class) public void checkPluginExceptionOnPluginLoad() throws Exception { IBootstrap<IBootstrapItem<String>> bootstrap = mock(IBootstrap.class); IPlugin plugin = new HttpsEndpointPlugin(bootstrap); doThrow(Exception.class).when(bootstrap).add(any(IBootstrapItem.class)); plugin.load(); fail(); }