use of com.fasterxml.jackson.datatype.jsr310.JSR310Module in project muikku by otavanopisto.
the class PyramusMocksRest method student1LoginMock.
public static void student1LoginMock() 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("testuser@example.com");
WhoAmI whoAmI = new WhoAmI((long) 1, "Test", "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)));
}
use of com.fasterxml.jackson.datatype.jsr310.JSR310Module in project muikku by otavanopisto.
the class PyramusMocksRest method mockCommons.
public static void mockCommons() throws JsonProcessingException {
ObjectMapper objectMapper = new ObjectMapper().registerModule(new JSR310Module()).disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
EducationType educationType = new EducationType((long) 1, "testEduType", "ET", false);
String educationTypeJson = objectMapper.writeValueAsString(educationType);
stubFor(get(urlEqualTo("/1/common/educationTypes/1")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(educationTypeJson).withStatus(200)));
EducationType[] educationTypeArray = { educationType };
String educationTypeArrayJson = objectMapper.writeValueAsString(educationTypeArray);
stubFor(get(urlEqualTo("/1/common/educationTypes")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(educationTypeArrayJson).withStatus(200)));
EducationalTimeUnit educationalTimeUnit = new EducationalTimeUnit((long) 1, "test time unit", "h", (double) 1, false);
String eduTimeUnitJson = objectMapper.writeValueAsString(educationalTimeUnit);
stubFor(get(urlEqualTo("/1/common/educationalTimeUnits/1")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(eduTimeUnitJson).withStatus(200)));
EducationalTimeUnit[] eduTimeUnitArray = { educationalTimeUnit };
String eduTimeUnitArrayJson = objectMapper.writeValueAsString(eduTimeUnitArray);
stubFor(get(urlEqualTo("/1/common/educationalTimeUnits")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(eduTimeUnitArrayJson).withStatus(200)));
fi.otavanopisto.pyramus.rest.model.CourseType courseType = new fi.otavanopisto.pyramus.rest.model.CourseType((long) 1, "Nonstop", false);
CourseType[] courseTypeArray = { courseType };
String courseTypeJson = objectMapper.writeValueAsString(courseTypeArray);
stubFor(get(urlEqualTo("/1/courses/courseTypes")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(courseTypeJson).withStatus(200)));
String courseTypeSingleJson = objectMapper.writeValueAsString(courseType);
stubFor(get(urlEqualTo("/1/courses/courseTypes/1")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(courseTypeSingleJson).withStatus(200)));
}
use of com.fasterxml.jackson.datatype.jsr310.JSR310Module in project muikku by otavanopisto.
the class PyramusMocksRest method mockRoles.
public static void mockRoles(List<String> payloads) throws JsonProcessingException {
ObjectMapper objectMapper = new ObjectMapper().registerModule(new JSR310Module()).disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
CourseStaffMemberRole[] roles = { new CourseStaffMemberRole(7l, "Opettaja"), new CourseStaffMemberRole(8l, "Tutor"), new CourseStaffMemberRole(9l, "Vastuuhenkilö"), new CourseStaffMemberRole(10l, "Opiskelija") };
stubFor(get(urlEqualTo("/1/courses/staffMemberRoles")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(roles)).withStatus(200)));
for (CourseStaffMemberRole role : roles) {
stubFor(get(urlEqualTo(String.format("/1/courses/staffMemberRoles/%d", role.getId()))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(role)).withStatus(200)));
}
}
use of com.fasterxml.jackson.datatype.jsr310.JSR310Module in project muikku by otavanopisto.
the class PyramusMocksRest method mockStudent.
public static Student mockStudent(Long personId, Long studentId, String firstName, String lastName, String email, List<String> tags, Map<String, String> variables, List<String> payloads, OffsetDateTime studyStartDate, OffsetDateTime studyEndDate) throws JsonProcessingException {
ObjectMapper objectMapper = new ObjectMapper().registerModule(new JSR310Module()).disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
Student student = new Student(studentId, personId, firstName, lastName, null, null, null, null, null, null, null, null, null, null, null, (long) 1, null, null, null, false, studyStartDate, studyEndDate, null, null, variables, tags, false);
String studentJson = objectMapper.writeValueAsString(student);
stubFor(get(urlEqualTo(String.format("/1/students/students/%d", studentId))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(studentJson).withStatus(200)));
Email emailObj = new Email(studentId, (long) 2, true, email);
Email[] emails = { emailObj };
String emailJson = objectMapper.writeValueAsString(emails);
Student[] studentArray = { student };
String studentArrayJson = objectMapper.writeValueAsString(studentArray);
stubFor(get(urlEqualTo(String.format("/1/students/students/%d/emails", studentId))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(emailJson).withStatus(200)));
stubFor(get(urlEqualTo(String.format("/1/students/students?email=%s", email))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(studentArrayJson).withStatus(200)));
addPayload(payloads, objectMapper.writeValueAsString(new WebhookStudentCreatePayload(student.getId())));
return student;
}
use of com.fasterxml.jackson.datatype.jsr310.JSR310Module in project muikku by otavanopisto.
the class PyramusMocksRest method mockUsers.
public static void mockUsers(List<String> payloads) throws JsonProcessingException {
ObjectMapper objectMapper = new ObjectMapper().registerModule(new JSR310Module()).disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
OffsetDateTime birthday = OffsetDateTime.of(1990, 2, 2, 0, 0, 0, 0, ZoneOffset.UTC);
Person person = mockPerson(1l, birthday, "345345-3453", Sex.MALE, 1l);
Person staff1 = mockPerson(2l, birthday, "345345-3453", Sex.MALE, 2l);
Person staff2 = mockPerson(3l, birthday, "345345-3453", Sex.MALE, 3l);
Person staff3 = mockPerson(4l, birthday, "345345-3453", Sex.MALE, 4l);
Person staff4 = mockPerson(5l, birthday, "345345-3453", Sex.MALE, 5l);
Person studentPerson2 = mockPerson(6l, birthday, "345345-3453", Sex.MALE, 6l);
Person[] personArray = { person, staff1, staff2, staff3, staff4, studentPerson2 };
String personArrayJson = objectMapper.writeValueAsString(personArray);
for (Person p : personArray) addPayload(payloads, objectMapper.writeValueAsString(new WebhookPersonCreatePayload(p.getId())));
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)));
Map<String, String> variables = null;
List<String> tags = null;
Student student1 = mockStudent(1l, 1l, "Test", "User", "testuser@example.com", tags, variables, payloads, toDate(2010, 1, 1), getNextYear());
Student student2 = mockStudent(6l, 6l, "Hidden", "Dragon", "crouchingtiger@example.com", tags, variables, payloads, toDate(2010, 1, 1), toDate(2011, 1, 1));
StaffMember staffMember1 = mockStaffMember(2l, 2l, "Test", "Staff1member", "teacher@example.com", UserRole.USER, tags, variables, payloads);
StaffMember staffMember2 = mockStaffMember(3l, 3l, "Test", "Staff2member", "mana@example.com", UserRole.MANAGER, tags, variables, payloads);
StaffMember staffMember3 = mockStaffMember(4l, 4l, "Test", "Administrator", "admin@example.com", UserRole.ADMINISTRATOR, tags, variables, payloads);
StaffMember staffMember4 = mockStaffMember(5l, 5l, "Trusted", "System", "trusted@example.com", UserRole.TRUSTED_SYSTEM, tags, variables, payloads);
Student[] studentArray = { student1, student2 };
StaffMember[] staffArray = { staffMember1, staffMember2, staffMember3, staffMember4 };
String studentArrayJson = objectMapper.writeValueAsString(studentArray);
String staffArrayJson = objectMapper.writeValueAsString(staffArray);
stubFor(get(urlMatching("/1/students/students?filterArchived=false&firstResult=.*&maxResults=.*")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(studentArrayJson).withStatus(200)));
stubFor(get(urlEqualTo("/1/staff/members")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(staffArrayJson).withStatus(200)));
mockPersonStudens(studentArray);
mockPersonStaffMembers(staffArray);
ContactType contactType = new ContactType((long) 1, "Koti", false, false);
ContactType[] contactTypes = { contactType };
String contactTypeJson = objectMapper.writeValueAsString(contactType);
stubFor(get(urlMatching("/1/common/contactTypes/.*")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(contactTypeJson).withStatus(200)));
String contactTypesJson = objectMapper.writeValueAsString(contactTypes);
stubFor(get(urlEqualTo("/1/common/contactTypes")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(contactTypesJson).withStatus(200)));
}
Aggregations