Skip to content

Commit

Permalink
JUnit test
Browse files Browse the repository at this point in the history
update int64test file
  • Loading branch information
Emmeline1101 committed Feb 13, 2024
1 parent 53a6553 commit a4c0e4c
Show file tree
Hide file tree
Showing 3 changed files with 304 additions and 147 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,62 @@
import com.provectus.kafka.ui.serdes.PropertyResolverImpl;
import com.provectus.kafka.ui.serdes.RecordHeadersImpl;
import org.apache.kafka.common.header.internals.RecordHeaders;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.BeforeEach; //JUnit's BeforeEach annotation is used to specify the method to be executed before each test method
import org.junit.jupiter.api.Test;//JUnit's Test annotation, used to mark test methods
import static org.junit.jupiter.api.Assertions.*;//Introducing JUnit's assertion library for test verification
import com.google.common.primitives.Longs; //Longs utility class in Guava library, used to handle conversion between long and byte
import com.provectus.kafka.ui.serde.api.*;//Introduce the project Serde interface and result class
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;


class Int64SerdeTest {

private Int64Serde serde;
private Int64Serde serde;//Test object

@BeforeEach
@BeforeEach //Initialization method executed before each test method is executed
void init() {
serde = new Int64Serde();
serde.configure(
serde = new Int64Serde();// Instantiate the test object
serde.configure( //original one
PropertyResolverImpl.empty(),
PropertyResolverImpl.empty(),
PropertyResolverImpl.empty()
);
}
@Test
void testSerializeValidLong() {
String topic = "testSerializeValidLong";
String value = "1234567890";//Define the value to be serialized
byte[] expected = Longs.toByteArray(Long.parseLong(value));//// expected byte sequence
byte[] actual = serde.serializer(topic, Serde.Target.VALUE).serialize(value);////Perform serialization operation
assertArrayEquals(expected, actual, "Serialization of a valid long should match expected bytes.");////Verify serialization results
}

@Test
void testDeserializeValidBytes() {
String topic = "testDeserializeValidBytes";
long value = 1234567890L;//Define the value to be deserialized
byte[] bytes = Longs.toByteArray(value);// Convert long value to byte sequence
DeserializeResult result = serde.deserializer(topic, Serde.Target.VALUE).deserialize(null, bytes);//Perform deserialization operation
assertEquals(String.valueOf(value), result.getResult(), "Deserialization should match the original long value as a string.");//Verify deserialization results
}

@Test
void testSerializeInvalidInputThrowsException() {
String topic = "testSerializeInvalidInputThrowsExceptio";
String invalidInput = "not a number";
assertThrows(NumberFormatException.class, () -> serde.serializer(topic, Serde.Target.VALUE).serialize(invalidInput),////Exception thrown when validating invalid input during serialization
"Serialization of invalid input should throw NumberFormatException.");
}

@Test
void testDeserializeInvalidBytesThrowsException() {
String topic = "testDeserializeInvalidBytesThrowsException";
byte[] invalidBytes = new byte[]{1, 2, 3, 4}; // invalid: Less than 8 bytes required for a long
//Exception thrown when verifying deserialization of invalid byte sequence
assertThrows(IllegalArgumentException.class, () -> serde.deserializer(topic, Serde.Target.VALUE).deserialize(null, invalidBytes),//
"Deserialization of invalid bytes should throw IllegalArgumentException.");
}

@ParameterizedTest
@EnumSource
Expand Down
4 changes: 2 additions & 2 deletions kafka-ui-react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"sass": "^1.52.3",
"styled-components": "^5.3.1",
"use-debounce": "^9.0.3",
"vite": "^4.0.0",
"vite": "^5.0.0",
"vite-tsconfig-paths": "^4.0.2",
"whatwg-fetch": "^3.6.2",
"yup": "^1.0.0",
Expand Down Expand Up @@ -73,7 +73,7 @@
"@types/eventsource": "^1.1.8",
"@types/lodash": "^4.14.172",
"@types/lossless-json": "^1.0.1",
"@types/node": "^16.4.13",
"@types/node": "^20.0.0",
"@types/react": "^18.0.9",
"@types/react-datepicker": "^4.8.0",
"@types/react-dom": "^18.0.3",
Expand Down
Loading

0 comments on commit a4c0e4c

Please sign in to comment.