EncassLoader implements BundleEntityLoader { @Override public void load(Bundle bundle, Element element) { final Element encassElement = getSingleChildElement(getSingleChildElement(element, RESOURCE), ENCAPSULATED_ASSERTION); final String policyId = getSingleChildElementAttribute(encassElement, POLICY_REFERENCE, ATTRIBUTE_ID); final String name = getSingleChildElementTextContent(encassElement, NAME); final String guid = getSingleChildElementTextContent(encassElement, GUID); final Map<String, Object> properties = mapPropertiesElements(getSingleChildElement(encassElement, PROPERTIES, true), PROPERTIES); properties.remove(POLICY_GUID_PROP); Encass encass = new Encass(); encass.setGuid(guid); encass.setName(name); encass.setProperties(properties); String policyPath = getPath(bundle, policyId); encass.setId(encassElement.getAttribute(ATTRIBUTE_ID)); encass.setPolicy(policyPath); encass.setArguments(getArguments(encassElement)); encass.setResults(getResults(encassElement)); encass.setPolicyId(policyId); bundle.getEncasses().put(name, encass); }  @Override void load(Bundle bundle, Element element); @Override String getEntityType();  }
@Test void load() { Policy policy = new Policy(); policy.setId(POLICY_ID); policy.setPath(TEST_POLICY_PATH); Bundle bundle = new Bundle(); bundle.getPolicies().put(policy.getPath(), policy); load(bundle); }
@Test void loadNoPolicy() { assertThrows(BundleLoadException.class, () -> load(new Bundle())); }