### Question:
AppNamespaceService { public AppNamespace createAppNamespaceInLocal(AppNamespace appNamespace) { return createAppNamespaceInLocal(appNamespace, true); }  @Transactional void batchDelete(String appId, String operator); @Transactional void deleteAppNamespace(AppNamespace appNamespace, String operator); AppNamespace findPublicNamespaceByName(String namespaceName); List<AppNamespace> findByAppId(String appId); List<AppNamespace> findPublicAppNamespaces(); AppNamespace findPublicAppNamespace(String namespaceName); AppNamespace findByAppIdAndName(String appId, String namespaceName); @Transactional void createDefaultAppNamespace(String appId, String createBy); @Transactional void createDefaultAppNamespace(String appId); boolean isAppNamespaceNameUnique(String appId, String namespaceName); AppNamespace createAppNamespaceInLocal(AppNamespace appNamespace); @Transactional AppNamespace createAppNamespaceInLocal(AppNamespace appNamespace, boolean appendNamespacePrefix); @Transactional AppNamespace deleteAppNamespace(String appId, String namespaceName); void batchDeleteByAppId(String appId, String operator);  }### Answer:
@Test(expected = BadRequestException.class) @Sql(scripts = "/sql/appnamespaceservice/init-appnamespace.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) @Sql(scripts = "/sql/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD) public void testCreatePublicAppNamespaceExisted() { AppNamespace appNamespace = assmbleBaseAppNamespace(); appNamespace.setPublic(true); appNamespace.setName("old"); appNamespaceService.createAppNamespaceInLocal(appNamespace); }
@Test @Sql(scripts = "/sql/appnamespaceservice/init-appnamespace.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) @Sql(scripts = "/sql/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD) public void testCreatePublicAppNamespaceNotExistedWithNoAppendnamespacePrefix() { AppNamespace appNamespace = assmbleBaseAppNamespace(); appNamespace.setPublic(true); appNamespace.setName("old"); AppNamespace createdAppNamespace = appNamespaceService.createAppNamespaceInLocal(appNamespace, false); Assert.assertNotNull(createdAppNamespace); Assert.assertEquals(appNamespace.getName(), createdAppNamespace.getName()); }
@Test(expected = BadRequestException.class) @Sql(scripts = "/sql/appnamespaceservice/init-appnamespace.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) @Sql(scripts = "/sql/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD) public void testCreatePublicAppNamespaceExistedWithNoAppendnamespacePrefix() { AppNamespace appNamespace = assmbleBaseAppNamespace(); appNamespace.setPublic(true); appNamespace.setName("datasource"); appNamespaceService.createAppNamespaceInLocal(appNamespace, false); }
@Test(expected = BadRequestException.class) @Sql(scripts = "/sql/appnamespaceservice/init-appnamespace.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) @Sql(scripts = "/sql/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD) public void testCreatePrivateAppNamespaceExisted() { AppNamespace appNamespace = assmbleBaseAppNamespace(); appNamespace.setPublic(false); appNamespace.setName("datasource.xml"); appNamespace.setAppId("100003173"); appNamespaceService.createAppNamespaceInLocal(appNamespace); }