Search in sources :

Example 21 with FacilityAdapter

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

the class FacilityAdapterControllerTest method updateFacilityAdapterValidCommandsExample.

@Test
public void updateFacilityAdapterValidCommandsExample() throws JsonProcessingException, Exception {
    FacilityAdapter adapter = createAdapter();
    facilityAdapterRepo.save(adapter);
    adapter.setCommands(null);
    expectedEx.expect(WormholeRequestException.class);
    expectedEx.expectMessage("The Commands field is required.");
    MvcResult result = this.mockMvc.perform(put("/v1/facilityadapter").contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValueAsString(adapter))).andExpect(status().is4xxClientError()).andReturn();
    facilityAdapterRepo.deleteById(adapter.getId());
    if (result.getResolvedException() != null) {
        throw result.getResolvedException();
    } else {
        TestCase.fail();
    }
}
Also used : 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 22 with FacilityAdapter

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

the class FacilityAdapterControllerTest method createFacilityAdapterExample.

@Test
public void createFacilityAdapterExample() throws JsonProcessingException, Exception {
    SetOperations<String, String> setop = Mockito.mock(SetOperations.class);
    when(redis.opsForSet()).thenReturn(setop);
    when(setop.add(anyString(), anyString())).thenReturn(1l);
    FacilityAdapter adapter = createAdapter();
    this.mockMvc.perform(post("/v1/facilityadapter").contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValueAsString(adapter))).andExpect(status().isCreated()).andExpect(header().string("Location", notNullValue())).andDo(document("facilityadapter-create-example", requestFields(fieldWithPath("id").description("ID of the facility adapter, created by flowgate"), fieldWithPath("displayName").description("Display name of the facility adapter, created by user"), fieldWithPath("type").description("Type of the facility adapter"), fieldWithPath("description").description("Description of the facility adapter"), fieldWithPath("topic").description("Topic of the facility adapter,created by flowgate"), fieldWithPath("subCategory").description("Subcategory of the facility adapter,created by flowgate"), fieldWithPath("queueName").description("Queue name of the facility adapter,created by flowgate"), fieldWithPath("serviceKey").description("Value for auth,created by flowgate"), fieldWithPath("createTime").description("Create time of the facility adapter,created by flowgate"), subsectionWithPath("commands").description("Job commands of the facility adapter,it should be not null")))).andReturn().getResponse().getHeader("Location");
    facilityAdapterRepo.deleteById(adapter.getId());
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) FacilityAdapter(com.vmware.flowgate.common.model.FacilityAdapter) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 23 with FacilityAdapter

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

Aggregations

FacilityAdapter (com.vmware.flowgate.common.model.FacilityAdapter)23 Test (org.junit.Test)17 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)17 AdapterJobCommand (com.vmware.flowgate.common.model.AdapterJobCommand)7 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 MvcResult (org.springframework.test.web.servlet.MvcResult)7 FacilitySoftwareConfig (com.vmware.flowgate.common.model.FacilitySoftwareConfig)6 ArrayList (java.util.ArrayList)5 WormholeRequestException (com.vmware.flowgate.exception.WormholeRequestException)3 AssetController (com.vmware.flowgate.controller.AssetController)1 HashMap (java.util.HashMap)1 HttpHeaders (org.springframework.http.HttpHeaders)1 FieldDescriptor (org.springframework.restdocs.payload.FieldDescriptor)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1