@Test public void serves_data_from_SystemInfoSections() throws Exception { NanoHTTPD.Response response = underTest.serve(createHttpSession(GET)); assertThat(response.getStatus()).isEqualTo(OK); ProtobufSystemInfo.SystemInfo systemInfo = ProtobufSystemInfo.SystemInfo.parseFrom(response.getData()); assertThat(systemInfo.getSectionsCount()).isEqualTo(2); assertThat(systemInfo.getSections(0).getName()).isEqualTo("state1"); assertThat(systemInfo.getSections(1).getName()).isEqualTo("state2"); }
@Test public void empty_result_is_returned_if_not_started_yet() { ProcessInfoProvider underTest = new ProcessInfoProvider(new SystemInfoSection[]{ new TestSystemInfoSection("foo"), new TestSystemInfoSection("bar")}); assertThat(ProcessInfoProvider.provide().getSectionsCount()).isEqualTo(0); underTest.start(); assertThat(ProcessInfoProvider.provide().getSectionsCount()).isEqualTo(2); underTest.stop(); assertThat(ProcessInfoProvider.provide().getSectionsCount()).isEqualTo(0); } }
@Test public void retrieveSystemInfo_get_information_if_process_is_up() { Buffer response = new Buffer(); response.read(ProtobufSystemInfo.Section.newBuilder().build().toByteArray()); server.enqueue(new MockResponse().setBody(response)); // initialize registration of process setUpWithHttpUrl(ProcessId.COMPUTE_ENGINE); Optional<ProtobufSystemInfo.SystemInfo> info = underTest.retrieveSystemInfo(); assertThat(info.get().getSectionsCount()).isEqualTo(0); }