FirewallConfigPolicy extends Policy { @Override public Map<String, String> savePolicies() throws PAPException { Map<String, String> successMap = new HashMap<>(); if (isPolicyExists()) { successMap.put("EXISTS", "This Policy already exist on the PAP"); return successMap; } if (!isPreparedToSave()) { prepareToSave(); } Path newPolicyPath = null; newPolicyPath = Paths.get(policyAdapter.getNewFileName()); Boolean dbIsUpdated = false; if (policyAdapter.getApiflag() != null && "admin".equalsIgnoreCase(policyAdapter.getApiflag())) { if (policyAdapter.isEditPolicy()) { dbIsUpdated = updateFirewallDictionaryData(policyAdapter.getJsonBody(), policyAdapter.getPrevJsonBody()); } else { try { dbIsUpdated = insertFirewallDicionaryData(policyAdapter.getJsonBody()); } catch (SQLException e) { throw new PAPException(e); } } } else { dbIsUpdated = true; } if (dbIsUpdated) { successMap = createPolicy(newPolicyPath, getCorrectPolicyDataObject()); } else { PolicyLogger.error("Failed to Update the Database Dictionary Tables."); String jsonBody = policyAdapter.getPrevJsonBody(); if (jsonBody != null) { saveConfigurations(policyName, jsonBody); } else { saveConfigurations(policyName, ""); } successMap.put("fwdberror", "DB UPDATE"); } return successMap; } FirewallConfigPolicy(); @Autowired  FirewallConfigPolicy(CommonClassDao commonClassDao);  FirewallConfigPolicy(PolicyRestAdapter policyAdapter); @Override Map<String, String> savePolicies(); @Override boolean prepareToSave(); @Override Object getCorrectPolicyDataObject();  }
@Test public void testSavePolicies() { Map<String, String> successMap = new HashMap<>(); successMap.put("success", "success"); try { when(mockFWConfig.savePolicies()).thenReturn(successMap); successMap = mockFWConfig.savePolicies(); } catch (Exception e) { logger.error("Exception Occured" + e); } }