mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Fix issues in test-cases
This commit is contained in:
parent
7431cde12a
commit
4f591bd41d
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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.device.mgt.extensions.push.notification.provider.mqtt;
|
||||
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Util class to initialize carbon-context.
|
||||
*/
|
||||
public class CarbonContextInitializationUtil {
|
||||
private final static String CARBON_HOME = "carbon.home";
|
||||
|
||||
public static void initializeCarbonContext() {
|
||||
if (System.getProperty("carbon.home") == null) {
|
||||
File file = new File("src/test/resources");
|
||||
if (file.exists()) {
|
||||
System.setProperty(CARBON_HOME, file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(
|
||||
org.wso2.carbon.base.MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(
|
||||
org.wso2.carbon.base.MultitenantConstants.SUPER_TENANT_ID);
|
||||
}
|
||||
}
|
||||
@ -35,8 +35,8 @@ import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/*
|
||||
Unit tests for MQTTBasedPushNotificationProvider class
|
||||
/**
|
||||
* Unit tests for MQTTBasedPushNotificationProvider class
|
||||
*/
|
||||
public class MQTTBasedPushNotificationProviderTest {
|
||||
private MQTTBasedPushNotificationProvider mqttBasedPushNotificationProvider;
|
||||
@ -47,7 +47,7 @@ public class MQTTBasedPushNotificationProviderTest {
|
||||
@BeforeClass
|
||||
public void init() throws NoSuchFieldException, IllegalAccessException, IOException, RegistryException,
|
||||
OutputEventAdapterException {
|
||||
initializeCarbonContext();
|
||||
CarbonContextInitializationUtil.initializeCarbonContext();
|
||||
mqttBasedPushNotificationProvider = Mockito.mock(MQTTBasedPushNotificationProvider.class,
|
||||
Mockito.CALLS_REAL_METHODS);
|
||||
carbonOutputEventAdapterService = Mockito.mock(CarbonOutputEventAdapterService.class,
|
||||
@ -55,19 +55,6 @@ public class MQTTBasedPushNotificationProviderTest {
|
||||
Mockito.doReturn(true).when(carbonOutputEventAdapterService).isPolled(ADAPTER_NAME);
|
||||
}
|
||||
|
||||
private void initializeCarbonContext() throws IOException, RegistryException {
|
||||
if (System.getProperty("carbon.home") == null) {
|
||||
File file = new File("src/test/resources");
|
||||
if (file.exists()) {
|
||||
System.setProperty("carbon.home", file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(
|
||||
org.wso2.carbon.base.MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(
|
||||
org.wso2.carbon.base.MultitenantConstants.SUPER_TENANT_ID);
|
||||
}
|
||||
|
||||
@Test(description = "test getType method")
|
||||
public void testGetType() {
|
||||
String type = mqttBasedPushNotificationProvider.getType();
|
||||
|
||||
@ -63,7 +63,7 @@ public class MQTTNotificationStrategyTest {
|
||||
@BeforeClass
|
||||
public void init() throws NoSuchFieldException, IllegalAccessException, IOException, RegistryException,
|
||||
OutputEventAdapterException {
|
||||
initializeCarbonContext();
|
||||
CarbonContextInitializationUtil.initializeCarbonContext();
|
||||
mqttNotificationStrategy = Mockito.mock(MQTTNotificationStrategy.class, Mockito.CALLS_REAL_METHODS);
|
||||
carbonOutputEventAdapterService = Mockito.mock(CarbonOutputEventAdapterService.class,
|
||||
Mockito.CALLS_REAL_METHODS);
|
||||
@ -72,19 +72,6 @@ public class MQTTNotificationStrategyTest {
|
||||
Mockito.doNothing().when(carbonOutputEventAdapterService).destroy(ADAPTER_NAME);
|
||||
}
|
||||
|
||||
private void initializeCarbonContext() throws IOException, RegistryException {
|
||||
if (System.getProperty("carbon.home") == null) {
|
||||
File file = new File("src/test/resources");
|
||||
if (file.exists()) {
|
||||
System.setProperty("carbon.home", file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(
|
||||
org.wso2.carbon.base.MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(
|
||||
org.wso2.carbon.base.MultitenantConstants.SUPER_TENANT_ID);
|
||||
}
|
||||
|
||||
@Test(description = "Testing the constructor of MQTTNotificationStrategy class")
|
||||
public void getNotificationStrategy() {
|
||||
Map<String, String> properties = new HashMap<>();
|
||||
|
||||
@ -88,6 +88,7 @@ public class DeviceAccessAuthorizationServiceTest {
|
||||
private static final String LAST_NAME = "lastName";
|
||||
private static final String EMAIL = "email";
|
||||
private static final String PASSWORD = "password";
|
||||
private static final String DRIVER_CLASS_NAME = "org.h2.Driver";
|
||||
private DeviceAccessAuthorizationServiceImpl deviceAccessAuthorizationService;
|
||||
private List<DeviceIdentifier> deviceIds = new ArrayList<>();
|
||||
private List<DeviceIdentifier> groupDeviceIds = new ArrayList<>();
|
||||
@ -134,7 +135,7 @@ public class DeviceAccessAuthorizationServiceTest {
|
||||
BasicDataSource dataSource = new BasicDataSource();
|
||||
String connectionUrl = "jdbc:h2:./target/databasetest/CARBON_TEST";
|
||||
dataSource.setUrl(connectionUrl);
|
||||
dataSource.setDriverClassName("org.h2.Driver");
|
||||
dataSource.setDriverClassName(DRIVER_CLASS_NAME);
|
||||
JDBCTenantManager jdbcTenantManager = new JDBCTenantManager(dataSource,
|
||||
MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
|
||||
realmService.setTenantManager(jdbcTenantManager);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user