You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by hwaastad <he...@waastad.org> on 2015/11/02 16:01:45 UTC

ApplicationComposer, alternative-stereotype mocking

Hi,

https://github.com/hwaastad/ApplicationComposerMock.git

Basically what I'm doing is adding a @alternative/@stereotype qualifier in
test sources and when needing to "mock" an injection I just add a:

@module
Beans beans = new Beans();
beans.addAlternativeStereotype(Alpha.class);

In 1.7.2 it's working fine, in 7.0.0 it's not.
I've tried to add beans.setBeanDiscoveryMode("all"); but it does'nt seem to
help at all.

BTW,
to add an alternative implementation for a Stateless during tests, I still
need to name my alternative stateless implementation.

eks:

BusinessBean impl interface

Alternative:

@Alpha (/this is the qualifier)
AlternativeBean(name="BusinessBean") extends BusinessBean {
}

This cant't be right?

br hw






--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/ApplicationComposer-alternative-stereotype-mocking-tp4676678.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Re: ApplicationComposer, alternative-stereotype mocking

Posted by Romain Manni-Bucau <rm...@gmail.com>.
I think only an EJB can specialize an EJB - writing it from memory so take
it as it please. This is actually nice cause it enforces the exception
model and avoid to miss cases in tests. But yes @Specializes is a quick and
efficient mocking solution.


Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
<http://www.tomitribe.com>

2015-11-03 10:08 GMT-08:00 hwaastad <he...@waastad.org>:

> OK,
> cool and I'll check out tomorrow.
>
> So, If I can try to summarize what I can do:
>
> - For CDI beans I only need @specializes when extending implementation.
>
> - For EJB's I need either a @Local or @Local(iface) and @specializes.
>
> No need for specific beans.xml config.
>
> Actually, just using @specializes fits my need in this pratially mocking
> scenario..
>
> Made a use.local-interface branch just to state the, after some
> consideration, the obvious :-)
>
> br hw
>
>
>
> --
> View this message in context:
> http://tomee-openejb.979440.n4.nabble.com/ApplicationComposer-alternative-stereotype-mocking-tp4676678p4676714.html
> Sent from the TomEE Users mailing list archive at Nabble.com.
>

Re: ApplicationComposer, alternative-stereotype mocking

Posted by hwaastad <he...@waastad.org>.
OK,
cool and I'll check out tomorrow.

So, If I can try to summarize what I can do:

- For CDI beans I only need @specializes when extending implementation.

- For EJB's I need either a @Local or @Local(iface) and @specializes.

No need for specific beans.xml config.

Actually, just using @specializes fits my need in this pratially mocking
scenario..

Made a use.local-interface branch just to state the, after some
consideration, the obvious :-)

br hw



--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/ApplicationComposer-alternative-stereotype-mocking-tp4676678p4676714.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Re: ApplicationComposer, alternative-stereotype mocking

Posted by Romain Manni-Bucau <rm...@gmail.com>.
you are right,

adding stereotypes programmatically now needs some "too much" knowledge on
tomee, added it: https://issues.apache.org/jira/browse/TOMEE-1652

Here is you 7.x test:

@RunWith(ApplicationComposer.class)
@Classes(cdiStereotypes = Alpha.class, value = {
    BusinessBean.class, MockSmsBean.class, Sms.class, ProductionSms.class,
    Shopping.class, MockShoppingBean.class, ProductionShopping.class
})
public class BusinessBeanMockTest {
    @Inject
    private BusinessBean businessBean;

    @Test
    public void testDoSomething() throws Exception {
        assertEquals("ProductionSms: doStuff Alpha",
businessBean.doSomething());
    }

    @Test
    public void testShopping() throws Exception {
        assertEquals("ProductionShopping: doStuff Alpha",
businessBean.doShopping());
    }

}




Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
<http://www.tomitribe.com>

2015-11-03 6:38 GMT-08:00 hwaastad <he...@waastad.org>:

> Hi,
> there's a BusinessBeanMockTest in the project which will fail using profile
> 7.0.0 but is OK in profile 1.7.2.
>
> BTW,
> most current branch is develop......
>
> br hw
>
>
>
> --
> View this message in context:
> http://tomee-openejb.979440.n4.nabble.com/ApplicationComposer-alternative-stereotype-mocking-tp4676678p4676710.html
> Sent from the TomEE Users mailing list archive at Nabble.com.
>

Re: ApplicationComposer, alternative-stereotype mocking

Posted by hwaastad <he...@waastad.org>.
Hi,
there's a BusinessBeanMockTest in the project which will fail using profile
7.0.0 but is OK in profile 1.7.2.

BTW,
most current branch is develop......

br hw



--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/ApplicationComposer-alternative-stereotype-mocking-tp4676678p4676710.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Re: ApplicationComposer, alternative-stereotype mocking

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Le 3 nov. 2015 04:46, "hwaastad" <he...@waastad.org> a écrit :
>
> Hi,
> I give myself an answer on one of my questions.
>
> When extending my production EJB as an altenative/stereotype I should not
> annotate with @Stateless.
> Using annotation on alternative I need to specify the name on the
> superclass...or am i missing sthg here.....
>

Sounds more like a @Specializes rule. Do you have failing tests in place in
tour project about it? Would be easier to ensure i get it right.

>
> br
>
>
>
> --
> View this message in context:
http://tomee-openejb.979440.n4.nabble.com/ApplicationComposer-alternative-stereotype-mocking-tp4676678p4676705.html
> Sent from the TomEE Users mailing list archive at Nabble.com.

Re: ApplicationComposer, alternative-stereotype mocking

Posted by hwaastad <he...@waastad.org>.
Hi,
I give myself an answer on one of my questions.

When extending my production EJB as an altenative/stereotype I should not
annotate with @Stateless.
Using annotation on alternative I need to specify the name on the
superclass...or am i missing sthg here.....


br



--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/ApplicationComposer-alternative-stereotype-mocking-tp4676678p4676705.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Re: ApplicationComposer, alternative-stereotype mocking

Posted by hwaastad <he...@waastad.org>.
Hi Romain,
the project I referenced in my post is race-ready.

Two profiles: 1.7.2 and 7.0.0

I did'nt know about composite beans...

I notices some issues with jdk 8 and maven 3.3.3 but I'll look into that for
another discussion.

Br hw



--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/ApplicationComposer-alternative-stereotype-mocking-tp4676678p4676687.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Re: ApplicationComposer, alternative-stereotype mocking

Posted by Romain Manni-Bucau <rm...@gmail.com>.
2015-11-02 7:01 GMT-08:00 hwaastad <he...@waastad.org>:
>
> Hi,
>
> https://github.com/hwaastad/ApplicationComposerMock.git
>
> Basically what I'm doing is adding a @alternative/@stereotype qualifier in
> test sources and when needing to "mock" an injection I just add a:
>
> @module
> Beans beans = new Beans();
> beans.addAlternativeStereotype(Alpha.class);
>
> In 1.7.2 it's working fine, in 7.0.0 it's not.
> I've tried to add beans.setBeanDiscoveryMode("all"); but it does'nt seem
to
> help at all.
>

in 1.7 we had a single beans.xml (aggregated). This is not what was in the
spec but was passing all TCKs and acceptable - done by most of last impl.
In 7.x we respect more the modules cause of this discovery mode i
particular even if we try to keep our nice merging behavior. We have a
workaround for app composer but can have side effect depending how your
test is written. Main source base uses now CompositeBeans instead of Beans.

If you can share a ready to run project we can investigate more.

>
> BTW,
> to add an alternative implementation for a Stateless during tests, I still
> need to name my alternative stateless implementation.
>
> eks:
>
> BusinessBean impl interface
>
> Alternative:
>
> @Alpha (/this is the qualifier)
> AlternativeBean(name="BusinessBean") extends BusinessBean {
> }
>
> This cant't be right?
>
> br hw
>
>
>
>
>
>
> --
> View this message in context:
http://tomee-openejb.979440.n4.nabble.com/ApplicationComposer-alternative-stereotype-mocking-tp4676678.html
> Sent from the TomEE Users mailing list archive at Nabble.com.