-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Performance opt. - Clean up Knowledge Manager Util - Add unit tests
- Loading branch information
1 parent
16bb0cf
commit 92601d7
Showing
6 changed files
with
94 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...d/engine/src/test/java/org/smartregister/fhircore/engine/util/KnowledgeManagerUtilTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright 2021-2024 Ona Systems, Inc | ||
* | ||
* 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. | ||
*/ | ||
|
||
package org.smartregister.fhircore.engine.util | ||
|
||
import android.content.Context | ||
import androidx.test.core.app.ApplicationProvider | ||
import ca.uhn.fhir.context.FhirContext | ||
import java.io.File | ||
import org.hl7.fhir.r4.model.StructureMap | ||
import org.junit.After | ||
import org.junit.Assert | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.smartregister.fhircore.engine.app.AppConfigService | ||
import org.smartregister.fhircore.engine.robolectric.RobolectricTest | ||
|
||
class KnowledgeManagerUtilTest : RobolectricTest() { | ||
|
||
private lateinit var configService: AppConfigService | ||
private val context = ApplicationProvider.getApplicationContext<Context>()!! | ||
|
||
@Before | ||
fun setUp() { | ||
configService = AppConfigService(context) | ||
} | ||
|
||
@Test | ||
fun testWriteToFile() { | ||
val structureMap = StructureMap().apply { id = "structure-map-id" } | ||
|
||
val filePath = | ||
"${KnowledgeManagerUtil.KNOWLEDGE_MANAGER_ASSETS_SUBFOLDER}/StructureMap/structure-map-id.json" | ||
val absoluteFilePath = "${context.filesDir}/$filePath" | ||
|
||
val file = File(absoluteFilePath) | ||
Assert.assertFalse(file.exists()) | ||
|
||
KnowledgeManagerUtil.writeToFile(filePath, structureMap, configService, context) | ||
|
||
Assert.assertTrue(file.exists()) | ||
|
||
val savedStructureMap = | ||
FhirContext.forR4Cached().newJsonParser().parseResource(file.readText()) as StructureMap | ||
Assert.assertNotNull(savedStructureMap.url) | ||
Assert.assertEquals( | ||
"http://fake.base.url.com/StructureMap/structure-map-id", | ||
savedStructureMap.url, | ||
) | ||
} | ||
|
||
@After | ||
fun tearDown() { | ||
val testFile = | ||
File( | ||
"${context.filesDir}/${KnowledgeManagerUtil.KNOWLEDGE_MANAGER_ASSETS_SUBFOLDER}/StructureMap/structure-map-id.json", | ||
) | ||
if (testFile.exists()) { | ||
testFile.delete() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters