2 * ============LICENSE_START=======================================================
3 * dcaegen2-collectors-veshv
4 * ================================================================================
5 * Copyright (C) 2018 NOKIA
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.dcae.collectors.veshv.tests.component
22 import arrow.core.getOrElse
23 import io.netty.buffer.ByteBuf
24 import io.netty.buffer.ByteBufAllocator
25 import io.netty.buffer.UnpooledByteBufAllocator
26 import org.onap.dcae.collectors.veshv.boundary.Collector
27 import org.onap.dcae.collectors.veshv.boundary.Sink
28 import org.onap.dcae.collectors.veshv.boundary.SinkProvider
29 import org.onap.dcae.collectors.veshv.factory.CollectorFactory
30 import org.onap.dcae.collectors.veshv.model.RoutedMessage
31 import org.onap.dcae.collectors.veshv.tests.fakes.FakeConfigurationProvider
32 import org.onap.dcae.collectors.veshv.tests.fakes.FakeHealthState
33 import org.onap.dcae.collectors.veshv.tests.fakes.FakeMetrics
34 import org.onap.dcae.collectors.veshv.tests.fakes.StoringSink
35 import reactor.core.publisher.Flux
36 import java.time.Duration
39 * @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
42 class Sut(sink: Sink = StoringSink()) {
43 val configurationProvider = FakeConfigurationProvider()
44 val healthStateProvider = FakeHealthState()
46 val alloc: ByteBufAllocator = UnpooledByteBufAllocator.DEFAULT
47 private val metrics = FakeMetrics()
48 private val collectorFactory = CollectorFactory(
49 configurationProvider,
50 SinkProvider.just(sink),
52 MAX_PAYLOAD_SIZE_BYTES,
54 private val collectorProvider = collectorFactory.createVesHvCollectorProvider()
56 val collector: Collector
57 get() = collectorProvider().getOrElse{ throw IllegalStateException("Collector not available.") }
60 const val MAX_PAYLOAD_SIZE_BYTES = 1024
65 fun Sut.handleConnection(sink: StoringSink, vararg packets: ByteBuf): List<RoutedMessage> {
66 collector.handleConnection(alloc, Flux.fromArray(packets)).block(Duration.ofSeconds(10))
67 return sink.sentMessages