Search in sources :

Example 1 with OutputWriterFactory

use of com.googlecode.jmxtrans.model.OutputWriterFactory in project jmxtrans by jmxtrans.

the class JmxProcessingTests method querySimpleAttribute.

@Test
public void querySimpleAttribute() throws Exception {
    OutputWriterFactory outputWriterFactory = mock(OutputWriterFactory.class);
    OutputWriter outputWriter = mock(OutputWriter.class);
    when(outputWriterFactory.create()).thenReturn(outputWriter);
    Query query = Query.builder().setObj(MBEAN_NAME).addAttr("DummyValue").addOutputWriterFactory(outputWriterFactory).build();
    Server server = localServer();
    Iterable<Result> results1 = server.execute(query);
    query.runOutputWritersForQuery(server, results1);
    verify(outputWriter).doWrite(any(Server.class), queryCaptor.capture(), resultsCaptor.capture());
    assertThat(queryCaptor.getValue()).isEqualTo(query);
    List<Result> results = resultsCaptor.getValue();
    assertThat(results).hasSize(1);
    Result result = results.get(0);
    assertThat(result.getValues().get("DummyValue")).isEqualTo(123);
}
Also used : OutputWriterFactory(com.googlecode.jmxtrans.model.OutputWriterFactory) Query(com.googlecode.jmxtrans.model.Query) MBeanServer(javax.management.MBeanServer) ServerFixtures.localServer(com.googlecode.jmxtrans.model.ServerFixtures.localServer) Server(com.googlecode.jmxtrans.model.Server) OutputWriter(com.googlecode.jmxtrans.model.OutputWriter) Result(com.googlecode.jmxtrans.model.Result) Test(org.junit.Test)

Aggregations

OutputWriter (com.googlecode.jmxtrans.model.OutputWriter)1 OutputWriterFactory (com.googlecode.jmxtrans.model.OutputWriterFactory)1 Query (com.googlecode.jmxtrans.model.Query)1 Result (com.googlecode.jmxtrans.model.Result)1 Server (com.googlecode.jmxtrans.model.Server)1 ServerFixtures.localServer (com.googlecode.jmxtrans.model.ServerFixtures.localServer)1 MBeanServer (javax.management.MBeanServer)1 Test (org.junit.Test)1