use of com.vmware.flowgate.common.model.AssetIPMapping 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.AssetIPMapping in project flowgate by vmware.
the class AssetControllerTest method createHostNameIPMappingExample.
@Test
public void createHostNameIPMappingExample() 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");
server = assetRepository.save(server);
AssetIPMapping assetipmapping = createAssetIPMapping();
assetipmapping.setAssetname(server.getAssetName());
assetipmapping.setIp("192.168.0.1");
assetipmapping.setMacAddress("50:00:56:ge:64:62");
this.mockMvc.perform(post("/v1/assets/mapping/hostnameip").contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValueAsString(assetipmapping))).andExpect(status().isCreated()).andDo(document("assets-createHostNameIPMapping-example", requestFields(fieldWithPath("id").description("ID of the asset, created by flowgate"), fieldWithPath("ip").description("ip of hostname"), fieldWithPath("macAddress").description("macAddress of IP"), fieldWithPath("assetname").description("The name of the asset in the third part DCIM/CMDB systems. Usually it will be a unique identifier of an asset"))));
assetipmapping = assetIPMappingRepository.findById(assetipmapping.getId()).get();
assetRepository.deleteById(server.getId());
assetIPMappingRepository.deleteById(assetipmapping.getId());
TestCase.assertEquals(server.getAssetName(), assetipmapping.getAssetname());
}
use of com.vmware.flowgate.common.model.AssetIPMapping in project flowgate by vmware.
the class AssetControllerTest method updateHostNameIPMappingExample.
@Test
public void updateHostNameIPMappingExample() 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");
server = assetRepository.save(server);
Asset server1 = createAsset();
server1.setCategory(AssetCategory.Server);
server1.setAssetName("cloud-sha1-esx8");
server1 = assetRepository.save(server1);
AssetIPMapping assetipmapping = createAssetIPMapping();
assetipmapping.setAssetname(server.getAssetName());
assetipmapping = assetIPMappingRepository.save(assetipmapping);
AssetIPMapping newAssetIPMapping = createAssetIPMapping();
newAssetIPMapping.setAssetname(server1.getAssetName());
newAssetIPMapping.setId(assetipmapping.getId());
newAssetIPMapping.setMacAddress("00:50:56:be:60:62");
newAssetIPMapping.setIp("192.168.0.1");
this.mockMvc.perform(put("/v1/assets/mapping/hostnameip").contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValueAsString(newAssetIPMapping))).andExpect(status().isOk()).andDo(document("assets-updateHostNameIPMapping-example", requestFields(fieldWithPath("id").description("ID of the asset, created by flowgate"), fieldWithPath("ip").description("ip of hostname"), fieldWithPath("macAddress").description("macAddress of IP"), fieldWithPath("assetname").description("The name of the asset in the third part DCIM/CMDB systems. Usually it will be a unique identifier of an asset"))));
assetipmapping = assetIPMappingRepository.findById(assetipmapping.getId()).get();
assetRepository.deleteById(server.getId());
assetRepository.deleteById(server1.getId());
assetIPMappingRepository.deleteById(assetipmapping.getId());
TestCase.assertEquals(server1.getAssetName(), assetipmapping.getAssetname());
TestCase.assertEquals("00:50:56:be:60:62", assetipmapping.getMacAddress());
}
use of com.vmware.flowgate.common.model.AssetIPMapping in project flowgate by vmware.
the class AssetService method batchCreateMappingFromFile.
public List<AssetIPMapping> batchCreateMappingFromFile(MultipartFile multipartFile) throws IOException {
List<AssetIPMapping> failureMappings = new ArrayList<AssetIPMapping>();
InputStream inputStream = multipartFile.getInputStream();
try (InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "UTF-8");
BufferedReader br = new BufferedReader(inputStreamReader)) {
String assetIPMappingString = null;
while ((assetIPMappingString = br.readLine()) != null) {
AssetIPMapping mapping = parseAssetIPMapingByString(assetIPMappingString);
if (isAssetNameValidate(mapping.getAssetname()) && IPAddressUtil.isValidIp(mapping.getIp())) {
BaseDocumentUtil.generateID(mapping);
assetIPMappingRepository.save(mapping);
} else {
failureMappings.add(mapping);
}
}
}
return failureMappings;
}
use of com.vmware.flowgate.common.model.AssetIPMapping in project flowgate by vmware.
the class AssetService method parseAssetIPMapingByString.
public static AssetIPMapping parseAssetIPMapingByString(String contentString) {
String[] contentsArray = contentString.trim().split("\\s+");
AssetIPMapping mapping = new AssetIPMapping();
for (String content : contentsArray) {
if (!content.isEmpty() && mapping.getIp() == null) {
mapping.setIp(content);
continue;
}
if (!content.isEmpty() && mapping.getAssetname() == null) {
mapping.setAssetname(content);
break;
}
}
return mapping;
}
Aggregations