static void validateJmxPrometheusExporterMetricsConfiguration(JmxPrometheusExporterMetrics jmxMetrics)   {
        List<String> errors = new ArrayList<>();

        if (jmxMetrics.getValueFrom() != null
                && jmxMetrics.getValueFrom().getConfigMapKeyRef() != null)   {
            // The Config Map reference exists
            if (jmxMetrics.getValueFrom().getConfigMapKeyRef().getName() == null
                    || jmxMetrics.getValueFrom().getConfigMapKeyRef().getName().isEmpty())  {
                errors.add("Name of the Config Map with metrics configuration is missing");
            }

            if (jmxMetrics.getValueFrom().getConfigMapKeyRef().getKey() == null
                    || jmxMetrics.getValueFrom().getConfigMapKeyRef().getKey().isEmpty())  {
                errors.add("The key under which the metrics configuration is stored in the ConfigMap is missing");
            }
        } else {
            // The Config Map reference is missing
            errors.add("Config Map reference is missing");
        }

        if (!errors.isEmpty())  {
            throw new InvalidResourceException("Metrics configuration is invalid: " + errors);
        }
    }
@Test
    public void testPrometheusJmxMetricsValidation() {
        assertDoesNotThrow(() -> MetricsModel.validateJmxPrometheusExporterMetricsConfiguration(new JmxPrometheusExporterMetricsBuilder().withNewValueFrom().withConfigMapKeyRef(new ConfigMapKeySelector("my-key", "my-name", false)).endValueFrom().build()));

        InvalidResourceException ex = assertThrows(InvalidResourceException.class, () -> MetricsModel.validateJmxPrometheusExporterMetricsConfiguration(new JmxPrometheusExporterMetricsBuilder().withNewValueFrom().withConfigMapKeyRef(new ConfigMapKeySelector()).endValueFrom().build()));
        assertThat(ex.getMessage(), is("Metrics configuration is invalid: [Name of the Config Map with metrics configuration is missing, The key under which the metrics configuration is stored in the ConfigMap is missing]"));

        ex = assertThrows(InvalidResourceException.class, () -> MetricsModel.validateJmxPrometheusExporterMetricsConfiguration(new JmxPrometheusExporterMetricsBuilder().withNewValueFrom().withConfigMapKeyRef(new ConfigMapKeySelector(null, "my-name", false)).endValueFrom().build()));
        assertThat(ex.getMessage(), is("Metrics configuration is invalid: [The key under which the metrics configuration is stored in the ConfigMap is missing]"));

        ex = assertThrows(InvalidResourceException.class, () -> MetricsModel.validateJmxPrometheusExporterMetricsConfiguration(new JmxPrometheusExporterMetricsBuilder().withNewValueFrom().endValueFrom().build()));
        assertThat(ex.getMessage(), is("Metrics configuration is invalid: [Config Map reference is missing]"));

        ex = assertThrows(InvalidResourceException.class, () -> MetricsModel.validateJmxPrometheusExporterMetricsConfiguration(new JmxPrometheusExporterMetricsBuilder().build()));
        assertThat(ex.getMessage(), is("Metrics configuration is invalid: [Config Map reference is missing]"));
    }