1 2 Previous Next 26 Replies Latest reply: Oct 19, 2012 4:21 AM by Bernard Labno RSS

Please can this extension be added to Arquillian

Tony Herstell Master

Please can this extension be added to Arquillian and be added to the guides.

 

http://blog.it-crowd.com.pl/2012/04/mock-contexts-for-arquillian.html

 

I cant see how any reasonable project can be achieved, simply and safely, without the use of Conversation scope (at least).

  • 1. Re: Please can this extension be added to Arquillian
    Tony Herstell Master

    Code that uses conversation....

     

     

    // Leverage EJB to get Transactional Support

    @Stateful

    // Lets be long running (multiple client-server round trips) - Needs Extended on

    // PersistanceContext too to hold onto my objects and not get LIEs.

    @ConversationScoped

    // EL Can can find me...

    @Named

    public class UserManagementController extends BaseController {

     

     

        private Logger logger = Logger.getLogger(UserManagementController.class.getName());

     

     

       @SuppressWarnings("unused")

        @URLQueryParameter("cid")

        private String cid;

     

     

        // DON'T let any Entities be Proxied by WELD so just use class local.

        // According to this definition, JPA entities are technically managed beans.

        // However, entities have

        // their own special lifecycle, state and identity model and are usually

        // instantiated by JPA or using

        // new. Therefore we don't recommend directly injecting an entity class. We

        // especially recommend

        // against assigning a scope other than @Dependent to an entity class, since

        // JPA is not able to

        // persist injected CDI proxies.

        private List<User> users;

     

     

        private CRUDMode cRUDMode;

        private CreateMode createMode;

     

     

        // Access to the persistence store so we can read from the DB with Long

        // Running extension to go with Conversation Scope above.

        @PersistenceContext(type = PersistenceContextType.EXTENDED)

        private EntityManager em;

     

     

        // Inject this to make conversation magic happen

        @Inject

        private Conversation conversation;

     

    ...

     

       /*

         * Hack to pass cid to prettyfaces so it can add it to URL - DONT remove.

         */

        public String getCid() {

            return this.conversation.getId();

        }

     

     

        public void setCid(String cid) {

            this.cid = cid;

        }

     

    ...

     

        // A good place to START a conversation from. ** land here off a menu

        // click...

        public String init() {

            this.logger.info(">>>init");

            if (!this.conversation.isTransient()) {

                this.logger.info("Existing conversation found:" + this.conversation.getId() + " Ending it...");

                this.conversation.end();

            }

            this.logger.info("+++CONVERSATION START");

            this.conversation.begin(); // START THE LONG RUNNING CONVERSATION

            this.logger.info("conversation:" + this.conversation.getId());

            this.logger.info("<<<init");

            return "pretty:manageUsers";

        }

     

    etc.

  • 2. Re: Please can this extension be added to Arquillian
    Tony Herstell Master

    Test Code that doesnt work.... (See pl.com.it_crowd.arquillian.mock_contexts.ConversationScopeRequired;)

     

        @ConversationScopeRequired

        @Test

        public void conversationScopedBeanTest() {

            // Assert.assertEquals(0, userManagementController.getCid());

            // userManagementController.setCid("1");

            // Assert.assertEquals(1, userManagementController.getCid());

            Assert.assertTrue(true);

        }

  • 3. Re: Please can this extension be added to Arquillian
    Bernard Labno Master

    If you want to use Conversation object you need to mock it, cause it's tightly coupled with Weld impl.

    Read this: http://blog.it-crowd.com.pl/2012/06/mock-conversation.html

  • 4. Re: Please can this extension be added to Arquillian
    Tony Herstell Master

    Humm..

    As it's a test do I add to beans.xml in the normal project or create a beans.xml in the test area?

     

    This:

    BeansDescriptor.class

    From:

    final String beansDescriptor = Descriptors.create(BeansDescriptor.class)

                    .createAlternatives()

                    .clazz(MockConversation.class.getCanonicalName())

                    .up()

                    .exportAsString();

    is not found; where did this come from (import?)?

     

    http://artifactory.it-crowd.com.pl/repo is giving unobtainable at the moment

     

    The Joys....

     

    found more info here:

       http://blog.it-crowd.com.pl/2012/04/mock-contexts-for-arquillian.html

  • 5. Re: Please can this extension be added to Arquillian
    Bernard Labno Master

    Artifactory is back again, thank you for reporting that. BeansDescriptor comes from shrinkwrap-descriptors-impl-javaee.

  • 6. Re: Please can this extension be added to Arquillian
    Tony Herstell Master

    >> Now you need to register it as alternative in beans.xml you ship with deployment:

    Do you have an example?

     

    I assume:


    <alternatives>


    <class>com.apiarymanager.controller.users.userManagement.MockConversation</class>

    </alternatives>

     

     

    >> As it's a test do I add to beans.xml in the normal project or create a beans.xml in the test area?

  • 7. Re: Please can this extension be added to Arquillian
    Tony Herstell Master

    Please can you see where you are getting shrinkwrap-descriptors-impl-javaee from in your pom.

     

    I dont have it available.

  • 8. Re: Please can this extension be added to Arquillian
    Tony Herstell Master

    I THINK this line means you dont have to include the override in beans.xml at all.....

     

    final String beansDescriptor = Descriptors.create(BeansDescriptor.class)

                    .createAlternatives()

                    .clazz(MockConversation.class.getCanonicalName())

                    .up()

                    .exportAsString();

     

    I have foce added this to pom:



    <!-- And this for Conversation scope -->


    <dependency>



    <groupId>org.jboss.shrinkwrap.descriptors</groupId>



    <artifactId>shrinkwrap-descriptors-api-javaee</artifactId>



    <version>2.0.0-alpha-3</version>


    </dependency>

     

    but alas now this is not known:

    .addAsWebInfResource

     

    What version of arquillian are you using?

  • 10. Re: Please can this extension be added to Arquillian
    Tony Herstell Master

    Gets me to...

     

    >>

    No resource META-INF/services/org.jboss.shrinkwrap.descriptor.api.beans10.BeansDescriptor was found configured for user view class org.jboss.shrinkwrap.descriptor.api.beans10.BeansDescriptor

    <<

     

    @Deployment

        public static WebArchive createDeployment() {

            final String beansDescriptor = Descriptors.create(BeansDescriptor.class)

                    .createAlternatives()

                    .clazz(MockConversation.class.getCanonicalName())

                    .up()

                    .exportAsString();

            WebArchive war = ShrinkWrap.create(WebArchive.class)

                    .addClass(UserManagementController.class)

                    .addClass(Identity.class)

                    .addAsWebInfResource(new StringAsset(beansDescriptor), "beans.xml")

                    .addAsManifestResource("META-INF/persistence.xml", "persistence.xml")

                    .addAsManifestResource("arquillian.xml", "arquillian.xml")

                    .addAsManifestResource(new StringAsset(beansDescriptor),"beans.xml");

            System.out.println(war.toString(true));

            return war;

        }

     

    Thx for the support Bernard

  • 11. Re: Please can this extension be added to Arquillian
    Bernard Labno Master

    You're missing somethin in pom.xml. Compare all dependnecies versions with the sample i've povided. Try comparing "mvn dependency:tree" on both my sample and your project.

  • 12. Re: Please can this extension be added to Arquillian
    Tony Herstell Master

    Is there an update to getting conversationm scope formally added?

  • 13. Re: Please can this extension be added to Arquillian
    Bernard Labno Master

    Tony what do you mean by this:

    Tony Herstell wrote:

     

    Is there an update to getting conversationm scope formally added?

  • 14. Re: Please can this extension be added to Arquillian
    Tony Herstell Master

    Bernard Labno wrote:

     

    Tony what do you mean by this:

    Tony Herstell wrote:

     

    Is there an update to getting conversationm scope formally added?

     

    Is this getting adopted?

     

    http://blog.it-crowd.com.pl/2012/04/mock-contexts-for-arquillian.html

1 2 Previous Next