Hello everyone. I have an interesting problem. I'm...
# micronaut
d
Hello everyone. I have an interesting problem. I'm doing a pet project URL shortener with Kotlin and Micronaut. It's very simple to redirect a request to a new URL. The issue I'm encountering is how do I write a test for this in Micronaut. The controller code looks like the following:
Copy code
fun redirectToUrl(@PathVariable urlId: String): MutableHttpResponse<URL>? {
        val result: Optional<UrlMap> = urlMapRepository.findById(urlId)

        return if (result.isPresent) {

            val record: UrlMap = result.get()
            val url = URI(record.url!!)
            record.visits = record.visits + 1
            urlMapRepository.update(record)

            HttpResponse.redirect<URL>(url)
        } else {

            HttpResponse.notFound()
        }
    }
When using RxHttpClient the response contains the html from the redirected page. Ultimately the only thing I really want to test for is a 302 redirect (if I have an internet connection I get a 200 for the redirected page). I also want the client to work without an internet connection. I hope this isn't a dumb question.