Search in sources :

Example 31 with Injector

use of com.google.inject.Injector in project hadoop by apache.

the class TestWebAppTests method testInstances.

@Test
public void testInstances() throws Exception {
    Injector injector = WebAppTests.createMockInjector(this);
    HttpServletRequest req = injector.getInstance(HttpServletRequest.class);
    HttpServletResponse res = injector.getInstance(HttpServletResponse.class);
    String val = req.getParameter("foo");
    PrintWriter out = res.getWriter();
    out.println("Hello world!");
    logInstances(req, res, out);
    assertSame(req, injector.getInstance(HttpServletRequest.class));
    assertSame(res, injector.getInstance(HttpServletResponse.class));
    assertSame(this, injector.getInstance(TestWebAppTests.class));
    verify(req).getParameter("foo");
    verify(res).getWriter();
    verify(out).println("Hello world!");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Injector(com.google.inject.Injector) HttpServletResponse(javax.servlet.http.HttpServletResponse) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 32 with Injector

use of com.google.inject.Injector in project hadoop by apache.

the class TestWebAppTests method testRequestScope.

@Test
public void testRequestScope() {
    Injector injector = WebAppTests.createMockInjector(this);
    assertSame(injector.getInstance(ScopeTest.class), injector.getInstance(ScopeTest.class));
}
Also used : Injector(com.google.inject.Injector) Test(org.junit.Test)

Example 33 with Injector

use of com.google.inject.Injector in project hadoop by apache.

the class TestAHSWebApp method testAppPageNaturalSortType.

@Test
public void testAppPageNaturalSortType() throws Exception {
    Injector injector = WebAppTests.createMockInjector(ApplicationBaseProtocol.class, mockApplicationHistoryClientService(1, 5, 1));
    AppPage appPageInstance = injector.getInstance(AppPage.class);
    appPageInstance.render();
    WebAppTests.flushOutput(injector);
    Map<String, String> moreParams = appPageInstance.context().requestContext().moreParams();
    String attemptsTableColumnsMeta = moreParams.get("ui.dataTables.attempts.init");
    Assert.assertTrue(attemptsTableColumnsMeta.indexOf("natural") != -1);
}
Also used : Injector(com.google.inject.Injector) Test(org.junit.Test)

Example 34 with Injector

use of com.google.inject.Injector in project hadoop by apache.

the class TestAHSWebApp method testAppControllerIndex.

@Test
public void testAppControllerIndex() throws Exception {
    ApplicationHistoryManager ahManager = mock(ApplicationHistoryManager.class);
    Injector injector = WebAppTests.createMockInjector(ApplicationHistoryManager.class, ahManager);
    AHSController controller = injector.getInstance(AHSController.class);
    controller.index();
    Assert.assertEquals("Application History", controller.get(TITLE, "unknown"));
}
Also used : ApplicationHistoryManager(org.apache.hadoop.yarn.server.applicationhistoryservice.ApplicationHistoryManager) Injector(com.google.inject.Injector) Test(org.junit.Test)

Example 35 with Injector

use of com.google.inject.Injector in project hadoop by apache.

the class TestAHSWebApp method testAppAttemptPage.

@Test
public void testAppAttemptPage() throws Exception {
    Injector injector = WebAppTests.createMockInjector(ApplicationBaseProtocol.class, mockApplicationHistoryClientService(1, 1, 5));
    AppAttemptPage appAttemptPageInstance = injector.getInstance(AppAttemptPage.class);
    appAttemptPageInstance.render();
    WebAppTests.flushOutput(injector);
    appAttemptPageInstance.set(YarnWebParams.APPLICATION_ATTEMPT_ID, ApplicationAttemptId.newInstance(ApplicationId.newInstance(0, 1), 1).toString());
    appAttemptPageInstance.render();
    WebAppTests.flushOutput(injector);
}
Also used : Injector(com.google.inject.Injector) Test(org.junit.Test)

Aggregations

Injector (com.google.inject.Injector)2117 AbstractModule (com.google.inject.AbstractModule)624 Test (org.junit.Test)513 Module (com.google.inject.Module)386 Binder (com.google.inject.Binder)140 Before (org.junit.Before)116 Properties (java.util.Properties)110 Test (org.testng.annotations.Test)105 Key (com.google.inject.Key)91 HttpServletRequest (javax.servlet.http.HttpServletRequest)78 Map (java.util.Map)75 Provider (com.google.inject.Provider)74 TypeLiteral (com.google.inject.TypeLiteral)70 IOException (java.io.IOException)69 Set (java.util.Set)63 BeforeClass (org.junit.BeforeClass)61 File (java.io.File)59 ImmutableList (com.google.common.collect.ImmutableList)58 CConfiguration (co.cask.cdap.common.conf.CConfiguration)55 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)55