Search in sources :

Example 11 with Sensor

use of com.vmware.flowgate.poweriqworker.model.Sensor in project flowgate by vmware.

the class SyncSensorMetaDataJobTest method testGetSensorRealTimeData.

@Test
public void testGetSensorRealTimeData() {
    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");
    SensorReading sensorReading = new SensorReading();
    sensorReading.setReadingTime("2019/02/14 04:31:14 +0200");
    sensorReading.setValue(30.0);
    sensorReading.setUom("%");
    sensor.setReading(sensorReading);
    Mockito.when(this.powerIQAPIClient.getSensorById("6566")).thenReturn(sensor);
    Set<String> assetIds = new HashSet<String>();
    assetIds.add("123o89qw4jjasd0");
    List<Asset> assets = new ArrayList<Asset>();
    assets.add(asset);
    List<RealTimeData> realTimeDatas = powerIQService.getSensorRealTimeData(createFacility(), assets);
    for (RealTimeData realtimeData : realTimeDatas) {
        TestCase.assertEquals("123o89qw4jjasd0", realtimeData.getAssetID());
        TestCase.assertEquals(1550111474000l, realtimeData.getTime());
        if ("123o89qw4jjasd0".equals(realtimeData.getAssetID())) {
            TestCase.assertEquals("%", realtimeData.getValues().get(0).getUnit());
        }
    }
}
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)

Example 12 with Sensor

use of com.vmware.flowgate.poweriqworker.model.Sensor in project flowgate by vmware.

the class SyncSensorMetaDataJobTest method testAggregatorSensorIdAndSourceForPdu1.

@Test
public void testAggregatorSensorIdAndSourceForPdu1() {
    Asset pdu = createAsset1();
    HashMap<String, String> justificationfields = new HashMap<String, String>();
    justificationfields.put(AssetSubCategory.Humidity.toString(), "509" + FlowgateConstant.SEPARATOR + "l9i8728d55368540fcba1692");
    pdu.setJustificationfields(justificationfields);
    Sensor sensor = new Sensor();
    sensor.setId(509);
    sensor.setType(PowerIQService.HumiditySensor);
    String source = "l9i8728d55368540fcba1692";
    pdu = powerIQService.aggregatorSensorIdAndSourceForPdu(pdu, sensor, source);
    TestCase.assertEquals(sensor.getId() + FlowgateConstant.SEPARATOR + source, pdu.getJustificationfields().get(AssetSubCategory.Humidity.toString()));
}
Also used : HashMap(java.util.HashMap) 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 13 with Sensor

use of com.vmware.flowgate.poweriqworker.model.Sensor in project flowgate by vmware.

the class SyncSensorMetaDataJobTest method testSaveSensorAssetsToFlowgate.

@Test
public void testSaveSensorAssetsToFlowgate() {
    Map<String, Asset> exsitingSensorAssets = new HashMap<>();
    Asset asset1 = createAsset();
    asset1.setId("18672301765107L");
    Asset asset2 = createAsset();
    asset2.setId("BOQBNBHQOQJAOJQY");
    exsitingSensorAssets.put(asset1.getId(), asset1);
    exsitingSensorAssets.put(asset2.getId(), asset2);
    String assetSource = "UGVINQVNQIGQGQIDNKD";
    LocationInfo location = new LocationInfo();
    Sensor sensor1 = createSensor();
    sensor1.setId(18672301765107L);
    sensor1.setName("sensor-1");
    sensor1.setType("TemperatureSensor");
    Sensor sensor2 = createSensor();
    sensor2.setId(81675117203607L);
    sensor2.setName("sensor-2");
    sensor2.setType("HumiditySensor");
    Sensor sensor3 = createSensor();
    sensor3.setId(61675386203607L);
    sensor3.setName("sensor-3");
    sensor3.setType("TemperatureSensor");
    Sensor sensor4 = createSensor();
    sensor4.setId(38661675203607L);
    sensor4.setName("sensor-4");
    sensor4.setType("AirFlowSensor");
    Mockito.doReturn(new ArrayList<>()).when(wormholeAPIClient).getAllAssetsBySourceAndType(Mockito.anyString(), Mockito.any());
    Mockito.doReturn(new ArrayList<>(Arrays.asList(sensor1, sensor2, sensor3, sensor4))).when(powerIQAPIClient).getSensors(100, 0);
    Mockito.doReturn(null).when(powerIQAPIClient).getSensors(100, 1);
    Mockito.doReturn(new ResponseEntity<Void>(HttpStatus.OK)).when(wormholeAPIClient).saveAssets(Mockito.any(Asset.class));
    Mockito.doReturn("32c1d6dacf248a23553edbc6bbc922cd").when(powerIQService).getAssetIdByResponseEntity(Mockito.any(ResponseEntity.class));
    powerIQService.saveSensorAssetsToFlowgate(exsitingSensorAssets, powerIQAPIClient, assetSource, location);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) HashMap(java.util.HashMap) Asset(com.vmware.flowgate.common.model.Asset) LocationInfo(com.vmware.flowgate.poweriqworker.model.LocationInfo) Sensor(com.vmware.flowgate.poweriqworker.model.Sensor) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Sensor (com.vmware.flowgate.poweriqworker.model.Sensor)13 Asset (com.vmware.flowgate.common.model.Asset)10 Test (org.junit.Test)7 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)7 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)5 RealTimeData (com.vmware.flowgate.common.model.RealTimeData)4 SensorReading (com.vmware.flowgate.poweriqworker.model.SensorReading)3 PowerIQAPIClient (com.vmware.flowgate.poweriqworker.client.PowerIQAPIClient)2 Parent (com.vmware.flowgate.poweriqworker.model.Parent)2 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 WormholeException (com.vmware.flowgate.common.exception.WormholeException)1 AdvanceSettingType (com.vmware.flowgate.common.model.FacilitySoftwareConfig.AdvanceSettingType)1 IntegrationStatus (com.vmware.flowgate.common.model.IntegrationStatus)1 ValueUnit (com.vmware.flowgate.common.model.ValueUnit)1 MetricUnit (com.vmware.flowgate.common.model.ValueUnit.MetricUnit)1 LocationInfo (com.vmware.flowgate.poweriqworker.model.LocationInfo)1 SensorResult (com.vmware.flowgate.poweriqworker.model.SensorResult)1