@Override
    public Integer call() throws Exception {
        super.call();

        try(DefaultHttpClient client = client()) {
            MutableHttpRequest<Object> request = HttpRequest
                .GET(apiUri("/templates/export/by-query") + (namespace != null ? "?namespace=" + namespace : ""))
                .accept(MediaType.APPLICATION_OCTET_STREAM);

            HttpResponse<byte[]> response = client.toBlocking().exchange(this.requestOptions(request), byte[].class);
            Path zipFile = Path.of(directory.toString(), DEFAULT_FILE_NAME);
            zipFile.toFile().createNewFile();
            Files.write(zipFile, response.body());

            stdOut("Exporting template(s) for namespace '" + namespace + "' successfully done !");
        } catch (HttpClientResponseException e) {
            TemplateValidateCommand.handleHttpException(e, "template");
            return 1;
        }

        return 0;
    }
@Test
    void run() throws IOException {
        URL directory = TemplateExportCommandTest.class.getClassLoader().getResource("templates");
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        System.setOut(new PrintStream(out));

        try (ApplicationContext ctx = ApplicationContext.run(Map.of("kestra.templates.enabled", "true"), Environment.CLI, Environment.TEST)) {

            EmbeddedServer embeddedServer = ctx.getBean(EmbeddedServer.class);
            embeddedServer.start();

            // we use the update command to add templates to extract
            String[] args = {
                "--server",
                embeddedServer.getURL().toString(),
                "--user",
                "myuser:pass:word",
                "io.kestra.tests",
                directory.getPath(),

            };
            PicocliRunner.call(TemplateNamespaceUpdateCommand.class, ctx, args);
            assertThat(out.toString(), containsString("3 template(s)"));

            // then we export them
            String[] exportArgs = {
                "--server",
                embeddedServer.getURL().toString(),
                "--user",
                "myuser:pass:word",
                "--namespace",
                "io.kestra.tests",
                "/tmp",
            };
            PicocliRunner.call(TemplateExportCommand.class, ctx, exportArgs);
            File file = new File("/tmp/templates.zip");
            assertThat(file.exists(), is(true));
            ZipFile zipFile = new ZipFile(file);
            assertThat(zipFile.stream().count(), is(3L));

            file.delete();
        }
    }