Search in sources :

Example 1 with OpenManageAuth

use of com.vmware.flowgate.auth.OpenManageAuth in project flowgate by vmware.

the class FacilitySoftwareControllerTest method createOpenManageThrowNotFoundException.

@Test
public void createOpenManageThrowNotFoundException() throws JsonProcessingException, Exception {
    OpenManageAuth openmanageAuth = Mockito.mock(OpenManageAuth.class);
    Mockito.doThrow(new HttpClientErrorException(HttpStatus.NOT_FOUND, "Not Found")).when(openmanageAuth).auth(Mockito.any(FacilitySoftwareConfig.class));
    Mockito.doReturn(createuser()).when(tokenService).getCurrentUser(any());
    Mockito.doReturn(openmanageAuth).when(serverValidationService).createOpenManageAuth();
    expectedEx.expect(WormholeRequestException.class);
    expectedEx.expectMessage("Unknown Host.Please check your server IP.");
    FacilitySoftwareConfig facilitySoftware = createFacilitySoftware();
    facilitySoftware.setType(SoftwareType.OpenManage);
    facilitySoftware.setName("myOpenManage");
    MvcResult result = this.mockMvc.perform(post("/v1/facilitysoftware").contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValueAsString(facilitySoftware))).andExpect(status().is4xxClientError()).andReturn();
    if (result.getResolvedException() != null) {
        throw result.getResolvedException();
    } else {
        TestCase.fail();
    }
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) OpenManageAuth(com.vmware.flowgate.auth.OpenManageAuth) 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)

Example 2 with OpenManageAuth

use of com.vmware.flowgate.auth.OpenManageAuth in project flowgate by vmware.

the class FacilitySoftwareControllerTest method createOpenManageThrowAuthException.

@Test
public void createOpenManageThrowAuthException() throws JsonProcessingException, Exception {
    OpenManageAuth openmanageAuth = Mockito.mock(OpenManageAuth.class);
    Mockito.doReturn(false).when(openmanageAuth).auth(Mockito.any(FacilitySoftwareConfig.class));
    Mockito.doReturn(createuser()).when(tokenService).getCurrentUser(any());
    Mockito.doReturn(openmanageAuth).when(serverValidationService).createOpenManageAuth();
    expectedEx.expect(WormholeRequestException.class);
    expectedEx.expectMessage("Invalid user name or password");
    FacilitySoftwareConfig facilitySoftware = createFacilitySoftware();
    facilitySoftware.setType(SoftwareType.OpenManage);
    facilitySoftware.setName("myOpenManage");
    MvcResult result = this.mockMvc.perform(post("/v1/facilitysoftware").contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValueAsString(facilitySoftware))).andExpect(status().is4xxClientError()).andReturn();
    if (result.getResolvedException() != null) {
        throw result.getResolvedException();
    } else {
        TestCase.fail();
    }
}
Also used : OpenManageAuth(com.vmware.flowgate.auth.OpenManageAuth) 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

OpenManageAuth (com.vmware.flowgate.auth.OpenManageAuth)2 FacilitySoftwareConfig (com.vmware.flowgate.common.model.FacilitySoftwareConfig)2 Test (org.junit.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 MvcResult (org.springframework.test.web.servlet.MvcResult)2 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)1