Jian Li | ae3fcff | 2018-07-30 11:55:44 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 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 | package org.onosproject.openstacktelemetry.impl; |
| 17 | |
| 18 | import org.junit.After; |
| 19 | import org.junit.Before; |
| 20 | import org.junit.Test; |
Jian Li | 69600e0 | 2018-12-24 13:21:18 +0900 | [diff] [blame^] | 21 | import org.onosproject.openstacktelemetry.api.TelemetryAdminService; |
Jian Li | ae3fcff | 2018-07-30 11:55:44 +0900 | [diff] [blame] | 22 | |
| 23 | import static org.junit.Assert.assertEquals; |
| 24 | |
| 25 | /** |
| 26 | * Unit tests for OpenstackTelemetryService class. |
| 27 | */ |
| 28 | public final class OpenstackTelemetryManagerTest { |
| 29 | |
Jian Li | 69600e0 | 2018-12-24 13:21:18 +0900 | [diff] [blame^] | 30 | private static final TelemetryAdminService GRPC_SERVICE = new GrpcTelemetryManager(); |
| 31 | private static final TelemetryAdminService INFLUXDB_SERVICE = new InfluxDbTelemetryManager(); |
| 32 | private static final TelemetryAdminService KAFKA_SERVICE = new KafkaTelemetryManager(); |
| 33 | private static final TelemetryAdminService PROMETHEUS_SERVICE = new PrometheusTelemetryManager(); |
| 34 | private static final TelemetryAdminService REST_SERVICE = new PrometheusTelemetryManager(); |
Jian Li | ae3fcff | 2018-07-30 11:55:44 +0900 | [diff] [blame] | 35 | |
| 36 | private OpenstackTelemetryManager manager; |
| 37 | |
| 38 | /** |
| 39 | * Initializes the unit test. |
| 40 | */ |
| 41 | @Before |
| 42 | public void setUp() { |
| 43 | manager = new OpenstackTelemetryManager(); |
| 44 | |
Jian Li | 69600e0 | 2018-12-24 13:21:18 +0900 | [diff] [blame^] | 45 | manager.telemetryConfigService = new TelemetryConfigManager(); |
| 46 | |
Jian Li | ae3fcff | 2018-07-30 11:55:44 +0900 | [diff] [blame] | 47 | manager.activate(); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Tests addTelemetryService method. |
| 52 | */ |
| 53 | @Test |
| 54 | public void testAddTelemetryService() { |
| 55 | addDefaultServices(); |
| 56 | |
Jian Li | 69600e0 | 2018-12-24 13:21:18 +0900 | [diff] [blame^] | 57 | TelemetryAdminService kafkaService = new KafkaTelemetryManager(); |
Jian Li | ae3fcff | 2018-07-30 11:55:44 +0900 | [diff] [blame] | 58 | |
boyoung2 | a8549d2 | 2018-11-23 20:42:37 +0900 | [diff] [blame] | 59 | assertEquals(5, manager.telemetryServices().size()); |
Jian Li | ae3fcff | 2018-07-30 11:55:44 +0900 | [diff] [blame] | 60 | |
| 61 | manager.addTelemetryService(kafkaService); |
| 62 | |
boyoung2 | a8549d2 | 2018-11-23 20:42:37 +0900 | [diff] [blame] | 63 | assertEquals(6, manager.telemetryServices().size()); |
Jian Li | ae3fcff | 2018-07-30 11:55:44 +0900 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Tests removeTelemetryService method. |
| 68 | */ |
| 69 | @Test |
| 70 | public void testRemoveTelemetryService() { |
| 71 | addDefaultServices(); |
| 72 | |
boyoung2 | a8549d2 | 2018-11-23 20:42:37 +0900 | [diff] [blame] | 73 | assertEquals(5, manager.telemetryServices().size()); |
Jian Li | ae3fcff | 2018-07-30 11:55:44 +0900 | [diff] [blame] | 74 | |
| 75 | manager.removeTelemetryService(GRPC_SERVICE); |
| 76 | |
boyoung2 | a8549d2 | 2018-11-23 20:42:37 +0900 | [diff] [blame] | 77 | assertEquals(4, manager.telemetryServices().size()); |
Jian Li | ae3fcff | 2018-07-30 11:55:44 +0900 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Tears down the unit test. |
| 82 | */ |
| 83 | @After |
| 84 | public void tearDown() { |
| 85 | manager.deactivate(); |
| 86 | } |
| 87 | |
| 88 | private void addDefaultServices() { |
| 89 | manager.addTelemetryService(GRPC_SERVICE); |
| 90 | manager.addTelemetryService(INFLUXDB_SERVICE); |
boyoung2 | a8549d2 | 2018-11-23 20:42:37 +0900 | [diff] [blame] | 91 | manager.addTelemetryService(KAFKA_SERVICE); |
| 92 | manager.addTelemetryService(PROMETHEUS_SERVICE); |
| 93 | manager.addTelemetryService(REST_SERVICE); |
Jian Li | ae3fcff | 2018-07-30 11:55:44 +0900 | [diff] [blame] | 94 | } |
| 95 | } |