@Test
public void testSpaceCreationAndDeletion() throws Exception {

  assertEquals(0, this.spaceRepository.count());
  final Tenant d_tenant = this.createDefaultTenant();
  final Space d_space = this.createSpace(d_tenant, TEST_DEFAULT_SPACE, true);
  assertEquals(1, this.spaceRepository.count());
  final String space_name = "foo";
  org.eclipse.steady.shared.json.model.Space new_shared_space =
      new org.eclipse.steady.shared.json.model.Space();
  new_shared_space.setSpaceName("foo");
  new_shared_space.setExportConfiguration(ExportConfiguration.OFF);
  new_shared_space.setSpaceDescription("bar");
  new_shared_space.setOwnerEmails(
      new HashSet<String>(Arrays.asList(new String[] {"foo@bar.com"})));
  // Post w tenant header (should create a NON default space as it's not provided)
  MockHttpServletRequestBuilder post_builder =
      post("/spaces")
          .content(JacksonUtil.asJsonString(new_shared_space))
          .contentType(MediaType.APPLICATION_JSON)
          .header(Constants.HTTP_TENANT_HEADER, d_tenant.getTenantToken())
          .accept(MediaType.APPLICATION_JSON);
  MvcResult result =
      mockMvc
          .perform(post_builder)
          .andExpect(status().isCreated())
          .andExpect(content().contentType(contentType))
          .andExpect(jsonPath("$.default", is(false)))
          .andExpect(jsonPath("$.spaceName", is(space_name)))
          .andReturn();
  assertEquals(2, this.spaceRepository.count());
  // Get the generated token
  org.eclipse.steady.shared.json.model.Space created_shared_space =
      (org.eclipse.steady.shared.json.model.Space)
          JacksonUtil.asObject(
              result.getResponse().getContentAsString(),
              org.eclipse.steady.shared.json.model.Space.class);
  // Post with non-existing tenant token, defaults in controller method
  MockHttpServletRequestBuilder del_builder =
      delete("/spaces/" + created_shared_space.getSpaceToken())
          .header(Constants.HTTP_TENANT_HEADER, TEST_DEFAULT_TENANT)
          .accept(MediaType.APPLICATION_JSON);
  mockMvc.perform(del_builder).andExpect(status().isOk());
  assertEquals(1, this.spaceRepository.count());
}