@PostMapping(
            path = "/admin/change-namespace",
            consumes = MediaType.APPLICATION_JSON_VALUE,
            produces = MediaType.APPLICATION_JSON_VALUE
    )
    public ResponseEntity<ResultJson> changeNamespace(@RequestBody ChangeNamespaceJson json) {
        try {
            admins.checkAdminUser();
            admins.changeNamespace(json);
            return ResponseEntity.ok(ResultJson.success("Scheduled namespace change from '" + json.oldNamespace + "' to '" + json.newNamespace + "'.\nIt can take 15 minutes to a couple hours for the change to become visible."));
        } catch (ErrorResultException exc) {
            return exc.toResponseEntity();
        }
    }
@Test
    public void testChangeNamespace() throws Exception {
        mockAdminUser();
        var foo = new Namespace();
        foo.setName("foo");
        Mockito.when(repositories.findNamespace(foo.getName())).thenReturn(foo);

        var bar = new Namespace();
        bar.setName("bar");
        Mockito.when(repositories.findNamespace(bar.getName())).thenReturn(null);

        var content = "{" +
                "\"oldNamespace\": \"foo\", " +
                "\"newNamespace\": \"bar\", " +
                "\"removeOldNamespace\": false, " +
                "\"mergeIfNewNamespaceAlreadyExists\": true" +
            "}";

        var json = new ChangeNamespaceJson();
        json.oldNamespace = "foo";
        json.newNamespace = "bar";
        json.removeOldNamespace = false;
        json.mergeIfNewNamespaceAlreadyExists = true;

        mockMvc.perform(post("/admin/change-namespace")
                .with(user("admin_user").authorities(new SimpleGrantedAuthority(("ROLE_ADMIN"))))
                .with(csrf().asHeader())
                .content(content)
                .contentType(MediaType.APPLICATION_JSON))
                .andExpect(status().isOk())
                .andExpect(content().json(successJson("Scheduled namespace change from 'foo' to 'bar'.\nIt can take 15 minutes to a couple hours for the change to become visible.")))
                .andExpect(result -> Mockito.verify(scheduler).enqueue(new ChangeNamespaceJobRequest(json)));
    }