Search in sources :

Example 1 with Realm

use of edu.hawaii.its.groupings.configuration.Realm in project uhgroupings by uhawaii-system-its-ti-iam.

the class GroupingsRestControllerTest method shouldDoGrouperHandshake.

@Test
@WithMockUhUser
public void shouldDoGrouperHandshake() throws Exception {
    GroupingsRestController controller = applicationContext.getBean(GroupingsRestController.class);
    Realm realm = controller.getRealm();
    assertFalse(realm.isAnyProfileActive("default"));
    assertTrue(realm.isAnyProfileActive("localTest"));
    // What we are testing.
    assertFalse(controller.shouldDoApiHandshake());
    Realm realmMock = mock(Realm.class);
    // Swap in mock.
    controller.setRealm(realmMock);
    assertTrue(mockingDetails(controller.getRealm()).isMock());
    given(realmMock.isAnyProfileActive("default", "localTest")).willReturn(false);
    // What we are testing.
    assertTrue(controller.shouldDoApiHandshake());
    // Mock real realm back.
    controller.setRealm(realm);
    assertFalse(mockingDetails(controller.getRealm()).isMock());
    // Let's cheat a little to get at some private fields.
    Class<?> c0 = controller.getClass();
    Field field0 = c0.getDeclaredField("API_HANDSHAKE_ENABLED");
    field0.setAccessible(true);
    Boolean existingValue = (Boolean) field0.get(controller);
    assertTrue(existingValue);
    field0.set(controller, Boolean.FALSE);
    // What we are testing.
    assertFalse(controller.shouldDoApiHandshake());
    // Put property value back.
    field0.set(controller, Boolean.TRUE);
}
Also used : Field(java.lang.reflect.Field) Realm(edu.hawaii.its.groupings.configuration.Realm) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) WithMockUhUser(edu.hawaii.its.groupings.controller.WithMockUhUser)

Example 2 with Realm

use of edu.hawaii.its.groupings.configuration.Realm 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

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