Skip to content

Instantly share code, notes, and snippets.

@Gopinathp
Created December 7, 2021 19:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gopinathp/4d0f9b44f1b32a4006c51c998e0fe266 to your computer and use it in GitHub Desktop.
Save Gopinathp/4d0f9b44f1b32a4006c51c998e0fe266 to your computer and use it in GitHub Desktop.
Added mongodb container test sample
import kotlinx.coroutines.runBlocking
import org.bson.types.ObjectId
import org.junit.*
import org.junit.Assert.*
import org.testcontainers.containers.MongoDBContainer
import org.testcontainers.containers.wait.strategy.HostPortWaitStrategy
import org.testcontainers.utility.DockerImageName
import java.math.BigInteger
import java.time.Duration
class FoodOrdersManagerTest {
companion object {
val mongoDBContainer = MongoDBContainer(DockerImageName.parse("mongo:4.0.10"))
.withExposedPorts(27017)
.waitingFor(HostPortWaitStrategy())
.withStartupTimeout(Duration.ofMinutes(5))
@BeforeClass
@JvmStatic
fun setup() {
mongoDBContainer.start();
}
@JvmStatic
@AfterClass
fun tearDown() {
mongoDBContainer.stop()
}
}
@Test
fun insertAndReadFavApps() = runBlocking {
DbCrudManager.MONGO_DB_HOST_NAME = mongoDBContainer.host
DbCrudManager.MONGO_DB_PORT = mongoDBContainer.firstMappedPort
val response1 = FoodOrdersManager.getOrders(getOrdersRequest {
this.userId = userIdDynamic
})
assertTrue(response1.data.ordersList.isEmpty());
val response2 = FoodOrdersManagerTest.addOrder(addFoodOrderRequest {
this.isFav = true
this.userId = userIdDynamic
this.placeId = placeId1Dynamic
this.resourceId = "a:b:c"
})
assertTrue(response2.data.ordersList.isNotEmpty());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment