-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
212 additions
and
287 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
src/test/java/com/sngular/kloadgen/loadgen/impl/ProtobufSRLoadGeneratorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* * file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
package com.sngular.kloadgen.loadgen.impl; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Locale; | ||
import java.util.Map; | ||
|
||
import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; | ||
import com.github.tomakehurst.wiremock.junit5.WireMockTest; | ||
import com.sngular.kloadgen.exception.KLoadGenException; | ||
import com.sngular.kloadgen.model.FieldValueMapping; | ||
import com.sngular.kloadgen.serializer.EnrichedRecord; | ||
import com.sngular.kloadgen.util.ProducerKeysHelper; | ||
import com.sngular.kloadgen.util.SchemaRegistryKeyHelper; | ||
import io.confluent.kafka.schemaregistry.client.SchemaRegistryClientConfig; | ||
import org.apache.jmeter.threads.JMeterContext; | ||
import org.apache.jmeter.threads.JMeterContextService; | ||
import org.apache.jmeter.threads.JMeterVariables; | ||
import org.apache.jmeter.util.JMeterUtils; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
@WireMockTest | ||
class ProtobufSRLoadGeneratorTest { | ||
|
||
@BeforeEach | ||
public void setUp(final WireMockRuntimeInfo wmRuntimeInfo) throws IOException { | ||
final File file = new File("src/test/resources"); | ||
final String absolutePath = file.getAbsolutePath(); | ||
final String kloadPath = absolutePath + "/kloadgen.properties"; | ||
final Map<String, String> properties = new HashMap<>(); | ||
properties.put(SchemaRegistryKeyHelper.SCHEMA_REGISTRY_URL, wmRuntimeInfo.getHttpBaseUrl()); | ||
properties.put(SchemaRegistryKeyHelper.SCHEMA_REGISTRY_AUTH_KEY, SchemaRegistryKeyHelper.SCHEMA_REGISTRY_AUTH_BASIC_TYPE); | ||
properties.put(SchemaRegistryKeyHelper.SCHEMA_REGISTRY_AUTH_FLAG, ProducerKeysHelper.FLAG_YES); | ||
properties.put(SchemaRegistryClientConfig.BASIC_AUTH_CREDENTIALS_SOURCE, "foo"); | ||
properties.put(SchemaRegistryClientConfig.USER_INFO_CONFIG,"foo"); | ||
JMeterUtils.loadJMeterProperties(kloadPath); | ||
final JMeterContext jmcx = JMeterContextService.getContext(); | ||
jmcx.getProperties().putAll(properties); | ||
jmcx.setVariables(new JMeterVariables()); | ||
JMeterUtils.setLocale(Locale.ENGLISH); | ||
} | ||
|
||
@Test | ||
void testAvroLoadGenerator(final WireMockRuntimeInfo wmRuntimeInfo) throws KLoadGenException { | ||
|
||
final List<FieldValueMapping> fieldValueMappingList = Arrays.asList( | ||
FieldValueMapping.builder().fieldName("propertyTest1.importedProperty.nestedProperty").fieldType("string").valueLength(0).fieldValueList("").required(true) | ||
.isAncestorRequired(true).build(), | ||
FieldValueMapping.builder().fieldName("propertyTest1.entityNumberTwo").fieldType("string").valueLength(0).fieldValueList("").required(true) | ||
.isAncestorRequired(true).build(), | ||
FieldValueMapping.builder().fieldName("propertyTest2.propertyNumberOne").fieldType("int").valueLength(0).fieldValueList("").required(true) | ||
.isAncestorRequired(true).build(), | ||
FieldValueMapping.builder().fieldName("propertyTest2.propertyNumberTwo").fieldType("string").valueLength(0).fieldValueList("").required(true) | ||
.isAncestorRequired(true).build() | ||
); | ||
|
||
final Map<String, String> originals = new HashMap<>(); | ||
originals.put(SchemaRegistryKeyHelper.SCHEMA_REGISTRY_URL, wmRuntimeInfo.getHttpBaseUrl()); | ||
originals.put(SchemaRegistryKeyHelper.SCHEMA_REGISTRY_USERNAME_KEY, "foo"); | ||
originals.put(SchemaRegistryKeyHelper.SCHEMA_REGISTRY_PASSWORD_KEY, "foo"); | ||
|
||
final ProtobufLoadGenerator protobufLoadGenerator = new ProtobufLoadGenerator(); | ||
protobufLoadGenerator.setUpGenerator(originals, "protobufSubjectWithImport", fieldValueMappingList); | ||
final Object message = protobufLoadGenerator.nextMessage(); | ||
Assertions.assertThat(message).isNotNull().isInstanceOf(EnrichedRecord.class); | ||
|
||
final EnrichedRecord enrichedRecord = (EnrichedRecord) message; | ||
Assertions.assertThat(enrichedRecord.getGenericRecord()).isNotNull(); | ||
Assertions.assertThat(enrichedRecord.getGenericRecord().toString()).contains("propertyTest1"); | ||
Assertions.assertThat(enrichedRecord.getGenericRecord().toString()).contains("entityNumberTwo"); | ||
Assertions.assertThat(enrichedRecord.getGenericRecord().toString()).contains("propertyNumberOne"); | ||
Assertions.assertThat(enrichedRecord.getGenericRecord().toString()).contains("propertyNumberTwo"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.