Search in sources :

Example 46 with WithMockUhUser

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

the class TestGroupingsRestController method groupingAssignmentTest.

@Test
@WithMockUhUser(username = "iamtst01")
public void groupingAssignmentTest() throws Exception {
    GroupingAssignment groupings = mapGroupingAssignment();
    boolean inGrouping = false;
    for (Grouping grouping : groupings.getGroupingsIn()) {
        if (grouping.getPath().contains(this.GROUPING)) {
            inGrouping = true;
            break;
        }
    }
    assertTrue(inGrouping);
    boolean canOptin = false;
    for (Grouping grouping : groupings.getGroupingsToOptInTo()) {
        if (grouping.getPath().contains(this.GROUPING)) {
            canOptin = true;
            break;
        }
    }
    assertFalse(canOptin);
    boolean canOptOut = false;
    for (Grouping grouping : groupings.getGroupingsToOptOutOf()) {
        if (grouping.getPath().contains(this.GROUPING)) {
            canOptOut = true;
            break;
        }
    }
    assertTrue(canOptOut);
    boolean ownsGrouping = false;
    for (Grouping grouping : groupings.getGroupingsOwned()) {
        if (grouping.getPath().contains(this.GROUPING)) {
            ownsGrouping = true;
            break;
        }
    }
    assertTrue(ownsGrouping);
}
Also used : Grouping(edu.hawaii.its.api.type.Grouping) GroupingAssignment(edu.hawaii.its.api.type.GroupingAssignment) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) WithMockUhUser(edu.hawaii.its.groupings.controller.WithMockUhUser)

Example 47 with WithMockUhUser

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

the class TestGroupingsRestController method adminListsFailTest.

@Test
@WithMockUhUser(username = "iamtst01")
public void adminListsFailTest() throws Exception {
    AdminListsHolder infoFail = mapAdminListsHolder();
    assertEquals(infoFail.getAdminGroup().getMembers().size(), 0);
    assertEquals(infoFail.getAllGroupings().size(), 0);
}
Also used : AdminListsHolder(edu.hawaii.its.api.type.AdminListsHolder) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) WithMockUhUser(edu.hawaii.its.groupings.controller.WithMockUhUser)

Example 48 with WithMockUhUser

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

the class UserContextServiceTest method testOwner.

@Test
@WithMockUhUser(username = "Owner", roles = { "ROLE_OWNER" })
public void testOwner() {
    User user = userContextService.getCurrentUser();
    assertThat(user.hasRole(Role.ADMIN), equalTo(false));
    assertThat(user.hasRole(Role.OWNER), equalTo(true));
}
Also used : WithMockUhUser(edu.hawaii.its.groupings.controller.WithMockUhUser) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test) WithMockUhUser(edu.hawaii.its.groupings.controller.WithMockUhUser)

Example 49 with WithMockUhUser

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

the class UserContextServiceTest method basics.

@Test
@WithMockUhUser(username = "admin", roles = { "ROLE_ADMIN" })
public void basics() {
    assertThat(userContextService.getCurrentUhUuid(), equalTo("12345678"));
    assertThat(userContextService.getCurrentUid(), equalTo("admin"));
    assertThat(userContextService.toString(), startsWith("UserContextServiceImpl"));
    User user = userContextService.getCurrentUser();
    assertNotNull(user);
    assertThat(user.getUhUuid(), equalTo("12345678"));
    assertThat(user.getUid(), equalTo("admin"));
    userContextService.setCurrentUhUuid("87654321");
    assertThat(userContextService.getCurrentUhUuid(), equalTo("87654321"));
}
Also used : WithMockUhUser(edu.hawaii.its.groupings.controller.WithMockUhUser) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test) WithMockUhUser(edu.hawaii.its.groupings.controller.WithMockUhUser)

Example 50 with WithMockUhUser

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

the class GroupingsRestControllerTest method removeMembersFromIncludeGroupTest.

@Test
@WithMockUhUser
public void removeMembersFromIncludeGroupTest() throws Exception {
    String uri = REST_CONTROLLER_BASE + GROUPING + "/" + USERNAME + "/removeMembersFromIncludeGroup";
    given(httpRequestService.makeApiRequest(eq(USERNAME), anyString(), eq(HttpMethod.DELETE))).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.DELETE));
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) WithMockUhUser(edu.hawaii.its.groupings.controller.WithMockUhUser)

Aggregations

WithMockUhUser (edu.hawaii.its.groupings.controller.WithMockUhUser)69 Test (org.junit.Test)69 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)69 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)34 ResponseEntity (org.springframework.http.ResponseEntity)31 GroupingsServiceResult (edu.hawaii.its.api.type.GroupingsServiceResult)15 ArrayList (java.util.ArrayList)10 Grouping (edu.hawaii.its.api.type.Grouping)9 GroupingAssignment (edu.hawaii.its.api.type.GroupingAssignment)7 Principal (java.security.Principal)3 SimplePrincipal (org.jasig.cas.client.authentication.SimplePrincipal)3 AdminListsHolder (edu.hawaii.its.api.type.AdminListsHolder)2 Realm (edu.hawaii.its.groupings.configuration.Realm)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 HttpRequestService (edu.hawaii.its.api.service.HttpRequestService)1 Group (edu.hawaii.its.api.type.Group)1 GroupingsHTTPException (edu.hawaii.its.api.type.GroupingsHTTPException)1 ApiServerHandshakeException (edu.hawaii.its.groupings.exceptions.ApiServerHandshakeException)1 Field (java.lang.reflect.Field)1 HashMap (java.util.HashMap)1