Java Code Examples for com.google.inject.Injector.getInstance()

The following are Jave code examples for showing how to use getInstance() of the com.google.inject.Injector class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: satisfy   File: SatisfyBaseStepListener.java   View Source Code Vote up 6 votes
public SatisfyBaseStepListener(final File outputDirectory, Injector
        injector) {
    super(outputDirectory, injector);
    this.proxyFactory = WebdriverProxyFactory.getFactory();
    this.testOutcomes = Lists.newArrayList();
    this.currentStepStack = new Stack<TestStep>();
    this.currentGroupStack = new Stack<TestStep>();
    this.outputDirectory = outputDirectory;
    this.inFluentStepSequence = false;
    this.storywideIssues = Lists.newArrayList();
    this.storywideTags = Lists.newArrayList();
    this.webdriverManager = injector.getInstance(WebdriverManager.class);
    this.clock = injector.getInstance(SystemClock.class);
    this.configuration = injector.getInstance(Configuration.class);
    this.screenshotProcessor = injector.getInstance(ScreenshotProcessor
            .class);
}
 
Example 2
Project: SurveyDSL   File: QueryITToXMIConverter.java   View Source Code Vote up 6 votes
public static void convertERDSLtoXMI(String inputM, String outputM) {
	Injector injector = new QueryITStandaloneSetup().createInjectorAndDoEMFRegistration();

	XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);


	URI uri = URI.createURI(inputM);
	

	Resource xtextResource = resourceSet.getResource(uri, true);

	EcoreUtil.resolveAll(xtextResource);

	Resource xmiResource = resourceSet.createResource(URI.createURI(outputM));
	xmiResource.getContents().add(xtextResource.getContents().get(0));
	try {
		xmiResource.save(null);
		System.out.println("Saved " + outputM);
    	System.out.println("QueryIT file converted successfully to XMI");
    	System.out.println("-------------------------------------");
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
Example 3
Project: bromium   File: BaseRecordIntegrationTest.java   View Source Code Vote up 5 votes
@Override
public void runTest() throws IOException {
    /**
     * record
     * -d ./bromium-chrome/bromium-chrome-base/src/test/resources/chromedriver
     * -a /home/hvrigazov/bromium-data/demo-app/configurations/demo.json
     * -u http://localhost:3000
     * -o bromium-core/src/test/resources/dynamic-testCase.json
     */
    File outputFile = createTempFile(pathToTestCase);
    opts.put(DRIVER, chromedriverFile.getAbsolutePath());
    opts.put(APPLICATION, configurationFile.getAbsolutePath());
    opts.put(URL, demoApp.getBaseUrl());
    opts.put(OUTPUT, outputFile.getAbsolutePath());
    opts.put(BROWSER, CHROME);
    opts.put(TIMEOUT, String.valueOf(10));
    opts.put(SCREEN, screen);
    Module defaultModule = new DefaultModule(RECORD, opts);
    Injector originalInjector = Guice.createInjector(defaultModule);
    RecordingSimulatorModule recordingSimulatorModule = new RecordingSimulatorModule(originalInjector);
    recordingSimulatorModule.whenPromptedForRecordingRunnable(this);
    Injector injector = Guice.createInjector(Modules.override(defaultModule).with(recordingSimulatorModule));
    stepsReader = injector.getInstance(Key.get(new TypeLiteral<IOProvider<StepsReader>>() {})).get();
    RecordCommand recordCommand = injector.getInstance(RecordCommand.class);
    recordCommand.run();
    verifyAssertions();
}
 
Example 4
Project: gw4e.project   File: DSLPoliciesStandaloneSetupGenerated.java   View Source Code Vote up 5 votes
public void register(Injector injector) {
	if (!EPackage.Registry.INSTANCE.containsKey("http://www.eclipse.gw4e/dsl/DSLPolicies")) {
		EPackage.Registry.INSTANCE.put("http://www.eclipse.gw4e/dsl/DSLPolicies", DSLPoliciesPackage.eINSTANCE);
	}
	IResourceFactory resourceFactory = injector.getInstance(IResourceFactory.class);
	IResourceServiceProvider serviceProvider = injector.getInstance(IResourceServiceProvider.class);
	
	Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("policies", resourceFactory);
	IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("policies", serviceProvider);
}
 
Example 5
Project: n4js   File: HeadlessCompilerFactory.java   View Source Code Vote up 5 votes
/**
 * Construct a {@link N4HeadlessCompiler} with configuration based on the provided properties.
 *
 * @param properties
 *            preferences.
 */
public static N4HeadlessCompiler createCompilerWithProperties(Properties properties) {
	Injector localinjector = new N4JSHeadlessStandaloneSetup(properties).createInjectorAndDoEMFRegistration();
	N4HeadlessCompiler instance = localinjector.getInstance(N4HeadlessCompiler.class);
	HeadlessExtensionRegistrationHelper headlessExtensionRegistrationHelper = localinjector
			.getInstance(HeadlessExtensionRegistrationHelper.class);
	headlessExtensionRegistrationHelper.registerExtensions();
	return instance;
}
 
Example 6
Project: SemanticRelationsEditor   File: GefPart.java   View Source Code Vote up 5 votes
@PostConstruct
void initUIPane(BorderPane pane){
	// configure application
	Injector injector = Guice.createInjector(createModule());
    domain = injector.getInstance(IDomain.class);
    viewer = domain.getAdapter(AdapterKey.get(IViewer.class, IDomain.CONTENT_VIEWER_ROLE));
    InfiniteCanvas canvas = (InfiniteCanvas)viewer.getCanvas();
    pane.setCenter(canvas);
    canvas.sceneProperty().addListener((observable, oldValue, newValue) -> {
      if (canvas.getScene() != null) {
        domain.activate();
      }
    });
}
 
Example 7
Project: nifi-config   File: ControllerServicesServiceTest.java   View Source Code Vote up 5 votes
@Test
public void updateControllerServiceTest() throws InterruptedException {
    Injector injector = Guice.createInjector(new AbstractModule() {
        protected void configure() {
            bind(ControllerServicesApi.class).toInstance(controllerServicesApiMock);
            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);
        }
    });
    ControllerServiceEntity controllerServiceDisabled = TestUtils.createControllerServiceEntity("id","name");
    controllerServiceDisabled.getComponent().setState(ControllerServiceDTO.StateEnum.DISABLED);
    ControllerServiceEntity controllerServiceEnabled = TestUtils.createControllerServiceEntity("id","name");
    controllerServiceEnabled.getComponent().setState(ControllerServiceDTO.StateEnum.ENABLED);
    ControllerServiceEntity controllerService = TestUtils.createControllerServiceEntity("id","name");

    when(controllerServicesApiMock.getControllerService("id")).thenReturn(controllerServiceDisabled).thenReturn(controllerServiceEnabled);

    when(controllerServicesApiMock.updateControllerService(eq("id"), any()))
            .thenReturn(controllerServiceDisabled)
            .thenReturn(controllerService)
            .thenReturn(controllerServiceEnabled);

    ControllerServicesService controllerServicesService = injector.getInstance(ControllerServicesService.class);

    ControllerServiceDTO component = new ControllerServiceDTO();
    component.getProperties().put("key", "value");
    controllerServicesService.updateControllerService(component, controllerService, false);

    ArgumentCaptor<ControllerServiceEntity> controllerServiceCapture = ArgumentCaptor.forClass(ControllerServiceEntity.class);
    verify(controllerServicesApiMock, times(1)).updateControllerService(eq("id"),controllerServiceCapture.capture());
   // assertEquals("id", controllerServiceCapture.getAllValues().get(0).getComponent().getId());
   // assertEquals(ControllerServiceDTO.StateEnum.DISABLED, controllerServiceCapture.getAllValues().get(0).getComponent().getState());
    assertEquals("id", controllerServiceCapture.getAllValues().get(0).getComponent().getId());
    assertEquals("value", controllerServiceCapture.getAllValues().get(0).getComponent().getProperties().get("key"));
 //   assertEquals("id", controllerServiceCapture.getAllValues().get(2).getComponent().getId());
 //   assertEquals(ControllerServiceDTO.StateEnum.ENABLED, controllerServiceCapture.getAllValues().get(2).getComponent().getState());
}
 
Example 8
Project: Building_Effective_Microservices   File: BaseRibbonTemplate.java   View Source Code Vote up 5 votes
private EurekaClient getEurekaClient(){
	if (eurekaClient==null){
		LifecycleInjectorBuilder builder = LifecycleInjector.builder();
		Injector injector = builder.build().createInjector();
		eurekaClient = injector.getInstance(EurekaClient.class);
	}
	return eurekaClient;
}
 
Example 9
Project: n4js   File: N4JSStandaloneSetupGenerated.java   View Source Code Vote up 5 votes
public void register(Injector injector) {
	IResourceFactory resourceFactory = injector.getInstance(IResourceFactory.class);
	IResourceServiceProvider serviceProvider = injector.getInstance(IResourceServiceProvider.class);
	
	Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("n4js", resourceFactory);
	IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("n4js", serviceProvider);
	Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("n4jsx", resourceFactory);
	IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("n4jsx", serviceProvider);
	Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("js", resourceFactory);
	IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("js", serviceProvider);
	Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("jsx", resourceFactory);
	IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("jsx", serviceProvider);
	Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("n4jsd", resourceFactory);
	IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("n4jsd", serviceProvider);
}
 
Example 10
Project: Xtext_Xtend_HTML_Generator   File: MyDslStandaloneSetupGenerated.java   View Source Code Vote up 5 votes
public void register(Injector injector) {
	if (!EPackage.Registry.INSTANCE.containsKey("http://www.xtext.org/example/mydsl/MyDsl")) {
		EPackage.Registry.INSTANCE.put("http://www.xtext.org/example/mydsl/MyDsl", MyDslPackage.eINSTANCE);
	}
	IResourceFactory resourceFactory = injector.getInstance(IResourceFactory.class);
	IResourceServiceProvider serviceProvider = injector.getInstance(IResourceServiceProvider.class);
	
	Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("mensa", resourceFactory);
	IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("mensa", serviceProvider);
}
 
Example 11
Project: hadoop   File: TestRMWebApp.java   View Source Code Vote up 5 votes
@Test
public void testControllerIndex() {
  Injector injector = WebAppTests.createMockInjector(TestRMWebApp.class,
      this, new Module() {

        @Override
        public void configure(Binder binder) {
          binder.bind(ApplicationACLsManager.class).toInstance(
              new ApplicationACLsManager(new Configuration()));
        }
      });
  RmController c = injector.getInstance(RmController.class);
  c.index();
  assertEquals("Applications", c.get(TITLE, "unknown"));
}
 
Example 12
Project: marathonv5   File: RealMain.java   View Source Code Vote up 5 votes
/**
 * Run Marathon in GUI mode with all bells and whistles.
 *
 * @param licensee
 */
private static void runGUIMode() {
    showSplash();
    String projectDir = getProjectDirectory(argProcessor.getProjectDirectory());
    if (projectDir == null) {
        System.exit(0);
    }
    processMPF(projectDir, false);
    initializeInjector();
    OSUtils.setLogConfiguration(projectDir);
    Injector injector = GuiceInjector.get();
    final DisplayWindow display = injector.getInstance(DisplayWindow.class);
    display.setVisible(true);
}
 
Example 13
Project: nifi-config   File: ConnectionServiceTest.java   View Source Code Vote up 5 votes
@Test
public void waitEmptyQueueForceTest() 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(true);
        }
    });
    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);

    DropRequestEntity dropRequest = new DropRequestEntity();
    dropRequest.setDropRequest(new DropRequestDTO());
    dropRequest.getDropRequest().setId("idDrop");
    dropRequest.getDropRequest().setFinished(true);
    when(flowfileQueuesApiMock.createDropRequest("id")).thenReturn(dropRequest);
    when(flowfileQueuesApiMock.getDropRequest("id", dropRequest.getDropRequest().getId())).thenReturn(dropRequest);
    when(flowfileQueuesApiMock.removeDropRequest("id", dropRequest.getDropRequest().getId())).thenReturn(dropRequest);

    connectionService.waitEmptyQueue(connection);
}
 
Example 14
Project: parabuild-ci   File: DwrGuiceServlet.java   View Source Code Vote up 5 votes
private static void initApplicationScoped()
{
    Injector injector = getInjector();
    for (Key<?> key : DwrScopes.APPLICATION.getKeysInScope())
    {
        // Eagerly create application-scoped object.
        injector.getInstance(key);
    }
}
 
Example 15
Project: mirage-integration   File: TransactionInterceptorTest.java   View Source Code Vote up 5 votes
public void testRollback() throws Exception {
	Injector injector = Guice.createInjector(new TestModule());
	TestDao2 dao = injector.getInstance(TestDao2.class);

	try {
		dao.getCount();
		fail();
	} catch(RuntimeException ignored){
	}

	verify(session, times(1)).begin();
	verify(session, times(1)).rollback();
	verify(session, never()).commit();
}
 
Example 16
Project: galop   File: LoaderImpl.java   View Source Code Vote up 4 votes
private void initStarter(final Configuration configuration) {
    final Injector childInjector = injector.createChildInjector(new LoadedModule(configuration));
    final Starter starter = childInjector.getInstance(Starter.class);
    starter.start();
}
 
Example 17
Project: Saturn   File: KronusStandaloneSetupGenerated.java   View Source Code Vote up 3 votes
public void register(Injector injector) {
if (!EPackage.Registry.INSTANCE.containsKey("http://www.ms.com/qaTools/saturn/Kronus")) {
	EPackage.Registry.INSTANCE.put("http://www.ms.com/qaTools/saturn/Kronus", com.ms.qaTools.saturn.kronus.KronusPackage.eINSTANCE);
}

	org.eclipse.xtext.resource.IResourceFactory resourceFactory = injector.getInstance(org.eclipse.xtext.resource.IResourceFactory.class);
	org.eclipse.xtext.resource.IResourceServiceProvider serviceProvider = injector.getInstance(org.eclipse.xtext.resource.IResourceServiceProvider.class);
	Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("kronus", resourceFactory);
	org.eclipse.xtext.resource.IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("kronus", serviceProvider);
	


}
 
Example 18
Project: bitflyer4j   File: HttpService.java   View Source Code Vote up 3 votes
HttpService(Injector injector) {

        client = injector.getInstance(HttpClient.class);

        gson = injector.getInstance(Gson.class);

        log.debug("Initialized.");

    }
 
Example 19
Project: cryptotrader   File: ResteasyContextListener.java   View Source Code Vote up 3 votes
@Inject
public EndpointImpl(Injector injector) {

    this.gson = new Gson();

    this.trader = injector.getInstance(Trader.class);

    this.configurationProvider = injector.getInstance(ConfigurationProvider.class);

}
 
Example 20
Project: gemoc-studio   File: GExpressionsStandaloneSetupGenerated.java   View Source Code Vote up 3 votes
public void register(Injector injector) {

		org.eclipse.xtext.resource.IResourceFactory resourceFactory = injector.getInstance(org.eclipse.xtext.resource.IResourceFactory.class);
		org.eclipse.xtext.resource.IResourceServiceProvider serviceProvider = injector.getInstance(org.eclipse.xtext.resource.IResourceServiceProvider.class);
		Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("gexpressions", resourceFactory);
		org.eclipse.xtext.resource.IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("gexpressions", serviceProvider);
		


	}