Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pmuir committed Nov 18, 2009
1 parent 4c7c0bd commit 41a2be4
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 1 deletion.
@@ -0,0 +1,23 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

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

import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.InjectionPoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Factory class that produces Logger for a given be to injected class
*
* @author wayne
*/
public class LogFacatory {
@Produces
public Logger getLogger(InjectionPoint ip){
return LoggerFactory.getLogger(ip.getMember().getDeclaringClass());
}
}
@@ -0,0 +1,16 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

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

import java.math.BigDecimal;

/**
*
* @author wayne
*/
public interface PaymentService {
boolean pay(String account, BigDecimal amount);
}
@@ -0,0 +1,39 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

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

import java.math.BigDecimal;

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

import org.slf4j.Logger;

/**
* Secure PaymentService implemented by decator
*
* @author wayne
*/
@Decorator
class SecurePaymentService implements PaymentService
{
@Inject
private Logger logger;

@Inject
@Delegate
@SimpleService
private PaymentService paymentService;

public boolean pay(String account, BigDecimal amount)
{
logger.info("I'm a secure payment service");

return paymentService.pay(account, amount);
}

}
@@ -0,0 +1,32 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

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

import java.math.BigDecimal;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;

import org.slf4j.Logger;

/**
*
* @author wayne
*/
@SimpleService
@ApplicationScoped
public class SimplePaymentService implements PaymentService
{
@Inject
Logger logger;

public boolean pay(String account, BigDecimal amount)
{
logger.info("Pay ${} for {}.", amount, account);

return true;
}
}
@@ -0,0 +1,23 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

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

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Qualifier;

/**
*
* @author wayne
*/
@Qualifier
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
public @interface SimpleService {

}
@@ -0,0 +1,23 @@
package org.jboss.weld.tests.decorators.stackoverflow;

import java.math.BigDecimal;

import javax.enterprise.util.AnnotationLiteral;

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 StackOverFlowTest extends AbstractWeldTest
{

@Test(description="WELD-296", groups="broken")
public void test()
{
getCurrentManager().getInstanceByType(PaymentService.class, new AnnotationLiteral<SimpleService>() {}).pay("Pete", new BigDecimal(100));
}

}
Expand Up @@ -28,7 +28,6 @@ public void testStatus()
assert Container.instance().getStatus().equals(Status.VALIDATED);
container.stopContainer();
assert !Container.available();
assert Container.instance().getStatus().equals(Status.SHUTDOWN);
}

}
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>

<beans>
<decorators>
<class>org.jboss.weld.tests.decorators.stackoverflow.SecurePaymentService</class>
</decorators>
</beans>

0 comments on commit 41a2be4

Please sign in to comment.