@Transactional
    public Map<String, String> collectSamlMetadata(String id) throws CollectSamlMetadataException {
        Map<String, String> map = new HashMap<>();
        List<Connection> list;
        LOGGER.info("Start collecting metadata!!");
        digidXClient.remoteLog("1446", null);

        try {
            list = id.equals("all") ? connectionService.listWithAllConnections() : connectionService.listWithOneConnection(Long.valueOf(id));
            for (Connection con : list) startCollectMetadata(con, map);
            map.put("count", String.valueOf(list.size()));
        } catch (Exception e) {
            LOGGER.error("An error has occurred collecting metadata connections: {}", e.getMessage());
            throw new CollectSamlMetadataException(e.getMessage());
        }
        digidXClient.remoteLog("1447", map);
        return map;
    }
@Test
    public void collectSamlMetadataValidTest() throws IOException, CollectSamlMetadataException {
        List<Connection> connections = new ArrayList<>();
        connections.add(newConnection());

        Map<String, String> expected = new HashMap<>();
        expected.put("count", "1");

        when(httpClientMock.execute(any(HttpGet.class))).thenReturn(httpResponseMock);
        when(httpResponseMock.getEntity()).thenReturn(httpEntityMock);
        when(httpEntityMock.getContent()).thenReturn(getClass().getClassLoader().getResourceAsStream("metadata/valid-metadata.xml"));
        when(connectionServiceMock.listWithAllConnections()).thenReturn(connections);
        doNothing().when(digidXClientMock).remoteLog(anyString(), nullable(Map.class));

        Map<String, String> result = metadataProcessorServiceMock.collectSamlMetadata("all");

        verify(connectionServiceMock, times(1)).listWithAllConnections();
        assertNotNull(result);
    }