public void setDefault(@NotNull IndexSetDefaultTemplate defaultTemplate, String userName) throws NotFoundException {
        Optional<IndexSetTemplate> indexSetTemplate = indexSetTemplateService.get(defaultTemplate.id());
        if (indexSetTemplate.isEmpty()) {
            throw new NotFoundException("Index template with id <%s> doesn't exist!".formatted(defaultTemplate.id()));
        }
        if (indexSetTemplate.get().isBuiltIn()) {
            throw new IllegalArgumentException("Built-in templates cannot be set as default!");
        }

        clusterConfigService.write(defaultTemplate);
        auditEventSender.success(AuditActor.user(userName), INDEX_SET_DEFAULT_TEMPLATE_UPDATE, ImmutableMap.of(
                "template_id", indexSetTemplate.get().id(),
                "template_title", indexSetTemplate.get().title()
        ));

    }
@Test
    void testSetDefaultSuccessfully() throws Exception {
        when(indexSetTemplate.id()).thenReturn(INDEX_SET_DEFAULT_TEMPLATE.id());
        when(indexSetTemplate.title()).thenReturn("title");
        when(indexSetTemplateService.get(INDEX_SET_DEFAULT_TEMPLATE.id())).thenReturn(Optional.of(indexSetTemplate));

        underTest.setDefault(INDEX_SET_DEFAULT_TEMPLATE, "user");

        verify(clusterConfigService).write(INDEX_SET_DEFAULT_TEMPLATE);
    }