use of edu.hawaii.its.groupings.controller.WithMockUhUser 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());
}
use of edu.hawaii.its.groupings.controller.WithMockUhUser in project uhgroupings by uhawaii-system-its-ti-iam.
the class GroupingsRestControllerTest method optOutTest.
@Test
@WithMockUhUser
public void optOutTest() throws Exception {
String uri = REST_CONTROLLER_BASE + GROUPING + "/optOut";
given(httpRequestService.makeApiRequest(eq(USERNAME), anyString(), eq(HttpMethod.PUT))).willReturn(new ResponseEntity(HttpStatus.OK));
assertNotNull(mockMvc.perform(post(uri).with(csrf())).andExpect(status().isOk()).andReturn());
verify(httpRequestService, times(1)).makeApiRequest(eq(USERNAME), anyString(), eq(HttpMethod.PUT));
}
use of edu.hawaii.its.groupings.controller.WithMockUhUser in project uhgroupings by uhawaii-system-its-ti-iam.
the class GroupingsRestControllerTest method addMembersToExcludeGroupTest.
@Test
@WithMockUhUser
public void addMembersToExcludeGroupTest() throws Exception {
String uri = REST_CONTROLLER_BASE + GROUPING + "/" + USERNAME + "/addMembersToExcludeGroup";
given(httpRequestService.makeApiRequest(eq(USERNAME), anyString(), eq(HttpMethod.PUT))).willReturn(new ResponseEntity(HttpStatus.OK));
assertNotNull(mockMvc.perform(post(uri).with(csrf())).andExpect(status().isOk()).andReturn());
verify(httpRequestService, times(1)).makeApiRequest(eq(USERNAME), anyString(), eq(HttpMethod.PUT));
}
use of edu.hawaii.its.groupings.controller.WithMockUhUser in project uhgroupings by uhawaii-system-its-ti-iam.
the class GroupingsRestControllerTest method setOptInFalseTest.
@Test
@WithMockUhUser
public void setOptInFalseTest() throws Exception {
String uri_false = REST_CONTROLLER_BASE + GROUPING + "/false/setOptIn";
given(httpRequestService.makeApiRequest(eq(USERNAME), anyString(), eq(HttpMethod.PUT))).willReturn(new ResponseEntity(HttpStatus.OK));
assertNotNull(mockMvc.perform(post(uri_false).with(csrf())).andExpect(status().isOk()).andReturn());
verify(httpRequestService, times(1)).makeApiRequest(eq(USERNAME), anyString(), eq(HttpMethod.PUT));
}
use of edu.hawaii.its.groupings.controller.WithMockUhUser in project uhgroupings by uhawaii-system-its-ti-iam.
the class GroupingsRestControllerTest method groupingsOwnedUidTest.
@Test
@WithMockUhUser
public void groupingsOwnedUidTest() throws Exception {
String uri = REST_CONTROLLER_BASE + "owners/" + USERNAME + "/groupings";
given(httpRequestService.makeApiRequest(eq(USERNAME), anyString(), eq(HttpMethod.GET))).willReturn(new ResponseEntity(HttpStatus.OK));
assertNotNull(mockMvc.perform(get(uri)).andExpect(status().isOk()).andReturn());
verify(httpRequestService, times(1)).makeApiRequest(eq(USERNAME), anyString(), eq(HttpMethod.GET));
}
Aggregations