Skip to content

Commit

Permalink
WELD-444
Browse files Browse the repository at this point in the history
  • Loading branch information
pmuir committed Feb 20, 2010
1 parent 671ec28 commit cc2d69c
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 5 deletions.
Expand Up @@ -1027,7 +1027,14 @@ public <T> InjectionTarget<T> createInjectionTarget(AnnotatedType<T> type)

public <T> InjectionTarget<T> createInjectionTarget(EjbDescriptor<T> descriptor)
{
return getBean(descriptor).getInjectionTarget();
if (descriptor.isMessageDriven())
{
return createInjectionTarget(createAnnotatedType(descriptor.getBeanClass()));
}
else
{
return getBean(descriptor).getInjectionTarget();
}
}

public <X> Bean<? extends X> getMostSpecializedBean(Bean<X> bean)
Expand Down
21 changes: 21 additions & 0 deletions tests/src/test/java/org/jboss/weld/tests/ejb/mdb/Control.java
@@ -0,0 +1,21 @@
package org.jboss.weld.tests.ejb.mdb;

import javax.enterprise.context.ApplicationScoped;

@ApplicationScoped
public class Control
{

private volatile boolean messageDelivered;

public boolean isMessageDelivered()
{
return messageDelivered;
}

public void setMessageDelivered(boolean messageDelivered)
{
this.messageDelivered = messageDelivered;
}

}
26 changes: 24 additions & 2 deletions tests/src/test/java/org/jboss/weld/tests/ejb/mdb/EJBTest.java
Expand Up @@ -16,20 +16,42 @@
*/
package org.jboss.weld.tests.ejb.mdb;

import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.naming.InitialContext;

import org.jboss.testharness.impl.packaging.Artifact;
import org.jboss.testharness.impl.packaging.IntegrationTest;
import org.jboss.testharness.impl.packaging.Packaging;
import org.jboss.testharness.impl.packaging.PackagingType;
import org.jboss.weld.test.AbstractWeldTest;
import org.testng.annotations.Test;

@Artifact
@Packaging(PackagingType.EAR)
@IntegrationTest
public class EJBTest extends AbstractWeldTest
{

@Test
public void testMdbDeploys()
public static final String MESSAGE = "Hello!";

@Test(groups="broken")
// TODO Need a way to deploy test-destinations-service.xml to JBoss AS
public void testMdbUsable() throws Exception
{
InitialContext ctx = new InitialContext();
QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup("ConnectionFactory");
QueueConnection connection = factory.createQueueConnection();
QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = (Queue) ctx.lookup("queue/testQueue");
QueueSender sender = session.createSender(queue);
sender.send(session.createTextMessage(MESSAGE));
Thread.sleep(1000);
assert getReference(Control.class).isMessageDelivered();
}

}
16 changes: 14 additions & 2 deletions tests/src/test/java/org/jboss/weld/tests/ejb/mdb/MilkMan.java
Expand Up @@ -18,19 +18,31 @@

import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.inject.Inject;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

@MessageDriven(activationConfig={
@ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Queue"),
@ActivationConfigProperty(propertyName="destination", propertyValue="queue/DLQ")
@ActivationConfigProperty(propertyName="destination", propertyValue="queue/testQueue")
})
public class MilkMan implements MessageListener
{

@Inject Control control;

public void onMessage(Message message)
{

try
{
control.setMessageDelivered(((TextMessage) message).getText().equals(EJBTest.MESSAGE));
}
catch (JMSException e)
{
throw new RuntimeException(e);
}
}

}
@@ -0,0 +1,39 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat, Inc., 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.ejb.mdb.dummy;

import org.jboss.testharness.impl.packaging.Artifact;
import org.jboss.testharness.impl.packaging.IntegrationTest;
import org.jboss.testharness.impl.packaging.Packaging;
import org.jboss.testharness.impl.packaging.PackagingType;
import org.jboss.weld.test.AbstractWeldTest;
import org.testng.annotations.Test;

@Artifact
@Packaging(PackagingType.EAR)
@IntegrationTest
public class EJBTest extends AbstractWeldTest
{

public static final String MESSAGE = "Hello!";

@Test
public void testMdbDeploys()
{
}

}
@@ -0,0 +1,37 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat, Inc., 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.ejb.mdb.dummy;

import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.Message;
import javax.jms.MessageListener;

@MessageDriven(activationConfig={
@ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Queue"),
@ActivationConfigProperty(propertyName="destination", propertyValue="queue/DLQ")
})
public class MilkMan implements MessageListener
{


public void onMessage(Message message)
{

}

}
@@ -0,0 +1,17 @@
<server>
<mbean code="org.jboss.mq.server.jmx.Topic"
name="jboss.mq.destination:service=Topic,name=testTopic">
<depends optional-attribute-name="ServerPeer">
jboss.messaging:service=ServerPeer
</depends>
<depends>jboss.messaging:service=PostOffice</depends>
</mbean>

<mbean code="org.jboss.mq.server.jmx.Queue"
name="jboss.mq.destination:service=Queue,name=testQueue">
<depends optional-attribute-name="ServerPeer">
jboss.messaging:service=ServerPeer
</depends>
<depends>jboss.messaging:service=PostOffice</depends>
</mbean>
</server>

0 comments on commit cc2d69c

Please sign in to comment.