diff options
Diffstat (limited to 'pomba/network-discovery-api/src/test')
2 files changed, 169 insertions, 0 deletions
diff --git a/pomba/network-discovery-api/src/test/java/org/onap/sdnc/apps/pomba/networkdiscovery/datamodel/test/PojoTest.java b/pomba/network-discovery-api/src/test/java/org/onap/sdnc/apps/pomba/networkdiscovery/datamodel/test/PojoTest.java new file mode 100644 index 0000000..0aa0809 --- /dev/null +++ b/pomba/network-discovery-api/src/test/java/org/onap/sdnc/apps/pomba/networkdiscovery/datamodel/test/PojoTest.java @@ -0,0 +1,82 @@ +/* + * ============LICENSE_START=================================================== + * Copyright (c) 2018 Amdocs + * ============================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END===================================================== + */ +package org.onap.sdnc.apps.pomba.networkdiscovery.datamodel.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import com.fasterxml.jackson.databind.ObjectMapper; +import java.util.HashMap; +import java.util.Map; +import org.junit.Test; +import org.onap.sdnc.apps.pomba.networkdiscovery.datamodel.Attribute; +import org.onap.sdnc.apps.pomba.networkdiscovery.datamodel.DataQuality; +import org.onap.sdnc.apps.pomba.networkdiscovery.datamodel.NetworkDiscoveryNotification; +import org.onap.sdnc.apps.pomba.networkdiscovery.datamodel.Resource; + +public class PojoTest { + + @Test + public void fromJson() throws Exception { + ObjectMapper objectMapper = new ObjectMapper(); + NetworkDiscoveryNotification notification = objectMapper.readValue( + ClassLoader.getSystemResourceAsStream("notification.json"), + NetworkDiscoveryNotification.class); + + System.out.println(notification); + + assertEquals("1", notification.getRequestId()); + assertEquals(200, notification.getCode().intValue()); + assertEquals(true, notification.getAckFinalIndicator()); + assertEquals(1, notification.getResources().size()); + Resource vserver = notification.getResources().get(0); + assertEquals("25fb07ab-0478-465e-a021-6384ac299671", vserver.getId()); + assertEquals("vserver", vserver.getType()); + assertEquals(DataQuality.Status.ok, vserver.getDataQuality().getStatus()); + assertNull(vserver.getDataQuality().getErrorText()); + + Map<String, String> expectedValues = new HashMap<>(); + expectedValues.put("vserver-id", "25fb07ab-0478-465e-a021-6384ac299671"); + expectedValues.put("power-state", "1"); + expectedValues.put("vm-state", "active"); + expectedValues.put("status", "ACTIVE"); + expectedValues.put("host-status", "UNKNOWN"); + expectedValues.put("updated", "2017-11-20T04:26:13Z"); + expectedValues.put("disk-allocation-gb", ".010"); + expectedValues.put("memory-usage-mb", "null"); + expectedValues.put("cpu-util-percent", ".043"); + expectedValues.put("retrieval-timestamp", "2018-06-25 18:02:55 +0000"); + + for (Attribute attribute : vserver.getAttributeList()) { + assertEquals(expectedValues.remove(attribute.getName()), attribute.getValue()); + assertEquals(DataQuality.Status.ok, attribute.getDataQuality().getStatus()); + } + assertEquals(0, expectedValues.size()); + } + + @Test + public void dataQualityHelpers() { + DataQuality value = DataQuality.ok(); + assertEquals(DataQuality.Status.ok, value.getStatus()); + assertNull(value.getErrorText()); + + value = DataQuality.error("test"); + assertEquals(DataQuality.Status.error, value.getStatus()); + assertEquals("test", value.getErrorText()); + } +} diff --git a/pomba/network-discovery-api/src/test/resources/notification.json b/pomba/network-discovery-api/src/test/resources/notification.json new file mode 100644 index 0000000..6a3bd4b --- /dev/null +++ b/pomba/network-discovery-api/src/test/resources/notification.json @@ -0,0 +1,87 @@ +{ + "requestId": "1", + "code": 200, + "message": "OK", + "ackFinalIndicator": true, + "resources": [ + { + "id": "25fb07ab-0478-465e-a021-6384ac299671", + "type": "vserver", + "dataQuality": { + "status": "ok" + }, + "attributeList": [ + { + "name": "vserver-id", + "value": "25fb07ab-0478-465e-a021-6384ac299671", + "dataQuality": { + "status": "ok" + } + }, + { + "name": "power-state", + "value": "1", + "dataQuality": { + "status": "ok" + } + }, + { + "name": "vm-state", + "value": "active", + "dataQuality": { + "status": "ok" + } + }, + { + "name": "status", + "value": "ACTIVE", + "dataQuality": { + "status": "ok" + } + }, + { + "name": "host-status", + "value": "UNKNOWN", + "dataQuality": { + "status": "ok" + } + }, + { + "name": "updated", + "value": "2017-11-20T04:26:13Z", + "dataQuality": { + "status": "ok" + } + }, + { + "name": "disk-allocation-gb", + "value": ".010", + "dataQuality": { + "status": "ok" + } + }, + { + "name": "memory-usage-mb", + "value": "null", + "dataQuality": { + "status": "ok" + } + }, + { + "name": "cpu-util-percent", + "value": ".043", + "dataQuality": { + "status": "ok" + } + }, + { + "name": "retrieval-timestamp", + "value": "2018-06-25 18:02:55 +0000", + "dataQuality": { + "status": "ok" + } + } + ] + } + ] +}
\ No newline at end of file |