EntityBuilderHelper { @VisibleForTesting static Entity getEntityWithMappings(final String type, final String path, final String id, final Element element, final String mappingAction, final Map<String, Object> mappingProperties) { Entity entity = new Entity(type, path, id, element, null); entity.setMappingAction(mappingAction); mappingProperties.forEach(entity::setMappingProperty); String mapBy = (String) entity.getMappingProperties().get(MappingProperties.MAP_BY); if (MappingProperties.PATH.equals(mapBy)) { entity.setMappingProperty(MappingProperties.MAP_TO, path); } else if (MappingProperties.NAME.equals(mapBy)) { entity.setMappingProperty(MappingProperties.MAP_TO, PathUtils.extractName(path)); } return entity; } private  EntityBuilderHelper();   }
@Test public void testGetEntityWithMappings() throws DocumentParseException { Map<String, Object> mappingProperties = new HashMap<>(); mappingProperties.put(MappingProperties.MAP_BY, MappingProperties.PATH); String id = "testId"; String path = "root/subpath/test"; DocumentTools documentTools = DocumentTools.INSTANCE; Document document = documentTools.parse("<Policy></Policy>"); Entity entity = EntityBuilderHelper.getEntityWithMappings(EntityTypes.POLICY_TYPE, path, id, document.getDocumentElement(), MappingActions.NEW_OR_UPDATE, mappingProperties); Assert.assertEquals(id, entity.getId()); Assert.assertEquals(path, entity.getName()); Assert.assertEquals(EntityTypes.POLICY_TYPE, entity.getType()); Assert.assertEquals(MappingActions.NEW_OR_UPDATE, entity.getMappingAction()); Assert.assertEquals(path, entity.getMappingProperties().get(MappingProperties.MAP_TO)); mappingProperties.put(MappingProperties.MAP_BY, MappingProperties.NAME); entity = EntityBuilderHelper.getEntityWithMappings(EntityTypes.POLICY_TYPE, path, id, document.getDocumentElement(), MappingActions.NEW_OR_UPDATE, mappingProperties); Assert.assertEquals(PathUtils.extractName(path), entity.getMappingProperties().get(MappingProperties.MAP_TO)); }