Search in sources :

Example 1 with GradingScale

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

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 JSR310Module (com.fasterxml.jackson.datatype.jsr310.JSR310Module)1 EducationType (fi.otavanopisto.pyramus.rest.model.EducationType)1 EducationalTimeUnit (fi.otavanopisto.pyramus.rest.model.EducationalTimeUnit)1 Grade (fi.otavanopisto.pyramus.rest.model.Grade)1 GradingScale (fi.otavanopisto.pyramus.rest.model.GradingScale)1 Subject (fi.otavanopisto.pyramus.rest.model.Subject)1 ArrayList (java.util.ArrayList)1