Merge pull request #1242 from GDLMadushanka/testCaseFixes

Fix issues in test-cases
4.x.x
Megala Uthayakumar 7 years ago committed by GitHub
commit 9ef622da4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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…
Cancel
Save