@Test
void build() {

    Element policyElement = createElementWithAttributesAndChildren(
            document,
            "wsp:Policy",
            ImmutableMap.of("xmlns:L7p", "http://www.layer7tech.com/ws/policy", "xmlns:wsp", "http://schemas.xmlsoap.org/ws/2002/12/policy&quot"),
            createSetVariableAssertion(document, "var", "value"),
            createIncludeAssertionElement(document, "include"),
            createHardcodedAssertionElement(document, "response")
    );
    Element encassElement = createEncapsulatedAssertionElement(document, TEST_ENCASS, "encass");
    encassElement.setAttribute(EncapsulatedAssertionBuilder.ENCASS_NAME, TEST_ENCASS);
    policyElement.appendChild(encassElement);
    document.appendChild(policyElement);
    policy.setPolicyXML(DocumentTools.INSTANCE.elementToString(document.getDocumentElement()));
    policy.setParentFolder(Folder.ROOT_FOLDER);
    policy.setGuid("policyGuid");
    policy.setId("policyID");
    policy.setName(policy.getPath());
    Encass encass = new Encass();
    encass.setGuid("encass");
    encass.setName(TEST_ENCASS);
    Set<Annotation> annotations = new HashSet<>();
    Annotation annotation = new Annotation(AnnotationType.SHARED);
    annotations.add(annotation);
    policy.setAnnotations(annotations);
    bundle.getEncasses().put(TEST_ENCASS, encass);
    bundle.getPolicies().put("Policy", policy);
    Policy include = new Policy();
    include.setParentFolder(Folder.ROOT_FOLDER);
    include.setPath("test/policy/include");
    include.setName(include.getPath());
    include.setId("includeID");
    include.setGuid("includeGuid");
    annotations = new HashSet<>();
    annotation = new Annotation(AnnotationType.SHARED);
    annotations.add(annotation);
    include.setAnnotations(annotations);
    include.setPolicyXML("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
            "<wsp:Policy xmlns:L7p=\"http://www.layer7tech.com/ws/policy\" xmlns:wsp=\"http://schemas.xmlsoap.org/ws/2002/12/policy\">\n" +
            "    <wsp:All wsp:Usage=\"Required\">\n" +
            "        <L7p:CommentAssertion>\n" +
            "            <L7p:Comment stringValue=\"Policy Fragment: includedPolicy\"/>\n" +
            "        </L7p:CommentAssertion>\n" +
            "    </wsp:All>\n" +
            "</wsp:Policy>");
    bundle.getPolicies().put("include", include);
    PolicyEntityBuilder builder = new PolicyEntityBuilder(DocumentTools.INSTANCE, new IdGenerator(), policyXMLBuilder);
    final List<Entity> entities = builder.build(bundle, BundleType.DEPLOYMENT, DocumentTools.INSTANCE.getDocumentBuilder().newDocument());
    assertFalse(entities.isEmpty());
    assertEquals(2, entities.size());
    entities.stream().collect(toMap(Entity::getId, identity())).forEach((i, e) -> {
        assertEquals(EntityTypes.POLICY_TYPE, e.getType());
        assertNotNull(e.getXml());
        assertTrue(e.getMappingProperties().containsKey(MAP_BY));
        assertEquals(MappingProperties.PATH, e.getMappingProperties().get(MAP_BY));
        assertTrue(e.getMappingProperties().containsKey(MAP_TO));
        assertEquals(e.getName(), e.getMappingProperties().get(MAP_TO));
        assertTrue("test/policy/include".equals(e.getName()) || "test/policy/path.xml".equals(e.getName()));
        assertTrue("includeID".equals(e.getId()) || "policyID".equals(e.getId()));
    });
}