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();
}
}
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."))));
}
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());
}
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);
}
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());
}
}
Aggregations