Commit e4b76655 authored by Iulia Damian's avatar Iulia Damian
Browse files

#36:unitTest completed

parent 955ffe9d
<?xml version="1.0" encoding="UTF-8"?>
<module external.system.module.type="sourceSet" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_11">
<output url="file://$MODULE_DIR$/../../src/ktor-server/build/classes/java/main" />
<component name="NewModuleRootManager">
<output-test url="file://$MODULE_DIR$/../../src/ktor-server/build/classes/java/test" />
<exclude-output />
<content url="file://$MODULE_DIR$/../../src/ktor-server/src/main">
<sourceFolder url="file://$MODULE_DIR$/../../src/ktor-server/src/main/kotlin" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/../../src/ktor-server/src/main/resources" type="java-resource" />
<content url="file://$MODULE_DIR$/../../src/ktor-server/src/test">
<sourceFolder url="file://$MODULE_DIR$/../../src/ktor-server/src/test/kotlin" isTestSource="true" />
</content>
<orderEntry type="jdk" jdkName="11" jdkType="JavaSDK" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="ktor-server.main" />
<orderEntry type="library" name="Gradle: io.ktor:ktor-serialization:1.5.1" level="project" />
<orderEntry type="library" name="Gradle: io.ktor:ktor-server-tests:1.5.1" level="project" />
<orderEntry type="library" name="Gradle: io.ktor:ktor-server-netty:1.5.1" level="project" />
<orderEntry type="library" name="Gradle: io.ktor:ktor-server-core:1.5.1" level="project" />
<orderEntry type="library" name="Gradle: org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.30-RC" level="project" />
......@@ -20,6 +21,7 @@
<orderEntry type="library" name="Gradle: com.squareup.moshi:moshi:1.11.0" level="project" />
<orderEntry type="library" name="Gradle: org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.2" level="project" />
<orderEntry type="library" name="Gradle: org.jsoup:jsoup:1.13.1" level="project" />
<orderEntry type="library" name="Gradle: org.junit.jupiter:junit-jupiter:5.7.1" level="project" />
<orderEntry type="library" name="Gradle: org.jetbrains.kotlin:kotlin-stdlib:1.4.30" level="project" />
<orderEntry type="library" name="Gradle: org.slf4j:slf4j-api:1.7.30" level="project" />
<orderEntry type="library" name="Gradle: org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.4.2-native-mt" level="project" />
......@@ -49,9 +51,12 @@
<orderEntry type="library" name="Gradle: com.zaxxer:SparseBitSet:1.2" level="project" />
<orderEntry type="library" name="Gradle: com.squareup.okio:okio:1.17.5" level="project" />
<orderEntry type="library" name="Gradle: org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.4.2" level="project" />
<orderEntry type="library" name="Gradle: org.junit.jupiter:junit-jupiter-params:5.7.1" level="project" />
<orderEntry type="library" name="Gradle: org.junit.jupiter:junit-jupiter-api:5.7.1" level="project" />
<orderEntry type="library" name="Gradle: org.jetbrains.kotlinx:kotlinx-serialization-json-jvm:1.0.1" level="project" />
<orderEntry type="library" name="Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:1.4.30" level="project" />
<orderEntry type="library" name="Gradle: org.jetbrains:annotations:13.0" level="project" />
<orderEntry type="library" name="Gradle: io.ktor:ktor-server-test-host:1.5.1" level="project" />
<orderEntry type="library" name="Gradle: io.ktor:ktor-server-host-common:1.5.1" level="project" />
<orderEntry type="library" name="Gradle: io.netty:netty-codec-http:4.1.54.Final" level="project" />
<orderEntry type="library" name="Gradle: io.netty:netty-handler:4.1.54.Final" level="project" />
......@@ -93,6 +98,14 @@
<orderEntry type="library" name="Gradle: org.apache.xmlgraphics:batik-ext:1.13" level="project" />
<orderEntry type="library" name="Gradle: org.apache.xmlgraphics:batik-i18n:1.13" level="project" />
<orderEntry type="library" name="Gradle: org.apache.pdfbox:pdfbox:2.0.22" level="project" />
<orderEntry type="library" name="Gradle: org.apiguardian:apiguardian-api:1.1.0" level="project" />
<orderEntry type="library" name="Gradle: org.junit.platform:junit-platform-commons:1.7.1" level="project" />
<orderEntry type="library" name="Gradle: org.opentest4j:opentest4j:1.2.0" level="project" />
<orderEntry type="library" name="Gradle: org.jetbrains.kotlin:kotlin-test-junit:1.4.21" level="project" />
<orderEntry type="library" name="Gradle: org.eclipse.jetty.http2:http2-http-client-transport:9.4.31.v20200723" level="project" />
<orderEntry type="library" name="Gradle: org.eclipse.jetty.http2:http2-client:9.4.31.v20200723" level="project" />
<orderEntry type="library" name="Gradle: org.eclipse.jetty:jetty-client:9.4.31.v20200723" level="project" />
<orderEntry type="library" name="Gradle: junit:junit:4.12" level="project" />
<orderEntry type="library" name="Gradle: io.netty:netty-resolver:4.1.54.Final" level="project" />
<orderEntry type="library" name="Gradle: io.ktor:ktor-http-cio-jvm:1.5.1" level="project" />
<orderEntry type="library" name="Gradle: io.ktor:ktor-network-tls-jvm:1.5.1" level="project" />
......@@ -102,11 +115,31 @@
<orderEntry type="library" name="Gradle: xalan:xalan:2.7.2" level="project" />
<orderEntry type="library" name="Gradle: xml-apis:xml-apis:1.4.01" level="project" />
<orderEntry type="library" name="Gradle: org.apache.pdfbox:fontbox:2.0.22" level="project" />
<orderEntry type="library" name="Gradle: io.ktor:ktor-websockets:1.5.1" level="project" />
<orderEntry type="library" name="Gradle: io.ktor:ktor-network-tls-certificates:1.5.1" level="project" />
<orderEntry type="library" name="Gradle: io.ktor:ktor-client-jetty:1.5.1" level="project" />
<orderEntry type="library" name="Gradle: org.jetbrains.kotlin:kotlin-test:1.4.21" level="project" />
<orderEntry type="library" name="Gradle: org.jetbrains.kotlin:kotlin-test-annotations-common:1.4.21" level="project" />
<orderEntry type="library" name="Gradle: org.eclipse.jetty.http2:http2-common:9.4.31.v20200723" level="project" />
<orderEntry type="library" name="Gradle: org.eclipse.jetty:jetty-alpn-client:9.4.31.v20200723" level="project" />
<orderEntry type="library" name="Gradle: org.eclipse.jetty:jetty-http:9.4.31.v20200723" level="project" />
<orderEntry type="library" name="Gradle: org.eclipse.jetty:jetty-io:9.4.31.v20200723" level="project" />
<orderEntry type="library" name="Gradle: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" name="Gradle: io.ktor:ktor-io-jvm:1.5.1" level="project" />
<orderEntry type="library" name="Gradle: commons-io:commons-io:1.3.1" level="project" />
<orderEntry type="library" name="Gradle: xalan:serializer:2.7.2" level="project" />
<orderEntry type="library" name="Gradle: org.eclipse.jetty:jetty-alpn-openjdk8-client:9.4.31.v20200723" level="project" />
<orderEntry type="library" name="Gradle: org.eclipse.jetty:jetty-alpn-java-client:9.4.31.v20200723" level="project" />
<orderEntry type="library" name="Gradle: org.jetbrains.kotlin:kotlin-test-common:1.4.21" level="project" />
<orderEntry type="library" name="Gradle: org.eclipse.jetty.http2:http2-hpack:9.4.31.v20200723" level="project" />
<orderEntry type="library" name="Gradle: org.eclipse.jetty:jetty-util:9.4.31.v20200723" level="project" />
<orderEntry type="library" name="Gradle: io.ktor:ktor-network-jvm:1.5.1" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Gradle: org.junit.jupiter:junit-jupiter-engine:5.7.1" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Gradle: com.fasterxml.woodstox:woodstox-core:5.2.1" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Gradle: org.junit.platform:junit-platform-engine:1.7.1" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Gradle: org.jetbrains.kotlinx:kotlinx-coroutines-debug:1.4.2-native-mt" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Gradle: org.codehaus.woodstox:stax2-api:4.2" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Gradle: net.java.dev.jna:jna-platform:5.5.0" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Gradle: net.java.dev.jna:jna:5.5.0" level="project" />
</component>
</module>
\ No newline at end of file
......@@ -2,18 +2,15 @@ package de.h_da.fbi.smebt.intentfinder.server.sources
import com.mongodb.BasicDBObject
import com.mongodb.MongoClient
import org.bson.BsonDocument
import org.bson.BsonObjectId
import org.bson.Document
import org.bson.*
import org.bson.json.JsonParseException
import org.bson.types.ObjectId
class DbConnector(db:String, table:String) {
val mongoClient = MongoClient()
val database = mongoClient.getDatabase(db)
val tbl = database.getCollection(table)
val tbl = database.getCollection(table, BsonDocument::class.java)
/*
List<Document> databases = mongoClient.listDatabases().into(new ArrayList<>());
......@@ -25,25 +22,26 @@ fun getData(){
val searchQry = BasicDBObject()
searchQry.put("title","ExampleMovie")
// performs a the find method using the variable searchQry
var cursor = tbl.find(searchQry)
val cursor = tbl.find(searchQry)
val it = cursor.iterator()
while(it.hasNext()){
println(it.next())
}
}
fun readData() {
val collection = database.getCollection(tbl, BsonDocument::class.java)
val populationOfAndorra = collection
fun readData():BsonDocument{
val populationOfAndorra = tbl
.find(BsonDocument("title", BsonString("Example Movie")), BsonDocument::class.java)
println("The population of Andorra is: ${populationOfAndorra.first().getDocument("vote_count").value}")
val test = populationOfAndorra.first()
return test
//println("The population of Andorra is: ${populationOfAndorra.first().getDocument("vote_count").values}")
}
fun saveNewDocument(collection: String, document: String): String {
try {
val bsonDocument = BsonDocument.parse(document)
// we create the id ourselves
bsonDocument.remove("_id")
//bsonDocument.remove("_id")
val oid = ObjectId()
bsonDocument.put("_id", BsonObjectId(oid))
//bsonDocument.put("_id", BsonObjectId(oid))
database.getCollection(collection, BsonDocument::class.java)
.insertOne(bsonDocument)
return oid.toHexString()
......
package de.h_da.fbi.smebt.intentfinder.server.sources
data class Question(val Question:String, val Answer:String)
package de.h_da.fbi.smebt.intentfinder.server.sources
import kotlin.test.assertEquals
internal class DbTest {
@org.junit.jupiter.api.Test
fun testDbInsert(){
val connector = DbConnector("testDB", "unitTest")
val qst = Question("Das ist eine Frage", "Das ist eine Antwort")
val json:String
json = "{\"vote_count\": \"2026\",\"_id\": \"19404\",\"title\": \"Example Movie\",\"overview\": \"Overview of example movie\"}"
connector.saveNewDocument("unitTest", json)
connector.readData()
//connector.getData()
//connector.getData();
}
@org.junit.jupiter.api.Test
fun testDbReader(){
val connector = DbConnector("testDB", "unitTest")
//val qst = Question("Das ist eine Frage", "Das ist eine Antwort")
//val json:String
//json = "{\"vote_count\": \"2026\",\"id\": \"19404\",\"title\": \"Example Movie\",\"overview\": \"Overview of example movie\"}"
val json = "{\"_id\": \"19404\", \"vote_count\": \"2026\", \"title\": \"Example Movie\", \"overview\": \"Overview of example movie\"}"
//connector.saveNewDocument("unitTest", json)
connector.getData()
//connector.getData();
connector.saveNewDocument("unitTest", json)
val bsonDocument = connector.readData()
val jsonResult = bsonDocument.toJson()
assertEquals(jsonResult, json)
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment