f34f153e23b129033807369e2712ad3a0013e698
[dcaegen2/collectors/hv-ves.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * dcaegen2-collectors-veshv
4  * ================================================================================
5  * Copyright (C) 2018-2019 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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20 package org.onap.dcae.collectors.veshv.ves.message.generator.impl
21
22 import arrow.core.Either
23 import org.assertj.core.api.Assertions.assertThat
24 import org.assertj.core.api.Assertions.fail
25 import org.jetbrains.spek.api.Spek
26 import org.jetbrains.spek.api.dsl.describe
27 import org.jetbrains.spek.api.dsl.given
28 import org.jetbrains.spek.api.dsl.it
29 import org.jetbrains.spek.api.dsl.on
30 import org.onap.dcae.collectors.veshv.tests.utils.assertFailedWithError
31 import org.onap.dcae.collectors.veshv.ves.message.generator.api.ParsingError
32 import org.onap.dcae.collectors.veshv.ves.message.generator.api.VesEventParameters
33 import org.onap.dcae.collectors.veshv.ves.message.generator.api.VesEventType.VALID
34 import org.onap.dcae.collectors.veshv.ves.message.generator.api.WireFrameParameters
35 import org.onap.dcae.collectors.veshv.ves.message.generator.api.WireFrameType.INVALID_GPB_DATA
36
37
38 /**
39  * @author Jakub Dudycz <jakub.dudycz@nokia.com>
40  * @since July 2018
41  */
42 object MessageParametersParserTest : Spek({
43     describe("Messages parameters parser") {
44         val cut = MessageParametersParserImpl()
45
46         given("parameters json array") {
47             on("valid parameters json") {
48
49                 it("should parse VesEventParameters") {
50                     val result = cut.parse(validVesEventParameters())
51
52                     result.fold({ fail("parsing VesEventParameters should have succeeded") }) { rightResult ->
53                         assertThat(rightResult).hasSize(1)
54
55                         val vesEventParams = rightResult.first()
56                         val expectedVesEventCount = 25000L
57
58                         assertThat(vesEventParams is VesEventParameters)
59                         vesEventParams as VesEventParameters
60                         assertThat(vesEventParams.messageType).isEqualTo(VALID)
61                         assertThat(vesEventParams.amount).isEqualTo(expectedVesEventCount)
62                     }
63                 }
64
65                 it("should parse WireFrameParameters") {
66                     val result = cut.parse(validWireFrameParameters())
67
68                     result.fold({ fail("parsing WireFrameParameters should have succeeded") }) { rightResult ->
69                         assertThat(rightResult).hasSize(1)
70
71                         val wireFrameParams = rightResult.first()
72                         val expectedWireFrameCount = 100L
73
74                         assertThat(wireFrameParams is WireFrameParameters)
75                         wireFrameParams as WireFrameParameters
76                         assertThat(wireFrameParams.messageType).isEqualTo(INVALID_GPB_DATA)
77                         assertThat(wireFrameParams.amount).isEqualTo(expectedWireFrameCount)
78                     }
79                 }
80
81
82                 it("should parse multiple types of MessageParameters") {
83                     val result = cut.parse(multipleMessageParameters())
84
85                     result.fold({ fail("parsing multiple types of MessageParameters should have succeeded") }) { rightResult ->
86                         assertThat(rightResult).hasSize(2)
87                         assertThat(rightResult[0] is VesEventParameters)
88                         assertThat(rightResult[1] is WireFrameParameters)
89                     }
90                 }
91             }
92
93             on("invalid parameters json") {
94                 it("should verify messageAmount") {
95                     cut
96                             .parse(nonNumberMessageAmountParameters())
97                             .assertFailedWithError { it.isInstanceOf(ParsingError::class.java) }
98                 }
99
100                 it("should verify messageType") {
101                     cut
102                             .parse(missingMessageTypeParameters())
103                             .assertFailedWithError { it.isInstanceOf(ParsingError::class.java) }
104                 }
105             }
106         }
107     }
108 })