/** Cleanup method. */
 @AfterClass
 protected void cleanUp() {
   BlogManagement bm = ServiceLocator.findService(BlogManagement.class);
   // remove the created test blogs
   try {
     Blog testBlog = bm.findBlogByIdentifier(BlogManagementTest.TEST_BLOG_IDENTIFIER);
     if (testBlog != null) {
       bm.deleteBlog(testBlog.getId(), null);
     }
   } catch (Exception e) {
     LOG.error("Clean up after test failed. ", e);
   }
 }
  /** Assign tag categories to blogs. */
  @Test(
      groups = {"globalTagCategories"},
      dependsOnMethods = {"updateCategorizedTags"})
  public void assignTagCategoriesToBlogs() throws Exception {
    TagCategoryManagement tcm = ServiceLocator.findService(TagCategoryManagement.class);
    // assign one to all blogs
    GlobalTagCategory categoryOne = loadGlobalTagCategory(GLOBAL_TAG_CATEGORY1_PREFIX);
    try {
      tcm.assignGlobalCategoryToAllBlogs(categoryOne.getId());
    } catch (TagCategoryNotFoundException e) {
      Assert.fail("assign failed", e);
    }

    // assign three to all blogs
    GlobalTagCategory categoryThree = loadGlobalTagCategory(GLOBAL_TAG_CATEGORY3_PREFIX);
    try {
      tcm.assignGlobalCategoryToAllBlogs(categoryThree.getId());
    } catch (TagCategoryNotFoundException e) {
      Assert.fail("assign failed", e);
    }

    // assign two to a single blog
    Blog blog = loadBlog(BlogManagementTest.TEST_BLOG_IDENTIFIER);
    GlobalTagCategory categoryTwo = loadGlobalTagCategory(GLOBAL_TAG_CATEGORY2_PREFIX);
    try {
      tcm.assignGlobalCategoryToBlog(categoryTwo.getId(), blog.getId());
    } catch (TagCategoryNotFoundException e) {
      Assert.fail("assign failed", e);
    } catch (TagCategoryAlreadyAssignedException e) {
      Assert.fail("assign failed", e);
    } catch (BlogNotFoundException e) {
      Assert.fail("assign failed", e);
    }

    // try to assign three to a single blog, should fail
    try {
      tcm.assignGlobalCategoryToBlog(categoryThree.getId(), blog.getId());
      Assert.fail(
          "can not assign category three to blog '"
              + blog.getId()
              + "', should be already assigned");
    } catch (TagCategoryNotFoundException e) {
      Assert.fail("assign failed", e);
    } catch (TagCategoryAlreadyAssignedException e) {
    } catch (BlogNotFoundException e) {
      Assert.fail("assign failed", e);
    }
  }