Temporarily removes unit tests

This commit is contained in:
ericdecanini 2022-03-07 10:28:48 +01:00
parent 858923846d
commit 6338941885
4 changed files with 0 additions and 311 deletions

View File

@ -1,72 +0,0 @@
/*
* Copyright (c) 2022 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.matrix.android.sdk.internal.auth
import android.net.Uri
import io.mockk.every
import io.mockk.mockk
import io.mockk.mockkStatic
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runBlockingTest
import org.junit.Before
import org.junit.Test
import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig
import org.matrix.android.sdk.internal.auth.login.LoginType
import org.matrix.android.sdk.test.fakes.internal.FakeSessionManager
import org.matrix.android.sdk.test.fakes.internal.auth.FakePendingSessionStore
import org.matrix.android.sdk.test.fakes.internal.auth.FakeSessionParamsCreator
import org.matrix.android.sdk.test.fakes.internal.auth.FakeSessionParamsStore
import org.matrix.android.sdk.test.fixtures.CredentialsFixture.aCredentials
import org.matrix.android.sdk.test.fixtures.SessionParamsFixture.aSessionParams
@ExperimentalCoroutinesApi
class DefaultSessionCreatorTest {
private val fakeSessionParamsStore = FakeSessionParamsStore()
private val fakeSessionManager = FakeSessionManager()
private val fakePendingSessionStore = FakePendingSessionStore()
private val fakeSessionParamsCreator = FakeSessionParamsCreator()
private val sessionCreator = DefaultSessionCreator(
fakeSessionParamsStore.instance,
fakeSessionManager.instance,
fakePendingSessionStore.instance,
fakeSessionParamsCreator.instance,
)
@Before
fun setup() {
mockkStatic(Uri::class)
every { Uri.parse(any()) } returns mockk()
}
@Test
fun `when createSession, then session created`() = runBlockingTest {
val output = sessionCreator.createSession(credentials, homeServerConnectionConfig, LoginType.UNKNOWN)
fakePendingSessionStore.verifyPendingSessionDataCleared()
fakeSessionParamsCreator.verifyCreatedWithParameters(credentials, homeServerConnectionConfig, LoginType.UNKNOWN)
fakeSessionParamsStore.verifyParamsSaved(sessionParams)
fakeSessionManager.assertSessionCreatedWithParams(output, sessionParams)
}
companion object {
private val sessionParams = aSessionParams()
private val credentials = aCredentials()
private val homeServerConnectionConfig = HomeServerConnectionConfig.Builder().withHomeServerUri("homeserver").build()
}
}

View File

@ -1,73 +0,0 @@
/*
* Copyright (c) 2022 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.matrix.android.sdk.internal.auth
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runBlockingTest
import org.junit.Test
import org.matrix.android.sdk.internal.auth.login.LoginType
import org.matrix.android.sdk.test.fakes.internal.auth.FakeIsValidClientServerApiTask
@ExperimentalCoroutinesApi
class DefaultSessionParamsCreatorTest : DefaultSessionParamsCreatorTestBase() {
private val fakeIsValidClientServerApiTask = FakeIsValidClientServerApiTask()
private val sessionParamsCreator = DefaultSessionParamsCreator(fakeIsValidClientServerApiTask.instance)
@Test
fun `when create, then SessionParams created`() = runBlockingTest {
val output = sessionParamsCreator.create(credentials, homeServerConnectionConfig, LoginType.UNKNOWN)
assertExpectedSessionParams(output)
}
@Test
fun `given credentials contains homeServerUri, when create, then SessionParams created with validated credentials uri`() = runBlockingTest {
val output = sessionParamsCreator.create(credentialsWithHomeServer, homeServerConnectionConfig, LoginType.UNKNOWN)
fakeIsValidClientServerApiTask.verifyExecutionWithConfig(homeServerConnectionConfig.copy(homeServerUriBase = discoveryWithHomeServer.getHomeServerUri()))
assertExpectedSessionParamsWithHomeServer(output)
}
@Test
fun `given credentials homeServerUri is equal to homeServerConnectionConfig, when create, then do not validate`() = runBlockingTest {
val homeServerConnectionConfigWithCredentialsUri = homeServerConnectionConfig.copy(homeServerUriBase = discoveryWithHomeServer.getHomeServerUri())
val output = sessionParamsCreator.create(credentialsWithHomeServer, homeServerConnectionConfigWithCredentialsUri, LoginType.UNKNOWN)
fakeIsValidClientServerApiTask.verifyNoExecution()
assertExpectedSessionParamsWithHomeServer(output)
}
@Test
fun `given credentials contains identityServerUri, when create, then SessionParams created with credentials uri`() = runBlockingTest {
val output = sessionParamsCreator.create(credentialsWithIdentityServer, homeServerConnectionConfig, LoginType.UNKNOWN)
assertExpectedSessionParamsWithIdentityServer(output)
}
@Test
fun `given home server validation fails, when create, then do not use home server uri from credentials`() = runBlockingTest {
fakeIsValidClientServerApiTask.givenValidationFails()
val output = sessionParamsCreator.create(credentialsWithHomeServer, homeServerConnectionConfig, LoginType.UNKNOWN)
fakeIsValidClientServerApiTask.verifyExecutionWithConfig(homeServerConnectionConfig)
assertExpectedSessionParams(output)
}
}

View File

@ -1,72 +0,0 @@
/*
* Copyright (c) 2022 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.matrix.android.sdk.internal.auth
import android.net.Uri
import org.amshove.kluent.shouldBeEqualTo
import org.matrix.android.sdk.api.auth.data.DiscoveryInformation
import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig
import org.matrix.android.sdk.api.auth.data.SessionParams
import org.matrix.android.sdk.internal.auth.login.LoginType
import org.matrix.android.sdk.test.fixtures.CredentialsFixture.aCredentials
import org.matrix.android.sdk.test.fixtures.DiscoveryInformationFixture.aDiscoveryInformation
import org.matrix.android.sdk.test.fixtures.WellKnownBaseConfigFixture.aWellKnownBaseConfig
abstract class DefaultSessionParamsCreatorTestBase {
protected val discoveryWithHomeServer = aDiscoveryInformation(homeServer = aWellKnownBaseConfig("http://homeserver_url/"))
private val discoveryWithIdentityServer = aDiscoveryInformation(identityServer = aWellKnownBaseConfig("http://identity_server_url/"))
protected val credentials = aCredentials()
protected val credentialsWithHomeServer = aCredentials(discoveryInformation = discoveryWithHomeServer)
protected val credentialsWithIdentityServer = aCredentials(discoveryInformation = discoveryWithIdentityServer)
protected val homeServerConnectionConfig = HomeServerConnectionConfig.Builder().withHomeServerUri("homeserver").build()
protected fun assertExpectedSessionParams(sessionParams: SessionParams) {
sessionParams shouldBeEqualTo SessionParams(
credentials = credentials,
homeServerConnectionConfig = homeServerConnectionConfig,
isTokenValid = true,
loginType = LoginType.UNKNOWN,
)
}
protected fun assertExpectedSessionParamsWithHomeServer(sessionParams: SessionParams) {
sessionParams shouldBeEqualTo SessionParams(
credentials = credentialsWithHomeServer,
homeServerConnectionConfig = homeServerConnectionConfig.copy(homeServerUriBase = discoveryWithHomeServer.getHomeServerUri()),
isTokenValid = true,
loginType = LoginType.UNKNOWN,
)
}
protected fun assertExpectedSessionParamsWithIdentityServer(sessionParams: SessionParams) {
sessionParams shouldBeEqualTo SessionParams(
credentials = credentialsWithHomeServer,
homeServerConnectionConfig = homeServerConnectionConfig.copy(identityServerUri = discoveryWithIdentityServer.getIdentityServerUri()),
isTokenValid = true,
loginType = LoginType.UNKNOWN,
)
}
private fun DiscoveryInformation.getIdentityServerUri() = identityServer?.baseURL?.convertToUri()!!
protected fun DiscoveryInformation.getHomeServerUri() = homeServer?.baseURL?.convertToUri()!!
private fun String.convertToUri() = trim { it == '/' }
.takeIf { it.isNotBlank() }
.let { Uri.parse(it) }
}

View File

@ -1,94 +0,0 @@
/*
* Copyright (c) 2022 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.matrix.android.sdk.internal.auth.db
import org.junit.Test
import org.matrix.android.sdk.test.fakes.internal.auth.db.sessionparams.FakeSessionParamsMapperMoshi
import org.matrix.android.sdk.test.fakes.internal.auth.db.sessionparams.FakeSessionParamsMapperMoshi.Companion.nullSessionParams
import org.matrix.android.sdk.test.fakes.internal.auth.db.sessionparams.FakeSessionParamsMapperMoshi.Companion.nullSessionParamsEntity
import org.matrix.android.sdk.test.fakes.internal.auth.db.sessionparams.FakeSessionParamsMapperMoshi.Companion.sessionParams
import org.matrix.android.sdk.test.fakes.internal.auth.db.sessionparams.FakeSessionParamsMapperMoshi.Companion.sessionParamsEntity
class SessionParamsMapperTest {
private val fakeMoshi = FakeSessionParamsMapperMoshi()
private val sessionParamsMapper = SessionParamsMapper(fakeMoshi.instance)
@Test
fun `when mapping entity, then map as SessionParams`() {
val output = sessionParamsMapper.map(sessionParamsEntity)
fakeMoshi.assertSessionParamsWasMappedSuccessfully(output)
}
@Test
fun `when mapping null entity, then return null`() {
val output = sessionParamsMapper.map(nullSessionParamsEntity)
fakeMoshi.assertSessionParamsIsNull(output)
}
@Test
fun `given null credentials json deserialization, when mapping entity, then return null`() {
fakeMoshi.credentialsJsonAdapter.givenNullDeserialization()
val output = sessionParamsMapper.map(sessionParamsEntity)
fakeMoshi.assertSessionParamsIsNull(output)
}
@Test
fun `given null homeServerConnectionConfig json deserialization, when mapping entity, then return null`() {
fakeMoshi.homeServerConnectionConfigAdapter.givenNullDeserialization()
val output = sessionParamsMapper.map(sessionParamsEntity)
fakeMoshi.assertSessionParamsIsNull(output)
}
@Test
fun `when mapping sessionParams, then map as SessionParamsEntity`() {
val output = sessionParamsMapper.map(sessionParams)
fakeMoshi.assertSessionParamsEntityWasMappedSuccessfully(output)
}
@Test
fun `when mapping null sessionParams, then return null`() {
val output = sessionParamsMapper.map(nullSessionParams)
fakeMoshi.assertSessionParamsEntityWasMappedSuccessfully(output)
}
@Test
fun `given null credentials json serialization, when mapping sessionParams, then return null`() {
fakeMoshi.credentialsJsonAdapter.givenNullSerialization()
val output = sessionParamsMapper.map(sessionParams)
fakeMoshi.assertSessionParamsEntityIsNull(output)
}
@Test
fun `given null homeServerConnectionConfig json serialization, when mapping sessionParams, then return null`() {
fakeMoshi.homeServerConnectionConfigAdapter.givenNullSerialization()
val output = sessionParamsMapper.map(sessionParams)
fakeMoshi.assertSessionParamsEntityIsNull(output)
}
}