0

How do you load the application context into MicronautLambdaContainerHandler when running a MicronautTest?

I see I can inject the ApplicationContext into my test, and I can see that the MicronautLambdaContainerHandler takes a ApplicationContextBuilder during construction, but I don't understand how to reconcile those two things?

Is it possible to give the MicronautLambdaContainerHandler the already running test context? Is it possible to get a builder from the test context?

Knut Knutson
  • 163
  • 2
  • 8
  • `"Is it possible to get a builder from the test context?"` - What is it that you want to accomplish by getting a builder from the test context? – Jeff Scott Brown Aug 21 '20 at 14:27
  • What I want to accomplish is to pass the MicronautLambdaContainerHandler the test application context. I'd be fine with any solution that gets me there. Since I can get the application context in the test, and MicronautLambdaContainerHandler takes a context builder I was wondering if a possible solution would be getting a builder from the context and passing it to the handler – Knut Knutson Aug 21 '20 at 14:39
  • "What I want to accomplish is to pass the MicronautLambdaContainerHandler the test application context." - Can you summarize what you want to accomplish by doing that? I am trying to understand what you are trying to accomplish as that will help identify the best solution. It isn't clear from the question what the end goal of passing the test application context is. – Jeff Scott Brown Aug 21 '20 at 16:11
  • Also the question asks about passing the context and asks about passing the context builder. Are you wanting both of those? – Jeff Scott Brown Aug 21 '20 at 16:53
  • Probably you don't need to touch `MicronautLambdaContainerHandler`, please put some example code so more people could help – Traycho Ivanov Aug 24 '20 at 07:38

1 Answers1

0

I had a similar problem, so I overloaded implementation of DefaultApplicationContextBuilder like this (kotlin)

class TestContextBuilder : DefaultApplicationContextBuilder() {
  init {
    this.properties(
      mapOf("propery" to "value")
    )
  }
}

and in test

@MicronautTest(contextBuilder = [TestContextBuilder::class])

looks ugly and brittle, but got things done