Search in sources :

Example 31 with SDDCSoftwareConfig

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

the class VCDataServiceTest method testGetVaildServerMapping.

@Test
public void testGetVaildServerMapping() {
    SDDCSoftwareConfig vc = Mockito.mock(SDDCSoftwareConfig.class);
    String serviceKey = "serviceKey";
    when(serviceKeyConfig.getServiceKey()).thenReturn(serviceKey);
    doNothing().when(restClient).setServiceKey(serviceKey);
    when(vc.getId()).thenReturn("id");
    ServerMapping mapping1 = new ServerMapping();
    mapping1.setVcMobID("vc1");
    mapping1.setAsset("asset1");
    ServerMapping mapping2 = new ServerMapping();
    mapping2.setVcMobID("vc2");
    mapping2.setAsset("asset2");
    ServerMapping[] mappings = { mapping1, mapping2 };
    ResponseEntity<ServerMapping[]> serverMappings = new ResponseEntity<ServerMapping[]>(mappings, HttpStatus.OK);
    when(restClient.getServerMappingsByVC(anyString())).thenReturn(serverMappings);
    Map<String, ServerMapping> mobIdDictionary = service.getVaildServerMapping(vc);
    TestCase.assertEquals(mapping1, mobIdDictionary.get(mapping1.getVcMobID()));
    TestCase.assertEquals(mapping2, mobIdDictionary.get(mapping2.getVcMobID()));
}
Also used : SDDCSoftwareConfig(com.vmware.flowgate.common.model.SDDCSoftwareConfig) ResponseEntity(org.springframework.http.ResponseEntity) ServerMapping(com.vmware.flowgate.common.model.ServerMapping) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 32 with SDDCSoftwareConfig

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

the class SDDCSoftwareControllerTest method testGetInternalServerConfigsByType.

@Test
public void testGetInternalServerConfigsByType() 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);
    MvcResult result = this.mockMvc.perform(get("/v1/sddc/internal/type/" + SoftwareType.VCENTER)).andExpect(status().isOk()).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());
}
Also used : SDDCSoftwareConfig(com.vmware.flowgate.common.model.SDDCSoftwareConfig) MvcResult(org.springframework.test.web.servlet.MvcResult) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 33 with SDDCSoftwareConfig

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

the class SDDCSoftwareControllerTest method createSDDCSoftwareConfig.

SDDCSoftwareConfig createSDDCSoftwareConfig(SoftwareType type) {
    SDDCSoftwareConfig example = new SDDCSoftwareConfig();
    example.setId(UUID.randomUUID().toString());
    example.setName("test server");
    example.setServerURL("10.160.30.134");
    example.setType(type);
    example.setUserName("administrator@vsphere.local");
    example.setPassword("Admin!23");
    example.setUserId("1001");
    example.setVerifyCert(false);
    example.setDescription("description");
    IntegrationStatus integrationStatus = new IntegrationStatus();
    example.setIntegrationStatus(integrationStatus);
    return example;
}
Also used : SDDCSoftwareConfig(com.vmware.flowgate.common.model.SDDCSoftwareConfig) IntegrationStatus(com.vmware.flowgate.common.model.IntegrationStatus)

Example 34 with SDDCSoftwareConfig

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

the class SDDCSoftwareControllerTest method sDDCSoftwareDeleteVroAndVropsMpExample.

@Test
public void sDDCSoftwareDeleteVroAndVropsMpExample() throws Exception {
    SDDCSoftwareConfig sddc = createSDDCSoftwareConfig(SoftwareType.VRO);
    sddcRepository.save(sddc);
    ServerMapping serverMapping1 = createServerMapping(SoftwareType.VRO, sddc.getId());
    serverMappingRepository.save(serverMapping1);
    ServerMapping serverMapping2 = createServerMapping(SoftwareType.VRO, sddc.getId());
    serverMappingRepository.save(serverMapping2);
    this.mockMvc.perform(delete("/v1/sddc/" + sddc.getId())).andExpect(status().isOk());
    Optional<ServerMapping> serverMappingOptional1 = serverMappingRepository.findById(serverMapping1.getId());
    TestCase.assertEquals(false, serverMappingOptional1.isPresent());
    Optional<ServerMapping> serverMappingOptional2 = serverMappingRepository.findById(serverMapping2.getId());
    TestCase.assertEquals(false, serverMappingOptional2.isPresent());
    Optional<SDDCSoftwareConfig> sddcOptional = sddcRepository.findById(sddc.getId());
    TestCase.assertEquals(false, sddcOptional.isPresent());
}
Also used : SDDCSoftwareConfig(com.vmware.flowgate.common.model.SDDCSoftwareConfig) ServerMapping(com.vmware.flowgate.common.model.ServerMapping) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 35 with SDDCSoftwareConfig

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

the class SDDCSoftwareControllerTest method sDDCSoftwareDeleteVcenterExample.

@Test
public void sDDCSoftwareDeleteVcenterExample() throws Exception {
    SDDCSoftwareConfig sddc = createSDDCSoftwareConfig(SoftwareType.VCENTER);
    sddcRepository.save(sddc);
    ServerMapping serverMapping1 = createServerMapping(SoftwareType.VCENTER, sddc.getId());
    serverMappingRepository.save(serverMapping1);
    ServerMapping serverMapping2 = createServerMapping(SoftwareType.VCENTER, sddc.getId());
    serverMappingRepository.save(serverMapping2);
    this.mockMvc.perform(delete("/v1/sddc/{Id}", sddc.getId())).andExpect(status().isOk()).andDo(document("SDDCSoftware-delete-example", pathParameters(parameterWithName("Id").description("The id of SDDCSoftwareConfig, generated by flowgate."))));
    Optional<ServerMapping> serverMappingOptional1 = serverMappingRepository.findById(serverMapping1.getId());
    TestCase.assertEquals(false, serverMappingOptional1.isPresent());
    Optional<ServerMapping> serverMappingOptional2 = serverMappingRepository.findById(serverMapping2.getId());
    TestCase.assertEquals(false, serverMappingOptional2.isPresent());
    Optional<SDDCSoftwareConfig> sddcOptional = sddcRepository.findById(sddc.getId());
    TestCase.assertEquals(false, sddcOptional.isPresent());
}
Also used : SDDCSoftwareConfig(com.vmware.flowgate.common.model.SDDCSoftwareConfig) ServerMapping(com.vmware.flowgate.common.model.ServerMapping) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Aggregations

SDDCSoftwareConfig (com.vmware.flowgate.common.model.SDDCSoftwareConfig)42 Test (org.junit.Test)22 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)16 ServerMapping (com.vmware.flowgate.common.model.ServerMapping)11 ArrayList (java.util.ArrayList)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 WormholeRequestException (com.vmware.flowgate.exception.WormholeRequestException)8 MvcResult (org.springframework.test.web.servlet.MvcResult)8 SoftwareType (com.vmware.flowgate.common.model.SDDCSoftwareConfig.SoftwareType)7 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 Asset (com.vmware.flowgate.common.model.Asset)6 IOException (java.io.IOException)6 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)5 AuthVcUser (com.vmware.flowgate.auth.AuthVcUser)5 EventMessage (com.vmware.flowgate.common.model.redis.message.EventMessage)5 HashMap (java.util.HashMap)5 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)5 HostSystem (com.vmware.vim.binding.vim.HostSystem)4 ManagedObjectReference (com.vmware.vim.binding.vmodl.ManagedObjectReference)4