@SuppressWarnings("unchecked") @Test public void getAllTargetTypesTest() throws Exception { when(targetTypesRepository.findAll()).thenReturn(getTargetTypesDetailsList()); List<AssetGroupTargetTypes> selectedTargetTypes = getSelectedTargetTypes(); when(config.getElasticSearch()).thenReturn(getElasticSearchProperty()); HttpEntity jsonEntity = new StringEntity("{}", ContentType.APPLICATION_JSON); when(targetTypesRepository.existsById(anyString())).thenReturn(false); when(response.getEntity()).thenReturn(jsonEntity); when(restClient.performRequest(anyString(), anyString(), any(Map.class), any(HttpEntity.class), Matchers.<Header>anyVararg())).thenReturn(response); ReflectionTestUtils.setField(targetTypesServiceImpl, "restClient", restClient); when(sl.getStatusCode()).thenReturn(200); when(response.getStatusLine()).thenReturn(sl); String jsonString = "{\"k1\":\"v1\",\"k2\":\"v2\"}"; JsonNode actualObj = new ObjectMapper().readTree(jsonString); when(mapper.readTree(anyString())).thenReturn(actualObj); assertThat(targetTypesService.getAllTargetTypes(selectedTargetTypes), is(notNullValue())); }
@Override public List<TargetTypesDetails> getAllTargetTypes(List<AssetGroupTargetTypes> selectedTargetTypes) { Map<String, Integer> selectedTargetTypeIndex = buildSelectedTargetTypesIndex(selectedTargetTypes); List<TargetTypesDetails> attributes = Lists.newArrayList(); List<TargetTypes> allTargets = targetTypesRepository.findAll(); for (TargetTypes targetType : allTargets) { String targetName = targetType.getTargetName().trim(); Integer index = selectedTargetTypeIndex.get(targetName.toLowerCase()); if(index==null) { String dataSourceName = targetType.getDataSourceName().trim(); TargetTypesDetails targetTypeAttribute = new TargetTypesDetails(); targetTypeAttribute.setAttributes(Lists.newArrayList()); targetTypeAttribute.setTargetName(targetType.getTargetName().trim()); targetTypeAttribute.setAllAttributesName(getFieldNames(dataSourceName + "_" + targetName, targetName)); targetTypeAttribute.setIncludeAll(false); attributes.add(targetTypeAttribute); } else { String dataSourceName = targetType.getDataSourceName().trim(); TargetTypesDetails targetTypeAttribute = new TargetTypesDetails(); targetTypeAttribute.setTargetName(targetType.getTargetName().trim()); targetTypeAttribute.setAllAttributesName(getFieldNames(dataSourceName + "_" + targetName, targetName)); attributes.add(targetTypeAttribute); } } return attributes; }
TargetTypesServiceImpl implements TargetTypesService { @Override public List<TargetTypesDetails> getAllTargetTypes(List<AssetGroupTargetTypes> selectedTargetTypes) { Map<String, Integer> selectedTargetTypeIndex = buildSelectedTargetTypesIndex(selectedTargetTypes); List<TargetTypesDetails> attributes = Lists.newArrayList(); List<TargetTypes> allTargets = targetTypesRepository.findAll(); for (TargetTypes targetType : allTargets) { String targetName = targetType.getTargetName().trim(); Integer index = selectedTargetTypeIndex.get(targetName.toLowerCase()); if(index==null) { String dataSourceName = targetType.getDataSourceName().trim(); TargetTypesDetails targetTypeAttribute = new TargetTypesDetails(); targetTypeAttribute.setAttributes(Lists.newArrayList()); targetTypeAttribute.setTargetName(targetType.getTargetName().trim()); targetTypeAttribute.setAllAttributesName(getFieldNames(dataSourceName + "_" + targetName, targetName)); targetTypeAttribute.setIncludeAll(false); attributes.add(targetTypeAttribute); } else { String dataSourceName = targetType.getDataSourceName().trim(); TargetTypesDetails targetTypeAttribute = new TargetTypesDetails(); targetTypeAttribute.setTargetName(targetType.getTargetName().trim()); targetTypeAttribute.setAllAttributesName(getFieldNames(dataSourceName + "_" + targetName, targetName)); attributes.add(targetTypeAttribute); } } return attributes; } }
TargetTypesServiceImpl implements TargetTypesService { @Override public List<TargetTypesDetails> getAllTargetTypes(List<AssetGroupTargetTypes> selectedTargetTypes) { Map<String, Integer> selectedTargetTypeIndex = buildSelectedTargetTypesIndex(selectedTargetTypes); List<TargetTypesDetails> attributes = Lists.newArrayList(); List<TargetTypes> allTargets = targetTypesRepository.findAll(); for (TargetTypes targetType : allTargets) { String targetName = targetType.getTargetName().trim(); Integer index = selectedTargetTypeIndex.get(targetName.toLowerCase()); if(index==null) { String dataSourceName = targetType.getDataSourceName().trim(); TargetTypesDetails targetTypeAttribute = new TargetTypesDetails(); targetTypeAttribute.setAttributes(Lists.newArrayList()); targetTypeAttribute.setTargetName(targetType.getTargetName().trim()); targetTypeAttribute.setAllAttributesName(getFieldNames(dataSourceName + "_" + targetName, targetName)); targetTypeAttribute.setIncludeAll(false); attributes.add(targetTypeAttribute); } else { String dataSourceName = targetType.getDataSourceName().trim(); TargetTypesDetails targetTypeAttribute = new TargetTypesDetails(); targetTypeAttribute.setTargetName(targetType.getTargetName().trim()); targetTypeAttribute.setAllAttributesName(getFieldNames(dataSourceName + "_" + targetName, targetName)); attributes.add(targetTypeAttribute); } } return attributes; }  }
TargetTypesServiceImpl implements TargetTypesService { @Override public List<TargetTypesDetails> getAllTargetTypes(List<AssetGroupTargetTypes> selectedTargetTypes) { Map<String, Integer> selectedTargetTypeIndex = buildSelectedTargetTypesIndex(selectedTargetTypes); List<TargetTypesDetails> attributes = Lists.newArrayList(); List<TargetTypes> allTargets = targetTypesRepository.findAll(); for (TargetTypes targetType : allTargets) { String targetName = targetType.getTargetName().trim(); Integer index = selectedTargetTypeIndex.get(targetName.toLowerCase()); if(index==null) { String dataSourceName = targetType.getDataSourceName().trim(); TargetTypesDetails targetTypeAttribute = new TargetTypesDetails(); targetTypeAttribute.setAttributes(Lists.newArrayList()); targetTypeAttribute.setTargetName(targetType.getTargetName().trim()); targetTypeAttribute.setAllAttributesName(getFieldNames(dataSourceName + "_" + targetName, targetName)); targetTypeAttribute.setIncludeAll(false); attributes.add(targetTypeAttribute); } else { String dataSourceName = targetType.getDataSourceName().trim(); TargetTypesDetails targetTypeAttribute = new TargetTypesDetails(); targetTypeAttribute.setTargetName(targetType.getTargetName().trim()); targetTypeAttribute.setAllAttributesName(getFieldNames(dataSourceName + "_" + targetName, targetName)); attributes.add(targetTypeAttribute); } } return attributes; }  @Override Collection<String> getTargetTypesNamesByDataSourceName(final String dataSourceName); @Override List<TargetTypes> getAllTargetTypesByDomainList(final List<String> domains); @Override Page<TargetTypesProjections> getAllTargetTypeDetails(String searchTerm, int page, int size); @Override List<String> getAllTargetTypesCategories(); @Override List<TargetTypesDetails> getAllTargetTypes(List<AssetGroupTargetTypes> selectedTargetTypes); @Override List<TargetTypeAttribute> getTargetTypeAttributes(final List<TargetTypes> targetTypes); @Override Map<String, Object> getAttributeValues(AttributeValuesRequest attributeValuesRequest); @Override TargetTypes getTargetTypesByName(String targetTypeName); @Override String updateTargetTypeDetails(CreateUpdateTargetTypeDetailsRequest targetTypesDetails, final String userId); @Override String addTargetTypeDetails(final CreateUpdateTargetTypeDetailsRequest targetTypeDetailsRequest, final String userId); @Override void deleteIndex(String targetTypeIndex); }
TargetTypesServiceImpl implements TargetTypesService { @Override public List<TargetTypesDetails> getAllTargetTypes(List<AssetGroupTargetTypes> selectedTargetTypes) { Map<String, Integer> selectedTargetTypeIndex = buildSelectedTargetTypesIndex(selectedTargetTypes); List<TargetTypesDetails> attributes = Lists.newArrayList(); List<TargetTypes> allTargets = targetTypesRepository.findAll(); for (TargetTypes targetType : allTargets) { String targetName = targetType.getTargetName().trim(); Integer index = selectedTargetTypeIndex.get(targetName.toLowerCase()); if(index==null) { String dataSourceName = targetType.getDataSourceName().trim(); TargetTypesDetails targetTypeAttribute = new TargetTypesDetails(); targetTypeAttribute.setAttributes(Lists.newArrayList()); targetTypeAttribute.setTargetName(targetType.getTargetName().trim()); targetTypeAttribute.setAllAttributesName(getFieldNames(dataSourceName + "_" + targetName, targetName)); targetTypeAttribute.setIncludeAll(false); attributes.add(targetTypeAttribute); } else { String dataSourceName = targetType.getDataSourceName().trim(); TargetTypesDetails targetTypeAttribute = new TargetTypesDetails(); targetTypeAttribute.setTargetName(targetType.getTargetName().trim()); targetTypeAttribute.setAllAttributesName(getFieldNames(dataSourceName + "_" + targetName, targetName)); attributes.add(targetTypeAttribute); } } return attributes; }  @Override Collection<String> getTargetTypesNamesByDataSourceName(final String dataSourceName); @Override List<TargetTypes> getAllTargetTypesByDomainList(final List<String> domains); @Override Page<TargetTypesProjections> getAllTargetTypeDetails(String searchTerm, int page, int size); @Override List<String> getAllTargetTypesCategories(); @Override List<TargetTypesDetails> getAllTargetTypes(List<AssetGroupTargetTypes> selectedTargetTypes); @Override List<TargetTypeAttribute> getTargetTypeAttributes(final List<TargetTypes> targetTypes); @Override Map<String, Object> getAttributeValues(AttributeValuesRequest attributeValuesRequest); @Override TargetTypes getTargetTypesByName(String targetTypeName); @Override String updateTargetTypeDetails(CreateUpdateTargetTypeDetailsRequest targetTypesDetails, final String userId); @Override String addTargetTypeDetails(final CreateUpdateTargetTypeDetailsRequest targetTypeDetailsRequest, final String userId); @Override void deleteIndex(String targetTypeIndex);  }