diff options
3 files changed, 19 insertions, 8 deletions
diff --git a/services/hv-ves-client/producer/impl/src/main/java/org/onap/dcaegen2/services/sdk/services/hvves/client/producer/impl/encoders/ProtobufEncoder.java b/services/hv-ves-client/producer/impl/src/main/java/org/onap/dcaegen2/services/sdk/services/hvves/client/producer/impl/encoders/ProtobufEncoder.java index 305716fe..5bee8461 100644 --- a/services/hv-ves-client/producer/impl/src/main/java/org/onap/dcaegen2/services/sdk/services/hvves/client/producer/impl/encoders/ProtobufEncoder.java +++ b/services/hv-ves-client/producer/impl/src/main/java/org/onap/dcaegen2/services/sdk/services/hvves/client/producer/impl/encoders/ProtobufEncoder.java @@ -33,7 +33,7 @@ public class ProtobufEncoder { private static final Logger LOGGER = LoggerFactory.getLogger(ProtobufEncoder.class); public ByteBuffer encode(VesEvent event) { - LOGGER.debug("Encoding VesEvent '{}'", event); + LOGGER.trace("Encoding VesEvent '{}'", event); return event.toByteString().asReadOnlyByteBuffer(); } } diff --git a/services/hv-ves-client/producer/impl/src/test/java/org/onap/dcaegen2/services/sdk/services/hvves/client/producer/impl/encoders/ProtobufEncoderTest.java b/services/hv-ves-client/producer/impl/src/test/java/org/onap/dcaegen2/services/sdk/services/hvves/client/producer/impl/encoders/ProtobufEncoderTest.java index ba5514ee..6fb6f42f 100644 --- a/services/hv-ves-client/producer/impl/src/test/java/org/onap/dcaegen2/services/sdk/services/hvves/client/producer/impl/encoders/ProtobufEncoderTest.java +++ b/services/hv-ves-client/producer/impl/src/test/java/org/onap/dcaegen2/services/sdk/services/hvves/client/producer/impl/encoders/ProtobufEncoderTest.java @@ -20,28 +20,38 @@ package org.onap.dcaegen2.services.sdk.services.hvves.client.producer.impl.encoders; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.ByteBufAllocator; +import com.google.protobuf.ByteString; import org.junit.jupiter.api.Test; import org.onap.dcaegen2.services.sdk.services.hvves.client.producer.impl.utils.VesEvents; import org.onap.ves.VesEventOuterClass.VesEvent; import java.nio.ByteBuffer; +import java.nio.charset.Charset; public class ProtobufEncoderTest { private final ProtobufEncoder protobufEncoder = new ProtobufEncoder(); @Test - void todo() { - // given + void encode_shouldDelegateToProtobufMethodsToSerializeMessage_andReturnReadOnlyByteBuffer() { + final VesEvent message = mock(VesEvent.class); + final ByteString bs = ByteString.copyFrom("vesEvent", Charset.defaultCharset()); + when(message.toByteString()).thenReturn(bs); + + final ByteBuffer encodedMessage = protobufEncoder.encode(message); + + assertThat(encodedMessage).isEqualByComparingTo(bs.asReadOnlyByteBuffer()); + } + + @Test + void encode_shouldReturnReadOnlyByteBuffer() { final VesEvent message = VesEvents.defaultVesEvent(); - // when final ByteBuffer encodedMessage = protobufEncoder.encode(message); - // then - assertThat(encodedMessage.remaining()).isGreaterThan(0); + assertThat(encodedMessage.isReadOnly()).isTrue(); } } diff --git a/services/hv-ves-client/producer/impl/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/services/hv-ves-client/producer/impl/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker new file mode 100644 index 00000000..ca6ee9ce --- /dev/null +++ b/services/hv-ves-client/producer/impl/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker @@ -0,0 +1 @@ +mock-maker-inline
\ No newline at end of file |