Skip to content

Commit

Permalink
Use copy of test topology properties (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
philipp94831 authored Jan 8, 2024
1 parent e6dd6c0 commit c59c2dd
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2023 bakdata
* Copyright (c) 2024 bakdata
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -34,6 +34,7 @@
import java.nio.file.Path;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.NoSuchElementException;
Expand Down Expand Up @@ -151,10 +152,11 @@ public TestTopology(final Function<? super Properties, ? extends Topology> topol
* APPLICATION_ID_CONFIG, BOOTSTRAP_SERVERS_CONFIG
*/
public TestTopology(final Function<? super Properties, ? extends Topology> topologyFactory,
final Map<Object, Object> properties) {
final Map<?, ?> properties) {
this(topologyFactory, schemaRegistryUrl -> {
properties.put(AbstractKafkaSchemaSerDeConfig.SCHEMA_REGISTRY_URL_CONFIG, schemaRegistryUrl);
return properties;
final Map<Object, Object> newProperties = new HashMap<>(properties);
newProperties.put(AbstractKafkaSchemaSerDeConfig.SCHEMA_REGISTRY_URL_CONFIG, schemaRegistryUrl);
return Map.copyOf(newProperties);
});
}

Expand All @@ -180,7 +182,7 @@ public TestTopology(final Supplier<? extends Topology> topologyFactory,
* @param properties The properties of the Kafka Streams application under test. Required entries:
* APPLICATION_ID_CONFIG, BOOTSTRAP_SERVERS_CONFIG
*/
public TestTopology(final Supplier<? extends Topology> topologyFactory, final Map<Object, Object> properties) {
public TestTopology(final Supplier<? extends Topology> topologyFactory, final Map<?, ?> properties) {
this(props -> topologyFactory.get(), properties);
}

Expand All @@ -206,7 +208,7 @@ public TestTopology(final Topology topology,
* @param properties The properties of the Kafka Streams application under test. Required entries:
* APPLICATION_ID_CONFIG, BOOTSTRAP_SERVERS_CONFIG
*/
public TestTopology(final Topology topology, final Map<Object, Object> properties) {
public TestTopology(final Topology topology, final Map<?, ?> properties) {
this(props -> topology, properties);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* MIT License
*
* Copyright (c) 2024 bakdata
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package com.bakdata.fluent_kafka_streams_tests;

import static org.assertj.core.api.Assertions.assertThatCode;

import com.bakdata.fluent_kafka_streams_tests.test_applications.MirrorAvro;
import com.bakdata.fluent_kafka_streams_tests.test_types.City;
import com.bakdata.fluent_kafka_streams_tests.test_types.Person;
import java.util.Map;
import org.junit.jupiter.api.Test;


class TestTopologyTest {

@Test
void shouldUseImmutableProperties() {
final TestTopology<Person, City> testTopology =
new TestTopology<>(MirrorAvro::getTopology, Map.copyOf(MirrorAvro.getKafkaProperties()));
assertThatCode(testTopology::start).doesNotThrowAnyException();
testTopology.stop();
}
}

0 comments on commit c59c2dd

Please sign in to comment.