Search in sources :

Example 46 with JSR310Module

use of com.fasterxml.jackson.datatype.jsr310.JSR310Module in project muikku by otavanopisto.

the class CourseManagementTestsBase method changeAdditionalInfoTest.

@Test
@TestEnvironments(browsers = { TestEnvironments.Browser.CHROME, TestEnvironments.Browser.FIREFOX, TestEnvironments.Browser.INTERNET_EXPLORER, TestEnvironments.Browser.EDGE, TestEnvironments.Browser.PHANTOMJS })
public void changeAdditionalInfoTest() throws Exception {
    MockStaffMember admin = new MockStaffMember(1l, 1l, "Admin", "User", UserRole.ADMINISTRATOR, "121212-1234", "admin@example.com", Sex.MALE);
    Builder mockBuilder = mocker();
    try {
        mockBuilder.addStaffMember(admin).mockLogin(admin).build();
        login();
        long courseId = 1l;
        Workspace workspace = createWorkspace("testcourse", "test course for testing", String.valueOf(courseId), Boolean.TRUE);
        try {
            navigate(String.format("/workspace/%s/workspace-management", workspace.getUrlName()), true);
            scrollIntoView(".additionalinfo-data input[name=\"workspaceNameExtension\"]");
            waitAndClick(".additionalinfo-data input[name=\"workspaceNameExtension\"]");
            clearElement(".additionalinfo-data input[name=\"workspaceNameExtension\"]");
            sendKeys(".additionalinfo-data input[name=\"workspaceNameExtension\"]", "For Test");
            waitAndClick(".workspace-management-footer .workspace-management-footer-actions-container button.save");
            waitForNotVisible(".loading");
            ObjectMapper objectMapper = new ObjectMapper().registerModule(new JSR310Module()).disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS).setSerializationInclusion(Include.NON_NULL);
            OffsetDateTime created = OffsetDateTime.of(1990, 2, 2, 0, 0, 0, 0, ZoneOffset.UTC);
            OffsetDateTime begin = OffsetDateTime.of(2000, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC);
            OffsetDateTime end = OffsetDateTime.of(2050, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC);
            Course course = new Course(courseId, "testcourse", created, created, "<p>test course for testing</p>\n", false, 1, (long) 25, begin, end, "For Test", (double) 15, (double) 45, (double) 45, (double) 15, (double) 45, (double) 45, end, (long) 1, (long) 1, (long) 1, null, (double) 45, (long) 1, (long) 1, (long) 1, (long) 1, null, null);
            String courseJson = objectMapper.writeValueAsString(course);
            stubFor(put(urlEqualTo(String.format("/1/courses/courses/%d", courseId))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(courseJson).withStatus(200)));
            stubFor(get(urlEqualTo(String.format("/1/courses/courses/%d", courseId))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(courseJson).withStatus(200)));
            String payload = objectMapper.writeValueAsString(new WebhookCourseCreatePayload(course.getId()));
            TestUtilities.webhookCall("http://dev.muikku.fi:" + System.getProperty("it.port.http") + "/pyramus/webhook", payload);
            navigate(String.format("/workspace/%s", workspace.getUrlName()), true);
            waitForPresent(".workspace-header-wrapper .workspace-additional-info-wrapper span");
            assertTextIgnoreCase(".workspace-header-wrapper .workspace-additional-info-wrapper span", "For Test");
        } finally {
            deleteWorkspace(workspace.getId());
        }
    } finally {
        mockBuilder.wiremockReset();
    }
}
Also used : OffsetDateTime(java.time.OffsetDateTime) Builder(fi.otavanopisto.muikku.mock.PyramusMock.Builder) JSR310Module(com.fasterxml.jackson.datatype.jsr310.JSR310Module) MockStaffMember(fi.otavanopisto.muikku.mock.model.MockStaffMember) Course(fi.otavanopisto.pyramus.rest.model.Course) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) WebhookCourseCreatePayload(fi.otavanopisto.pyramus.webhooks.WebhookCourseCreatePayload) Workspace(fi.otavanopisto.muikku.atests.Workspace) Test(org.junit.Test) AbstractUITest(fi.otavanopisto.muikku.ui.AbstractUITest) TestEnvironments(fi.otavanopisto.muikku.TestEnvironments)

Example 47 with JSR310Module

use of com.fasterxml.jackson.datatype.jsr310.JSR310Module in project muikku by otavanopisto.

the class CourseManagementTestsBase method changeCourseNameTest.

@Test
@TestEnvironments(browsers = { TestEnvironments.Browser.CHROME, TestEnvironments.Browser.FIREFOX, TestEnvironments.Browser.INTERNET_EXPLORER, TestEnvironments.Browser.EDGE, TestEnvironments.Browser.PHANTOMJS })
public void changeCourseNameTest() throws Exception {
    MockStaffMember admin = new MockStaffMember(1l, 1l, "Admin", "User", UserRole.ADMINISTRATOR, "121212-1234", "admin@example.com", Sex.MALE);
    Builder mockBuilder = mocker();
    try {
        mockBuilder.addStaffMember(admin).mockLogin(admin).build();
        login();
        long courseId = 1l;
        Workspace workspace = createWorkspace("testcourse", "test course for testing", String.valueOf(courseId), Boolean.TRUE);
        try {
            navigate(String.format("/workspace/%s/workspace-management", workspace.getUrlName()), true);
            waitAndClick(".workspace-management-container input[name=\"workspaceName\"]");
            clearElement(".workspace-management-container input[name=\"workspaceName\"]");
            sendKeys(".workspace-management-container input[name=\"workspaceName\"]", "Testing course");
            ObjectMapper objectMapper = new ObjectMapper().registerModule(new JSR310Module()).disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS).setSerializationInclusion(Include.NON_NULL);
            OffsetDateTime created = OffsetDateTime.of(1990, 2, 2, 0, 0, 0, 0, ZoneOffset.UTC);
            OffsetDateTime begin = OffsetDateTime.of(2000, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC);
            OffsetDateTime end = OffsetDateTime.of(2050, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC);
            waitAndClick(".workspace-management-footer .workspace-management-footer-actions-container button.save");
            waitForNotVisible(".loading");
            Course course = new Course(courseId, "Testing course", created, created, "<p>test course for testing</p>\n", false, 1, (long) 25, begin, end, "test extension", (double) 15, (double) 45, (double) 45, (double) 15, (double) 45, (double) 45, end, (long) 1, (long) 1, (long) 1, null, (double) 45, (long) 1, (long) 1, (long) 1, (long) 1, null, null);
            String courseJson = objectMapper.writeValueAsString(course);
            stubFor(put(urlEqualTo(String.format("/1/courses/courses/%d", courseId))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(courseJson).withStatus(200)));
            stubFor(get(urlEqualTo(String.format("/1/courses/courses/%d", courseId))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(courseJson).withStatus(200)));
            String payload = objectMapper.writeValueAsString(new WebhookCourseCreatePayload(course.getId()));
            TestUtilities.webhookCall("http://dev.muikku.fi:" + System.getProperty("it.port.http") + "/pyramus/webhook", payload);
            navigate(String.format("/workspace/%s", workspace.getUrlName()), true);
            waitForPresent(".workspace-header-wrapper .workspace-header-container h1.workspace-title");
            assertTextIgnoreCase(".workspace-header-wrapper .workspace-header-container h1.workspace-title", "Testing course");
        } finally {
            deleteWorkspace(workspace.getId());
        }
    } finally {
        mockBuilder.wiremockReset();
    }
}
Also used : OffsetDateTime(java.time.OffsetDateTime) Builder(fi.otavanopisto.muikku.mock.PyramusMock.Builder) JSR310Module(com.fasterxml.jackson.datatype.jsr310.JSR310Module) MockStaffMember(fi.otavanopisto.muikku.mock.model.MockStaffMember) Course(fi.otavanopisto.pyramus.rest.model.Course) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) WebhookCourseCreatePayload(fi.otavanopisto.pyramus.webhooks.WebhookCourseCreatePayload) Workspace(fi.otavanopisto.muikku.atests.Workspace) Test(org.junit.Test) AbstractUITest(fi.otavanopisto.muikku.ui.AbstractUITest) TestEnvironments(fi.otavanopisto.muikku.TestEnvironments)

Example 48 with JSR310Module

use of com.fasterxml.jackson.datatype.jsr310.JSR310Module in project muikku by otavanopisto.

the class AbstractRESTTest method setupRestAssured.

@Before
public void setupRestAssured() throws JsonProcessingException {
    RestAssured.baseURI = getAppUrl(true) + "/rest";
    RestAssured.port = getPortHttps();
    RestAssured.authentication = certificate(getKeystoreFile(), getKeystorePass());
    RestAssured.config = RestAssuredConfig.config().objectMapperConfig(ObjectMapperConfig.objectMapperConfig().jackson2ObjectMapperFactory(new Jackson2ObjectMapperFactory() {

        @SuppressWarnings("rawtypes")
        @Override
        public com.fasterxml.jackson.databind.ObjectMapper create(Class cls, String charset) {
            com.fasterxml.jackson.databind.ObjectMapper objectMapper = new com.fasterxml.jackson.databind.ObjectMapper();
            objectMapper.registerModule(new JSR310Module());
            objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
            return objectMapper;
        }
    }));
}
Also used : Jackson2ObjectMapperFactory(com.jayway.restassured.mapper.factory.Jackson2ObjectMapperFactory) JSR310Module(com.fasterxml.jackson.datatype.jsr310.JSR310Module) Before(org.junit.Before)

Example 49 with JSR310Module

use of com.fasterxml.jackson.datatype.jsr310.JSR310Module in project muikku by otavanopisto.

the class CourseUsersTestsBase method courseArchiveStudentTest.

@Test
public void courseArchiveStudentTest() 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();
    try {
        mockBuilder.addStaffMember(admin).mockLogin(admin).build();
        login();
        Long courseId = 1l;
        Workspace workspace = createWorkspace("testcourse", "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.addStudent(student).addCourseStaffMember(courseId, courseStaffMember).addCourseStudent(courseId, courseStudent).build();
        try {
            navigate(String.format("/workspace/%s/users", workspace.getUrlName()), true);
            waitForPresent(".workspace-students-listing-wrapper .workspace-users-name");
            waitAndClick("div[data-user-id='PYRAMUS-STUDENT-2']>div.workspace-users-archive");
            waitAndClick(".archive-button");
            waitForPresentAndVisible(".workspace-students-listing-wrapper");
            ObjectMapper objectMapper = new ObjectMapper().registerModule(new JSR310Module()).disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
            String payload = objectMapper.writeValueAsString(new WebhookStudentUpdatePayload(2l));
            TestUtilities.webhookCall("http://dev.muikku.fi:" + getPortHttp() + "/pyramus/webhook", payload);
            reloadCurrentPage();
            waitForPresent(".workspace-students-list");
            assertNotPresent("div[data-user-id='PYRAMUS-STUDENT-2']");
        } finally {
            deleteWorkspace(workspace.getId());
        }
    } finally {
        mockBuilder.wiremockReset();
        mockBuilder.resetBuilder();
    }
}
Also used : Builder(fi.otavanopisto.muikku.mock.PyramusMock.Builder) CourseStaffMember(fi.otavanopisto.pyramus.rest.model.CourseStaffMember) JSR310Module(com.fasterxml.jackson.datatype.jsr310.JSR310Module) MockStaffMember(fi.otavanopisto.muikku.mock.model.MockStaffMember) MockStudent(fi.otavanopisto.muikku.mock.model.MockStudent) MockCourseStudent(fi.otavanopisto.muikku.mock.model.MockCourseStudent) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Workspace(fi.otavanopisto.muikku.atests.Workspace) WebhookStudentUpdatePayload(fi.otavanopisto.pyramus.webhooks.WebhookStudentUpdatePayload) Test(org.junit.Test) AbstractUITest(fi.otavanopisto.muikku.ui.AbstractUITest)

Example 50 with JSR310Module

use of com.fasterxml.jackson.datatype.jsr310.JSR310Module in project muikku by otavanopisto.

the class EvaluationTestsBase method evaluateWorkspaceStudent.

@Test
@TestEnvironments(browsers = { TestEnvironments.Browser.CHROME, TestEnvironments.Browser.FIREFOX, TestEnvironments.Browser.INTERNET_EXPLORER, TestEnvironments.Browser.EDGE, TestEnvironments.Browser.SAFARI })
public void evaluateWorkspaceStudent() 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();
    try {
        mockBuilder.addStudent(student).addStaffMember(admin).mockLogin(admin).build();
        Long courseId = 1l;
        login();
        Workspace workspace = createWorkspace("testcourse", "test course for testing", courseId.toString(), 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();
        try {
            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");
            try {
                Long assessorId = getUserEntityIdForIdentifier(String.format("STAFF-%s", admin.getId()));
                logout();
                mockBuilder.mockLogin(student).build();
                login();
                navigate(String.format("/workspace/%s/materials", workspace.getUrlName()), true);
                waitForPresent(String.format("#page-%d", htmlMaterial.getId()));
                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()));
                logout();
                mockBuilder.mockLogin(admin).build();
                login();
                ObjectMapper objectMapper = new ObjectMapper().registerModule(new JSR310Module()).disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS).setSerializationInclusion(Include.NON_NULL);
                // TODO: Move to new mocker
                OffsetDateTime assessmentCreated = OffsetDateTime.of(2015, 2, 2, 0, 0, 0, 0, ZoneOffset.UTC);
                CourseAssessment courseAssessment = new CourseAssessment(1l, courseStudent.getId(), 1l, 1l, admin.getId(), 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)));
                navigate(String.format("/evaluation"), true);
                waitAndClick("#filter-students-by-assessment-requested");
                waitAndClick(".evaluation-student-name");
                addTextToCKEditor("Test evaluation.");
                clearElement("#evaluationDate");
                sendKeys("#evaluationDate", "2.12.2015");
                selectOption("#grade", "1/PYRAMUS@1/PYRAMUS");
                selectOption("select[name='assessor']", assessorId.toString());
                click(".save-evaluation-button");
                waitForPresent(".notification-queue-item-success");
                // There's no JSONComparator that allows different values. And since dev machine and travis testing gives different dates we can not test requestBody with CourseAssessment model.
                CourseAssessment cAss = new fi.otavanopisto.pyramus.rest.model.CourseAssessment(null, courseStudent.getId(), 1l, 1l, admin.getId(), null, "<p>Test evaluation.</p>\n", Boolean.TRUE);
                verify(postRequestedFor(urlEqualTo(String.format("/1/students/students/%d/courses/%d/assessments/", student.getId(), courseId))).withHeader("Content-Type", equalTo("application/json")).withRequestBody(equalToJson(objectMapper.writeValueAsString(cAss), true, true)));
                PyramusMocks.mockAssessedStudent1Workspace1(courseStudent, assessorId);
                waitForPresentAndVisible(".evaluation-assignment-wrapper");
                assertClassPresent(".evaluation-student-wrapper", "workspace-evaluated");
                waitAndClick(".evaluation-student-name");
                waitForPresent("#grade");
                assertValue("#grade", "1/PYRAMUS@1/PYRAMUS");
                waitForPresent("select[name='assessor']");
                assertValue("select[name='assessor']", assessorId.toString());
                waitForPresent(".cke_contents");
                assertEquals("Test evaluation.", getCKEditorContent());
            } finally {
                deleteWorkspaceHtmlMaterial(workspace.getId(), htmlMaterial.getId());
            }
        } finally {
            deleteWorkspace(workspace.getId());
        }
    } finally {
        mockBuilder.wiremockReset();
    }
}
Also used : WorkspaceHtmlMaterial(fi.otavanopisto.muikku.atests.WorkspaceHtmlMaterial) Builder(fi.otavanopisto.muikku.mock.PyramusMock.Builder) JSR310Module(com.fasterxml.jackson.datatype.jsr310.JSR310Module) MockCourseStudent(fi.otavanopisto.muikku.mock.model.MockCourseStudent) CourseAssessment(fi.otavanopisto.pyramus.rest.model.CourseAssessment) WorkspaceFolder(fi.otavanopisto.muikku.atests.WorkspaceFolder) OffsetDateTime(java.time.OffsetDateTime) CourseStaffMember(fi.otavanopisto.pyramus.rest.model.CourseStaffMember) MockStaffMember(fi.otavanopisto.muikku.mock.model.MockStaffMember) MockStudent(fi.otavanopisto.muikku.mock.model.MockStudent) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Workspace(fi.otavanopisto.muikku.atests.Workspace) Test(org.junit.Test) AbstractUITest(fi.otavanopisto.muikku.ui.AbstractUITest) TestEnvironments(fi.otavanopisto.muikku.TestEnvironments)

Aggregations

JSR310Module (com.fasterxml.jackson.datatype.jsr310.JSR310Module)56 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)55 Response (com.jayway.restassured.response.Response)13 OffsetDateTime (java.time.OffsetDateTime)13 CourseStaffMember (fi.otavanopisto.pyramus.rest.model.CourseStaffMember)9 ArrayList (java.util.ArrayList)9 Workspace (fi.otavanopisto.muikku.atests.Workspace)7 Test (org.junit.Test)7 Builder (fi.otavanopisto.muikku.mock.PyramusMock.Builder)6 MockStaffMember (fi.otavanopisto.muikku.mock.model.MockStaffMember)6 AbstractUITest (fi.otavanopisto.muikku.ui.AbstractUITest)6 StaffMember (fi.otavanopisto.pyramus.rest.model.StaffMember)6 Course (fi.otavanopisto.pyramus.rest.model.Course)5 Email (fi.otavanopisto.pyramus.rest.model.Email)5 WebhookPersonCreatePayload (fi.otavanopisto.pyramus.webhooks.WebhookPersonCreatePayload)5 TestEnvironments (fi.otavanopisto.muikku.TestEnvironments)4 MockCourseStudent (fi.otavanopisto.muikku.mock.model.MockCourseStudent)4 CourseStudent (fi.otavanopisto.pyramus.rest.model.CourseStudent)4 Person (fi.otavanopisto.pyramus.rest.model.Person)4 Student (fi.otavanopisto.pyramus.rest.model.Student)4