4
votes

I have a very famous error, but I can't solve it. I'm trying to run arqullian test for my application. I've done everything according to the official documentation. The long search for solution to the problem given nothing.

 16:49:42,713 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-4) MSC00001: Failed to start service jboss.deployment.unit."test.war".WeldService: org.jboss.msc.service.StartException in service jboss.deployment.unit."test.war".WeldService: org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [Sender] with qualifiers [@Default] at injection point [[field] @Inject com.test.test2.ejb.AppManagerBean.sender]
    at org.jboss.as.weld.services.WeldService.start(WeldService.java:83)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_13]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_13]
    at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_13]
Caused by: org.jboss.weld.exceptions.DeploymentException: 

    WELD-001408 Unsatisfied dependencies for type [Sender] with qualifiers [@Default] 

    at injection point [[field] @Inject com.test.test2.ejb.AppManagerBean.sender]
    at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:275)
    at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:244)
    at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:107)
    at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:127)
    at org.jboss.weld.bootstrap.Validator.validateBeans(Validator.java:346)
    at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:331)
    at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:366)
    at org.jboss.as.weld.WeldContainer.start(WeldContainer.java:83)
    at org.jboss.as.weld.services.WeldService.start(WeldService.java:76)
    ... 5 more

My test class:

package com.highstreetlabs.wlcome.rest;

import com.google.android.gcm.server.Result;
import com.google.android.gcm.server.Sender;
import com.test.test2.ejb.AppManager;
import com.test.test2.ejb.Storage;
import com.test.test2model.Customer;
import com.test.test2.rest.model.ProximityModel;
import com.test.test2.util.EntityManagerProducer;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.json.simple.parser.ParseException;
import org.junit.Test;
import org.junit.runner.RunWith;

import javax.ejb.EJB;
import javax.inject.Inject;

@RunWith(Arquillian.class)
public class CustomerCollectionResourceTest {

    @Deployment
    public static WebArchive createTestArchive() {
        return ShrinkWrap.create(WebArchive.class, "test.war")
                .addClasses(CustomerCollectionResource.class, EntityManagerProducer.class,
                        AppManager.class, Storage.class,
                        ParseException.class, Sender.class)
                .addPackage(Customer.class.getPackage())
                .addPackage(Result.class.getPackage())
                .addPackage(NotFoundException.class.getPackage())
                .addPackage(CustomerPhotoResource.class.getPackage())
                .addPackage(ProximityModel.class.getPackage())
                .addAsResource("import.sql")
                .addAsManifestResource(EmptyAsset.INSTANCE, "META-INF/beans.xml")
                .addAsManifestResource("test-ds.xml", "test-ds.xml");
    }

    @Inject
    CustomerCollectionResource resource;
    @EJB
    AppManager manager;

    @Test
    public void testList() throws Exception {
        resource = new CustomerCollectionResource();
        resource.list(null);
    }
}

AppManagerBean.java

import com.google.android.gcm.server.Constants;
import com.google.android.gcm.server.Message;
import com.google.android.gcm.server.Result;
import com.google.android.gcm.server.Sender;
import com.google.common.base.Strings;
import com.test.test2.json.JacksonObjectMapperProvider;
import com.test.test2.model.*;
import com.test.test2.rest.HttpStatusException;
import com.test.test2.rest.NotFoundException;
import com.test.test2.rest.model.ProximityModel;
import org.codehaus.jackson.map.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.ejb.Asynchronous;
import javax.ejb.Local;
import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.persistence.*;
import javax.persistence.criteria.*;
import javax.ws.rs.core.Response;
import java.io.IOException;
import java.util.List;


/**
 * Stateless EJB bean containing entire business logic implementation
 */
@Local(AppManager.class)
@Stateless
public class AppManagerBean implements AppManager {

    public static final String
            GCM_ENTER_ACTION = "enter",
            GCM_EXIT_ACTION = "exit",
            PARAM_DATA_JSON = "proximityModel",
            PARAM_CUSTOMER_ID = "customerId",
            PARAM_ACTION = "action";

    @Inject
    EntityManager em;

    @Inject
    Sender sender;
....
}

And finally class for test CustomerCollectionResource

@Path("customer/")
@RequestScoped
public class CustomerCollectionResource {

    final static int CACHEABLE_SECONDS = 0;
    @EJB
    private AppManager manager;

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public Response list(@QueryParam("email") String email) {

        final List<Customer> entities = manager.listCustomers(email);

        if(entities.size() == 0)
            throw new NotFoundException("There is no any customer");

        ListModel<ListItem> result = new ListModel<ListItem>(entities.size());
        result.itemType = ListItem.MEDIA_TYPE;
        final UriBuilder itemLink = UriBuilder.fromResource(CustomerResource.class);
        for (Customer entity : entities) {
            result.add(new ListItem(entity.getName(), itemLink.build(entity.getId())));
        }
        CacheControl cc = new CacheControl();
        cc.setMaxAge(CACHEABLE_SECONDS);
        cc.setPrivate(true);
        return Response.ok(result).cacheControl(cc).build();
    }


}

Sender Producer

public class GcmSenderProducer {

    @Resource String senderId;

    @Produces public Sender getSender() {
        return new Sender(senderId);
    }

}
1
and sender? Where is sender? Also, since you're using a web archive, I'm not sure what your app server is but put beans.xml in WEB-INF. Has a higher chance of being correct.John Ament
add producer code. when i moved beans.xml to web-inf - nothing changes.milgoff
Server: jboss as 7. Sender codemilgoff
I didn't think putting it in web-inf would change anything, but that's considered the most appropriate place to put it. Can you try explicitly adding GcmSenderProducer to your archive? Since all of your package names are removed, it's hard to tell if it's being included. Note that you may still get some odd behavior, since Sender is likely an external lib, but you're including it in your WAR.John Ament
Maybe the producer method's class has to be a bean? Try to make it @Stateless or somethingOndra Žižka

1 Answers

3
votes

Yes, I also think the GcmSenderProducer is missing so the Sender class cannot be injected propperly since it looks like it has no no-arg constructor and I guess the constructor.