Search in sources :

Example 61 with Asset

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

the class AssetControllerTest method createHostNameAndIPMappingFailureExample2.

@Test
public void createHostNameAndIPMappingFailureExample2() throws Exception {
    SetOperations<String, String> setOperations = Mockito.mock(SetOperations.class);
    when(template.hasKey(anyString())).thenReturn(false);
    when(template.opsForSet()).thenReturn(setOperations);
    when(setOperations.add(anyString(), any())).thenReturn(1l);
    Asset server = createAsset();
    server.setCategory(AssetCategory.Server);
    server.setAssetName("cloud-sha1-esx2");
    assetRepository.save(server);
    AssetIPMapping mapping = createAssetIPMapping();
    mapping.setAssetname("cloud-sha1-esx8");
    mapping.setIp("192.168.0.1");
    mapping.setMacAddress("50:00:56:ge:64:62");
    expectedEx.expect(WormholeRequestException.class);
    expectedEx.expectMessage("Can't find any asset with the name : " + mapping.getAssetname());
    MvcResult result = this.mockMvc.perform(post("/v1/assets/mapping/hostnameip").contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValueAsString(mapping))).andReturn();
    if (result.getResolvedException() != null) {
        assetRepository.deleteById(server.getId());
        throw result.getResolvedException();
    }
}
Also used : AssetIPMapping(com.vmware.flowgate.common.model.AssetIPMapping) Asset(com.vmware.flowgate.common.model.Asset) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MvcResult(org.springframework.test.web.servlet.MvcResult) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 62 with Asset

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

the class AssetControllerTest method assetDeleteExample.

@Test
public void assetDeleteExample() throws Exception {
    Asset asset = createAsset();
    asset = assetRepository.save(asset);
    this.mockMvc.perform(delete("/v1/assets/{assetId}", asset.getId())).andExpect(status().isOk()).andDo(document("assets-delete-example", pathParameters(parameterWithName("assetId").description("The id of asset,generated by flowgate."))));
}
Also used : Asset(com.vmware.flowgate.common.model.Asset) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 63 with Asset

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

the class AssetControllerTest method testGetServerMetricsByIDFormulaIsEmpty.

@Test
public void testGetServerMetricsByIDFormulaIsEmpty() {
    Asset asset = createAsset();
    long time = System.currentTimeMillis();
    int duration = 30 * 60 * 1000;
    long startTime = time - duration;
    Map<String, String> formulars = new HashMap<String, String>();
    asset.setMetricsformulars(formulars);
    asset = assetRepository.save(asset);
    List<MetricData> metricDatas = assetService.getMetricsByID(asset.getId(), startTime, duration);
    TestCase.assertEquals(0, metricDatas.size());
    assetRepository.deleteById(asset.getId());
}
Also used : HashMap(java.util.HashMap) Asset(com.vmware.flowgate.common.model.Asset) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MetricData(com.vmware.flowgate.common.model.MetricData) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 64 with Asset

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

the class AssetControllerTest method testMetricFormulaStringIsNull.

@Test
public void testMetricFormulaStringIsNull() {
    Asset asset = createAsset();
    Map<String, String> formulaInfo = asset.metricsFormulaToMap(null, new TypeReference<Map<String, String>>() {
    });
    TestCase.assertEquals(null, formulaInfo);
}
Also used : Asset(com.vmware.flowgate.common.model.Asset) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Map(java.util.Map) HashMap(java.util.HashMap) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 65 with Asset

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

the class AssetControllerTest method findServersWithoutPDUInfoExample.

@Test
public void findServersWithoutPDUInfoExample() throws Exception {
    Asset asset = createAsset();
    asset = assetRepository.save(asset);
    ServerMapping mapping = new ServerMapping();
    mapping.setId(UUID.randomUUID().toString());
    mapping.setAsset(asset.getId());
    mapping.setVcID("5b7cfd5655368548d42e0fd5");
    mapping.setVcHostName("10.192.74.203");
    mapping.setVcMobID("host-11");
    serverMappingRepository.save(mapping);
    Asset asset2 = createAsset();
    asset2 = assetRepository.save(asset2);
    ServerMapping mapping2 = new ServerMapping();
    mapping2.setId(UUID.randomUUID().toString());
    mapping2.setAsset(asset2.getId());
    mapping2.setVcID("5b7cfd5655368548d42e0fd6");
    mapping2.setVcHostName("10.192.74.203");
    mapping2.setVcMobID("host-11");
    serverMappingRepository.save(mapping2);
    try {
        this.mockMvc.perform(get("/v1/assets/pdusisnull")).andDo(document("assets-findServersWithoutPDUInfo-example", responseFields(fieldWithPath("[]").description("An array of assets")).andWithPrefix("[].", fieldpath)));
    } finally {
        assetRepository.deleteById(asset.getId());
        serverMappingRepository.deleteById(mapping.getId());
        assetRepository.deleteById(asset2.getId());
        serverMappingRepository.deleteById(mapping2.getId());
    }
}
Also used : ServerMapping(com.vmware.flowgate.common.model.ServerMapping) Asset(com.vmware.flowgate.common.model.Asset) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

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