Skip to content
This repository has been archived by the owner on Oct 3, 2020. It is now read-only.

Commit

Permalink
added delete feature test
Browse files Browse the repository at this point in the history
  • Loading branch information
fulton committed Feb 21, 2020
1 parent f39e84d commit af48c28
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
14 changes: 8 additions & 6 deletions src/main/java/com/andromeda/araserver/pages/UpdateDB.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package com.andromeda.araserver.pages

import com.andromeda.araserver.util.CosmosClients
import com.andromeda.araserver.util.OutputModel
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.microsoft.azure.documentdb.*
import org.json.JSONObject
import java.util.*
import kotlin.collections.ArrayList


class UpdateDB {
Expand All @@ -27,11 +24,16 @@ class UpdateDB {
}
val dbLink = System.getenv("IOTDB")
val client = DocumentClient("https://ara-account-data.documents.azure.com:443/", dbLink, ConnectionPolicy(), ConsistencyLevel.Session)
update(client, key!!, id!!, prop!!, newVal!!)
update(client, id!!, prop!!, newVal!!)
return "ok"
}

private fun update(client:DocumentClient, key: String, id:String, prop:String, newVal:Any){
fun update(
client: DocumentClient,
id: String,
prop: String,
newVal: Any
){

val options = FeedOptions()
options.enableCrossPartitionQuery = true
Expand All @@ -57,7 +59,7 @@ class UpdateDB {

}
if(key.equals("")) throw SecurityException("not a valid user")
update(CosmosClients.client, key!!, id!!, prop!!, newVal)
update(CosmosClients.client, id!!, prop!!, newVal)
return "ok"
}
fun fromJson(jsontxt: String?): Any {
Expand Down
15 changes: 9 additions & 6 deletions src/test/java/com/andromeda/araserver/test/TestNewCosmosDB.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.andromeda.araserver.test

import com.andromeda.araserver.pages.UpdateDB
import com.andromeda.araserver.util.CosmosClients
import com.andromeda.araserver.util.DeleteDoc
import com.andromeda.araserver.util.NewDoc
Expand All @@ -8,11 +9,13 @@ import org.junit.Test

class TestNewCosmosDB {
@Test
fun runTest(){
if (System.getenv().contains("IOTDB")){
val testData = OutputModel("test", "test", "test","test", "test", "test")
NewDoc().newDoc("test", testData, 123.toString())
//DeleteDoc().delDoc(CosmosClients.client, "test", 123.toString())
}
fun runTest() {
if (System.getenv().contains("IOTDB")) {
val testData = OutputModel("test", "test", "test", "test", "test", "test")
var id = 123.toString()
NewDoc().newDoc("test", testData, id)
UpdateDB().update(CosmosClients.client, id, "title", "test2")
DeleteDoc().delDoc(CosmosClients.client, "test", id)
}
}
}

0 comments on commit af48c28

Please sign in to comment.