use of com.vmware.flowgate.common.model.SDDCSoftwareConfig in project flowgate by vmware.
the class SDDCSoftwareControllerTest method getVCServerConfigsExample.
@Test
public void getVCServerConfigsExample() throws Exception {
SDDCSoftwareConfig sddc1Create = createSDDCSoftwareConfig(SoftwareType.VCENTER);
sddc1Create.setType(SoftwareType.VCENTER);
sddc1Create.setName("flowgate");
sddc1Create.setDescription("flowgate cluster");
SDDCSoftwareConfig sddc2Create = createSDDCSoftwareConfig(SoftwareType.VCENTER);
sddc2Create.setType(SoftwareType.VCENTER);
sddc1Create.setPassword(EncryptionGuard.encode(sddc1Create.getPassword()));
sddc2Create.setPassword(EncryptionGuard.encode(sddc2Create.getPassword()));
sddcRepository.save(sddc1Create);
sddcRepository.save(sddc2Create);
FieldDescriptor[] fieldpath = new FieldDescriptor[] { fieldWithPath("id").description("ID of SDDCSoftwareConfig, created by flowgate"), fieldWithPath("name").description("The SDDCSoftwareConfig name."), fieldWithPath("description").description("The SDDCSoftwareConfig description."), fieldWithPath("userName").description("An username used to obtain authorization"), fieldWithPath("password").description(" A password used to obtain authorization."), fieldWithPath("serverURL").description("The server's address, it can be an IP or FQDN."), fieldWithPath("type").description("A type for SDDCSoftwareConfig,forExample VRO, VCENTER, OTHERS, VROPSMP").type(SoftwareType.class).optional(), fieldWithPath("userId").description("userId"), fieldWithPath("subCategory").description("subCategory"), fieldWithPath("verifyCert").description("Whether to verify the certificate when accessing the serverURL.").type(JsonFieldType.BOOLEAN), subsectionWithPath("integrationStatus").description("The status of integration.").optional() };
MvcResult result = this.mockMvc.perform(get("/v1/sddc/vc")).andExpect(status().isOk()).andDo(document("SDDCSoftware-getVCServerConfigs-example", responseFields(fieldWithPath("[]").description("An array of vCenter server configs")).andWithPrefix("[].", fieldpath))).andReturn();
String res = result.getResponse().getContentAsString();
ObjectMapper mapper = new ObjectMapper();
SDDCSoftwareConfig[] sddcs = mapper.readValue(res, SDDCSoftwareConfig[].class);
for (SDDCSoftwareConfig sddc : sddcs) {
if (sddc.getName().equals("flowgate")) {
TestCase.assertEquals("flowgate cluster", sddc.getDescription());
}
}
sddcRepository.deleteById(sddc1Create.getId());
sddcRepository.deleteById(sddc2Create.getId());
}
use of com.vmware.flowgate.common.model.SDDCSoftwareConfig in project flowgate by vmware.
the class SDDCSoftwareControllerTest method syncSDDCServerDataExample.
@Test
public void syncSDDCServerDataExample() throws JsonProcessingException, Exception {
Mockito.doReturn(createuser()).when(tokenService).getCurrentUser(any());
SDDCSoftwareConfig sddcCreate = createSDDCSoftwareConfig(SoftwareType.VCENTER);
sddcCreate.setPassword(EncryptionGuard.encode(sddcCreate.getPassword()));
SDDCSoftwareConfig sddc = sddcRepository.save(sddcCreate);
AuthVcUser vcAuth = Mockito.mock(AuthVcUser.class);
ListOperations<String, String> listOperations = Mockito.mock(ListOperations.class);
Mockito.doReturn(0L).when(listOperations).leftPush(Mockito.anyString(), Mockito.anyString());
Mockito.doReturn(listOperations).when(template).opsForList();
Mockito.doNothing().when(vcAuth).authenticateUser(Mockito.anyString(), Mockito.anyString());
Mockito.doReturn(vcAuth).when(serverValidationService).getVcAuth(Mockito.any(SDDCSoftwareConfig.class));
Mockito.doNothing().when(publisher).publish(Mockito.anyString(), Mockito.anyString());
try {
MvcResult result = this.mockMvc.perform(post("/v1/sddc/syncdatabyserverid/" + sddc.getId() + "")).andDo(document("SDDCSoftware-syncSDDCServerData-example")).andReturn();
TestCase.assertEquals(201, result.getResponse().getStatus());
} catch (Exception e) {
TestCase.fail();
}
sddcRepository.deleteById(sddc.getId());
}
use of com.vmware.flowgate.common.model.SDDCSoftwareConfig in project flowgate by vmware.
the class SDDCSoftwareControllerTest method getVROServerConfigsByUserExample.
@Test
public void getVROServerConfigsByUserExample() throws Exception {
Mockito.doReturn(createuser()).when(tokenService).getCurrentUser(any());
SDDCSoftwareConfig sddc1Create = createSDDCSoftwareConfig(SoftwareType.VCENTER);
sddc1Create.setType(SoftwareType.VRO);
sddc1Create.setName("flowgate");
sddc1Create.setDescription("flowgate cluster");
SDDCSoftwareConfig sddc2Create = createSDDCSoftwareConfig(SoftwareType.VCENTER);
sddc2Create.setType(SoftwareType.VRO);
sddc1Create.setPassword(EncryptionGuard.encode(sddc1Create.getPassword()));
sddc2Create.setPassword(EncryptionGuard.encode(sddc2Create.getPassword()));
sddcRepository.save(sddc1Create);
sddcRepository.save(sddc2Create);
FieldDescriptor[] fieldpath = new FieldDescriptor[] { fieldWithPath("id").description("ID of SDDCSoftwareConfig, created by flowgate"), fieldWithPath("name").description("The SDDCSoftwareConfig name."), fieldWithPath("description").description("The SDDCSoftwareConfig description."), fieldWithPath("userName").description("An username used to obtain authorization"), fieldWithPath("password").description(" A password used to obtain authorization."), fieldWithPath("serverURL").description("The server's address, it can be an IP or FQDN."), fieldWithPath("type").description("A type for SDDCSoftwareConfig,forExample VRO, VCENTER, OTHERS, VROPSMP").type(SoftwareType.class).optional(), fieldWithPath("userId").description("userId"), fieldWithPath("subCategory").description("subCategory"), fieldWithPath("verifyCert").description("Whether to verify the certificate when accessing the serverURL.").type(JsonFieldType.BOOLEAN), subsectionWithPath("integrationStatus").description("The status of integration.").optional() };
MvcResult result = this.mockMvc.perform(get("/v1/sddc/user/vrops")).andExpect(status().isOk()).andDo(document("SDDCSoftware-getVROServerConfigsByUser-example", responseFields(fieldWithPath("[]").description("An array of VROPS server configs")).andWithPrefix("[].", fieldpath))).andReturn();
String res = result.getResponse().getContentAsString();
ObjectMapper mapper = new ObjectMapper();
SDDCSoftwareConfig[] sddcs = mapper.readValue(res, SDDCSoftwareConfig[].class);
for (SDDCSoftwareConfig sddc : sddcs) {
if (sddc.getName().equals("flowgate")) {
TestCase.assertEquals("flowgate cluster", sddc.getDescription());
}
}
sddcRepository.deleteById(sddc1Create.getId());
sddcRepository.deleteById(sddc2Create.getId());
}
use of com.vmware.flowgate.common.model.SDDCSoftwareConfig in project flowgate by vmware.
the class SDDCSoftwareControllerTest method updateAnSDDCSoftwareConfigUserNameAndPassword.
/**
* Update SDDCSoftwareConfig Test case two:To update the username and password.Whether the wrong
* username and password can be saved successfully The message 'Invalid user name or password'
* will be throwed,when you given a password and an userName what is wrong;
*/
@Test
public void updateAnSDDCSoftwareConfigUserNameAndPassword() throws JsonProcessingException, Exception {
AuthVcUser vcAuth = Mockito.mock(AuthVcUser.class);
Mockito.doNothing().when(vcAuth).authenticateUser(Mockito.anyString(), Mockito.anyString());
Mockito.doReturn(vcAuth).when(serverValidationService).getVcAuth(Mockito.any(SDDCSoftwareConfig.class));
SDDCSoftwareConfig sddcCreate = createSDDCSoftwareConfig(SoftwareType.VCENTER);
SDDCSoftwareConfig sddc = sddcRepository.save(sddcCreate);
sddc.setName("test update name");
sddc.setUserName("testUserName");
sddc.setPassword("testPassword");
try {
MvcResult result = this.mockMvc.perform(put("/v1/sddc/").contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValueAsString(sddc))).andReturn();
TestCase.assertEquals(200, result.getResponse().getStatus());
} catch (Exception e) {
TestCase.fail();
}
sddcRepository.deleteById(sddc.getId());
}
use of com.vmware.flowgate.common.model.SDDCSoftwareConfig in project flowgate by vmware.
the class SDDCSoftwareControllerTest method createVCenterSDDCSoftwareConfig.
@Test
public void createVCenterSDDCSoftwareConfig() throws JsonProcessingException, Exception {
SDDCSoftwareConfig sddc = createSDDCSoftwareConfig(SoftwareType.VCENTER);
Mockito.doReturn(createuser()).when(tokenService).getCurrentUser(any());
AuthVcUser vcAuth = Mockito.mock(AuthVcUser.class);
ListOperations<String, String> listOperations = Mockito.mock(ListOperations.class);
Mockito.doReturn(0L).when(listOperations).leftPush(Mockito.anyString(), Mockito.anyString());
Mockito.doReturn(listOperations).when(template).opsForList();
Mockito.doNothing().when(vcAuth).authenticateUser(Mockito.anyString(), Mockito.anyString());
Mockito.doReturn(vcAuth).when(serverValidationService).getVcAuth(Mockito.any(SDDCSoftwareConfig.class));
Mockito.doNothing().when(publisher).publish(Mockito.anyString(), Mockito.anyString());
try {
this.mockMvc.perform(post("/v1/sddc/").contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValueAsString(sddc))).andExpect(status().isCreated()).andDo(document("SDDCSoftware-create-example", requestFields(fieldWithPath("id").description("ID of the SDDCSoftwareConfig, created by flowgate"), fieldWithPath("name").description("The SDDCSoftwareConfig name."), fieldWithPath("description").description("The SDDCSoftwareConfig description."), fieldWithPath("serverURL").description("An ip address for a SDDCSoftwareConfig"), fieldWithPath("userName").description("An username used to obtain authorization"), fieldWithPath("password").description(" A password used to obtain authorization."), fieldWithPath("type").description("A type for SDDCSoftwareConfig,forExample VRO, VCENTER, OTHERS").type(SoftwareType.class).optional(), fieldWithPath("userId").description("userId"), fieldWithPath("subCategory").description("subCategory"), fieldWithPath("verifyCert").description("Whether to verify the certificate when accessing the serverURL."), subsectionWithPath("integrationStatus").description("The status of integration.")))).andReturn();
} catch (Exception e) {
TestCase.fail(e.getMessage());
}
sddcRepository.deleteById(sddc.getId());
}
Aggregations