3d3d0c6f5c6a5f5fb1957fa9fe9661f569d39040
[ccsdk/cds.git] / ms / blueprintsprocessor / functions / message-prioritizaion / src / test / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / functions / message / prioritization / TestConfiguration.kt
1 /*
2  * Copyright © 2018-2019 AT&T Intellectual Property.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.onap.ccsdk.cds.blueprintsprocessor.functions.message.prioritization
18
19 import org.onap.ccsdk.cds.blueprintsprocessor.db.PrimaryDBLibGenericService
20 import org.onap.ccsdk.cds.blueprintsprocessor.functions.message.prioritization.db.MessagePrioritization
21 import org.onap.ccsdk.cds.blueprintsprocessor.functions.message.prioritization.topology.MessageAggregateProcessor
22 import org.onap.ccsdk.cds.blueprintsprocessor.functions.message.prioritization.topology.MessageOutputProcessor
23 import org.onap.ccsdk.cds.blueprintsprocessor.functions.message.prioritization.topology.MessagePrioritizeProcessor
24 import org.onap.ccsdk.cds.blueprintsprocessor.message.service.BluePrintMessageLibPropertyService
25 import org.springframework.boot.autoconfigure.EnableAutoConfiguration
26 import org.springframework.context.annotation.Bean
27 import org.springframework.context.annotation.ComponentScan
28 import org.springframework.context.annotation.Configuration
29 import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate
30 import org.springframework.stereotype.Service
31 import javax.sql.DataSource
32
33 @Configuration
34 @ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor.functions.message.prioritization.db"])
35 @EnableAutoConfiguration
36 open class TestDatabaseConfiguration {
37
38     @Bean("primaryDBLibGenericService")
39     open fun primaryDBLibGenericService(dataSource: DataSource): PrimaryDBLibGenericService {
40         return PrimaryDBLibGenericService(
41             NamedParameterJdbcTemplate(dataSource)
42         )
43     }
44 }
45
46 /* Sample Prioritization Listener, used during Application startup
47 @Component
48 open class SamplePrioritizationListeners(private val defaultMessagePrioritizationConsumer: MessagePrioritizationConsumer) {
49
50     private val log = logger(SamplePrioritizationListeners::class)
51
52     @EventListener(ApplicationReadyEvent::class)
53     open fun init() = runBlocking {
54         log.info("Starting PrioritizationListeners...")
55         defaultMessagePrioritizationConsumer
56             .startConsuming(MessagePrioritizationSample.samplePrioritizationConfiguration())
57     }
58
59     @PreDestroy
60     open fun destroy() = runBlocking {
61         log.info("Shutting down PrioritizationListeners...")
62         defaultMessagePrioritizationConsumer.shutDown()
63     }
64 }
65  */
66
67 @Service
68 open class SampleMessagePrioritizationConsumer(
69     bluePrintMessageLibPropertyService: BluePrintMessageLibPropertyService
70 ) : MessagePrioritizationConsumer(bluePrintMessageLibPropertyService)
71
72 @Service(MessagePrioritizationConstants.PROCESSOR_PRIORITIZE)
73 open class SampleMessagePrioritizeProcessor : MessagePrioritizeProcessor() {
74     override fun getGroupCorrelationTypes(messagePrioritization: MessagePrioritization): List<String>? {
75         return when (messagePrioritization.group) {
76             "group-typed" -> arrayListOf("type-0", "type-1", "type-2")
77             else -> null
78         }
79     }
80 }
81
82 @Service(MessagePrioritizationConstants.PROCESSOR_AGGREGATE)
83 open class SampleMessageAggregateProcessor() : MessageAggregateProcessor()
84
85 @Service(MessagePrioritizationConstants.PROCESSOR_OUTPUT)
86 open class SampleMessageOutputProcessor : MessageOutputProcessor()