Java Code Examples for org.fest.reflect.reference.TypeRef

The following examples show how to use org.fest.reflect.reference.TypeRef. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: seed   Source File: TransactionPluginTest.java    License: Mozilla Public License 2.0 6 votes vote down vote up
@Test
public void initTransactionPluginTest2() {
    InitState initState = pluginUnderTest.init(
            mockInitContext(LocalTransactionManager.class, TransactionHandlerTestImpl.class));
    Object object = pluginUnderTest.nativeUnitModule();
    Assertions.assertThat(object).isNotNull();
    Assertions.assertThat(object).isInstanceOf(TransactionModule.class);
    Set<TransactionMetadataResolver> transactionMetadataResolvers = Reflection.field(
            "transactionMetadataResolvers").ofType(new TypeRef<Set<TransactionMetadataResolver>>() {
    }).in(pluginUnderTest).get();
    Assertions.assertThat(transactionMetadataResolvers).isNotNull();
    TransactionManager transactionManager = Reflection.field("transactionManager").ofType(
            TransactionManager.class).in(pluginUnderTest).get();
    Assertions.assertThat(transactionManager).isNotNull();
    Assertions.assertThat(initState).isEqualTo(InitState.INITIALIZED);
}
 
Example 2
Source Project: fuchsia   Source File: PhilipsHueImporterTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void checkPoolOfLampBridgewereFilled() throws BinderException {

    String philipsId = "L1-ID";

    ImportDeclaration declaration = spy(ImportDeclarationBuilder.fromMetadata(generateValidMetadata(philipsId)).build());
    importer.registration(serviceReference);
    declaration.bind(serviceReference);

    importer.useDeclaration(declaration);

    Map<String, ServiceRegistration> lamps = field("lamps").ofType(new TypeRef<Map<String, ServiceRegistration>>() {
    }).in(importer).get();
    Map<String, ServiceRegistration> bridges = field("bridges").ofType(new TypeRef<Map<String, ServiceRegistration>>() {
    }).in(importer).get();

    Assert.assertEquals(1, lamps.size());
    Assert.assertEquals(lamps.get(philipsId), lightServiceRegistration);

    //Assert.assertEquals(1,bridges.size());
    //Assert.assertEquals(bridges.get(philipsId),bridgeServiceRegistration);

}
 
Example 3
@Test
public void testCollect() {
    Collection<BindingStrategy> strategies = underTest
            .collect(Lists.newArrayList(Dto1.class, Dto2.class, Dto3.class));
    Assertions.assertThat(strategies)
            .hasSize(2); // 2 default assembler implementation
    Map<Type[], Key<?>> typeVariables = Reflection.field("constructorParamsMap")
            .ofType(new TypeRef<Map<Type[], Key<?>>>() {})
            .in(strategies.iterator().next())
            .get();
    Assertions.assertThat(typeVariables)
            .hasSize(3); // 3 dtos
}
 
Example 4
@Test
public void resolvePermissionsInRole_should_return_permissions() {
    Map<String, Set<String>> rolesMap = Reflection.field("roles").ofType(new TypeRef<Map<String, Set<String>>>() {
    }).in(underTest).get();
    Set<String> permissions = new HashSet<>();
    permissions.add("bar");
    rolesMap.put("foo", permissions);

    underTest.resolvePermissionsInRole(new Role("foo"));
}
 
Example 5
@Test
public void readConfiguration_should_build_roles() {
    SecurityConfig securityConfig = new SecurityConfig().addRolePermissions("foo",
            Sets.newHashSet("bar", "foobar"));
    underTest.readConfiguration(securityConfig);
    Map<String, Set<String>> map = Reflection.field("roles").ofType(new TypeRef<Map<String, Set<String>>>() {
    }).in(underTest).get();
    Set<String> permissions = map.get("foo");
    assertTrue(permissions.contains("bar"));
    assertTrue(permissions.contains("foobar"));
}
 
Example 6
@Before
public void before() {
    underTest = new ConfigurationRoleMapping();
    Set<String> mappedRoles = new HashSet<>();
    mappedRoles.add(mappedRole1);
    mappedRoles.add(mappedRole2);
    map.put(role, mappedRoles);
    Reflection.field("map").ofType(new TypeRef<Map<String, Set<String>>>() {
    }).in(underTest).set(map);
    Reflection.field("scopeClasses").ofType(new TypeRef<Map<String, Class<? extends Scope>>>() {
    }).in(underTest).set(new HashMap<>());
}
 
Example 7
@Test
public void readConfiguration_should_fill_map() {
    SecurityConfig securityConfig = new SecurityConfig()
            .addRole("foo", Sets.newHashSet("bar.foo", "foo.bar"));
    underTest.readConfiguration(securityConfig);
    Map<String, Set<String>> roleMap = Reflection.field("map").ofType(new TypeRef<Map<String, Set<String>>>() {
    }).in(underTest).get();
    Set<String> roles = roleMap.get("bar.foo");
    assertTrue(roles.contains("foo"));

    Set<String> roles2 = roleMap.get("foo.bar");
    assertTrue(roles2.contains("foo"));
}
 
Example 8
Source Project: seed   Source File: TransactionPluginTest.java    License: Mozilla Public License 2.0 5 votes vote down vote up
@Test
public void initTransactionPluginTest7() {
    InitState initState = pluginUnderTest.init(mockInitContext(null, TransactionHandlerTestImpl.class));
    Assertions.assertThat(initState).isEqualTo(InitState.INITIALIZED);
    Set<TransactionMetadataResolver> transactionMetadataResolvers = Reflection.field(
            "transactionMetadataResolvers").ofType(new TypeRef<Set<TransactionMetadataResolver>>() {
    }).in(pluginUnderTest).get();
    Assertions.assertThat(transactionMetadataResolvers).isNotNull();
    TransactionManager transactionManager = Reflection.field("transactionManager").ofType(
            TransactionManager.class).in(pluginUnderTest).get();
    Assertions.assertThat(transactionManager).isNotNull();
}
 
Example 9
Source Project: fuchsia   Source File: PhilipsHueImporterTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void checkGracefulStop() throws BinderException {

    String philipsId = "L1-ID";

    ImportDeclaration declaration = spy(ImportDeclarationBuilder.fromMetadata(generateValidMetadata(philipsId)).build());
    importer.registration(serviceReference);
    declaration.bind(serviceReference);

    importer.useDeclaration(declaration);


    Map<String, ServiceRegistration> lamps = field("lamps").ofType(new TypeRef<Map<String, ServiceRegistration>>() {
    }).in(importer).get();
    Map<String, ServiceRegistration> bridges = field("bridges").ofType(new TypeRef<Map<String, ServiceRegistration>>() {
    }).in(importer).get();

    Assert.assertEquals(1, lamps.size());
    //Assert.assertEquals(1,bridges.size());

    importer.invalidate();

    Assert.assertEquals(0, lamps.size());
    //Assert.assertEquals(0,bridges.size());

}
 
Example 10
Source Project: fuchsia   Source File: PhilipsHueImporterTest.java    License: Apache License 2.0 3 votes vote down vote up
@Test
public void checkDenyImport() throws BinderException {

    String philipsId = "L1-ID";

    ImportDeclaration declaration = spy(ImportDeclarationBuilder.fromMetadata(generateValidMetadata(philipsId)).build());
    importer.registration(serviceReference);
    declaration.bind(serviceReference);

    importer.useDeclaration(declaration);

    Map<String, ServiceRegistration> lamps = field("lamps").ofType(new TypeRef<Map<String, ServiceRegistration>>() {
    }).in(importer).get();
    Map<String, ServiceRegistration> bridges = field("bridges").ofType(new TypeRef<Map<String, ServiceRegistration>>() {
    }).in(importer).get();

    Assert.assertEquals(1, lamps.size());
    //Assert.assertEquals(1,bridges.size());

    importer.denyDeclaration(declaration);

    Assert.assertEquals(0, lamps.size());
    //Assert.assertEquals(0,bridges.size());

    verify(declaration, times(1)).unhandle(serviceReference);

}