Search in sources :

Example 1 with FacilityAdapter

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

the class FacilityAdapterControllerTest method createFacilityAdapterValidCommands.

@Test
public void createFacilityAdapterValidCommands() throws JsonProcessingException, Exception {
    FacilityAdapter adapter = createAdapter();
    adapter.setCommands(null);
    expectedEx.expect(WormholeRequestException.class);
    expectedEx.expectMessage("The Commands field is required.");
    MvcResult result = this.mockMvc.perform(post("/v1/facilityadapter").contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValueAsString(adapter))).andExpect(status().is4xxClientError()).andReturn();
    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 2 with FacilityAdapter

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

the class FacilityAdapterControllerTest method deleteFacilityAdapterExample.

@Test
public void deleteFacilityAdapterExample() throws Exception {
    SetOperations<String, String> setop = Mockito.mock(SetOperations.class);
    when(redis.opsForSet()).thenReturn(setop);
    when(setop.isMember(anyString(), anyString())).thenReturn(true);
    when(setop.remove(anyString(), anyString())).thenReturn(1l);
    FacilityAdapter adapter = createAdapter();
    facilityAdapterRepo.save(adapter);
    this.mockMvc.perform(delete("/v1/facilityadapter/{Id}", adapter.getId())).andExpect(status().isOk()).andDo(document("facilityadapter-deleteById-example", pathParameters(parameterWithName("Id").description("The id of facility adapter,generated by flowgate.")))).andReturn();
}
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 3 with FacilityAdapter

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

the class FacilityAdapterControllerTest method updateFacilityAdapterExample.

@Test
public void updateFacilityAdapterExample() throws JsonProcessingException, Exception {
    FacilityAdapter adapter = createAdapter();
    facilityAdapterRepo.save(adapter);
    adapter.setDisplayName("displayNameForTestUpdate");
    this.mockMvc.perform(put("/v1/facilityadapter").contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValueAsString(adapter))).andExpect(status().isOk()).andDo(document("facilityadapter-update-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();
    facilityAdapterRepo.deleteById(adapter.getId());
}
Also used : FacilityAdapter(com.vmware.flowgate.common.model.FacilityAdapter) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 4 with FacilityAdapter

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

the class FacilityAdapterControllerTest method createFacilityAdapterValidDisplayName.

@Test
public void createFacilityAdapterValidDisplayName() throws JsonProcessingException, Exception {
    FacilityAdapter adapter = createAdapter();
    adapter.setDisplayName("Nlyte");
    expectedEx.expect(WormholeRequestException.class);
    expectedEx.expectMessage("Invalid value: 'Nlyte' for field: 'DisplayName' ");
    MvcResult result = this.mockMvc.perform(post("/v1/facilityadapter").contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValueAsString(adapter))).andExpect(status().is4xxClientError()).andReturn();
    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 5 with FacilityAdapter

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

the class FacilityAdapterService method deleteAdapter.

public void deleteAdapter(String id) {
    FacilityAdapter adapter = findById(id);
    int count = facilitySoftwareRepo.countFacilityBySubcategory(adapter.getSubCategory());
    if (count > 0) {
        throw new WormholeRequestException("Adapter deletion failed, there are some integration instances are using it");
    } else {
        facilityAdapterRepo.deleteById(id);
        if (redis.opsForSet().isMember(FlowgateConstant.SERVICE_KEY_SET, adapter.getServiceKey())) {
            redis.opsForSet().remove(FlowgateConstant.SERVICE_KEY_SET, adapter.getServiceKey());
        }
    }
}
Also used : WormholeRequestException(com.vmware.flowgate.exception.WormholeRequestException) FacilityAdapter(com.vmware.flowgate.common.model.FacilityAdapter)

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