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);
}
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());
}
Aggregations