Fix test cases related to hierarchical group changes

kernel-4.4.x
Saad Sahibjan 3 years ago
parent e18aa57fe8
commit 24e69d5492

@ -15,11 +15,26 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
* *
*
* Copyright (c) 2021, Entgra (pvt) Ltd. (https://entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. 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.jaxrs.service.impl; package org.wso2.carbon.device.mgt.jaxrs.service.impl;
import org.mockito.Mock;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito; import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PowerMockIgnore;
@ -130,13 +145,14 @@ public class GroupManagementServiceImplTest {
.toReturn(groupManagementProviderService); .toReturn(groupManagementProviderService);
PowerMockito.stub(PowerMockito.method(PrivilegedCarbonContext.class, "getThreadLocalCarbonContext")) PowerMockito.stub(PowerMockito.method(PrivilegedCarbonContext.class, "getThreadLocalCarbonContext"))
.toReturn(context); .toReturn(context);
Mockito.doReturn(2).when(groupManagementProviderService).getGroupCount(Mockito.anyString()); Mockito.doReturn(2).when(groupManagementProviderService)
.getGroupCount(Mockito.anyString(), Mockito.anyString());
Response response = groupManagementService.getGroupCount(); Response response = groupManagementService.getGroupCount();
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
"GetGroupCount request failed with valid parameters"); "GetGroupCount request failed with valid parameters");
Mockito.reset(groupManagementProviderService); Mockito.reset(groupManagementProviderService);
Mockito.doThrow(new GroupManagementException()).when(groupManagementProviderService) Mockito.doThrow(new GroupManagementException()).when(groupManagementProviderService)
.getGroupCount(Mockito.anyString()); .getGroupCount(Mockito.anyString(), Mockito.anyString());
response = groupManagementService.getGroupCount(); response = groupManagementService.getGroupCount();
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"GetGroupCount request succeeded with in-valid parameters"); "GetGroupCount request succeeded with in-valid parameters");
@ -174,16 +190,16 @@ public class GroupManagementServiceImplTest {
public void testGetGroup() throws GroupManagementException { public void testGetGroup() throws GroupManagementException {
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getGroupManagementProviderService")) PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getGroupManagementProviderService"))
.toReturn(groupManagementProviderService); .toReturn(groupManagementProviderService);
Mockito.doReturn(new DeviceGroup()).when(groupManagementProviderService).getGroup(1, false); Mockito.doReturn(new DeviceGroup()).when(groupManagementProviderService).getGroup(1, false, 1);
Mockito.doReturn(null).when(groupManagementProviderService).getGroup(2, false); Mockito.doReturn(null).when(groupManagementProviderService).getGroup(2, false, 1);
Mockito.doThrow(new GroupManagementException()).when(groupManagementProviderService).getGroup(3, false); Mockito.doThrow(new GroupManagementException()).when(groupManagementProviderService).getGroup(3, false, 1);
Response response = groupManagementService.getGroup(1, false); Response response = groupManagementService.getGroup(1, false, 1);
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
"getGroup request failed for a request with valid parameters"); "getGroup request failed for a request with valid parameters");
response = groupManagementService.getGroup(2, false); response = groupManagementService.getGroup(2, false, 1);
Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode(), Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode(),
"getGroup request returned a group for a non-existing group"); "getGroup request returned a group for a non-existing group");
response = groupManagementService.getGroup(3, false); response = groupManagementService.getGroup(3, false, 1);
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"getGroup request returned a group for a in-valid request"); "getGroup request returned a group for a in-valid request");
} }
@ -216,16 +232,16 @@ public class GroupManagementServiceImplTest {
public void testDeleteGroup() throws GroupManagementException { public void testDeleteGroup() throws GroupManagementException {
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getGroupManagementProviderService")) PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getGroupManagementProviderService"))
.toReturn(groupManagementProviderService); .toReturn(groupManagementProviderService);
Mockito.doReturn(true).when(groupManagementProviderService).deleteGroup(1); Mockito.doReturn(true).when(groupManagementProviderService).deleteGroup(1, false);
Mockito.doReturn(false).when(groupManagementProviderService).deleteGroup(2); Mockito.doReturn(false).when(groupManagementProviderService).deleteGroup(2, false);
Mockito.doThrow(new GroupManagementException()).when(groupManagementProviderService).deleteGroup(3); Mockito.doThrow(new GroupManagementException()).when(groupManagementProviderService).deleteGroup(3, false);
Response response = groupManagementService.deleteGroup(1); Response response = groupManagementService.deleteGroup(1, false);
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
"delete group request failed for a request with valid parameters"); "delete group request failed for a request with valid parameters");
response = groupManagementService.deleteGroup(2); response = groupManagementService.deleteGroup(2, false);
Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode(), Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode(),
"Non-existing group was successfully deleted"); "Non-existing group was successfully deleted");
response = groupManagementService.deleteGroup(3); response = groupManagementService.deleteGroup(3, false);
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"Deletion succeeded with an erroneous condition."); "Deletion succeeded with an erroneous condition.");
} }

@ -8,6 +8,23 @@
* *
* http://www.apache.org/licenses/LICENSE-2.0 * 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.
*
* Copyright (c) 2021, Entgra (pvt) Ltd. (https://entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. 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, * Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an * software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@ -103,7 +120,7 @@ public class GroupManagementProviderServiceNegativeTest extends BaseDeviceManage
expectedExceptions = {GroupManagementException.class}, expectedExceptionsMessageRegExp = "Error occurred " expectedExceptions = {GroupManagementException.class}, expectedExceptionsMessageRegExp = "Error occurred "
+ "while retrieving group count of user.*") + "while retrieving group count of user.*")
public void testGetGroupCountWithUserName() throws GroupManagementException { public void testGetGroupCountWithUserName() throws GroupManagementException {
groupManagementProviderService.getGroupCount("test"); groupManagementProviderService.getGroupCount("test", null);
} }
@ -145,7 +162,7 @@ public class GroupManagementProviderServiceNegativeTest extends BaseDeviceManage
expectedExceptions = {GroupManagementException.class}, expectedExceptionsMessageRegExp = "Received empty " expectedExceptions = {GroupManagementException.class}, expectedExceptionsMessageRegExp = "Received empty "
+ "user name for getGroupCount.*") + "user name for getGroupCount.*")
public void testGetGroupCountWithUserName2() throws GroupManagementException { public void testGetGroupCountWithUserName2() throws GroupManagementException {
groupManagementProviderService.getGroupCount(null); groupManagementProviderService.getGroupCount(null, null);
} }
@Test(description = "This method tests getGroups method under negative circumstances", @Test(description = "This method tests getGroups method under negative circumstances",

@ -14,6 +14,23 @@
* KIND, either express or implied. See the License for the * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*
*
* Copyright (c) 2021, Entgra (pvt) Ltd. (https://entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. 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.core.service; package org.wso2.carbon.device.mgt.core.service;
@ -119,13 +136,13 @@ public class GroupManagementProviderServiceTest extends BaseDeviceManagementTest
@Test(dependsOnMethods = ("createGroup")) @Test(dependsOnMethods = ("createGroup"))
public void deleteGroup() throws GroupManagementException { public void deleteGroup() throws GroupManagementException {
DeviceGroup deviceGroup = groupManagementProviderService.getGroup(TestUtils.createDeviceGroup4().getName(), false); DeviceGroup deviceGroup = groupManagementProviderService.getGroup(TestUtils.createDeviceGroup4().getName(), false);
Assert.assertTrue(groupManagementProviderService.deleteGroup(deviceGroup.getGroupId())); Assert.assertTrue(groupManagementProviderService.deleteGroup(deviceGroup.getGroupId(), false));
} }
@Test(dependsOnMethods = ("createGroup")) @Test(dependsOnMethods = ("createGroup"))
public void deleteGroupNotExists() throws GroupManagementException { public void deleteGroupNotExists() throws GroupManagementException {
groupManagementProviderService.deleteGroup(8); groupManagementProviderService.deleteGroup(8, false);
} }
@ -190,7 +207,7 @@ public class GroupManagementProviderServiceTest extends BaseDeviceManagementTest
@Test(dependsOnMethods = ("createGroup")) @Test(dependsOnMethods = ("createGroup"))
public void getGroupCountByUsername(String username) throws GroupManagementException { public void getGroupCountByUsername(String username) throws GroupManagementException {
int x = groupManagementProviderService.getGroupCount(username); int x = groupManagementProviderService.getGroupCount(username, null);
Assert.assertNotNull(x); Assert.assertNotNull(x);
} }

@ -14,6 +14,7 @@ CREATE TABLE IF NOT EXISTS DM_GROUP (
STATUS VARCHAR(50) DEFAULT NULL, STATUS VARCHAR(50) DEFAULT NULL,
DESCRIPTION TEXT DEFAULT NULL, DESCRIPTION TEXT DEFAULT NULL,
OWNER VARCHAR(45) DEFAULT NULL, OWNER VARCHAR(45) DEFAULT NULL,
PARENT_PATH VARCHAR(255) DEFAULT NULL,
TENANT_ID INTEGER DEFAULT 0, TENANT_ID INTEGER DEFAULT 0,
PRIMARY KEY (ID) PRIMARY KEY (ID)
); );

@ -18,6 +18,7 @@ CREATE TABLE IF NOT EXISTS DM_GROUP (
DATE_OF_CREATE BIGINT DEFAULT NULL, DATE_OF_CREATE BIGINT DEFAULT NULL,
DATE_OF_LAST_UPDATE BIGINT DEFAULT NULL, DATE_OF_LAST_UPDATE BIGINT DEFAULT NULL,
OWNER VARCHAR(45) DEFAULT NULL, OWNER VARCHAR(45) DEFAULT NULL,
PARENT_PATH VARCHAR(255) DEFAULT NULL,
TENANT_ID INTEGER DEFAULT 0, TENANT_ID INTEGER DEFAULT 0,
PRIMARY KEY (ID) PRIMARY KEY (ID)
); );
@ -607,4 +608,4 @@ DM_DEVICE.DEVICE_TYPE_ID = DM_DEVICE_TYPE.ID AND
DM_DEVICE.ID = DM_DEVICE_DETAIL.DEVICE_ID DM_DEVICE.ID = DM_DEVICE_DETAIL.DEVICE_ID
ORDER BY TENANT_ID, DEVICE_ID; ORDER BY TENANT_ID, DEVICE_ID;
-- END OF DASHBOARD RELATED VIEWS -- -- END OF DASHBOARD RELATED VIEWS --

Loading…
Cancel
Save