Search in sources :

Example 11 with StaffMember

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

the class PyramusMocks method adminMock.

public static void adminMock() 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 staff3 = mockPerson((long) 4, birthday, "345345-3453", fi.otavanopisto.pyramus.rest.model.Sex.MALE, (long) 4);
    Person[] personArray = { 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)));
    StaffMember staffMember3 = new StaffMember((long) 4, (long) 4, null, "Test", "Administrator", null, fi.otavanopisto.pyramus.rest.model.UserRole.ADMINISTRATOR, tags, variables);
    String 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 };
    String 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 = { staffMember3 };
    String staffArrayJson = objectMapper.writeValueAsString(staffArray);
    stubFor(get(urlEqualTo("/1/staff/members")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(staffArrayJson).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 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 tutorRole = new CourseStaffMemberRole((long) 2, "Tutor");
    // CourseStaffMemberRole vRole = new CourseStaffMemberRole((long) 3, "Vastuuhenkilö");
    // CourseStaffMemberRole studentRole = new CourseStaffMemberRole((long) 9, "Opiskelija");
    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)));
    }
    mockContactTypes();
    String 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);
}
Also used : CourseStaffMemberRole(fi.otavanopisto.pyramus.rest.model.CourseStaffMemberRole) Email(fi.otavanopisto.pyramus.rest.model.Email) WebhookPersonCreatePayload(fi.otavanopisto.pyramus.webhooks.WebhookPersonCreatePayload) JSR310Module(com.fasterxml.jackson.datatype.jsr310.JSR310Module) CourseStaffMember(fi.otavanopisto.pyramus.rest.model.CourseStaffMember) StaffMember(fi.otavanopisto.pyramus.rest.model.StaffMember) OffsetDateTime(java.time.OffsetDateTime) Person(fi.otavanopisto.pyramus.rest.model.Person) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) WebhookStaffMemberCreatePayload(fi.otavanopisto.pyramus.webhooks.WebhookStaffMemberCreatePayload)

Example 12 with StaffMember

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

the class PyramusMocks method mockStaffMember.

@SuppressWarnings("unused")
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)));
    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)

Example 13 with StaffMember

use of fi.otavanopisto.pyramus.rest.model.StaffMember 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)

Aggregations

StaffMember (fi.otavanopisto.pyramus.rest.model.StaffMember)13 Student (fi.otavanopisto.pyramus.rest.model.Student)9 StudentGroupStudent (fi.otavanopisto.pyramus.rest.model.StudentGroupStudent)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 JSR310Module (com.fasterxml.jackson.datatype.jsr310.JSR310Module)6 CourseStaffMember (fi.otavanopisto.pyramus.rest.model.CourseStaffMember)6 Email (fi.otavanopisto.pyramus.rest.model.Email)5 Person (fi.otavanopisto.pyramus.rest.model.Person)5 SchoolDataBridgeInternalException (fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException)3 CourseStudent (fi.otavanopisto.pyramus.rest.model.CourseStudent)3 WebhookPersonCreatePayload (fi.otavanopisto.pyramus.webhooks.WebhookPersonCreatePayload)3 WebhookStaffMemberCreatePayload (fi.otavanopisto.pyramus.webhooks.WebhookStaffMemberCreatePayload)3 OffsetDateTime (java.time.OffsetDateTime)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 ContactType (fi.otavanopisto.pyramus.rest.model.ContactType)2 CourseStaffMemberRole (fi.otavanopisto.pyramus.rest.model.CourseStaffMemberRole)2 List (java.util.List)2 MockCourseStudent (fi.otavanopisto.muikku.mock.model.MockCourseStudent)1 RoleSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.RoleSchoolDataIdentifier)1