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.ClientContext
31 import org.onap.dcae.collectors.veshv.model.RoutedMessage
32 import org.onap.dcae.collectors.veshv.tests.fakes.FakeConfigurationProvider
33 import org.onap.dcae.collectors.veshv.tests.fakes.FakeHealthState
34 import org.onap.dcae.collectors.veshv.tests.fakes.FakeMetrics
35 import org.onap.dcae.collectors.veshv.tests.fakes.StoringSink
36 import reactor.core.publisher.Flux
37 import java.time.Duration
40 * @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
43 class Sut(sink: Sink = StoringSink()) {
44 val configurationProvider = FakeConfigurationProvider()
45 val healthStateProvider = FakeHealthState()
47 val alloc: ByteBufAllocator = UnpooledByteBufAllocator.DEFAULT
48 private val metrics = FakeMetrics()
49 private val collectorFactory = CollectorFactory(
50 configurationProvider,
51 SinkProvider.just(sink),
53 MAX_PAYLOAD_SIZE_BYTES,
55 private val collectorProvider = collectorFactory.createVesHvCollectorProvider()
57 val collector: Collector
58 get() = collectorProvider(ClientContext(alloc)).getOrElse{ throw IllegalStateException("Collector not available.") }
61 const val MAX_PAYLOAD_SIZE_BYTES = 1024
66 fun Sut.handleConnection(sink: StoringSink, vararg packets: ByteBuf): List<RoutedMessage> {
67 collector.handleConnection(Flux.fromArray(packets)).block(Duration.ofSeconds(10))
68 return sink.sentMessages