Search in sources :

Example 1 with AuthVcUser

use of com.vmware.flowgate.auth.AuthVcUser 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());
}
Also used : SDDCSoftwareConfig(com.vmware.flowgate.common.model.SDDCSoftwareConfig) AuthVcUser(com.vmware.flowgate.auth.AuthVcUser) MvcResult(org.springframework.test.web.servlet.MvcResult) WormholeRequestException(com.vmware.flowgate.exception.WormholeRequestException) SSLException(javax.net.ssl.SSLException) ExpectedException(org.junit.rules.ExpectedException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 2 with AuthVcUser

use of com.vmware.flowgate.auth.AuthVcUser 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());
}
Also used : SDDCSoftwareConfig(com.vmware.flowgate.common.model.SDDCSoftwareConfig) AuthVcUser(com.vmware.flowgate.auth.AuthVcUser) MvcResult(org.springframework.test.web.servlet.MvcResult) WormholeRequestException(com.vmware.flowgate.exception.WormholeRequestException) SSLException(javax.net.ssl.SSLException) ExpectedException(org.junit.rules.ExpectedException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 3 with AuthVcUser

use of com.vmware.flowgate.auth.AuthVcUser 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());
}
Also used : SDDCSoftwareConfig(com.vmware.flowgate.common.model.SDDCSoftwareConfig) AuthVcUser(com.vmware.flowgate.auth.AuthVcUser) SoftwareType(com.vmware.flowgate.common.model.SDDCSoftwareConfig.SoftwareType) WormholeRequestException(com.vmware.flowgate.exception.WormholeRequestException) SSLException(javax.net.ssl.SSLException) ExpectedException(org.junit.rules.ExpectedException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 4 with AuthVcUser

use of com.vmware.flowgate.auth.AuthVcUser in project flowgate by vmware.

the class SDDCSoftwareControllerTest method updateAnSDDCSoftwareConfig.

/**
 * Update SDDCSoftwareConfig Test case three:Whether can be saved successfully,when modify only
 * the server name or server description save success and test pass
 */
@Test
public void updateAnSDDCSoftwareConfig() 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");
    this.mockMvc.perform(put("/v1/sddc/").contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValueAsString(sddc))).andExpect(status().isOk()).andReturn();
    sddcRepository.deleteById(sddc.getId());
}
Also used : SDDCSoftwareConfig(com.vmware.flowgate.common.model.SDDCSoftwareConfig) AuthVcUser(com.vmware.flowgate.auth.AuthVcUser) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 5 with AuthVcUser

use of com.vmware.flowgate.auth.AuthVcUser in project flowgate by vmware.

the class SDDCSoftwareControllerTest method updateSDDCSoftwareConfigIsVerifyCert.

/**
 * Update SDDCSoftwareConfig Test case one:To update the IsVerifyCert.Whether can be saved
 * successfully,when the VerifyCert is true. The message 'Certificate verification error' will be
 * throwed,when the VerifyCert is true.
 */
@Test
public void updateSDDCSoftwareConfigIsVerifyCert() throws Exception {
    expectedEx.expect(WormholeRequestException.class);
    expectedEx.expectMessage("Certificate verification error");
    SDDCSoftwareConfig sddcCreate = createSDDCSoftwareConfig(SoftwareType.VCENTER);
    SDDCSoftwareConfig sddc = sddcRepository.save(sddcCreate);
    sddc.setVerifyCert(true);
    AuthVcUser vcAuth = Mockito.mock(AuthVcUser.class);
    Mockito.doThrow(new SSLException("I will failed")).when(vcAuth).authenticateUser(Mockito.anyString(), Mockito.anyString());
    Mockito.doReturn(vcAuth).when(serverValidationService).getVcAuth(Mockito.any(SDDCSoftwareConfig.class));
    try {
        MvcResult result = this.mockMvc.perform(put("/v1/sddc/").contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValueAsString(sddc))).andDo(document("SDDCSoftware-update-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();
        if (result.getResolvedException() != null) {
            throw result.getResolvedException();
        }
    } catch (Exception e) {
        throw e;
    } finally {
        sddcRepository.deleteById(sddc.getId());
    }
}
Also used : SDDCSoftwareConfig(com.vmware.flowgate.common.model.SDDCSoftwareConfig) AuthVcUser(com.vmware.flowgate.auth.AuthVcUser) MvcResult(org.springframework.test.web.servlet.MvcResult) SSLException(javax.net.ssl.SSLException) SoftwareType(com.vmware.flowgate.common.model.SDDCSoftwareConfig.SoftwareType) WormholeRequestException(com.vmware.flowgate.exception.WormholeRequestException) SSLException(javax.net.ssl.SSLException) ExpectedException(org.junit.rules.ExpectedException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Aggregations

AuthVcUser (com.vmware.flowgate.auth.AuthVcUser)5 SDDCSoftwareConfig (com.vmware.flowgate.common.model.SDDCSoftwareConfig)5 Test (org.junit.Test)5 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 WormholeRequestException (com.vmware.flowgate.exception.WormholeRequestException)4 SSLException (javax.net.ssl.SSLException)4 ExpectedException (org.junit.rules.ExpectedException)4 MvcResult (org.springframework.test.web.servlet.MvcResult)3 SoftwareType (com.vmware.flowgate.common.model.SDDCSoftwareConfig.SoftwareType)2