Search in sources :

Example 1 with FacilitySoftwareConfig

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

the class FacilitySoftwareControllerTest method facilitySoftwareQueryByPageExample1.

// query by currentUser
@Test
public void facilitySoftwareQueryByPageExample1() throws Exception {
    WormholeUserDetails userDeails = createuser();
    userDeails.setUserId("5b7d208d55368540fcba1692");
    Mockito.doReturn(userDeails).when(tokenService).getCurrentUser(any());
    WormholeUser user = new WormholeUser();
    user.setId("5b7d208d55368540fcba1692");
    List<String> roles = new ArrayList<String>();
    // not admin
    roles.add("queryFacility");
    user.setRoleNames(roles);
    userRepository.save(user);
    // userId of the facilitySoftware is '5b7d208d55368540fcba1692'
    FacilitySoftwareConfig facilitySoftware = createFacilitySoftware();
    facilitySoftware.setUserId("5b7d208d55368540fcba1692");
    facilitySoftware.setPassword(EncryptionGuard.encode(facilitySoftware.getPassword()));
    facilitySoftwareRepository.save(facilitySoftware);
    int pageNumber = 1;
    int pageSize = 5;
    try {
        this.mockMvc.perform(get("/v1/facilitysoftware/page/{pageNumber}/pagesize/{pageSize}", pageNumber, pageSize)).andExpect(status().isOk()).andExpect(jsonPath("$..content[0].name").value(facilitySoftware.getName())).andExpect(jsonPath("$..content[0].userId").value(facilitySoftware.getUserId()));
    } finally {
        facilitySoftwareRepository.deleteById(facilitySoftware.getId());
        userRepository.deleteById(user.getId());
    }
}
Also used : WormholeUserDetails(com.vmware.flowgate.util.WormholeUserDetails) ArrayList(java.util.ArrayList) FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) WormholeUser(com.vmware.flowgate.common.model.WormholeUser) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 2 with FacilitySoftwareConfig

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

the class FacilitySoftwareControllerTest method getInternalFacilitySoftwareConfigByTypeExample.

@Test
public void getInternalFacilitySoftwareConfigByTypeExample() throws Exception {
    Mockito.doReturn(createuser()).when(tokenService).getCurrentUser(any());
    FacilitySoftwareConfig facilitySoftware1 = createFacilitySoftware();
    facilitySoftware1.setName("1");
    facilitySoftware1.setPassword(EncryptionGuard.encode(facilitySoftware1.getPassword()));
    facilitySoftwareRepository.save(facilitySoftware1);
    FacilitySoftwareConfig facilitySoftware2 = createFacilitySoftware();
    facilitySoftware1.setName("2");
    facilitySoftware2.setPassword(EncryptionGuard.encode(facilitySoftware2.getPassword()));
    facilitySoftwareRepository.save(facilitySoftware2);
    try {
        this.mockMvc.perform(get("/v1/facilitysoftware/internal/type/" + facilitySoftware1.getType() + "")).andExpect(status().isOk());
    } finally {
        facilitySoftwareRepository.deleteById(facilitySoftware1.getId());
        facilitySoftwareRepository.deleteById(facilitySoftware2.getId());
    }
}
Also used : FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 3 with FacilitySoftwareConfig

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

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

the class FacilitySoftwareControllerTest method facilitySoftwareDeleteExample.

@Test
public void facilitySoftwareDeleteExample() throws Exception {
    FacilitySoftwareConfig facilitySoftware = createFacilitySoftware();
    facilitySoftware = facilitySoftwareRepository.save(facilitySoftware);
    this.mockMvc.perform(delete("/v1/facilitysoftware/{Id}", facilitySoftware.getId())).andExpect(status().isOk()).andDo(document("facilitySoftware-delete-example", pathParameters(parameterWithName("Id").description("The id of facilitysoftwareConfig, generated by flowgate."))));
}
Also used : FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 5 with FacilitySoftwareConfig

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

the class FacilitySoftwareControllerTest method getFacilitySoftwareConfigByTypeExample.

@Test
public void getFacilitySoftwareConfigByTypeExample() throws Exception {
    Mockito.doReturn(createuser()).when(tokenService).getCurrentUser(any());
    FacilitySoftwareConfig facilitySoftware1 = createFacilitySoftware();
    facilitySoftware1.setName("1");
    facilitySoftware1.setPassword(EncryptionGuard.encode(facilitySoftware1.getPassword()));
    facilitySoftwareRepository.save(facilitySoftware1);
    FacilitySoftwareConfig facilitySoftware2 = createFacilitySoftware();
    facilitySoftware1.setName("2");
    facilitySoftware2.setPassword(EncryptionGuard.encode(facilitySoftware2.getPassword()));
    facilitySoftwareRepository.save(facilitySoftware2);
    FieldDescriptor[] fieldpath = new FieldDescriptor[] { fieldWithPath("id").description("ID of FacilitySoftwareConfig, created by flowgate"), fieldWithPath("name").description("The facilitySoftware name."), fieldWithPath("description").description("The facilitySoftware 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 facilitySoftware,forExample Nlyte,PowerIQ,Device42,OtherDCIM or OtherCMDB").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."), fieldWithPath("advanceSetting").description("Advance setting.").type(JsonFieldType.OBJECT) };
    try {
        this.mockMvc.perform(get("/v1/facilitysoftware/type/{type}", facilitySoftware1.getType())).andExpect(status().isOk()).andDo(document("facilitySoftware-getFacilitySoftwareConfigByType-example", pathParameters(parameterWithName("type").description("The type of FacilitySoftwareConfig. Sample value: Nlyte/PowerIQ/InfoBlox/OpenManage/Labsdb, you can use anyone of these options")), responseFields(fieldWithPath("[]").description("An array of facility software configs")).andWithPrefix("[].", fieldpath)));
    } finally {
        facilitySoftwareRepository.deleteById(facilitySoftware1.getId());
        facilitySoftwareRepository.deleteById(facilitySoftware2.getId());
    }
}
Also used : FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) SoftwareType(com.vmware.flowgate.common.model.FacilitySoftwareConfig.SoftwareType) FieldDescriptor(org.springframework.restdocs.payload.FieldDescriptor) 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