use of org.apache.johnzon.jsonb.cdi.JohnzonCdiExtension in project meecrowave by apache.
the class MeecrowaveClientLifecycleListenerTest method autoClose.
@Test
public void autoClose() throws IOException, NoSuchFieldException, IllegalAccessException {
try (final Meecrowave meecrowave = new Meecrowave(new Meecrowave.Builder().randomHttpPort().includePackages(MeecrowaveClientLifecycleListenerTest.class.getName())).bake()) {
final JohnzonCdiExtension johnzonCdiExtension = CDI.current().select(JohnzonCdiExtension.class).get();
final Field jsonbs = JohnzonCdiExtension.class.getDeclaredField("jsonbs");
jsonbs.setAccessible(true);
final BeanManager beanManager = CDI.current().getBeanManager();
final JohnzonCdiExtension extensionInstance = JohnzonCdiExtension.class.cast(beanManager.getContext(ApplicationScoped.class).get(beanManager.resolve(beanManager.getBeans(JohnzonCdiExtension.class))));
final Collection<?> o = Collection.class.cast(jsonbs.get(extensionInstance));
{
// ensure server is init whatever test suite we run in
final Client client = ClientBuilder.newClient();
get(meecrowave, client);
client.close();
}
final int origin = o.size();
final Client client = ClientBuilder.newClient();
final JsonbJaxrsProvider<?> provider = new JsonbJaxrsProvider<>();
client.register(provider);
get(meecrowave, client);
assertEquals(origin + 1, o.size());
client.close();
assertEquals(origin, o.size());
}
}
Aggregations