@Test public void getDirectorsAndExcutiveSponsersTest() throws Exception { String response = "{\"took\":195,\"timed_out\":false,\"_shards\":{\"total\":5,\"successful\":5,\"failed\":0}," + "\"hits\":{\"total\":1,\"max_score\":14.612631,\"hits\":[{\"_index\":\"_index\",\"_type\":\"_type\",\"_id\":\"test\",\"_score\":14.612631," + "\"_source\":{\"_appType\":\"_appType\",\"issueID\":\"issueID\",\"businessUnit\":\"billing\",\"discoverydate\":\"2018-06-26 14:00:00-0700\"," + "\"_docid\":\"_docid\",\"description\":\"app1\",\"tier\":\"Tier II\",\"cloudProvider\":\"AWS\",\"@id\":\"test\",\"appTag\":\"appTag\",\"latest\":true," + "\"summary\":\"App: summary\",\"_resourceid\":\"_resourceid\",\"projectLead\":\"abcd@test.com\",\"hiddenFlag\":\"No\",\"appName\":\"appName\"," + "\"director\":\"director1\",\"intakeDate\":\"2018-06-13\",\"workload\":\"workload\",\"parentOf\":[],\"executiveSponsor\":\"executive1\"," + "\"priority\":\"P2 - Critical\",\"issueType\":\"issueType\",\"stage\":\"On-Boarding\",\"appID\":\"appID\",\"internalFlag\":\"No\"," + "\"status\":\"Open\"}}]}}"; mockStatic(PacHttpUtils.class); ReflectionTestUtils.setField(patchingRepositoryImpl, "esUrl", "dummyEsURL"); String emptyDirresponse = "{\"took\":195,\"timed_out\":false,\"_shards\":{\"total\":5,\"successful\":5,\"failed\":0},\"hits\":{\"total\":1,\"max_score\":14.612631," + "\"hits\":[{\"_index\":\"_index\",\"_type\":\"_type\",\"_id\":\"test\",\"_score\":14.612631,\"_source\":{\"_appType\":\"_appType\"," + "\"issueID\":\"issueID\",\"businessUnit\":\"billing\",\"discoverydate\":\"2018-06-26 14:00:00-0700\",\"_docid\":\"_docid\",\"description\":" + "\"app1\",\"tier\":\"Tier II\",\"cloudProvider\":\"AWS\",\"@id\":\"test\",\"appTag\":\"TibcoBW\",\"latest\":true,\"summary\":\"App: summary\"," + "\"_resourceid\":\"_resourceid\",\"projectLead\":\"abcd@test.com\",\"hiddenFlag\":\"No\",\"appName\":\"appName\",\"director\":\"\",\"director\":" + "\"2018-06-13\",\"executiveSponsor\":\"\",\"issueType\":\"issueType\",\"stage\":\"stage\",\"appID\":\"TBW\",\"internalFlag\":\"No\",\"status\":\"Open\"}}]}}"; when(PacHttpUtils.doHttpPost(anyString(), anyString())).thenReturn(emptyDirresponse); patchingRepositoryImpl.getDirectorsAndExcutiveSponsers("app1", "Cloud"); String responsewithempty = "{\"took\":195,\"timed_out\":false,\"_shards\":{\"total\":5,\"successful\":5,\"failed\":0},\"hits\":{\"total\":1," + "\"max_score\":14.612631,\"hits\":[{\"_index\":\"aws_apps\",\"_type\":\"apps\",\"_id\":\"test\",\"_score\":14.612631," + "\"_source\":{\"_appType\":\"_appType\",\"issueID\":\"issueID\",\"businessUnit\":\"billing\",\"discoverydate\":\"2018-06-26 14:00:00-0700\"," + "\"_docid\":\"_docid\",\"description\":\"app1\",\"tier\":\"Tier II\",\"cloudProvider\":\"AWS\",\"@id\":\"test\",\"appTag\":\"appTag\"," + "\"latest\":true,\"summary\":\"App: summary\",\"_resourceid\":\"_resourceid\",\"projectLead\":\"abcd@test.com\",\"hiddenFlag\":\"No\"," + "\"appName\":\"appName\",\"intakeDate\":\"2018-06-13\",\"issueType\":\"issueType\",\"stage\":\"On-Boarding\",\"appID\":\"appID\"," + "\"internalFlag\":\"No\",\"status\":\"Open\"}}]}}"; when(PacHttpUtils.doHttpPost(anyString(), anyString())).thenReturn(responsewithempty); patchingRepositoryImpl.getDirectorsAndExcutiveSponsers("app1", "Cloud"); when(PacHttpUtils.doHttpPost(anyString(), anyString())).thenReturn(response); ReflectionTestUtils.setField(patchingRepositoryImpl, "esUrl", "dummyEsURL"); patchingRepositoryImpl.getDirectorsAndExcutiveSponsers("app1", "Cloud"); when(PacHttpUtils.doHttpPost(anyString(), anyString())).thenThrow(new RuntimeException()); assertThatThrownBy(() -> patchingRepositoryImpl.getDirectorsAndExcutiveSponsers("app1", "Cloud")).isInstanceOf( DataException.class); }
@Override public Map<String, Object> getDirectorsAndExcutiveSponsers(String appTag, String appType) throws DataException { String responseJson = null; String director = null; String executiveSponsor = null; String ipprotocol = null; JsonParser jsonParser; JsonObject resultJson; Map<String, Object> dirAndExecMap = new HashMap<>(); StringBuilder urlToQueryBuffer = new StringBuilder(esUrl).append("/") .append("aws_apps").append("/").append("apps").append("/") .append(SEARCH); StringBuilder requestBody = new StringBuilder( "{\"size\":10000,\"query\":{\"bool\":{\"must\":[{\"match\":{\"_appType\":\"" + appType + "\"}},{\"match\":{\"appTag.keyword\":\"" + appTag + "\"}}]}}}"); try { responseJson = PacHttpUtils.doHttpPost(urlToQueryBuffer.toString(), requestBody.toString()); } catch(Exception e){ throw new DataException(e); } jsonParser = new JsonParser(); resultJson = (JsonObject) jsonParser.parse(responseJson); JsonObject hitsJson = (JsonObject) jsonParser.parse(resultJson.get( "hits").toString()); JsonArray hitsArray = hitsJson.getAsJsonArray("hits"); for (int i = 0; i < hitsArray.size(); i++) { JsonObject source = hitsArray.get(i).getAsJsonObject() .get("_source").getAsJsonObject(); if (null!=source.get(DIRECTOR)&&!source.get(DIRECTOR).isJsonNull()) { director = source.get(DIRECTOR).getAsString(); } else { director = ""; } if (null!=source.get(EXCUTIVE_SPONSOR)&&!source.get(EXCUTIVE_SPONSOR).isJsonNull()) { executiveSponsor = source.get(EXCUTIVE_SPONSOR).getAsString(); } else { executiveSponsor = ""; } logger.info(ipprotocol); dirAndExecMap.put(DIRECTOR, director); dirAndExecMap.put(EXCUTIVE_SPONSOR, executiveSponsor); } return dirAndExecMap; }
PatchingRepositoryImpl implements PatchingRepository, Constants { @Override public Map<String, Object> getDirectorsAndExcutiveSponsers(String appTag, String appType) throws DataException { String responseJson = null; String director = null; String executiveSponsor = null; String ipprotocol = null; JsonParser jsonParser; JsonObject resultJson; Map<String, Object> dirAndExecMap = new HashMap<>(); StringBuilder urlToQueryBuffer = new StringBuilder(esUrl).append("/") .append("aws_apps").append("/").append("apps").append("/") .append(SEARCH); StringBuilder requestBody = new StringBuilder( "{\"size\":10000,\"query\":{\"bool\":{\"must\":[{\"match\":{\"_appType\":\"" + appType + "\"}},{\"match\":{\"appTag.keyword\":\"" + appTag + "\"}}]}}}"); try { responseJson = PacHttpUtils.doHttpPost(urlToQueryBuffer.toString(), requestBody.toString()); } catch(Exception e){ throw new DataException(e); } jsonParser = new JsonParser(); resultJson = (JsonObject) jsonParser.parse(responseJson); JsonObject hitsJson = (JsonObject) jsonParser.parse(resultJson.get( "hits").toString()); JsonArray hitsArray = hitsJson.getAsJsonArray("hits"); for (int i = 0; i < hitsArray.size(); i++) { JsonObject source = hitsArray.get(i).getAsJsonObject() .get("_source").getAsJsonObject(); if (null!=source.get(DIRECTOR)&&!source.get(DIRECTOR).isJsonNull()) { director = source.get(DIRECTOR).getAsString(); } else { director = ""; } if (null!=source.get(EXCUTIVE_SPONSOR)&&!source.get(EXCUTIVE_SPONSOR).isJsonNull()) { executiveSponsor = source.get(EXCUTIVE_SPONSOR).getAsString(); } else { executiveSponsor = ""; } logger.info(ipprotocol); dirAndExecMap.put(DIRECTOR, director); dirAndExecMap.put(EXCUTIVE_SPONSOR, executiveSponsor); } return dirAndExecMap; } }
PatchingRepositoryImpl implements PatchingRepository, Constants { @Override public Map<String, Object> getDirectorsAndExcutiveSponsers(String appTag, String appType) throws DataException { String responseJson = null; String director = null; String executiveSponsor = null; String ipprotocol = null; JsonParser jsonParser; JsonObject resultJson; Map<String, Object> dirAndExecMap = new HashMap<>(); StringBuilder urlToQueryBuffer = new StringBuilder(esUrl).append("/") .append("aws_apps").append("/").append("apps").append("/") .append(SEARCH); StringBuilder requestBody = new StringBuilder( "{\"size\":10000,\"query\":{\"bool\":{\"must\":[{\"match\":{\"_appType\":\"" + appType + "\"}},{\"match\":{\"appTag.keyword\":\"" + appTag + "\"}}]}}}"); try { responseJson = PacHttpUtils.doHttpPost(urlToQueryBuffer.toString(), requestBody.toString()); } catch(Exception e){ throw new DataException(e); } jsonParser = new JsonParser(); resultJson = (JsonObject) jsonParser.parse(responseJson); JsonObject hitsJson = (JsonObject) jsonParser.parse(resultJson.get( "hits").toString()); JsonArray hitsArray = hitsJson.getAsJsonArray("hits"); for (int i = 0; i < hitsArray.size(); i++) { JsonObject source = hitsArray.get(i).getAsJsonObject() .get("_source").getAsJsonObject(); if (null!=source.get(DIRECTOR)&&!source.get(DIRECTOR).isJsonNull()) { director = source.get(DIRECTOR).getAsString(); } else { director = ""; } if (null!=source.get(EXCUTIVE_SPONSOR)&&!source.get(EXCUTIVE_SPONSOR).isJsonNull()) { executiveSponsor = source.get(EXCUTIVE_SPONSOR).getAsString(); } else { executiveSponsor = ""; } logger.info(ipprotocol); dirAndExecMap.put(DIRECTOR, director); dirAndExecMap.put(EXCUTIVE_SPONSOR, executiveSponsor); } return dirAndExecMap; }  }
PatchingRepositoryImpl implements PatchingRepository, Constants { @Override public Map<String, Object> getDirectorsAndExcutiveSponsers(String appTag, String appType) throws DataException { String responseJson = null; String director = null; String executiveSponsor = null; String ipprotocol = null; JsonParser jsonParser; JsonObject resultJson; Map<String, Object> dirAndExecMap = new HashMap<>(); StringBuilder urlToQueryBuffer = new StringBuilder(esUrl).append("/") .append("aws_apps").append("/").append("apps").append("/") .append(SEARCH); StringBuilder requestBody = new StringBuilder( "{\"size\":10000,\"query\":{\"bool\":{\"must\":[{\"match\":{\"_appType\":\"" + appType + "\"}},{\"match\":{\"appTag.keyword\":\"" + appTag + "\"}}]}}}"); try { responseJson = PacHttpUtils.doHttpPost(urlToQueryBuffer.toString(), requestBody.toString()); } catch(Exception e){ throw new DataException(e); } jsonParser = new JsonParser(); resultJson = (JsonObject) jsonParser.parse(responseJson); JsonObject hitsJson = (JsonObject) jsonParser.parse(resultJson.get( "hits").toString()); JsonArray hitsArray = hitsJson.getAsJsonArray("hits"); for (int i = 0; i < hitsArray.size(); i++) { JsonObject source = hitsArray.get(i).getAsJsonObject() .get("_source").getAsJsonObject(); if (null!=source.get(DIRECTOR)&&!source.get(DIRECTOR).isJsonNull()) { director = source.get(DIRECTOR).getAsString(); } else { director = ""; } if (null!=source.get(EXCUTIVE_SPONSOR)&&!source.get(EXCUTIVE_SPONSOR).isJsonNull()) { executiveSponsor = source.get(EXCUTIVE_SPONSOR).getAsString(); } else { executiveSponsor = ""; } logger.info(ipprotocol); dirAndExecMap.put(DIRECTOR, director); dirAndExecMap.put(EXCUTIVE_SPONSOR, executiveSponsor); } return dirAndExecMap; }  @Override List<Map<String, Object>> getPatchingProgress(String assetGroup,
            LocalDate startDate, LocalDate endDate); @Override List<Map<String, Object>> getIssueInfo(String assetGroup); List<Map<String, Object>> getClosedIssueInfo(String assetGroup,
            int size); @Override List<Map<String, Object>> getInstanceInfo(String assetGroup,
            Map<String, String> filters); @Override List<Map<String, Object>> getExecAndDirectorInfo(); @Override long getInstanceInfoCount(String assetGroup,
            Map<String, String> filters, String searchText); @Override String getAmilAvailDate(int year, int quarter); @Override int getPatchingWindow(); @Override Map<String, Long> getQuartersWithPatchingData(String assetGroup); Map<String, Object> addParentConditionPatching(String targetType); @Override List<Map<String, Object>> getOnpremIssueInfo(String assetGroup); @Override List<Map<String, Object>> getOnpremResourceInfo(String assetGroup,
            Map<String, String> filters); @Override Map<String, Object> getDirectorsAndExcutiveSponsers(String appTag,
            String appType); @Override Map<String, Long> getNonCompliantNumberForAgAndResourceType(
            String assetGroup, String resourceType); @Override List<Map<String, Object>> getPatchingPercentForDateRange(String assetGroup, LocalDate fromDate,
			LocalDate toDate); }
PatchingRepositoryImpl implements PatchingRepository, Constants { @Override public Map<String, Object> getDirectorsAndExcutiveSponsers(String appTag, String appType) throws DataException { String responseJson = null; String director = null; String executiveSponsor = null; String ipprotocol = null; JsonParser jsonParser; JsonObject resultJson; Map<String, Object> dirAndExecMap = new HashMap<>(); StringBuilder urlToQueryBuffer = new StringBuilder(esUrl).append("/") .append("aws_apps").append("/").append("apps").append("/") .append(SEARCH); StringBuilder requestBody = new StringBuilder( "{\"size\":10000,\"query\":{\"bool\":{\"must\":[{\"match\":{\"_appType\":\"" + appType + "\"}},{\"match\":{\"appTag.keyword\":\"" + appTag + "\"}}]}}}"); try { responseJson = PacHttpUtils.doHttpPost(urlToQueryBuffer.toString(), requestBody.toString()); } catch(Exception e){ throw new DataException(e); } jsonParser = new JsonParser(); resultJson = (JsonObject) jsonParser.parse(responseJson); JsonObject hitsJson = (JsonObject) jsonParser.parse(resultJson.get( "hits").toString()); JsonArray hitsArray = hitsJson.getAsJsonArray("hits"); for (int i = 0; i < hitsArray.size(); i++) { JsonObject source = hitsArray.get(i).getAsJsonObject() .get("_source").getAsJsonObject(); if (null!=source.get(DIRECTOR)&&!source.get(DIRECTOR).isJsonNull()) { director = source.get(DIRECTOR).getAsString(); } else { director = ""; } if (null!=source.get(EXCUTIVE_SPONSOR)&&!source.get(EXCUTIVE_SPONSOR).isJsonNull()) { executiveSponsor = source.get(EXCUTIVE_SPONSOR).getAsString(); } else { executiveSponsor = ""; } logger.info(ipprotocol); dirAndExecMap.put(DIRECTOR, director); dirAndExecMap.put(EXCUTIVE_SPONSOR, executiveSponsor); } return dirAndExecMap; }  @Override List<Map<String, Object>> getPatchingProgress(String assetGroup,
            LocalDate startDate, LocalDate endDate); @Override List<Map<String, Object>> getIssueInfo(String assetGroup); List<Map<String, Object>> getClosedIssueInfo(String assetGroup,
            int size); @Override List<Map<String, Object>> getInstanceInfo(String assetGroup,
            Map<String, String> filters); @Override List<Map<String, Object>> getExecAndDirectorInfo(); @Override long getInstanceInfoCount(String assetGroup,
            Map<String, String> filters, String searchText); @Override String getAmilAvailDate(int year, int quarter); @Override int getPatchingWindow(); @Override Map<String, Long> getQuartersWithPatchingData(String assetGroup); Map<String, Object> addParentConditionPatching(String targetType); @Override List<Map<String, Object>> getOnpremIssueInfo(String assetGroup); @Override List<Map<String, Object>> getOnpremResourceInfo(String assetGroup,
            Map<String, String> filters); @Override Map<String, Object> getDirectorsAndExcutiveSponsers(String appTag,
            String appType); @Override Map<String, Long> getNonCompliantNumberForAgAndResourceType(
            String assetGroup, String resourceType); @Override List<Map<String, Object>> getPatchingPercentForDateRange(String assetGroup, LocalDate fromDate,
			LocalDate toDate);  }