forked from github/wulkanowy-mirror
Add notes api (#8)
* Add notes api with tests * Get county for snp direct from database
This commit is contained in:
14
app/src/test/java/io/github/wulkanowy/api/FixtureHelper.java
Normal file
14
app/src/test/java/io/github/wulkanowy/api/FixtureHelper.java
Normal file
@ -0,0 +1,14 @@
|
||||
package io.github.wulkanowy.api;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class FixtureHelper {
|
||||
|
||||
public static String getAsString(InputStream inputStream) {
|
||||
Scanner s = new Scanner(inputStream).useDelimiter("\\A");
|
||||
String input = s.hasNext() ? s.next() : "";
|
||||
|
||||
return input;
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package io.github.wulkanowy.api.notes;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.unitils.reflectionassert.ReflectionAssert;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import io.github.wulkanowy.api.FixtureHelper;
|
||||
|
||||
public class AchievementsListTest {
|
||||
|
||||
private String fixtureFilledFileName = "UwagiOsiagniecia-filled.html";
|
||||
|
||||
private String fixtureEmptyFileName = "UwagiOsiagniecia-empty.html";
|
||||
|
||||
private AchievementsList getSetUpAchievementsList(String fixtureFileName) throws Exception {
|
||||
String input = FixtureHelper.getAsString(getClass().getResourceAsStream(fixtureFileName));
|
||||
|
||||
Document notesPageDocument = Jsoup.parse(input);
|
||||
|
||||
Notes notes = Mockito.mock(Notes.class);
|
||||
Mockito.when(notes.getNotesPageDocument()).thenReturn(notesPageDocument);
|
||||
|
||||
return new AchievementsList(notes);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAllAchievementsFilledTest() throws Exception {
|
||||
List<String> expectedList = new ArrayList<>();
|
||||
expectedList.add("I miejsce w ogólnopolskim konkursie ortograficznym");
|
||||
expectedList.add("III miejsce w ogólnopolskim konkursie plastycznym");
|
||||
|
||||
List<String> actualList = getSetUpAchievementsList(
|
||||
fixtureFilledFileName).getAllAchievements();
|
||||
|
||||
Assert.assertEquals(2, actualList.size());
|
||||
ReflectionAssert.assertReflectionEquals(expectedList, actualList);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAllAchievementsEmptyTest() throws Exception {
|
||||
List<String> expectedList = new ArrayList<>();
|
||||
|
||||
List<String> actualList = getSetUpAchievementsList(
|
||||
fixtureEmptyFileName).getAllAchievements();
|
||||
|
||||
Assert.assertEquals(0, actualList.size());
|
||||
ReflectionAssert.assertReflectionEquals(expectedList, actualList);
|
||||
}
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
package io.github.wulkanowy.api.notes;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.unitils.reflectionassert.ReflectionAssert;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import io.github.wulkanowy.api.FixtureHelper;
|
||||
import io.github.wulkanowy.api.StudentAndParent;
|
||||
|
||||
public class NotesListTest {
|
||||
|
||||
private String fixtureFilledFileName = "UwagiOsiagniecia-filled.html";
|
||||
|
||||
private String fixtureEmptyFileName = "UwagiOsiagniecia-empty.html";
|
||||
|
||||
private NotesList getSetUpNotesList(String fixtureFileName) throws Exception {
|
||||
String input = FixtureHelper.getAsString(getClass().getResourceAsStream(fixtureFileName));
|
||||
|
||||
Document notesPageDocument = Jsoup.parse(input);
|
||||
|
||||
Notes notes = Mockito.mock(Notes.class);
|
||||
Mockito.when(notes.getNotesPageDocument()).thenReturn(notesPageDocument);
|
||||
StudentAndParent snp = Mockito.mock(StudentAndParent.class);
|
||||
Mockito.when(snp.getRowDataChildValue(Mockito.any(Element.class),
|
||||
Mockito.anyInt())).thenCallRealMethod();
|
||||
|
||||
return new NotesList(notes, snp);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAllNotesFilledTest() throws Exception {
|
||||
List<Note> expectedList = new ArrayList<>();
|
||||
expectedList.add(new Note()
|
||||
.setDate("06.06.2017")
|
||||
.setTeacher("Jan Kowalski [JK]")
|
||||
.setCategory("Zaangażowanie społeczne")
|
||||
.setContent("Pomoc przy pikniku charytatywnym")
|
||||
);
|
||||
expectedList.add(new Note()
|
||||
.setDate("01.12.2016")
|
||||
.setTeacher("Ochocka Zofia [PZ]")
|
||||
.setCategory("Reprezentowanie szkoły")
|
||||
.setContent("Udział w przygotowaniu spektaklu")
|
||||
);
|
||||
expectedList.add(new Note()
|
||||
.setDate("01.10.2016")
|
||||
.setTeacher("Kochański Leszek [KL]")
|
||||
.setCategory("Zachowanie na lekcji")
|
||||
.setContent("Przeszkadzanie w prowadzeniu lekcji")
|
||||
);
|
||||
|
||||
List<Note> actualList = getSetUpNotesList(fixtureFilledFileName).getAllNotes();
|
||||
|
||||
Assert.assertEquals(3, actualList.size());
|
||||
ReflectionAssert.assertReflectionEquals(expectedList, actualList);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAllNotesWhenEmpty() throws Exception {
|
||||
List<Note> actualList = getSetUpNotesList(fixtureEmptyFileName).getAllNotes();
|
||||
|
||||
List<Note> expectedList = new ArrayList<>();
|
||||
|
||||
Assert.assertEquals(0, actualList.size());
|
||||
ReflectionAssert.assertReflectionEquals(expectedList, actualList);
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="pl">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Witryna ucznia i rodzica – Uwagi i osiągnięcia</title>
|
||||
</head>
|
||||
<body>
|
||||
<main class="mainContainer">
|
||||
<div>
|
||||
<h1>Uwagi</h1>
|
||||
<h2>Brak informacji do wyświetlenia</h2>
|
||||
</div>
|
||||
<div>
|
||||
<h1>Osiągnięcia</h1>
|
||||
<h2>Brak informacji do wyświetlenia</h2>
|
||||
</div>
|
||||
</main>
|
||||
<footer>wersja: 17.05.0000.24042</footer>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,65 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="pl">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Witryna ucznia i rodzica – Uwagi i osiągnięcia</title>
|
||||
</head>
|
||||
<body>
|
||||
<main class="mainContainer">
|
||||
<div>
|
||||
<h1>Uwagi</h1>
|
||||
<h2>06.06.2017</h2>
|
||||
<article>
|
||||
<div class="daneWiersz">
|
||||
<div class="tytul">Nauczyciel:</div>
|
||||
<div class="wartosc">Jan Kowalski [JK]</div>
|
||||
</div>
|
||||
<div class="daneWiersz">
|
||||
<div class="tytul">Kategoria:</div>
|
||||
<div class="wartosc">Zaangażowanie społeczne</div>
|
||||
</div>
|
||||
<div class="daneWiersz">
|
||||
<div class="tytul">Treść:</div>
|
||||
<div class="wartosc">Pomoc przy pikniku charytatywnym</div>
|
||||
</div>
|
||||
</article>
|
||||
<h2>01.12.2016</h2>
|
||||
<article>
|
||||
<div class="daneWiersz">
|
||||
<div class="tytul">Nauczyciel:</div>
|
||||
<div class="wartosc">Ochocka Zofia [PZ]</div>
|
||||
</div>
|
||||
<div class="daneWiersz">
|
||||
<div class="tytul">Kategoria:</div>
|
||||
<div class="wartosc">Reprezentowanie szkoły</div>
|
||||
</div>
|
||||
<div class="daneWiersz">
|
||||
<div class="tytul">Treść:</div>
|
||||
<div class="wartosc">Udział w przygotowaniu spektaklu</div>
|
||||
</div>
|
||||
</article>
|
||||
<h2>01.10.2016</h2>
|
||||
<article>
|
||||
<div class="daneWiersz">
|
||||
<div class="tytul">Nauczyciel:</div>
|
||||
<div class="wartosc">Kochański Leszek [KL]</div>
|
||||
</div>
|
||||
<div class="daneWiersz">
|
||||
<div class="tytul">Kategoria:</div>
|
||||
<div class="wartosc">Zachowanie na lekcji</div>
|
||||
</div>
|
||||
<div class="daneWiersz">
|
||||
<div class="tytul">Treść:</div>
|
||||
<div class="wartosc">Przeszkadzanie w prowadzeniu lekcji</div>
|
||||
</div>
|
||||
</article>
|
||||
</div>
|
||||
<div>
|
||||
<h1>Osiągnięcia</h1>
|
||||
<article>I miejsce w ogólnopolskim konkursie ortograficznym</article>
|
||||
<article>III miejsce w ogólnopolskim konkursie plastycznym</article>
|
||||
</div>
|
||||
</main>
|
||||
<footer>wersja: 17.05.0000.24042</footer>
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user