PolicyValidationUtils { public static boolean validate(final byte[] policy) { boolean isValid = false; try { final String policyString = new String(policy, DOMUtils.DEFAULT_ENCODING); final Document policyDoc = DOMUtils.bytesToDocument(policy); final Evaluatable policyObj = PolicyMarshaller .unmarshal(new ByteArrayInputStream(policy)); Assert.notNull(policyString); Assert.notNull(policyObj); Assert.notNull(policyDoc); isValid = true; } catch (final Exception e) { LOGGER.debug(e.getMessage(), e); } return isValid; }  static boolean validate(final byte[] policy); static PolicyDto validateAndReturn(PolicyDto policyDto);  }
@Test public void testValidate() throws UnsupportedEncodingException { final boolean valid = PolicyValidationUtils.validate(POLICY_STRING .getBytes(DOMUtils.DEFAULT_ENCODING)); assertTrue(valid); }
@Test public void testValidate_Invalid_By_Encoding() throws UnsupportedEncodingException { final boolean valid = PolicyValidationUtils.validate(POLICY_STRING .getBytes("UTF-16")); assertFalse(valid); }
@Test public void testValidate_Invalid_By_Not_Valid_XACML() throws UnsupportedEncodingException { final boolean valid = PolicyValidationUtils .validate(POLICY_STRING_NOT_VALID_XACML .getBytes(DOMUtils.DEFAULT_ENCODING)); assertFalse(valid); }
@Test public void testValidate_Invalid_By_Not_Wellformed() throws UnsupportedEncodingException { final boolean valid = PolicyValidationUtils .validate(POLICY_STRING_NOT_WELLFORMED .getBytes(DOMUtils.DEFAULT_ENCODING)); assertFalse(valid); }