Search in sources :

Example 1 with HttpdForTests

use of com.facebook.buck.testutil.integration.HttpdForTests in project buck by facebook.

the class FetchCommandIntegrationTest method startHttpd.

@BeforeClass
public static void startHttpd() throws Exception {
    httpd = new HttpdForTests();
    httpd.addStaticContent("cheese");
    httpd.start();
}
Also used : HttpdForTests(com.facebook.buck.testutil.integration.HttpdForTests) BeforeClass(org.junit.BeforeClass)

Example 2 with HttpdForTests

use of com.facebook.buck.testutil.integration.HttpdForTests in project buck by facebook.

the class DoctorCommandIntegrationTest method setUp.

@Before
public void setUp() throws Exception {
    workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "report", tempFolder);
    workspace.setUp();
    objectMapper = ObjectMappers.newDefaultInstance();
    rageResult = DefectSubmitResult.builder().setIsRequestSuccessful(true).setReportSubmitErrorMessage(Optional.empty()).setReportSubmitMessage("This is a json/string generated by the remote server.").setRequestProtocol(RageConfig.RageProtocolVersion.JSON).build();
    doctorResponse = DoctorEndpointResponse.of(Optional.empty(), ImmutableList.of(DoctorSuggestion.of(DoctorSuggestion.StepStatus.ERROR, Optional.empty(), "Suggestion no1"), DoctorSuggestion.of(DoctorSuggestion.StepStatus.WARNING, Optional.of("Area"), "Suggestion no2")));
    httpd = new HttpdForTests();
    httpd.addHandler(createHttpdHandler("POST", "{\"buildId\":\"ac8bd626-6137-4747-84dd-5d4f215c876c\",\"logDirPath\":\"" + LOG_PATH + "\",\"machineReadableLog\""));
    httpd.start();
}
Also used : HttpdForTests(com.facebook.buck.testutil.integration.HttpdForTests) Before(org.junit.Before)

Example 3 with HttpdForTests

use of com.facebook.buck.testutil.integration.HttpdForTests in project buck by facebook.

the class PublicAnnouncementManagerIntegrationTest method testAnnouncementsWork.

@Test
public void testAnnouncementsWork() throws Exception {
    final AtomicReference<byte[]> requestBody = new AtomicReference<>();
    try (HttpdForTests httpd = new HttpdForTests()) {
        httpd.addHandler(new AbstractHandler() {

            @Override
            public void handle(String s, Request request, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException, ServletException {
                httpServletResponse.setStatus(200);
                request.setHandled(true);
                if (request.getUri().getPath().equals("/status.php")) {
                    return;
                }
                requestBody.set(ByteStreams.toByteArray(httpServletRequest.getInputStream()));
                FrontendRequest thriftRequest = new FrontendRequest();
                ThriftUtil.deserialize(ThriftProtocol.BINARY, requestBody.get(), thriftRequest);
                assertTrue("Request should contain the repository.", thriftRequest.getAnnouncementRequest().getRepository().equals(REPOSITORY));
                try (DataOutputStream out = new DataOutputStream(httpServletResponse.getOutputStream())) {
                    Announcement announcement = new Announcement();
                    announcement.setErrorMessage(ERROR_MSG);
                    announcement.setSolutionMessage(SOLUTION_MSG);
                    AnnouncementResponse announcementResponse = new AnnouncementResponse();
                    announcementResponse.setAnnouncements(ImmutableList.of(announcement));
                    FrontendResponse frontendResponse = new FrontendResponse();
                    frontendResponse.setType(FrontendRequestType.ANNOUNCEMENT);
                    frontendResponse.setAnnouncementResponse(announcementResponse);
                    out.write(ThriftUtil.serialize(ThriftProtocol.BINARY, frontendResponse));
                }
            }
        });
        httpd.start();
        Clock clock = new DefaultClock();
        BuckEventBus eventBus = BuckEventBusFactory.newInstance(clock);
        ExecutionEnvironment executionEnvironment = new DefaultExecutionEnvironment(ImmutableMap.copyOf(System.getenv()), System.getProperties());
        BuckConfig buckConfig = new FakeBuckConfig.Builder().setSections(ImmutableMap.of("log", ImmutableMap.of("slb_server_pool", "http://localhost:" + httpd.getRootUri().getPort()))).build();
        TestConsole console = new TestConsole();
        SuperConsoleEventBusListener listener = new SuperConsoleEventBusListener(new SuperConsoleConfig(FakeBuckConfig.builder().build()), console, clock, /* verbosity */
        TestResultSummaryVerbosity.of(false, false), executionEnvironment, Optional.empty(), Locale.US, logPath, TimeZone.getTimeZone("UTC"));
        eventBus.register(listener);
        PublicAnnouncementManager manager = new PublicAnnouncementManager(clock, eventBus, listener, REPOSITORY, new RemoteLogBuckConfig(buckConfig), MoreExecutors.newDirectExecutorService());
        manager.getAndPostAnnouncements();
        Optional<String> announcements = listener.getPublicAnnouncements();
        assertEquals("The header and the message", announcements.get(), "**-------------------------------**\n" + "**- Sticky Public Announcements -**\n" + "**-------------------------------**\n" + "** This is the error message. This is the solution message.");
    }
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) RemoteLogBuckConfig(com.facebook.buck.util.network.RemoteLogBuckConfig) DefaultExecutionEnvironment(com.facebook.buck.util.environment.DefaultExecutionEnvironment) ExecutionEnvironment(com.facebook.buck.util.environment.ExecutionEnvironment) Announcement(com.facebook.buck.distributed.thrift.Announcement) AnnouncementResponse(com.facebook.buck.distributed.thrift.AnnouncementResponse) DataOutputStream(java.io.DataOutputStream) DefaultClock(com.facebook.buck.timing.DefaultClock) Clock(com.facebook.buck.timing.Clock) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) RemoteLogBuckConfig(com.facebook.buck.util.network.RemoteLogBuckConfig) BuckConfig(com.facebook.buck.cli.BuckConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) DefaultClock(com.facebook.buck.timing.DefaultClock) FrontendRequest(com.facebook.buck.distributed.thrift.FrontendRequest) HttpdForTests(com.facebook.buck.testutil.integration.HttpdForTests) DefaultExecutionEnvironment(com.facebook.buck.util.environment.DefaultExecutionEnvironment) Request(org.eclipse.jetty.server.Request) FrontendRequest(com.facebook.buck.distributed.thrift.FrontendRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) FrontendResponse(com.facebook.buck.distributed.thrift.FrontendResponse) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Example 4 with HttpdForTests

use of com.facebook.buck.testutil.integration.HttpdForTests in project buck by facebook.

the class ResolverIntegrationTest method setUpFakeMavenRepo.

@BeforeClass
public static void setUpFakeMavenRepo() throws Exception {
    repo = TestDataHelper.getTestDataDirectory(ResolverIntegrationTest.class);
    httpd = new HttpdForTests();
    httpd.addHandler(new HttpdForTests.FileDispenserRequestHandler(repo));
    httpd.start();
}
Also used : HttpdForTests(com.facebook.buck.testutil.integration.HttpdForTests) BeforeClass(org.junit.BeforeClass)

Example 5 with HttpdForTests

use of com.facebook.buck.testutil.integration.HttpdForTests in project buck by facebook.

the class TestPublisher method create.

/**
   * @param pseudoLocalRepo typically {@link org.junit.rules.TemporaryFolder#newFolder}
   */
public static TestPublisher create(Path pseudoLocalRepo) throws Exception {
    HttpdForTests.DummyPutRequestsHandler putRequestsHandler = new HttpdForTests.DummyPutRequestsHandler();
    HttpdForTests httpd = new HttpdForTests();
    httpd.addHandler(putRequestsHandler);
    httpd.start();
    return new TestPublisher(pseudoLocalRepo, httpd, putRequestsHandler);
}
Also used : HttpdForTests(com.facebook.buck.testutil.integration.HttpdForTests)

Aggregations

HttpdForTests (com.facebook.buck.testutil.integration.HttpdForTests)9 TestConsole (com.facebook.buck.testutil.TestConsole)4 Clock (com.facebook.buck.timing.Clock)4 DefaultClock (com.facebook.buck.timing.DefaultClock)4 IOException (java.io.IOException)4 ServletException (javax.servlet.ServletException)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 Request (org.eclipse.jetty.server.Request)4 AbstractHandler (org.eclipse.jetty.server.handler.AbstractHandler)4 Test (org.junit.Test)4 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)3 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)3 NoOpCmdLineInterface (com.facebook.buck.util.versioncontrol.NoOpCmdLineInterface)3 DataOutputStream (java.io.DataOutputStream)3 Optional (java.util.Optional)3 BeforeClass (org.junit.BeforeClass)3 ZipInspector (com.facebook.buck.testutil.integration.ZipInspector)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2