@Test
public void testPolicyAttributeValidation() throws IOException {

    PolicyValidation validation = new PolicyValidation();
    PolicyRestAdapter policyData = new PolicyRestAdapter();
    policyData.setPolicyName("ALegalPolicyName");
    policyData.setPolicyDescription("A Valid Description");
    String responseString = validation.validatePolicy(policyData).toString();
    assertEquals("success", responseString);
    policyData.setApiflag("API");
    responseString = validation.validatePolicy(policyData).toString();
    assertEquals("success", responseString);
    policyData.setApiflag("NOTAPI");
    responseString = validation.validatePolicy(policyData).toString();
    assertEquals("success", responseString);
    List<Object> attributes = new ArrayList<>();
    policyData.setAttributes(attributes);
    responseString = validation.validatePolicy(policyData).toString();
    assertEquals("success", responseString);
    attributes.add(new String("hello"));
    responseString = validation.validatePolicy(policyData).toString();
    assertEquals("success", responseString);
    attributes.clear();
    Map<String, String> mapAttribute = new LinkedHashMap<>();
    attributes.add(mapAttribute);
    responseString = validation.validatePolicy(policyData).toString();
    assertThat(responseString).contains("Component Attributes</b>:<i> has one missing Component Attribute value");
    mapAttribute.put("key", "value");
    responseString = validation.validatePolicy(policyData).toString();
    assertEquals("<b>Component Attributes</b>:<i> has one missing Component Attribute value</i><br>",
                    responseString);
    mapAttribute.put("key", "");
    responseString = validation.validatePolicy(policyData).toString();
    assertEquals("<b>Attributes or Component Attributes</b>:<i>null : value has spaces or invalid characters</i>"
                    + "<br><b>Component Attributes</b>:<i> has one missing Component Attribute value</i><br>",
                    responseString);
    mapAttribute.clear();
    responseString = validation.validatePolicy(policyData).toString();
    mapAttribute.put("hello", "aaa");
    responseString = validation.validatePolicy(policyData).toString();
    assertEquals("<b>Component Attributes</b>:<i> has one missing Component Attribute key</i><br>"
                    + "<b>Component Attributes</b>:<i> has one missing Component Attribute value</i><br>",
                    responseString);
    policyData.setPolicyType("Config");
    responseString = validation.validatePolicy(policyData).toString();
    assertEquals("<b>RiskType</b>: Risk Type Should not be Empty</i><br>"
                    + "<b>RiskLevel</b>: Risk Level Should not be Empty</i><br>"
                    + "<b>Guard</b>: Guard Value Should not be Empty</i><br>", responseString);
    policyData.setConfigPolicyType("Base");
    responseString = validation.validatePolicy(policyData).toString();
    assertThat(responseString).contains("has one missing Attribute key");
    policyData.setConfigPolicyType("BRMS_Param");
    responseString = validation.validatePolicy(policyData).toString();
    assertThat(responseString).contains("has one missing Attribute key");
    policyData.setConfigPolicyType("BRMS_Raw");
    responseString = validation.validatePolicy(policyData).toString();
    assertThat(responseString).contains("has one missing Attribute key");
    policyData.setConfigPolicyType(null);
    responseString = validation.validatePolicy(policyData).toString();
    assertThat(responseString).contains("Risk Level Should not be Empty");
    mapAttribute.clear();
    mapAttribute.put("value", "thevalue");
    responseString = validation.validatePolicy(policyData).toString();
    assertThat(responseString).contains("Risk Level Should not be Empty");
    mapAttribute.put("value", "$$$%%%%");
    responseString = validation.validatePolicy(policyData).toString();
    assertThat(responseString).contains("Risk Level Should not be Empty");
    policyData.setConfigPolicyType("Base");
    responseString = validation.validatePolicy(policyData).toString();
    assertThat(responseString).contains("value has spaces or invalid characters");
    policyData.setConfigPolicyType("BRMS_Param");
    responseString = validation.validatePolicy(policyData).toString();
    assertThat(responseString).contains("value has spaces or invalid characters");
    policyData.setConfigPolicyType("BRMS_Raw");
    responseString = validation.validatePolicy(policyData).toString();
    assertThat(responseString).contains("value has spaces or invalid characters");
    policyData.setConfigPolicyType(null);
    policyData.setPolicyType(null);
    responseString = validation.validatePolicy(policyData).toString();
    assertThat(responseString).contains("value has spaces or invalid characters");
}