use of com.vmware.flowgate.common.model.Asset in project flowgate by vmware.
the class OpenManageJobTest method executeJobTest.
@Test
public void executeJobTest() {
FacilitySoftwareConfig config = new FacilitySoftwareConfig();
config.setId("executeJob");
IntegrationStatus integrationStatus = new IntegrationStatus();
integrationStatus.setStatus(IntegrationStatus.Status.ACTIVE);
doNothing().when(this.openManageAPIClient).getToken();
doNothing().when(this.wormholeAPIClient).setServiceKey(any(String.class));
Mockito.when(this.openmanageJobService.createClient(config)).thenReturn(this.openManageAPIClient);
Mockito.when(this.wormholeAPIClient.saveAssets(any(Asset.class))).thenReturn(saveAsset());
Mockito.when(this.wormholeAPIClient.saveAssets(ArgumentMatchers.anyList())).thenReturn(null);
Mockito.when(this.wormholeAPIClient.getAllAssetsBySourceAndType(config.getId(), AssetCategory.Server)).thenReturn(getAllAssetsBySourceAndType());
Mockito.when(this.wormholeAPIClient.getAllAssetsBySourceAndType(config.getId(), AssetCategory.Chassis)).thenReturn(new ArrayList<Asset>());
Mockito.when(this.openManageAPIClient.getDevices(any(Integer.class), any(Integer.class), ArgumentMatchers.eq(Server.class))).thenReturn(getCommonResultServer());
Mockito.when(this.openManageAPIClient.getDevices(any(Integer.class), any(Integer.class), ArgumentMatchers.eq(Chassis.class))).thenReturn(new CommonResult<Chassis>());
openmanageJobService.executeJob(EventMessageUtil.OpenManage_SyncAssetsMetaData, config);
}
use of com.vmware.flowgate.common.model.Asset in project flowgate by vmware.
the class SyncPduAssetJobTest method testGetAssetIdfromformular.
@Test
public void testGetAssetIdfromformular() throws JsonProcessingException {
List<Asset> assets = new ArrayList<>();
Asset asset = createAsset();
Map<String, String> formulars = new HashMap<>();
Map<String, Map<String, String>> sensorFormulars = new HashMap<String, Map<String, String>>();
Map<String, String> humidityLocationAndIdMap = new HashMap<String, String>();
humidityLocationAndIdMap.put("1", "po09imkhdplbvf540fwusy67n");
Map<String, String> tempreatureLocationAndIdMap = new HashMap<String, String>();
tempreatureLocationAndIdMap.put("2", "asdasd2s2gxvf5wfwudwadbn");
sensorFormulars.put(MetricName.PDU_HUMIDITY, humidityLocationAndIdMap);
sensorFormulars.put(MetricName.PDU_TEMPERATURE, tempreatureLocationAndIdMap);
formulars.put(FlowgateConstant.SENSOR, mapper.writeValueAsString(sensorFormulars));
asset.setMetricsformulars(formulars);
assets.add(asset);
Set<String> assetIDs = powerIQService.getAssetIdfromformular(assets);
TestCase.assertEquals(2, assetIDs.size());
Map<String, String> map = new HashMap<String, String>();
map.put("po09imkhdplbvf540fwusy67n", "po09imkhdplbvf540fwusy67n");
map.put("asdasd2s2gxvf5wfwudwadbn", "asdasd2s2gxvf5wfwudwadbn");
for (String assetid : assetIDs) {
TestCase.assertEquals(map.get(assetid), assetid);
}
}
use of com.vmware.flowgate.common.model.Asset in project flowgate by vmware.
the class SyncPduAssetJobTest method createAsset.
Asset createAsset() {
Asset asset = new Asset();
ObjectMapper mapper = new ObjectMapper();
asset.setAssetName("pek-wor-pdu-02");
asset.setAssetNumber(89765);
asset.setAssetSource("po09imkhdplbvf540fwusy67n");
asset.setCategory(AssetCategory.PDU);
asset.setModel("Dell 750");
asset.setManufacturer("Dell");
Map<String, String> pduInfo = new HashMap<String, String>();
pduInfo.put(FlowgateConstant.PDU_ID_FROM_POWERIQ, "128");
String pduInfoString = null;
try {
pduInfoString = mapper.writeValueAsString(pduInfo);
} catch (JsonProcessingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
HashMap<String, String> justficationfields = new HashMap<String, String>();
justficationfields.put(FlowgateConstant.PDU, pduInfoString);
asset.setJustificationfields(justficationfields);
return asset;
}
use of com.vmware.flowgate.common.model.Asset in project flowgate by vmware.
the class SyncPduAssetJobTest method testSavePduAssetsToFlowgate.
@Test
public void testSavePduAssetsToFlowgate() {
Map<String, Asset> existedPduAssets = new HashMap<>();
Asset asset1 = createAsset();
asset1.setId("126134615724572");
Asset asset2 = createAsset();
asset2.setId("BOQBNBHQOQJAOJQY");
existedPduAssets.put(asset1.getId(), asset1);
existedPduAssets.put(asset2.getId(), asset2);
String assetSource = "UGVINQVNQIGQGQIDNKD";
LocationInfo location = null;
Pdu pdu1 = createPdu();
pdu1.setId(126134615724572L);
pdu1.setName("pek-wor-pdu-01");
Pdu pdu2 = createPdu();
pdu2.setId(226134615724572L);
pdu2.setName("pek-wor-pdu-02");
Mockito.doReturn(new ArrayList<>(Arrays.asList(pdu1, pdu2))).when(powerIQAPIClient).getPdus(100, 0);
Mockito.doReturn(null).when(powerIQAPIClient).getPdus(100, 100);
Mockito.doReturn(getOutlets()).when(powerIQAPIClient).getOutlets(Mockito.anyLong());
Mockito.doReturn(getInlets()).when(powerIQAPIClient).getInlets(Mockito.anyLong());
Mockito.doReturn(new ResponseEntity<Void>(HttpStatus.OK)).when(wormholeAPIClient).saveAssets(Mockito.any(Asset.class));
Mockito.doReturn("23551d6dacf2432c8a3edbc6bbc922cd").when(powerIQService).getAssetIdByResponseEntity(Mockito.any(ResponseEntity.class));
boolean triggerPDUAggregation = powerIQService.savePduAssetsToFlowgate(existedPduAssets, assetSource, powerIQAPIClient, location);
TestCase.assertTrue(triggerPDUAggregation);
}
use of com.vmware.flowgate.common.model.Asset in project flowgate by vmware.
the class SyncPduAssetJobTest method testUpdatePduMetricformular2.
@Test
public void testUpdatePduMetricformular2() throws JsonProcessingException {
List<Asset> assets = new ArrayList<>();
Asset asset = createAsset();
asset.setCabinetUnitPosition(1);
asset.setId("po09imkhdplbvf540fwusy67n");
asset.setCategory(AssetCategory.Sensors);
asset.setSubCategory(AssetSubCategory.Humidity);
Map<String, String> sensorInfoMap = new HashMap<String, String>();
sensorInfoMap.put(FlowgateConstant.POSITION, "INLET");
ObjectMapper mapper = new ObjectMapper();
HashMap<String, String> justfication = new HashMap<String, String>();
try {
justfication.put(FlowgateConstant.SENSOR, mapper.writeValueAsString(sensorInfoMap));
} catch (JsonProcessingException e1) {
TestCase.fail();
}
asset.setJustificationfields(justfication);
Parent parent = new Parent();
parent.setParentId("125");
parent.setType("PDU");
asset.setParent(parent);
assets.add(asset);
Map<String, Asset> pduIdAndAssetMap = new HashMap<String, Asset>();
Asset pduAsset = createAsset();
pduIdAndAssetMap.put("125", pduAsset);
Set<Asset> pduNeedTosave = powerIQService.updatePduMetricformular(assets, pduIdAndAssetMap);
TestCase.assertEquals(1, pduNeedTosave.size());
Asset pdu = pduNeedTosave.iterator().next();
TestCase.assertEquals(pduAsset.getAssetName(), pdu.getAssetName());
try {
Map<String, String> formulars = pdu.getMetricsformulars();
Map<String, Map<String, String>> sensorFormulars = mapper.readValue(formulars.get(FlowgateConstant.SENSOR), new TypeReference<Map<String, Map<String, String>>>() {
});
Map<String, String> humidityLocationAndIdMap = sensorFormulars.get(MetricName.PDU_HUMIDITY);
TestCase.assertEquals("po09imkhdplbvf540fwusy67n", humidityLocationAndIdMap.get(FlowgateConstant.RACK_UNIT_PREFIX + "1" + FlowgateConstant.SEPARATOR + sensorInfoMap.get(FlowgateConstant.POSITION)));
} catch (Exception e) {
TestCase.fail();
}
}
Aggregations