Search in sources :

Example 1 with NlyteAuth

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

the class FacilitySoftwareControllerTest method updateAnFacilitySoftware.

@Test
public void updateAnFacilitySoftware() throws Exception {
    NlyteAuth nlyteAuth = Mockito.mock(NlyteAuth.class);
    Mockito.doReturn(false).when(nlyteAuth).auth(Mockito.any(FacilitySoftwareConfig.class));
    Mockito.doReturn(nlyteAuth).when(serverValidationService).createNlyteAuth();
    FacilitySoftwareConfig facilitySoftware = createFacilitySoftware();
    facilitySoftware.setPassword(EncryptionGuard.encode(facilitySoftware.getPassword()));
    facilitySoftwareRepository.save(facilitySoftware);
    facilitySoftware.setDescription("for generalUser");
    facilitySoftware.setUserName("generalUser");
    facilitySoftware.setPassword("generalUserPassword");
    try {
        this.mockMvc.perform(put("/v1/facilitysoftware").contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValueAsString(facilitySoftware))).andDo(document("facilitySoftware-update-example", requestFields(fieldWithPath("id").description("ID of the facilitySoftware, created by flowgate"), fieldWithPath("name").description("The facilitySoftware name."), fieldWithPath("description").description("The facilitySoftware description."), fieldWithPath("serverURL").description("The server's address, it can be an IP or FQDN."), fieldWithPath("userName").description("An username used to obtain authorization"), fieldWithPath("password").description(" A password used to obtain authorization."), fieldWithPath("type").description("A type for facilitySoftware,forExample Nlyte,PowerIQ,Device42,OtherDCIM or OtherCMDB").type(AssetSubCategory.class).optional(), fieldWithPath("userId").description("userId"), fieldWithPath("subCategory").description("subCategory"), fieldWithPath("verifyCert").description("Whether to verify the certificate when accessing the serverURL."), fieldWithPath("advanceSetting").description("advanceSetting"), fieldWithPath("integrationStatus.status").type(IntegrationStatus.Status.class).description("The status of integration.").optional(), fieldWithPath("integrationStatus.detail").type(String.class).description("If the status is error, it means error message").optional(), fieldWithPath("integrationStatus.retryCounter").type(JsonFieldType.NUMBER).description("Retry counter").optional())));
        facilitySoftware.setPassword(null);
        this.mockMvc.perform(put("/v1/facilitysoftware").contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValueAsString(facilitySoftware))).andDo(document("facilitySoftware-update-example", requestFields(fieldWithPath("id").description("ID of the facilitySoftware, created by flowgate"), fieldWithPath("name").description("The facilitySoftware name."), fieldWithPath("description").description("The facilitySoftware description."), fieldWithPath("serverURL").description("The server's address, it can be an IP or FQDN."), fieldWithPath("userName").description("An username used to obtain authorization"), fieldWithPath("password").description(" A password used to obtain authorization."), fieldWithPath("type").description("A type for facilitySoftware,forExample Nlyte,PowerIQ,Device42,OtherDCIM or OtherCMDB").type(AssetSubCategory.class).optional(), fieldWithPath("userId").description("userId"), fieldWithPath("subCategory").description("subCategory"), fieldWithPath("verifyCert").description("Whether to verify the certificate when accessing the serverURL."), fieldWithPath("advanceSetting").description("advanceSetting"), fieldWithPath("integrationStatus.status").type(IntegrationStatus.Status.class).description("The status of integration.").optional(), fieldWithPath("integrationStatus.detail").type(String.class).description("If the status is error, it means error message").optional(), fieldWithPath("integrationStatus.retryCounter").type(JsonFieldType.NUMBER).description("Retry counter").optional())));
    } catch (Exception e) {
        TestCase.fail();
    } finally {
        facilitySoftwareRepository.deleteById(facilitySoftware.getId());
    }
}
Also used : Status(com.vmware.flowgate.common.model.IntegrationStatus.Status) IntegrationStatus(com.vmware.flowgate.common.model.IntegrationStatus) HttpStatus(org.springframework.http.HttpStatus) FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) WormholeRequestException(com.vmware.flowgate.exception.WormholeRequestException) ExpectedException(org.junit.rules.ExpectedException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) NlyteAuth(com.vmware.flowgate.auth.NlyteAuth) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 2 with NlyteAuth

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

the class FacilitySoftwareControllerTest method createAnFacilitySoftwareThrowException.

@Test
public void createAnFacilitySoftwareThrowException() throws JsonProcessingException, Exception {
    NlyteAuth nlyteAuth = Mockito.mock(NlyteAuth.class);
    Mockito.doReturn(false).when(nlyteAuth).auth(Mockito.any(FacilitySoftwareConfig.class));
    Mockito.doReturn(createuser()).when(tokenService).getCurrentUser(any());
    Mockito.doReturn(nlyteAuth).when(serverValidationService).createNlyteAuth();
    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(publisher).publish(Mockito.anyString(), Mockito.anyString());
    expectedEx.expect(WormholeRequestException.class);
    expectedEx.expectMessage("Invalid user name or password");
    FacilitySoftwareConfig facilitySoftware = createFacilitySoftware();
    MvcResult result = this.mockMvc.perform(post("/v1/facilitysoftware").contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValueAsString(facilitySoftware))).andExpect(status().is4xxClientError()).andDo(document("facilitySoftware-create-example", requestFields(fieldWithPath("id").description("ID of the facilitySoftware, created by flowgate"), fieldWithPath("name").description("The facilitySoftware name."), fieldWithPath("description").description("The facilitySoftware description."), fieldWithPath("serverURL").description("The server's address, it can be an IP or FQDN."), fieldWithPath("userName").description("An username used to obtain authorization"), fieldWithPath("password").description(" A password used to obtain authorization."), fieldWithPath("type").description("A type for facilitySoftware,forExample Nlyte,PowerIQ,Device42,OtherDCIM or OtherCMDB").type(AssetSubCategory.class).optional(), fieldWithPath("userId").description("userid"), fieldWithPath("subCategory").description("subCategory"), fieldWithPath("verifyCert").description("Whether to verify the certificate when accessing the serverURL."), fieldWithPath("advanceSetting").description("advanceSetting"), subsectionWithPath("integrationStatus").description("The status of integration.")))).andReturn();
    if (result.getResolvedException() != null) {
        throw result.getResolvedException();
    } else {
        TestCase.fail();
    }
}
Also used : FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) MvcResult(org.springframework.test.web.servlet.MvcResult) AssetSubCategory(com.vmware.flowgate.common.AssetSubCategory) NlyteAuth(com.vmware.flowgate.auth.NlyteAuth) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 3 with NlyteAuth

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

the class FacilitySoftwareControllerTest method createAnFacilitySoftware.

@Test
public void createAnFacilitySoftware() throws JsonProcessingException, Exception {
    NlyteAuth nlyteAuth = Mockito.mock(NlyteAuth.class);
    Mockito.doReturn(true).when(nlyteAuth).auth(Mockito.any(FacilitySoftwareConfig.class));
    Mockito.doReturn(nlyteAuth).when(serverValidationService).createNlyteAuth();
    Mockito.doReturn(createuser()).when(tokenService).getCurrentUser(any());
    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(publisher).publish(Mockito.anyString(), Mockito.anyString());
    FacilitySoftwareConfig facilitySoftware = createFacilitySoftware();
    facilitySoftware.setServerURL("some.not.exit.server");
    facilitySoftware.setUserName("atestuser1");
    facilitySoftware.setPassword("atestuser1");
    try {
        this.mockMvc.perform(post("/v1/facilitysoftware").contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValueAsString(facilitySoftware))).andExpect(status().isCreated()).andDo(document("facilitySoftware-create-example", requestFields(fieldWithPath("id").description("ID of the facilitySoftware, created by flowgate"), fieldWithPath("name").description("The facilitySoftware name."), fieldWithPath("description").description("The facilitySoftware description."), fieldWithPath("serverURL").description("The server's address, it can be an IP or FQDN."), fieldWithPath("userName").description("An username used to obtain authorization"), fieldWithPath("password").description(" A password used to obtain authorization."), fieldWithPath("type").description("A type for facilitySoftware,forExample Nlyte,PowerIQ,Device42,OtherDCIM or OtherCMDB").type(AssetSubCategory.class).optional(), fieldWithPath("userId").description("userId"), fieldWithPath("subCategory").description("subCategory"), fieldWithPath("verifyCert").description("Whether to verify the certificate when accessing the serverURL."), fieldWithPath("advanceSetting").description("advanceSetting"), subsectionWithPath("integrationStatus").description("The status of integration."))));
    } catch (Exception e) {
        TestCase.fail();
    } finally {
        facilitySoftwareRepository.deleteById(facilitySoftware.getId());
    }
}
Also used : FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) WormholeRequestException(com.vmware.flowgate.exception.WormholeRequestException) ExpectedException(org.junit.rules.ExpectedException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) NlyteAuth(com.vmware.flowgate.auth.NlyteAuth) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Aggregations

NlyteAuth (com.vmware.flowgate.auth.NlyteAuth)3 FacilitySoftwareConfig (com.vmware.flowgate.common.model.FacilitySoftwareConfig)3 Test (org.junit.Test)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 WormholeRequestException (com.vmware.flowgate.exception.WormholeRequestException)2 ExpectedException (org.junit.rules.ExpectedException)2 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)2 AssetSubCategory (com.vmware.flowgate.common.AssetSubCategory)1 IntegrationStatus (com.vmware.flowgate.common.model.IntegrationStatus)1 Status (com.vmware.flowgate.common.model.IntegrationStatus.Status)1 HttpStatus (org.springframework.http.HttpStatus)1 MvcResult (org.springframework.test.web.servlet.MvcResult)1