Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Serialize also kafka client-id and bindingVersion #141

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ public void serialize(KafkaOperationBinding value, JsonGenerator gen, Serializer
if (value.getGroupId() != null) {
writeGroupId(value, gen);
}
if(value.getClientId() != null) {
writeClientId(value, gen);
}
if(value.getBindingVersion() != null) {
writeBindingVersion(value, gen);
}

gen.writeEndObject();
}
Expand All @@ -39,4 +45,24 @@ private void writeGroupId(KafkaOperationBinding value, JsonGenerator gen) throws
gen.writeEndObject();
}

private void writeClientId(KafkaOperationBinding value, JsonGenerator gen) throws IOException {;
gen.writeFieldName("clientId");
gen.writeStartObject();
gen.writeStringField("type", "string");
gen.writeArrayFieldStart("enum");
gen.writeString((String) value.getClientId());
gen.writeEndArray();
gen.writeEndObject();
}

private void writeBindingVersion(KafkaOperationBinding value, JsonGenerator gen) throws IOException {
gen.writeFieldName("bindingVersion");
gen.writeStartObject();
gen.writeStringField("type", "string");
gen.writeArrayFieldStart("enum");
gen.writeString(value.getBindingVersion());
gen.writeEndArray();
gen.writeEndObject();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,25 @@ public class KafkaOperationBindingSerializerTest {
}

@Test
public void bindingWithGroupId() throws JsonProcessingException, JSONException {
public void bindingWithClientIdTest() throws JsonProcessingException, JSONException {
KafkaOperationBinding binding = KafkaOperationBinding.builder().clientId("testClientId").build();
String actual = objectMapper.writeValueAsString(binding);
String expected = "{\"clientId\":{\"type\":\"string\",\"enum\":[\"testClientId\"]}}";
JSONAssert.assertEquals(expected, actual, JSONCompareMode.NON_EXTENSIBLE);
}


@Test
public void bindingWithClientIdEmptyTest() throws JsonProcessingException, JSONException {
KafkaOperationBinding binding = KafkaOperationBinding.builder().clientId("").build();
String actual = objectMapper.writeValueAsString(binding);
String expected = "{\"clientId\":{\"type\":\"string\",\"enum\":[\"\"]}}";
JSONAssert.assertEquals(expected, actual, JSONCompareMode.NON_EXTENSIBLE);
}


@Test
public void bindingWithGroupIdTest() throws JsonProcessingException, JSONException {
KafkaOperationBinding binding = KafkaOperationBinding.builder().groupId("testGroupId").build();
String actual = objectMapper.writeValueAsString(binding);
String expected = "{\"groupId\":{\"type\":\"string\",\"enum\":[\"testGroupId\"]}}";
Expand All @@ -29,19 +47,49 @@ public void bindingWithGroupId() throws JsonProcessingException, JSONException {


@Test
public void bindingWithEmptyGroupId() throws JsonProcessingException, JSONException {
public void bindingWithGroupIdEmptyTest() throws JsonProcessingException, JSONException {
KafkaOperationBinding binding = KafkaOperationBinding.builder().groupId("").build();
String actual = objectMapper.writeValueAsString(binding);
String expected = "{\"groupId\":{\"type\":\"string\",\"enum\":[\"\"]}}";
JSONAssert.assertEquals(expected, actual, JSONCompareMode.NON_EXTENSIBLE);
}


@Test
public void bindingWithoutEmptyGroupId() throws JsonProcessingException, JSONException {
public void bindingWithBindingVersionTest() throws JsonProcessingException, JSONException {
KafkaOperationBinding binding = KafkaOperationBinding.builder().bindingVersion("v1").build();
String actual = objectMapper.writeValueAsString(binding);
String expected = "{\"bindingVersion\":{\"type\":\"string\",\"enum\":[\"v1\"]}}";
JSONAssert.assertEquals(expected, actual, JSONCompareMode.NON_EXTENSIBLE);
}


@Test
public void bindingWithBindingVersionEmptyTest() throws JsonProcessingException, JSONException {
KafkaOperationBinding binding = KafkaOperationBinding.builder().bindingVersion("").build();
String actual = objectMapper.writeValueAsString(binding);
String expected = "{\"bindingVersion\":{\"type\":\"string\",\"enum\":[\"\"]}}";
JSONAssert.assertEquals(expected, actual, JSONCompareMode.NON_EXTENSIBLE);
}

@Test
public void emptyKafkaOperationBindingTest() throws JsonProcessingException, JSONException {
KafkaOperationBinding binding = new KafkaOperationBinding();
String actual = objectMapper.writeValueAsString(binding);
String expected = "{}";
JSONAssert.assertEquals(expected, actual, JSONCompareMode.NON_EXTENSIBLE);
}

@Test
public void fullKafkaOperationBindingTest() throws JsonProcessingException, JSONException {
KafkaOperationBinding binding = KafkaOperationBinding.builder().bindingVersion("v1").clientId("testClientId").groupId("testGroupId").build();
String actual = objectMapper.writeValueAsString(binding);
String expected = "{" +
"\"clientId\":{\"type\":\"string\",\"enum\":[\"testClientId\"]}," +
"\"groupId\":{\"type\":\"string\",\"enum\":[\"testGroupId\"]}," +
"\"bindingVersion\":{\"type\":\"string\",\"enum\":[\"v1\"]}" +
"}";
JSONAssert.assertEquals(expected, actual, JSONCompareMode.NON_EXTENSIBLE);
}

}