Search in sources :

Example 1 with TestLogger

use of io.strimzi.test.logging.TestLogger in project strimzi by strimzi.

the class ValidationVisitorTest method testValidationErrorsAreLogged.

@Test
public void testValidationErrorsAreLogged() {
    Kafka k = TestUtils.fromYaml("/example.yaml", Kafka.class, true);
    assertThat(k, is(notNullValue()));
    TestLogger logger = TestLogger.create(ValidationVisitorTest.class);
    HasMetadata resource = new KafkaBuilder().withNewMetadata().withName("testname").withNamespace("testnamespace").endMetadata().withApiVersion("v1beta2").build();
    Set<Condition> warningConditions = new HashSet<>();
    ResourceVisitor.visit(Reconciliation.DUMMY_RECONCILIATION, k, new ValidationVisitor(resource, logger, warningConditions));
    List<String> warningMessages = warningConditions.stream().map(Condition::getMessage).collect(Collectors.toList());
    assertThat(warningMessages, hasItem("Contains object at path spec.kafka with an unknown property: foo"));
    assertThat(warningMessages, hasItem("In API version v1beta2 the enableECDSA property at path spec.kafka.listeners.auth.enableECDSA has been deprecated."));
    assertThat(warningMessages, hasItem("In API version v1beta2 the service property at path spec.kafkaExporter.template.service has been deprecated. " + "The Kafka Exporter service has been removed."));
    logger.assertLoggedAtLeastOnce(lm -> lm.level() == Level.WARN && lm.formattedMessage().matches("Reconciliation #[0-9]*\\(test\\) kind\\(namespace\\/name\\): " + "Contains object at path spec.kafka with an unknown property: foo"));
    logger.assertLoggedAtLeastOnce(lm -> lm.level() == Level.WARN && lm.formattedMessage().matches("Reconciliation #[0-9]*\\(test\\) kind\\(namespace\\/name\\): " + "In API version v1beta2 the enableECDSA property at path spec.kafka.listeners.auth.enableECDSA has been deprecated."));
    logger.assertLoggedAtLeastOnce(lm -> lm.level() == Level.WARN && lm.formattedMessage().matches("Reconciliation #[0-9]*\\(test\\) kind\\(namespace\\/name\\): " + "In API version v1beta2 the service property at path spec.kafkaExporter.template.service has been deprecated. " + "The Kafka Exporter service has been removed."));
}
Also used : Condition(io.strimzi.api.kafka.model.status.Condition) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Kafka(io.strimzi.api.kafka.model.Kafka) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) TestLogger(io.strimzi.test.logging.TestLogger) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 2 with TestLogger

use of io.strimzi.test.logging.TestLogger in project strimzi-kafka-operator by strimzi.

the class ValidationVisitorTest method testValidationErrorsAreLogged.

@Test
public void testValidationErrorsAreLogged() {
    Kafka k = TestUtils.fromYaml("/example.yaml", Kafka.class, true);
    assertThat(k, is(notNullValue()));
    TestLogger logger = TestLogger.create(ValidationVisitorTest.class);
    HasMetadata resource = new KafkaBuilder().withNewMetadata().withName("testname").withNamespace("testnamespace").endMetadata().withApiVersion("v1beta2").build();
    Set<Condition> warningConditions = new HashSet<>();
    ResourceVisitor.visit(Reconciliation.DUMMY_RECONCILIATION, k, new ValidationVisitor(resource, logger, warningConditions));
    List<String> warningMessages = warningConditions.stream().map(Condition::getMessage).collect(Collectors.toList());
    assertThat(warningMessages, hasItem("Contains object at path spec.kafka with an unknown property: foo"));
    assertThat(warningMessages, hasItem("In API version v1beta2 the enableECDSA property at path spec.kafka.listeners.auth.enableECDSA has been deprecated."));
    assertThat(warningMessages, hasItem("In API version v1beta2 the service property at path spec.kafkaExporter.template.service has been deprecated. " + "The Kafka Exporter service has been removed."));
    logger.assertLoggedAtLeastOnce(lm -> lm.level() == Level.WARN && lm.formattedMessage().matches("Reconciliation #[0-9]*\\(test\\) kind\\(namespace\\/name\\): " + "Contains object at path spec.kafka with an unknown property: foo"));
    logger.assertLoggedAtLeastOnce(lm -> lm.level() == Level.WARN && lm.formattedMessage().matches("Reconciliation #[0-9]*\\(test\\) kind\\(namespace\\/name\\): " + "In API version v1beta2 the enableECDSA property at path spec.kafka.listeners.auth.enableECDSA has been deprecated."));
    logger.assertLoggedAtLeastOnce(lm -> lm.level() == Level.WARN && lm.formattedMessage().matches("Reconciliation #[0-9]*\\(test\\) kind\\(namespace\\/name\\): " + "In API version v1beta2 the service property at path spec.kafkaExporter.template.service has been deprecated. " + "The Kafka Exporter service has been removed."));
}
Also used : Condition(io.strimzi.api.kafka.model.status.Condition) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Kafka(io.strimzi.api.kafka.model.Kafka) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) TestLogger(io.strimzi.test.logging.TestLogger) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)2 Kafka (io.strimzi.api.kafka.model.Kafka)2 KafkaBuilder (io.strimzi.api.kafka.model.KafkaBuilder)2 Condition (io.strimzi.api.kafka.model.status.Condition)2 TestLogger (io.strimzi.test.logging.TestLogger)2 HashSet (java.util.HashSet)2 Test (org.junit.jupiter.api.Test)2