Search in sources :

Example 1 with CourseStaffMember

use of fi.otavanopisto.pyramus.rest.model.CourseStaffMember in project muikku by otavanopisto.

the class PyramusMocksRest method mockWorkspaceUsers.

public static void mockWorkspaceUsers(List<String> payloads) throws JsonProcessingException {
    ObjectMapper objectMapper = new ObjectMapper().registerModule(new JSR310Module()).disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    Long courseId = 1l;
    Long teacherRoleId = 7l;
    CourseStaffMember courseStaffMember = new CourseStaffMember(1l, courseId, 4l, teacherRoleId);
    CourseStaffMember[] courseStaffMembers = { courseStaffMember };
    stubFor(get(urlEqualTo(String.format("/1/courses/courses/%d/staffMembers", courseId))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(courseStaffMembers)).withStatus(200)));
    stubFor(get(urlEqualTo(String.format("/1/courses/courses/%d/staffMembers/%d", courseId, courseStaffMember.getId()))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(courseStaffMember)).withStatus(200)));
    addPayload(payloads, objectMapper.writeValueAsString(new WebhookCourseStaffMemberCreatePayload(courseStaffMember.getId(), courseId, courseStaffMember.getStaffMemberId())));
    OffsetDateTime enrolmentTime = OffsetDateTime.of(1999, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC);
    CourseStudent courseStudent = new CourseStudent(2l, courseId, 1l, enrolmentTime, false, null, null, false, null, null);
    CourseStudent[] students = { courseStudent };
    stubFor(get(urlEqualTo(String.format("/1/courses/courses/%d/students", courseId))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(students)).withStatus(200)));
    stubFor(get(urlEqualTo(String.format("/1/courses/courses/%d/students/%d", courseId, courseStudent.getId()))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(courseStudent)).withStatus(200)));
    addPayload(payloads, objectMapper.writeValueAsString(new WebhookCourseStudentCreatePayload(courseStudent.getId(), courseId, courseStudent.getStudentId())));
}
Also used : WebhookCourseStudentCreatePayload(fi.otavanopisto.pyramus.webhooks.WebhookCourseStudentCreatePayload) OffsetDateTime(java.time.OffsetDateTime) CourseStaffMember(fi.otavanopisto.pyramus.rest.model.CourseStaffMember) CourseStudent(fi.otavanopisto.pyramus.rest.model.CourseStudent) JSR310Module(com.fasterxml.jackson.datatype.jsr310.JSR310Module) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) WebhookCourseStaffMemberCreatePayload(fi.otavanopisto.pyramus.webhooks.WebhookCourseStaffMemberCreatePayload)

Example 2 with CourseStaffMember

use of fi.otavanopisto.pyramus.rest.model.CourseStaffMember in project muikku by otavanopisto.

the class CourseTestsBase method courseTeacherVacationInfoTest.

@Test
@TestEnvironments(browsers = { TestEnvironments.Browser.CHROME, TestEnvironments.Browser.FIREFOX, TestEnvironments.Browser.INTERNET_EXPLORER, TestEnvironments.Browser.EDGE, TestEnvironments.Browser.SAFARI })
public void courseTeacherVacationInfoTest() throws Exception {
    MockStaffMember admin = new MockStaffMember(1l, 1l, "Admin", "User", UserRole.ADMINISTRATOR, "121212-1234", "admin@example.com", Sex.MALE);
    MockStudent student = new MockStudent(2l, 2l, "Student", "Tester", "student@example.com", 1l, OffsetDateTime.of(1990, 2, 2, 0, 0, 0, 0, ZoneOffset.UTC), "121212-1212", Sex.FEMALE, TestUtilities.toDate(2012, 1, 1), TestUtilities.getNextYear());
    Builder mockBuilder = mocker();
    long courseId = 1l;
    CourseStaffMember courseStaffMember = new CourseStaffMember(1l, courseId, admin.getId(), 7l);
    MockCourseStudent courseStudent = new MockCourseStudent(2l, courseId, student.getId());
    mockBuilder.addStudent(student).addStaffMember(admin).mockLogin(admin).build();
    login();
    Workspace workspace = createWorkspace("testcourse", "test course for testing", Long.toString(courseId), Boolean.TRUE);
    mockBuilder.addCourseStaffMember(courseId, courseStaffMember).addCourseStudent(courseId, courseStudent).build();
    try {
        navigate("/profile", true);
        waitForPresent(".profile-vacation-date");
        sendKeys(".profile-vacation-date input[name=\"profile-vacation-start\"]", "21.12.2010");
        sendKeys(".profile-vacation-date input[name=\"profile-vacation-end\"]", "21.12.2025");
        waitAndClick(".save-profile-fields");
        logout();
        mockBuilder.mockLogin(student);
        login();
        navigate(String.format("/workspace/%s", workspace.getUrlName()), true);
        waitForPresent(".workspace-teacher-info .vacation-period");
        assertNotTextIgnoreCase(".workspace-teacher-info .vacation-period", "Unavailable 21.12.2010 - 21.12.2025");
    } finally {
        WireMock.reset();
        deleteWorkspace(workspace.getId());
    }
}
Also used : Builder(fi.otavanopisto.muikku.mock.PyramusMock.Builder) CourseStaffMember(fi.otavanopisto.pyramus.rest.model.CourseStaffMember) MockStaffMember(fi.otavanopisto.muikku.mock.model.MockStaffMember) MockStudent(fi.otavanopisto.muikku.mock.model.MockStudent) MockCourseStudent(fi.otavanopisto.muikku.mock.model.MockCourseStudent) Workspace(fi.otavanopisto.muikku.atests.Workspace) Test(org.junit.Test) AbstractUITest(fi.otavanopisto.muikku.ui.AbstractUITest) TestEnvironments(fi.otavanopisto.muikku.TestEnvironments)

Example 3 with CourseStaffMember

use of fi.otavanopisto.pyramus.rest.model.CourseStaffMember in project muikku by otavanopisto.

the class CourseTestsBase method courseProgressWidgetsExistsTest.

@Test
public void courseProgressWidgetsExistsTest() throws Exception {
    MockStaffMember admin = new MockStaffMember(1l, 1l, "Admin", "User", UserRole.ADMINISTRATOR, "121212-1234", "admin@example.com", Sex.MALE);
    MockStudent student = new MockStudent(2l, 2l, "Student", "Tester", "student@example.com", 1l, OffsetDateTime.of(1990, 2, 2, 0, 0, 0, 0, ZoneOffset.UTC), "121212-1212", Sex.FEMALE, TestUtilities.toDate(2012, 1, 1), TestUtilities.getNextYear());
    Long courseId = 1l;
    Builder mockBuilder = mocker();
    mockBuilder.addStaffMember(admin).addStudent(student).mockLogin(admin).build();
    try {
        login();
        Workspace workspace = createWorkspace("testcourses", "test course for testing", String.valueOf(courseId), Boolean.TRUE);
        MockCourseStudent courseStudent = new MockCourseStudent(2l, courseId, student.getId());
        CourseStaffMember courseStaffMember = new CourseStaffMember(1l, courseId, admin.getId(), 7l);
        mockBuilder.addCourseStaffMember(courseId, courseStaffMember).addCourseStudent(courseId, courseStudent).build();
        WorkspaceFolder workspaceFolder1 = createWorkspaceFolder(workspace.getId(), null, Boolean.FALSE, 1, "Test Course material folder", "DEFAULT");
        WorkspaceHtmlMaterial htmlMaterial = createWorkspaceHtmlMaterial(workspace.getId(), workspaceFolder1.getId(), "Test", "text/html;editor=CKEditor", "<p><object type=\"application/vnd.muikku.field.text\"><param name=\"type\" value=\"application/json\" /><param name=\"content\" value=\"{&quot;name&quot;:&quot;muikku-field-nT0yyez23QwFXD3G0I8HzYeK&quot;,&quot;rightAnswers&quot;:[],&quot;columns&quot;:&quot;&quot;,&quot;hint&quot;:&quot;&quot;}\" /></object></p>", 1l, "EVALUATED");
        WorkspaceHtmlMaterial htmlMaterial2 = createWorkspaceHtmlMaterial(workspace.getId(), workspaceFolder1.getId(), "Test", "text/html;editor=CKEditor", "<p><object type=\"application/vnd.muikku.field.text\"><param name=\"type\" value=\"application/json\" /><param name=\"content\" value=\"{&quot;name&quot;:&quot;muikku-field-nT0yyez23QwFXD3G0I8HzYeK&quot;,&quot;rightAnswers&quot;:[],&quot;columns&quot;:&quot;&quot;,&quot;hint&quot;:&quot;&quot;}\" /></object></p>", 1l, "EXERCISE");
        logout();
        try {
            mockBuilder.mockLogin(student);
            login();
            navigate(String.format("/workspace/%s", workspace.getUrlName()), true);
            waitForElementToBePresent(By.className("workspace-title"));
            waitForPresent(".materials-progress-evaluated-status");
            boolean evaluatedExists = getWebDriver().findElements(By.cssSelector(".materials-progress-evaluated-status")).size() > 0;
            assertTrue(evaluatedExists);
            waitAndClick(".materials-progress-evaluated-status");
            waitForPresentAndVisible(".workspace-progress-element-menu-content.evaluable");
            assertPresent(".workspace-progress-element-menu-content.evaluable");
            waitForPresent(".materials-progress-practice-status");
            boolean practiceExists = getWebDriver().findElements(By.cssSelector(".materials-progress-practice-status")).size() > 0;
            assertTrue(practiceExists);
            waitAndClick(".materials-progress-practice-status");
            waitForPresentAndVisible(".workspace-progress-element-menu-content.exercise");
            assertPresent(".workspace-progress-element-menu-content.exercise");
        } finally {
            deleteWorkspaceHtmlMaterial(workspace.getId(), htmlMaterial2.getId());
            deleteWorkspaceHtmlMaterial(workspace.getId(), htmlMaterial.getId());
            deleteWorkspace(workspace.getId());
        }
    } finally {
        mockBuilder.wiremockReset();
    }
}
Also used : WorkspaceHtmlMaterial(fi.otavanopisto.muikku.atests.WorkspaceHtmlMaterial) Builder(fi.otavanopisto.muikku.mock.PyramusMock.Builder) CourseStaffMember(fi.otavanopisto.pyramus.rest.model.CourseStaffMember) MockStaffMember(fi.otavanopisto.muikku.mock.model.MockStaffMember) MockStudent(fi.otavanopisto.muikku.mock.model.MockStudent) MockCourseStudent(fi.otavanopisto.muikku.mock.model.MockCourseStudent) Workspace(fi.otavanopisto.muikku.atests.Workspace) WorkspaceFolder(fi.otavanopisto.muikku.atests.WorkspaceFolder) Test(org.junit.Test) AbstractUITest(fi.otavanopisto.muikku.ui.AbstractUITest)

Example 4 with CourseStaffMember

use of fi.otavanopisto.pyramus.rest.model.CourseStaffMember in project muikku by otavanopisto.

the class CourseTestsBase method courseProgressWidgetTest.

@Test
@TestEnvironments(browsers = { TestEnvironments.Browser.CHROME, TestEnvironments.Browser.FIREFOX, TestEnvironments.Browser.INTERNET_EXPLORER, TestEnvironments.Browser.EDGE, TestEnvironments.Browser.SAFARI })
public void courseProgressWidgetTest() throws Exception {
    MockStaffMember admin = new MockStaffMember(1l, 1l, "Admin", "User", UserRole.ADMINISTRATOR, "121212-1234", "admin@example.com", Sex.MALE);
    MockStudent student = new MockStudent(2l, 2l, "Student", "Tester", "student@example.com", 1l, OffsetDateTime.of(1990, 2, 2, 0, 0, 0, 0, ZoneOffset.UTC), "121212-1212", Sex.FEMALE, TestUtilities.toDate(2012, 1, 1), TestUtilities.getNextYear());
    Long courseId = 2l;
    Builder mockBuilder = mocker();
    mockBuilder.addStaffMember(admin).addStudent(student).mockLogin(admin).build();
    try {
        login();
        Workspace workspace = createWorkspace("testcourses", "test course for testing", String.valueOf(courseId), Boolean.TRUE);
        MockCourseStudent courseStudent = new MockCourseStudent(2l, courseId, student.getId());
        CourseStaffMember courseStaffMember = new CourseStaffMember(1l, courseId, admin.getId(), 7l);
        mockBuilder.addCourseStaffMember(courseId, courseStaffMember).addCourseStudent(courseId, courseStudent).build();
        WorkspaceFolder workspaceFolder1 = createWorkspaceFolder(workspace.getId(), null, Boolean.FALSE, 1, "Test Course material folder", "DEFAULT");
        WorkspaceHtmlMaterial htmlMaterial = createWorkspaceHtmlMaterial(workspace.getId(), workspaceFolder1.getId(), "Test", "text/html;editor=CKEditor", "<p><object type=\"application/vnd.muikku.field.text\"><param name=\"type\" value=\"application/json\" /><param name=\"content\" value=\"{&quot;name&quot;:&quot;muikku-field-nT0yyez23QwFXD3G0I8HzYeK&quot;,&quot;rightAnswers&quot;:[],&quot;columns&quot;:&quot;&quot;,&quot;hint&quot;:&quot;&quot;}\" /></object></p>", 1l, "EVALUATED");
        WorkspaceHtmlMaterial exerciseMaterial = createWorkspaceHtmlMaterial(workspace.getId(), workspaceFolder1.getId(), "Test", "text/html;editor=CKEditor", "<p><object type=\"application/vnd.muikku.field.text\"><param name=\"type\" value=\"application/json\" /><param name=\"content\" value=\"{&quot;name&quot;:&quot;muikku-field-nT0yyez23QwFXD3G0I8HzYeK&quot;,&quot;rightAnswers&quot;:[],&quot;columns&quot;:&quot;&quot;,&quot;hint&quot;:&quot;&quot;}\" /></object></p>", 1l, "EXERCISE");
        logout();
        try {
            mockBuilder.mockLogin(student);
            login();
            navigate(String.format("/workspace/%s/materials", workspace.getUrlName()), true);
            waitForPresent(".materials-progress-evaluated-status");
            boolean evaluatedExists = getWebDriver().findElements(By.cssSelector(".materials-progress-evaluated-status")).size() > 0;
            assertTrue(evaluatedExists);
            waitForPresent(".materials-progress-practice-status");
            boolean practiceExists = getWebDriver().findElements(By.cssSelector(".materials-progress-practice-status")).size() > 0;
            assertTrue(practiceExists);
            assertVisible(String.format("#page-%d .muikku-text-field", htmlMaterial.getId()));
            assertValue(String.format("#page-%d .muikku-text-field", htmlMaterial.getId()), "");
            assertClassNotPresent(String.format("#page-%d .muikku-text-field", htmlMaterial.getId()), "muikku-field-saved");
            sendKeys(String.format("#page-%d .muikku-text-field", htmlMaterial.getId()), "field value");
            waitClassPresent(String.format("#page-%d .muikku-text-field", htmlMaterial.getId()), "muikku-field-saved");
            waitAndClick(String.format("#page-%d .muikku-submit-assignment", htmlMaterial.getId()));
            waitForPresentAndVisible(".notification-queue-item-success");
            waitForElementToBeClickable(String.format("#page-%d .muikku-withdraw-assignment", htmlMaterial.getId()));
            waitForPresent(".materials-progress-evaluated-status");
            assertTextIgnoreCase(".materials-progress-evaluated-status span", "1/1");
            assertVisible(String.format("#page-%d .muikku-text-field", exerciseMaterial.getId()));
            assertValue(String.format("#page-%d .muikku-text-field", exerciseMaterial.getId()), "");
            assertClassNotPresent(String.format("#page-%d .muikku-text-field", exerciseMaterial.getId()), "muikku-field-saved");
            sendKeys(String.format("#page-%d .muikku-text-field", exerciseMaterial.getId()), "field value");
            waitClassPresent(String.format("#page-%d .muikku-text-field", exerciseMaterial.getId()), "muikku-field-saved");
            waitAndClick(String.format("#page-%d .muikku-assignment-button", exerciseMaterial.getId()));
            waitUntilAnimationIsDone(".materials-progress-practice-status .slice .bar");
            waitForPresent(".materials-progress-practice-status");
            assertTextIgnoreCase(".materials-progress-practice-status span", "1/1");
            waitAndClick(".materials-progress-evaluated-status.evaluable span");
            waitForPresentAndVisible(".workspace-progress-element-menu-content.evaluable");
            assertTextIgnoreCase("#evaluableMenu>div>div:nth-child(2)>span:first-child", "Tehtäviä palautettu");
            assertTextIgnoreCase("#evaluableMenu>div>div:nth-child(2)>span:last-child", "1");
            assertTextIgnoreCase("#evaluableMenu>div>div:nth-child(3)>span:first-child", "Tehtäviä yhteensä");
            assertTextIgnoreCase("#evaluableMenu>div>div:nth-child(3)>span:last-child", "1");
            assertTextIgnoreCase("#evaluableMenu>div>div:nth-child(4)>span:first-child", "Tehtäviä arvioimatta");
            assertTextIgnoreCase("#evaluableMenu>div>div:nth-child(4)>span:last-child", "1");
            waitAndClick(".materials-progress-practice-status.exercise span");
            waitForPresentAndVisible(".workspace-progress-element-menu-content.exercise");
            assertTextIgnoreCase("#exerciseMenu>div>div:nth-child(2)>span:first-child", "Tehtäviä tehty");
            assertTextIgnoreCase("#exerciseMenu>div>div:nth-child(2)>span:last-child", "1");
            assertTextIgnoreCase("#exerciseMenu>div>div:nth-child(3)>span:first-child", "Tehtäviä yhteensä");
            assertTextIgnoreCase("#exerciseMenu>div>div:nth-child(3)>span:last-child", "1");
        } finally {
            deleteWorkspaceHtmlMaterial(workspace.getId(), htmlMaterial.getId());
            deleteWorkspaceHtmlMaterial(workspace.getId(), exerciseMaterial.getId());
            deleteWorkspace(workspace.getId());
        }
    } finally {
        WireMock.reset();
    }
}
Also used : WorkspaceHtmlMaterial(fi.otavanopisto.muikku.atests.WorkspaceHtmlMaterial) Builder(fi.otavanopisto.muikku.mock.PyramusMock.Builder) CourseStaffMember(fi.otavanopisto.pyramus.rest.model.CourseStaffMember) MockStaffMember(fi.otavanopisto.muikku.mock.model.MockStaffMember) MockStudent(fi.otavanopisto.muikku.mock.model.MockStudent) MockCourseStudent(fi.otavanopisto.muikku.mock.model.MockCourseStudent) Workspace(fi.otavanopisto.muikku.atests.Workspace) WorkspaceFolder(fi.otavanopisto.muikku.atests.WorkspaceFolder) Test(org.junit.Test) AbstractUITest(fi.otavanopisto.muikku.ui.AbstractUITest) TestEnvironments(fi.otavanopisto.muikku.TestEnvironments)

Example 5 with CourseStaffMember

use of fi.otavanopisto.pyramus.rest.model.CourseStaffMember in project muikku by otavanopisto.

the class PyramusMocks method personsPyramusMocks.

public static void personsPyramusMocks() throws Exception {
    ObjectMapper objectMapper = new ObjectMapper().registerModule(new JSR310Module()).disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    Map<String, String> variables = null;
    List<String> tags = null;
    OffsetDateTime birthday = OffsetDateTime.of(1990, 2, 2, 0, 0, 0, 0, ZoneOffset.UTC);
    Person person = mockPerson(1l, birthday, "030545-3453", fi.otavanopisto.pyramus.rest.model.Sex.MALE, 1l);
    Student student = new Student((long) 1, (long) 1, "Test", "User", null, null, null, null, null, null, null, null, null, null, null, (long) 1, null, null, null, false, null, null, null, null, variables, tags, false);
    String studentJson = objectMapper.writeValueAsString(student);
    stubFor(get(urlEqualTo("/1/students/students/1")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(studentJson).withStatus(200)));
    Email email = new Email((long) 1, (long) 1, true, "testuser@example.com");
    Email[] emails = { email };
    String emailJson = objectMapper.writeValueAsString(emails);
    stubFor(get(urlEqualTo("/1/students/students/1/emails")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(emailJson).withStatus(200)));
    Student[] studentArray = { student };
    String studentArrayJson = objectMapper.writeValueAsString(studentArray);
    stubFor(get(urlEqualTo("/1/students/students?email=testuser@example.com")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(studentArrayJson).withStatus(200)));
    /* Student #2 for workspace #2*/
    OffsetDateTime birthday2 = OffsetDateTime.of(1992, 2, 2, 0, 0, 0, 0, ZoneOffset.UTC);
    Person person2 = mockPerson(5l, birthday2, "021092-2112", fi.otavanopisto.pyramus.rest.model.Sex.MALE, 5l);
    Student student2 = new Student((long) 5, (long) 5, "Second", "User", null, null, null, null, null, null, null, null, null, null, null, (long) 1, null, null, null, false, null, null, null, null, variables, tags, false);
    String student2Json = objectMapper.writeValueAsString(student2);
    stubFor(get(urlEqualTo("/1/students/students/5")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(student2Json).withStatus(200)));
    Email email2 = new Email((long) 5, (long) 1, true, "seconduser@example.com");
    Email[] emails2 = { email2 };
    String email2Json = objectMapper.writeValueAsString(emails2);
    stubFor(get(urlEqualTo("/1/students/students/5/emails")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(email2Json).withStatus(200)));
    Student[] student2Array = { student2 };
    String student2ArrayJson = objectMapper.writeValueAsString(student2Array);
    stubFor(get(urlEqualTo("/1/students/students?email=seconduser@example.com")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(student2ArrayJson).withStatus(200)));
    /* Student #2 for workspace #2 */
    Person staff1 = mockPerson(2l, birthday, "030545-3454", fi.otavanopisto.pyramus.rest.model.Sex.MALE, 2l);
    Person staff2 = mockPerson(3l, birthday, "030545-3455", fi.otavanopisto.pyramus.rest.model.Sex.MALE, 3l);
    Person staff3 = mockPerson(4l, birthday, "030545-3456", fi.otavanopisto.pyramus.rest.model.Sex.MALE, 4l);
    Person[] personArray = { person, person2, staff1, staff2, staff3 };
    String personArrayJson = objectMapper.writeValueAsString(personArray);
    stubFor(get(urlMatching("/1/persons/persons?filterArchived=.*")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(personArrayJson).withStatus(200)));
    stubFor(get(urlEqualTo("/1/persons/persons")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(personArrayJson).withStatus(200)));
    Student[] students = { student, student2 };
    student2ArrayJson = objectMapper.writeValueAsString(students);
    stubFor(get(urlMatching("/1/students/students?filterArchived=false&firstResult=.*&maxResults=.*")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(studentArrayJson).withStatus(200)));
    StaffMember staffMember1 = new StaffMember((long) 2, (long) 2, null, "Test", "Staff1member", null, fi.otavanopisto.pyramus.rest.model.UserRole.MANAGER, tags, variables);
    String staffMemberJson = objectMapper.writeValueAsString(staffMember1);
    stubFor(get(urlEqualTo("/1/staff/members/2")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(staffMemberJson).withStatus(200)));
    StaffMember[] staffMemberArray = { staffMember1 };
    String staffMemberArrayJson = objectMapper.writeValueAsString(staffMemberArray);
    stubFor(get(urlEqualTo("/1/staff/members?email=teacher@example.com")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(staffMemberArrayJson).withStatus(200)));
    StaffMember staffMember2 = new StaffMember((long) 3, (long) 3, null, "Test", "Staff2member", null, fi.otavanopisto.pyramus.rest.model.UserRole.MANAGER, tags, variables);
    staffMemberJson = objectMapper.writeValueAsString(staffMember2);
    stubFor(get(urlEqualTo("/1/staff/members/3")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(staffMemberJson).withStatus(200)));
    StaffMember[] staffMember2Array = { staffMember2 };
    staffMemberArrayJson = objectMapper.writeValueAsString(staffMember2Array);
    stubFor(get(urlEqualTo("/1/staff/members?email=mana@example.com")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(staffMemberArrayJson).withStatus(200)));
    StaffMember staffMember3 = new StaffMember((long) 4, (long) 4, null, "Test", "Administrator", null, fi.otavanopisto.pyramus.rest.model.UserRole.ADMINISTRATOR, tags, variables);
    staffMemberJson = objectMapper.writeValueAsString(staffMember3);
    stubFor(get(urlEqualTo("/1/staff/members/4")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(staffMemberJson).withStatus(200)));
    StaffMember[] staffMember3Array = { staffMember3 };
    staffMemberArrayJson = objectMapper.writeValueAsString(staffMember3Array);
    stubFor(get(urlEqualTo("/1/staff/members?email=admin@example.com")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(staffMemberArrayJson).withStatus(200)));
    StaffMember[] staffArray = { staffMember1, staffMember2, staffMember3 };
    String staffArrayJson = objectMapper.writeValueAsString(staffArray);
    stubFor(get(urlEqualTo("/1/staff/members")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(staffArrayJson).withStatus(200)));
    stubFor(get(urlEqualTo("1/courses/courses/1/staffMembers")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(staffArrayJson).withStatus(200)));
    staffMemberJson = objectMapper.writeValueAsString(staffMember1);
    stubFor(get(urlEqualTo("1/courses/courses/1/staffMembers/2")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(staffMemberJson).withStatus(200)));
    staffMemberJson = objectMapper.writeValueAsString(staffMember2);
    stubFor(get(urlEqualTo("1/courses/courses/1/staffMembers/3")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(staffMemberJson).withStatus(200)));
    staffMemberJson = objectMapper.writeValueAsString(staffMember3);
    stubFor(get(urlEqualTo("1/courses/courses/1/staffMembers/4")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(staffMemberJson).withStatus(200)));
    Email staff1Email = new Email((long) 2, (long) 1, true, "teacher@example.com");
    Email[] staff1Emails = { staff1Email };
    String staff1EmailJson = objectMapper.writeValueAsString(staff1Emails);
    stubFor(get(urlEqualTo("/1/staff/members/2/emails")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(staff1EmailJson).withStatus(200)));
    Email staff2Email = new Email((long) 3, (long) 1, true, "mana@example.com");
    Email[] staff2Emails = { staff2Email };
    String staff2EmailJson = objectMapper.writeValueAsString(staff2Emails);
    stubFor(get(urlEqualTo("/1/staff/members/3/emails")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(staff2EmailJson).withStatus(200)));
    Email staff3Email = new Email((long) 4, (long) 1, true, "admin@example.com");
    Email[] staff3Emails = { staff3Email };
    String staff3EmailJson = objectMapper.writeValueAsString(staff3Emails);
    stubFor(get(urlEqualTo("/1/staff/members/4/emails")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(staff3EmailJson).withStatus(200)));
    CourseStaffMemberRole teacherRole = new CourseStaffMemberRole((long) 8, "Opettaja");
    CourseStaffMemberRole[] cRoleArray = { teacherRole };
    String cRoleJson = objectMapper.writeValueAsString(cRoleArray);
    stubFor(get(urlEqualTo("/1/courses/staffMemberRoles")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(cRoleJson).withStatus(200)));
    for (CourseStaffMemberRole role : cRoleArray) {
        stubFor(get(urlEqualTo(String.format("/1/courses/staffMemberRoles/%d", role.getId()))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(role)).withStatus(200)));
    }
    CourseStaffMember staffMember = new CourseStaffMember(1l, 1l, 4l, 1l);
    CourseStaffMember[] staffMembers = { staffMember };
    stubFor(get(urlEqualTo(String.format("/1/courses/courses/%d/staffMembers", 1l))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(staffMembers)).withStatus(200)));
    stubFor(get(urlEqualTo(String.format("/1/courses/courses/%d/staffMembers/%d", 1l, staffMember.getId()))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(staffMember)).withStatus(200)));
    stubFor(get(urlEqualTo(String.format("/1/courses/courses/%d/staffMembers", 2l))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(staffMembers)).withStatus(200)));
    stubFor(get(urlEqualTo(String.format("/1/courses/courses/%d/staffMembers/%d", 2l, staffMember.getId()))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(staffMember)).withStatus(200)));
    stubFor(get(urlMatching("/1/courses/courses/1/students?filterArchived=.*")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(studentArrayJson).withStatus(200)));
    mockContactTypes();
    mockStudyProgrammes();
    CourseStudent courseStudent = new CourseStudent(3l, 1l, 1l, OffsetDateTime.of(2010, 2, 2, 0, 0, 0, 0, ZoneOffset.UTC), false, null, null, null, null, null);
    CourseStudent[] csArray = { courseStudent };
    String coursestudentArrayJson = objectMapper.writeValueAsString(csArray);
    String courseStudenJson = objectMapper.writeValueAsString(courseStudent);
    stubFor(get(urlMatching(String.format("/1/courses/courses/%d/students?filterArchived=.*", courseStudent.getCourseId()))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(coursestudentArrayJson).withStatus(200)));
    stubFor(get(urlMatching("/1/courses/courses/1/students")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(coursestudentArrayJson).withStatus(200)));
    stubFor(get(urlMatching(String.format("/1/courses/courses/%d/students/%d", courseStudent.getCourseId(), courseStudent.getId()))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(courseStudenJson).withStatus(200)));
    OffsetDateTime assessmentCreated = OffsetDateTime.of(2015, 2, 2, 0, 0, 0, 0, ZoneOffset.UTC);
    CourseAssessment courseAssessment = new CourseAssessment(1l, courseStudent.getId(), 1l, 1l, 4l, assessmentCreated, "Test evaluation.", Boolean.TRUE);
    stubFor(post(urlMatching(String.format("/1/students/students/%d/courses/%d/assessments/", student.getId(), courseStudent.getCourseId()))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(courseAssessment)).withStatus(200)));
    stubFor(get(urlMatching(String.format("/1/students/students/%d/courses/%d/assessments/", student.getId(), courseStudent.getCourseId()))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(new ArrayList<>())).withStatus(200)));
    CourseStudent courseStudent2 = new CourseStudent(2l, 2l, 5l, OffsetDateTime.of(2010, 2, 2, 0, 0, 0, 0, ZoneOffset.UTC), false, null, null, null, null, null);
    CourseStudent[] csArray2 = { courseStudent2 };
    String coursestudentArrayJson2 = objectMapper.writeValueAsString(csArray2);
    String courseStudenJson2 = objectMapper.writeValueAsString(courseStudent2);
    stubFor(get(urlMatching(String.format("/1/courses/courses/%d/students?filterArchived=.*", courseStudent2.getCourseId()))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(coursestudentArrayJson2).withStatus(200)));
    stubFor(get(urlMatching("/1/courses/courses/2/students")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(coursestudentArrayJson2).withStatus(200)));
    stubFor(get(urlMatching(String.format("/1/courses/courses/%d/students/%d", courseStudent2.getCourseId(), courseStudent2.getId()))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(courseStudenJson2).withStatus(200)));
    CourseAssessment courseAssessment2 = new CourseAssessment(1l, courseStudent.getId(), 1l, 1l, 4l, assessmentCreated, "", Boolean.TRUE);
    stubFor(get(urlMatching(String.format("/1/students/students/%d/courses/%d/assessments/", student2.getId(), courseStudent2.getCourseId()))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(courseAssessment2)).withStatus(200)));
    CourseStaffMember courseStaffMember = new CourseStaffMember(1l, 1l, 4l, 7l);
    CourseStaffMember[] coursestaffMembers = { courseStaffMember };
    stubFor(get(urlEqualTo(String.format("/1/courses/courses/%d/staffMembers", 1l))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(coursestaffMembers)).withStatus(200)));
    stubFor(get(urlEqualTo(String.format("/1/courses/courses/%d/staffMembers/%d", 1l, staffMember.getId()))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(courseStaffMember)).withStatus(200)));
    mockPersonStudens(new Student[] { student, student2 });
    mockPersonStaffMembers(new StaffMember[] { staffMember1, staffMember2, staffMember3 });
    String payload = objectMapper.writeValueAsString(new WebhookStudentCreatePayload((long) 5));
    TestUtilities.webhookCall("http://dev.muikku.fi:" + System.getProperty("it.port.http") + "/pyramus/webhook", payload);
    payload = objectMapper.writeValueAsString(new WebhookPersonCreatePayload((long) 5));
    TestUtilities.webhookCall("http://dev.muikku.fi:" + System.getProperty("it.port.http") + "/pyramus/webhook", payload);
    payload = objectMapper.writeValueAsString(new WebhookStudentCreatePayload((long) 1));
    TestUtilities.webhookCall("http://dev.muikku.fi:" + System.getProperty("it.port.http") + "/pyramus/webhook", payload);
    payload = objectMapper.writeValueAsString(new WebhookPersonCreatePayload((long) 1));
    TestUtilities.webhookCall("http://dev.muikku.fi:" + System.getProperty("it.port.http") + "/pyramus/webhook", payload);
    payload = objectMapper.writeValueAsString(new WebhookStaffMemberCreatePayload((long) 4));
    TestUtilities.webhookCall("http://dev.muikku.fi:" + System.getProperty("it.port.http") + "/pyramus/webhook", payload);
    payload = objectMapper.writeValueAsString(new WebhookPersonCreatePayload((long) 4));
    TestUtilities.webhookCall("http://dev.muikku.fi:" + System.getProperty("it.port.http") + "/pyramus/webhook", payload);
    payload = objectMapper.writeValueAsString(new WebhookCourseStudentCreatePayload(courseStudent.getId(), courseStudent.getCourseId(), courseStudent.getStudentId()));
    TestUtilities.webhookCall("http://dev.muikku.fi:" + System.getProperty("it.port.http") + "/pyramus/webhook", payload);
    payload = objectMapper.writeValueAsString(new WebhookCourseStudentCreatePayload(courseStudent2.getId(), courseStudent2.getCourseId(), courseStudent2.getStudentId()));
    TestUtilities.webhookCall("http://dev.muikku.fi:" + System.getProperty("it.port.http") + "/pyramus/webhook", payload);
    payload = objectMapper.writeValueAsString(new WebhookCourseStaffMemberCreatePayload(1l, 1l, 4l));
    TestUtilities.webhookCall("http://dev.muikku.fi:" + System.getProperty("it.port.http") + "/pyramus/webhook", payload);
}
Also used : CourseStaffMemberRole(fi.otavanopisto.pyramus.rest.model.CourseStaffMemberRole) Email(fi.otavanopisto.pyramus.rest.model.Email) JSR310Module(com.fasterxml.jackson.datatype.jsr310.JSR310Module) CourseStaffMember(fi.otavanopisto.pyramus.rest.model.CourseStaffMember) StaffMember(fi.otavanopisto.pyramus.rest.model.StaffMember) WebhookStudentCreatePayload(fi.otavanopisto.pyramus.webhooks.WebhookStudentCreatePayload) WebhookCourseStudentCreatePayload(fi.otavanopisto.pyramus.webhooks.WebhookCourseStudentCreatePayload) MockCourseStudent(fi.otavanopisto.muikku.mock.model.MockCourseStudent) CourseStudent(fi.otavanopisto.pyramus.rest.model.CourseStudent) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) WebhookPersonCreatePayload(fi.otavanopisto.pyramus.webhooks.WebhookPersonCreatePayload) Student(fi.otavanopisto.pyramus.rest.model.Student) MockCourseStudent(fi.otavanopisto.muikku.mock.model.MockCourseStudent) CourseStudent(fi.otavanopisto.pyramus.rest.model.CourseStudent) CourseAssessment(fi.otavanopisto.pyramus.rest.model.CourseAssessment) WebhookCourseStaffMemberCreatePayload(fi.otavanopisto.pyramus.webhooks.WebhookCourseStaffMemberCreatePayload) OffsetDateTime(java.time.OffsetDateTime) CourseStaffMember(fi.otavanopisto.pyramus.rest.model.CourseStaffMember) Person(fi.otavanopisto.pyramus.rest.model.Person) WebhookStaffMemberCreatePayload(fi.otavanopisto.pyramus.webhooks.WebhookStaffMemberCreatePayload)

Aggregations

CourseStaffMember (fi.otavanopisto.pyramus.rest.model.CourseStaffMember)22 MockCourseStudent (fi.otavanopisto.muikku.mock.model.MockCourseStudent)19 Workspace (fi.otavanopisto.muikku.atests.Workspace)18 Builder (fi.otavanopisto.muikku.mock.PyramusMock.Builder)18 MockStaffMember (fi.otavanopisto.muikku.mock.model.MockStaffMember)18 MockStudent (fi.otavanopisto.muikku.mock.model.MockStudent)18 AbstractUITest (fi.otavanopisto.muikku.ui.AbstractUITest)18 Test (org.junit.Test)18 TestEnvironments (fi.otavanopisto.muikku.TestEnvironments)13 WorkspaceFolder (fi.otavanopisto.muikku.atests.WorkspaceFolder)10 WorkspaceHtmlMaterial (fi.otavanopisto.muikku.atests.WorkspaceHtmlMaterial)10 OffsetDateTime (java.time.OffsetDateTime)10 MockCourse (fi.otavanopisto.muikku.mock.model.MockCourse)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 JSR310Module (com.fasterxml.jackson.datatype.jsr310.JSR310Module)5 RoleSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.RoleSchoolDataIdentifier)2 UserSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)2 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)2 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)2 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)2