Package org.jtalks.jcommune.plugin.api.core

Examples of org.jtalks.jcommune.plugin.api.core.RegistrationPlugin


        assertEquals(response.getStatus(), JsonResponseStatus.SUCCESS);
    }

    @Test
    public void testRegistrationFormWithAvailablePluginShouldBeSuccessful() {
        RegistrationPlugin plugin = mock(RegistrationPlugin.class);
        when(pluginService.getRegistrationPlugins()).thenReturn(
                new ImmutableMap.Builder<Long, RegistrationPlugin>().put(1L, plugin).build());

        JsonResponse response = userController.registrationForm(request, Locale.ENGLISH);
View Full Code Here


        pluginService.getPluginById(pluginId);
    }

    @Test
    public void getRegistrationPluginsShouldReturnEnabledRegistrationPlugins() throws NotFoundException {
        RegistrationPlugin plugin = mock(RegistrationPlugin.class);
        Long pluginId = 1L;
        PluginConfiguration pluginConfiguration =
                new PluginConfiguration("plugin", true, new ArrayList<PluginProperty>());
        pluginConfiguration.setId(pluginId);
        List<Plugin> pluginList = new ArrayList<>();
        pluginList.add(plugin);
        when(plugin.getState()).thenReturn(Plugin.State.ENABLED);
        when(pluginLoader.getPlugins(any(TypeFilter.class))).thenReturn(pluginList);
        when(pluginConfigurationDao.get(plugin.getName())).thenReturn(pluginConfiguration);

        Map<Long, RegistrationPlugin> result = pluginService.getRegistrationPlugins();

        assertEquals(result.get(pluginId), plugin);
    }
View Full Code Here

        assertEquals(result.get(pluginId), plugin);
    }

    @Test
    public void getRegistrationPluginsShouldNotReturnInappropriatePlugins() throws NotFoundException {
        RegistrationPlugin plugin = mock(RegistrationPlugin.class);
        Long pluginId = 1L;
        PluginConfiguration pluginConfiguration =
                new PluginConfiguration("plugin", true, new ArrayList<PluginProperty>());
        pluginConfiguration.setId(pluginId);
        List<Plugin> pluginList = new ArrayList<>();
        pluginList.add(plugin);
        when(pluginLoader.getPlugins(any(TypeFilter.class))).thenReturn(pluginList);
        when(pluginConfigurationDao.get(plugin.getName())).thenReturn(pluginConfiguration);

        Map<Long, RegistrationPlugin> result = pluginService.getRegistrationPlugins();

        assertEquals(result.size(), 0);
    }
View Full Code Here

        assertEquals(result.size(), 0);
    }

    @Test
    public void getRegistrationPluginsIfAnyPluginConfigurationNotFoundShouldNotBeFailed() throws NotFoundException {
        RegistrationPlugin plugin = mock(RegistrationPlugin.class);
        Long pluginId = 1L;
        PluginConfiguration pluginConfiguration = new PluginConfiguration();
        pluginConfiguration.setId(pluginId);
        List<Plugin> pluginList = new ArrayList<>();
        pluginList.add(plugin);
        when(plugin.getState()).thenReturn(Plugin.State.ENABLED);
        when(pluginLoader.getPlugins(any(TypeFilter.class))).thenReturn(pluginList);
        when(pluginConfigurationDao.get(plugin.getName())).thenThrow(new NotFoundException());

        Map<Long, RegistrationPlugin> result = pluginService.getRegistrationPlugins();

        assertEquals(result.size(), 0);
    }
View Full Code Here

     */
    public void registerByPlugin(UserDto userDto, boolean dryRun, BindingResult bindingResult)
            throws UnexpectedErrorException, NoConnectionException {
        Map<Long, RegistrationPlugin> registrationPlugins = pluginService.getRegistrationPlugins();
        for (Map.Entry<Long, RegistrationPlugin> entry : registrationPlugins.entrySet()) {
            RegistrationPlugin registrationPlugin = entry.getValue();
            if (registrationPlugin != null && registrationPlugin.getState() == Plugin.State.ENABLED) {
                Map<String, String> errors = dryRun
                        ? registrationPlugin.validateUser(userDto, entry.getKey())
                        : registrationPlugin.registerUser(userDto, entry.getKey());
                for (Map.Entry<String, String> error : errors.entrySet()) {
                    bindingResult.rejectValue(error.getKey(), null, error.getValue());
                }
            }
        }
View Full Code Here

        Map<String, String> errors = new HashMap<>();
        errors.put("userDto.email", "Invalid email length");
        errors.put("userDto.username", "Invalid username length");
        errors.put("userDto.password", "Invalid password length");

        RegistrationPlugin plugin = mock(RegistrationPlugin.class);
        when(plugin.getState()).thenReturn(Plugin.State.ENABLED);
        when(plugin.registerUser(userDto.getUserDto(), 1L)).thenReturn(errors);

        when(pluginService.getRegistrationPlugins()).thenReturn(
                new ImmutableMap.Builder<Long, RegistrationPlugin>().put(1L, plugin).build());

        when(bindingResult.hasErrors()).thenReturn(true);
View Full Code Here

    }

    @Test(expectedExceptions = NoConnectionException.class)
    public void registerUserShouldFailIfPluginThrowsNoConnectionException() throws Exception {
        RegisterUserDto userDto = createRegisterUserDto("username", "password", "email@email.em", null);
        RegistrationPlugin plugin = mock(RegistrationPlugin.class);
        when(plugin.getState()).thenReturn(Plugin.State.ENABLED);
        when(plugin.registerUser(userDto.getUserDto(), 1L))
                .thenThrow(new NoConnectionException());
        when(pluginService.getRegistrationPlugins()).thenReturn(
                new ImmutableMap.Builder<Long, RegistrationPlugin>().put(1L, plugin).build());

        when(bindingResult.hasErrors()).thenReturn(true);
View Full Code Here

    }

    @Test(expectedExceptions = UnexpectedErrorException.class)
    public void registerUserShouldFailIfPluginThrowsUnexpectedErrorException() throws Exception {
        RegisterUserDto userDto = createRegisterUserDto("username", "password", "email@email.em", null);
        RegistrationPlugin plugin = mock(RegistrationPlugin.class);
        when(plugin.getState()).thenReturn(Plugin.State.ENABLED);
        when(plugin.registerUser(userDto.getUserDto(), 1L))
                .thenThrow(new UnexpectedErrorException());
        when(pluginService.getRegistrationPlugins()).thenReturn(
                new ImmutableMap.Builder<Long, RegistrationPlugin>().put(1L, plugin).build());

        authenticator.register(userDto);
View Full Code Here

TOP

Related Classes of org.jtalks.jcommune.plugin.api.core.RegistrationPlugin

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.