aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFilip Krzywka <filip.krzywka@nokia.com>2019-01-29 07:48:10 +0100
committerFilip Krzywka <filip.krzywka@nokia.com>2019-01-29 09:06:26 +0100
commite55759f5f4c9d53108889256d3897c533077f1b8 (patch)
tree7ecaa336710dbda17b076f600e03bfa0f58e0f2b
parentc2343da9dda10cad1cea5a7b3e4995a43a4796c5 (diff)
Test encoding intermediate packages using GPB
Change-Id: I1f3e2fefce165fa17e27a5e2c2edd456e27b63b4 Issue-ID: DCAEGEN2-1131 Signed-off-by: Filip Krzywka <filip.krzywka@nokia.com>
-rw-r--r--services/hv-ves-client/producer/impl/src/main/java/org/onap/dcaegen2/services/sdk/services/hvves/client/producer/impl/encoders/ProtobufEncoder.java2
-rw-r--r--services/hv-ves-client/producer/impl/src/test/java/org/onap/dcaegen2/services/sdk/services/hvves/client/producer/impl/encoders/ProtobufEncoderTest.java24
-rw-r--r--services/hv-ves-client/producer/impl/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker1
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