/** * Copyright 2011 the original author or authors. * * Licensed 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.bricket.plugin.role.service; import junit.framework.Assert; import org.bricket.plugin.role.domain.Role; import org.bricket.service.BricketServiceException; import org.bricket.testsupport.AbstractBricketContextTest; import org.junit.Before; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; /** * @author Ingo Renner * @author Henning Teek * */ public class RoleServiceTest extends AbstractBricketContextTest { @Autowired private RoleService roleService; @Before public void setUp() throws BricketServiceException { roleService.init(); } @Test public void testRole() throws Exception { Role r = createRole(); checkRole(r); updateRole(r); checkRole(r); deleteRole(r); } private void deleteRole(Role r) throws BricketServiceException { roleService.deleteRole(r); Role dr = roleService.loadRole(r.getId()); Assert.assertNull("expected null but got " + dr, dr); } private void updateRole(Role r) throws BricketServiceException { r.setName("ROLE_TEST2"); roleService.saveRole(r); } private void checkRole(Role m) { Role mr = roleService.loadRole(m.getId()); Assert.assertEquals(mr.getName(), m.getName()); // equal impl test Assert.assertEquals(m, mr); } private Role createRole() throws BricketServiceException { Role r = roleService.createDomainObject(); r.setName("ROLE_TEST"); r = roleService.saveRole(r); Assert.assertTrue("expected id but got:" + r.getId(), r.getId() != null); return r; } }