CodeCoverage improvement for dcaegen2-analytics-tca-gen2
[dcaegen2/analytics/tca-gen2.git] / dcae-analytics / dcae-analytics-model / src / test / java / org / onap / dcae / analytics / model / util / json / mixin / cef / AlertTypeMixinTest.java
1 /*
2  * ============LICENSE_START=======================================================
3  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
4  * Copyright (c) 2022 Huawei. All rights reserved.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  * ============LICENSE_END=========================================================
18  *
19  */
20
21 package org.onap.dcae.analytics.model.util.json.mixin.cef;
22
23 import static org.junit.jupiter.api.Assertions.assertEquals;
24 import static org.onap.dcae.analytics.model.util.json.AnalyticsModelJsonConversion.ANALYTICS_MODEL_OBJECT_MAPPER;
25
26 import org.assertj.core.api.Assertions;
27 import org.junit.jupiter.api.DisplayName;
28 import org.junit.jupiter.api.Test;
29 import org.onap.dcae.analytics.model.BaseAnalyticsModelTest;
30 import org.onap.dcae.analytics.model.cef.AlertType;
31
32
33 /**
34  * Test Alert Type Mixin JSON conversions.
35  *
36  * @author Rajiv Singla
37  */
38 class AlertTypeMixinTest extends BaseAnalyticsModelTest {
39
40     // NOTE: Alert type enum has some special customizations in AlertTypeMixin class
41     // as Java enum names does not allow for "-" so actual values are coded as enum names
42     @Test
43     @DisplayName("Test Alert Type Json Conversions")
44     public void testAlertTypeJsonConversions() throws Exception {
45
46         final String alertTypeJson = serializeModelToJson(AlertType.CARD_ANOMALY, ANALYTICS_MODEL_OBJECT_MAPPER);
47         Assertions.assertThat(alertTypeJson)
48                 .as("Alert Type Json for CARD ANOMALY must have hyphen in it").isEqualTo("\"CARD-ANOMALY\"");
49         // convert parsed alert type back to enum
50         final AlertType alertType = ANALYTICS_MODEL_OBJECT_MAPPER.readValue(alertTypeJson, AlertType.class);
51         Assertions.assertThat(alertType)
52                 .as("Json String for CARD ANOMALY with hyphen can be converted back to Alert Type")
53                 .isEqualTo(AlertType.CARD_ANOMALY);
54     }
55
56     @Test
57     public void forvalueTest() throws Exception {
58         assertEquals(AlertType.CARD_ANOMALY, AlertTypeMixin.forValue("CARD-ANOMALY"));
59         assertEquals(AlertType.ELEMENT_ANOMALY, AlertTypeMixin.forValue("ELEMENT-ANOMALY"));
60         assertEquals(AlertType.INTERFACE_ANOMALY, AlertTypeMixin.forValue("INTERFACE-ANOMALY"));
61         assertEquals(AlertType.SERVICE_ANOMALY, AlertTypeMixin.forValue("SERVICE-ANOMALY"));
62         assertEquals(AlertType.UNKNOWN, AlertTypeMixin.forValue("UNKNOWN"));
63     }
64
65 }