HandlerFunction<ServerResponse> handlerFunction(String name) {
        return request -> singlePageFinder.getByName(name)
            .doOnNext(singlePageVo -> {
                titleVisibilityIdentifyCalculator.calculateTitle(
                    singlePageVo.getSpec().getTitle(),
                    singlePageVo.getSpec().getVisible(),
                    localeContextResolver.resolveLocaleContext(request.exchange())
                        .getLocale()
                );
            })
            .flatMap(singlePageVo -> {
                Map<String, Object> model = ModelMapUtils.singlePageModel(singlePageVo);
                String template = singlePageVo.getSpec().getTemplate();
                return viewNameResolver.resolveViewNameOrDefault(request, template,
                        DefaultTemplateEnum.SINGLE_PAGE.getValue())
                    .flatMap(viewName -> ServerResponse.ok().render(viewName, model));
            })
            .switchIfEmpty(
                Mono.error(new NotFoundException("Single page not found"))
            );
    }
@Test
    void handlerFunction() {
        // fix gh-3448
        when(viewNameResolver.resolveViewNameOrDefault(any(ServerRequest.class), any(), any()))
            .thenReturn(Mono.just(DefaultTemplateEnum.POST.getValue()));

        String pageName = "fake-page";
        when(viewResolver.resolveViewName(any(), any()))
            .thenReturn(Mono.just(new EmptyView() {
                @Override
                public Mono<Void> render(Map<String, ?> model, MediaType contentType,
                    ServerWebExchange exchange) {
                    assertThat(model).containsKey(ModelConst.TEMPLATE_ID);
                    assertThat(model.get(ModelConst.TEMPLATE_ID))
                        .isEqualTo(DefaultTemplateEnum.SINGLE_PAGE.getValue());
                    assertThat(model.get("name"))
                        .isEqualTo(pageName);
                    assertThat(model.get("plural")).isEqualTo("singlepages");
                    assertThat(model.get("singlePage")).isNotNull();
                    assertThat(model.get("groupVersionKind"))
                        .isEqualTo(GroupVersionKind.fromExtension(SinglePage.class));
                    return super.render(model, contentType, exchange);
                }
            }));

        SinglePage singlePage = new SinglePage();
        singlePage.setMetadata(new Metadata());
        singlePage.getMetadata().setName(pageName);
        singlePage.setSpec(new SinglePage.SinglePageSpec());
        when(singlePageFinder.getByName(eq(pageName)))
            .thenReturn(Mono.just(SinglePageVo.from(singlePage)));

        HandlerFunction<ServerResponse> handlerFunction =
            singlePageRoute.handlerFunction(pageName);
        RouterFunction<ServerResponse> routerFunction =
            RouterFunctions.route().GET("/archives/{name}", handlerFunction).build();

        WebTestClient webTestClient = WebTestClient.bindToRouterFunction(routerFunction)
            .handlerStrategies(HandlerStrategies.builder()
                .viewResolver(viewResolver)
                .build())
            .build();

        when(localeContextResolver.resolveLocaleContext(any()))
            .thenReturn(new SimpleLocaleContext(Locale.getDefault()));
        webTestClient.get()
            .uri("/archives/fake-name")
            .exchange()
            .expectStatus().isOk();
    }