diff --git a/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/interceptor/ExceptionHandlerInterceptorTest.java b/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/interceptor/ExceptionHandlerInterceptorTest.java index e91b694..b5546ed 100644 --- a/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/interceptor/ExceptionHandlerInterceptorTest.java +++ b/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/interceptor/ExceptionHandlerInterceptorTest.java @@ -1,336 +1,342 @@ -///* -// * Demoiselle Framework -// * Copyright (C) 2010 SERPRO -// * ---------------------------------------------------------------------------- -// * This file is part of Demoiselle Framework. -// * -// * Demoiselle Framework is free software; you can redistribute it and/or -// * modify it under the terms of the GNU Lesser General Public License version 3 -// * as published by the Free Software Foundation. -// * -// * This program is distributed in the hope that it will be useful, -// * but WITHOUT ANY WARRANTY; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU General Public License for more details. -// * -// * You should have received a copy of the GNU Lesser General Public License version 3 -// * along with this program; if not, see -// * or write to the Free Software Foundation, Inc., 51 Franklin Street, -// * Fifth Floor, Boston, MA 02110-1301, USA. -// * ---------------------------------------------------------------------------- -// * Este arquivo é parte do Framework Demoiselle. -// * -// * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou -// * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação -// * do Software Livre (FSF). -// * -// * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA -// * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou -// * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português -// * para maiores detalhes. -// * -// * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título -// * "LICENCA.txt", junto com esse programa. Se não, acesse -// * ou escreva para a Fundação do Software Livre (FSF) Inc., -// * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. -// */ -//package br.gov.frameworkdemoiselle.internal.interceptor; -// -//import static org.easymock.EasyMock.expect; -//import static org.easymock.EasyMock.verify; -//import static org.junit.Assert.assertEquals; -//import static org.junit.Assert.assertNull; -//import static org.junit.Assert.assertTrue; -//import static org.junit.Assert.fail; -//import static org.powermock.api.easymock.PowerMock.mockStatic; -//import static org.powermock.api.easymock.PowerMock.replay; -//import static org.powermock.api.easymock.PowerMock.replayAll; -//import static org.powermock.api.easymock.PowerMock.verifyAll; -// -//import java.util.Locale; -// -//import javax.interceptor.InvocationContext; -// -//import org.easymock.EasyMock; -//import org.junit.Before; -//import org.junit.Test; -//import org.junit.runner.RunWith; -//import org.powermock.api.easymock.PowerMock; -//import org.powermock.core.classloader.annotations.PrepareForTest; -//import org.powermock.modules.junit4.PowerMockRunner; -//import org.slf4j.Logger; -// -//import br.gov.frameworkdemoiselle.DemoiselleException; -//import br.gov.frameworkdemoiselle.exception.ExceptionHandler; -//import br.gov.frameworkdemoiselle.internal.bootstrap.CoreBootstrap; -//import br.gov.frameworkdemoiselle.util.ResourceBundle; -// -//@RunWith(PowerMockRunner.class) -//@PrepareForTest(CoreBootstrap.class) -//public class ExceptionHandlerInterceptorTest { -// -// private ExceptionHandlerInterceptor interceptor; -// -// private InvocationContext context; -// -// private Logger logger; -// -// private ResourceBundle bundle; -// -// class TestException extends DemoiselleException { -// -// private static final long serialVersionUID = 1L; -// -// public TestException(String message) { -// super(message); -// } -// } -// -// class ClassWithMethodsAnnotatedWithExceptionHandler { -// -// int times = 0; -// -// @ExceptionHandler -// public void methodWithExceptionHandlerAnotation(DemoiselleException cause) { -// times++; -// } -// -// @ExceptionHandler -// public void methodWithExceptionHandlerAnotationAndGenericException(Exception cause) { -// times++; -// } -// -// } -// -// class ClassWithoutMethodsAnnotatedWithExceptionHandler { -// -// public void methodWithoutExceptionHandlerAnotation(DemoiselleException cause) { -// } -// } -// -// class ClassWithMethodsAnnotatedWithExceptionHandlerAndThrowException { -// -// int times = 0; -// -// @ExceptionHandler -// public void methodWithExceptionHandlerAnotation(DemoiselleException cause) { -// times++; -// throw new RuntimeException(); -// } -// } -// -// class ClassWithMethodWithoutParameterAnnotatedWithExceptionHandler { -// -// @ExceptionHandler -// public void methodWithExceptionHandlerAnotation() { -// } -// -// } -// -// class ClassWithExceptionHandlerMethodThatRethrowException { -// -// int times = 0; -// -// @ExceptionHandler -// public void methodThatRethrowException(TestException cause) { -// times++; -// throw cause; -// } -// -// } -// -// @Before -// public void setUp() throws Exception { -// this.logger = PowerMock.createMock(Logger.class); -// this.bundle = new ResourceBundle("demoiselle-core-bundle", Locale.getDefault()); -// this.logger.info(EasyMock.anyObject(String.class)); -// PowerMock.expectLastCall().anyTimes(); -// replay(this.logger); -// this.interceptor = new ExceptionHandlerInterceptor(this.logger, this.bundle); -// this.context = PowerMock.createMock(InvocationContext.class); -// mockStatic(CoreBootstrap.class); -// } -// -// @Test -// public void manageSuccessfully() throws Throwable { -// expect(this.context.proceed()).andReturn(null); -// replay(); -// assertEquals(null, this.interceptor.manage(this.context)); -// verify(); -// } -// -// @Test -// public void manageWithClassThatDoesNotContainHandleMethod() throws Exception { -// ClassWithoutMethodsAnnotatedWithExceptionHandler classWithoutException = new ClassWithoutMethodsAnnotatedWithExceptionHandler(); -// expect(this.context.getTarget()).andReturn(classWithoutException); -// expect(this.context.proceed()).andThrow(new DemoiselleException("")); -// expect(CoreBootstrap.isAnnotatedType(ClassWithoutMethodsAnnotatedWithExceptionHandler.class)).andReturn(true); -// replayAll(this.context, ClassWithoutMethodsAnnotatedWithExceptionHandler.class); -// -// try { -// this.interceptor.manage(this.context); -// fail(); -// } catch (DemoiselleException e) { -// assertTrue(true); -// } -// -// verifyAll(); -// } -// -// @Test -// public void manageWithClassThatContainsHandleMethod() throws Exception { -// ClassWithMethodsAnnotatedWithExceptionHandler classWithException = new ClassWithMethodsAnnotatedWithExceptionHandler(); -// expect(this.context.getTarget()).andReturn(classWithException).anyTimes(); -// expect(this.context.proceed()).andThrow(new DemoiselleException("")); -// expect(CoreBootstrap.isAnnotatedType(ClassWithMethodsAnnotatedWithExceptionHandler.class)).andReturn(true); -// replayAll(this.context, CoreBootstrap.class); -// -// assertNull(this.interceptor.manage(this.context)); -// assertEquals(1, classWithException.times); -// verifyAll(); -// } -// -// @Test -// public void manageWithClassThatContainsParentExceptionHandleMethod() throws Exception { -// ClassWithMethodsAnnotatedWithExceptionHandler classWithException = new ClassWithMethodsAnnotatedWithExceptionHandler(); -// expect(this.context.getTarget()).andReturn(classWithException).anyTimes(); -// expect(this.context.proceed()).andThrow(new DemoiselleException("")); -// expect(CoreBootstrap.isAnnotatedType(ClassWithMethodsAnnotatedWithExceptionHandler.class)).andReturn(true); -// replayAll(this.context, CoreBootstrap.class); -// -// assertNull(this.interceptor.manage(this.context)); -// assertEquals(1, classWithException.times); -// verifyAll(); -// } -// -// @Test -// public void manageWithClassThatContainsHandleMethodWithDiferentException() throws Exception { -// ClassWithMethodsAnnotatedWithExceptionHandler classWithException = new ClassWithMethodsAnnotatedWithExceptionHandler(); -// expect(this.context.getTarget()).andReturn(classWithException).anyTimes(); -// expect(this.context.proceed()).andThrow(new TestException("")); -// replay(this.context); -// expect(CoreBootstrap.isAnnotatedType(ClassWithMethodsAnnotatedWithExceptionHandler.class)).andReturn(true); -// replayAll(this.context, CoreBootstrap.class); -// -// try { -// this.interceptor.manage(this.context); -// fail(); -// } catch (TestException e) { -// assertEquals(0, classWithException.times); -// } -// -// verify(); -// } -// -// @Test -// public void manageWithClassThatContainsHandleMethodThatThrowsAnotherException() throws Exception { -// ClassWithMethodsAnnotatedWithExceptionHandlerAndThrowException classWithException = new ClassWithMethodsAnnotatedWithExceptionHandlerAndThrowException(); -// expect(this.context.getTarget()).andReturn(classWithException).anyTimes(); -// expect(this.context.proceed()).andThrow(new DemoiselleException("")); -// expect(CoreBootstrap.isAnnotatedType(ClassWithMethodsAnnotatedWithExceptionHandlerAndThrowException.class)) -// .andReturn(true); -// replayAll(this.context, CoreBootstrap.class); -// -// try { -// this.interceptor.manage(this.context); -// fail(); -// } catch (RuntimeException e) { -// assertEquals(1, classWithException.times); -// } -// -// verifyAll(); -// } -// -// @Test -// public void manageWithClassThatContainsHandleMethodsAndIsInvokedTwice() throws Exception { -// ClassWithMethodsAnnotatedWithExceptionHandler classWithException = new ClassWithMethodsAnnotatedWithExceptionHandler(); -// expect(this.context.getTarget()).andReturn(classWithException).anyTimes(); -// expect(this.context.proceed()).andThrow(new DemoiselleException("")); -// expect(CoreBootstrap.isAnnotatedType(ClassWithMethodsAnnotatedWithExceptionHandler.class)).andReturn(true) -// .anyTimes(); -// replayAll(this.context, CoreBootstrap.class); -// -// assertNull(this.interceptor.manage(this.context)); -// assertEquals(1, classWithException.times); -// -// this.context = PowerMock.createMock(InvocationContext.class); -// expect(this.context.getTarget()).andReturn(classWithException).anyTimes(); -// expect(this.context.proceed()).andThrow(new Exception("")); -// replayAll(this.context, CoreBootstrap.class); -// -// assertNull(this.interceptor.manage(this.context)); -// assertEquals(2, classWithException.times); -// verifyAll(); -// -// } -// -// @Test -// public void manageWithClassThatContainsHandleMethodWithoutParameter() throws Exception { -// ClassWithMethodWithoutParameterAnnotatedWithExceptionHandler classWithException = new ClassWithMethodWithoutParameterAnnotatedWithExceptionHandler(); -// expect(this.context.getTarget()).andReturn(classWithException).anyTimes(); -// expect(this.context.proceed()).andThrow(new DemoiselleException("")); -// expect(CoreBootstrap.isAnnotatedType(ClassWithMethodWithoutParameterAnnotatedWithExceptionHandler.class)) -// .andReturn(true); -// replayAll(this.context, CoreBootstrap.class); -// -// try { -// this.interceptor.manage(this.context); -// fail(); -// } catch (DemoiselleException e) { -// assertTrue(true); -// } -// -// verifyAll(); -// } -// -// @Test -// public void manageHandlerMethodThatRethrowExpectedException() throws Exception { -// ClassWithExceptionHandlerMethodThatRethrowException testClass = new ClassWithExceptionHandlerMethodThatRethrowException(); -// expect(this.context.getTarget()).andReturn(testClass).anyTimes(); -// expect(this.context.proceed()).andThrow(new TestException("")); -// expect(CoreBootstrap.isAnnotatedType(ClassWithExceptionHandlerMethodThatRethrowException.class)) -// .andReturn(true); -// replayAll(this.context, CoreBootstrap.class); -// -// try { -// this.interceptor.manage(this.context); -// fail(); -// } catch (TestException e) { -// assertEquals(1, testClass.times); -// } -// -// verifyAll(); -// } -// -// /** -// * Tests an exception handler when the class that contains the method is a proxy. This is the case when using -// * injection. -// * -// * @throws Exception -// */ -// @Test -// public void manageHandlerMethodInsideProxyClass() throws Exception { -// // creates a proxy class -// ClassWithExceptionHandlerMethodThatRethrowException testClass = PowerMock -// .createNicePartialMockForAllMethodsExcept(ClassWithExceptionHandlerMethodThatRethrowException.class, -// "methodThatRethrowException"); -// expect(this.context.getTarget()).andReturn(testClass).anyTimes(); -// expect(this.context.proceed()).andThrow(new TestException("")); -// expect(CoreBootstrap.isAnnotatedType(testClass.getClass())).andReturn(false); -// -// this.logger = PowerMock.createMock(Logger.class); -// this.logger.info(EasyMock.anyObject(String.class)); -// this.logger.debug(EasyMock.anyObject(String.class)); -// replayAll(testClass, this.context, CoreBootstrap.class, logger); -// -// this.interceptor = new ExceptionHandlerInterceptor(this.logger, this.bundle); -// -// try { -// this.interceptor.manage(this.context); -// fail(); -// } catch (TestException e) { -// assertEquals(1, testClass.times); -// } -// } -// -//} +/* + * Demoiselle Framework + * Copyright (C) 2010 SERPRO + * ---------------------------------------------------------------------------- + * This file is part of Demoiselle Framework. + * + * Demoiselle Framework is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License version 3 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License version 3 + * along with this program; if not, see + * or write to the Free Software Foundation, Inc., 51 Franklin Street, + * Fifth Floor, Boston, MA 02110-1301, USA. + * ---------------------------------------------------------------------------- + * Este arquivo é parte do Framework Demoiselle. + * + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação + * do Software Livre (FSF). + * + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português + * para maiores detalhes. + * + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título + * "LICENCA.txt", junto com esse programa. Se não, acesse + * ou escreva para a Fundação do Software Livre (FSF) Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. + */ +package br.gov.frameworkdemoiselle.internal.interceptor; + +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.verify; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.powermock.api.easymock.PowerMock.mockStatic; +import static org.powermock.api.easymock.PowerMock.replay; +import static org.powermock.api.easymock.PowerMock.replayAll; +import static org.powermock.api.easymock.PowerMock.verifyAll; + +import java.util.Locale; + +import javax.interceptor.InvocationContext; + +import org.easymock.EasyMock; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.api.easymock.PowerMock; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.slf4j.Logger; + +import br.gov.frameworkdemoiselle.DemoiselleException; +import br.gov.frameworkdemoiselle.exception.ExceptionHandler; +import br.gov.frameworkdemoiselle.internal.bootstrap.CoreBootstrap; +import br.gov.frameworkdemoiselle.util.Beans; +import br.gov.frameworkdemoiselle.util.ResourceBundle; + +@RunWith(PowerMockRunner.class) +@PrepareForTest(Beans.class) +public class ExceptionHandlerInterceptorTest { + + private ExceptionHandlerInterceptor interceptor; + + private InvocationContext context; + + private Logger logger; + + private CoreBootstrap coreBootstrap; + + class TestException extends DemoiselleException { + + private static final long serialVersionUID = 1L; + + public TestException(String message) { + super(message); + } + } + + class ClassWithMethodsAnnotatedWithExceptionHandler { + + int times = 0; + + @ExceptionHandler + public void methodWithExceptionHandlerAnotation(DemoiselleException cause) { + times++; + } + + @ExceptionHandler + public void methodWithExceptionHandlerAnotationAndGenericException(Exception cause) { + times++; + } + + } + + class ClassWithoutMethodsAnnotatedWithExceptionHandler { + + public void methodWithoutExceptionHandlerAnotation(DemoiselleException cause) { + } + } + + class ClassWithMethodsAnnotatedWithExceptionHandlerAndThrowException { + + int times = 0; + + @ExceptionHandler + public void methodWithExceptionHandlerAnotation(DemoiselleException cause) { + times++; + throw new RuntimeException(); + } + } + + class ClassWithMethodWithoutParameterAnnotatedWithExceptionHandler { + + @ExceptionHandler + public void methodWithExceptionHandlerAnotation() { + } + + } + + class ClassWithExceptionHandlerMethodThatRethrowException { + + int times = 0; + + @ExceptionHandler + public void methodThatRethrowException(TestException cause) { + times++; + throw cause; + } + + } + + @Before + public void setUp() throws Exception { + + this.interceptor = new ExceptionHandlerInterceptor(); + this.context = PowerMock.createMock(InvocationContext.class); + this.coreBootstrap = PowerMock.createMock(CoreBootstrap.class); + + mockStatic(Beans.class); + expect(Beans.getReference(Locale.class)).andReturn(Locale.getDefault()).anyTimes(); + expect(Beans.getReference(CoreBootstrap.class)).andReturn(this.coreBootstrap).anyTimes(); + + } + + @Test + public void manageSuccessfully() throws Throwable { + expect(this.context.proceed()).andReturn(null); + replayAll(); + assertEquals(null, this.interceptor.manage(this.context)); + verify(); + } + + @Test + public void manageWithClassThatDoesNotContainHandleMethod() throws Exception { + ClassWithoutMethodsAnnotatedWithExceptionHandler classWithoutException = new ClassWithoutMethodsAnnotatedWithExceptionHandler(); + + expect(this.context.getTarget()).andReturn(classWithoutException); + expect(this.context.proceed()).andThrow(new DemoiselleException("")); + expect(this.coreBootstrap.isAnnotatedType(ClassWithoutMethodsAnnotatedWithExceptionHandler.class)).andReturn( + true); + + replayAll(this.context, this.coreBootstrap, Beans.class); + + try { + this.interceptor.manage(this.context); + fail(); + } catch (DemoiselleException e) { + assertTrue(true); + } + + verifyAll(); + } + + @Test + public void manageWithClassThatContainsHandleMethod() throws Exception { + ClassWithMethodsAnnotatedWithExceptionHandler classWithException = new ClassWithMethodsAnnotatedWithExceptionHandler(); + expect(this.context.getTarget()).andReturn(classWithException).anyTimes(); + expect(this.context.proceed()).andThrow(new DemoiselleException("")); + expect(this.coreBootstrap.isAnnotatedType(ClassWithMethodsAnnotatedWithExceptionHandler.class)).andReturn(true); + + replayAll(this.context, this.coreBootstrap, Beans.class); + + assertNull(this.interceptor.manage(this.context)); + assertEquals(1, classWithException.times); + verifyAll(); + } + + @Test + public void manageWithClassThatContainsParentExceptionHandleMethod() throws Exception { + ClassWithMethodsAnnotatedWithExceptionHandler classWithException = new ClassWithMethodsAnnotatedWithExceptionHandler(); + expect(this.context.getTarget()).andReturn(classWithException).anyTimes(); + expect(this.context.proceed()).andThrow(new DemoiselleException("")); + expect(this.coreBootstrap.isAnnotatedType(ClassWithMethodsAnnotatedWithExceptionHandler.class)).andReturn(true); + replayAll(this.context, this.coreBootstrap, Beans.class); + + assertNull(this.interceptor.manage(this.context)); + assertEquals(1, classWithException.times); + verifyAll(); + } + + @Test + public void manageWithClassThatContainsHandleMethodWithDiferentException() throws Exception { + ClassWithMethodsAnnotatedWithExceptionHandler classWithException = new ClassWithMethodsAnnotatedWithExceptionHandler(); + expect(this.context.getTarget()).andReturn(classWithException).anyTimes(); + expect(this.context.proceed()).andThrow(new TestException("")); + replay(this.context); + expect(this.coreBootstrap.isAnnotatedType(ClassWithMethodsAnnotatedWithExceptionHandler.class)).andReturn(true); + replayAll(this.context, this.coreBootstrap, Beans.class); + + try { + this.interceptor.manage(this.context); + fail(); + } catch (TestException e) { + assertEquals(0, classWithException.times); + } + + verify(); + } + + @Test + public void manageWithClassThatContainsHandleMethodThatThrowsAnotherException() throws Exception { + ClassWithMethodsAnnotatedWithExceptionHandlerAndThrowException classWithException = new ClassWithMethodsAnnotatedWithExceptionHandlerAndThrowException(); + expect(this.context.getTarget()).andReturn(classWithException).anyTimes(); + expect(this.context.proceed()).andThrow(new DemoiselleException("")); + expect(this.coreBootstrap.isAnnotatedType(ClassWithMethodsAnnotatedWithExceptionHandlerAndThrowException.class)) + .andReturn(true); + replayAll(this.context, this.coreBootstrap, Beans.class); + + try { + this.interceptor.manage(this.context); + fail(); + } catch (RuntimeException e) { + assertEquals(1, classWithException.times); + } + + verifyAll(); + } + + @Test + public void manageWithClassThatContainsHandleMethodsAndIsInvokedTwice() throws Exception { + ClassWithMethodsAnnotatedWithExceptionHandler classWithException = new ClassWithMethodsAnnotatedWithExceptionHandler(); + expect(this.context.getTarget()).andReturn(classWithException).anyTimes(); + expect(this.context.proceed()).andThrow(new DemoiselleException("")); + expect(this.coreBootstrap.isAnnotatedType(ClassWithMethodsAnnotatedWithExceptionHandler.class)).andReturn(true) + .anyTimes(); + replayAll(this.context, this.coreBootstrap, Beans.class); + + assertNull(this.interceptor.manage(this.context)); + assertEquals(1, classWithException.times); + + this.context = PowerMock.createMock(InvocationContext.class); + expect(this.context.getTarget()).andReturn(classWithException).anyTimes(); + expect(this.context.proceed()).andThrow(new Exception("")); + replayAll(this.context); + + assertNull(this.interceptor.manage(this.context)); + assertEquals(2, classWithException.times); + verifyAll(); + + } + + @Test + public void manageWithClassThatContainsHandleMethodWithoutParameter() throws Exception { + ClassWithMethodWithoutParameterAnnotatedWithExceptionHandler classWithException = new ClassWithMethodWithoutParameterAnnotatedWithExceptionHandler(); + expect(this.context.getTarget()).andReturn(classWithException).anyTimes(); + expect(this.context.proceed()).andThrow(new DemoiselleException("")); + expect(this.coreBootstrap.isAnnotatedType(ClassWithMethodWithoutParameterAnnotatedWithExceptionHandler.class)) + .andReturn(true); + replayAll(this.context, this.coreBootstrap, Beans.class); + + try { + this.interceptor.manage(this.context); + fail(); + } catch (DemoiselleException e) { + assertTrue(true); + } + + verifyAll(); + } + + @Test + public void manageHandlerMethodThatRethrowExpectedException() throws Exception { + ClassWithExceptionHandlerMethodThatRethrowException testClass = new ClassWithExceptionHandlerMethodThatRethrowException(); + expect(this.context.getTarget()).andReturn(testClass).anyTimes(); + expect(this.context.proceed()).andThrow(new TestException("")); + expect(this.coreBootstrap.isAnnotatedType(ClassWithExceptionHandlerMethodThatRethrowException.class)) + .andReturn(true); + replayAll(this.context, this.coreBootstrap, Beans.class); + + try { + this.interceptor.manage(this.context); + fail(); + } catch (TestException e) { + assertEquals(1, testClass.times); + } + + verifyAll(); + } + + /** + * Tests an exception handler when the class that contains the method is a proxy. This is the case when using + * injection. + * + * @throws Exception + */ + @Test + public void manageHandlerMethodInsideProxyClass() throws Exception { + // creates a proxy class + ClassWithExceptionHandlerMethodThatRethrowException testClass = PowerMock + .createNicePartialMockForAllMethodsExcept(ClassWithExceptionHandlerMethodThatRethrowException.class, + "methodThatRethrowException"); + expect(this.context.getTarget()).andReturn(testClass).anyTimes(); + expect(this.context.proceed()).andThrow(new TestException("")); + expect(this.coreBootstrap.isAnnotatedType(testClass.getClass())).andReturn(false); + + this.logger = PowerMock.createMock(Logger.class); + this.logger.info(EasyMock.anyObject(String.class)); + this.logger.debug(EasyMock.anyObject(String.class)); + replayAll(testClass, this.context, this.coreBootstrap, logger, Beans.class); + + this.interceptor = new ExceptionHandlerInterceptor(); + + try { + this.interceptor.manage(this.context); + fail(); + } catch (TestException e) { + assertEquals(1, testClass.times); + } + } + +} diff --git a/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/interceptor/RequiredPermissionInterceptorTest.java b/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/interceptor/RequiredPermissionInterceptorTest.java index 8f79a40..e4a30db 100644 --- a/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/interceptor/RequiredPermissionInterceptorTest.java +++ b/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/interceptor/RequiredPermissionInterceptorTest.java @@ -1,410 +1,407 @@ -//package br.gov.frameworkdemoiselle.internal.interceptor; -// -//import static org.easymock.EasyMock.createMock; -//import static org.easymock.EasyMock.expect; -//import static org.easymock.EasyMock.expectLastCall; -//import static org.junit.Assert.fail; -//import static org.powermock.api.easymock.PowerMock.mockStatic; -//import static org.powermock.api.easymock.PowerMock.replay; -// -//import java.util.Locale; -// -//import javax.enterprise.inject.Instance; -//import javax.interceptor.InvocationContext; -// -//import org.junit.Before; -//import org.junit.Test; -//import org.junit.runner.RunWith; -//import org.powermock.core.classloader.annotations.PrepareForTest; -//import org.powermock.modules.junit4.PowerMockRunner; -//import org.slf4j.Logger; -// -//import br.gov.frameworkdemoiselle.annotation.Name; -//import br.gov.frameworkdemoiselle.internal.implementation.CoreBundle; -//import br.gov.frameworkdemoiselle.security.NotLoggedInException; -//import br.gov.frameworkdemoiselle.security.RequiredPermission; -//import br.gov.frameworkdemoiselle.security.SecurityContext; -//import br.gov.frameworkdemoiselle.security.SecurityException; -//import br.gov.frameworkdemoiselle.security.User; -//import br.gov.frameworkdemoiselle.util.ResourceBundle; -// -//@RunWith(PowerMockRunner.class) -//@PrepareForTest(CoreBundle.class) -//public class RequiredPermissionInterceptorTest { -// -// private RequiredPermissionInterceptor interceptor; -// -// private InvocationContext ic; -// -// private SecurityContext securityContext; -// -// class UnnamedClass { -// -// @RequiredPermission -// public void requiredPermissionWithoutDeclaredResourceAndOperation() { -// } -// -// @RequiredPermission(operation = "insert") -// public void requiredPermissionWithDeclaredOperation() { -// } -// -// @RequiredPermission(resource = "contact") -// public void requiredPermissionWithDeclaredResource() { -// } -// -// @RequiredPermission(resource = "contact", operation = "insert") -// public void requiredPermissionWithDeclaredResourceAndOperation() { -// } -// } -// -// @Name("contact2") -// class NamedClass { -// -// @RequiredPermission -// public void requiredPermissionWithoutDeclaredResourceAndOperation() { -// } -// -// @RequiredPermission(operation = "insert") -// public void requiredPermissionWithDeclaredOperation() { -// } -// -// @RequiredPermission(resource = "contact") -// public void requiredPermissionWithDeclaredResource() { -// } -// -// @RequiredPermission(resource = "contact", operation = "insert") -// public void requiredPermissionWithDeclaredResourceAndOperation() { -// } -// } -// -// @Name("contact2") -// class NamedClassWithNamedMethods { -// -// @Name("delete") -// @RequiredPermission -// public void requiredPermissionWithoutDeclaredResourceAndOperation() { -// } -// -// @Name("delete") -// @RequiredPermission(operation = "insert") -// public void requiredPermissionWithDeclaredOperation() { -// } -// -// @Name("delete") -// @RequiredPermission(resource = "contact") -// public void requiredPermissionWithDeclaredResource() { -// } -// -// @Name("delete") -// @RequiredPermission(resource = "contact", operation = "insert") -// public void requiredPermissionWithDeclaredResourceAndOperation() { -// } -// } -// -// @RequiredPermission -// class ClassAnnotedWithRequiredPermission { -// -// public void withoutRequiredPermissionAnnotation() { -// } -// -// @RequiredPermission(operation = "insert") -// public void requiredPermissionWithDeclaredOperation() { -// } -// } -// -// @Before -// public void setUp() throws Exception { -// @SuppressWarnings("unchecked") -// Instance securityContextInstance = createMock(Instance.class); -// Logger logger = createMock(Logger.class); -// -// ResourceBundle bundle = new ResourceBundle("demoiselle-core-bundle", Locale.getDefault()); -// User user = createMock(User.class); -// -// mockStatic(CoreBundle.class); -// expect(CoreBundle.get()).andReturn(bundle); -// -// this.securityContext = createMock(SecurityContext.class); -// this.ic = createMock(InvocationContext.class); -// -// expect(user.getId()).andReturn("UserName").anyTimes(); -// expect(this.securityContext.getUser()).andReturn(user).anyTimes(); -// expect(securityContextInstance.get()).andReturn(securityContext).anyTimes(); -// expect(this.ic.proceed()).andReturn(null); -// replay(securityContextInstance, user, CoreBundle.class); -// -// this.interceptor = new RequiredPermissionInterceptor(securityContextInstance, bundle, logger); -// } -// -// private void prepareMock(Object target, String methodName, String expectedResource, String expectedOperation, -// boolean hasPermission, boolean isLoggedUser) throws Exception { -// -// expect(this.securityContext.isLoggedIn()).andReturn(isLoggedUser).anyTimes(); -// -// this.securityContext.hasPermission(expectedResource, expectedOperation); -// -// if (isLoggedUser) { -// expectLastCall().andReturn(hasPermission); -// } else { -// expectLastCall().andThrow(new NotLoggedInException("")); -// } -// -// expect(this.ic.getTarget()).andReturn(target).anyTimes(); -// expect(this.ic.getMethod()).andReturn(target.getClass().getMethod(methodName)).anyTimes(); -// replay(this.ic, this.securityContext); -// } -// -// /* Testing UnnamedClass */ -// -// @Test -// public void testManageUnnamedClassAtRequiredPermissionWithoutDeclaredResourceAndOperationMethod() throws Exception { -// try { -// Object target = new UnnamedClass(); -// String methodName = "requiredPermissionWithoutDeclaredResourceAndOperation"; -// String expectedResource = target.getClass().getSimpleName(); -// String expectedOperation = methodName; -// prepareMock(target, methodName, expectedResource, expectedOperation, true, true); -// -// interceptor.manage(this.ic); -// } catch (SecurityException cause) { -// fail(); -// } -// } -// -// @Test -// public void testManageUnnamedClassAtRequiredPermissionWithDeclaredOperationMethod() throws Exception { -// try { -// Object target = new UnnamedClass(); -// String methodName = "requiredPermissionWithDeclaredOperation"; -// String expectedResource = target.getClass().getSimpleName(); -// String expectedOperation = "insert"; -// prepareMock(target, methodName, expectedResource, expectedOperation, true, true); -// -// interceptor.manage(this.ic); -// } catch (SecurityException cause) { -// fail(); -// } -// } -// -// @Test -// public void testManageUnnamedClassAtRequiredPermissionWithDeclaredResourceMethod() throws Exception { -// try { -// Object target = new UnnamedClass(); -// String methodName = "requiredPermissionWithDeclaredResource"; -// String expectedResource = "contact"; -// String expectedOperation = methodName; -// prepareMock(target, methodName, expectedResource, expectedOperation, true, true); -// -// interceptor.manage(this.ic); -// } catch (SecurityException cause) { -// fail(); -// } -// } -// -// @Test -// public void testManageUnnamedClassAtRequiredPermissionWithDeclaredResourceAndOperation() throws Exception { -// try { -// Object target = new UnnamedClass(); -// String methodName = "requiredPermissionWithDeclaredResourceAndOperation"; -// String expectedResource = "contact"; -// String expectedOperation = "insert"; -// prepareMock(target, methodName, expectedResource, expectedOperation, true, true); -// -// interceptor.manage(this.ic); -// } catch (SecurityException cause) { -// fail(); -// } -// } -// -// /* Testing NamedClass */ -// -// @Test -// public void testManageNamedClassAtRequiredPermissionWithoutDeclaredResourceAndOperationMethod() throws Exception { -// try { -// Object target = new NamedClass(); -// String methodName = "requiredPermissionWithoutDeclaredResourceAndOperation"; -// String expectedResource = "contact2"; -// String expectedOperation = methodName; -// prepareMock(target, methodName, expectedResource, expectedOperation, true, true); -// -// interceptor.manage(this.ic); -// } catch (SecurityException cause) { -// fail(); -// } -// } -// -// @Test -// public void testManageNamedClassAtRequiredPermissionWithDeclaredOperationMethod() throws Exception { -// try { -// Object target = new NamedClass(); -// String methodName = "requiredPermissionWithDeclaredOperation"; -// String expectedResource = "contact2"; -// String expectedOperation = "insert"; -// prepareMock(target, methodName, expectedResource, expectedOperation, true, true); -// -// interceptor.manage(this.ic); -// } catch (SecurityException cause) { -// fail(); -// } -// } -// -// @Test -// public void testManageNamedClassAtRequiredPermissionWithDeclaredResourceMethod() throws Exception { -// try { -// Object target = new NamedClass(); -// String methodName = "requiredPermissionWithDeclaredResource"; -// String expectedResource = "contact"; -// String expectedOperation = methodName; -// prepareMock(target, methodName, expectedResource, expectedOperation, true, true); -// -// interceptor.manage(this.ic); -// } catch (SecurityException cause) { -// fail(); -// } -// } -// -// @Test -// public void testManageNamedClassAtRequiredPermissionWithDeclaredResourceAndOperation() throws Exception { -// try { -// Object target = new NamedClass(); -// String methodName = "requiredPermissionWithDeclaredResourceAndOperation"; -// String expectedResource = "contact"; -// String expectedOperation = "insert"; -// prepareMock(target, methodName, expectedResource, expectedOperation, true, true); -// -// interceptor.manage(this.ic); -// } catch (SecurityException cause) { -// fail(); -// } -// } -// -// /* Testing NamedClassWithNamedMethods */ -// -// @Test -// public void testManageNamedClassWithNamedMethodsAtRequiredPermissionWithoutDeclaredResourceAndOperationMethod() -// throws Exception { -// try { -// Object target = new NamedClassWithNamedMethods(); -// String methodName = "requiredPermissionWithoutDeclaredResourceAndOperation"; -// String expectedResource = "contact2"; -// String expectedOperation = "delete"; -// prepareMock(target, methodName, expectedResource, expectedOperation, true, true); -// -// interceptor.manage(this.ic); -// } catch (SecurityException cause) { -// fail(); -// } -// } -// -// @Test -// public void testManageNamedClassWithNamedMethodsAtRequiredPermissionWithDeclaredOperationMethod() throws Exception { -// try { -// Object target = new NamedClassWithNamedMethods(); -// String methodName = "requiredPermissionWithDeclaredOperation"; -// String expectedResource = "contact2"; -// String expectedOperation = "insert"; -// prepareMock(target, methodName, expectedResource, expectedOperation, true, true); -// -// interceptor.manage(this.ic); -// } catch (SecurityException cause) { -// fail(); -// } -// } -// -// @Test -// public void testManageNamedClassWithNamedMethodsAtRequiredPermissionWithDeclaredResourceMethod() throws Exception { -// try { -// Object target = new NamedClassWithNamedMethods(); -// String methodName = "requiredPermissionWithDeclaredResource"; -// String expectedResource = "contact"; -// String expectedOperation = "delete"; -// prepareMock(target, methodName, expectedResource, expectedOperation, true, true); -// -// interceptor.manage(this.ic); -// } catch (SecurityException cause) { -// fail(); -// } -// } -// -// @Test -// public void testManageNamedClassWithNamedMethodsAtRequiredPermissionWithDeclaredResourceAndOperation() -// throws Exception { -// try { -// Object target = new NamedClassWithNamedMethods(); -// String methodName = "requiredPermissionWithDeclaredResourceAndOperation"; -// String expectedResource = "contact"; -// String expectedOperation = "insert"; -// prepareMock(target, methodName, expectedResource, expectedOperation, true, true); -// -// interceptor.manage(this.ic); -// } catch (SecurityException cause) { -// fail(); -// } -// } -// -// /* Testing ClassAnnotedWithRequiredPermission */ -// -// @Test -// public void testManageClassAnnotedWithRequiredPermissionAtWithoutRequiredPermissionAnnotation() throws Exception { -// try { -// Object target = new ClassAnnotedWithRequiredPermission(); -// String methodName = "withoutRequiredPermissionAnnotation"; -// String expectedResource = target.getClass().getSimpleName(); -// String expectedOperation = methodName; -// prepareMock(target, methodName, expectedResource, expectedOperation, true, true); -// -// interceptor.manage(this.ic); -// } catch (SecurityException cause) { -// fail(); -// } -// } -// -// @Test -// public void testManageClassAnnotedWithRequiredPermissionAtRequiredPermissionWithDeclaredOperation() -// throws Exception { -// try { -// Object target = new ClassAnnotedWithRequiredPermission(); -// String methodName = "requiredPermissionWithDeclaredOperation"; -// String expectedResource = target.getClass().getSimpleName(); -// String expectedOperation = "insert"; -// prepareMock(target, methodName, expectedResource, expectedOperation, true, true); -// -// interceptor.manage(this.ic); -// } catch (SecurityException cause) { -// fail(); -// } -// } -// -// /* Other tests */ -// -// @Test -// public void testManagePermissionNotAllowed() throws Exception { -// try { -// Object target = new UnnamedClass(); -// String methodName = "requiredPermissionWithDeclaredResourceAndOperation"; -// String expectedResource = "contact"; -// String expectedOperation = "insert"; -// prepareMock(target, methodName, expectedResource, expectedOperation, false, true); -// -// interceptor.manage(this.ic); -// fail(); -// } catch (SecurityException cause) { -// } -// } -// -// @Test -// public void testUserNotLoggedIn() throws Exception { -// try { -// Object target = new UnnamedClass(); -// String methodName = "requiredPermissionWithDeclaredResourceAndOperation"; -// String expectedResource = "contact"; -// String expectedOperation = "insert"; -// prepareMock(target, methodName, expectedResource, expectedOperation, true, false); -// -// interceptor.manage(this.ic); -// fail(); -// } catch (SecurityException cause) { -// } -// } -// -//} +package br.gov.frameworkdemoiselle.internal.interceptor; + +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.expectLastCall; +import static org.junit.Assert.fail; +import static org.powermock.api.easymock.PowerMock.mockStatic; +import static org.powermock.api.easymock.PowerMock.replay; + +import java.util.Locale; + +import javax.enterprise.inject.Instance; +import javax.interceptor.InvocationContext; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import br.gov.frameworkdemoiselle.annotation.Name; +import br.gov.frameworkdemoiselle.security.NotLoggedInException; +import br.gov.frameworkdemoiselle.security.RequiredPermission; +import br.gov.frameworkdemoiselle.security.SecurityContext; +import br.gov.frameworkdemoiselle.security.SecurityException; +import br.gov.frameworkdemoiselle.security.User; +import br.gov.frameworkdemoiselle.util.Beans; + +@RunWith(PowerMockRunner.class) +@PrepareForTest(Beans.class) +public class RequiredPermissionInterceptorTest { + + private RequiredPermissionInterceptor interceptor; + + private InvocationContext ic; + + private SecurityContext securityContext; + + class UnnamedClass { + + @RequiredPermission + public void requiredPermissionWithoutDeclaredResourceAndOperation() { + } + + @RequiredPermission(operation = "insert") + public void requiredPermissionWithDeclaredOperation() { + } + + @RequiredPermission(resource = "contact") + public void requiredPermissionWithDeclaredResource() { + } + + @RequiredPermission(resource = "contact", operation = "insert") + public void requiredPermissionWithDeclaredResourceAndOperation() { + } + } + + @Name("contact2") + class NamedClass { + + @RequiredPermission + public void requiredPermissionWithoutDeclaredResourceAndOperation() { + } + + @RequiredPermission(operation = "insert") + public void requiredPermissionWithDeclaredOperation() { + } + + @RequiredPermission(resource = "contact") + public void requiredPermissionWithDeclaredResource() { + } + + @RequiredPermission(resource = "contact", operation = "insert") + public void requiredPermissionWithDeclaredResourceAndOperation() { + } + } + + @Name("contact2") + class NamedClassWithNamedMethods { + + @Name("delete") + @RequiredPermission + public void requiredPermissionWithoutDeclaredResourceAndOperation() { + } + + @Name("delete") + @RequiredPermission(operation = "insert") + public void requiredPermissionWithDeclaredOperation() { + } + + @Name("delete") + @RequiredPermission(resource = "contact") + public void requiredPermissionWithDeclaredResource() { + } + + @Name("delete") + @RequiredPermission(resource = "contact", operation = "insert") + public void requiredPermissionWithDeclaredResourceAndOperation() { + } + } + + @RequiredPermission + class ClassAnnotedWithRequiredPermission { + + public void withoutRequiredPermissionAnnotation() { + } + + @RequiredPermission(operation = "insert") + public void requiredPermissionWithDeclaredOperation() { + } + } + + @Before + public void setUp() throws Exception { + @SuppressWarnings("unchecked") + Instance securityContextInstance = createMock(Instance.class); + + User user = createMock(User.class); + + this.securityContext = createMock(SecurityContext.class); + this.ic = createMock(InvocationContext.class); + + mockStatic(Beans.class); + expect(Beans.getReference(Locale.class)).andReturn(Locale.getDefault()); + expect(Beans.getReference(SecurityContext.class)).andReturn(this.securityContext); + + expect(user.getId()).andReturn("UserName").anyTimes(); + expect(this.securityContext.getUser()).andReturn(user).anyTimes(); + expect(securityContextInstance.get()).andReturn(securityContext).anyTimes(); + expect(this.ic.proceed()).andReturn(null); + replay(securityContextInstance, user, Beans.class); + + this.interceptor = new RequiredPermissionInterceptor(); + } + + private void prepareMock(Object target, String methodName, String expectedResource, String expectedOperation, + boolean hasPermission, boolean isLoggedUser) throws Exception { + + expect(this.securityContext.isLoggedIn()).andReturn(isLoggedUser).anyTimes(); + + this.securityContext.hasPermission(expectedResource, expectedOperation); + + if (isLoggedUser) { + expectLastCall().andReturn(hasPermission); + } else { + expectLastCall().andThrow(new NotLoggedInException("")); + } + + expect(this.ic.getTarget()).andReturn(target).anyTimes(); + expect(this.ic.getMethod()).andReturn(target.getClass().getMethod(methodName)).anyTimes(); + replay(this.ic, this.securityContext); + } + + /* Testing UnnamedClass */ + + @Test + public void testManageUnnamedClassAtRequiredPermissionWithoutDeclaredResourceAndOperationMethod() throws Exception { + try { + Object target = new UnnamedClass(); + String methodName = "requiredPermissionWithoutDeclaredResourceAndOperation"; + String expectedResource = target.getClass().getSimpleName(); + String expectedOperation = methodName; + prepareMock(target, methodName, expectedResource, expectedOperation, true, true); + + interceptor.manage(this.ic); + } catch (SecurityException cause) { + fail(); + } + } + + @Test + public void testManageUnnamedClassAtRequiredPermissionWithDeclaredOperationMethod() throws Exception { + try { + Object target = new UnnamedClass(); + String methodName = "requiredPermissionWithDeclaredOperation"; + String expectedResource = target.getClass().getSimpleName(); + String expectedOperation = "insert"; + prepareMock(target, methodName, expectedResource, expectedOperation, true, true); + + interceptor.manage(this.ic); + } catch (SecurityException cause) { + fail(); + } + } + + @Test + public void testManageUnnamedClassAtRequiredPermissionWithDeclaredResourceMethod() throws Exception { + try { + Object target = new UnnamedClass(); + String methodName = "requiredPermissionWithDeclaredResource"; + String expectedResource = "contact"; + String expectedOperation = methodName; + prepareMock(target, methodName, expectedResource, expectedOperation, true, true); + + interceptor.manage(this.ic); + } catch (SecurityException cause) { + fail(); + } + } + + @Test + public void testManageUnnamedClassAtRequiredPermissionWithDeclaredResourceAndOperation() throws Exception { + try { + Object target = new UnnamedClass(); + String methodName = "requiredPermissionWithDeclaredResourceAndOperation"; + String expectedResource = "contact"; + String expectedOperation = "insert"; + prepareMock(target, methodName, expectedResource, expectedOperation, true, true); + + interceptor.manage(this.ic); + } catch (SecurityException cause) { + fail(); + } + } + + /* Testing NamedClass */ + + @Test + public void testManageNamedClassAtRequiredPermissionWithoutDeclaredResourceAndOperationMethod() throws Exception { + try { + Object target = new NamedClass(); + String methodName = "requiredPermissionWithoutDeclaredResourceAndOperation"; + String expectedResource = "contact2"; + String expectedOperation = methodName; + prepareMock(target, methodName, expectedResource, expectedOperation, true, true); + + interceptor.manage(this.ic); + } catch (SecurityException cause) { + fail(); + } + } + + @Test + public void testManageNamedClassAtRequiredPermissionWithDeclaredOperationMethod() throws Exception { + try { + Object target = new NamedClass(); + String methodName = "requiredPermissionWithDeclaredOperation"; + String expectedResource = "contact2"; + String expectedOperation = "insert"; + prepareMock(target, methodName, expectedResource, expectedOperation, true, true); + + interceptor.manage(this.ic); + } catch (SecurityException cause) { + fail(); + } + } + + @Test + public void testManageNamedClassAtRequiredPermissionWithDeclaredResourceMethod() throws Exception { + try { + Object target = new NamedClass(); + String methodName = "requiredPermissionWithDeclaredResource"; + String expectedResource = "contact"; + String expectedOperation = methodName; + prepareMock(target, methodName, expectedResource, expectedOperation, true, true); + + interceptor.manage(this.ic); + } catch (SecurityException cause) { + fail(); + } + } + + @Test + public void testManageNamedClassAtRequiredPermissionWithDeclaredResourceAndOperation() throws Exception { + try { + Object target = new NamedClass(); + String methodName = "requiredPermissionWithDeclaredResourceAndOperation"; + String expectedResource = "contact"; + String expectedOperation = "insert"; + prepareMock(target, methodName, expectedResource, expectedOperation, true, true); + + interceptor.manage(this.ic); + } catch (SecurityException cause) { + fail(); + } + } + + /* Testing NamedClassWithNamedMethods */ + + @Test + public void testManageNamedClassWithNamedMethodsAtRequiredPermissionWithoutDeclaredResourceAndOperationMethod() + throws Exception { + try { + Object target = new NamedClassWithNamedMethods(); + String methodName = "requiredPermissionWithoutDeclaredResourceAndOperation"; + String expectedResource = "contact2"; + String expectedOperation = "delete"; + prepareMock(target, methodName, expectedResource, expectedOperation, true, true); + + interceptor.manage(this.ic); + } catch (SecurityException cause) { + fail(); + } + } + + @Test + public void testManageNamedClassWithNamedMethodsAtRequiredPermissionWithDeclaredOperationMethod() throws Exception { + try { + Object target = new NamedClassWithNamedMethods(); + String methodName = "requiredPermissionWithDeclaredOperation"; + String expectedResource = "contact2"; + String expectedOperation = "insert"; + prepareMock(target, methodName, expectedResource, expectedOperation, true, true); + + interceptor.manage(this.ic); + } catch (SecurityException cause) { + fail(); + } + } + + @Test + public void testManageNamedClassWithNamedMethodsAtRequiredPermissionWithDeclaredResourceMethod() throws Exception { + try { + Object target = new NamedClassWithNamedMethods(); + String methodName = "requiredPermissionWithDeclaredResource"; + String expectedResource = "contact"; + String expectedOperation = "delete"; + prepareMock(target, methodName, expectedResource, expectedOperation, true, true); + + interceptor.manage(this.ic); + } catch (SecurityException cause) { + fail(); + } + } + + @Test + public void testManageNamedClassWithNamedMethodsAtRequiredPermissionWithDeclaredResourceAndOperation() + throws Exception { + try { + Object target = new NamedClassWithNamedMethods(); + String methodName = "requiredPermissionWithDeclaredResourceAndOperation"; + String expectedResource = "contact"; + String expectedOperation = "insert"; + prepareMock(target, methodName, expectedResource, expectedOperation, true, true); + + interceptor.manage(this.ic); + } catch (SecurityException cause) { + fail(); + } + } + + /* Testing ClassAnnotedWithRequiredPermission */ + + @Test + public void testManageClassAnnotedWithRequiredPermissionAtWithoutRequiredPermissionAnnotation() throws Exception { + try { + Object target = new ClassAnnotedWithRequiredPermission(); + String methodName = "withoutRequiredPermissionAnnotation"; + String expectedResource = target.getClass().getSimpleName(); + String expectedOperation = methodName; + prepareMock(target, methodName, expectedResource, expectedOperation, true, true); + + interceptor.manage(this.ic); + } catch (SecurityException cause) { + fail(); + } + } + + @Test + public void testManageClassAnnotedWithRequiredPermissionAtRequiredPermissionWithDeclaredOperation() + throws Exception { + try { + Object target = new ClassAnnotedWithRequiredPermission(); + String methodName = "requiredPermissionWithDeclaredOperation"; + String expectedResource = target.getClass().getSimpleName(); + String expectedOperation = "insert"; + prepareMock(target, methodName, expectedResource, expectedOperation, true, true); + + interceptor.manage(this.ic); + } catch (SecurityException cause) { + fail(); + } + } + + /* Other tests */ + + @Test + public void testManagePermissionNotAllowed() throws Exception { + try { + Object target = new UnnamedClass(); + String methodName = "requiredPermissionWithDeclaredResourceAndOperation"; + String expectedResource = "contact"; + String expectedOperation = "insert"; + prepareMock(target, methodName, expectedResource, expectedOperation, false, true); + + interceptor.manage(this.ic); + fail(); + } catch (SecurityException cause) { + } + } + + @Test + public void testUserNotLoggedIn() throws Exception { + try { + Object target = new UnnamedClass(); + String methodName = "requiredPermissionWithDeclaredResourceAndOperation"; + String expectedResource = "contact"; + String expectedOperation = "insert"; + prepareMock(target, methodName, expectedResource, expectedOperation, true, false); + + interceptor.manage(this.ic); + fail(); + } catch (SecurityException cause) { + } + } + +} diff --git a/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/interceptor/RequiredRoleInterceptorTest.java b/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/interceptor/RequiredRoleInterceptorTest.java index c633cf8..06b3cff 100644 --- a/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/interceptor/RequiredRoleInterceptorTest.java +++ b/impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/interceptor/RequiredRoleInterceptorTest.java @@ -1,310 +1,307 @@ -//package br.gov.frameworkdemoiselle.internal.interceptor; -// -//import static org.easymock.EasyMock.expect; -//import static org.junit.Assert.fail; -//import static org.powermock.api.easymock.PowerMock.mockStatic; -//import static org.powermock.api.easymock.PowerMock.replay; -// -//import java.util.Locale; -// -//import javax.enterprise.inject.Instance; -//import javax.interceptor.InvocationContext; -// -//import org.easymock.EasyMock; -//import org.junit.Before; -//import org.junit.Test; -//import org.junit.runner.RunWith; -//import org.powermock.core.classloader.annotations.PrepareForTest; -//import org.powermock.modules.junit4.PowerMockRunner; -//import org.slf4j.Logger; -// -//import br.gov.frameworkdemoiselle.internal.implementation.CoreBundle; -//import br.gov.frameworkdemoiselle.security.AuthorizationException; -//import br.gov.frameworkdemoiselle.security.NotLoggedInException; -//import br.gov.frameworkdemoiselle.security.RequiredRole; -//import br.gov.frameworkdemoiselle.security.SecurityContext; -//import br.gov.frameworkdemoiselle.security.User; -//import br.gov.frameworkdemoiselle.util.ResourceBundle; -// -//@RunWith(PowerMockRunner.class) -//@PrepareForTest(CoreBundle.class) -//public class RequiredRoleInterceptorTest { -// -// private RequiredRoleInterceptor interceptor; -// -// private InvocationContext ic; -// -// private SecurityContext securityContext; -// -// class ClassNotAnnoted { -// -// @RequiredRole("simpleRoleName") -// public void requiredRoleWithSingleRole() { -// } -// -// @RequiredRole({ "firstRole", "secondRole", "thirdRole", "fourthRole", "fifthRole" }) -// public void requiredRoleWithArrayOfRoles() { -// } -// -// @RequiredRole({ "firstRole, secondRole" }) -// public void requiredRoleWithArrayOfSingleRoleComma() { -// } -// -// @RequiredRole("firstRole, secondRole") -// public void requiredRoleWithSingleRoleComma() { -// } -// -// @RequiredRole("") -// public void requiredRoleWithEmptyValue() { -// } -// -// @RequiredRole({}) -// public void requiredRoleWithEmptyArray() { -// } -// -// @RequiredRole({ "" }) -// public void requiredRoleWithArrayOfEmptyString() { -// } -// -// public void methodNotAnnoted() { -// } -// } -// -// @RequiredRole("classRole") -// class ClassAnnotedWithRequiredRole { -// -// public void withoutRole() { -// } -// -// @RequiredRole("simpleRoleName") -// public void requiredRoleWithSingleRole() { -// } -// } -// -// @Before -// public void setUp() throws Exception { -// -// @SuppressWarnings("unchecked") -// Instance securityContextInstance = EasyMock.createMock(Instance.class); -// ResourceBundle bundle = new ResourceBundle("demoiselle-core-bundle", Locale.getDefault()); -// Logger logger = EasyMock.createMock(Logger.class); -// User user = EasyMock.createMock(User.class); -// -// this.securityContext = EasyMock.createMock(SecurityContext.class); -// this.ic = EasyMock.createMock(InvocationContext.class); -// -// mockStatic(CoreBundle.class); -// expect(CoreBundle.get()).andReturn(bundle); -// -// expect(user.getId()).andReturn("UserName").anyTimes(); -// expect(this.securityContext.getUser()).andReturn(user).anyTimes(); -// expect(securityContextInstance.get()).andReturn(securityContext).anyTimes(); -// expect(this.ic.proceed()).andReturn(null); -// replay(securityContextInstance, user, CoreBundle.class); -// -// this.interceptor = new RequiredRoleInterceptor(securityContextInstance, bundle, logger); -// } -// -// private void prepareMock(Object target, String methodName, String[] expectedRoles, boolean hasHole, -// boolean isLoggedUser) throws Exception { -// -// expect(this.securityContext.isLoggedIn()).andReturn(isLoggedUser).anyTimes(); -// -// for (String role : expectedRoles) { -// this.securityContext.hasRole(role); -// if (isLoggedUser) { -// EasyMock.expectLastCall().andReturn(hasHole); -// } else { -// EasyMock.expectLastCall().andThrow(new NotLoggedInException("")); -// } -// } -// -// expect(this.ic.getTarget()).andReturn(target).anyTimes(); -// expect(this.ic.getMethod()).andReturn(target.getClass().getMethod(methodName)).anyTimes(); -// replay(this.ic, this.securityContext); -// } -// -// /* -// * Testing ClassNotAnnoted -// */ -// @Test -// public void testManageClassNotAnnotedAtRequiredRoleWithSingleRole() throws Exception { -// Object target = new ClassNotAnnoted(); -// String methodName = "requiredRoleWithSingleRole"; -// String[] expectedRoles = { "simpleRoleName" }; -// prepareMock(target, methodName, expectedRoles, true, true); -// -// interceptor.manage(this.ic); -// } -// -// @Test -// public void testManageClassNotAnnotedAtRequiredRoleWithArrayOfRoles() throws Exception { -// Object target = new ClassNotAnnoted(); -// String methodName = "requiredRoleWithArrayOfRoles"; -// String[] expectedRoles = { "firstRole", "secondRole", "thirdRole", "fourthRole", "fifthRole" }; -// prepareMock(target, methodName, expectedRoles, true, true); -// -// interceptor.manage(this.ic); -// } -// -// @Test -// public void testManageClassNotAnnotedAtRequiredRoleWithArrayOfSingleRoleComma() throws Exception { -// Object target = new ClassNotAnnoted(); -// String methodName = "requiredRoleWithArrayOfSingleRoleComma"; -// String[] expectedRoles = { "firstRole, secondRole" }; -// prepareMock(target, methodName, expectedRoles, true, true); -// -// interceptor.manage(this.ic); -// } -// -// @Test -// public void testManageClassNotAnnotedAtRequiredRoleWithSingleRoleComma() throws Exception { -// Object target = new ClassNotAnnoted(); -// String methodName = "requiredRoleWithSingleRoleComma"; -// String[] expectedRoles = { "firstRole, secondRole" }; -// prepareMock(target, methodName, expectedRoles, true, true); -// -// interceptor.manage(this.ic); -// } -// -// @Test -// public void testManageClassNotAnnotedAtRequiredRoleWithEmptyValue() throws Exception { -// try { -// Object target = new ClassNotAnnoted(); -// String methodName = "requiredRoleWithEmptyValue"; -// String[] expectedRoles = { "" }; -// prepareMock(target, methodName, expectedRoles, false, true); -// -// interceptor.manage(this.ic); -// fail(); -// } catch (AuthorizationException cause) { -// } -// } -// -// @Test -// public void testManageClassNotAnnotedAtRequiredRoleWithEmptyArray() throws Exception { -// try { -// Object target = new ClassNotAnnoted(); -// String methodName = "requiredRoleWithEmptyArray"; -// String[] expectedRoles = { "" }; -// prepareMock(target, methodName, expectedRoles, false, true); -// -// interceptor.manage(this.ic); -// fail(); -// } catch (AuthorizationException cause) { -// } -// } -// -// @Test -// public void testManageClassNotAnnotedAtRequiredRoleWithArrayOfEmptyString() throws Exception { -// try { -// Object target = new ClassNotAnnoted(); -// String methodName = "requiredRoleWithArrayOfEmptyString"; -// String[] expectedRoles = { "" }; -// prepareMock(target, methodName, expectedRoles, false, true); -// -// interceptor.manage(this.ic); -// fail(); -// } catch (AuthorizationException cause) { -// } -// } -// -// @Test -// public void testManageClassNotAnnotedAtMethodNotAnnoted() throws Exception { -// try { -// Object target = new ClassNotAnnoted(); -// String methodName = "methodNotAnnoted"; -// String[] expectedRoles = { "" }; -// prepareMock(target, methodName, expectedRoles, false, true); -// -// interceptor.manage(this.ic); -// fail(); -// } catch (AuthorizationException cause) { -// } -// } -// -// /* -// * Testing ClassAnnoted -// */ -// @Test -// public void testManageClassAnnotedWithRequiredRoleAtWithoutRole() throws Exception { -// Object target = new ClassAnnotedWithRequiredRole(); -// String methodName = "withoutRole"; -// String[] expectedRoles = { "classRole" }; -// prepareMock(target, methodName, expectedRoles, true, true); -// -// interceptor.manage(this.ic); -// } -// -// @Test -// public void testManageClassAnnotedWithRequiredRoleAtRequiredRoleWithSingleRole() throws Exception { -// Object target = new ClassAnnotedWithRequiredRole(); -// String methodName = "requiredRoleWithSingleRole"; -// String[] expectedRoles = { "simpleRoleName" }; -// prepareMock(target, methodName, expectedRoles, true, true); -// -// interceptor.manage(this.ic); -// } -// -// /* -// * Other tests -// */ -// -// @Test -// public void testDoesNotHaveSingleRole() throws Exception { -// try { -// Object target = new ClassNotAnnoted(); -// String methodName = "requiredRoleWithSingleRole"; -// String[] expectedRoles = { "simpleRoleName" }; -// prepareMock(target, methodName, expectedRoles, false, true); -// -// interceptor.manage(this.ic); -// fail(); -// } catch (AuthorizationException cause) { -// } -// } -// -// @Test -// public void testUserNotLoggedIn() throws Exception { -// try { -// Object target = new ClassNotAnnoted(); -// String methodName = "requiredRoleWithSingleRole"; -// String[] expectedRoles = { "simpleRoleName" }; -// prepareMock(target, methodName, expectedRoles, true, false); -// -// interceptor.manage(this.ic); -// fail(); -// } catch (NotLoggedInException cause) { -// } -// } -// -// @Test -// public void testDoesNotHaveOneOrMoreRolesOfArray() throws Exception { -// Object target = new ClassNotAnnoted(); -// String methodName = "requiredRoleWithArrayOfRoles"; -// String[] expectedRoles = { "thirdRole", "fourthRole", "fifthRole" }; -// -// expect(this.securityContext.hasRole("firstRole")).andReturn(false); -// expect(this.securityContext.hasRole("secondRole")).andReturn(false); -// -// prepareMock(target, methodName, expectedRoles, true, true); -// -// interceptor.manage(this.ic); -// } -// -// @Test -// public void testHasMoreRolesThenArray() throws Exception { -// Object target = new ClassNotAnnoted(); -// String methodName = "requiredRoleWithArrayOfRoles"; -// String[] expectedRoles = { "thirdRole", "fourthRole", "fifthRole" }; -// -// expect(this.securityContext.hasRole("firstRole")).andReturn(false); -// expect(this.securityContext.hasRole("secondRole")).andReturn(false); -// expect(this.securityContext.hasRole("sixthRole")).andReturn(true); -// -// prepareMock(target, methodName, expectedRoles, true, true); -// -// interceptor.manage(this.ic); -// } -// -//} +package br.gov.frameworkdemoiselle.internal.interceptor; + +import static org.easymock.EasyMock.expect; +import static org.junit.Assert.fail; +import static org.powermock.api.easymock.PowerMock.mockStatic; +import static org.powermock.api.easymock.PowerMock.replay; + +import java.util.Locale; + +import javax.enterprise.inject.Instance; +import javax.interceptor.InvocationContext; + +import org.easymock.EasyMock; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import br.gov.frameworkdemoiselle.security.AuthorizationException; +import br.gov.frameworkdemoiselle.security.NotLoggedInException; +import br.gov.frameworkdemoiselle.security.RequiredRole; +import br.gov.frameworkdemoiselle.security.SecurityContext; +import br.gov.frameworkdemoiselle.security.User; +import br.gov.frameworkdemoiselle.util.Beans; + +@RunWith(PowerMockRunner.class) +@PrepareForTest(Beans.class) +public class RequiredRoleInterceptorTest { + + private RequiredRoleInterceptor interceptor; + + private InvocationContext ic; + + private SecurityContext securityContext; + + class ClassNotAnnoted { + + @RequiredRole("simpleRoleName") + public void requiredRoleWithSingleRole() { + } + + @RequiredRole({ "firstRole", "secondRole", "thirdRole", "fourthRole", "fifthRole" }) + public void requiredRoleWithArrayOfRoles() { + } + + @RequiredRole({ "firstRole, secondRole" }) + public void requiredRoleWithArrayOfSingleRoleComma() { + } + + @RequiredRole("firstRole, secondRole") + public void requiredRoleWithSingleRoleComma() { + } + + @RequiredRole("") + public void requiredRoleWithEmptyValue() { + } + + @RequiredRole({}) + public void requiredRoleWithEmptyArray() { + } + + @RequiredRole({ "" }) + public void requiredRoleWithArrayOfEmptyString() { + } + + public void methodNotAnnoted() { + } + } + + @RequiredRole("classRole") + class ClassAnnotedWithRequiredRole { + + public void withoutRole() { + } + + @RequiredRole("simpleRoleName") + public void requiredRoleWithSingleRole() { + } + } + + @Before + public void setUp() throws Exception { + + @SuppressWarnings("unchecked") + Instance securityContextInstance = EasyMock.createMock(Instance.class); + User user = EasyMock.createMock(User.class); + + this.securityContext = EasyMock.createMock(SecurityContext.class); + this.ic = EasyMock.createMock(InvocationContext.class); + + mockStatic(Beans.class); + expect(Beans.getReference(Locale.class)).andReturn(Locale.getDefault()); + expect(Beans.getReference(SecurityContext.class)).andReturn(this.securityContext); + + expect(user.getId()).andReturn("UserName").anyTimes(); + expect(this.securityContext.getUser()).andReturn(user).anyTimes(); + expect(securityContextInstance.get()).andReturn(securityContext).anyTimes(); + expect(this.ic.proceed()).andReturn(null); + replay(securityContextInstance, user, Beans.class); + + this.interceptor = new RequiredRoleInterceptor(); + } + + private void prepareMock(Object target, String methodName, String[] expectedRoles, boolean hasHole, + boolean isLoggedUser) throws Exception { + + expect(this.securityContext.isLoggedIn()).andReturn(isLoggedUser).anyTimes(); + + for (String role : expectedRoles) { + this.securityContext.hasRole(role); + if (isLoggedUser) { + EasyMock.expectLastCall().andReturn(hasHole); + } else { + EasyMock.expectLastCall().andThrow(new NotLoggedInException("")); + } + } + + expect(this.ic.getTarget()).andReturn(target).anyTimes(); + expect(this.ic.getMethod()).andReturn(target.getClass().getMethod(methodName)).anyTimes(); + replay(this.ic, this.securityContext); + } + + /* + * Testing ClassNotAnnoted + */ + @Test + public void testManageClassNotAnnotedAtRequiredRoleWithSingleRole() throws Exception { + Object target = new ClassNotAnnoted(); + String methodName = "requiredRoleWithSingleRole"; + String[] expectedRoles = { "simpleRoleName" }; + prepareMock(target, methodName, expectedRoles, true, true); + + interceptor.manage(this.ic); + } + + @Test + public void testManageClassNotAnnotedAtRequiredRoleWithArrayOfRoles() throws Exception { + Object target = new ClassNotAnnoted(); + String methodName = "requiredRoleWithArrayOfRoles"; + String[] expectedRoles = { "firstRole", "secondRole", "thirdRole", "fourthRole", "fifthRole" }; + prepareMock(target, methodName, expectedRoles, true, true); + + interceptor.manage(this.ic); + } + + @Test + public void testManageClassNotAnnotedAtRequiredRoleWithArrayOfSingleRoleComma() throws Exception { + Object target = new ClassNotAnnoted(); + String methodName = "requiredRoleWithArrayOfSingleRoleComma"; + String[] expectedRoles = { "firstRole, secondRole" }; + prepareMock(target, methodName, expectedRoles, true, true); + + interceptor.manage(this.ic); + } + + @Test + public void testManageClassNotAnnotedAtRequiredRoleWithSingleRoleComma() throws Exception { + Object target = new ClassNotAnnoted(); + String methodName = "requiredRoleWithSingleRoleComma"; + String[] expectedRoles = { "firstRole, secondRole" }; + prepareMock(target, methodName, expectedRoles, true, true); + + interceptor.manage(this.ic); + } + + @Test + public void testManageClassNotAnnotedAtRequiredRoleWithEmptyValue() throws Exception { + try { + Object target = new ClassNotAnnoted(); + String methodName = "requiredRoleWithEmptyValue"; + String[] expectedRoles = { "" }; + prepareMock(target, methodName, expectedRoles, false, true); + + interceptor.manage(this.ic); + fail(); + } catch (AuthorizationException cause) { + } + } + + @Test + public void testManageClassNotAnnotedAtRequiredRoleWithEmptyArray() throws Exception { + try { + Object target = new ClassNotAnnoted(); + String methodName = "requiredRoleWithEmptyArray"; + String[] expectedRoles = { "" }; + prepareMock(target, methodName, expectedRoles, false, true); + + interceptor.manage(this.ic); + fail(); + } catch (AuthorizationException cause) { + } + } + + @Test + public void testManageClassNotAnnotedAtRequiredRoleWithArrayOfEmptyString() throws Exception { + try { + Object target = new ClassNotAnnoted(); + String methodName = "requiredRoleWithArrayOfEmptyString"; + String[] expectedRoles = { "" }; + prepareMock(target, methodName, expectedRoles, false, true); + + interceptor.manage(this.ic); + fail(); + } catch (AuthorizationException cause) { + } + } + + @Test + public void testManageClassNotAnnotedAtMethodNotAnnoted() throws Exception { + try { + Object target = new ClassNotAnnoted(); + String methodName = "methodNotAnnoted"; + String[] expectedRoles = { "" }; + prepareMock(target, methodName, expectedRoles, false, true); + + interceptor.manage(this.ic); + fail(); + } catch (AuthorizationException cause) { + } + } + + /* + * Testing ClassAnnoted + */ + @Test + public void testManageClassAnnotedWithRequiredRoleAtWithoutRole() throws Exception { + Object target = new ClassAnnotedWithRequiredRole(); + String methodName = "withoutRole"; + String[] expectedRoles = { "classRole" }; + prepareMock(target, methodName, expectedRoles, true, true); + + interceptor.manage(this.ic); + } + + @Test + public void testManageClassAnnotedWithRequiredRoleAtRequiredRoleWithSingleRole() throws Exception { + Object target = new ClassAnnotedWithRequiredRole(); + String methodName = "requiredRoleWithSingleRole"; + String[] expectedRoles = { "simpleRoleName" }; + prepareMock(target, methodName, expectedRoles, true, true); + + interceptor.manage(this.ic); + } + + /* + * Other tests + */ + + @Test + public void testDoesNotHaveSingleRole() throws Exception { + try { + Object target = new ClassNotAnnoted(); + String methodName = "requiredRoleWithSingleRole"; + String[] expectedRoles = { "simpleRoleName" }; + prepareMock(target, methodName, expectedRoles, false, true); + + interceptor.manage(this.ic); + fail(); + } catch (AuthorizationException cause) { + } + } + + @Test + public void testUserNotLoggedIn() throws Exception { + try { + Object target = new ClassNotAnnoted(); + String methodName = "requiredRoleWithSingleRole"; + String[] expectedRoles = { "simpleRoleName" }; + prepareMock(target, methodName, expectedRoles, true, false); + + interceptor.manage(this.ic); + fail(); + } catch (NotLoggedInException cause) { + } + } + + @Test + public void testDoesNotHaveOneOrMoreRolesOfArray() throws Exception { + Object target = new ClassNotAnnoted(); + String methodName = "requiredRoleWithArrayOfRoles"; + String[] expectedRoles = { "thirdRole", "fourthRole", "fifthRole" }; + + expect(this.securityContext.hasRole("firstRole")).andReturn(false); + expect(this.securityContext.hasRole("secondRole")).andReturn(false); + + prepareMock(target, methodName, expectedRoles, true, true); + + interceptor.manage(this.ic); + } + + @Test + public void testHasMoreRolesThenArray() throws Exception { + Object target = new ClassNotAnnoted(); + String methodName = "requiredRoleWithArrayOfRoles"; + String[] expectedRoles = { "thirdRole", "fourthRole", "fifthRole" }; + + expect(this.securityContext.hasRole("firstRole")).andReturn(false); + expect(this.securityContext.hasRole("secondRole")).andReturn(false); + expect(this.securityContext.hasRole("sixthRole")).andReturn(true); + + prepareMock(target, methodName, expectedRoles, true, true); + + interceptor.manage(this.ic); + } + +} -- libgit2 0.21.2