com.google.inject.AbstractModule Java Examples
The following examples show how to use
com.google.inject.AbstractModule.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MainTest.java From nifi-config with Apache License 2.0 | 6 votes |
@Test(expected = ConfigException.class) public void mainExceptionTest() throws Exception { Injector injector = Guice.createInjector(new AbstractModule() { protected void configure() { bind(AccessService.class).toInstance(accessServiceMock); bind(InformationService.class).toInstance(informationServiceMock); bind(TemplateService.class).toInstance(templateServiceMock); bind(Integer.class).annotatedWith(Names.named("timeout")).toInstance(10); bind(Integer.class).annotatedWith(Names.named("interval")).toInstance(10); bind(Boolean.class).annotatedWith(Names.named("forceMode")).toInstance(false); bind(Double.class).annotatedWith(Names.named("placeWidth")).toInstance(1200d); bind(PositionDTO.class).annotatedWith(Names.named("startPosition")).toInstance(new PositionDTO()); } }); //given PowerMockito.mockStatic(Guice.class); Mockito.when(Guice.createInjector((AbstractModule) anyObject())).thenReturn(injector); doThrow(new ApiException()).when(accessServiceMock).addTokenOnConfiguration(false, null, null); Main.main(new String[]{"-nifi", "http://localhost:8080/nifi-api", "-branch", "\"root>N2\"", "-conf", "adr", "-m", "undeploy"}); }
Example #2
Source File: HiveMQMainModuleTest.java From hivemq-community-edition with Apache License 2.0 | 6 votes |
@Test public void test_topic_matcher_not_same() { final Injector injector = Guice.createInjector(Stage.PRODUCTION, new HiveMQMainModule(), new AbstractModule() { @Override protected void configure() { bind(EventExecutorGroup.class).toInstance(Mockito.mock(EventExecutorGroup.class)); } }); final TopicMatcher instance1 = injector.getInstance(TopicMatcher.class); final TopicMatcher instance2 = injector.getInstance(TopicMatcher.class); assertNotSame(instance1, instance2); }
Example #3
Source File: GuiceBootstrap.java From hivemq-community-edition with Apache License 2.0 | 6 votes |
@Nullable public static Injector bootstrapInjector( final @NotNull SystemInformation systemInformation, final @NotNull MetricRegistry metricRegistry, final @NotNull HivemqId hiveMQId, final @NotNull FullConfigurationService fullConfigurationService, final @NotNull Injector persistenceInjector) { if (!Boolean.parseBoolean(System.getProperty("diagnosticMode"))) { log.trace("Turning Guice stack traces off"); System.setProperty("guice_include_stack_traces", "OFF"); } final ImmutableList.Builder<AbstractModule> modules = ImmutableList.builder(); return getInjector(systemInformation, metricRegistry, hiveMQId, fullConfigurationService, modules, persistenceInjector); }
Example #4
Source File: ConnectionServiceTest.java From nifi-config with Apache License 2.0 | 6 votes |
@Test(expected = TimeoutException.class) public void waitEmptyQueueTimeOutTest() throws ApiException, IOException, URISyntaxException { Injector injector = Guice.createInjector(new AbstractModule() { protected void configure() { bind(ConnectionsApi.class).toInstance(connectionsApiMock); bind(FlowfileQueuesApi.class).toInstance(flowfileQueuesApiMock); bind(Integer.class).annotatedWith(Names.named("timeout")).toInstance(1); bind(Integer.class).annotatedWith(Names.named("interval")).toInstance(1); bind(Boolean.class).annotatedWith(Names.named("forceMode")).toInstance(false); } }); ConnectionService connectionService = injector.getInstance(ConnectionService.class); ConnectionEntity connection = TestUtils.createConnectionEntity("id","sourceId","destinationId"); connection.setStatus(new ConnectionStatusDTO()); connection.getStatus().setAggregateSnapshot(new ConnectionStatusSnapshotDTO()); connection.getStatus().getAggregateSnapshot().setQueuedCount("1"); connection.getStatus().getAggregateSnapshot().setQueuedSize("0"); when(connectionsApiMock.getConnection("id")).thenReturn(connection); connectionService.waitEmptyQueue(connection); }
Example #5
Source File: ConfigurationModuleTest.java From hivemq-community-edition with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); testConfigurationBootstrap = new TestConfigurationBootstrap(); final FullConfigurationService fullConfigurationService = testConfigurationBootstrap.getFullConfigurationService(); injector = Guice.createInjector(new SystemInformationModule(new SystemInformationImpl()), new ConfigurationModule(fullConfigurationService, new HivemqId()), new AbstractModule() { @Override protected void configure() { bind(SharedSubscriptionService.class).toInstance(sharedSubscriptionService); } }); }
Example #6
Source File: TestStorageContainerServiceProviderImpl.java From hadoop-ozone with Apache License 2.0 | 6 votes |
@Before public void setup() { injector = Guice.createInjector(new AbstractModule() { @Override protected void configure() { try { StorageContainerLocationProtocol mockScmClient = mock( StorageContainerLocationProtocol.class); pipelineID = PipelineID.randomId().getProtobuf(); when(mockScmClient.getPipeline(pipelineID)) .thenReturn(mock(Pipeline.class)); bind(StorageContainerLocationProtocol.class) .toInstance(mockScmClient); bind(StorageContainerServiceProvider.class) .to(StorageContainerServiceProviderImpl.class); } catch (Exception e) { Assert.fail(); } } }); }
Example #7
Source File: PersistenceMigrationModuleTest.java From hivemq-community-edition with Apache License 2.0 | 6 votes |
@Test public void test_memory_persistence() { when(persistenceConfigurationService.getMode()).thenReturn(PersistenceConfigurationService.PersistenceMode.IN_MEMORY); final Injector injector = Guice.createInjector( new PersistenceMigrationModule(new MetricRegistry(), persistenceConfigurationService), new AbstractModule() { @Override protected void configure() { bind(SystemInformation.class).toInstance(systemInformation); bindScope(LazySingleton.class, LazySingletonScope.get()); bind(MqttConfigurationService.class).toInstance(mqttConfigurationService); } }); assertTrue(injector.getInstance(RetainedMessageLocalPersistence.class) instanceof RetainedMessageMemoryLocalPersistence); assertTrue(injector.getInstance(PublishPayloadLocalPersistence.class) instanceof PublishPayloadMemoryLocalPersistence); }
Example #8
Source File: PersistenceMigrationModuleTest.java From hivemq-community-edition with Apache License 2.0 | 6 votes |
@Test public void test_startup_singleton() { final Injector injector = Guice.createInjector( new PersistenceMigrationModule(new MetricRegistry(), persistenceConfigurationService), new AbstractModule() { @Override protected void configure() { bind(SystemInformation.class).toInstance(systemInformation); bindScope(LazySingleton.class, LazySingletonScope.get()); bind(MqttConfigurationService.class).toInstance(mqttConfigurationService); } }); final PersistenceStartup instance1 = injector.getInstance(PersistenceStartup.class); final PersistenceStartup instance2 = injector.getInstance(PersistenceStartup.class); assertSame(instance1, instance2); }
Example #9
Source File: ConnectionServiceTest.java From nifi-config with Apache License 2.0 | 6 votes |
@Test public void waitEmptyQueueTest() throws ApiException, IOException, URISyntaxException { Injector injector = Guice.createInjector(new AbstractModule() { protected void configure() { bind(ConnectionsApi.class).toInstance(connectionsApiMock); bind(FlowfileQueuesApi.class).toInstance(flowfileQueuesApiMock); bind(Integer.class).annotatedWith(Names.named("timeout")).toInstance(1); bind(Integer.class).annotatedWith(Names.named("interval")).toInstance(1); bind(Boolean.class).annotatedWith(Names.named("forceMode")).toInstance(false); } }); ConnectionService connectionService = injector.getInstance(ConnectionService.class); ConnectionEntity connection = TestUtils.createConnectionEntity("id","sourceId","destinationId"); connection.setStatus(new ConnectionStatusDTO()); connection.getStatus().setAggregateSnapshot(new ConnectionStatusSnapshotDTO()); connection.getStatus().getAggregateSnapshot().setQueuedCount("0"); connection.getStatus().getAggregateSnapshot().setQueuedSize("0"); when(connectionsApiMock.getConnection("id")).thenReturn(connection); connectionService.waitEmptyQueue(connection); }
Example #10
Source File: MetricsModuleTest.java From hivemq-community-edition with Apache License 2.0 | 6 votes |
@Before public void before() { MockitoAnnotations.initMocks(this); injector = Guice.createInjector(new AbstractModule() { @Override protected void configure() { final Injector persistenceInjector = mock(Injector.class); when(persistenceInjector.getInstance(MetricsHolder.class)).thenReturn(mock(MetricsHolder.class)); final NettyConfiguration nettyConfiguration = mock(NettyConfiguration.class); when(nettyConfiguration.getChildEventLoopGroup()).thenReturn(mock(EventLoopGroup.class)); bind(NettyConfiguration.class).toInstance(nettyConfiguration); bind(ChannelGroup.class).toInstance(mock(ChannelGroup.class)); bind(ClientSessionLocalPersistence.class).toInstance(mock(ClientSessionLocalPersistence.class)); bind(LocalTopicTree.class).toInstance(mock(TopicTreeImpl.class)); bind(RetainedMessagePersistence.class).toInstance(mock(RetainedMessagePersistence.class)); bind(SystemInformation.class).toInstance(mock(SystemInformation.class)); bindScope(LazySingleton.class, LazySingletonScope.get()); install(new MetricsModule(new MetricRegistry(), persistenceInjector)); } }); }
Example #11
Source File: SecurityModuleTest.java From hivemq-community-edition with Apache License 2.0 | 6 votes |
@Test public void test_ssl_factory_same() { final Injector injector = Guice.createInjector(Stage.PRODUCTION, new SecurityModule(), new AbstractModule() { @Override protected void configure() { bind(EventExecutorGroup.class).toInstance(mock(EventExecutorGroup.class)); bind(ShutdownHooks.class).toInstance(mock(ShutdownHooks.class)); bindScope(LazySingleton.class, LazySingletonScope.get()); } }); final SslFactory instance1 = injector.getInstance(SslFactory.class); final SslFactory instance2 = injector.getInstance(SslFactory.class); assertSame(instance1, instance2); }
Example #12
Source File: GuiceBootstrap.java From hivemq-community-edition with Apache License 2.0 | 6 votes |
public static @NotNull Injector persistenceInjector( final @NotNull SystemInformation systemInformation, final @NotNull MetricRegistry metricRegistry, final @NotNull HivemqId hiveMQId, final @NotNull FullConfigurationService configService) { final ImmutableList.Builder<AbstractModule> modules = ImmutableList.builder(); modules.add(new SystemInformationModule(systemInformation), new ConfigurationModule(configService, hiveMQId), new LazySingletonModule(), LifecycleModule.get(), new PersistenceMigrationModule(metricRegistry, configService.persistenceConfigurationService())); return Guice.createInjector(Stage.PRODUCTION, modules.build()); }
Example #13
Source File: ProcessorServiceTest.java From nifi-config with Apache License 2.0 | 6 votes |
@Test(expected = ConfigException.class) public void setStateExceptionTest() { Injector injector = Guice.createInjector(new AbstractModule() { protected void configure() { bind(ProcessorsApi.class).toInstance(processorsApiMock); bind(Integer.class).annotatedWith(Names.named("timeout")).toInstance(1); bind(Integer.class).annotatedWith(Names.named("interval")).toInstance(1); bind(Boolean.class).annotatedWith(Names.named("forceMode")).toInstance(false); } }); ProcessorService processorService = injector.getInstance(ProcessorService.class); ProcessorEntity processor = TestUtils.createProcessorEntity("id", "name"); processor.getComponent().setState(ProcessorDTO.StateEnum.STOPPED); ProcessorEntity processorResponse = TestUtils.createProcessorEntity("id", "name"); processorResponse.getComponent().setState(ProcessorDTO.StateEnum.RUNNING); when(processorsApiMock.updateProcessor(eq("id"), any() )).thenThrow(new ApiException()); when(processorsApiMock.getProcessor(eq("id") )).thenReturn(processorResponse); processorService.setState(processor, ProcessorDTO.StateEnum.RUNNING); }
Example #14
Source File: TestIpcdBridgeServiceImpl.java From arcusplatform with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Before public void setUp() throws Exception { Bootstrap bootstrap = Bootstrap.builder() .withModuleClasses(IpcdServerModule.class, GsonModule.class, MessagesModule.class) .withModules(new AbstractModule() { @Override protected void configure() { bind(ProtocolMessageBus.class).to(InMemoryProtocolMessageBus.class); bind(PlatformMessageBus.class).to(InMemoryPlatformMessageBus.class); } }) .withConfigPaths("src/dist/conf/ipcd-bridge.properties") .build(); ServiceLocator.init(GuiceServiceLocator.create(bootstrap.bootstrap())); this.protocolBus = ServiceLocator.getInstance(InMemoryProtocolMessageBus.class); this.ipcdDevice = new Device(); this.ipcdDevice.setIpcdver("0.3"); this.ipcdDevice.setVendor("Blackbox"); this.ipcdDevice.setModel("Switch1"); this.ipcdDevice.setSn("123456789"); this.clientId = ProtocolDeviceId.hashDeviceId(ipcdDevice.getVendor() + "-" + ipcdDevice.getModel() + "-" + ipcdDevice.getSn()).getRepresentation(); }
Example #15
Source File: IrisTestCase.java From arcusplatform with Apache License 2.0 | 6 votes |
protected Injector bootstrap() throws ClassNotFoundException, BootstrapException { final Module m = ProviderMethodsModule.forObject(this); return Bootstrap .builder() .withModuleClassnames(moduleClassNames()) .withModuleClasses(moduleClasses()) .withModules(modules()) .withModules(new AbstractModule() { @Override protected void configure() { // generating sources for ProviderMethods will result in an NPE m.configure(binder().skipSources(IrisTestCase.this.getClass())); // get injections bind(IrisTestCase.class).toInstance(IrisTestCase.this); IrisTestCase.this.configure(binder()); } }) .withConfigPaths(configs()) .build() .bootstrap(); }
Example #16
Source File: SabotNode.java From dremio-oss with Apache License 2.0 | 6 votes |
protected void init( SingletonRegistry registry, SabotConfig config, ClusterCoordinator clusterCoordinator, ScanResult classpathScan, boolean allRoles, List<AbstractModule> overrideModules) throws Exception { this.overrideModules = overrideModules; DremioConfig dremioConfig = DremioConfig.create(null, config); dremioConfig = dremioConfig.withValue(DremioConfig.ENABLE_COORDINATOR_BOOL, allRoles); final BootStrapContext bootstrap = new BootStrapContext(dremioConfig, classpathScan, registry); guiceSingletonHandler = new GuiceServiceModule(); injector = createInjector(dremioConfig, classpathScan, registry, clusterCoordinator, allRoles, bootstrap); registry.registerGuiceInjector(injector); }
Example #17
Source File: MainTest.java From nifi-config with Apache License 2.0 | 6 votes |
@Test public void mainExtractWithoutBranchTest() throws Exception { Injector injector = Guice.createInjector(new AbstractModule() { protected void configure() { bind(AccessService.class).toInstance(accessServiceMock); bind(InformationService.class).toInstance(informationServiceMock); bind(ExtractProcessorService.class).toInstance(extractProcessorServiceMock); bind(Integer.class).annotatedWith(Names.named("timeout")).toInstance(10); bind(Integer.class).annotatedWith(Names.named("interval")).toInstance(10); bind(Boolean.class).annotatedWith(Names.named("forceMode")).toInstance(false); bind(Double.class).annotatedWith(Names.named("placeWidth")).toInstance(1200d); bind(PositionDTO.class).annotatedWith(Names.named("startPosition")).toInstance(new PositionDTO()); } }); //given PowerMockito.mockStatic(Guice.class); Mockito.when(Guice.createInjector((AbstractModule) anyObject())).thenReturn(injector); Main.main(new String[]{"-nifi", "http://localhost:8080/nifi-api", "-conf", "adr", "-m", "extractConfig", "-accessFromTicket"}); verify(extractProcessorServiceMock).extractByBranch(Arrays.asList("root"), "adr", false); }
Example #18
Source File: MainTest.java From nifi-config with Apache License 2.0 | 6 votes |
@Test public void mainUpdateWithPasswordFromEnvTest() throws Exception { PowerMockito.mockStatic(System.class); Mockito.when(System.getenv(Main.ENV_NIFI_PASSWORD)).thenReturn("nifi_pass"); Injector injector = Guice.createInjector(new AbstractModule() { protected void configure() { bind(AccessService.class).toInstance(accessServiceMock); bind(InformationService.class).toInstance(informationServiceMock); bind(UpdateProcessorService.class).toInstance(updateProcessorServiceMock); // bind(ConnectionPortService.class).toInstance(createRouteServiceMock); bind(Integer.class).annotatedWith(Names.named("timeout")).toInstance(10); bind(Integer.class).annotatedWith(Names.named("interval")).toInstance(10); bind(Boolean.class).annotatedWith(Names.named("forceMode")).toInstance(false); bind(Double.class).annotatedWith(Names.named("placeWidth")).toInstance(1200d); bind(PositionDTO.class).annotatedWith(Names.named("startPosition")).toInstance(new PositionDTO()); } }); //given PowerMockito.mockStatic(Guice.class); Mockito.when(Guice.createInjector((AbstractModule) anyObject())).thenReturn(injector); Main.main(new String[]{"-nifi", "http://localhost:8080/nifi-api", "-branch", "\"root>N2\"", "-conf", "adr", "-m", "updateConfig", "-user", "user", "-password", "password"}); verify(updateProcessorServiceMock).updateByBranch(Arrays.asList("root", "N2"), "adr", false); verify(accessServiceMock).addTokenOnConfiguration(false, "user", "nifi_pass"); }
Example #19
Source File: MainTest.java From nifi-config with Apache License 2.0 | 6 votes |
@Test public void mainUpdateWithPasswordTest() throws Exception { Injector injector = Guice.createInjector(new AbstractModule() { protected void configure() { bind(AccessService.class).toInstance(accessServiceMock); bind(InformationService.class).toInstance(informationServiceMock); bind(UpdateProcessorService.class).toInstance(updateProcessorServiceMock); // bind(ConnectionPortService.class).toInstance(createRouteServiceMock); bind(Integer.class).annotatedWith(Names.named("timeout")).toInstance(10); bind(Integer.class).annotatedWith(Names.named("interval")).toInstance(10); bind(Boolean.class).annotatedWith(Names.named("forceMode")).toInstance(false); bind(Double.class).annotatedWith(Names.named("placeWidth")).toInstance(1200d); bind(PositionDTO.class).annotatedWith(Names.named("startPosition")).toInstance(new PositionDTO()); } }); //given PowerMockito.mockStatic(Guice.class); Mockito.when(Guice.createInjector((AbstractModule) anyObject())).thenReturn(injector); Main.main(new String[]{"-nifi", "http://localhost:8080/nifi-api", "-branch", "\"root>N2\"", "-conf", "adr", "-m", "updateConfig", "-user", "user", "-password", "password"}); verify(updateProcessorServiceMock).updateByBranch(Arrays.asList("root", "N2"), "adr", false); }
Example #20
Source File: MainTest.java From nifi-config with Apache License 2.0 | 6 votes |
@Test public void mainDeployTest() throws Exception { Injector injector = Guice.createInjector(new AbstractModule() { protected void configure() { bind(AccessService.class).toInstance(accessServiceMock); bind(InformationService.class).toInstance(informationServiceMock); bind(TemplateService.class).toInstance(templateServiceMock); bind(Integer.class).annotatedWith(Names.named("timeout")).toInstance(10); bind(Integer.class).annotatedWith(Names.named("interval")).toInstance(10); bind(Boolean.class).annotatedWith(Names.named("forceMode")).toInstance(false); bind(Double.class).annotatedWith(Names.named("placeWidth")).toInstance(1200d); bind(PositionDTO.class).annotatedWith(Names.named("startPosition")).toInstance(new PositionDTO()); } }); //given PowerMockito.mockStatic(Guice.class); Mockito.when(Guice.createInjector((AbstractModule) anyObject())).thenReturn(injector); Main.main(new String[]{"-nifi", "http://localhost:8080/nifi-api", "-branch", "\"root>N2\"", "-conf", "adr", "-m", "deployTemplate"}); verify(templateServiceMock).installOnBranch(Arrays.asList("root", "N2"), "adr", false); }
Example #21
Source File: MainTest.java From nifi-config with Apache License 2.0 | 6 votes |
@Test public void mainHttpsUndeployTest() throws Exception { Injector injector = Guice.createInjector(new AbstractModule() { protected void configure() { bind(AccessService.class).toInstance(accessServiceMock); bind(InformationService.class).toInstance(informationServiceMock); bind(TemplateService.class).toInstance(templateServiceMock); bind(Integer.class).annotatedWith(Names.named("timeout")).toInstance(10); bind(Integer.class).annotatedWith(Names.named("interval")).toInstance(10); bind(Boolean.class).annotatedWith(Names.named("forceMode")).toInstance(false); bind(Double.class).annotatedWith(Names.named("placeWidth")).toInstance(1200d); bind(PositionDTO.class).annotatedWith(Names.named("startPosition")).toInstance(new PositionDTO()); } }); //given PowerMockito.mockStatic(Guice.class); Mockito.when(Guice.createInjector((AbstractModule) anyObject())).thenReturn(injector); Main.main(new String[]{"-nifi", "https://localhost:8080/nifi-api", "-branch", "\"root>N2\"", "-m", "undeploy", "-noVerifySsl"}); verify(templateServiceMock).undeploy(Arrays.asList("root", "N2")); }
Example #22
Source File: FakeServiceModuleTest.java From exonum-java-binding with Apache License 2.0 | 6 votes |
@Test void configure() { // todo: Do we need this wonderful test? Injector injector = Guice.createInjector(new AbstractModule() { @Override protected void configure() { bind(ServiceInstanceSpec.class).toInstance(ServiceInstanceSpec.newInstance("test", 1, ServiceArtifactId.newJavaId("a/b", "1"))); } }, new FakeServiceModule()); Service instance = injector.getInstance(Service.class); assertNotNull(instance); assertThat(instance, instanceOf(FakeService.class)); }
Example #23
Source File: MainTest.java From nifi-config with Apache License 2.0 | 6 votes |
@Test public void mainUndeployTest() throws Exception { Injector injector = Guice.createInjector(new AbstractModule() { protected void configure() { bind(AccessService.class).toInstance(accessServiceMock); bind(InformationService.class).toInstance(informationServiceMock); bind(TemplateService.class).toInstance(templateServiceMock); bind(Integer.class).annotatedWith(Names.named("timeout")).toInstance(10); bind(Integer.class).annotatedWith(Names.named("interval")).toInstance(10); bind(Boolean.class).annotatedWith(Names.named("forceMode")).toInstance(false); bind(Double.class).annotatedWith(Names.named("placeWidth")).toInstance(1200d); bind(PositionDTO.class).annotatedWith(Names.named("startPosition")).toInstance(new PositionDTO()); } }); //given PowerMockito.mockStatic(Guice.class); Mockito.when(Guice.createInjector((AbstractModule) anyObject())).thenReturn(injector); Main.main(new String[]{"-nifi", "http://localhost:8080/nifi-api", "-branch", "\"root>N2\"", "-conf", "adr", "-m", "undeploy"}); verify(templateServiceMock).undeploy(Arrays.asList("root", "N2")); }
Example #24
Source File: ResteasyContextListenerTest.java From cryptotrader with GNU Affero General Public License v3.0 | 6 votes |
@BeforeMethod public void setUp() { target = new ResteasyContextListener(); provider = mock(ConfigurationProvider.class); trader = mock(Trader.class); endpoint = new EndpointImpl(Guice.createInjector(new AbstractModule() { @Override protected void configure() { bind(ConfigurationProvider.class).toInstance(provider); bind(Trader.class).toInstance(trader); } })); }
Example #25
Source File: PortServiceTest.java From nifi-config with Apache License 2.0 | 6 votes |
@Test public void setStateTest() throws ApiException, IOException, URISyntaxException { Injector injector = Guice.createInjector(new AbstractModule() { protected void configure() { bind(InputPortsApi.class).toInstance(inputPortsApiMock); bind(OutputPortsApi.class).toInstance(outputPortsApiMock); bind(Integer.class).annotatedWith(Names.named("timeout")).toInstance(1); bind(Integer.class).annotatedWith(Names.named("interval")).toInstance(1); bind(Boolean.class).annotatedWith(Names.named("forceMode")).toInstance(false); } }); PortService portService = injector.getInstance(PortService.class); PortEntity port = new PortEntity(); port.setComponent(new PortDTO()); port.getComponent().setId("id"); port.getComponent().setState(PortDTO.StateEnum.STOPPED); port.setStatus(new PortStatusDTO()); port.getStatus().setRunStatus("Stopped"); portService.setState(port, PortDTO.StateEnum.STOPPED); verify(inputPortsApiMock,never()).updateInputPort(eq("id"), any()); verify(outputPortsApiMock,never()).updateOutputPort(eq("id"), any()); }
Example #26
Source File: ActivationProvisionListenerTest.java From titus-control-plane with Apache License 2.0 | 6 votes |
@Test public void testDeactivationOrderIsReverseOfActivation() throws Exception { LifecycleInjector injector = InjectorBuilder.fromModules( new ContainerEventBusModule(), new AbstractModule() { @Override protected void configure() { bind(TitusRuntime.class).toInstance(TitusRuntimes.internal()); bind(ActivationProvisionListenerTest.class).toInstance(ActivationProvisionListenerTest.this); bind(ServiceB.class).asEagerSingleton(); bind(ServiceA.class).asEagerSingleton(); } }).createInjector(); ActivationLifecycle activationLifecycle = injector.getInstance(ActivationLifecycle.class); activationLifecycle.activate(); activationLifecycle.deactivate(); assertThat(activationTrace).hasSize(4); String firstActivated = activationTrace.get(0).getLeft(); String secondActivated = activationTrace.get(1).getLeft(); assertThat(activationTrace.subList(2, 4)).containsExactly( Pair.of(secondActivated, "DEACTIVATED"), Pair.of(firstActivated, "DEACTIVATED") ); }
Example #27
Source File: PortServiceTest.java From nifi-config with Apache License 2.0 | 6 votes |
@Test public void getByIdOutputTest() throws ApiException, IOException, URISyntaxException { Injector injector = Guice.createInjector(new AbstractModule() { protected void configure() { bind(InputPortsApi.class).toInstance(inputPortsApiMock); bind(OutputPortsApi.class).toInstance(outputPortsApiMock); bind(Integer.class).annotatedWith(Names.named("timeout")).toInstance(1); bind(Integer.class).annotatedWith(Names.named("interval")).toInstance(1); bind(Boolean.class).annotatedWith(Names.named("forceMode")).toInstance(false); } }); PortService portService = injector.getInstance(PortService.class); PortEntity port = new PortEntity(); port.setComponent(new PortDTO()); port.getComponent().setId("id"); when(outputPortsApiMock.getOutputPort("id")).thenReturn(port); PortEntity portResult = portService.getById("id", PortDTO.TypeEnum.OUTPUT_PORT); assertEquals("id", portResult.getComponent().getId()); }
Example #28
Source File: PortServiceTest.java From nifi-config with Apache License 2.0 | 6 votes |
/** * Creates a token for accessing the REST API via username/password * <p> * The token returned is formatted as a JSON Web Token (JWT). The token is base64 encoded and comprised of three parts. The header, the body, and the signature. The expiration of the token is a contained within the body. The token can be used in the Authorization header in the format 'Authorization: Bearer <token>'. * * @throws ApiException if the Api call fails */ @Test public void getByIdInputTest() throws ApiException, IOException, URISyntaxException { Injector injector = Guice.createInjector(new AbstractModule() { protected void configure() { bind(InputPortsApi.class).toInstance(inputPortsApiMock); bind(OutputPortsApi.class).toInstance(outputPortsApiMock); bind(Integer.class).annotatedWith(Names.named("timeout")).toInstance(1); bind(Integer.class).annotatedWith(Names.named("interval")).toInstance(1); bind(Boolean.class).annotatedWith(Names.named("forceMode")).toInstance(false); } }); PortService portService = injector.getInstance(PortService.class); PortEntity port = new PortEntity(); port.setComponent(new PortDTO()); port.getComponent().setId("id"); when(inputPortsApiMock.getInputPort("id")).thenReturn(port); PortEntity portResult = portService.getById("id", PortDTO.TypeEnum.INPUT_PORT); assertEquals("id", portResult.getComponent().getId()); }
Example #29
Source File: ActivationProvisionListenerTest.java From titus-control-plane with Apache License 2.0 | 6 votes |
@Test public void testServiceReordering() throws Exception { LifecycleInjector injector = InjectorBuilder.fromModules( new ContainerEventBusModule(), new AbstractModule() { @Override protected void configure() { bind(TitusRuntime.class).toInstance(TitusRuntimes.internal()); bind(ActivationProvisionListenerTest.class).toInstance(ActivationProvisionListenerTest.this); bind(ServiceB.class).asEagerSingleton(); bind(ServiceA.class).asEagerSingleton(); } }).createInjector(); ActivationLifecycle activationLifecycle = injector.getInstance(ActivationLifecycle.class); activationLifecycle.activate(); assertThat(activationTrace).containsExactlyInAnyOrder( Pair.of("serviceA", "ACTIVATED"), Pair.of("serviceB", "ACTIVATED") ); }
Example #30
Source File: ActivationProvisionListenerTest.java From titus-control-plane with Apache License 2.0 | 6 votes |
@Test public void testActivationLifecycle() throws Exception { LifecycleInjector injector = InjectorBuilder.fromModules( new ContainerEventBusModule(), new AbstractModule() { @Override protected void configure() { bind(TitusRuntime.class).toInstance(TitusRuntimes.internal()); bind(ActivationProvisionListenerTest.class).toInstance(ActivationProvisionListenerTest.this); bind(ServiceA.class).asEagerSingleton(); } }).createInjector(); ActivationLifecycle activationLifecycle = injector.getInstance(ActivationLifecycle.class); ServiceA serviceA = injector.getInstance(ServiceA.class); assertThat(serviceA.state).isEqualTo("NOT_READY"); activationLifecycle.activate(); assertThat(activationLifecycle.isActive(serviceA)).isTrue(); assertThat(serviceA.state).isEqualTo("ACTIVATED"); activationLifecycle.deactivate(); assertThat(activationLifecycle.isActive(serviceA)).isFalse(); assertThat(serviceA.state).isEqualTo("DEACTIVATED"); }