Skip to content

Commit

Permalink
Merge pull request #33 from xwiki-contrib/ANDAUTH-38
Browse files Browse the repository at this point in the history
ANDAUTH - 38 Allow creating several accounts
  • Loading branch information
InsanusMokrassar committed Jul 25, 2019
2 parents c603527 + 0724f8a commit 6534576
Show file tree
Hide file tree
Showing 63 changed files with 2,173 additions and 909 deletions.
20 changes: 10 additions & 10 deletions LICENSE
Expand Up @@ -79,7 +79,7 @@ Public License permits more lax criteria for linking other code with
the library.

We call this license the "Lesser" General Public License because it
does Less to protect the user's freedom than the ordinary General
does Less to protect the userAccount's freedom than the ordinary General
Public License. It also provides other free software developers Less
of an advantage over competing non-free programs. These disadvantages
are the reason we use the ordinary General Public License for many
Expand All @@ -102,7 +102,7 @@ operating system, as well as its variant, the GNU/Linux operating
system.

Although the Lesser General Public License is Less protective of the
users' freedom, it does ensure that the user of a program that is
users' freedom, it does ensure that the userAccount of a program that is
linked with the Library has the freedom and the wherewithal to run
that program using a modified version of the Library.

Expand Down Expand Up @@ -280,7 +280,7 @@ Library is used in it and that the Library and its use are covered by
this License. You must supply a copy of this License. If the work
during execution displays copyright notices, you must include the
copyright notice for the Library among them, as well as a reference
directing the user to the copy of this License. Also, you must do one
directing the userAccount to the copy of this License. Also, you must do one
of these things:

a) Accompany the work with the complete corresponding
Expand All @@ -289,31 +289,31 @@ of these things:
Sections 1 and 2 above); and, if the work is an executable linked
with the Library, with the complete machine-readable "work that
uses the Library", as object code and/or source code, so that the
user can modify the Library and then relink to produce a modified
userAccount can modify the Library and then relink to produce a modified
executable containing the modified Library. (It is understood
that the user who changes the contents of definitions files in the
that the userAccount who changes the contents of definitions files in the
Library will not necessarily be able to recompile the application
to use the modified definitions.)

b) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (1) uses at run time a
copy of the library already present on the user's computer system,
copy of the library already present on the userAccount's computer system,
rather than copying library functions into the executable, and (2)
will operate properly with a modified version of the library, if
the user installs one, as long as the modified version is
the userAccount installs one, as long as the modified version is
interface-compatible with the version that the work was made with.

c) Accompany the work with a written offer, valid for at
least three years, to give the same user the materials
least three years, to give the same userAccount the materials
specified in Subsection 6a, above, for a charge no more
than the cost of performing this distribution.

d) If distribution of the work is made by offering access to copy
from a designated place, offer equivalent access to copy the above
specified materials from the same place.

e) Verify that the user has already received a copy of these
materials or that you have already sent this user a copy.
e) Verify that the userAccount has already received a copy of these
materials or that you have already sent this userAccount a copy.

For an executable, the required form of the "work that uses the
Library" must include any data and utility programs needed for
Expand Down
47 changes: 16 additions & 31 deletions app/build.gradle
Expand Up @@ -9,8 +9,8 @@ android {
defaultConfig {
minSdkVersion rootProject.minSdkVersion
targetSdkVersion rootProject.targetSdkVersion
versionCode 37
versionName "0.6"
versionCode 38
versionName "0.7"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down Expand Up @@ -47,52 +47,37 @@ dependencies {
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlin_coroutines_version"
implementation "androidx.core:core-ktx:$kotlin_android_extensions_version"

// Room Library
implementation "androidx.room:room-runtime:2.1.0"
implementation "androidx.room:room-ktx:2.1.0"
kapt "androidx.room:room-compiler:2.1.0"

// For ViewModel lifecycle
kapt "androidx.lifecycle:lifecycle-compiler:2.2.0-alpha02"
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0-alpha02"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0-alpha02"

//rxjava Dependencies
implementation 'io.reactivex:rxandroid:1.1.0'
implementation 'io.reactivex:rxjava:1.3.0'

// For Local Unit Tests

// Required -- JUnit 4 framework
testImplementation 'junit:junit:4.12'

// Part of Instrumented Tests or Local Test

// Optional -- Mockito framework
testImplementation 'org.mockito:mockito-core:2.8.9'

// Optional -- Robolectric library

//testImplementation "org.robolectric:robolectric:3.0"

// For android test support (it depends on emulator)
androidTestImplementation "com.android.support:support-annotations:$rootProject.supportLibraryVersion"

// Removed Tue Apr 2 14:02:28 HKT 2019 after updating of dependencies and removing of redundant tests
// androidTestImplementation 'com.android.support.test:runner:1.0.2'
// androidTestImplementation 'com.android.support.test:rules:1.0.2'

// Optional -- Hamcrest library

//androidTestImplementation 'org.hamcrest:hamcrest-library:1.3'

// Optional -- Robotium library
androidTestImplementation 'com.jayway.android.robotium:robotium-solo:5.5.4'

//For androidx test support
androidTestImplementation "androidx.test:core-ktx:1.2.0"
androidTestImplementation "androidx.test.ext:junit-ktx:1.1.1"
androidTestImplementation "androidx.arch.core:core-testing:2.0.1"

// Optional -- UI testing with Espresso
// androidTestImplementation 'com.android.support.test.e.presso:espresso-core:3.0.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'androidx.test.espresso:espresso-idling-resource:3.2.0'

// For ViewModel lifecycle
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'

// Optional -- UI testing with UI Automator

//androidTestImplementation 'com.android.support.test.uiautomator:uiautomator-v23:2.1.1'
// https://mvnrepository.com/artifact/org.xwiki.platform/xwiki-platform-distribution-flavor-data-hsqldb
implementation "org.xwiki.platform:xwiki-platform-distribution-flavor-data-hsqldb:11.4"

implementation 'com.facebook.stetho:stetho:1.5.1'
}
@@ -0,0 +1,99 @@
package org.xwiki.android.sync.DB

import android.content.Context
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import androidx.room.Room
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import junit.framework.Assert.assertEquals
import junit.framework.Assert.assertTrue
import kotlinx.coroutines.runBlocking
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.xwiki.android.sync.XWIKI_DEFAULT_SERVER_ADDRESS
import org.xwiki.android.sync.contactdb.AppDatabase
import org.xwiki.android.sync.contactdb.UserAccount
import org.xwiki.android.sync.contactdb.dao.AccountsDao
import java.io.IOException

@RunWith(AndroidJUnit4::class)
class AccountsDaoTest {

@get:Rule
val instantTaskExecutorRule = InstantTaskExecutorRule()

private lateinit var accountsDao: AccountsDao
private lateinit var db: AppDatabase

@Before
fun createDb() {
val context = ApplicationProvider.getApplicationContext<Context>()
// Using an in-memory database because the information stored here disappears when the
// process is killed.
db = Room.inMemoryDatabaseBuilder(context, AppDatabase::class.java)
// Allowing main thread queries, just for testing.
.allowMainThreadQueries()
.build()
accountsDao = db.usersDao()
}

@After
@Throws(IOException::class)
fun closeDb() {
db.close()
}

@Test
@Throws(Exception::class)
fun insertAndGetUser() = runBlocking {
val user = UserAccount(
"testUser1",
XWIKI_DEFAULT_SERVER_ADDRESS
)
accountsDao.insertAccount(user)
val allUsers = accountsDao.getAllAccount()
assertEquals(allUsers[0].accountName, user.accountName)
}

@Test
@Throws(Exception::class)
fun getAllUsers() = runBlocking {
val user1 = UserAccount(
"testUser1",
XWIKI_DEFAULT_SERVER_ADDRESS
)
accountsDao.insertAccount(user1)
val user2 = UserAccount(
"testUser2",
XWIKI_DEFAULT_SERVER_ADDRESS
)
accountsDao.insertAccount(user2)
val allUsers = accountsDao.getAllAccount()
assertEquals(allUsers[0].accountName, user1.accountName)
assertEquals(allUsers[1].accountName, user2.accountName)
}

@Test
@Throws(Exception::class)
fun deleteAllUsers() = runBlocking {
val user1Id = accountsDao.insertAccount(
UserAccount(
"testUser1",
XWIKI_DEFAULT_SERVER_ADDRESS
)
)
val user2Id = accountsDao.insertAccount(
UserAccount(
"testUser2",
XWIKI_DEFAULT_SERVER_ADDRESS
)
)
accountsDao.deleteUser(user1Id)
accountsDao.deleteUser(user2Id)
val allUsers = accountsDao.getAllAccount()
assertTrue(allUsers.isEmpty())
}
}
@@ -0,0 +1,44 @@
package org.xwiki.android.sync.DB

/*
* Copyright (C) 2017 The Android Open Source Project
*
* 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.
*/

import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer

import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit

/**
* Get the value from a LiveData object. We're waiting for LiveData to emit, for 2 seconds.
* Once we got a notification via onChanged, we stop observing.
*/
@Throws(InterruptedException::class)
fun <T> LiveData<T>.waitForValue(): T {
val data = arrayOfNulls<Any>(1)
val latch = CountDownLatch(1)
val observer = object : Observer<T> {
override fun onChanged(o: T?) {
data[0] = o
latch.countDown()
this@waitForValue.removeObserver(this)
}
}
this.observeForever(observer)
latch.await(2, TimeUnit.SECONDS)

return data[0] as T
}
@@ -1,21 +1,29 @@
package org.xwiki.android.sync.activities

import android.accounts.AccountManager
import android.content.Context
import android.content.Intent
import androidx.lifecycle.LifecycleObserver
import androidx.room.Room
import androidx.test.core.app.ActivityScenario
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.MediumTest
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.xwiki.android.sync.appContext
import android.content.Intent
import androidx.test.core.app.ApplicationProvider
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.IdlingRegistry
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.MediumTest
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.xwiki.android.sync.ACCOUNT_TYPE
import org.xwiki.android.sync.R
import org.xwiki.android.sync.XWIKI_DEFAULT_SERVER_ADDRESS
import org.xwiki.android.sync.appContext
import org.xwiki.android.sync.contactdb.AppDatabase
import org.xwiki.android.sync.contactdb.UserAccount
import org.xwiki.android.sync.utils.idlingResource


Expand All @@ -30,8 +38,30 @@ open class SyncSettingsActivityTest : LifecycleObserver {

@Before
open fun setUp() {
val context = ApplicationProvider.getApplicationContext<Context>()
// Using an in-memory database because the information stored here disappears when the
// process is killed.
val db = Room.inMemoryDatabaseBuilder(context, AppDatabase::class.java)
// Allowing main thread queries, just for testing.
.allowMainThreadQueries()
.build()
val userDao = db.usersDao()

val user = UserAccount(
"testUser1",
XWIKI_DEFAULT_SERVER_ADDRESS
)

userDao.insertAccount(user)


IdlingRegistry.getInstance().register(idlingResource)
activityScenario = ActivityScenario.launch(SyncSettingsActivity::class.java)
val i = Intent(appContext, SyncSettingsActivity::class.java)
i.putExtra(AccountManager.KEY_ACCOUNT_NAME, user.accountName)
i.putExtra(AccountManager.KEY_ACCOUNT_TYPE, ACCOUNT_TYPE)
i.putExtra("Test", true)

activityScenario = ActivityScenario.launch(i)
}

@Test
Expand Down
Expand Up @@ -7,19 +7,19 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.test.core.app.ActivityScenario
import androidx.test.espresso.Espresso.onView
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith
import org.xwiki.android.sync.ACCOUNT_TYPE
import org.xwiki.android.sync.AUTHTOKEN_TYPE_FULL_ACCESS
import org.xwiki.android.sync.appContext
import org.junit.Before
import androidx.test.espresso.IdlingRegistry
import androidx.test.espresso.action.ViewActions.*
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.MediumTest
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.xwiki.android.sync.ACCOUNT_TYPE
import org.xwiki.android.sync.AUTHTOKEN_TYPE_FULL_ACCESS
import org.xwiki.android.sync.R
import org.xwiki.android.sync.appContext
import org.xwiki.android.sync.utils.idlingResource

/**
Expand Down

0 comments on commit 6534576

Please sign in to comment.