Search in sources :

Example 16 with FacilityAdapter

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

the class FacilityAdapterControllerTest method findAllFacilityAdapterExample.

@Test
public void findAllFacilityAdapterExample() throws JsonProcessingException, Exception {
    FacilityAdapter adapter = createAdapter();
    adapter.setDisplayName("displayNameForTestfindall");
    facilityAdapterRepo.save(adapter);
    FieldDescriptor[] fieldpath = new FieldDescriptor[] { 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") };
    this.mockMvc.perform(get("/v1/facilityadapter")).andExpect(status().isOk()).andExpect(jsonPath("$[0].displayName").value("displayNameForTestfindall")).andDo(document("facilityadapter-findAll-example", responseFields(fieldWithPath("[]").description("An array of facility adapters")).andWithPrefix("[].", fieldpath)));
    facilityAdapterRepo.deleteById(adapter.getId());
}
Also used : FacilityAdapter(com.vmware.flowgate.common.model.FacilityAdapter) FieldDescriptor(org.springframework.restdocs.payload.FieldDescriptor) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 17 with FacilityAdapter

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

the class FacilityAdapterControllerTest method findAllFacilityAdapterByPageExample.

@Test
public void findAllFacilityAdapterByPageExample() throws JsonProcessingException, Exception {
    FacilityAdapter adapter = createAdapter();
    adapter.setDisplayName("displayNameForTestfindallByPage");
    facilityAdapterRepo.save(adapter);
    this.mockMvc.perform(get("/v1/facilityadapter/pagenumber/{pageNumber}/pagesize/{pageSize}", 1, 5)).andExpect(status().isOk()).andExpect(jsonPath("$..content[0].displayName").value("displayNameForTestfindallByPage")).andDo(document("facilityadapter-findByPage-example", pathParameters(parameterWithName("pageNumber").description("The page you want to get"), parameterWithName("pageSize").description("The number of facilityadapters you want to get by every request.Default value: 20")), responseFields(subsectionWithPath("content").description("FacilityAdapter's array."), fieldWithPath("totalPages").description("content's total pages."), fieldWithPath("totalElements").description("content's total elements."), fieldWithPath("last").description("Is the last."), fieldWithPath("number").description("The page number."), fieldWithPath("size").description("The page size."), fieldWithPath("sort").description("The sort."), fieldWithPath("numberOfElements").description("The number of Elements."), fieldWithPath("first").description("Is the first."), subsectionWithPath("pageable").description("pageable.").ignored(), subsectionWithPath("sort").description("sorted.").ignored(), fieldWithPath("empty").description("Is empty.").ignored())));
    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 18 with FacilityAdapter

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

the class FacilityAdapterControllerTest method createAdapter.

FacilityAdapter createAdapter() {
    FacilityAdapter adapter = new FacilityAdapter();
    adapter.setId(UUID.randomUUID().toString());
    adapter.setDisplayName("defaultAdapter");
    adapter.setType(SoftwareType.OtherCMDB);
    adapter.setDescription("Default adapter for test");
    List<AdapterJobCommand> commands = new ArrayList<AdapterJobCommand>();
    AdapterJobCommand command = new AdapterJobCommand();
    command.setCommand("syncmetadata");
    command.setTriggerCycle(1440);
    command.setDescription("sync metadata job");
    commands.add(command);
    AdapterJobCommand metricsCommand = new AdapterJobCommand();
    metricsCommand.setCommand("syncmetricsdata");
    metricsCommand.setTriggerCycle(5);
    metricsCommand.setDescription("sync metrics data job");
    commands.add(metricsCommand);
    adapter.setCommands(commands);
    return adapter;
}
Also used : AdapterJobCommand(com.vmware.flowgate.common.model.AdapterJobCommand) ArrayList(java.util.ArrayList) FacilityAdapter(com.vmware.flowgate.common.model.FacilityAdapter)

Example 19 with FacilityAdapter

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

the class FacilityAdapterControllerTest method updateFacilityAdapterValidExistedExample.

@Test
public void updateFacilityAdapterValidExistedExample() throws JsonProcessingException, Exception {
    FacilityAdapter adapter = createAdapter();
    expectedEx.expect(WormholeRequestException.class);
    expectedEx.expectMessage("Failed to find FacilityAdapter with field: id  and value: " + adapter.getId() + "");
    MvcResult result = this.mockMvc.perform(put("/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 20 with FacilityAdapter

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

the class FacilityAdapterControllerTest method createFacilityAdapterValidDisplayName1.

@Test
public void createFacilityAdapterValidDisplayName1() throws JsonProcessingException, Exception {
    FacilityAdapter adapter = createAdapter();
    adapter.setDisplayName("testdisplayName");
    facilityAdapterRepo.save(adapter);
    FacilityAdapter adapter1 = createAdapter();
    adapter1.setDisplayName(adapter.getDisplayName());
    expectedEx.expect(WormholeRequestException.class);
    expectedEx.expectMessage("Adapter with dispalyName : testdisplayName is existed");
    MvcResult result = this.mockMvc.perform(post("/v1/facilityadapter").contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValueAsString(adapter1))).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)

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