@Test
public void testSpaceCreation() 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());
  // Create 2nd space used for some tests
  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(TEST_DEFAULT_SPACE);
  new_shared_space.setDefault(
      true); // This will not be possible, as another default space has been created above
  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"})));
  // returns 400 as default space already exists
  MockHttpServletRequestBuilder post_builder =
      post("/spaces")
          .header(Constants.HTTP_TENANT_HEADER, d_tenant.getTenantToken())
          .content(JacksonUtil.asJsonString(new_shared_space))
          .contentType(MediaType.APPLICATION_JSON)
          .accept(MediaType.APPLICATION_JSON);
  mockMvc.perform(post_builder).andExpect(status().isBadRequest());
  //		MvcResult result = mockMvc.perform(post_builder).andExpect(status().isCreated())
  //				.andExpect(content().contentType(contentType))
  //				.andExpect(jsonPath("$.spaceName", is(space_name))).andReturn();
  // Still one space only
  assertEquals(1, this.spaceRepository.count());
  new_shared_space.setDefault(false);
  // Post w/o tenant header to try to create a NON default space
  post_builder =
      post("/spaces")
          .content(JacksonUtil.asJsonString(new_shared_space))
          .contentType(MediaType.APPLICATION_JSON)
          .accept(MediaType.APPLICATION_JSON);
  mockMvc.perform(post_builder).andExpect(status().isCreated());
  assertEquals(2, this.spaceRepository.count());
  // Create with read-only enabled -> bad request
  new_shared_space.setReadOnly(true);
  post_builder =
      post("/spaces")
          .header(Constants.HTTP_TENANT_HEADER, d_tenant.getTenantToken())
          .content(JacksonUtil.asJsonString(new_shared_space))
          .contentType(MediaType.APPLICATION_JSON)
          .accept(MediaType.APPLICATION_JSON);
  mockMvc.perform(post_builder).andExpect(status().isBadRequest());
  // Still two space only
  assertEquals(2, this.spaceRepository.count());
  new_shared_space.setReadOnly(false);
  new_shared_space.setSpaceName(space_name);
  new_shared_space.setDefault(false);
  post_builder =
      post("/spaces")
          .header(Constants.HTTP_TENANT_HEADER, d_tenant.getTenantToken())
          .content(JacksonUtil.asJsonString(new_shared_space))
          .contentType(MediaType.APPLICATION_JSON)
          .accept(MediaType.APPLICATION_JSON);
  mockMvc
      .perform(post_builder)
      .andExpect(status().isCreated())
      .andExpect(content().contentType(contentType))
      .andExpect(jsonPath("$.spaceName", is(space_name)));
  // Now three space
  assertEquals(3, this.spaceRepository.count());
  // Post with non-existing tenant token, defaults in controller method
  MockHttpServletRequestBuilder post_builder2 =
      post("/spaces")
          .content(JacksonUtil.asJsonString(new_shared_space))
          .contentType(MediaType.APPLICATION_JSON)
          .header(Constants.HTTP_TENANT_HEADER, "does-not-exist")
          .accept(MediaType.APPLICATION_JSON);
  mockMvc.perform(post_builder2).andExpect(status().isNotFound());
}