Search in sources :

Example 6 with CommonResult

use of com.vmware.flowgate.openmanage.datamodel.CommonResult in project flowgate by vmware.

the class OpenManageJobTest method handleChassiAssetsTest.

@Test
public void handleChassiAssetsTest() {
    CommonResult<Chassis> serversResult = new CommonResult<Chassis>();
    List<Chassis> chassisList = new ArrayList<Chassis>();
    Chassis chassis1 = new Chassis();
    chassis1.setAssetTag("chassis1");
    chassis1.setModel("los23");
    chassis1.setId(2583l);
    chassis1.setDeviceName("mychassis1");
    chassis1.setPowerState(PowerState.ON.getValue());
    chassis1.setStatus(DeviceStatus.NORMAL.getValue());
    chassisList.add(chassis1);
    Chassis chassis2 = new Chassis();
    chassis2.setAssetTag("chassis2");
    chassis2.setModel("sr4d");
    chassis2.setId(2523l);
    chassis2.setDeviceName("mychassis2");
    chassis2.setPowerState(PowerState.ON.getValue());
    chassis2.setStatus(DeviceStatus.NORMAL.getValue());
    chassisList.add(chassis2);
    Chassis chassis3 = new Chassis();
    chassis3.setAssetTag("chassis3");
    chassis3.setModel("chassis");
    chassis3.setId(2522l);
    chassis3.setDeviceName("mychassis3");
    chassis3.setPowerState(PowerState.ON.getValue());
    chassis3.setStatus(DeviceStatus.UNKNOWN.getValue());
    chassisList.add(chassis3);
    serversResult.setValue(chassisList);
    Asset asset = new Asset();
    asset.setCategory(AssetCategory.Chassis);
    asset.setAssetName("mychassis2");
    asset.setModel("sr4d");
    asset.setManufacturer("Dell");
    asset.setTag("0121");
    Map<String, String> openManageMap = new HashMap<String, String>();
    openManageMap.put(FlowgateConstant.ASSETNUMBER, String.valueOf(chassis2.getId()));
    HashMap<String, String> justficationfileds = new HashMap<String, String>();
    try {
        String openManageInfo = mapper.writeValueAsString(openManageMap);
        justficationfileds.put(FlowgateConstant.OPENMANAGE, openManageInfo);
        asset.setJustificationfields(justficationfileds);
    } catch (JsonProcessingException e) {
        TestCase.fail(e.getMessage());
    }
    Map<Long, Asset> assetNumberMap = new HashMap<Long, Asset>();
    assetNumberMap.put(252l, asset);
    String source = "integrationId";
    List<Asset> assets = openmanageJobService.handleChassisAssets(serversResult, assetNumberMap, source);
    TestCase.assertEquals(chassisList.size() - 1, assets.size());
    for (Asset chassisAsset : assets) {
        if (chassis1.getDeviceName().equals(chassisAsset.getAssetName())) {
            TestCase.assertEquals(chassis1.getAssetTag(), chassisAsset.getTag());
            TestCase.assertEquals(chassis1.getModel(), chassisAsset.getModel());
            HashMap<String, String> valueMap = chassisAsset.getJustificationfields();
            if (valueMap.isEmpty() || !valueMap.containsKey(FlowgateConstant.OPENMANAGE)) {
                TestCase.fail("Asset number is required");
            }
            String openManageInfo = valueMap.get(FlowgateConstant.OPENMANAGE);
            try {
                Map<String, String> infoMap = mapper.readValue(openManageInfo, new TypeReference<Map<String, String>>() {
                });
                ;
                String openManageDeviceId = infoMap.get(FlowgateConstant.ASSETNUMBER);
                TestCase.assertEquals(chassis1.getId(), Long.valueOf(openManageDeviceId).longValue());
            } catch (IOException ioException) {
                TestCase.fail(ioException.getMessage());
            }
        } else if (chassis2.getDeviceName().equals(chassisAsset.getAssetName())) {
            TestCase.assertEquals(chassis2.getAssetTag(), chassisAsset.getTag());
        } else {
            TestCase.fail("Invalid asset");
        }
    }
}
Also used : Chassis(com.vmware.flowgate.openmanage.datamodel.Chassis) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Asset(com.vmware.flowgate.common.model.Asset) CommonResult(com.vmware.flowgate.openmanage.datamodel.CommonResult) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Map(java.util.Map) HashMap(java.util.HashMap) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 7 with CommonResult

use of com.vmware.flowgate.openmanage.datamodel.CommonResult in project flowgate by vmware.

the class OpenManageJobTest method getCommonResultServer.

private CommonResult<Server> getCommonResultServer() {
    CommonResult<Server> serversResult = new CommonResult<Server>();
    List<Server> servers = new ArrayList<Server>();
    Server server1 = new Server();
    server1.setAssetTag("lkw456");
    server1.setModel("los23");
    server1.setId(258l);
    server1.setDeviceName("myserver1");
    server1.setPowerState(PowerState.ON.getValue());
    server1.setStatus(DeviceStatus.NORMAL.getValue());
    ServerSpecificData specificData = new ServerSpecificData();
    specificData.setManufacturer("Dell");
    server1.setDeviceSpecificData(specificData);
    servers.add(server1);
    Server server2 = new Server();
    server2.setAssetTag("asdqw2");
    server2.setModel("sr4d");
    server2.setId(252l);
    server2.setDeviceName("myserver2");
    server2.setPowerState(PowerState.OFF.getValue());
    server2.setStatus(DeviceStatus.NORMAL.getValue());
    ServerSpecificData specificData2 = new ServerSpecificData();
    specificData2.setManufacturer("Dell");
    server2.setDeviceSpecificData(specificData2);
    servers.add(server2);
    serversResult.setValue(servers);
    return serversResult;
}
Also used : Server(com.vmware.flowgate.openmanage.datamodel.Server) ArrayList(java.util.ArrayList) CommonResult(com.vmware.flowgate.openmanage.datamodel.CommonResult) ServerSpecificData(com.vmware.flowgate.openmanage.datamodel.ServerSpecificData)

Aggregations

CommonResult (com.vmware.flowgate.openmanage.datamodel.CommonResult)7 ArrayList (java.util.ArrayList)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 Asset (com.vmware.flowgate.common.model.Asset)2 Server (com.vmware.flowgate.openmanage.datamodel.Server)2 ServerSpecificData (com.vmware.flowgate.openmanage.datamodel.ServerSpecificData)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Test (org.junit.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 ResolvableType (org.springframework.core.ResolvableType)2 Chassis (com.vmware.flowgate.openmanage.datamodel.Chassis)1 Plugin (com.vmware.flowgate.openmanage.datamodel.Plugin)1 PowerSetting (com.vmware.flowgate.openmanage.datamodel.PowerSetting)1 URI (java.net.URI)1 UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)1