/*
 * Copyright (c) 2018, 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.apimgt.micro.gateway.usage.publisher.internal;

import org.junit.Test;
import org.mockito.Mockito;
import org.osgi.framework.BundleContext;
import org.osgi.service.component.ComponentContext;
import org.wso2.carbon.apimgt.impl.APIManagerConfigurationService;
import org.wso2.carbon.ntask.core.service.TaskService;
import org.wso2.carbon.user.core.service.RealmService;

/**
 * APIUsagePublisherComponent test class
 *
 */
public class APIUsagePublisherComponentTest {

    @Test
    public void activate() throws Exception {
        APIUsagePublisherComponent serviceComponent = new APIUsagePublisherComponent();
        ComponentContext componentContext = Mockito.mock(ComponentContext.class);
        BundleContext bundleContext = Mockito.mock(BundleContext.class);
        Mockito.when(componentContext.getBundleContext()).thenReturn(bundleContext);
        serviceComponent.activate(componentContext);
    }

    @Test
    public void deactivate() throws Exception {
        APIUsagePublisherComponent serviceComponent = new APIUsagePublisherComponent();
        ComponentContext componentContext = Mockito.mock(ComponentContext.class);
        serviceComponent.deactivate(componentContext);
    }

    @Test
    public void setAPIManagerConfigurationService() throws Exception {
        APIUsagePublisherComponent serviceComponent = new APIUsagePublisherComponent();
        APIManagerConfigurationService apiManagerConfigurationService = Mockito
                .mock(APIManagerConfigurationService.class);
        serviceComponent.setAPIManagerConfigurationService(apiManagerConfigurationService);
    }

    @Test
    public void unsetAPIManagerConfigurationService() throws Exception {
        APIUsagePublisherComponent serviceComponent = new APIUsagePublisherComponent();
        APIManagerConfigurationService apiManagerConfigurationService = Mockito
                .mock(APIManagerConfigurationService.class);
        serviceComponent.unsetAPIManagerConfigurationService(apiManagerConfigurationService);
    }

    @Test
    public void setRealmService() throws Exception {
        RealmService realmService = Mockito.mock(RealmService.class);
        APIUsagePublisherComponent serviceComponent = new APIUsagePublisherComponent();
        serviceComponent.setRealmService(realmService);
    }

    @Test
    public void unsetRealmService() throws Exception {
        RealmService realmService = Mockito.mock(RealmService.class);
        APIUsagePublisherComponent serviceComponent = new APIUsagePublisherComponent();
        serviceComponent.unsetRealmService(realmService);
    }

    @Test
    public void setTaskService() throws Exception {
        APIUsagePublisherComponent serviceComponent = new APIUsagePublisherComponent();
        TaskService taskService = Mockito.mock(TaskService.class);
        serviceComponent.setTaskService(taskService);
    }

    @Test
    public void unsetTaskService() throws Exception {
        APIUsagePublisherComponent serviceComponent = new APIUsagePublisherComponent();
        TaskService taskService = Mockito.mock(TaskService.class);
        serviceComponent.unsetTaskService(taskService);
    }

}

@@ -756,16 +756,49 @@
 t.Test;%0A
+import org.junit.runner.RunWith;%0A
 import o
@@ -925,62 +925,445 @@
 org.
-wso2.carbon.apimgt.impl.APIManagerConfigurationService
+powermock.api.mockito.PowerMockito;%0Aimport org.powermock.core.classloader.annotations.PrepareForTest;%0Aimport org.powermock.modules.junit4.PowerMockRunner;%0Aimport org.wso2.carbon.apimgt.impl.APIManagerConfiguration;%0Aimport org.wso2.carbon.apimgt.impl.APIManagerConfigurationService;%0Aimport org.wso2.carbon.apimgt.micro.gateway.common.internal.ServiceReferenceHolder;%0Aimport org.wso2.carbon.apimgt.micro.gateway.common.util.HttpRequestUtil
 ;%0Aim
@@ -1469,16 +1469,58 @@
 Service;
+%0Aimport org.wso2.carbon.utils.CarbonUtils;
 %0A%0A/**%0A *
@@ -1562,117 +1562,971 @@
 ass%0A
- *%0A
  */%0A
-public class APIUsagePublisherComponentTest %7B%0A%0A    @Test%0A    public void activate() throws Exception %7B
+@RunWith(PowerMockRunner.class)%0A@PrepareForTest(%7BCarbonUtils.class, APIManagerConfiguration.class, ServiceReferenceHolder.class,%0A        APIManagerConfigurationService.class, HttpRequestUtil.class, RealmService.class%7D)%0Apublic class APIUsagePublisherComponentTest %7B%0A    public static final String CARBON_HOME = %22carbon.home%22;%0A    public static final String CARBON_CONFIGS_PATH = %22/repository/conf%22;%0A    public static final String CARBON_TENANT_CONFIGS_PATH = %22/repository/tenants%22;%0A%0A    @Test%0A    public void activate() throws Exception %7B%0A%0A        String carbonConfigPath = System.getProperty(CARBON_HOME) + CARBON_CONFIGS_PATH;%0A        String tenantDirPath = System.getProperty(CARBON_HOME) + CARBON_TENANT_CONFIGS_PATH;%0A        PowerMockito.mockStatic(CarbonUtils.class);%0A        PowerMockito.when(CarbonUtils.getCarbonTenantsDirPath()).thenReturn(tenantDirPath);%0A        PowerMockito.when(CarbonUtils.getCarbonConfigDirPath()).thenReturn(carbonConfigPath);%0A
 %0A   

Fix the micro-gateway test case failure.