Skip to content

Commit

Permalink
Tests for WELD-314
Browse files Browse the repository at this point in the history
  • Loading branch information
mbogoevici committed Jan 20, 2010
1 parent 0df85a9 commit afbaefa
Show file tree
Hide file tree
Showing 7 changed files with 227 additions and 0 deletions.
@@ -0,0 +1,34 @@
/*
* JBoss, Home of Professional Open Source
* Copyright2010, Red Hat, Inc. and/or its affiliates, and individual
* contributors by the @authors tag. See the copyright.txt in the
* distribution for a full listing of individual contributors.
*
* 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.jboss.weld.tests.decorators.interceptor;

import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import javax.interceptor.InterceptorBinding;

@Inherited
@InterceptorBinding
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface Intercepted
{
}
@@ -0,0 +1,43 @@
/*
* JBoss, Home of Professional Open Source
* Copyright2010, Red Hat, Inc. and/or its affiliates, and individual
* contributors by the @authors tag. See the copyright.txt in the
* distribution for a full listing of individual contributors.
*
* 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.jboss.weld.tests.decorators.interceptor;

import org.jboss.testharness.impl.packaging.Artifact;
import org.jboss.testharness.impl.packaging.jsr299.BeansXml;
import org.jboss.weld.test.AbstractWeldTest;

import org.testng.annotations.Test;

@Artifact
@BeansXml("beans.xml")
public class InterceptorAndDecoratorTest extends AbstractWeldTest
{

@Test(description="WELD-314", groups = "broken")
public void test()
{
ServiceImpl.invocationCount = 0;
ServiceDecorator.invocationCount = 0;
ServiceInterceptor.invocationCount = 0;
getReference(Service.class).execute();
assert ServiceImpl.invocationCount == 1;
assert ServiceDecorator.invocationCount == 1;
assert ServiceInterceptor.invocationCount == 1;
}

}
@@ -0,0 +1,23 @@
/*
* JBoss, Home of Professional Open Source
* Copyright2010, Red Hat, Inc. and/or its affiliates, and individual
* contributors by the @authors tag. See the copyright.txt in the
* distribution for a full listing of individual contributors.
*
* 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.jboss.weld.tests.decorators.interceptor;

public interface Service
{
void execute();
}
@@ -0,0 +1,52 @@
/*
* JBoss, Home of Professional Open Source
* Copyright2010, Red Hat, Inc. and/or its affiliates, and individual
* contributors by the @authors tag. See the copyright.txt in the
* distribution for a full listing of individual contributors.
*
* 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.
*/

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package org.jboss.weld.tests.decorators.interceptor;

import java.math.BigDecimal;
import java.util.concurrent.atomic.AtomicInteger;

import javax.decorator.Decorator;
import javax.decorator.Delegate;
import javax.inject.Inject;

/**
* Secure PaymentService implemented by decator
*
* @author wayne
*/
@Decorator
class ServiceDecorator implements Service
{

@Inject
@Delegate
private Service service;

public static int invocationCount = 0;

public void execute()
{
invocationCount++;
service.execute();
}
}
@@ -0,0 +1,30 @@
/*
* JBoss, Home of Professional Open Source
* Copyright2010, Red Hat, Inc. and/or its affiliates, and individual
* contributors by the @authors tag. See the copyright.txt in the
* distribution for a full listing of individual contributors.
*
* 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.jboss.weld.tests.decorators.interceptor;

public class ServiceImpl implements Service
{

public static int invocationCount = 0;

@Intercepted
public void execute()
{
invocationCount ++;
}
}
@@ -0,0 +1,37 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat, Inc. and/or its affiliates, and individual
* contributors by the @authors tag. See the copyright.txt in the
* distribution for a full listing of individual contributors.
*
* 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.jboss.weld.tests.decorators.interceptor;

import javax.interceptor.AroundInvoke;
import javax.interceptor.Interceptor;
import javax.interceptor.InvocationContext;

@Intercepted @Interceptor
public class ServiceInterceptor
{

public static int invocationCount = 0;

@AroundInvoke
public Object interceptService(InvocationContext invocationContext) throws Exception
{
this.invocationCount++;
return invocationContext.proceed();
}

}
@@ -0,0 +1,8 @@
<beans>
<decorators>
<class>org.jboss.weld.tests.decorators.interceptor.ServiceDecorator</class>
</decorators>
<interceptors>
<class>org.jboss.weld.tests.decorators.interceptor.ServiceInterceptor</class>
</interceptors>
</beans>

0 comments on commit afbaefa

Please sign in to comment.