Search in sources :

Example 41 with Asset

use of com.vmware.flowgate.common.model.Asset in project flowgate by vmware.

the class SyncRealTimeDataJobTest method createAsset.

Asset createAsset() {
    Asset asset = new Asset();
    asset.setAssetName("pek-wor-pdu-02");
    asset.setAssetNumber(12345);
    asset.setAssetSource("l9i8728d55368540fcba1692");
    asset.setCategory(AssetCategory.PDU);
    asset.setModel("Dell 750");
    asset.setManufacturer("Dell");
    return asset;
}
Also used : Asset(com.vmware.flowgate.common.model.Asset)

Example 42 with Asset

use of com.vmware.flowgate.common.model.Asset in project flowgate by vmware.

the class SyncRealTimeDataJobTest method testGetMatchedPdus1.

@Test
public void testGetMatchedPdus1() {
    Pdu pdu = createPdu();
    pdu.setName("pek-wor-pdu");
    Asset asset = createAsset();
    List<Asset> assets = new ArrayList<Asset>();
    assets.add(asset);
    Map<String, Pdu> filterCondition = new HashMap<String, Pdu>();
    filterCondition.put(pdu.getName(), pdu);
    Map<String, Pdu> map = powerIQService.getMatchedPdus(filterCondition, assets);
    TestCase.assertEquals(true, map.isEmpty());
}
Also used : Pdu(com.vmware.flowgate.poweriqworker.model.Pdu) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Asset(com.vmware.flowgate.common.model.Asset) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 43 with Asset

use of com.vmware.flowgate.common.model.Asset in project flowgate by vmware.

the class SyncSensorMetaDataJobTest method testGetSensorRealTimeData1.

@Test
public void testGetSensorRealTimeData1() {
    HashMap<String, String> justificationfields = generateExtraInfo("6566");
    Asset asset = createAsset();
    asset.setId("123o89qw4jjasd0");
    asset.setJustificationfields(justificationfields);
    Sensor sensor = createSensor();
    sensor.setId(6566);
    sensor.setName("HumiditySensor");
    sensor.setSerialNumber("8999");
    sensor.setType("HumiditySensor");
    Mockito.when(this.powerIQAPIClient.getSensorById("6566")).thenReturn(sensor);
    List<Asset> assets = new ArrayList<Asset>();
    assets.add(asset);
    List<RealTimeData> realTimeDatas = powerIQService.getSensorRealTimeData(createFacility(), assets);
    TestCase.assertEquals(0, realTimeDatas.size());
}
Also used : RealTimeData(com.vmware.flowgate.common.model.RealTimeData) ArrayList(java.util.ArrayList) Asset(com.vmware.flowgate.common.model.Asset) Sensor(com.vmware.flowgate.poweriqworker.model.Sensor) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 44 with Asset

use of com.vmware.flowgate.common.model.Asset in project flowgate by vmware.

the class SyncSensorMetaDataJobTest method testUpdateServer.

@Test
public void testUpdateServer() throws JsonProcessingException {
    List<Asset> assets = new ArrayList<Asset>();
    Asset server = createAsset();
    server.setAssetName("pek-wor-server");
    server.setCategory(AssetCategory.Server);
    Map<String, String> formulars = new HashMap<>();
    Map<String, String> sensorLocationAndId = new HashMap<String, String>();
    sensorLocationAndId.put("Rack01", "256");
    sensorLocationAndId.put("Rack02", "128");
    Map<String, Map<String, String>> sensorInfo = new HashMap<String, Map<String, String>>();
    sensorInfo.put("FRONT", sensorLocationAndId);
    formulars.put(FlowgateConstant.SENSOR, mapper.writeValueAsString(sensorInfo));
    server.setMetricsformulars(formulars);
    assets.add(server);
    List<Asset> servers = powerIQService.updateServer(assets, "128");
    TestCase.assertEquals(assets.size(), servers.size());
    Asset updatedServer = servers.get(0);
    Map<String, String> formulars1 = updatedServer.getMetricsformulars();
    Map<String, Map<String, String>> sensorInfo1 = formatSensorFormulas(formulars1.get(FlowgateConstant.SENSOR));
    Map<String, String> sensorLocationAndId1 = sensorInfo1.get("FRONT");
    TestCase.assertEquals(1, sensorLocationAndId1.size());
    TestCase.assertEquals("256", sensorLocationAndId1.entrySet().iterator().next().getValue());
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Asset(com.vmware.flowgate.common.model.Asset) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 45 with Asset

use of com.vmware.flowgate.common.model.Asset in project flowgate by vmware.

the class SyncSensorMetaDataJobTest method testGetSensorRealTimeData2.

@Test
public void testGetSensorRealTimeData2() {
    HashMap<String, String> justificationfields = generateExtraInfo("6566");
    Asset asset = createAsset();
    asset.setId("123o89qw4jjasd0");
    asset.setJustificationfields(justificationfields);
    HashMap<String, String> justificationfields1 = generateExtraInfo("6567");
    Asset asset1 = createAsset();
    asset1.setId("123o89qw4jjasd1");
    asset1.setJustificationfields(justificationfields1);
    Sensor sensor = createSensor();
    SensorReading sensorReading = createReading();
    sensorReading.setUom("%");
    sensor.setId(6566);
    sensor.setName("HumiditySensor");
    sensor.setSerialNumber("8999");
    sensor.setType("HumiditySensor");
    sensor.setReading(sensorReading);
    Mockito.when(this.powerIQAPIClient.getSensorById("6566")).thenReturn(sensor);
    Sensor sensor1 = createSensor();
    SensorReading sensorReading1 = createReading();
    sensorReading1.setUom("F");
    sensor1.setId(6567);
    sensor1.setName("TemperatureSensor");
    sensor1.setSerialNumber("9000");
    sensor1.setType("TemperatureSensor");
    sensor1.setReading(sensorReading1);
    Mockito.when(this.powerIQAPIClient.getSensorById("6567")).thenReturn(sensor1);
    Set<String> assetIds = new HashSet<String>();
    assetIds.add("123o89qw4jjasd0");
    assetIds.add("123o89qw4jjasd1");
    List<Asset> assets = new ArrayList<Asset>();
    assets.add(asset);
    assets.add(asset1);
    List<RealTimeData> realTimeDatas = powerIQService.getSensorRealTimeData(createFacility(), assets);
    for (RealTimeData realtimedata : realTimeDatas) {
        if ("123o89qw4jjasd0".equals(realtimedata.getAssetID())) {
            TestCase.assertEquals((double) 100, realtimedata.getValues().get(0).getValueNum());
        } else {
            TestCase.assertEquals((double) (100 - 32) * 5 / 9, realtimedata.getValues().get(0).getValueNum());
        }
    }
}
Also used : RealTimeData(com.vmware.flowgate.common.model.RealTimeData) SensorReading(com.vmware.flowgate.poweriqworker.model.SensorReading) ArrayList(java.util.ArrayList) Asset(com.vmware.flowgate.common.model.Asset) Sensor(com.vmware.flowgate.poweriqworker.model.Sensor) HashSet(java.util.HashSet) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Asset (com.vmware.flowgate.common.model.Asset)173 Test (org.junit.Test)96 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)90 HashMap (java.util.HashMap)86 ArrayList (java.util.ArrayList)82 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)36 NlyteAsset (com.vmware.flowgate.nlyteworker.model.NlyteAsset)35 Map (java.util.Map)34 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)31 RealTimeData (com.vmware.flowgate.common.model.RealTimeData)23 IOException (java.io.IOException)23 ServerMapping (com.vmware.flowgate.common.model.ServerMapping)22 MetricData (com.vmware.flowgate.common.model.MetricData)16 HandleAssetUtil (com.vmware.flowgate.nlyteworker.scheduler.job.common.HandleAssetUtil)16 HashSet (java.util.HashSet)15 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)13 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)13 List (java.util.List)12 MvcResult (org.springframework.test.web.servlet.MvcResult)12 TypeReference (com.fasterxml.jackson.core.type.TypeReference)10