UntisInfoParser extends UntisCommonParser { @NotNull static List<String> parseClasses(String navbarDoc, JSONObject data) throws JSONException, IOException { Pattern pattern = Pattern.compile("var classes = (\\[[^\\]]*\\]);"); return parseJsonList(navbarDoc, data, pattern); } UntisInfoParser(SubstitutionScheduleData scheduleData, CookieProvider cookieProvider); @Override SubstitutionSchedule getSubstitutionSchedule(); @Override List<String> getAllClasses(); @Override List<String> getAllTeachers(); static final String PARAM_BASEURL; static final String PARAM_CLASS_SELECT_REGEX; static final String PARAM_REMOVE_NON_MATCHING_CLASSES; static final String PARAM_W_AFTER_NUMBER; }
@Test public void testGetClasses() throws Exception { List<String> classes = UntisInfoParser.parseClasses(html, new JSONObject()); assertEquals( Arrays.asList(new String[]{"UAEG2", "UAEG", "SL", "VW", "PB", "AEG1", "13", "12", "11", "10E", "10D", "10C", "10B", "10A", "09D", "09C", "09B", "09A", "08F", "08E", "08D", "08C", "08B", "08A", "07F", "07E", "07D", "07C", "07B", "07A", "06G2", "06G1", "06D", "06C", "06B", "06A", "05G2", "05G1", "05C", "05B", "05A", "ESL"}), classes); }
@Test public void testGetClassesRegex() throws Exception { final JSONObject data = new JSONObject(); data.put(UntisInfoParser.PARAM_CLASS_SELECT_REGEX, "\\d+"); List<String> classes = UntisInfoParser.parseClasses(html, data); assertEquals(Arrays.asList( new String[]{"2", "UAEG", "SL", "VW", "PB", "1", "13", "12", "11", "10", "10", "10", "10", "10", "09", "09", "09", "09", "08", "08", "08", "08", "08", "08", "07", "07", "07", "07", "07", "07", "06", "06", "06", "06", "06", "06", "05", "05", "05", "05", "05", "ESL"}), classes); }
@Test public void testGetClassesRegexRemove() throws Exception { final JSONObject data = new JSONObject(); data.put(UntisInfoParser.PARAM_CLASS_SELECT_REGEX, "^\\d+\\w?\\d?$"); data.put(UntisInfoParser.PARAM_REMOVE_NON_MATCHING_CLASSES, true); List<String> classes = UntisInfoParser.parseClasses(html, data); assertEquals(Arrays.asList( new String[]{"13", "12", "11", "10E", "10D", "10C", "10B", "10A", "09D", "09C", "09B", "09A", "08F", "08E", "08D", "08C", "08B", "08A", "07F", "07E", "07D", "07C", "07B", "07A", "06G2", "06G1", "06D", "06C", "06B", "06A", "05G2", "05G1", "05C", "05B", "05A"}), classes); }