@Test
public void testAnnotatedEncassDeleteBundle_WithPolicyFragment() {

    BundleEntityBuilder builder = createBundleEntityBuilder();
    Bundle bundle = createBundleWithPolicyFragment(false, projectInfo);
    Encass encass = buildTestEncassWithAnnotation(TEST_GUID, TEST_ENCASS_POLICY, false);
    bundle.putAllEncasses(ImmutableMap.of(TEST_ENCASS, encass));
    Map<String, BundleArtifacts> bundles = builder.build(bundle, DEPLOYMENT,
            DocumentTools.INSTANCE.getDocumentBuilder().newDocument(), projectInfo);
    assertNotNull(bundles);
    assertEquals(1, bundles.size());
    Element deleteBundleElement = bundles.get(TEST_ENCASS_ANNOTATION_NAME + "-1.0").getDeleteBundle().getElement();
    assertNotNull(deleteBundleElement);
    // Assert Bundle
    assertEquals(BundleDocumentBuilder.GATEWAY_MANAGEMENT, deleteBundleElement.getAttribute(BundleDocumentBuilder.L7));
    assertEquals(BUNDLE, deleteBundleElement.getTagName());
    final int expectedElementCountBundle = 3;
    // Assert References
    final Element references = getSingleChildElement(deleteBundleElement, REFERENCES);
    assertNotNull(references);
    final List<Element> itemList = getChildElements(references, ITEM);
    assertNotNull(itemList);
    assertEquals(expectedElementCountBundle, itemList.size());
    final Element item1 = itemList.get(2);
    assertEquals("::" + projectInfo.getGroupName() + "." + TEST_ENCASS_ANNOTATION_NAME + "::" + TEST_POLICY_FRAGMENT + "::" + projectInfo.getVersion()  ,
            getSingleChildElementTextContent(item1, NAME));
    assertEquals(EntityTypes.POLICY_TYPE, getSingleChildElementTextContent(item1, TYPE));
    assertNotNull(getSingleChildElement(item1, RESOURCE));
    final Element item2 = itemList.get(1);
    assertEquals("::" + projectInfo.getGroupName() + "." + TEST_ENCASS_ANNOTATION_NAME + "::" + TEST_ENCASS_POLICY + "::" + projectInfo.getVersion()   ,
            getSingleChildElementTextContent(item2, NAME));
    assertEquals(EntityTypes.POLICY_TYPE, getSingleChildElementTextContent(item2, TYPE));
    assertNotNull(getSingleChildElement(item2, RESOURCE));
    final Element item3 = itemList.get(0);
    assertEquals("::" + projectInfo.getGroupName() + "." + TEST_ENCASS_ANNOTATION_NAME + "::" + TEST_ENCASS + "::" + projectInfo.getVersion(), getSingleChildElementTextContent(item3, NAME));
    assertEquals(EntityTypes.ENCAPSULATED_ASSERTION_TYPE, getSingleChildElementTextContent(item3, TYPE));
    assertNotNull(getSingleChildElement(item3, RESOURCE));
    // Assert Mappings
    final Element mappings = getSingleChildElement(deleteBundleElement, MAPPINGS);
    assertNotNull(mappings);
    final List<Element> mappingItemList = getChildElements(mappings, MAPPING);
    assertEquals(expectedElementCountBundle, mappingItemList.size());
    final Element mapping1 = mappingItemList.get(2);
    final Element mapping1Properties = getSingleChildElement(mapping1, PROPERTIES);
    Set<String> propertyValues = getChildElementsTextContents(mapping1Properties, PROPERTY);
    assertTrue(propertyValues.contains("::" + projectInfo.getGroupName() + "." + TEST_ENCASS_ANNOTATION_NAME + "::" + TEST_POLICY_FRAGMENT + "::" + projectInfo.getVersion()));
    assertEquals(MappingActions.DELETE, mapping1.getAttribute("action"));
    assertEquals(EntityTypes.POLICY_TYPE, mapping1.getAttribute("type"));
    final Element mapping2 = mappingItemList.get(1);
    final Element mapping2Properties = getSingleChildElement(mapping2, PROPERTIES);
    propertyValues = getChildElementsTextContents(mapping2Properties, PROPERTY);
    assertTrue(propertyValues.contains("::" + projectInfo.getGroupName() + "." + TEST_ENCASS_ANNOTATION_NAME + "::" + TEST_ENCASS_POLICY + "::" + projectInfo.getVersion()));
    assertEquals(MappingActions.DELETE, mapping2.getAttribute("action"));
    assertEquals(EntityTypes.POLICY_TYPE, mapping2.getAttribute("type"));
    final Element mapping3 = mappingItemList.get(0);
    final Element mapping3Properties = getSingleChildElement(mapping3, PROPERTIES);
    propertyValues = getChildElementsTextContents(mapping3Properties, PROPERTY);
    assertTrue(propertyValues.contains("::" + projectInfo.getGroupName() + "." + TEST_ENCASS_ANNOTATION_NAME + "::" + TEST_ENCASS + "::" + projectInfo.getVersion()));
    assertEquals(MappingActions.DELETE, mapping3.getAttribute("action"));
    assertEquals(EntityTypes.ENCAPSULATED_ASSERTION_TYPE, mapping3.getAttribute("type"));
}