Search in sources :

Example 36 with JSR310Module

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

the class AbstractUITest method setupRestAssured.

@Before
public void setupRestAssured() {
    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) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JSR310Module(com.fasterxml.jackson.datatype.jsr310.JSR310Module) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Example 37 with JSR310Module

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

the class PyramusMocks method mockCourseTypes.

public static void mockCourseTypes() throws JsonProcessingException {
    ObjectMapper objectMapper = new ObjectMapper().registerModule(new JSR310Module()).disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    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)));
}
Also used : CourseType(fi.otavanopisto.pyramus.rest.model.CourseType) JSR310Module(com.fasterxml.jackson.datatype.jsr310.JSR310Module) CourseType(fi.otavanopisto.pyramus.rest.model.CourseType) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 38 with JSR310Module

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

the class PyramusMocks method workspacePyramusMock.

public static void workspacePyramusMock(Long id, String name, String description) throws Exception {
    ObjectMapper objectMapper = new ObjectMapper().registerModule(new JSR310Module()).disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    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, name, created, created, description, 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(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);
    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)));
    stubFor(put(urlEqualTo(String.format("/1/courses/courses/%d", id))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(courseJson).withStatus(200)));
    mockStudyProgrammes();
    mockCommons();
    mockCourseTypes();
    String payload = objectMapper.writeValueAsString(new WebhookCourseCreatePayload(course.getId()));
    TestUtilities.webhookCall("http://dev.muikku.fi:" + System.getProperty("it.port.http") + "/pyramus/webhook", payload);
}
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)

Example 39 with JSR310Module

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

the class PyramusMocks method studentGroupsMocks.

public static void studentGroupsMocks() throws JsonProcessingException {
    ObjectMapper objectMapper = new ObjectMapper().registerModule(new JSR310Module()).disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    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 lastmodified = OffsetDateTime.of(2000, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC);
    StudentGroup studentGroupStudents = new StudentGroup((long) 1, "Opiskelijat", "Spring 2015 Students", begin, (long) 1, created, (long) 1, lastmodified, null, false, false);
    StudentGroup studentGroupAnother = new StudentGroup((long) 2, "Opiskelijat 2", "Spring 2015 Students 2", begin, (long) 1, created, (long) 1, lastmodified, null, false, false);
    StudentGroup[] studentGroupArray = { studentGroupStudents, studentGroupAnother };
    String studentGroupsJson = objectMapper.writeValueAsString(studentGroupArray);
    stubFor(get(urlMatching("/1/students/studentGroups")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(studentGroupsJson).withStatus(200)));
}
Also used : OffsetDateTime(java.time.OffsetDateTime) JSR310Module(com.fasterxml.jackson.datatype.jsr310.JSR310Module) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) StudentGroup(fi.otavanopisto.pyramus.rest.model.StudentGroup)

Example 40 with JSR310Module

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

the class PyramusMocks method mockCommons.

public static void mockCommons() throws JsonProcessingException {
    ObjectMapper objectMapper = new ObjectMapper().registerModule(new JSR310Module()).disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    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)));
    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)));
    List<GradingScale> gradingScales = new ArrayList<GradingScale>();
    GradingScale gs = new GradingScale(1l, "Pass/Fail", "Passed or failed scale", false);
    gradingScales.add(gs);
    stubFor(get(urlEqualTo("/1/common/gradingScales")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(gradingScales)).withStatus(200)));
    stubFor(get(urlEqualTo(String.format("/1/common/gradingScales/%d", gs.getId()))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(gs)).withStatus(200)));
    Grade grade1 = new Grade(1l, "Excellent", "Excellent answer showing expertise in area of study", 1l, true, "0", null, false);
    Grade grade2 = new Grade(2l, "Failed", "Failed answer. Not proving any expertise in the matter.", 1l, false, "1", null, false);
    List<Grade> grades = new ArrayList<Grade>();
    grades.add(grade1);
    grades.add(grade2);
    stubFor(get(urlEqualTo(String.format("/1/common/gradingScales/%d/grades", gs.getId()))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(grades)).withStatus(200)));
    stubFor(get(urlEqualTo(String.format("/1/common/gradingScales/%d/grades/%d", gs.getId(), grade1.getId()))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(grade1)).withStatus(200)));
    stubFor(get(urlEqualTo(String.format("/1/common/gradingScales/%d/grades/%d", gs.getId(), grade2.getId()))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(grade2)).withStatus(200)));
    stubFor(get(urlEqualTo(String.format("/1/common/gradingScales/?filterArchived=true"))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(gradingScales)).withStatus(200)));
}
Also used : GradingScale(fi.otavanopisto.pyramus.rest.model.GradingScale) EducationType(fi.otavanopisto.pyramus.rest.model.EducationType) JSR310Module(com.fasterxml.jackson.datatype.jsr310.JSR310Module) ArrayList(java.util.ArrayList) Grade(fi.otavanopisto.pyramus.rest.model.Grade) Subject(fi.otavanopisto.pyramus.rest.model.Subject) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) EducationalTimeUnit(fi.otavanopisto.pyramus.rest.model.EducationalTimeUnit)

Aggregations

JSR310Module (com.fasterxml.jackson.datatype.jsr310.JSR310Module)55 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)54 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