0aa080949d54706012eebdf586928c489af3c368
[sdnc/apps.git] /
1 /*
2  *  ============LICENSE_START===================================================
3  * Copyright (c) 2018 Amdocs
4  * ============================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  * ============LICENSE_END=====================================================
17  */
18 package org.onap.sdnc.apps.pomba.networkdiscovery.datamodel.test;
19
20 import static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.assertNull;
22
23 import com.fasterxml.jackson.databind.ObjectMapper;
24 import java.util.HashMap;
25 import java.util.Map;
26 import org.junit.Test;
27 import org.onap.sdnc.apps.pomba.networkdiscovery.datamodel.Attribute;
28 import org.onap.sdnc.apps.pomba.networkdiscovery.datamodel.DataQuality;
29 import org.onap.sdnc.apps.pomba.networkdiscovery.datamodel.NetworkDiscoveryNotification;
30 import org.onap.sdnc.apps.pomba.networkdiscovery.datamodel.Resource;
31
32 public class PojoTest {
33
34     @Test
35     public void fromJson() throws Exception {
36         ObjectMapper objectMapper = new ObjectMapper();
37         NetworkDiscoveryNotification notification = objectMapper.readValue(
38                 ClassLoader.getSystemResourceAsStream("notification.json"),
39                 NetworkDiscoveryNotification.class);
40
41         System.out.println(notification);
42
43         assertEquals("1", notification.getRequestId());
44         assertEquals(200, notification.getCode().intValue());
45         assertEquals(true, notification.getAckFinalIndicator());
46         assertEquals(1, notification.getResources().size());
47         Resource vserver = notification.getResources().get(0);
48         assertEquals("25fb07ab-0478-465e-a021-6384ac299671", vserver.getId());
49         assertEquals("vserver", vserver.getType());
50         assertEquals(DataQuality.Status.ok, vserver.getDataQuality().getStatus());
51         assertNull(vserver.getDataQuality().getErrorText());
52
53         Map<String, String> expectedValues = new HashMap<>();
54         expectedValues.put("vserver-id", "25fb07ab-0478-465e-a021-6384ac299671");
55         expectedValues.put("power-state", "1");
56         expectedValues.put("vm-state", "active");
57         expectedValues.put("status", "ACTIVE");
58         expectedValues.put("host-status", "UNKNOWN");
59         expectedValues.put("updated", "2017-11-20T04:26:13Z");
60         expectedValues.put("disk-allocation-gb", ".010");
61         expectedValues.put("memory-usage-mb", "null");
62         expectedValues.put("cpu-util-percent", ".043");
63         expectedValues.put("retrieval-timestamp", "2018-06-25 18:02:55 +0000");
64
65         for (Attribute attribute : vserver.getAttributeList()) {
66             assertEquals(expectedValues.remove(attribute.getName()), attribute.getValue());
67             assertEquals(DataQuality.Status.ok, attribute.getDataQuality().getStatus());
68         }
69         assertEquals(0, expectedValues.size());
70     }
71
72     @Test
73     public void dataQualityHelpers() {
74         DataQuality value = DataQuality.ok();
75         assertEquals(DataQuality.Status.ok, value.getStatus());
76         assertNull(value.getErrorText());
77
78         value = DataQuality.error("test");
79         assertEquals(DataQuality.Status.error, value.getStatus());
80         assertEquals("test", value.getErrorText());
81     }
82 }