Skip to content

B.5: Add AdminDashboardController with Micrometer metrics endpoints and WebMvcTest#76

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/create-tests-for-admindashboardcontroller
Draft

B.5: Add AdminDashboardController with Micrometer metrics endpoints and WebMvcTest#76
Copilot wants to merge 2 commits intomainfrom
copilot/create-tests-for-admindashboardcontroller

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 28, 2026

Adds AdminDashboardController exposing operational metrics via Micrometer's MeterRegistry, and the corresponding @WebMvcTest slice tests.

New Controller — /admin

  • GET /admin/resumo — returns buscas_total (from vigisus.buscas.total counter, 0.0 if absent) and timestamp
  • GET /admin/top-municipios — returns municipalities sorted descending by search count from vigisus.buscas.municipio counters

Tests

@WebMvcTest(AdminDashboardController.class) with @MockBean MeterRegistry — stubs find() to return Search.in(meterRegistry), which yields null counter / empty collection from the mock registry, exercising the zero-state fallback path:

@WebMvcTest(AdminDashboardController.class)
@WithMockUser
class AdminDashboardControllerTest {

    @MockBean MeterRegistry meterRegistry;

    @Test
    void deveRetornarResumoVazioSemMedidas() throws Exception {
        when(meterRegistry.find(any())).thenReturn(Search.in(meterRegistry));

        mockMvc.perform(get("/admin/resumo"))
            .andExpect(status().isOk())
            .andExpect(jsonPath("$.buscas_total").isNumber())
            .andExpect(jsonPath("$.timestamp").isString());
    }
}

@WithMockUser is required because @WebMvcTest applies Spring Security's default filter chain (all requests authenticated) without loading the app's custom SecurityFilterChain.

Supporting changes

  • SecurityConfig — added .requestMatchers("/admin/**").permitAll() consistent with the current public-data / hackathon scope
  • pom.xml — added spring-security-test (test scope) to provide @WithMockUser

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Agent-Logs-Url: https://github.com/fiap-tech-challenge-java/vigisus/sessions/b6196849-bf36-4aaa-b734-3e74ba7fc6da

Co-authored-by: rebecanonato89 <38442994+rebecanonato89@users.noreply.github.com>
Copilot AI changed the title [WIP] Add tests for AdminDashboardController B.5: Add AdminDashboardController with Micrometer metrics endpoints and WebMvcTest Mar 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants