Search in sources :

Example 1 with HttpRequestService

use of edu.hawaii.its.api.service.HttpRequestService in project uhgroupings by uhawaii-system-its-ti-iam.

the class GroupingsRestControllerTest method doGrouperHandshake.

@Test
@WithMockUhUser
public void doGrouperHandshake() {
    GroupingsRestController controller = applicationContext.getBean(GroupingsRestController.class);
    assertFalse(controller.shouldDoApiHandshake());
    try {
        controller.doApiHandshake();
    } catch (Exception e) {
        fail("Should not reach here.");
    }
    Realm realm = controller.getRealm();
    Realm realmMock = mock(Realm.class);
    // Swap in mock.
    controller.setRealm(realmMock);
    assertTrue(mockingDetails(controller.getRealm()).isMock());
    given(realmMock.isAnyProfileActive("default", "localTest")).willReturn(false);
    try {
        controller.doApiHandshake();
        fail("Should not reach here.");
    } catch (Exception e) {
        assertThat(e, instanceOf(ApiServerHandshakeException.class));
    }
    // Cause in an internal exception.
    HttpRequestService httpRequestServiceOriginal = controller.getHttpRequestService();
    controller.setHttpRequestService(null);
    try {
        controller.doApiHandshake();
        fail("Should not reach here.");
    } catch (Exception e) {
        assertThat(e, instanceOf(ApiServerHandshakeException.class));
    }
    // Put stuff back.
    controller.setHttpRequestService(httpRequestServiceOriginal);
    controller.setRealm(realm);
    assertFalse(mockingDetails(controller.getRealm()).isMock());
}
Also used : HttpRequestService(edu.hawaii.its.api.service.HttpRequestService) Realm(edu.hawaii.its.groupings.configuration.Realm) ApiServerHandshakeException(edu.hawaii.its.groupings.exceptions.ApiServerHandshakeException) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) WithMockUhUser(edu.hawaii.its.groupings.controller.WithMockUhUser)

Aggregations

HttpRequestService (edu.hawaii.its.api.service.HttpRequestService)1 Realm (edu.hawaii.its.groupings.configuration.Realm)1 WithMockUhUser (edu.hawaii.its.groupings.controller.WithMockUhUser)1 ApiServerHandshakeException (edu.hawaii.its.groupings.exceptions.ApiServerHandshakeException)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1