Skip to content
This repository has been archived by the owner on Mar 24, 2021. It is now read-only.

Commit

Permalink
Added Instrumentation Tests
Browse files Browse the repository at this point in the history
Reverted back to original

Edited by mistake
  • Loading branch information
crowded committed Dec 11, 2019
1 parent 611b8d8 commit 927b553
Show file tree
Hide file tree
Showing 16 changed files with 2,609 additions and 26 deletions.
3 changes: 3 additions & 0 deletions offix/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ buildscript {
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
}
}
apollo {
generateKotlinModels = true // or false
}

task cleanBuildPublish(type: GradleBuild) {
tasks = ['clean', 'build', 'bintrayUpload' , 'sourcesJar' ,'javadocJar' , 'javadoc']
Expand Down

This file was deleted.

100 changes: 100 additions & 0 deletions offix/src/androidTest/java/org/aerogear/offix/MainInstrumentedTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package org.aerogear.offix

import android.support.test.InstrumentationRegistry
import android.support.test.runner.AndroidJUnit4
import android.util.Log
import com.apollographql.apollo.ApolloCall
import com.apollographql.apollo.api.Input
import com.apollographql.apollo.api.Response
import com.apollographql.apollo.exception.ApolloException
import org.aerogear.offix.Offline.Companion.getDb
import org.aerogear.offix.persistence.Mutation
import org.aerogear.offix.type.TaskInput
import org.json.JSONObject

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* @see [Testing documentation](http://d.android.com/tools/testing)
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
val input = TaskInput(Input.optional(0), "title", "desc", "test")
val mutation = CreateTaskMutation(input)
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getTargetContext()
assertEquals("org.aerogear.offixsdk.test", appContext.packageName)
}

@Test
fun addMutationCheck(){
getDb()?.mutationDao()?.deleteAllMutations()
var a = getDb()?.mutationDao()?.getAllMutations()?.size
assertEquals(0, a)
val m = Mutation(mutation.operationId(), mutation.queryDocument(), mutation.name(), JSONObject(mutation.variables().valueMap()), mutation.responseFieldMapper().javaClass.simpleName)
getDb()!!.mutationDao().insertMutation(m)
a = getDb()?.mutationDao()?.getAllMutations()?.size
assertEquals(1, a)
}

@Test
fun discreteObjectCheck(){
val m1 = Mutation(mutation.operationId(), mutation.queryDocument(), mutation.name(), JSONObject(mutation.variables().valueMap()), mutation.responseFieldMapper().javaClass.simpleName)
val m2 = getDb()!!.mutationDao().getAMutation(0)
assertTrue(!m1.equals(m2))
}

@Test
fun deleteMutationCheck(){
var a = getDb()?.mutationDao()?.getAllMutations()?.size
assertEquals(1, a)
getDb()?.mutationDao()?.deleteAllMutations()
a = getDb()?.mutationDao()?.getAllMutations()?.size
assertEquals(0, a)
}

@Test
fun getAllTasksWorking(){
val callback = object : ApolloCall.Callback<FindAllTasksQuery.Data>() {

override fun onFailure(e: ApolloException) {
e.printStackTrace()
Log.e("TAG", "getTasks ----$e ")
assert(false)
}

override fun onResponse(response: Response<FindAllTasksQuery.Data>) {
Log.e("TAG", "on Response getTasks : Data ${response.data()}")
assert(true)
}
}
Offline.apClient?.query(FindAllTasksQuery())?.watcher()
?.enqueueAndWatch(callback)
}

@Test
fun getAllUsersWorking(){
val callback = object : ApolloCall.Callback<FindAllUsersQuery.Data>() {

override fun onFailure(e: ApolloException) {
e.printStackTrace()
Log.e("TAG", "getTasks ----$e ")
assert(false)
}

override fun onResponse(response: Response<FindAllUsersQuery.Data>) {
Log.e("TAG", "on Response getTasks : Data ${response.data()}")
assert(true)
}
}
Offline.apClient?.query(FindAllUsersQuery())?.watcher()
?.enqueueAndWatch(callback)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
mutation checkAndUpdateTask($id: ID!, $title: String, $description: String, $version: Int!, $status: String!){
checkAndUpdateTask(id: $id, title: $title, description: $description, version: $version, status: $status){
id
version
title
description
status
creationMetadata{
createdDate
createdBy{
id
firstName
lastName
title
email
}
}
assignedTo{
id
firstName
lastName
title
email
}
}
}
31 changes: 31 additions & 0 deletions offix/src/main/graphql/org.aerogear.offix/createTask.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
mutation createTask($input: TaskInput!){
createTask(input: $input){
id
version
title
description
status
creationMetadata{
createdDate
taskId
createdBy{
id
firstName
lastName
title
email
taskId
creationmetadataId
}
}
assignedTo{
id
firstName
lastName
title
email
taskId
creationmetadataId
}
}
}
11 changes: 11 additions & 0 deletions offix/src/main/graphql/org.aerogear.offix/createUser.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
mutation createUser($input: UserInput!){
createUser(input: $input){
id
firstName
lastName
title
email
taskId
creationmetadataId
}
}
31 changes: 31 additions & 0 deletions offix/src/main/graphql/org.aerogear.offix/findAllTasks.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
query findAllTasks{
findAllTasks{
id
version
title
description
status
creationMetadata{
createdDate
taskId
createdBy{
id
firstName
lastName
title
email
taskId
creationmetadataId
}
}
assignedTo{
id
firstName
lastName
title
email
taskId
creationmetadataId
}
}
}
11 changes: 11 additions & 0 deletions offix/src/main/graphql/org.aerogear.offix/findAllUsers.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
query findAllUsers{
findAllUsers{
id
firstName
lastName
title
email
taskId
creationmetadataId
}
}
11 changes: 11 additions & 0 deletions offix/src/main/graphql/org.aerogear.offix/findUsers.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
query findUsers($fields: UserFilter!){
findUsers(fields: $fields){
id
firstName
lastName
title
email
taskId
creationmetadataId
}
}
31 changes: 31 additions & 0 deletions offix/src/main/graphql/org.aerogear.offix/newTask.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
subscription newTask{
newTask{
id
version
title
description
status
creationMetadata{
createdDate
taskId
createdBy{
id
firstName
lastName
title
email
taskId
creationmetadataId
}
}
assignedTo{
id
firstName
lastName
title
email
taskId
creationmetadataId
}
}
}
11 changes: 11 additions & 0 deletions offix/src/main/graphql/org.aerogear.offix/newUser.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
subscription newUser{
newUser{
id
firstName
lastName
title
email
taskId
creationmetadataId
}
}
Loading

0 comments on commit 927b553

Please sign in to comment.