Try to fix tests

This commit is contained in:
Mikołaj Pich 2018-08-31 02:00:58 +02:00
parent 09637dbca2
commit beae2274cd
No known key found for this signature in database
GPG key ID: F62B26E36D4C4BAA
4 changed files with 34 additions and 16 deletions

View file

@ -12,6 +12,8 @@ jobs:
- restore_cache: - restore_cache:
key: cache-{{ checksum "build.gradle" }} key: cache-{{ checksum "build.gradle" }}
- run: ./.circleci/host-hotfix.sh
- run: ./gradlew build -x check --no-daemon --stacktrace --console=plain -PdisablePreDex - run: ./gradlew build -x check --no-daemon --stacktrace --console=plain -PdisablePreDex
- run: ./gradlew check jacocoTestReport --no-daemon --stacktrace --console=plain -PdisablePreDex - run: ./gradlew check jacocoTestReport --no-daemon --stacktrace --console=plain -PdisablePreDex

7
.circleci/host-hotfix.sh Executable file
View file

@ -0,0 +1,7 @@
#!/usr/bin/env bash
echo "127.0.0.1 fakelog.localhost" | sudo tee -a /etc/hosts
echo "127.0.0.1 adfs.fakelog.localhost" | sudo tee -a /etc/hosts
echo "127.0.0.1 cufs.fakelog.localhost" | sudo tee -a /etc/hosts
echo "127.0.0.1 uonetplus.fakelog.localhost" | sudo tee -a /etc/hosts
echo "127.0.0.1 uonetplus-opiekun.fakelog.localhost" | sudo tee -a /etc/hosts

View file

@ -16,6 +16,16 @@ import org.junit.Test
class LoginTest : BaseTest() { class LoginTest : BaseTest() {
private val normal by lazy {
LoginRepository("http", "localhost:3000", "default",
getService(LoginService::class.java, "http://localhost:3000/"))
}
private val adfs by lazy {
LoginRepository("http", "localhost:3001", "default",
getService(LoginService::class.java, "http://localhost:3001/"))
}
private lateinit var server: MockWebServer private lateinit var server: MockWebServer
@Before @Before
@ -23,11 +33,6 @@ class LoginTest : BaseTest() {
server = MockWebServer() server = MockWebServer()
} }
private fun getRepo(url: String): LoginRepository {
return LoginRepository("http", url.removePrefix("http://").removeSuffix("/"), "default",
getService(LoginService::class.java, url))
}
@Test @Test
fun adfsTest() { fun adfsTest() {
server.enqueue(MockResponse().setBody(LoginTest::class.java.getResource("ADFS-form-1.html").readText())) server.enqueue(MockResponse().setBody(LoginTest::class.java.getResource("ADFS-form-1.html").readText()))
@ -37,7 +42,7 @@ class LoginTest : BaseTest() {
server.enqueue(MockResponse().setBody(LoginTest::class.java.getResource("Login-success.html").readText())) server.enqueue(MockResponse().setBody(LoginTest::class.java.getResource("Login-success.html").readText()))
server.start(3001) server.start(3001)
val res = getRepo(server.url("/").toString()).login("jan@fakelog.cf", "jan123").blockingGet() val res = adfs.login("jan@fakelog.cf", "jan123").blockingGet()
assertTrue(res.schools.isNotEmpty()) assertTrue(res.schools.isNotEmpty())
} }
@ -48,7 +53,7 @@ class LoginTest : BaseTest() {
server.enqueue(MockResponse().setBody(LoginTest::class.java.getResource("Login-success.html").readText())) server.enqueue(MockResponse().setBody(LoginTest::class.java.getResource("Login-success.html").readText()))
server.start(3000) server.start(3000)
val res = getRepo(server.url("/").toString()).login("jan@fakelog.cf", "jan123").blockingGet() val res = normal.login("jan@fakelog.cf", "jan123").blockingGet()
assertTrue(res.schools.isNotEmpty()) assertTrue(res.schools.isNotEmpty())
} }
@ -60,7 +65,7 @@ class LoginTest : BaseTest() {
server.enqueue(MockResponse().setBody(LoginTest::class.java.getResource("Logowanie-adfs-zle-haslo.html").readText())) server.enqueue(MockResponse().setBody(LoginTest::class.java.getResource("Logowanie-adfs-zle-haslo.html").readText()))
server.start(3001) server.start(3001)
val res = getRepo(server.url("/").toString()).login("jan@fakelog.cf", "jan1234") val res = adfs.login("jan@fakelog.cf", "jan1234")
val observer = TestObserver<HomepageResponse>() val observer = TestObserver<HomepageResponse>()
res.subscribe(observer) res.subscribe(observer)
observer.assertTerminated() observer.assertTerminated()
@ -73,7 +78,7 @@ class LoginTest : BaseTest() {
server.enqueue(MockResponse().setBody(LoginTest::class.java.getResource("Logowanie-normal-zle-haslo.html").readText())) server.enqueue(MockResponse().setBody(LoginTest::class.java.getResource("Logowanie-normal-zle-haslo.html").readText()))
server.start(3000) server.start(3000)
val res = getRepo(server.url("/").toString()).login("jan@fakelog.cf", "jan1234") val res = normal.login("jan@fakelog.cf", "jan1234")
val observer = TestObserver<HomepageResponse>() val observer = TestObserver<HomepageResponse>()
res.subscribe(observer) res.subscribe(observer)
observer.assertTerminated() observer.assertTerminated()
@ -86,7 +91,7 @@ class LoginTest : BaseTest() {
server.enqueue(MockResponse().setBody(LoginTest::class.java.getResource("Logowanie-brak-dostepu.html").readText())) server.enqueue(MockResponse().setBody(LoginTest::class.java.getResource("Logowanie-brak-dostepu.html").readText()))
server.start(3000) server.start(3000)
val res = getRepo(server.url("/").toString()).login("jan@fakelog.cf", "jan123") val res = normal.login("jan@fakelog.cf", "jan123")
val observer = TestObserver<HomepageResponse>() val observer = TestObserver<HomepageResponse>()
res.subscribe(observer) res.subscribe(observer)
observer.assertTerminated() observer.assertTerminated()

View file

@ -23,6 +23,16 @@ class RegisterTest : BaseTest() {
server = MockWebServer() server = MockWebServer()
} }
private val login by lazy {
LoginRepository("http", "localhost:3000", "default",
getService(LoginService::class.java, "http://localhost:3000/"))
}
private val normal by lazy {
RegisterRepository("default", "jan@fakelog.localhost", "jan123", login,
getService(StudentAndParentService::class.java, "http://localhost:3000/"))
}
@Test @Test
fun pupilsTest() { fun pupilsTest() {
server.enqueue(MockResponse().setBody(LoginTest::class.java.getResource("Logowanie-uonet.html").readText())) server.enqueue(MockResponse().setBody(LoginTest::class.java.getResource("Logowanie-uonet.html").readText()))
@ -36,12 +46,6 @@ class RegisterTest : BaseTest() {
server.enqueue(MockResponse().setBody(LoginTest::class.java.getResource("Logowanie-brak-dostepu.html").readText())) server.enqueue(MockResponse().setBody(LoginTest::class.java.getResource("Logowanie-brak-dostepu.html").readText()))
server.start(3000) server.start(3000)
val url = server.url("/").toString()
val normal = RegisterRepository("default", "jan@fakelog.localhost", "jan123",
LoginRepository("http", url.removePrefix("http://").removeSuffix("/"), "default",
getService(LoginService::class.java, url)),
getService(StudentAndParentService::class.java, url))
val res = normal.getPupils().blockingGet() val res = normal.getPupils().blockingGet()
assertEquals(1, res.size) assertEquals(1, res.size)