Search in sources :

Example 1 with JSR310Module

use of com.fasterxml.jackson.datatype.jsr310.JSR310Module in project service-proxy by membrane.

the class OAuth2AnswerParameters method getObjectMapper.

private static ObjectMapper getObjectMapper() {
    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new JSR310Module());
    return mapper;
}
Also used : JSR310Module(com.fasterxml.jackson.datatype.jsr310.JSR310Module) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with JSR310Module

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

the class AbstractPyramusMocks method mockPersonStaffMembers.

protected static void mockPersonStaffMembers(StaffMember[] staffMembers) throws JsonProcessingException {
    ObjectMapper objectMapper = new ObjectMapper().registerModule(new JSR310Module()).disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    Map<Long, List<StaffMember>> personStaffMembers = new HashMap<>();
    for (StaffMember staffMember : staffMembers) {
        if (!personStaffMembers.containsKey(staffMember.getPersonId())) {
            personStaffMembers.put(staffMember.getPersonId(), new ArrayList<StaffMember>());
        }
        personStaffMembers.get(staffMember.getPersonId()).add(staffMember);
    }
    for (Long personId : personStaffMembers.keySet()) {
        stubFor(get(urlMatching(String.format("/1/persons/persons/%d/staffMembers", personId))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(personStaffMembers.get(personId))).withStatus(200)));
    }
}
Also used : HashMap(java.util.HashMap) JSR310Module(com.fasterxml.jackson.datatype.jsr310.JSR310Module) ArrayList(java.util.ArrayList) List(java.util.List) StaffMember(fi.otavanopisto.pyramus.rest.model.StaffMember) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with JSR310Module

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

the class AbstractPyramusMocks method mockPersonStudens.

protected static void mockPersonStudens(Student[] students) throws JsonProcessingException {
    ObjectMapper objectMapper = new ObjectMapper().registerModule(new JSR310Module()).disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    Map<Long, List<Student>> personStudents = new HashMap<>();
    for (Student student : students) {
        if (!personStudents.containsKey(student.getPersonId())) {
            personStudents.put(student.getPersonId(), new ArrayList<Student>());
        }
        personStudents.get(student.getPersonId()).add(student);
    }
    for (Long personId : personStudents.keySet()) {
        stubFor(get(urlMatching(String.format("/1/persons/persons/%d/students", personId))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(personStudents.get(personId))).withStatus(200)));
    }
}
Also used : HashMap(java.util.HashMap) JSR310Module(com.fasterxml.jackson.datatype.jsr310.JSR310Module) ArrayList(java.util.ArrayList) List(java.util.List) Student(fi.otavanopisto.pyramus.rest.model.Student) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 4 with JSR310Module

use of com.fasterxml.jackson.datatype.jsr310.JSR310Module 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 5 with JSR310Module

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

the class PyramusMocksRest method addPayload.

private static void addPayload(List<String> payloads, Object obj) throws JsonProcessingException {
    ObjectMapper objectMapper = new ObjectMapper().registerModule(new JSR310Module()).disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    addPayload(payloads, objectMapper.writeValueAsString(obj));
}
Also used : JSR310Module(com.fasterxml.jackson.datatype.jsr310.JSR310Module) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

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