Search in sources :

Example 11 with TranslateContext

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

the class TranslateFunctionServiceTest method testExceptionConvertServerPeakUsedPowerMinimumUsedPowerPeakTemperature.

@Test
public void testExceptionConvertServerPeakUsedPowerMinimumUsedPowerPeakTemperature() {
    String assetId = "752c0c7637104a39a4242031cd48785e";
    long startTime = System.currentTimeMillis();
    long endTime = startTime + 30000;
    ValueUnit valueUnit = new ValueUnit();
    valueUnit.setTime(endTime);
    valueUnit.setKey(MetricName.SERVER_PEAK_USED_POWER);
    valueUnit.setUnit(ValueUnit.MetricUnit.kW.toString());
    valueUnit.setValueNum(0.07);
    String displayName = MetricName.SERVER_PEAK_USED_POWER;
    Function<TranslateContext, MetricData> function = TranslateFunctionService.serverFormulaKeyAndFunction.get(MetricName.SERVER_PEAK_USED_POWER);
    Map<String, ValueUnit> valueUnitMap = new HashMap<>();
    valueUnitMap.put(assetId, valueUnit);
    TranslateContext translateContext = TranslateContext.buildByValueUnitsAndDisplayNameAndFormula(valueUnitMap, displayName, assetId);
    MetricData metricData = function.apply(translateContext);
    TestCase.assertNull(metricData);
    valueUnit.setExtraidentifier(String.valueOf(startTime));
    translateContext = TranslateContext.buildByValueUnitsAndDisplayNameAndFormula(valueUnitMap, displayName, assetId);
    metricData = function.apply(translateContext);
    TestCase.assertNull(metricData);
}
Also used : HashMap(java.util.HashMap) ValueUnit(com.vmware.flowgate.common.model.ValueUnit) TranslateContext(com.vmware.flowgate.common.model.TranslateContext) MetricData(com.vmware.flowgate.common.model.MetricData) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 12 with TranslateContext

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

the class TranslateFunctionServiceTest method testConvertByExtraIdentifier.

@Test
public void testConvertByExtraIdentifier() {
    String assetId = "752c0c7637104a39a4242031cd48785e";
    long currentTimeMillis = System.currentTimeMillis();
    ValueUnit valueUnit = new ValueUnit();
    valueUnit.setKey(MetricName.PDU_ACTIVE_POWER);
    valueUnit.setUnit(ValueUnit.MetricUnit.kW.toString());
    valueUnit.setExtraidentifier("OUTLET:7");
    valueUnit.setValueNum(0.2);
    valueUnit.setTime(currentTimeMillis);
    String displayName = MetricName.PDU_XLET_ACTIVE_POWER;
    Function<TranslateContext, MetricData> function = TranslateFunctionService.pduFormulaKeyAndFunction.get(MetricName.PDU_XLET_ACTIVE_POWER);
    Map<String, ValueUnit> valueUnitMap = new HashMap<>();
    valueUnitMap.put(assetId, valueUnit);
    TranslateContext translateContext = TranslateContext.buildByValueUnitsAndDisplayNameAndFormula(valueUnitMap, displayName, assetId);
    MetricData metricData = function.apply(translateContext);
    TestCase.assertEquals(String.format(displayName, valueUnit.getExtraidentifier()), metricData.getMetricName());
    TestCase.assertEquals(valueUnit.getTime(), metricData.getTimeStamp());
    TestCase.assertEquals(valueUnit.getValueNum(), metricData.getValueNum());
    TestCase.assertEquals(valueUnit.getUnit(), metricData.getUnit());
}
Also used : HashMap(java.util.HashMap) ValueUnit(com.vmware.flowgate.common.model.ValueUnit) TranslateContext(com.vmware.flowgate.common.model.TranslateContext) MetricData(com.vmware.flowgate.common.model.MetricData) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 13 with TranslateContext

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

the class TranslateFunctionServiceTest method testConvertPduCurrentVoltageFreeCapacityByExtraIdentifier.

@Test
public void testConvertPduCurrentVoltageFreeCapacityByExtraIdentifier() {
    String assetId = "752c0c7637104a39a4242031cd48785e";
    long currentTimeMillis = System.currentTimeMillis();
    ValueUnit valueUnit = new ValueUnit();
    valueUnit.setKey(MetricName.PDU_CURRENT);
    valueUnit.setUnit(ValueUnit.MetricUnit.A.toString());
    valueUnit.setExtraidentifier("INLET:1|L1");
    valueUnit.setValueNum(6);
    valueUnit.setTime(currentTimeMillis);
    String displayName = MetricName.PDU_INLET_XPOLE_CURRENT;
    Function<TranslateContext, MetricData> function = TranslateFunctionService.pduFormulaKeyAndFunction.get(MetricName.PDU_INLET_XPOLE_CURRENT);
    Map<String, ValueUnit> valueUnitMap = new HashMap<>();
    valueUnitMap.put(assetId, valueUnit);
    TranslateContext translateContext = TranslateContext.buildByValueUnitsAndDisplayNameAndFormula(valueUnitMap, displayName, assetId);
    MetricData metricData = function.apply(translateContext);
    TestCase.assertEquals("INLET:1|L1|Current", metricData.getMetricName());
    TestCase.assertEquals(valueUnit.getTime(), metricData.getTimeStamp());
    TestCase.assertEquals(valueUnit.getValueNum(), metricData.getValueNum());
    TestCase.assertEquals(valueUnit.getUnit(), metricData.getUnit());
}
Also used : HashMap(java.util.HashMap) ValueUnit(com.vmware.flowgate.common.model.ValueUnit) TranslateContext(com.vmware.flowgate.common.model.TranslateContext) MetricData(com.vmware.flowgate.common.model.MetricData) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

MetricData (com.vmware.flowgate.common.model.MetricData)13 TranslateContext (com.vmware.flowgate.common.model.TranslateContext)13 ValueUnit (com.vmware.flowgate.common.model.ValueUnit)13 HashMap (java.util.HashMap)13 Test (org.junit.Test)9 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)9 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Map (java.util.Map)4