<commit_before>/*
 * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 * WSO2 Inc. licenses this file to you under the Apache License,
 * Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package org.wso2.carbon.identity.event;

import org.mockito.Mock;
import org.mockito.Mockito;
import org.testng.annotations.Test;
import org.wso2.carbon.identity.core.bean.context.MessageContext;
import org.wso2.carbon.identity.event.event.Event;
import org.wso2.carbon.identity.event.handler.AbstractEventHandler;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;

public class EventDistributionTaskTest {

    @Mock
    AbstractEventHandler module;

    @Test
    public void testRun() throws IdentityEventException {

        module = mock(AbstractEventHandler.class);
        doReturn(true).when(module).isEnabled(any(MessageContext.class));

        Event event = new Event("event");
        event.addEventProperty("value","value");

        List notificationModules = new ArrayList();
        notificationModules.add(module);

        final EventDistributionTask eventDistributionTask = new EventDistributionTask(notificationModules , 1);
        eventDistributionTask.addEventToQueue(event);

        ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();

        Runnable task = new Runnable() {
            public void run() {
                eventDistributionTask.run();
                Mockito.verify(module).isEnabled(any(MessageContext.class));
            }
        };

        int delay = 5;
        scheduler.schedule(task, delay, TimeUnit.SECONDS);
        scheduler.shutdown();

        eventDistributionTask.shutdown();

    }
}<commit_msg>IDENTITY-6536 Adding tests for identity-event<commit_after>/*
 * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 * WSO2 Inc. licenses this file to you under the Apache License,
 * Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package org.wso2.carbon.identity.event;

import org.mockito.Mock;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.modules.testng.PowerMockTestCase;
import org.testng.annotations.Test;
import org.wso2.carbon.identity.core.bean.context.MessageContext;
import org.wso2.carbon.identity.event.event.Event;
import org.wso2.carbon.identity.event.handler.AbstractEventHandler;


import java.util.ArrayList;
import java.util.List;


import static org.mockito.Matchers.any;


public class EventDistributionTaskTest extends PowerMockTestCase{

    @Mock
    AbstractEventHandler module;

    @Test
    public void testRun() throws IdentityEventException {

       PowerMockito.when(module.isEnabled(any(MessageContext.class))).thenReturn(true);
        Event event = new Event("event");
        event.addEventProperty("value","value");

        List notificationModules = new ArrayList();
        notificationModules.add(module);

        EventDistributionTask eventDistributionTask = new EventDistributionTask(notificationModules , 1);
        eventDistributionTask.addEventToQueue(event);

        Thread thread = new Thread(eventDistributionTask);
        thread.start();

        eventDistributionTask.shutdown();
    }
}
{'fraction_non_alphanumeric': 0.09336665152203544, 'fraction_numerical': 0.008405270331667424, 'mean_word_length': 3.7858695652173915, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4830102', 'n_tokens_mistral': 1222, 'n_tokens_neox': 1167, 'n_words': 337}