use of org.glassfish.hk2.api.TypeLiteral in project soapstone by alfasoftware.
the class TestSoapstoneService method testGetAListOfThings.
/**
* Test that we get type information when returning a list of some supertype
*/
@Test
public void testGetAListOfThings() throws JsonProcessingException {
String response = target().path("path/getAListOfThings").request().get(String.class);
JavaType returnType = OBJECT_MAPPER.constructType(new TypeLiteral<List<WebService.SuperClass>>() {
}.getType());
List<WebService.SuperClass> list = OBJECT_MAPPER.readerFor(returnType).readValue(response);
assertThat(list, containsInAnyOrder(asList(instanceOf(WebService.SuperClass.SubClass1.class), instanceOf(WebService.SuperClass.SubClass2.class))));
}
use of org.glassfish.hk2.api.TypeLiteral in project glassfish-hk2 by eclipse-ee4j.
the class TypeLiteralTest method testParameterizedLiteral.
/**
* Tests the type return from a TypeLiteral
*/
@Test
public void testParameterizedLiteral() {
TypeLiteral<List<String>> tl = new TypeLiteral<List<String>>() {
};
Type t = tl.getType();
Assert.assertTrue(t instanceof ParameterizedType);
ParameterizedType pt = (ParameterizedType) t;
Assert.assertSame(List.class, pt.getRawType());
Assert.assertEquals(1, pt.getActualTypeArguments().length);
Assert.assertSame(String.class, pt.getActualTypeArguments()[0]);
}
use of org.glassfish.hk2.api.TypeLiteral in project glassfish-hk2 by eclipse-ee4j.
the class ProvidesTest method testProvidesGenericTypeParametersInstanceMethodToField.
/**
* Verifies that generic type parameters are carried through a {@link
* Provides} chain starting from an instance method and ending with a generic
* {@link Provides} field.
*/
@Test
public void testProvidesGenericTypeParametersInstanceMethodToField() {
ServiceLocator locator = createAndPopulateServiceLocator();
ServiceLocatorUtilities.addClasses(locator, ProvidesListener.class, GenericTypeParameterChains.class);
ProvidesGenericField<Value7> providerA = locator.getService(new TypeLiteral<ProvidesGenericField<Value7>>() {
}.getType());
assertNotNull(providerA);
assertNotNull(providerA.value);
assertEquals(Value7.class, providerA.value.getClass());
Value7 providedA = locator.getService(Value7.class);
assertNotNull(providedA);
assertEquals(Value7.class, providedA.getClass());
ProvidesGenericField<Value8> providerB = locator.getService(new TypeLiteral<ProvidesGenericField<Value8>>() {
}.getType());
assertNotNull(providerB);
assertNotNull(providerB.value);
assertEquals(Value8.class, providerB.value.getClass());
Value8 providedB = locator.getService(Value8.class);
assertNotNull(providedB);
assertEquals(Value8.class, providedB.getClass());
}
use of org.glassfish.hk2.api.TypeLiteral in project glassfish-hk2 by eclipse-ee4j.
the class ProvidesTest method testProvidesGenericTypeParametersInstanceFieldToMethod.
/**
* Verifies that generic type parameters are carried through a {@link
* Provides} chain starting from an instance field and ending with a generic
* {@link Provides} method.
*/
@Test
public void testProvidesGenericTypeParametersInstanceFieldToMethod() {
ServiceLocator locator = createAndPopulateServiceLocator();
ServiceLocatorUtilities.addClasses(locator, ProvidesListener.class, GenericTypeParameterChains.class);
ProvidesGenericMethod<Value11> providerA = locator.getService(new TypeLiteral<ProvidesGenericMethod<Value11>>() {
}.getType());
assertNotNull(providerA);
assertNotNull(providerA.getValue());
assertEquals(Value11.class, providerA.getValue().getClass());
Value11 providedA = locator.getService(Value11.class);
assertNotNull(providedA);
assertEquals(Value11.class, providedA.getClass());
ProvidesGenericMethod<Value12> providerB = locator.getService(new TypeLiteral<ProvidesGenericMethod<Value12>>() {
}.getType());
assertNotNull(providerB);
assertNotNull(providerB.getValue());
assertEquals(Value12.class, providerB.getValue().getClass());
Value12 providedB = locator.getService(Value12.class);
assertNotNull(providedB);
assertEquals(Value12.class, providedB.getClass());
}
use of org.glassfish.hk2.api.TypeLiteral in project glassfish-hk2 by eclipse-ee4j.
the class ProvidesTest method testProvidesLifecycleFromInstanceField.
/**
* Verifies the lifecycle a service obtained from an instance field that is
* annotated with {@link Provides}.
*/
@Test
public void testProvidesLifecycleFromInstanceField() {
ServiceLocator locator = createAndPopulateServiceLocator();
ServiceLocatorUtilities.addClasses(locator, ProvidesListener.class, ProvidesLifecycleFactory.class, ProvidesLifecycleDependency.class);
IterableProvider<ProvidesLifecycleFromInstanceField> provider = locator.getService(new TypeLiteral<IterableProvider<ProvidesLifecycleFromInstanceField>>() {
}.getType());
ServiceHandle<ProvidesLifecycleFromInstanceField> handle = provider.getHandle();
ProvidesLifecycleFromInstanceField root = handle.getService();
assertFalse(root.wasStarted());
assertTrue(root.factory.wasStarted());
assertFalse(root.dependency.wasStarted());
assertFalse(root.wasStopped());
assertFalse(root.factory.wasStopped());
assertFalse(root.dependency.wasStopped());
handle.close();
assertFalse(root.wasStopped());
assertTrue(root.factory.wasStopped());
assertFalse(root.dependency.wasStopped());
}
Aggregations