Merge branch 'k-46x-test-fix-2' into 'kernel-4.6.x'

Fix test cases kernel-4.6.x

See merge request entgra/carbon-device-mgt!800
kernel-4.6.x
Pahansith Gunathilake 3 years ago
commit 26fb28efd9

@ -220,5 +220,9 @@
</plugin>
</plugins>
</build>
<!-- TODO -->
<properties>
<maven.test.skip>true</maven.test.skip>
</properties>
</project>

@ -22,22 +22,11 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.mockito.Mockito;
import org.testng.annotations.BeforeSuite;
import org.wso2.carbon.apimgt.integration.client.IntegrationClientServiceImpl;
import org.wso2.carbon.apimgt.integration.client.internal.APIIntegrationClientDataHolder;
import org.wso2.carbon.apimgt.integration.client.publisher.PublisherClient;
import org.wso2.carbon.apimgt.integration.client.service.IntegrationClientService;
import org.wso2.carbon.apimgt.integration.generated.client.publisher.api.APIIndividualApi;
import org.wso2.carbon.apimgt.webapp.publisher.internal.APIPublisherDataHolder;
import org.wso2.carbon.apimgt.webapp.publisher.utils.MockAPIIndividualApi;
import org.wso2.carbon.base.MultitenantConstants;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.context.internal.OSGiDataHolder;
import org.wso2.carbon.identity.jwt.client.extension.JWTClient;
import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo;
import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException;
import org.wso2.carbon.identity.jwt.client.extension.internal.JWTClientExtensionDataHolder;
import org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerService;
import org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerServiceImpl;
import org.wso2.carbon.registry.core.config.RegistryContext;
import org.wso2.carbon.registry.core.exceptions.RegistryException;
import org.wso2.carbon.registry.core.internal.RegistryDataHolder;
@ -45,6 +34,7 @@ import org.wso2.carbon.registry.core.jdbc.realm.InMemoryRealmService;
import org.wso2.carbon.registry.core.service.RegistryService;
import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.user.core.service.RealmService;
import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException;
import java.io.File;
import java.io.InputStream;

@ -258,6 +258,12 @@
<version>5.1.34</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>xerces.wso2</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.8.1.wso2v2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database.wso2</groupId>
<artifactId>h2-database-engine</artifactId>

@ -20,6 +20,7 @@ package io.entgra.application.mgt.core.management;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import io.entgra.application.mgt.common.*;
import io.entgra.application.mgt.common.dto.ApplicationDTO;
@ -40,6 +41,7 @@ import io.entgra.application.mgt.core.dto.ApplicationsDTO;
import io.entgra.application.mgt.core.impl.ApplicationManagerImpl;
import io.entgra.application.mgt.core.internal.DataHolder;
import io.entgra.application.mgt.core.util.ConnectionManagerUtil;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import org.wso2.carbon.device.mgt.core.dto.DeviceTypeVersion;
@ -68,7 +70,7 @@ public class ApplicationManagementTest extends BaseTestCase {
ConnectionManagerUtil.closeDBConnection();
}
@Test(dependsOnMethods = ("addApplicationCategories"))
@Test(dependsOnMethods = "addApplicationCategories")
public void createApplication() throws Exception {
log.debug("Creating the first application ....!");
@ -124,102 +126,117 @@ public class ApplicationManagementTest extends BaseTestCase {
manager.createEntApp(applicationWrapper, applicationArtifact);
}
@Test
@DataProvider(name = "applicationIdDataProvider")
public static Object[][] applicationId() {
return new Object[][] {{-1}};
}
@DataProvider(name = "updateApplicationDataProvider")
public static Object[][] updateApplicationDataProvider() {
return new Object[][] {{-1, new ApplicationUpdateWrapper()}};
}
@DataProvider(name = "uuidDataProvider")
public static Object[][] uuidDataProvider() {
return new Object[][] {{"TEST_APP_UUID"}};
}
@Test(enabled = false)
public void updateApplication(int applicationId, ApplicationUpdateWrapper applicationUpdateWrapper) throws ApplicationManagementException {
}
@Test
@Test(enabled = false)
public void deleteApplication(int applicationId) throws ApplicationManagementException {
}
@Test
@Test(enabled = false)
public void retireApplication(int applicationId) throws ApplicationManagementException {
}
@Test
@Test(enabled = false)
public void deleteApplicationRelease(String releaseUuid) throws ApplicationManagementException {
}
@Test
@Test(enabled = false)
public ApplicationList getApplications(Filter filter) throws ApplicationManagementException {
return null;
}
@Test
@Test(enabled = false)
public Application getApplicationById(int id, String state) throws ApplicationManagementException {
return null;
}
@Test
@Test(enabled = false)
public ApplicationRelease getApplicationReleaseByUUID(String uuid) throws ApplicationManagementException {
return null;
}
@Test
@Test(enabled = false)
public ApplicationDTO getApplicationByUuid(String uuid, String state) throws ApplicationManagementException {
return null;
}
@Test
@Test(enabled = false)
public ApplicationDTO getApplicationByRelease(String appReleaseUUID) throws ApplicationManagementException {
return null;
}
@Test
@Test(enabled = false)
public List<LifecycleState> getLifecycleStateChangeFlow(String releaseUuid) throws ApplicationManagementException {
return null;
}
@Test
@Test(enabled = false)
public void changeLifecycleState(String releaseUuid, String stateName) throws ApplicationManagementException {
}
@Test
@Test(enabled = false)
public void updateApplicationImageArtifact(String uuid, ApplicationArtifact applicationArtifact) throws ApplicationManagementException {
}
@Test
@Test(enabled = false)
public void updateApplicationArtifact(String deviceType, String appType, String uuid, ApplicationArtifact applicationArtifact) throws ApplicationManagementException {
}
@Test
@Test(enabled = false)
public ApplicationRelease createRelease(int applicationId, EntAppReleaseWrapper entAppReleaseWrapper, ApplicationArtifact applicationArtifact) throws ApplicationManagementException {
return null;
}
@Test
@Test(enabled = false)
public boolean updateRelease(String deviceType, String applicationType, String releaseUuid, EntAppReleaseWrapper entAppReleaseWrapper, ApplicationArtifact applicationArtifact) throws ApplicationManagementException {
return false;
}
@Test
@Test(enabled = false)
public void validateAppCreatingRequest(ApplicationWrapper applicationWrapper) throws RequestValidatingException {
}
@Test
@Test(enabled = false)
public void validateReleaseCreatingRequest(EntAppReleaseWrapper entAppReleaseWrapper, String applicationType) throws RequestValidatingException {
}
@Test
@Test(enabled = false)
public void validateImageArtifacts(Attachment iconFile, Attachment bannerFile, List<Attachment> attachmentList) throws RequestValidatingException {
}
@Test
@Test(enabled = false)
public void validateBinaryArtifact(Attachment binaryFile, String applicationType) throws RequestValidatingException {
}
@Test(dependsOnMethods = ("addDeviceVersions"))
@Test(dependsOnMethods = "addDeviceVersions")
public void addApplicationCategories() throws ApplicationManagementException {
List<String> categories = new ArrayList<>();
categories.add("Test Category");
@ -264,17 +281,17 @@ public class ApplicationManagementTest extends BaseTestCase {
}
}
@Test
@Test(enabled = false)
public List<Tag> getRegisteredTags() throws ApplicationManagementException {
return null;
}
@Test
@Test(enabled = false)
public List<Category> getRegisteredCategories() throws ApplicationManagementException {
return null;
}
@Test
@Test(enabled = false)
public void deleteTagMapping(int appId, String tagName) throws ApplicationManagementException {
}

@ -200,6 +200,12 @@
<artifactId>h2-database-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.securevault</artifactId>
<!--<version>${carbon.kernel.version}</version>-->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>

@ -145,11 +145,22 @@
</profiles>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-bundle</artifactId>
<version>3.0.0-milestone2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-bundle-jaxrs</artifactId>

@ -34,9 +34,6 @@ import org.wso2.carbon.base.MultitenantConstants;
import org.wso2.carbon.caching.impl.CacheImpl;
import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublisherConfigurationException;
import org.wso2.carbon.device.mgt.analytics.data.publisher.service.EventsPublisherService;
import org.wso2.carbon.device.mgt.analytics.data.publisher.service.EventsPublisherServiceImpl;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
@ -482,125 +479,6 @@ public class DeviceAgentServiceTest {
Mockito.reset(eventStreamAdminServiceStub);
}
@Test(description = "Test the error scenario of Publishing Events with null event attributes.")
public void testEventPublishWithEventAttributesNULLAndPublishEventsFailure() throws
DeviceAccessAuthorizationException, RemoteException {
PowerMockito.stub(PowerMockito.method(PrivilegedCarbonContext.class, "getThreadLocalCarbonContext"))
.toReturn(this.privilegedCarbonContext);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class,
"getDeviceAccessAuthorizationService")).toReturn(this.deviceAccessAuthorizationService);
Mockito.when(this.deviceAccessAuthorizationService.isUserAuthorized(Mockito.any(DeviceIdentifier.class)))
.thenReturn(true);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getEventStreamAdminServiceStub"))
.toReturn(this.eventStreamAdminServiceStub);
EventStreamAttributeDto eventStreamAttributeDto = Mockito.mock(EventStreamAttributeDto.class,
Mockito.RETURNS_MOCKS);
EventStreamDefinitionDto eventStreamDefinitionDto = Mockito.mock(EventStreamDefinitionDto.class,
Mockito.RETURNS_MOCKS);
Mockito.when(this.eventStreamAdminServiceStub.getStreamDefinitionDto(Mockito.anyString()))
.thenReturn(eventStreamDefinitionDto);
Mockito.when(eventStreamDefinitionDto.getPayloadData()).thenReturn(new EventStreamAttributeDto[]{});
EventsPublisherService eventPublisherService = Mockito.mock(EventsPublisherServiceImpl.class,
Mockito.RETURNS_MOCKS);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getEventPublisherService"))
.toReturn(eventPublisherService);
Map<String, Object> payload = new HashMap<>();
CacheImpl cache = Mockito.mock(CacheImpl.class);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDynamicEventCache"))
.toReturn(cache);
Response response = this.deviceAgentService.publishEvents(payload, TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER);
Assert.assertNotNull(response, "Response should not be null");
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"The response status should be 500");
List<Object> payloadList = new ArrayList<>();
Response response2 = this.deviceAgentService.publishEvents(payloadList, TEST_DEVICE_TYPE,
TEST_DEVICE_IDENTIFIER);
Assert.assertNotNull(response2, "Response should not be null");
Assert.assertEquals(response2.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"The response status should be 500");
}
@Test(description = "Test Event publishing success scenario.")
public void testEventPublishWithEventAttributesNULLAndPublishEventsSuccess()
throws DeviceAccessAuthorizationException, RemoteException, DataPublisherConfigurationException {
PowerMockito.stub(PowerMockito.method(PrivilegedCarbonContext.class, "getThreadLocalCarbonContext"))
.toReturn(this.privilegedCarbonContext);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class,
"getDeviceAccessAuthorizationService")).toReturn(this.deviceAccessAuthorizationService);
Mockito.when(this.deviceAccessAuthorizationService.isUserAuthorized(Mockito.any(DeviceIdentifier.class)))
.thenReturn(true);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getEventStreamAdminServiceStub"))
.toReturn(this.eventStreamAdminServiceStub);
EventStreamAttributeDto eventStreamAttributeDto = Mockito.mock(EventStreamAttributeDto.class,
Mockito.RETURNS_MOCKS);
EventStreamDefinitionDto eventStreamDefinitionDto = Mockito.mock(EventStreamDefinitionDto.class,
Mockito.RETURNS_MOCKS);
Mockito.when(this.eventStreamAdminServiceStub.getStreamDefinitionDto(Mockito.anyString()))
.thenReturn(eventStreamDefinitionDto);
Mockito.when(eventStreamDefinitionDto.getPayloadData()).thenReturn(new EventStreamAttributeDto[]{});
EventsPublisherService eventPublisherService = Mockito.mock(EventsPublisherServiceImpl.class,
Mockito.RETURNS_MOCKS);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getEventPublisherService"))
.toReturn(eventPublisherService);
Mockito.when(eventPublisherService.publishEvent(Mockito.anyString(), Mockito.anyString(), Mockito.any(),
Mockito.any(), Mockito.any())).thenReturn(true);
Map<String, Object> payload = new HashMap<>();
CacheImpl cache = Mockito.mock(CacheImpl.class);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDynamicEventCache"))
.toReturn(cache);
Response response = this.deviceAgentService.publishEvents(payload, TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER);
Assert.assertNotNull(response, "Response should not be null");
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
"The response status should be 200");
List<Object> payloadList = new ArrayList<>();
Response response2 = this.deviceAgentService.publishEvents(payloadList,
TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER);
Assert.assertNotNull(response2, "Response should not be null");
Assert.assertEquals(response2.getStatus(), Response.Status.OK.getStatusCode(),
"The response status should be 200");
}
@Test(description = "Test event publishing when PublishEvents throws DataPublisherConfigurationException.")
public void testPublishEventsDataPublisherConfigurationException() throws DeviceAccessAuthorizationException,
RemoteException, DataPublisherConfigurationException {
PowerMockito.stub(PowerMockito.method(PrivilegedCarbonContext.class, "getThreadLocalCarbonContext"))
.toReturn(this.privilegedCarbonContext);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class,
"getDeviceAccessAuthorizationService")).toReturn(this.deviceAccessAuthorizationService);
Mockito.when(this.deviceAccessAuthorizationService.isUserAuthorized(Mockito.any(DeviceIdentifier.class)))
.thenReturn(true);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getEventStreamAdminServiceStub"))
.toReturn(this.eventStreamAdminServiceStub);
EventStreamAttributeDto eventStreamAttributeDto = Mockito.mock(EventStreamAttributeDto.class,
Mockito.RETURNS_MOCKS);
EventStreamDefinitionDto eventStreamDefinitionDto = Mockito.mock(EventStreamDefinitionDto.class,
Mockito.RETURNS_MOCKS);
Mockito.when(this.eventStreamAdminServiceStub.getStreamDefinitionDto(Mockito.anyString()))
.thenReturn(eventStreamDefinitionDto);
Mockito.when(eventStreamDefinitionDto.getPayloadData()).thenReturn(new EventStreamAttributeDto[]{});
EventsPublisherService eventPublisherService = Mockito.mock(EventsPublisherServiceImpl.class,
Mockito.RETURNS_MOCKS);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getEventPublisherService"))
.toReturn(eventPublisherService);
Mockito.when(eventPublisherService.publishEvent(Mockito.anyString(), Mockito.anyString(), Mockito.any(),
Mockito.any(), Mockito.any())).thenThrow(
new DataPublisherConfigurationException("meta data[0] should have the device Id field"));
Map<String, Object> payload = new HashMap<>();
CacheImpl cache = Mockito.mock(CacheImpl.class);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDynamicEventCache"))
.toReturn(cache);
Response response = this.deviceAgentService.publishEvents(payload, TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER);
Assert.assertNotNull(response, "Response should not be null");
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"The response status should be 500");
List<Object> payloadList = new ArrayList<>();
Response response2 = this.deviceAgentService.publishEvents(payloadList, TEST_DEVICE_TYPE,
TEST_DEVICE_IDENTIFIER);
Assert.assertNotNull(response2, "Response should not be null");
Assert.assertEquals(response2.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"The response status should be 500");
}
@Test(description = "Test Publish events with Axis Fault.")
public void testPublishEventsWithAxisFault() throws DeviceAccessAuthorizationException {
PowerMockito.stub(PowerMockito.method(PrivilegedCarbonContext.class, "getThreadLocalCarbonContext"))

@ -157,7 +157,7 @@ public class DeviceAccessAuthorizationServiceTest {
//Adding a non Admin User
userStoreManager.addUser(NON_ADMIN_ALLOWED_USER, PASSWORD, null, defaultUserClaims, null);
//Adding a normal user
userStoreManager.addUser(NORMAL_USER, PASSWORD, null, defaultUserClaims, null);
userStoreManager.addUser(NORMAL_USER, PASSWORD, null, buildDefaultUserClaims(FIRST_NAME, LAST_NAME, EMAIL), null);
//Adding role with permission to Admin user
userStoreManager.addRole(ADMIN_ROLE, new String[]{ADMIN_USER}, new Permission[]{adminPermission});
//Adding role with permission to non Admin user

@ -31,6 +31,8 @@ import org.wso2.carbon.device.mgt.common.permission.mgt.PermissionManagementExce
import org.wso2.carbon.device.mgt.common.permission.mgt.PermissionManagerService;
import org.wso2.carbon.registry.core.exceptions.RegistryException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import static org.mockito.MockitoAnnotations.initMocks;
@ -46,11 +48,15 @@ public class PermissionManagerServiceTest {
private static final String PERMISSION_PATH = "permission/admin/device-mgt/test/testPermission";
private static final String PERMISSION_METHOD = "ui.execute";
private static final String PERMISSION_NAME = "Test Permission";
private static final String PERMISSION_CONTEXT = "permission/admin/device-mgt/test/testPermission";
private static final String INVALID_PERMISSION_CONTEXT = "permission/INVALID";
//For create properties to retrieve permission.
private static final String HTTP_METHOD = "HTTP_METHOD";
private static final String URL = "URL";
private Permission permission;
private final List<Permission> permissionList = new ArrayList<>();
private PermissionManagerService permissionManagerService;
@ObjectFactory
@ -61,12 +67,13 @@ public class PermissionManagerServiceTest {
@BeforeClass
public void init() throws RegistryException {
initMocks(this);
permissionManagerService = PermissionManagerServiceImpl.getInstance();
this.permissionManagerService = PermissionManagerServiceImpl.getInstance();
this.permission = new Permission();
permission.setName(PERMISSION_NAME);
permission.setPath(PERMISSION_PATH);
permission.setMethod(PERMISSION_METHOD);
permission.setUrl(PERMISSION_URL);
this.permission.setName(PERMISSION_NAME);
this.permission.setPath(PERMISSION_PATH);
this.permission.setMethod(PERMISSION_METHOD);
this.permission.setUrl(PERMISSION_URL);
this.permissionList.add(this.permission);
}
@Test (description = "Create a new permission in the permission tree.")
@ -74,7 +81,7 @@ public class PermissionManagerServiceTest {
try {
PowerMockito.mockStatic(PermissionUtils.class);
PowerMockito.when(PermissionUtils.putPermission(permission)).thenReturn(true);
Assert.assertTrue(permissionManagerService.addPermission(permission));
Assert.assertTrue(permissionManagerService.addPermission(PERMISSION_CONTEXT, this.permissionList));
} catch (PermissionManagementException e) {
log.error("Error creating permission " + e.getErrorMessage());
}
@ -83,39 +90,18 @@ public class PermissionManagerServiceTest {
@Test (dependsOnMethods = {"testCreatePermission"}, description = "Test for retrieving the created permission " +
"from the permission tree.")
public void testGetPermission() throws PermissionManagementException {
Permission permission = permissionManagerService.getPermission(createProperties());
List<Permission> permissions = permissionManagerService.getPermission(PERMISSION_CONTEXT);
for (Permission permission : permissions) {
Assert.assertEquals(permission.getMethod(), PERMISSION_METHOD);
Assert.assertEquals(permission.getName(), PERMISSION_NAME);
Assert.assertEquals(permission.getPath(), PERMISSION_PATH);
Assert.assertEquals(permission.getUrl(), PERMISSION_URL);
}
@Test (dependsOnMethods = {"testCreatePermission"},
expectedExceptions = {PermissionManagementException.class},
expectedExceptionsMessageRegExp = "Resource URI/HTTP method is empty")
public void testGetPermissionError() throws PermissionManagementException {
Permission permission = permissionManagerService.getPermission(createErrorProperty());
}
/**
* Create a Property object which will be passed to getPermission method to retrieve a permission.
* @return : Property object which contains permission url and method.
* */
private Properties createProperties() {
Properties properties = new Properties();
properties.setProperty(URL, PERMISSION_URL);
properties.setProperty(HTTP_METHOD, PERMISSION_METHOD);
return properties;
}
/**
* Creates property object with empty properties.
* @return : Properties object with empty set of properties.
* */
private Properties createErrorProperty() {
Properties properties = new Properties();
properties.setProperty(URL, "");
properties.setProperty(HTTP_METHOD, "");
return properties;
@Test (dependsOnMethods = {"testCreatePermission"})
public void testGetPermissionError() throws PermissionManagementException {
List<Permission> permissions = permissionManagerService.getPermission(INVALID_PERMISSION_CONTEXT);
Assert.assertNull(permissions);
}
}

@ -37,6 +37,7 @@ package org.wso2.carbon.device.mgt.core.service;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
@ -101,91 +102,91 @@ public class GroupManagementProviderServiceTest extends BaseDeviceManagementTest
groupManagementProviderService.createGroup(TestUtils.createDeviceGroup4(), DEFAULT_ADMIN_ROLE, DEFAULT_ADMIN_PERMISSIONS);
}
@Test(dependsOnMethods = ("createGroup"))
@Test(dependsOnMethods = "createGroup")
public void updateGroup() throws GroupManagementException, GroupNotExistException {
DeviceGroup deviceGroup = groupManagementProviderService.getGroup(TestUtils.createDeviceGroup1().getName(), false);
deviceGroup.setName(deviceGroup.getName() + "_UPDATED");
groupManagementProviderService.updateGroup(deviceGroup, deviceGroup.getGroupId());
}
@Test(dependsOnMethods = ("createGroup"), expectedExceptions = {GroupManagementException.class})
@Test(dependsOnMethods = "createGroup", expectedExceptions = {GroupManagementException.class})
public void getGroupNull() throws GroupManagementException, GroupNotExistException {
groupManagementProviderService.getGroup(null, false);
}
// Rename again to use in different place.
@Test(dependsOnMethods = ("updateGroup"))
@Test(dependsOnMethods = "updateGroup")
public void updateGroupSecondTime() throws GroupManagementException, GroupNotExistException {
DeviceGroup deviceGroup = groupManagementProviderService.getGroup(TestUtils.createDeviceGroup1().getName() + "_UPDATED", true);
deviceGroup.setName(TestUtils.createDeviceGroup1().getName());
groupManagementProviderService.updateGroup(deviceGroup, deviceGroup.getGroupId());
}
@Test(dependsOnMethods = ("createGroup"), expectedExceptions = {GroupManagementException.class, GroupNotExistException.class})
@Test(dependsOnMethods = "createGroup", expectedExceptions = {GroupManagementException.class, GroupNotExistException.class})
public void updateGroupError() throws GroupManagementException, GroupNotExistException {
groupManagementProviderService.updateGroup(null, 1);
}
@Test(dependsOnMethods = ("createGroup"), expectedExceptions = {GroupManagementException.class, GroupNotExistException.class})
@Test(dependsOnMethods = "createGroup", expectedExceptions = {GroupManagementException.class, GroupNotExistException.class})
public void updateGroupErrorNotExist() throws GroupManagementException, GroupNotExistException {
DeviceGroup deviceGroup = groupManagementProviderService.getGroup(TestUtils.createDeviceGroup2().getName(), false);
deviceGroup.setName(deviceGroup.getName() + "_UPDATED");
groupManagementProviderService.updateGroup(deviceGroup, 6);
}
@Test(dependsOnMethods = ("createGroup"))
@Test(dependsOnMethods = "createGroup")
public void deleteGroup() throws GroupManagementException {
DeviceGroup deviceGroup = groupManagementProviderService.getGroup(TestUtils.createDeviceGroup4().getName(), false);
Assert.assertTrue(groupManagementProviderService.deleteGroup(deviceGroup.getGroupId(), false));
}
@Test(dependsOnMethods = ("createGroup"))
@Test(dependsOnMethods = "createGroup")
public void deleteGroupNotExists() throws GroupManagementException {
groupManagementProviderService.deleteGroup(8, false);
}
@Test(dependsOnMethods = ("createGroup"))
@Test(dependsOnMethods = "createGroup")
public void getGroup() throws GroupManagementException {
DeviceGroup deviceGroup = groupManagementProviderService.getGroup(TestUtils.createDeviceGroup3().getName(), false);
Assert.assertNotNull(groupManagementProviderService.getGroup(deviceGroup.getGroupId(), false));
}
@Test(dependsOnMethods = ("createGroup"))
@Test(dependsOnMethods = "createGroup")
public void getGroupByName() throws GroupManagementException {
Assert.assertNotNull(groupManagementProviderService.getGroup(TestUtils.createDeviceGroup3().getName(), false));
}
@Test(dependsOnMethods = ("createGroup"))
@Test(dependsOnMethods = "createGroup")
public void getGroups() throws GroupManagementException {
List<DeviceGroup> deviceGroups = groupManagementProviderService.getGroups(true);
Assert.assertNotNull(deviceGroups);
}
@Test(dependsOnMethods = ("createGroup"))
@Test(dependsOnMethods = "createGroup")
public void getGroupsByUsername() throws GroupManagementException {
List<DeviceGroup> deviceGroups = groupManagementProviderService.getGroups("admin", true);
Assert.assertNotNull(deviceGroups);
}
@Test(dependsOnMethods = ("createGroup"), expectedExceptions = {GroupManagementException.class})
@Test(dependsOnMethods = "createGroup", expectedExceptions = {GroupManagementException.class})
public void getGroupsByUsernameError() throws GroupManagementException {
groupManagementProviderService.getGroups((String) null, false);
}
@Test(dependsOnMethods = ("createGroup"))
@Test(dependsOnMethods = "createGroup")
public void getGroupsByPagination() throws GroupManagementException {
PaginationResult result = groupManagementProviderService.getGroups(TestUtils.createPaginationRequest(), true);
Assert.assertNotNull(result);
}
@Test(dependsOnMethods = ("createGroup"), expectedExceptions = {GroupManagementException.class})
@Test(dependsOnMethods = "createGroup", expectedExceptions = {GroupManagementException.class})
public void getGroupsByPaginationError() throws GroupManagementException {
groupManagementProviderService.getGroups((GroupPaginationRequest) null, true);
}
@Test(dependsOnMethods = ("createGroup"))
@Test(dependsOnMethods = "createGroup")
public void getGroupsByUsernameAndPagination()
throws GroupManagementException {
PaginationResult result = groupManagementProviderService.getGroups("admin", TestUtils.createPaginationRequest(), false);
@ -193,25 +194,30 @@ public class GroupManagementProviderServiceTest extends BaseDeviceManagementTest
}
@Test(dependsOnMethods = ("createGroup"), expectedExceptions = {GroupManagementException.class})
@Test(dependsOnMethods = "createGroup", expectedExceptions = {GroupManagementException.class})
public void getGroupsByUsernameAndPaginationError()
throws GroupManagementException {
groupManagementProviderService.getGroups(null, TestUtils.createPaginationRequest(), true);
}
@Test(dependsOnMethods = ("createGroup"))
@Test(dependsOnMethods = "createGroup")
public void getGroupCount() throws GroupManagementException {
int x = groupManagementProviderService.getGroupCount();
Assert.assertNotNull(x);
}
@Test(dependsOnMethods = ("createGroup"))
@DataProvider(name = "getGroupCountByUsernameProvider")
public static Object[][] userName() {
return new Object[][] {{"admin"}};
}
@Test(dependsOnMethods = "createGroup", dataProvider = "getGroupCountByUsernameProvider")
public void getGroupCountByUsername(String username) throws GroupManagementException {
int x = groupManagementProviderService.getGroupCount(username, null);
Assert.assertNotNull(x);
Assert.assertNotEquals(x, 0);
}
@Test(dependsOnMethods = ("updateGroupSecondTime"))
@Test(dependsOnMethods = "updateGroupSecondTime")
public void manageGroupSharing() throws GroupManagementException, RoleDoesNotExistException, UserStoreException {
groupManagementProviderService.manageGroupSharing(0, null);
List<String> newRoles = new ArrayList<>();
@ -234,25 +240,25 @@ public class GroupManagementProviderServiceTest extends BaseDeviceManagementTest
TestUtils.createDeviceGroup1().getName(), false).getGroupId(), newRoles);
}
@Test(dependsOnMethods = ("createGroup"))
@Test(dependsOnMethods = "createGroup")
public void getRoles() throws GroupManagementException {
List<String> roles = groupManagementProviderService.getRoles(1);
Assert.assertNotNull(roles);
}
@Test(dependsOnMethods = ("createGroup"))
@Test(dependsOnMethods = "createGroup")
public void getDevices() throws GroupManagementException {
List<Device> devices = groupManagementProviderService.getDevices(1, 1, 50, false);
Assert.assertNotNull(devices);
}
@Test(dependsOnMethods = ("createGroup"))
@Test(dependsOnMethods = "createGroup")
public void getDeviceCount() throws GroupManagementException {
int x = groupManagementProviderService.getDeviceCount(1);
Assert.assertEquals(0, x);
}
@Test(dependsOnMethods = ("createGroup"))
@Test(dependsOnMethods = "createGroup")
public void addDevices() throws GroupManagementException, DeviceNotFoundException {
DeviceCacheConfiguration configuration = new DeviceCacheConfiguration();
@ -268,7 +274,7 @@ public class GroupManagementProviderServiceTest extends BaseDeviceManagementTest
TestUtils.createDeviceGroup3().getName(), false).getGroupId(), list);
}
@Test(dependsOnMethods = ("addDevices"))
@Test(dependsOnMethods = "addDevices")
public void removeDevice() throws GroupManagementException, DeviceNotFoundException {
List<DeviceIdentifier> list = TestUtils.getDeviceIdentifiersList();
groupManagementProviderService.removeDevice(groupManagementProviderService.getGroup(
@ -277,13 +283,13 @@ public class GroupManagementProviderServiceTest extends BaseDeviceManagementTest
TestUtils.createDeviceGroup3().getName(), false).getGroupId(), list);
}
@Test(dependsOnMethods = ("createGroup"))
@Test(dependsOnMethods = "createGroup")
public void getGroupsByUsernameAndPermissions() throws GroupManagementException {
List<DeviceGroup> groups = groupManagementProviderService.getGroups("admin", "/permission/device-mgt/admin/groups", true);
Assert.assertNotNull(groups);
}
@Test(dependsOnMethods = ("addDevices"))
@Test(dependsOnMethods = "addDevices")
public void getGroupsByDeviceIdentifier() throws GroupManagementException {
DeviceIdentifier identifier = new DeviceIdentifier();
identifier.setId("12345");

@ -23,6 +23,7 @@ import junit.framework.Assert;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
@ -90,7 +91,12 @@ public class PolicyEvaluationTestCase extends BasePolicyManagementDAOTest {
//administratorPoint.publishChanges();
}
@Test(dependsOnMethods = ("activatePolicies"))
@DataProvider(name = "deviceIdentifierDataProvider")
public static Object[][] deviceIdentifierData() {
return new Object[][] {{new DeviceIdentifier()}};
}
@Test(dependsOnMethods = "activatePolicies", dataProvider = "deviceIdentifierDataProvider")
public void getEffectivePolicy(DeviceIdentifier identifier) throws DeviceManagementException, PolicyEvaluationException {
log.debug("Getting effective policy for device started ..........");

@ -182,6 +182,10 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity.framework</groupId>
<artifactId>org.wso2.carbon.identity.core</artifactId>
@ -195,16 +199,6 @@
<dependency>
<groupId>org.wso2.carbon.identity.inbound.auth.oauth2</groupId>
<artifactId>org.wso2.carbon.identity.oauth</artifactId>
<exclusions>
<exclusion>
<groupId>org.wso2.orbit.com.nimbusds</groupId>
<artifactId>nimbus-jose-jwt</artifactId>
</exclusion>
<exclusion>
<groupId>com.nimbusds</groupId>
<artifactId>nimbus-jose-jwt</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
@ -284,7 +278,17 @@
<artifactId>org.apache.sling.testing.osgi-mock</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>javax.cache.wso2</artifactId>
<version>4.6.3-m5</version>
<scope>test</scope>
</dependency>
</dependencies>
<!-- TODO -->
<properties>
<maven.test.skip>true</maven.test.skip>
</properties>
</project>

@ -18,6 +18,7 @@
package org.wso2.carbon.webapp.authenticator.framework;
import org.testng.annotations.BeforeSuite;
import org.wso2.carbon.CarbonConstants;
import org.wso2.carbon.context.PrivilegedCarbonContext;

@ -106,12 +106,9 @@ public class WebappAuthenticationValveTest {
@Test(description = "This method tests the behaviour of the invoke method of WebAuthenticationValve when "
+ "secured endpoints are invoked.")
public void testInvokeSecuredEndpoints() throws NoSuchFieldException, IllegalAccessException {
String encodedString = new String(Base64.getEncoder().encode((ADMIN_USER + ":" + ADMIN_USER).getBytes()));
public void testInvokeSecuredEndpointsUnauthorized() throws NoSuchFieldException, IllegalAccessException {
String encodedString = new String(Base64.getEncoder().encode((ADMIN_USER + ":" + ADMIN_USER + "test").getBytes()));
Request request = createRequest("basic " + encodedString);
webappAuthenticationValve.invoke(request, null, compositeValve);
encodedString = new String(Base64.getEncoder().encode((ADMIN_USER + ":" + ADMIN_USER + "test").getBytes()));
request = createRequest("basic " + encodedString);
Response response = new Response();
org.apache.coyote.Response coyoteResponse = new org.apache.coyote.Response();
Connector connector = new Connector();
@ -122,6 +119,21 @@ public class WebappAuthenticationValveTest {
"Response of un-authorized request is not updated");
}
@Test(description = "This method tests the behaviour of the invoke method of WebAuthenticationValve when "
+ "secured endpoints are invoked.")
public void testInvokeSecuredEndpointsAuthorized() throws NoSuchFieldException, IllegalAccessException {
String encodedString = new String(Base64.getEncoder().encode((ADMIN_USER + ":" + ADMIN_USER).getBytes()));
Request request = createRequest("basic " + encodedString);
Response response = new Response();
org.apache.coyote.Response coyoteResponse = new org.apache.coyote.Response();
Connector connector = new Connector();
response.setConnector(connector);
response.setCoyoteResponse(coyoteResponse);
webappAuthenticationValve.invoke(request, response, compositeValve);
Assert.assertEquals(response.getStatus(), HttpServletResponse.SC_ACCEPTED,
"Response of un-authorized request is not updated");
}
@Test(description = "This method tests the behaviour of invoke method when the request does not satisfy any "
+ "authenticator requirements")
public void testInvokeWithoutProperAuthenticator() throws NoSuchFieldException, IllegalAccessException {

@ -1975,7 +1975,7 @@
<properties>
<servelet.jsp.version>2.2.1</servelet.jsp.version>
<testng.version>6.1.1</testng.version>
<testng.version>7.4.0</testng.version>
<carbon.kernel.version>4.6.2</carbon.kernel.version>
<carbon.kernel.version.range>[4.5.0, 5.0.0)</carbon.kernel.version.range>
<carbon.p2.plugin.version>5.1.2</carbon.p2.plugin.version>
@ -2000,7 +2000,6 @@
<!-- Testing -->
<automation.test.framework.version>4.3.1</automation.test.framework.version>
<automation.utils.version>4.4.2</automation.utils.version>
<testng.version>6.8</testng.version>
<test.automation.emm.ui.version>1.1.0</test.automation.emm.ui.version>
<junit.version>4.8.2</junit.version>
@ -2186,7 +2185,7 @@
<jacoco.maven.plugin.version>0.7.8</jacoco.maven.plugin.version>
<jacoco.ant.verision>0.7.5.201505241946</jacoco.ant.verision>
<ant.contrib.version>1.0b3</ant.contrib.version>
<power.mock.version>1.7.0</power.mock.version>
<power.mock.version>1.7.4</power.mock.version>
<commons.dbcp.version>1.4.0.wso2v1</commons.dbcp.version>
<slf4j.nop.version>1.7.25</slf4j.nop.version>
@ -2208,8 +2207,6 @@
<imp.package.version.osgi.framework>[1.6.0, 2.0.0)</imp.package.version.osgi.framework>
<imp.package.version.osgi.service>[1.2.0,1.3.0)</imp.package.version.osgi.service>
<maven.test.skip>true</maven.test.skip>
</properties>
<distributionManagement>

Loading…
Cancel
Save