Java 类com.google.inject.AbstractModule 实例源码

项目:rotabuilder    文件:DomainApplication.java   
@Override
protected Module newIsisWicketModule() {
    final Module isisDefaults = super.newIsisWicketModule();

    final Module overrides = new AbstractModule() {
        @Override
        protected void configure() {
            bind(ComponentFactoryRegistrar.class).to(MyComponentFactoryRegistrar.class);

            bind(String.class).annotatedWith(Names.named("applicationName")).toInstance("RotaBuilder");
            bind(String.class).annotatedWith(Names.named("applicationCss")).toInstance("css/application.css");
            bind(String.class).annotatedWith(Names.named("applicationJs")).toInstance("scripts/application.js");
            bind(String.class).annotatedWith(Names.named("welcomeMessage")).toInstance(readLines(getClass(), "welcome.html"));
            bind(String.class).annotatedWith(Names.named("aboutMessage")).toInstance("RotaBuilder");
            bind(InputStream.class).annotatedWith(Names.named("metaInfManifest")).toProvider(
                    Providers.of(getServletContext().getResourceAsStream("/META-INF/MANIFEST.MF")));
            // if uncommented, then overrides isis.appManifest in config file.
            // bind(AppManifest.class).toInstance(new DomainAppAppManifest());
        }
    };

    return Modules.override(isisDefaults).with(overrides);
}
项目:Pogamut3    文件:UT2004TCServerModule.java   
@Override
protected void configureModules() {
    super.configureModules();
    addModule(new AbstractModule() {

        @Override
        public void configure() {
            bind(IWorldMessageTranslator.class).to(ServerFSM.class);
            bind(IWorldView.class).to(IVisionWorldView.class);
            bind(IVisionWorldView.class).to(UT2004WorldView.class);
            bind(ComponentDependencies.class).annotatedWith(Names.named(UT2004WorldView.WORLDVIEW_DEPENDENCY)).toProvider(worldViewDependenciesProvider);
            bind(IAgent.class).to(IWorldServer.class);
            bind(IWorldServer.class).to(IUT2004Server.class);
            bind(IUT2004Server.class).to(UT2004TCServer.class);
        }

    });
}
项目:Pogamut3    文件:UT2004HSServerModule.java   
@Override
protected void configureModules() {
    super.configureModules();
    addModule(new AbstractModule() {

        @Override
        public void configure() {
            bind(IWorldMessageTranslator.class).to(ServerFSM.class);
            bind(IWorldView.class).to(IVisionWorldView.class);
            bind(IVisionWorldView.class).to(UT2004WorldView.class);
            bind(ComponentDependencies.class).annotatedWith(Names.named(UT2004WorldView.WORLDVIEW_DEPENDENCY)).toProvider(worldViewDependenciesProvider);
            bind(IAgent.class).to(IWorldServer.class);
            bind(IWorldServer.class).to(IUT2004Server.class);
            bind(IUT2004Server.class).to(UT2004HSServer.class);
        }

    });
}
项目:Pogamut3    文件:HSObserverModule.java   
@Override
protected void configureModules() {
    super.configureModules();
    addModule(new AbstractModule() {

        @Override
        public void configure() {
            bind(IWorldMessageTranslator.class).to(ObserverFSM.class);
            bind(IWorldView.class).to(IVisionWorldView.class);
            bind(IVisionWorldView.class).to(UT2004WorldView.class);
            bind(ComponentDependencies.class).annotatedWith(Names.named(UT2004WorldView.WORLDVIEW_DEPENDENCY)).toProvider(worldViewDependenciesProvider);
            bind(IAgent.class).to(IUT2004Observer.class);

            // THIS tells guice it should instantiate our class and not default one
            bind(IUT2004Observer.class).to(HSObserver.class); 
        }

    });
}
项目:Pogamut3    文件:UT2004TagServerModule.java   
@Override
protected void configureModules() {
    super.configureModules();
    addModule(new AbstractModule() {

        @Override
        public void configure() {
            bind(IWorldMessageTranslator.class).to(ServerFSM.class);
            bind(IWorldView.class).to(IVisionWorldView.class);
            bind(IVisionWorldView.class).to(UT2004WorldView.class);
            bind(ComponentDependencies.class).annotatedWith(Names.named(UT2004WorldView.WORLDVIEW_DEPENDENCY)).toProvider(worldViewDependenciesProvider);
            bind(IAgent.class).to(IWorldServer.class);
            bind(IWorldServer.class).to(IUT2004Server.class);
            bind(IUT2004Server.class).to(UT2004TagServer.class);
        }

    });
}
项目:Pogamut3    文件:UT2004VIPServerModule.java   
@Override
protected void configureModules() {
    super.configureModules();
    addModule(new AbstractModule() {

        @Override
        public void configure() {
            bind(IWorldMessageTranslator.class).to(ServerFSM.class);
            bind(IWorldView.class).to(IVisionWorldView.class);
            bind(IVisionWorldView.class).to(UT2004WorldView.class);
            bind(ComponentDependencies.class).annotatedWith(Names.named(UT2004WorldView.WORLDVIEW_DEPENDENCY)).toProvider(worldViewDependenciesProvider);
            bind(IAgent.class).to(IWorldServer.class);
            bind(IWorldServer.class).to(IUT2004Server.class);
            bind(IUT2004Server.class).to(UT2004VIPServer.class);
        }

    });
}
项目:Pogamut3    文件:CSObserverModule.java   
@Override
protected void configureModules() {
    super.configureModules();
    addModule(new AbstractModule() {

        @Override
        public void configure() {
            bind(IWorldMessageTranslator.class).to(ObserverFSM.class);
            bind(IWorldView.class).to(IVisionWorldView.class);
            bind(IVisionWorldView.class).to(UT2004WorldView.class);
            bind(ComponentDependencies.class).annotatedWith(Names.named(UT2004WorldView.WORLDVIEW_DEPENDENCY)).toProvider(worldViewDependenciesProvider);
            bind(IAgent.class).to(IUT2004Observer.class);

            // THIS tells guice it should instantiate our class and not default one
            bind(IUT2004Observer.class).to(CSObserver.class); 
        }

    });
}
项目:Pogamut3    文件:GuiceRemoteAgentModule.java   
@Override
protected void configureModules() {
    super.configureModules();

    addModule(
            new AbstractModule() {

                @Override
                protected void configure() {
                    bind(ICommandSerializer.class).to(StringCommandSerializer.class);
                    bind(IAct.class).to(Act.class);
                    bind(IWorldReaderProvider.class).to(IWorldConnection.class);
                    bind(IWorldWriterProvider.class).to(IWorldConnection.class);
                }               

            }
        );      
}
项目:Pogamut3    文件:UT2004CommunicationModule.java   
@Override
protected void configureModules() {
    super.configureModules();
    addModule(new AbstractModule() {

        @Override
        public void configure() {
            bind(IWorldConnection.class).to(SocketConnection.class);
            bind(ComponentDependencies.class).annotatedWith(Names.named(SocketConnection.CONNECTION_DEPENDENCY)).toProvider(connectionDependenciesProvider);
               bind(ISocketConnectionAddress.class).annotatedWith(Names.named(SocketConnection.CONNECTION_ADDRESS_DEPENDENCY)).toProvider((Provider<ISocketConnectionAddress>) getAddressProvider());
            bind(IWorldMessageParser.class).to(UT2004Parser.class);
            bind(ItemTypeTranslator.class).to(UT2004ItemTypeTranslator.class);
            bind(IYylex.class).to(IUT2004Yylex.class);
            bind(IUT2004Yylex.class).to(Yylex.class);
            bind(IYylexObserver.class).to(IYylexObserver.LogObserver.class);
            bind(UT2004AgentParameters.class).toProvider(getAgentParamsProvider());
        }

    });
}
项目:Pogamut3    文件:UT2004ObserverModule.java   
@Override
protected void configureModules() {
    super.configureModules();
    addModule(new AbstractModule() {

        @Override
        public void configure() {
            bind(IWorldMessageTranslator.class).to(ObserverFSM.class);
            bind(IWorldView.class).to(IVisionWorldView.class);
            bind(IVisionWorldView.class).to(UT2004WorldView.class);
            bind(ComponentDependencies.class).annotatedWith(Names.named(UT2004WorldView.WORLDVIEW_DEPENDENCY)).toProvider(worldViewDependenciesProvider);
            bind(IAgent.class).to(IUT2004Observer.class);
            bind(IUT2004Observer.class).to(UT2004Observer.class);               
        }

    });
}
项目:Pogamut3    文件:UT2004ServerModule.java   
@Override
protected void configureModules() {
    super.configureModules();
    addModule(new AbstractModule() {

        @Override
        public void configure() {
            bind(IWorldMessageTranslator.class).to(ServerFSM.class);
            bind(IWorldView.class).to(IVisionWorldView.class);
            bind(IVisionWorldView.class).to(UT2004WorldView.class);
            bind(ComponentDependencies.class).annotatedWith(Names.named(UT2004WorldView.WORLDVIEW_DEPENDENCY)).toProvider(worldViewDependenciesProvider);
            bind(IAgent.class).to(IWorldServer.class);
            bind(IWorldServer.class).to(IUT2004Server.class);
            bind(IUT2004Server.class).to(UT2004Server.class);               
        }

    });
}
项目:Pogamut3    文件:UT2004BotModule.java   
@Override
protected void configureModules() {
    super.configureModules();
    addModule(new AbstractModule() {

        @Override
        public void configure() {
            bind(IWorldMessageTranslator.class).to(BotFSM.class);
            bind(IWorldView.class).to(IVisionWorldView.class);
            bind(IVisionWorldView.class).to(ILockableVisionWorldView.class);
            bind(ILockableWorldView.class).to(ILockableVisionWorldView.class);
            bind(ILockableVisionWorldView.class).to(UT2004SyncLockableWorldView.class);
            bind(ComponentDependencies.class).annotatedWith(Names.named(UT2004SyncLockableWorldView.WORLDVIEW_DEPENDENCY)).toProvider(worldViewDependenciesProvider);
            bind(IAgent.class).to(IAgent3D.class);
            bind(IAgent3D.class).to(IUT2004Bot.class);
            bind(IUT2004Bot.class).to(UT2004Bot.class);
            if (botControllerClass != null) {
                bind(IUT2004BotController.class).to(botControllerClass);
            }
            bind(UT2004BotParameters.class).toProvider((Provider<? extends UT2004BotParameters>) getAgentParamsProvider());
        }

    });
}
项目:dragoman    文件:MongoCannedDatasetsWriterTest.java   
@BeforeEach
public void setUp() {
  Injector injector =
      Guice.createInjector(
          Modules.override(
                  new DatasetModule(), new CannedDatasetsModule(), new ConfigurationModule())
              .with(
                  new MongoOverrideModule(),
                  new AbstractModule() {
                    @Override
                    protected void configure() {
                      bind(CannedDatasetsLoader.class)
                          .toInstance(Mockito.mock(CannedDatasetsLoader.class));
                    }
                  }));
  injector.injectMembers(this);

  when(mongoProvider.provide()).thenReturn(getMongoClient());
}
项目:tac-kbp-eal    文件:DerivedQuerySelector2016.java   
private static void trueMain(String[] argv) throws IOException {
  final Parameters params = Parameters.loadSerifStyle(new File(argv[0]));
  Guice.createInjector(new AbstractModule() {
    @Override
    protected void configure() {
      try {
        bind(EREToKBPEventOntologyMapper.class)
            .toInstance(EREToKBPEventOntologyMapper.create2016Mapping());
      } catch (IOException ioe) {
        throw new TACKBPEALException(ioe);
      }
    }

    @Provides
    ERELoader ereLoader() {
      return ERELoader.builder().build();
    }
  }).getInstance(DerivedQuerySelector2016.class)
      .go(params.copyNamespace("com.bbn.tac.eal"));
}
项目:beadledom    文件:BeadledomLifecycleInjectorBuilder.java   
@Override
public LifecycleInjector createInjector() {
  final LifecycleShutdownManager shutdownManager = new LifecycleShutdownManagerImpl();

  List<Module> fullModules = new ArrayList<Module>();
  fullModules.addAll(modules);
  fullModules.add(new BeadledomLifecycleModule());
  fullModules.add(new ShutdownHookModule());
  fullModules.add(new AbstractModule() {
    @Override
    protected void configure() {
      bind(LifecycleShutdownManager.class).toInstance(shutdownManager);
      requestInjection(BeadledomLifecycleInjectorBuilder.this);
    }
  });

  Injector injector = Guice.createInjector(fullModules);
  return BeadledomLifecycleInjector.create(injector, shutdownManager);
}
项目:verify-hub    文件:StateControllerFactoryTest.java   
@Before
public void setup() {
    Injector injector = Guice.createInjector(
            Modules.override(new PolicyModule()
            ).with(new AbstractModule() {
                @Override
                protected void configure() {
                    bind(EventSinkProxy.class).toInstance(mock(EventSinkProxy.class));
                    bind(IdentityProvidersConfigProxy.class).toInstance(mock(IdentityProvidersConfigProxy.class));
                    bind(Client.class).toInstance(mock(Client.class));
                    bind(Environment.class).toInstance(mock(Environment.class));
                    bind(PolicyConfiguration.class).toInstance(aPolicyConfiguration().build());
                    InfinispanCacheManager infinispanCacheManager = anInfinispanCacheManager().build(InfinispanJunitRunner.EMBEDDED_CACHE_MANAGER);
                    bind(InfinispanCacheManager.class).toInstance(infinispanCacheManager);
                    bind(EventSinkHubEventLogger.class).toInstance(mock(EventSinkHubEventLogger.class));
                    bind(JsonClient.class).annotatedWith(Names.named("samlSoapProxyClient")).toInstance(mock(JsonClient.class));
                    bind(JsonClient.class).toInstance(mock(JsonClient.class));
                }
            })
    );

    factory = new StateControllerFactory(injector);
}
项目:outland    文件:IdempotencyCheckerTest.java   
@Test
public void testCheck() {

  RedisConfiguration rc = new RedisConfiguration();
  rc.name = "outland_feature_idempotency_check_redis";
  RedisServersConfiguration rsc = new RedisServersConfiguration();
  rsc.servers = Lists.newArrayList(rc);

  final Injector injector = Guice.createInjector(
      new RedisModule(rsc),
      new AbstractModule() {
        @Override protected void configure() {
          bind(IdempotencyChecker.class).to(IdempotencyCheckerRedis.class).asEagerSingleton();
        }
      }
  );

  final IdempotencyChecker checker = injector.getInstance(IdempotencyChecker.class);

  final String key = Ulid.random();
  assertFalse(checker.seen(key));
  assertTrue(checker.seen(key));

  assertFalse(checker.seen(Ulid.random()));
  assertFalse(checker.seen(Ulid.random()));
}
项目:crnk-framework    文件:DropwizardService.java   
@Override
public void initialize(Bootstrap<DropwizardConfiguration> bootstrap) {
    guiceBundle = GuiceBundle.<DropwizardConfiguration>newBuilder()
            .addModule(new AbstractModule() {

                @Provides
                public MongoManaged mongoManaged(DropwizardConfiguration configuration) throws Exception {
                    return new MongoManaged(configuration.mongo);
                }

                @Override
                protected void configure() {
                    bind(ProjectRepository.class);
                    bind(TaskRepository.class);
                    bind(TaskToProjectRepository.class);
                }

            })
            .setConfigClass(DropwizardConfiguration.class)
            .build();

    bootstrap.addBundle(guiceBundle);
}
项目:violet    文件:DuplexTest.java   
@Test
public void testNotExposed() {
  final Injector injector = Guice.createInjector(new AbstractModule() {
    @Override
    protected void configure() {
      DuplexBinder.create(this.binder()).install(new DuplexModule() {
        @Override
        protected void configure() {
          this.bind(Thing.class).annotatedWith(Names.named("r0")).toInstance(new Thing("r0"));
        }
      });
    }
  });
  try {
    injector.getInstance(ShouldNotWork.class);
  } catch(final ConfigurationException expected) {
    final String message = expected.getMessage();
    if(message.contains("It was already configured on one or more child injectors or private modules")
      && message.contains("If it was in a PrivateModule, did you forget to expose the binding?")) {
      return;
    }
  }
  fail("should not be exposed");
}
项目:datarouter    文件:ModuleFactory.java   
@Override
public Module createModule(ITestContext context, Class<?> testClass){

    Module globalModule = new AbstractModule(){

        @Override
        protected void configure(){
            for(Module module : modules){
                install(module);
            }
        }

    };
    Iterable<? extends Module> overriders = getOverriders();
    return Modules.override(globalModule).with(overriders);
}
项目:clustercode    文件:CancelTaskIT.java   
@Before
public void setUp() throws Exception {
    Properties properties = getMinimalConfiguration();
    injector = Guice.createInjector(Arrays.asList(
        new ApiModule(properties),
        new ClusterModule(),
        new TranscodeModule(properties),
        new ProcessModule(),
        new GlobalModule(),
        new AbstractModule() {
            @Override
            protected void configure() {
                bind(MediaScanSettings.class).to(MediaScanSettingsImpl.class);
                Names.bindProperties(binder(), properties);
            }
        }
    ));

    injector.getInstance(ClusterService.class).joinCluster();
}
项目:cryptotrader    文件:ResteasyContextListenerTest.java   
@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);
        }
    }));

}
项目:Proyecto2017Seguros    文件:PacinetesApplication.java   
@Override
 protected Module newIsisWicketModule() {
     final Module isisDefaults = super.newIsisWicketModule();

     final Module overrides = new AbstractModule() {
         @Override
         protected void configure() {
             bind(String.class).annotatedWith(Names.named("applicationName")).toInstance("SiGeSe");
             bind(String.class).annotatedWith(Names.named("applicationCss")).toInstance("css/application.css");
             bind(String.class).annotatedWith(Names.named("applicationJs")).toInstance("scripts/application.js");
    bind(String.class).annotatedWith(Names.named("brandLogoSignin")).toInstance("/about/images/login.png");
    bind(String.class).annotatedWith(Names.named("welcomeMessage")).toInstance(readLines(getClass(), "welcome.html"));
    bind(String.class).annotatedWith(Names.named("aboutMessage")).toInstance("SiGeSe");
    bind(InputStream.class).annotatedWith(Names.named("metaInfManifest")).toProvider(Providers.of(getServletContext().getResourceAsStream("/META-INF/MANIFEST.MF")));
}
     };

     return Modules.override(isisDefaults).with(overrides);
 }
项目:webserver    文件:BeanParamIntegrationTest.java   
@BeforeClass
public static void initialize() throws Exception {
  injector = Guice.createInjector(new AbstractModule() {
    @Override
    protected void configure() {
      bind(BookResource.class);
    }

    @DefaultConnector
    @Provides
    Configurator configurator() {
      return () -> 0; // port
    }
  }, new WebServerModule(), new HTTPConnectorModule());

  client = ClientBuilder.newClient();
  server = injector.getInstance(Server.class);
  server.start();
}
项目:nifi-config    文件:MainTest.java   
@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"));
}
项目:nifi-config    文件:MainTest.java   
@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"));
}
项目:nifi-config    文件:MainTest.java   
@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);
}
项目:nifi-config    文件:MainTest.java   
@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);
}
项目:nifi-config    文件:MainTest.java   
@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");
}
项目:nifi-config    文件:MainTest.java   
@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"});
}
项目:nifi-config    文件:ProcessorServiceTest.java   
@Test
public void setStateAlreadyTest() {
    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.RUNNING);
    processorService.setState(processor, ProcessorDTO.StateEnum.RUNNING);
    verify(processorsApiMock, never()).updateProcessor(anyString(), anyObject());
}
项目:nifi-config    文件:ProcessorServiceTest.java   
@Test
public void setStateTest() {
    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() )).thenReturn(processorResponse);
    when(processorsApiMock.getProcessor(eq("id"))).thenReturn(processorResponse);

    processorService.setState(processor, ProcessorDTO.StateEnum.RUNNING);
    ArgumentCaptor<ProcessorEntity> processorEntity = ArgumentCaptor.forClass(ProcessorEntity.class);
    verify(processorsApiMock).updateProcessor(eq("id"), processorEntity.capture());
    assertEquals("id", processorEntity.getValue().getComponent().getId());
    assertEquals( ProcessorDTO.StateEnum.RUNNING, processorEntity.getValue().getComponent().getState());
}
项目:nifi-config    文件:ProcessorServiceTest.java   
@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);
}
项目:nifi-config    文件:ConnectionServiceTest.java   
@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);
}
项目:nifi-config    文件:ConnectionServiceTest.java   
@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);
}
项目:nifi-config    文件:PortServiceTest.java   
/**
 * 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 &#39;Authorization: Bearer &lt;token&gt;&#39;.
 *
 * @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());
}
项目:nifi-config    文件:PortServiceTest.java   
@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());
}
项目:nifi-config    文件:PortServiceTest.java   
@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);
    portService.setState(port, PortDTO.StateEnum.STOPPED);
    verify(inputPortsApiMock,never()).updateInputPort(eq("id"), any());
    verify(outputPortsApiMock,never()).updateOutputPort(eq("id"), any());
}
项目:ninja-vertx-standalone    文件:NinjaVertxBootstrap.java   
protected void bindVertxRoutes() throws Exception {

        String applicationRoutesClassName
                = resolveApplicationClassName(CONF_VERTX_ROUTES);

        if (doesClassExist(applicationRoutesClassName)) {

            final Class<? extends ApplicationVertxRoutes> vertxRoutes =
                    (Class<? extends ApplicationVertxRoutes>) Class.forName(applicationRoutesClassName);

            addModule(new AbstractModule() {
                @Override
                protected void configure() {
                    bind(Vertx.class).toInstance(vertxInitializer.getVertx());
                    resolveVertxHandlers().forEach(this::bind);
                    bind(ApplicationVertxRoutes.class).to(vertxRoutes).in(Singleton.class);
                }
            });

        }

    }
项目:StopCozi-api    文件:Server.java   
@Override
public void initialize(Bootstrap<ServerConfiguration> bootstrap) {
    bootstrap.addBundle(hibernateBundle);

    bootstrap.addBundle(new AssetsBundle("/swagger-spec", "/api-spec", null));

    bootstrap.addBundle(GuiceBundle.<ServerConfiguration>newBuilder()
        .addModule(new AbstractModule(){
            @Override protected void configure() {}
            @Provides SessionFactory sessionFactoryProvider() { return hibernateBundle.getSessionFactory();}
        })
        .setConfigClass(ServerConfiguration.class)
        .enableAutoConfig(getClass().getPackage().getName())
        .build(Stage.DEVELOPMENT)
    );

    bootstrap.addBundle(new Java8Bundle());

    // Enable variable substitution with environment variables
    bootstrap.setConfigurationSourceProvider(
        new SubstitutingSourceProvider(bootstrap.getConfigurationSourceProvider(),
            new EnvironmentVariableSubstitutor(false)
        )
    );
}