ActorReceiverCreatorPlugin implements IPlugin { @Override public void load() throws PluginException { try { IBootstrapItem<String> item = new BootstrapItem("ActorReceiverCreator"); item .after("IOC") .before("starter") .after("InitializeReceiverGenerator") .after("InitializeWrapperGenerator") .after("IFieldPlugin") .after("IFieldNamePlugin") .process( () -> { try { IOC.register( Keys.getOrAdd("actor_receiver_queue"), new CreateNewInstanceStrategy(args -> new ConcurrentLinkedQueue())); IOC.register( Keys.getOrAdd("actor_receiver_busyness_flag"), new CreateNewInstanceStrategy(args -> new AtomicBoolean(false))); ActorReceiverCreator objectCreator = new ActorReceiverCreator(); IOC.register( IOC.resolve( IOC.getKeyForKeyStorage(), IRoutedObjectCreator.class.getCanonicalName() + "#actor" ), new SingletonStrategy(objectCreator) ); } catch (ResolutionException e) { throw new ActionExecuteException("ActorReceiverCreator plugin can't load: can't get ActorReceiverCreator key", e); } catch (InvalidArgumentException e) { throw new ActionExecuteException("ActorReceiverCreator plugin can't load: can't create strategy", e); } catch (RegistrationException e) { throw new ActionExecuteException("ActorReceiverCreator plugin can't load: can't register new strategy", e); } catch (ObjectCreationException e) { throw new ActionExecuteException("ActorReceiverCreator plugin can't load: constructor error", e); } } ); this.bootstrap.add(item); } catch (Throwable e) { throw new PluginException("Could not load 'ActorReceiverCreator plugin'", e); } } ActorReceiverCreatorPlugin(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 ActorReceiverCreatorPlugin(bootstrap); plugin.load(); assertEquals(itemList.size(), 1); IBootstrapItem<String> item = itemList.get(0); item.executeProcess(); IRoutedObjectCreator objectCreator = IOC.resolve( IOC.resolve( IOC.getKeyForKeyStorage(), IRoutedObjectCreator.class.getCanonicalName() + "#actor" ) ); assertNotNull(objectCreator); reset(bootstrap); }
@Test (expected = PluginException.class) public void checkPluginExceptionOnPluginLoad() throws Exception { IBootstrap<IBootstrapItem<String>> bootstrap = mock(IBootstrap.class); IPlugin plugin = new ActorReceiverCreatorPlugin(bootstrap); doThrow(Exception.class).when(bootstrap).add(any(IBootstrapItem.class)); plugin.load(); fail(); }