ElkConnectorImpl implements ElkConnector { @Override public boolean delete(PolicyRestAdapter policyData) throws IllegalStateException { PolicyIndexType indexType = null; JestResult result; try { String policyName = policyData.getNewFileName(); if (policyName.contains("Config_")) { policyName = policyName.replace(".Config_", ":Config_"); } else if (policyName.contains("Action_")) { policyName = policyName.replace(".Action_", ":Action_"); } else if (policyName.contains("Decision_")) { policyName = policyName.replace(".Decision_", ":Decision_"); } String[] splitPolicyName = policyName.split(":"); indexType = ElkConnector.toPolicyIndexType(splitPolicyName[1]); if (!isType(indexType)) { throw new IllegalStateException( "ELK: Index: " + ELK_INDEX_POLICY + " Type: " + indexType + " is not configured"); } PolicyElasticData elasticData = new PolicyElasticData(policyData); Delete deleteRequest = new Delete.Builder(elasticData.getPolicyName()).index(ELK_INDEX_POLICY) .type(indexType.name()).build(); result = jestClient.execute(deleteRequest); } catch (IllegalArgumentException | IOException e) { LOGGER.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + ": delete:" + indexType + ": null" + ":" + policyData.getNewFileName() + ": " + e.getMessage(), e); throw new IllegalStateException(e); } if (result.isSucceeded()) { if (LOGGER.isInfoEnabled()) LOGGER.info("OK: DELETE operation of " + indexType + ":" + policyData.getNewFileName() + ": " + "success=" + result.isSucceeded() + "[" + result.getResponseCode() + ":" + result.getPathToResult() + "]" + System.lineSeparator() + result.getJsonString()); } else { if (LOGGER.isWarnEnabled()) LOGGER.warn("FAILURE: DELETE operation of " + indexType + ":" + policyData.getNewFileName() + ": " + "success=" + result.isSucceeded() + "[" + result.getResponseCode() + ":" + result.getPathToResult() + "]" + System.lineSeparator() + result.getJsonString()); } return result.isSucceeded(); } ElkConnectorImpl(); @Override JestResult search(PolicyIndexType type, String text); @Override JestResult search(PolicyIndexType type, String text, Map<String, String> filter_s); boolean put(PolicyRestAdapter policyData); @Override boolean delete(PolicyRestAdapter policyData); @Override boolean update(PolicyRestAdapter policyData);  }
@Test public void testDelete() { thrown.expect(NullPointerException.class); ElkConnectorImpl impl = new ElkConnectorImpl(); PolicyRestAdapter adapter = new PolicyRestAdapter(); impl.delete(adapter); fail("Expected exception to be thrown"); }