Search in sources :

Example 51 with FacilitySoftwareConfig

use of com.vmware.flowgate.common.model.FacilitySoftwareConfig 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 52 with FacilitySoftwareConfig

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

the class FacilitySoftwareControllerTest method createOpenManageThrowAuthException.

@Test
public void createOpenManageThrowAuthException() throws JsonProcessingException, Exception {
    OpenManageAuth openmanageAuth = Mockito.mock(OpenManageAuth.class);
    Mockito.doReturn(false).when(openmanageAuth).auth(Mockito.any(FacilitySoftwareConfig.class));
    Mockito.doReturn(createuser()).when(tokenService).getCurrentUser(any());
    Mockito.doReturn(openmanageAuth).when(serverValidationService).createOpenManageAuth();
    expectedEx.expect(WormholeRequestException.class);
    expectedEx.expectMessage("Invalid user name or password");
    FacilitySoftwareConfig facilitySoftware = createFacilitySoftware();
    facilitySoftware.setType(SoftwareType.OpenManage);
    facilitySoftware.setName("myOpenManage");
    MvcResult result = this.mockMvc.perform(post("/v1/facilitysoftware").contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValueAsString(facilitySoftware))).andExpect(status().is4xxClientError()).andReturn();
    if (result.getResolvedException() != null) {
        throw result.getResolvedException();
    } else {
        TestCase.fail();
    }
}
Also used : OpenManageAuth(com.vmware.flowgate.auth.OpenManageAuth) FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) MvcResult(org.springframework.test.web.servlet.MvcResult) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 53 with FacilitySoftwareConfig

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

the class FacilitySoftwareControllerTest method syncFacilityServerDataExample2.

@Test
public void syncFacilityServerDataExample2() throws JsonProcessingException, Exception {
    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.setType(FacilitySoftwareConfig.SoftwareType.PowerIQ);
    facilitySoftware.setPassword(EncryptionGuard.encode(facilitySoftware.getPassword()));
    facilitySoftware = facilitySoftwareRepository.save(facilitySoftware);
    try {
        MvcResult result = this.mockMvc.perform(post("/v1/facilitysoftware/syncdatabyserverid/" + facilitySoftware.getId() + "")).andDo(document("facilitySoftware-syncFacilityServerData-example")).andReturn();
        if (result.getResolvedException() != null) {
            throw result.getResolvedException();
        }
    } finally {
        facilitySoftwareRepository.deleteById(facilitySoftware.getId());
    }
}
Also used : FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) MvcResult(org.springframework.test.web.servlet.MvcResult) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 54 with FacilitySoftwareConfig

use of com.vmware.flowgate.common.model.FacilitySoftwareConfig 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)

Example 55 with FacilitySoftwareConfig

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

the class FacilitySoftwareControllerTest method createOpenManageThrowConnectException.

@Test
public void createOpenManageThrowConnectException() throws JsonProcessingException, Exception {
    Mockito.doReturn(createuser()).when(tokenService).getCurrentUser(any());
    expectedEx.expect(WormholeRequestException.class);
    expectedEx.expectMessage("Connect failed.");
    FacilitySoftwareConfig facilitySoftware = createFacilitySoftware();
    facilitySoftware.setType(SoftwareType.OpenManage);
    facilitySoftware.setName("myOpenManage");
    MvcResult result = this.mockMvc.perform(post("/v1/facilitysoftware").contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValueAsString(facilitySoftware))).andExpect(status().is4xxClientError()).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) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Aggregations

FacilitySoftwareConfig (com.vmware.flowgate.common.model.FacilitySoftwareConfig)60 Test (org.junit.Test)29 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)29 ArrayList (java.util.ArrayList)13 Asset (com.vmware.flowgate.common.model.Asset)8 IntegrationStatus (com.vmware.flowgate.common.model.IntegrationStatus)8 MvcResult (org.springframework.test.web.servlet.MvcResult)8 EventMessage (com.vmware.flowgate.common.model.redis.message.EventMessage)7 IOException (java.io.IOException)7 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 FacilityAdapter (com.vmware.flowgate.common.model.FacilityAdapter)6 AdapterJobCommand (com.vmware.flowgate.common.model.AdapterJobCommand)5 EventUser (com.vmware.flowgate.common.model.redis.message.EventUser)5 EventMessageImpl (com.vmware.flowgate.common.model.redis.message.impl.EventMessageImpl)5 HashMap (java.util.HashMap)5 ResponseEntity (org.springframework.http.ResponseEntity)5 RealTimeData (com.vmware.flowgate.common.model.RealTimeData)4 WormholeUser (com.vmware.flowgate.common.model.WormholeUser)4 WormholeUserDetails (com.vmware.flowgate.util.WormholeUserDetails)4