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