Search in sources :

Example 51 with JSR310Module

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

the class PyramusMocksRest method mockStudyProgrammes.

private static void mockStudyProgrammes(List<String> payloads) throws JsonProcessingException {
    ObjectMapper objectMapper = new ObjectMapper().registerModule(new JSR310Module()).disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    StudyProgrammeCategory spc = new StudyProgrammeCategory(1l, "All Study Programmes", 1l, false);
    StudyProgramme sp = new StudyProgramme(1l, "test", "Test Study Programme", 1l, false);
    StudyProgramme[] sps = { sp };
    StudyProgrammeCategory[] spcs = { spc };
    stubFor(get(urlEqualTo("/1/students/studyProgrammes")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(sps)).withStatus(200)));
    stubFor(get(urlEqualTo("/1/students/studyProgrammes/1")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(sp)).withStatus(200)));
    stubFor(get(urlEqualTo("/1/students/studyProgrammeCategories")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(spcs)).withStatus(200)));
    stubFor(get(urlEqualTo("/1/students/studyProgrammeCategories/1")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(spc)).withStatus(200)));
}
Also used : StudyProgramme(fi.otavanopisto.pyramus.rest.model.StudyProgramme) StudyProgrammeCategory(fi.otavanopisto.pyramus.rest.model.StudyProgrammeCategory) JSR310Module(com.fasterxml.jackson.datatype.jsr310.JSR310Module) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 52 with JSR310Module

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

the class PyramusMocksRest method mockStaffMember.

private static StaffMember mockStaffMember(Long personId, Long staffMemberId, String firstName, String lastName, String email, UserRole role, List<String> tags, Map<String, String> variables, List<String> payloads) throws JsonProcessingException {
    ObjectMapper objectMapper = new ObjectMapper().registerModule(new JSR310Module()).disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    StaffMember staffMember = new StaffMember(staffMemberId, personId, null, firstName, lastName, null, role, tags, variables);
    String staffMemberJson = objectMapper.writeValueAsString(staffMember);
    stubFor(get(urlEqualTo("/1/staff/members/" + staffMemberId)).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(staffMemberJson).withStatus(200)));
    StaffMember[] staffMemberArray = { staffMember };
    String staffMemberArrayJson = objectMapper.writeValueAsString(staffMemberArray);
    stubFor(get(urlEqualTo("/1/staff/members?email=" + email)).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(staffMemberArrayJson).withStatus(200)));
    Email staffEmail = new Email(staffMemberId, (long) 1, true, email);
    Email[] staffEmails = { staffEmail };
    String staffEmailJson = objectMapper.writeValueAsString(staffEmails);
    stubFor(get(urlEqualTo("/1/staff/members/" + staffMemberId + "/emails")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(staffEmailJson).withStatus(200)));
    addPayload(payloads, objectMapper.writeValueAsString(new WebhookStaffMemberCreatePayload(staffMember.getId())));
    return staffMember;
}
Also used : 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) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) WebhookStaffMemberCreatePayload(fi.otavanopisto.pyramus.webhooks.WebhookStaffMemberCreatePayload)

Example 53 with JSR310Module

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

the class PyramusMocksRest method mockUserGroups.

public static void mockUserGroups(List<String> payloads) throws JsonProcessingException {
    ObjectMapper objectMapper = new ObjectMapper().registerModule(new JSR310Module()).disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    OffsetDateTime begin = OffsetDateTime.of(2000, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC);
    Long creatorId = 1l;
    Long groupId = 2l;
    StudentGroup studentGroup = new StudentGroup(groupId, "Group1", "", begin, creatorId, begin, creatorId, begin, null, false, false);
    StudentGroup[] studentGroups = new StudentGroup[] { studentGroup };
    stubFor(get(urlEqualTo("/1/students/studentGroups")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(studentGroups)).withStatus(200)));
    stubFor(get(urlEqualTo(String.format("/1/students/studentGroups/%d", groupId))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(studentGroup)).withStatus(200)));
    addPayload(payloads, objectMapper.writeValueAsString(new WebhookStudentGroupCreatePayload(groupId)));
    StudentGroupUser studentGroupStaffMember = new StudentGroupUser(1l, 4l);
    StudentGroupUser[] studentGroupStaffMembers = { studentGroupStaffMember };
    stubFor(get(urlEqualTo(String.format("/1/students/studentGroups/%d/staffmembers", groupId))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(studentGroupStaffMembers)).withStatus(200)));
    stubFor(get(urlEqualTo(String.format("/1/students/studentGroups/%d/staffmembers/%d", groupId, studentGroupStaffMember.getId()))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(studentGroupStaffMember)).withStatus(200)));
    addPayload(payloads, objectMapper.writeValueAsString(new WebhookStudentGroupStaffMemberCreatePayload(studentGroupStaffMember.getId(), groupId, studentGroupStaffMember.getStaffMemberId())));
    StudentGroupStudent studentGroupStudent = new StudentGroupStudent(2l, 1l);
    StudentGroupStudent[] studentGroupStudents = { studentGroupStudent };
    stubFor(get(urlEqualTo(String.format("/1/students/studentGroups/%d/students", groupId))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(studentGroupStudents)).withStatus(200)));
    stubFor(get(urlEqualTo(String.format("/1/students/studentGroups/%d/students/%d", groupId, studentGroupStudent.getId()))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(studentGroupStudent)).withStatus(200)));
    addPayload(payloads, objectMapper.writeValueAsString(new WebhookStudentGroupStudentCreatePayload(studentGroupStudent.getId(), groupId, studentGroupStudent.getStudentId())));
}
Also used : WebhookStudentGroupCreatePayload(fi.otavanopisto.pyramus.webhooks.WebhookStudentGroupCreatePayload) JSR310Module(com.fasterxml.jackson.datatype.jsr310.JSR310Module) WebhookStudentGroupStudentCreatePayload(fi.otavanopisto.pyramus.webhooks.WebhookStudentGroupStudentCreatePayload) StudentGroupStudent(fi.otavanopisto.pyramus.rest.model.StudentGroupStudent) OffsetDateTime(java.time.OffsetDateTime) StudentGroupUser(fi.otavanopisto.pyramus.rest.model.StudentGroupUser) WebhookStudentGroupStaffMemberCreatePayload(fi.otavanopisto.pyramus.webhooks.WebhookStudentGroupStaffMemberCreatePayload) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) StudentGroup(fi.otavanopisto.pyramus.rest.model.StudentGroup)

Example 54 with JSR310Module

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

the class PyramusMocksRest method teacherLoginMock.

public static void teacherLoginMock() throws JsonProcessingException {
    stubFor(get(urlEqualTo("/dnm")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody("").withStatus(204)));
    stubFor(get(urlMatching("/users/authorize.*")).willReturn(aResponse().withStatus(302).withHeader("Location", "http://dev.muikku.fi:" + System.getProperty("it.port.http") + "/login?_stg=rsp&code=1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111")));
    stubFor(post(urlEqualTo("/1/oauth/token")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody("{\"expires_in\":3600,\"refresh_token\":\"12312ewsdf34fsd234r43rfsw32rf33e\",\"access_token\":\"ur84ur839843ruwf39843ru39ru37y2e\"}").withStatus(200)));
    List<String> emails = new ArrayList<String>();
    emails.add("teacher@example.com");
    WhoAmI whoAmI = new WhoAmI((long) 2, "Teacher", "User", emails);
    ObjectMapper objectMapper = new ObjectMapper().registerModule(new JSR310Module()).disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    String whoAmIJson = objectMapper.writeValueAsString(whoAmI);
    stubFor(get(urlEqualTo("/1/system/whoami")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(whoAmIJson).withStatus(200)));
}
Also used : ArrayList(java.util.ArrayList) JSR310Module(com.fasterxml.jackson.datatype.jsr310.JSR310Module) WhoAmI(fi.otavanopisto.pyramus.rest.model.WhoAmI) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 55 with JSR310Module

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

the class PyramusMocksRest method mockWorkspace.

public static void mockWorkspace(Long id, List<String> payloads) throws JsonProcessingException {
    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(id, "testCourse", created, created, "test course for testing", 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);
    ObjectMapper objectMapper = new ObjectMapper().registerModule(new JSR310Module()).disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    String courseJson = objectMapper.writeValueAsString(course);
    stubFor(get(urlEqualTo(String.format("/1/courses/courses/%d", id))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(courseJson).withStatus(200)));
    Course[] courseArray = { course };
    String courseArrayJson = objectMapper.writeValueAsString(courseArray);
    addPayload(payloads, new WebhookCourseCreatePayload(id));
    stubFor(get(urlEqualTo("/1/courses/courses")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(courseArrayJson).withStatus(200)));
    stubFor(get(urlMatching("/1/courses/courses?filterArchived=false&firstResult=.*&maxResults=.*")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(courseArrayJson).withStatus(200)));
    Subject subject = new Subject((long) 1, "tc_11", "Test course", (long) 1, false);
    String subjectJson = objectMapper.writeValueAsString(subject);
    stubFor(get(urlMatching("/1/common/subjects/.*")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(subjectJson).withStatus(200)));
    Subject[] subjectArray = { subject };
    String subjectArrayJson = objectMapper.writeValueAsString(subjectArray);
    stubFor(get(urlEqualTo("/1/common/subjects")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(subjectArrayJson).withStatus(200)));
}
Also used : OffsetDateTime(java.time.OffsetDateTime) JSR310Module(com.fasterxml.jackson.datatype.jsr310.JSR310Module) Course(fi.otavanopisto.pyramus.rest.model.Course) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) WebhookCourseCreatePayload(fi.otavanopisto.pyramus.webhooks.WebhookCourseCreatePayload) Subject(fi.otavanopisto.pyramus.rest.model.Subject)

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