當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。