当前位置: 首页>>代码示例>>Java>>正文


Java Guice类代码示例

本文整理汇总了Java中com.google.inject.Guice的典型用法代码示例。如果您正苦于以下问题:Java Guice类的具体用法?Java Guice怎么用?Java Guice使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Guice类属于com.google.inject包,在下文中一共展示了Guice类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: mainExceptionTest

import com.google.inject.Guice; //导入依赖的package包/类
@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"});
}
 
开发者ID:hermannpencole,项目名称:nifi-config,代码行数:21,代码来源:MainTest.java

示例2: start

import com.google.inject.Guice; //导入依赖的package包/类
@Override
public void start(Stage primaryStage) throws Exception {
    final Injector injector = Guice.createInjector(new WizardModule());

    final URL fxml = WizardMain.class.getClassLoader().getResource("wizard-fxml/Wizard.fxml");

    if (fxml != null) {
        final Parent p = FXMLLoader.load(fxml,
                null,
                new JavaFXBuilderFactory(),
                injector::getInstance
        );

        final Scene scene = new Scene(p);

        primaryStage.setScene(scene);
        primaryStage.setWidth(800);
        primaryStage.setHeight(600);
        primaryStage.setTitle("Java gEneric DAta Integration (JedAI) Toolkit");

        primaryStage.show();
    }
}
 
开发者ID:scify,项目名称:jedai-ui,代码行数:24,代码来源:WizardMain.java

示例3: getByIdOutputTest

import com.google.inject.Guice; //导入依赖的package包/类
@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());
}
 
开发者ID:hermannpencole,项目名称:nifi-config,代码行数:20,代码来源:PortServiceTest.java

示例4: doWork

import com.google.inject.Guice; //导入依赖的package包/类
@Override
protected Injector doWork() throws Exception
{
	long start = System.currentTimeMillis();
	Iterable<URL> localClassPath = privatePluginService.getLocalClassPath(pluginId);
	final ClassLoader classLoader = privatePluginService.getClassLoader(pluginId);
	Collection<Parameter> params = extension.getParameters("class");
	List<Module> modules = new ArrayList<Module>();
	for( Parameter param : params )
	{
		Module module = (Module) privatePluginService.getBean(pluginId, param.valueAsString());
		modules.add(module);
	}

	modules.add(new ScannerModule(privatePluginService, classLoader, localClassPath, getBeanCheckers()));
	modules.add(new Jsr250Module());
	injector = Guice.createInjector(new ExternalProviders(getDependents(), modules));
	long end = System.currentTimeMillis();
	LOGGER.info("Guice module for " + pluginId + " took:" + (end - start));
	return injector;
}
 
开发者ID:equella,项目名称:Equella,代码行数:22,代码来源:GuicePlugin.java

示例5: testSingletonInScopeProvider

import com.google.inject.Guice; //导入依赖的package包/类
@Test
public void testSingletonInScopeProvider() {
  final Injector injector = Guice.createInjector(new AbstractModule() {
    @Override
    protected void configure() {
      this.bind(SingletonThing.class).in(LazySingleton.SCOPE);
    }
  });

  assertEquals(SingletonThing.CONSTRUCTION_COUNT.get(), 0);
  final SingletonThingProvider provider = injector.getInstance(SingletonThingProvider.class);
  assertEquals(SingletonThing.CONSTRUCTION_COUNT.get(), 0);
  final SingletonThing a = provider.provider.get();
  assertEquals(SingletonThing.CONSTRUCTION_COUNT.get(), 1);
  final SingletonThing b = provider.provider.get();
  assertEquals(SingletonThing.CONSTRUCTION_COUNT.get(), 1);
  assertSame(a, b);
}
 
开发者ID:KyoriPowered,项目名称:violet,代码行数:19,代码来源:LazyTest.java

示例6: setStateAlreadyTest

import com.google.inject.Guice; //导入依赖的package包/类
@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());
}
 
开发者ID:hermannpencole,项目名称:nifi-config,代码行数:17,代码来源:ProcessorServiceTest.java

示例7: testSingletonBoundScopeProvider

import com.google.inject.Guice; //导入依赖的package包/类
@Test
public void testSingletonBoundScopeProvider() {
  final Injector injector = Guice.createInjector(new AbstractModule() {
    @Override
    protected void configure() {
      this.bindScope(LazySingleton.class, LazySingleton.SCOPE);
    }
  });

  assertEquals(AnnotatedSingletonThing.CONSTRUCTION_COUNT.get(), 0);
  final AnnotatedSingletonThingProvider provider = injector.getInstance(AnnotatedSingletonThingProvider.class);
  assertEquals(AnnotatedSingletonThing.CONSTRUCTION_COUNT.get(), 0);
  final AnnotatedSingletonThing ap = provider.provider.get();
  assertEquals(AnnotatedSingletonThing.CONSTRUCTION_COUNT.get(), 1);
  final AnnotatedSingletonThing bp = provider.provider.get();
  assertEquals(AnnotatedSingletonThing.CONSTRUCTION_COUNT.get(), 1);
  assertSame(ap, bp);
}
 
开发者ID:KyoriPowered,项目名称:violet,代码行数:19,代码来源:LazyTest.java

示例8: mainUpdateWithPasswordTest

import com.google.inject.Guice; //导入依赖的package包/类
@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);
}
 
开发者ID:hermannpencole,项目名称:nifi-config,代码行数:23,代码来源:MainTest.java

示例9: ifCommmandIsInvalidResponseExceptionIsThrown

import com.google.inject.Guice; //导入依赖的package包/类
@Test
public void ifCommmandIsInvalidResponseExceptionIsThrown() throws IOException, URISyntaxException {
    String command = "invalid";
    Map<String, Object> opts = new HashMap<>();
    opts.put(BROWSER, CHROME);
    opts.put(DRIVER, chromedriverFile.getAbsolutePath());
    opts.put(APPLICATION, configurationFile.getAbsolutePath());
    opts.put(URL, localhostUrl);
    opts.put(CASE, caseFile.getAbsolutePath());
    opts.put(SCREEN, screenString);
    opts.put(TIMEOUT, timeoutString);
    opts.put(PRECISION, precisionString);
    Module module = new DefaultModule(command, opts);
    Injector injector = Guice.createInjector(module);

    try {
        IOProvider<ResponseFilter> instance = injector.getInstance(new Key<IOProvider<ResponseFilter>>() {});
        instance.get();
    } catch (ProvisionException e) {
        assertTrue(e.getCause() instanceof NoSuchCommandException);
    }
}
 
开发者ID:hristo-vrigazov,项目名称:bromium,代码行数:23,代码来源:DefaultModuleTest.java

示例10: setUp

import com.google.inject.Guice; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
  String ip = esContainer.getContainerIpAddress();
  Integer transportPort = esContainer.getMappedPort(9300);
  MapConfiguration memoryParams = new MapConfiguration(new HashMap<>());
  memoryParams.setProperty(CONFIG_ES_CLUSTER_HOST, ip);
  memoryParams.setProperty(CONFIG_ES_CLUSTER_PORT, transportPort);
  memoryParams.setProperty(CONFIG_ES_CLUSTER_NAME, "elasticsearch");
  Injector injector = Guice.createInjector(
      Modules.override(new ElasticSearchModule()).with(
          binder -> {
            binder.bind(Configuration.class).toInstance(memoryParams);
          }
      )
  );
  transportClientProvider = injector.getInstance(TransportClientProvider.class);
}
 
开发者ID:email2liyang,项目名称:grpc-mate,代码行数:18,代码来源:TransportClientProviderTest.java

示例11: testNotExposed

import com.google.inject.Guice; //导入依赖的package包/类
@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");
}
 
开发者ID:KyoriPowered,项目名称:violet,代码行数:25,代码来源:DuplexTest.java

示例12: canCreateRecordBrowserProvider

import com.google.inject.Guice; //导入依赖的package包/类
@Test
public void canCreateRecordBrowserProvider() throws IOException, URISyntaxException {
    String command = RECORD;
    Map<String, Object> opts = new HashMap<>();
    opts.put(DRIVER, chromedriverFile.getAbsolutePath());
    opts.put(APPLICATION, configurationFile.getAbsolutePath());
    opts.put(URL, localhostUrl);
    opts.put(OUTPUT, "output.json");
    opts.put(BROWSER, CHROME);
    opts.put(TIMEOUT, timeoutString);
    opts.put(SCREEN, screenString);
    Module module = new DefaultModule(command, opts);
    Injector injector = Guice.createInjector(module);
    IOURIProvider<RecordBrowser> instance = injector.getInstance(new Key<IOURIProvider<RecordBrowser>>() {});
    RecordBrowser recordBrowser = instance.get();

    // cleanup
    recordBrowser.cleanUp();
}
 
开发者ID:hristo-vrigazov,项目名称:bromium,代码行数:20,代码来源:DefaultModuleTest.java

示例13: ifCommmandIsInvalidExceptionIsThrown

import com.google.inject.Guice; //导入依赖的package包/类
@Test
public void ifCommmandIsInvalidExceptionIsThrown() throws IOException, URISyntaxException {
    String command = "invalid";
    Map<String, Object> opts = new HashMap<>();
    opts.put(BROWSER, CHROME);
    opts.put(DRIVER, chromedriverFile.getAbsolutePath());
    opts.put(APPLICATION, configurationFile.getAbsolutePath());
    opts.put(URL, localhostUrl);
    opts.put(CASE, caseFile.getAbsolutePath());
    opts.put(SCREEN, screenString);
    opts.put(TIMEOUT, timeoutString);
    opts.put(PRECISION, precisionString);
    Module module = new DefaultModule(command, opts);
    Injector injector = Guice.createInjector(module);

    try {
        RequestFilter instance = injector.getInstance(
                Key.get(new TypeLiteral<IOProvider<RequestFilter>>() {})).get();
    } catch (ProvisionException e) {
        assertTrue(e.getCause() instanceof NoSuchCommandException);
    }
}
 
开发者ID:hristo-vrigazov,项目名称:bromium,代码行数:23,代码来源:DefaultModuleTest.java

示例14: setup

import com.google.inject.Guice; //导入依赖的package包/类
@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);
}
 
开发者ID:alphagov,项目名称:verify-hub,代码行数:24,代码来源:StateControllerFactoryTest.java

示例15: run

import com.google.inject.Guice; //导入依赖的package包/类
@Override
public void run(Config config, Environment environment) throws UnsupportedEncodingException {
    injector = Guice.createInjector(new StroomStatsServiceModule(config, hibernateBundle.getSessionFactory()));
    injector.getInstance(ServiceDiscoveryManager.class);

    if(config.isLogRequestsAndResponses()) {
        environment.jersey().register(new LoggingFeature(java.util.logging.Logger.getLogger(
                getClass().getName()),
                Level.OFF,
                LoggingFeature.Verbosity.PAYLOAD_TEXT,
                8192));
    }

    configureAuthentication(environment, injector.getInstance(JwtVerificationFilter.class));
    registerResources(environment);
    registerTasks(environment);
    HealthChecks.register(environment, injector);
    registerManagedObjects(environment);
}
 
开发者ID:gchq,项目名称:stroom-stats,代码行数:20,代码来源:App.java


注:本文中的com.google.inject.Guice类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。