deltaspike-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Allen Cunningham <cunning...@olsdallas.com>
Subject Re: Test-Control ProjectStage
Date Sun, 07 Dec 2014 23:44:51 GMT
Gerhard,

The only difference I could see in your template was the DeltaSpike
version. So I downloaded 1.2.0 and my tests work fine now.
If anyone else cares, I suspect ProjectStage has a problem in 1.0.3. We're
happy to use 1.2.0.

Allen

On Fri, Dec 5, 2014 at 5:27 PM, Gerhard Petracek <gerhard.petracek@gmail.com
> wrote:

> hi allen,
>
> the zip-file you provided contains a bit more.
> however, if i use the parts you described in your mail (with [1]),
> everything works as expected.
>
> regards,
> gerhard
>
> [1] https://github.com/os890/javase-cdi-ds-project-template
>
>
>
> http://www.irian.at
>
> Your JavaEE powerhouse -
> JavaEE Consulting, Development and
> Courses in English and German
>
> Professional Support for Apache
> MyFaces, DeltaSpike and OpenWebBeans
>
>
>
> 2014-12-05 21:25 GMT+01:00 Allen Cunningham <cunningham@olsdallas.com>:
>
> > I'm having trouble with the ProjectStage in Test-Control. My tests run
> with
> > ProjectStage.Production instead of UnitTest.
> >
> > I put together a simple project to demonstrate my problem:
> >
> > Test class:
> >
> > @RunWith(CdiTestRunner.class)
> > @TestControl(startScopes = ApplicationScoped.class)
> > public class UnitTest {
> >   @Inject SampleClient sampleClient;
> >
> >   @Test
> >   @TestControl(projectStage = ProjectStage.UnitTest.class)
> >   public void go() {
> >     sampleClient.init(new StartupEvent());
> >   }
> > }
> >
> > SampleClient:
> >
> > @ApplicationScoped
> > public class SampleClient {
> >   @Inject SampleAPI sampleAPI;
> >
> >   public void init(@Observes @Any StartupEvent event) {
> >     System.out.println(sampleAPI.doSomething());
> >   }
> > }
> >
> > The API:
> >
> > public interface SampleAPI {
> >   public String doSomething();
> > }
> >
> > The production implementation:
> >
> > @ApplicationScoped
> > @Exclude(ifProjectStage = ProjectStage.UnitTest.class)
> > public class SampleImpl implements SampleAPI {
> >
> >   @Override
> >   public String doSomething() {
> >     return "Greetings from Impl";
> >   }
> > }
> >
> > And finally the mock bean:
> >
> > @ApplicationScoped
> > @Exclude(exceptIfProjectStage = ProjectStage.UnitTest.class)
> > public class SampleMock implements SampleAPI {
> >
> >   @Override
> >   public String doSomething() {
> >     return "Greetings from Mock";
> >   }
> > }
> >
> > When I launch the app using CdiContainer, it loads the mock bean
> correctly,
> > but when I launch it using CdiTestRunner it loads SampleImpl.
> >
> > Single stepping through OWB I see that the DeltaSpike
> ProjectStageProducer
> > sees projectStage == null and sets it to Production by default.
> >
> > Am I missing something in my test config?
> >
> > I put a zip of the project here:
> > https://www.dropbox.com/s/vg76rdapsl4yps9/ProjectStage.zip?dl=0
> > Sorry it isn't Maven!
> > "ant" will launch it normally and "ant test" will run the unit test.
> >
> > Thanks!
> > Allen
> >
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message