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

Added offix library unit tests #192

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions offix/src/main/java/org/aerogear/offix/MutationDataCheck.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package org.aerogear.offix

import org.json.JSONObject
import com.apollographql.apollo.api.OperationName

object MutationDataCheck{
fun checkOperationID(x1: String): String{
if(validateOperationID(x1)){
return x1
}
throw Exception("Exception: NullOperationID")
}
fun checkOperationName(x2: OperationName): OperationName{
if(validateOperationName(x2)){
return x2
}
throw Exception("Exception: EmptyOperationName")
}
fun checkOperationDoc(x3: String): String{
if(validateOperationDoc(x3)){
return x3
}
throw Exception("Exception: NullOperationDoc")
}
fun checkJSONObject(x4: JSONObject): JSONObject{
if(validateJSONObject(x4)){
return x4
}
throw Exception("Exception: NullJSONObject")
}
fun validateOperationID(x1: String): Boolean{
if (x1.isNullOrBlank()){
return false//Exception("Exception: NullOperationID")
}
return true
}
fun validateOperationName(x2: OperationName): Boolean{
if (x2.name().isBlank()){
return false//throw Exception("Exception: EmptyOperationName")
}
return true
}
fun validateOperationDoc(x3: String): Boolean{
if (x3.isNullOrBlank()){
return false//throw Exception("Exception: NullOperationDoc")
}
return true
}
fun validateJSONObject(x4: JSONObject): Boolean{
if (x4 == null){
return false//throw Exception("Exception: NullJSONObject")
}
return true
}
}
9 changes: 5 additions & 4 deletions offix/src/main/java/org/aerogear/offix/Offix.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.apollographql.apollo.api.Input
import com.apollographql.apollo.api.Mutation
import com.apollographql.apollo.api.Operation
import org.json.JSONObject
import org.aerogear.offix.MutationDataCheck

/*
conflictedMutationClass variable stores the name of the mutation class in which conflict has occurred.
Expand All @@ -19,11 +20,11 @@ var conflictedMutationClass=""
*/
fun getPersistenceMutation(mutation: Mutation<Operation.Data, Any, Operation.Variables>): org.aerogear.offix.persistence.Mutation {

val operationId = mutation.operationId()
val operationDoc = mutation.queryDocument()
val operationName = mutation.name()
val operationId = MutationDataCheck.checkOperationID(mutation.operationId())
val operationDoc = MutationDataCheck.checkOperationDoc(mutation.queryDocument())
val operationName = MutationDataCheck.checkOperationName(mutation.name())
val valMap = mutation.variables().valueMap()
val jsonObject = JSONObject(valMap)
val jsonObject = MutationDataCheck.checkJSONObject(JSONObject(valMap))
val responseClassName = mutation.javaClass.name

/* Make an object of com.aerogear.offix.persistence.Mutation
Expand Down
46 changes: 46 additions & 0 deletions offix/src/test/java/org/aerogear/offix/OffixLibraryUnitTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.aerogear.offix

import com.apollographql.apollo.api.OperationName
import com.google.gson.JsonParser
import org.json.JSONObject
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test


/**
* This Offix Library unit test, will execute validate offix mutation data values for null and blank.
*
*/
class OffixLibraryUnitTest {
@Test
fun validateOperationIDisTrue(){
assertTrue(MutationDataCheck.validateOperationID("2"))
}
@Test
fun validateOperationIDisFalse(){
//String xx = null
assertFalse(MutationDataCheck.validateOperationID(""))
}
@Test
fun validateOperationNameisTrue(){
assertTrue(MutationDataCheck.validateOperationName(OperationName { "testoperation" }))
}
@Test
fun validateOperationNameisFalse(){
assertFalse(MutationDataCheck.validateOperationName(OperationName { "" }))
}
@Test
fun validateOperationDocisTrue(){
assertTrue(MutationDataCheck.validateOperationDoc("doc value"))
}
@Test
fun validateOperationDocisFalse(){
assertFalse(MutationDataCheck.validateOperationDoc(""))
}
@Test
fun validateJSONObjectisTrue(){
val jo = JSONObject("""{"name":"test name", "age":25}""")
assertTrue(MutationDataCheck.validateJSONObject(jo))
}
}