Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * The contents of this file are subject to the OpenMRS Public License
- * Version 1.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://license.openmrs.org
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * Copyright (C) OpenMRS, LLC. All Rights Reserved.
- */
- package org.openmrs.module.metadatadeploy.handler.impl;
- import org.hibernate.FlushMode;
- import org.hibernate.SessionFactory;
- import org.junit.Assert;
- import org.junit.Test;
- import org.openmrs.Privilege;
- import org.openmrs.Role;
- import org.openmrs.api.context.Context;
- import org.openmrs.module.metadatadeploy.MetadataUtils;
- import org.openmrs.module.metadatadeploy.api.MetadataDeployService;
- import org.openmrs.test.BaseModuleContextSensitiveTest;
- import org.springframework.beans.factory.annotation.Autowired;
- import static org.hamcrest.Matchers.contains;
- import static org.hamcrest.Matchers.containsInAnyOrder;
- import static org.hamcrest.Matchers.is;
- import static org.hamcrest.Matchers.nullValue;
- import static org.openmrs.module.metadatadeploy.bundle.CoreConstructors.idSet;
- import static org.openmrs.module.metadatadeploy.bundle.CoreConstructors.privilege;
- import static org.openmrs.module.metadatadeploy.bundle.CoreConstructors.role;
- import java.lang.reflect.Method;
- /**
- * Tests for {@link RoleDeployHandler}
- */
- public class RoleDeployHandlerTest extends BaseModuleContextSensitiveTest {
- @Autowired
- private MetadataDeployService deployService;
- @Autowired
- private SessionFactory sessionFactory;
- /**
- * Tests use of handler for installation
- */
- /**
- * Replicates DPLY-1: Overwriting of existing roles can lose inherited roles
- */
- @Test
- public void integration_shouldNotLoseInheritedRoles() throws Exception {
- deployService.installObject(role("Role1", "Testing", null, null));
- deployService.installObject(role("Role2", "Testing", idSet("Role1"), null));
- Context.flushSession();
- Context.clearSession();
- //TestUtil.printOutTableContents(getConnection(), "role_role");
- deployService.installObject(role("Role1", "Testing", null, null));
- deployService.installObject(role("Role2", "Testing", idSet("Role1"), null));
- Context.flushSession();
- Context.clearSession();
- //TestUtil.printOutTableContents(getConnection(), "role_role");
- Role role1 = MetadataUtils.existing(Role.class, "Role1");
- Role role2 = MetadataUtils.existing(Role.class, "Role2");
- Assert.assertThat(role2.getInheritedRoles(), contains(role1));
- }
- /**
- * Gets the current hibernate session while taking care of the hibernate 3 and 4 differences.
- *
- * @return the current hibernate session.
- */
- private org.hibernate.Session getCurrentSession() {
- try {
- return sessionFactory.getCurrentSession();
- }
- catch (NoSuchMethodError ex) {
- try {
- Method method = sessionFactory.getClass().getMethod("getCurrentSession", null);
- return (org.hibernate.Session)method.invoke(sessionFactory, null);
- }
- catch (Exception e) {
- throw new RuntimeException("Failed to get the current hibernate session", e);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement