@Test public void testToPolicyDtoPolicyContentDto_Throws_PolicyIdNotFoundException() throws SAXException, IOException { thrown.expect(PolicyIdNotFoundException.class); final byte[] bytes = POLICY_STRING_NO_ID .getBytes(DOMUtils.DEFAULT_ENCODING); final PolicyContentDto addPolicyRequestDto = new PolicyContentDto(); addPolicyRequestDto.setPolicy(bytes); MappingUtils.toPolicyDto(addPolicyRequestDto); }
public static PolicyDto toPolicyDto(byte[] policy) { String id = null; final Document policyDoc = bytesToDocument(policy); final Optional<Node> policySetId = DOMUtils.getNode(policyDoc, XPATH_POLICY_SET_ID); if (policySetId.isPresent()) { id = policySetId.get().getNodeValue(); } else { final Optional<Node> policyId = DOMUtils.getNode(policyDoc, XPATH_POLICY_ID); if (policyId.isPresent()) { id = policyId.get().getNodeValue(); } } if (id == null) { throw new PolicyIdNotFoundException( "Cannot find the PolicyId/PolicySetId in one or more of the submitted policies!"); } else { final PolicyDto dto = new PolicyDto(); dto.setId(id); dto.setPolicy(policy); return dto; } }
MappingUtils { public static PolicyDto toPolicyDto(byte[] policy) { String id = null; final Document policyDoc = bytesToDocument(policy); final Optional<Node> policySetId = DOMUtils.getNode(policyDoc, XPATH_POLICY_SET_ID); if (policySetId.isPresent()) { id = policySetId.get().getNodeValue(); } else { final Optional<Node> policyId = DOMUtils.getNode(policyDoc, XPATH_POLICY_ID); if (policyId.isPresent()) { id = policyId.get().getNodeValue(); } } if (id == null) { throw new PolicyIdNotFoundException( "Cannot find the PolicyId/PolicySetId in one or more of the submitted policies!"); } else { final PolicyDto dto = new PolicyDto(); dto.setId(id); dto.setPolicy(policy); return dto; } } }
MappingUtils { public static PolicyDto toPolicyDto(byte[] policy) { String id = null; final Document policyDoc = bytesToDocument(policy); final Optional<Node> policySetId = DOMUtils.getNode(policyDoc, XPATH_POLICY_SET_ID); if (policySetId.isPresent()) { id = policySetId.get().getNodeValue(); } else { final Optional<Node> policyId = DOMUtils.getNode(policyDoc, XPATH_POLICY_ID); if (policyId.isPresent()) { id = policyId.get().getNodeValue(); } } if (id == null) { throw new PolicyIdNotFoundException( "Cannot find the PolicyId/PolicySetId in one or more of the submitted policies!"); } else { final PolicyDto dto = new PolicyDto(); dto.setId(id); dto.setPolicy(policy); return dto; } }  }
MappingUtils { public static PolicyDto toPolicyDto(byte[] policy) { String id = null; final Document policyDoc = bytesToDocument(policy); final Optional<Node> policySetId = DOMUtils.getNode(policyDoc, XPATH_POLICY_SET_ID); if (policySetId.isPresent()) { id = policySetId.get().getNodeValue(); } else { final Optional<Node> policyId = DOMUtils.getNode(policyDoc, XPATH_POLICY_ID); if (policyId.isPresent()) { id = policyId.get().getNodeValue(); } } if (id == null) { throw new PolicyIdNotFoundException( "Cannot find the PolicyId/PolicySetId in one or more of the submitted policies!"); } else { final PolicyDto dto = new PolicyDto(); dto.setId(id); dto.setPolicy(policy); return dto; } }  static PolicyDto toPolicyDto(byte[] policy); static PolicyDto toPolicyDto(PolicyContentDto policyContentDto); }
MappingUtils { public static PolicyDto toPolicyDto(byte[] policy) { String id = null; final Document policyDoc = bytesToDocument(policy); final Optional<Node> policySetId = DOMUtils.getNode(policyDoc, XPATH_POLICY_SET_ID); if (policySetId.isPresent()) { id = policySetId.get().getNodeValue(); } else { final Optional<Node> policyId = DOMUtils.getNode(policyDoc, XPATH_POLICY_ID); if (policyId.isPresent()) { id = policyId.get().getNodeValue(); } } if (id == null) { throw new PolicyIdNotFoundException( "Cannot find the PolicyId/PolicySetId in one or more of the submitted policies!"); } else { final PolicyDto dto = new PolicyDto(); dto.setId(id); dto.setPolicy(policy); return dto; } }  static PolicyDto toPolicyDto(byte[] policy); static PolicyDto toPolicyDto(PolicyContentDto policyContentDto);  }