Search in sources :

Example 46 with FacilitySoftwareConfig

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

the class FacilityAdapterControllerTest method deleteFacilityAdapterThrowExceptionExample.

@Test
public void deleteFacilityAdapterThrowExceptionExample() throws Exception {
    FacilityAdapter adapter = createAdapter();
    String subcategory = "OtherDCIM_" + UUID.randomUUID().toString();
    adapter.setSubCategory(subcategory);
    facilityAdapterRepo.save(adapter);
    FacilitySoftwareConfig example = new FacilitySoftwareConfig();
    example.setId(UUID.randomUUID().toString());
    example.setName("Nlyte");
    example.setUserName("administrator@vsphere.local");
    example.setPassword("Admin!23");
    example.setServerURL("https://10.160.30.134");
    example.setType(FacilitySoftwareConfig.SoftwareType.Nlyte);
    example.setUserId("1");
    example.setVerifyCert(false);
    example.setDescription("description");
    example.setSubCategory(subcategory);
    facilitySoftwareRepo.save(example);
    expectedEx.expect(WormholeRequestException.class);
    expectedEx.expectMessage("Adapter deletion failed, there are some integration instances are using it");
    MvcResult result = this.mockMvc.perform(delete("/v1/facilityadapter/" + adapter.getId() + "").content("{\"id\":\"" + adapter.getId() + "\"}")).andReturn();
    if (result.getResolvedException() != null) {
        facilityAdapterRepo.deleteById(adapter.getId());
        facilitySoftwareRepo.deleteById(example.getId());
        throw result.getResolvedException();
    } else {
        TestCase.fail();
    }
}
Also used : FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MvcResult(org.springframework.test.web.servlet.MvcResult) FacilityAdapter(com.vmware.flowgate.common.model.FacilityAdapter) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 47 with FacilitySoftwareConfig

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

the class FacilitySoftwareControllerTest method facilitySoftwareQueryByPageAndTypeExample.

// facilitySoftwareConfigsByType
@Test
public void facilitySoftwareQueryByPageAndTypeExample() 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>();
    roles.add("admin");
    user.setRoleNames(roles);
    userRepository.save(user);
    // userId of the facilitySoftware is not '5b7d208d55368540fcba1692'
    FacilitySoftwareConfig facilitySoftware = createFacilitySoftware();
    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).param("softwaretypes", "Nlyte")).andExpect(status().isOk()).andExpect(jsonPath("$..content[0].name").value(facilitySoftware.getName())).andExpect(jsonPath("$..content[0].userId").value(facilitySoftware.getUserId())).andExpect(jsonPath("$..content[0].type").value(facilitySoftware.getType().name())).andDo(document("facilitySoftware-queryByTypeAndPage-example", pathParameters(parameterWithName("pageNumber").description("Get datas for this page number."), parameterWithName("pageSize").description("The number of facilitysoftwares you want to get by every request.Default value: 20")), requestParameters(parameterWithName("softwaretypes").description("A list of software, maybe contain Nlyte/PowerIQ/InfoBlox/OpenManage/Labsdb"))));
    } 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 48 with FacilitySoftwareConfig

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

the class FacilitySoftwareControllerTest method facilitySoftwareQueryByPageExample.

// admin can find all facilitySoftwareConfigs
@Test
public void facilitySoftwareQueryByPageExample() 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>();
    roles.add("admin");
    user.setRoleNames(roles);
    userRepository.save(user);
    // userId of the facilitySoftware is not '5b7d208d55368540fcba1692'
    FacilitySoftwareConfig facilitySoftware = createFacilitySoftware();
    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())).andDo(document("facilitySoftware-queryByPage-example", pathParameters(parameterWithName("pageNumber").description("Get datas for this page number."), parameterWithName("pageSize").description("The number of facilitysoftwares you want to get by every request.Default value: 20"))));
    } 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 49 with FacilitySoftwareConfig

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

the class FacilitySoftwareControllerTest method getInternalFacilitySoftwareConfigByIDExample.

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

Example 50 with FacilitySoftwareConfig

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

the class FacilitySoftwareControllerTest method syncDataForOpenmanageExample.

@Test
public void syncDataForOpenmanageExample() 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.OpenManage);
    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)

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