Initial TCA commit into DCAEGEN2
[dcaegen2/analytics/tca.git] / dcae-analytics-model / src / test / java / org / openecomp / dcae / apod / analytics / model / util / json / mixin / cef / EventListenerMixinTest.java
1 /*
2  * ===============================LICENSE_START======================================
3  *  dcae-analytics
4  * ================================================================================
5  *    Copyright © 2017 AT&T Intellectual Property. All rights reserved.
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
21 package org.openecomp.dcae.apod.analytics.model.util.json.mixin.cef;
22
23 import com.fasterxml.jackson.core.type.TypeReference;
24 import org.junit.Test;
25 import org.openecomp.dcae.apod.analytics.model.BaseAnalyticsModelUnitTest;
26 import org.openecomp.dcae.apod.analytics.model.domain.cef.EventListener;
27 import org.openecomp.dcae.apod.analytics.model.domain.cef.MeasurementsForVfScalingFields;
28 import org.openecomp.dcae.apod.analytics.model.domain.cef.VNicUsageArray;
29
30 import java.util.List;
31 import java.util.Map;
32
33 import static org.hamcrest.CoreMatchers.is;
34 import static org.junit.Assert.assertThat;
35
36 /**
37  * @author Rajiv Singla . Creation Date: 10/18/2016.
38  */
39 public class EventListenerMixinTest extends BaseAnalyticsModelUnitTest {
40
41     final String eventListenerJsonFileLocation = "data/json/cef/event_listener.json";
42     final String cefMessagesJsonFileLocation = "data/json/cef/cef_messages.json";
43
44     @Test
45     public void testEventListenerJsonConversions() throws Exception {
46
47         final EventListener eventListener = assertJsonConversions(eventListenerJsonFileLocation, EventListener.class);
48
49         Map<String, Object> dynamicProperties = eventListener.getDynamicProperties();
50
51         assertThat("Dynamic Properties size must be 1", dynamicProperties.size(), is(1));
52
53
54     }
55
56     @Test
57     public void testCollectionOfEventListenersJsonConversion() throws Exception {
58
59         final String cefMessageAsString = fromStream(cefMessagesJsonFileLocation);
60
61         final TypeReference<List<EventListener>> eventListenerListTypeReference =
62                 new TypeReference<List<EventListener>>() {
63                 };
64         List<EventListener> eventListeners = objectMapper.readValue(cefMessageAsString, eventListenerListTypeReference);
65         assertThat("Event Listeners size must be 350", eventListeners.size(), is(350));
66
67         final MeasurementsForVfScalingFields measurementsForVfScalingFields = eventListeners.get(0).getEvent()
68                 .getMeasurementsForVfScalingFields();
69
70         // Note: vNicUsageArray - due to odd naming convention have to be explicitly resolved with Mixin annotations
71         assertThat("vNicUsageArray is present on the first measurementForVfScaling",
72                 measurementsForVfScalingFields.getVNicUsageArray().size(), is(1));
73         final VNicUsageArray vNicUsageArray = measurementsForVfScalingFields.getVNicUsageArray().get(0);
74         assertThat("ByesIn is present on vNicUsageArray", vNicUsageArray.getBytesIn(), is(6086L));
75
76         // Note: vNicIdentifier - due to odd naming convention have to be explicity resolved with Mixin annotations
77         assertThat("vNicIdentifier is present on vNicUsageArray", vNicUsageArray.getVNicIdentifier(), is("eth0"));
78
79         // Check serialized json will match deserialized json
80         final String eventListenerString = objectMapper.writeValueAsString(eventListeners);
81         assertJson(cefMessageAsString, eventListenerString);
82
83         // Checks serialization
84         testSerialization(eventListeners, getClass());
85
86     }
87
88 }