public String getServiceUUID(Connection connection, String serviceEntityId, int consumingServiceIdx) {
        if (connection == null || serviceEntityId == null)
            return null;

        EntityDescriptor serviceEntityDescriptor = resolveEntityDescriptorFromMetadata(connection, serviceEntityId);

        if (serviceEntityDescriptor == null || serviceEntityDescriptor.getRoleDescriptors() == null) {
            return null;
        }

        List<XMLObject> list = serviceEntityDescriptor.getRoleDescriptors().get(0).getOrderedChildren();

        if (list == null) {
            return null;
        }

        Optional<XMLObject> xmlObject = list
            .stream()
            .filter(obj -> obj instanceof AttributeConsumingService && ((AttributeConsumingService) obj).getIndex() == consumingServiceIdx)
            .findFirst();

        if (xmlObject.isEmpty()) {
            return null;
        }

        AttributeConsumingService attributeConsumingService = (AttributeConsumingService) xmlObject.get();
        Optional<RequestedAttribute> requestedAttribute = attributeConsumingService.getRequestedAttributes()
            .stream()
            .filter(o -> o.getName().equals(SAML_SERVICE_UUID_NAME))
            .findFirst();

        return requestedAttribute.isEmpty() ? null : ((XSAny) requestedAttribute.get().getAttributeValues().get(0)).getTextContent();
    }
@Test
    void metadataResponseMapperMapsSuccessResponseTest() {
        String samlData = "samlData";
        Connection connection = newConnection(SAML_COMBICONNECT, true, true, true);
        Service service = newService(true);
        String requestStatus = "OK";

        SamlMetadataResponse metadataResponse = samlMetadataResponseMapper.mapSuccessResponse(samlData, connection, service, requestStatus);
        assertEquals(metadataResponse.getSamlMetadata(), samlData);
        assertEquals(metadataResponse.getFederationName(), connection.getSsoDomain());
        assertEquals(metadataResponse.getMinimumReliabilityLevel(), service.getMinimumReliabilityLevel());
        assertEquals(metadataResponse.getEncryptionIdType(), service.getEncryptionIdType().name());
        assertEquals(metadataResponse.getAppReturnUrl(), service.getAppReturnUrl());
        assertEquals(metadataResponse.getAppActive(), service.getAppActive());
        assertEquals(metadataResponse.getServiceName(), service.getName());
        assertEquals(metadataResponse.getLegacyWebserviceId(), service.getLegacyServiceId());
        assertEquals(metadataResponse.getRequestStatus(), requestStatus);
        assertNull(metadataResponse.getErrorDescription());
        assertEquals(metadataResponse.getServiceUuid(), service.getServiceUuid());
        assertEquals(metadataResponse.getPermissionQuestion(), service.getPermissionQuestion());
        assertEquals(metadataResponse.getProtocolType(), connection.getProtocolType());
    }