Search in sources :

Example 96 with Asset

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

the class SycnRealTimeDataJobTest method testSavePduAssetAndUpdatePduUsageFormula.

@Test
public void testSavePduAssetAndUpdatePduUsageFormula() {
    List<Asset> assets = new ArrayList<>();
    Asset asset = createAsset();
    asset.setCategory(AssetCategory.PDU);
    asset.setId(null);
    assets.add(asset);
    Mockito.doReturn(new ResponseEntity<Void>(HttpStatus.OK)).when(wormholeAPIClient).saveAssets(Mockito.any(Asset.class));
    Mockito.doReturn("23551d6dacf2432c8a3edbc6bbc922cd").when(nlyteDataService).getAssetIdByResponseEntity(Mockito.any(ResponseEntity.class));
    nlyteDataService.savePduAssetAndUpdatePduUsageFormula(assets);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ArrayList(java.util.ArrayList) NlyteAsset(com.vmware.flowgate.nlyteworker.model.NlyteAsset) Asset(com.vmware.flowgate.common.model.Asset) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 97 with Asset

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

the class SycnRealTimeDataJobTest method testGenerateNewAsset1.

@Test
public void testGenerateNewAsset1() {
    List<NlyteAsset> nlyteAssets = getNlyteAsset();
    HashMap<Integer, LocationGroup> locationMap = getLocationMap();
    HashMap<Integer, Material> materialMap = getMaterialMap();
    HashMap<Integer, Manufacturer> manufacturerMap = getManufacturerMap();
    List<Asset> assetsFromFlowgate = new ArrayList<Asset>();
    Asset preAsset = new Asset();
    preAsset.setAssetNumber(197);
    preAsset.setAssetSource("l9i8728d55368540fcba1692");
    assetsFromFlowgate.add(preAsset);
    Mockito.when(this.wormholeAPIClient.getAllAssetsBySourceAndType("l9i8728d55368540fcba1692", AssetCategory.Server)).thenReturn(assetsFromFlowgate);
    HashMap<Integer, String> cabinetIdAndNameMap = new HashMap<Integer, String>();
    cabinetIdAndNameMap.put(562, "cbName");
    nlyteAssets = nlyteDataService.supplementCabinetName(cabinetIdAndNameMap, nlyteAssets);
    List<Asset> assets = nlyteDataService.generateAssets("l9i8728d55368540fcba1692", nlyteAssets, locationMap, manufacturerMap, materialMap, AssetCategory.Server, new HashMap<Long, String>());
    for (Asset asset : assets) {
        if ("sin2-blrqeops-esxstress024".equals(asset.getAssetName())) {
            TestCase.assertEquals(197, asset.getAssetNumber());
            TestCase.assertEquals("SG-07-04", asset.getRoom());
            TestCase.assertEquals("Cisco 1721 Modular Access Router", asset.getModel());
            TestCase.assertEquals("Cisco", asset.getManufacturer());
            TestCase.assertEquals("cbName", asset.getCabinetName());
        }
    }
}
Also used : HashMap(java.util.HashMap) NlyteAsset(com.vmware.flowgate.nlyteworker.model.NlyteAsset) ArrayList(java.util.ArrayList) Material(com.vmware.flowgate.nlyteworker.model.Material) Manufacturer(com.vmware.flowgate.nlyteworker.model.Manufacturer) NlyteAsset(com.vmware.flowgate.nlyteworker.model.NlyteAsset) Asset(com.vmware.flowgate.common.model.Asset) LocationGroup(com.vmware.flowgate.nlyteworker.model.LocationGroup) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 98 with Asset

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

the class SycnRealTimeDataJobTest method testGetAssetIdfromformular1.

@Test
public void testGetAssetIdfromformular1() {
    List<Asset> assets = new ArrayList<Asset>();
    Asset asset = createAsset();
    assets.add(asset);
    Set<String> assetIds = nlyteDataService.getAssetIdfromformular(assets);
    TestCase.assertEquals(0, assetIds.size());
}
Also used : ArrayList(java.util.ArrayList) NlyteAsset(com.vmware.flowgate.nlyteworker.model.NlyteAsset) Asset(com.vmware.flowgate.common.model.Asset) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 99 with Asset

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

the class SycnRealTimeDataJobTest method testHandleAssets4.

@Test
public void testHandleAssets4() {
    List<Asset> toUpdateAssets = new ArrayList<Asset>();
    Map<Long, Asset> exsitingaAssetMap = new HashMap<Long, Asset>();
    Asset asset = createAsset();
    asset.setAssetNumber(127);
    asset.setTag("tag1");
    toUpdateAssets.add(asset);
    Asset asset2 = createAsset();
    asset2.setAssetNumber(128);
    asset2.setTag("tag2");
    asset2.setCabinetName("cabinet1");
    Tenant tenant = new Tenant();
    tenant.setOwner("admin");
    tenant.setTenant("tenant");
    tenant.setTenantManager("manager");
    asset2.setTenant(tenant);
    asset2.setRoom("room1");
    asset2.setRow("r2");
    asset2.setCol("c2");
    asset2.setMountingSide(MountingSide.Front);
    asset2.setCategory(AssetCategory.Networks);
    Parent parent = new Parent();
    parent.setParentId("ouqwenkja72hoas9034a");
    parent.setType("Chassis");
    asset2.setParent(parent);
    toUpdateAssets.add(asset2);
    Asset oldAsset1 = createAsset();
    oldAsset1.setAssetNumber(127);
    oldAsset1.setTag("oldtag1");
    exsitingaAssetMap.put(oldAsset1.getAssetNumber(), oldAsset1);
    Asset oldAsset2 = createAsset();
    oldAsset2.setAssetNumber(128);
    oldAsset2.setTag("oldtag2");
    exsitingaAssetMap.put(oldAsset2.getAssetNumber(), oldAsset2);
    HandleAssetUtil util = new HandleAssetUtil();
    List<Asset> assets = util.handleAssets(toUpdateAssets, exsitingaAssetMap);
    for (Asset assetTosave : assets) {
        if (assetTosave.getAssetNumber() == 128) {
            TestCase.assertEquals(asset2.getTag(), assetTosave.getTag());
            TestCase.assertEquals(asset2.getRoom(), assetTosave.getRoom());
            TestCase.assertEquals(asset2.getRow(), assetTosave.getRow());
            TestCase.assertEquals(asset2.getCol(), assetTosave.getCol());
            TestCase.assertEquals(asset2.getMountingSide(), assetTosave.getMountingSide());
            TestCase.assertEquals(asset2.getTenant().getOwner(), assetTosave.getTenant().getOwner());
            HashMap<String, String> justfications = assetTosave.getJustificationfields();
            TestCase.assertEquals("ouqwenkja72hoas9034a", assetTosave.getParent().getParentId());
        } else if (assetTosave.getAssetNumber() == 127) {
            TestCase.assertEquals(asset.getTag(), assetTosave.getTag());
        } else {
            TestCase.fail("Invalid assetNumber");
        }
    }
}
Also used : Tenant(com.vmware.flowgate.common.model.Tenant) HandleAssetUtil(com.vmware.flowgate.nlyteworker.scheduler.job.common.HandleAssetUtil) HashMap(java.util.HashMap) Parent(com.vmware.flowgate.common.model.Parent) ArrayList(java.util.ArrayList) NlyteAsset(com.vmware.flowgate.nlyteworker.model.NlyteAsset) Asset(com.vmware.flowgate.common.model.Asset) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 100 with Asset

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

the class SycnRealTimeDataJobTest method createAsset.

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

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