Search in sources :

Example 41 with WithMockUhUser

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

the class TestGroupingsRestController method adminListsPassTest.

@Test
@WithMockUhUser(username = "_groupings_api_2")
public void adminListsPassTest() throws Exception {
    AdminListsHolder infoSuccess = mapAdminListsHolder();
    // STUDENT_TEST_USERNAME can be replaced with any account that has admin access
    assertTrue(infoSuccess.getAdminGroup().getUsernames().contains(STUDENT_TEST_USERNAME));
}
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 42 with WithMockUhUser

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

the class TestGroupingsRestController method assignAndRemoveOwnershipTest.

@Test
@WithMockUhUser(username = "iamtst01")
public void assignAndRemoveOwnershipTest() throws Exception {
    Grouping g = mapGrouping(GROUPING);
    assertFalse(g.getOwners().getUsernames().contains(tst[1]));
    mapGSR("/api/groupings/" + GROUPING + "/" + tst[1] + "/assignOwnership");
    g = mapGrouping(GROUPING);
    assertTrue(g.getOwners().getUsernames().contains(tst[1]));
    mapGSR("/api/groupings/" + GROUPING + "/" + tst[1] + "/removeOwnership");
    g = mapGrouping(GROUPING);
    assertFalse(g.getOwners().getUsernames().contains(tst[1]));
}
Also used : Grouping(edu.hawaii.its.api.type.Grouping) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) WithMockUhUser(edu.hawaii.its.groupings.controller.WithMockUhUser)

Example 43 with WithMockUhUser

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

the class TestGroupingsRestController method myGroupingsTest3.

@Test
@WithMockUhUser(username = "iamtst04")
public void myGroupingsTest3() throws Exception {
    boolean optedIn = false;
    GroupingAssignment tst4Groupings = mapGroupingAssignment();
    assertEquals(tst4Groupings.getGroupingsOptedInTo().size(), 0);
    mapGSRs("/api/groupings/" + GROUPING + "/optIn");
    tst4Groupings = mapGroupingAssignment();
    for (Grouping grouping : tst4Groupings.getGroupingsOptedInTo()) {
        if (grouping.getPath().contains(GROUPING)) {
            optedIn = true;
        }
    }
    // in basis
    assertFalse(optedIn);
}
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 44 with WithMockUhUser

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

the class TestGroupingsRestController method myGroupingsTest2.

@Test
@WithMockUhUser(username = "iamtst04")
public void myGroupingsTest2() throws Exception {
    GroupingAssignment groupings = mapGroupingAssignment();
    boolean inGrouping = false;
    for (Grouping grouping : groupings.getGroupingsIn()) {
        if (grouping.getPath().contains(this.GROUPING)) {
            inGrouping = true;
            break;
        }
    }
    assertFalse(inGrouping);
    boolean ownsGrouping = false;
    for (Grouping grouping : groupings.getGroupingsOwned()) {
        if (grouping.getPath().contains(this.GROUPING)) {
            ownsGrouping = true;
            break;
        }
    }
    assertFalse(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 45 with WithMockUhUser

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

the class TestGroupingsRestController method aaronTest.

@Test
@WithMockUhUser(username = "aaronvil")
public void aaronTest() throws Exception {
    // This test often fails because the test server is very slow.
    // Because the server caches some results and gets quicker the more times
    // it is run, we let it run a few times if it starts failing
    int i = 0;
    while (i < 5) {
        try {
            GroupingAssignment aaronsGroupings = mapGroupingAssignment();
            assertNotNull(aaronsGroupings);
            break;
        } catch (AssertionError ae) {
            i++;
        }
    }
    assertTrue(i < 5);
}
Also used : 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)

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