Re: Question about unit testing

2012-09-05 Thread Martin Makundi
https://cwiki.apache.org/WICKET/type-safe-testing-in-wicket.html

=)

2012/9/5 Markward Schubert markward.schub...@gmail.com:
 Hi folks!

 I am sure this is a trivial question, but i am simply too dumb to figure
 this out.
 We have a DopDownChoice, which is prefilled by some modelvalue, given to
 the page.
 Until now i was doing some testing about the model-state before and after
 submitting, which then was correct.
 The problem in the browser was, that the rendered DropDownChoice did  not
 show the preselected value correctly. It could not recognize the equality
 between some member of the available choices and the model's choice.

 Actually it turned out that it was a problem with the model object's
 equals.

 Now my question is:

 What is the most elegant way to unit test the correct rendering of the
 preselection of the DropDownChoice or similar components?
 As said, simply dealing with sumbmit and stuff worked correctly.


 Regards,

 Markward

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Question about unit testing

2012-09-05 Thread Markward Schubert
Thanks for the link!

This is really interesting and I think I will adapt this.
Unfortunately I am not sure if this addresses my original Problem.

What I need is a kind of code, like this:

// start page...
tester.startComponentInPage(MyFormPanel.)

// verify that after initial page rendering, the selected item in the
DropDown equals the pageModel's
assertEquals(pageModel.myChoice.getLabel(),getDropDownChoice().currentlyRenderedSelectedChoiceItem());

As described before, I had a problem in the equals. This resulted in
myChoice being let's say red and the DropDown containing red black
blue, but please select was rendered in the DDC, because myChoice(red)
was not equal to dropChoice(red).

Sorry for the pseudo code :-)

So the DDC could not find out that the red of my model was the same as the
red in the choices list.
Of course this would be a stupid bug, but i would like to protect my code
against fellows changing the equals behavior.





--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Question-about-unit-testing-tp4651766p4651768.html
Sent from the Users forum mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Question about unit testing

2012-09-05 Thread Martin Makundi
This is what you need, works for any component:

/**
   * @param T
   * @param formComponent
   * @return T
   */
  @SuppressWarnings(unchecked)
  public static T T getConvertedValue(FormComponentT formComponent) {
try {
  if (formComponent instanceof AbstractSingleSelectChoice) {
return (T)
abstractSingleSelectChoiceConverterMethod.invoke(formComponent,
formComponent.getValue());
  }

  if (formComponent instanceof RadioGroupWithVisibleConverter) {
String rawInput = ((RadioGroupWithVisibleConverterT)
formComponent).getRawInput();
if (rawInput != null) {
  return ((RadioGroupWithVisibleConverterT)
formComponent).convertValue(new String[] { rawInput });
}

T t = formComponent.getConvertedInput();

if (t != null) {
  return t;
}

return formComponent.getModelObject();
  }

  String value = getRawInputForReal(formComponent);

  if ([-NO-RAW-INPUT-].equals(value)) {
return formComponent.getModelObject();
  }

  if (Utils.isEmpty(value) 
(!String.class.equals(formComponent.getType( {
value = null;
  }

  return (T)
formComponent.getConverter(formComponent.getType()).convertToObject(value,
formComponent.getLocale());
} catch (ConversionException e) {
  ValidationError error = new ValidationError();
  if (e.getResourceKey() != null)
  {
error.addMessageKey(e.getResourceKey());
  }
  String simpleName = Classes.simpleName(formComponent.getType());
  error.addMessageKey(IConverter. + simpleName);
  error.addMessageKey(IConverter);
  error.setVariable(type, simpleName);

  final Locale locale = e.getLocale();
  if (locale != null)
  {
error.setVariable(locale, locale);
error.setVariable(input, Utils.noNull(formComponent.getRawInput()));
  }
  error.setVariable(exception, e);
  Format format = e.getFormat();
  if (format instanceof SimpleDateFormat)
  {
error.setVariable(format,
((SimpleDateFormat)format).toLocalizedPattern());
  }

  MapString, Object variables = e.getVariables();
  if (variables != null)
  {
error.getVariables().putAll(variables);
  }

  formComponent.error((IValidationError)error);

  return formComponent.getModelObject(); // Default value
} catch (Exception e) {
  throw new RuntimeException(e);
}
  }

**
Martin

2012/9/5 Markward Schubert markward.schub...@gmail.com:
 Thanks for the link!

 This is really interesting and I think I will adapt this.
 Unfortunately I am not sure if this addresses my original Problem.

 What I need is a kind of code, like this:

 // start page...
 tester.startComponentInPage(MyFormPanel.)

 // verify that after initial page rendering, the selected item in the
 DropDown equals the pageModel's
 assertEquals(pageModel.myChoice.getLabel(),getDropDownChoice().currentlyRenderedSelectedChoiceItem());

 As described before, I had a problem in the equals. This resulted in
 myChoice being let's say red and the DropDown containing red black
 blue, but please select was rendered in the DDC, because myChoice(red)
 was not equal to dropChoice(red).

 Sorry for the pseudo code :-)

 So the DDC could not find out that the red of my model was the same as the
 red in the choices list.
 Of course this would be a stupid bug, but i would like to protect my code
 against fellows changing the equals behavior.





 --
 View this message in context: 
 http://apache-wicket.1842946.n4.nabble.com/Question-about-unit-testing-tp4651766p4651768.html
 Sent from the Users forum mailing list archive at Nabble.com.

 -
 To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
 For additional commands, e-mail: users-h...@wicket.apache.org


-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Question about Unit Testing with custom Session

2011-02-09 Thread Dmitriy Neretin
Thank you for reply,

yes! And I get then another exception :)

Cannot resolve ServletContextResource without ServletContext

Does andybody know how can I get/set the servletContext?

Dmitriy

On 8 February 2011 18:01, Igor Vaynberg igor.vaynb...@gmail.com wrote:

 did you call context.refresh() ? like the error message said?

 -igor

 On Tue, Feb 8, 2011 at 1:31 AM, Dmitriy Neretin
 dmitriy.nere...@googlemail.com wrote:
  Hi,
 
  my complete setUp looks like this:
 
  @Before
 public void setUp() {
 MworldWicketApplication wicketWebApp = new
 MworldWicketApplication()
  {
 
 ApplicationContext ctx = new XmlWebApplicationContext();
 
 @Override
 public void init() {
 addComponentInstantiationListener(new
  SpringComponentInjector(this, ctx, true));
 }
 };
 
 tester = new WicketTester(wicketWebApp);
 pageParams = new HashMapString, String();
 }
 
  So the wickettester instance is created after the Appllication class is
  overriden. Even if I extract the wickettester creation from setup and
 will
  make it in each test (it is actually the same) I have the same problem.
 
  After debuggin the tests I have seen that my appcontext instance was
 created
  and the .xml file was correctly recognized :( But I still get the
  exception...
 
  On 8 February 2011 07:37, Igor Vaynberg igor.vaynb...@gmail.com wrote:
 
  make sure your setup() code runs before wicket tester instance is
 created.
 
  -igor
 
  On Mon, Feb 7, 2011 at 7:41 AM, Dmitriy Neretin
 
 
 

 -
 To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
 For additional commands, e-mail: users-h...@wicket.apache.org




Re: Question about Unit Testing with custom Session

2011-02-09 Thread Attila Király
Hi,

Try this in your application's #init() method (before calling #refresh() on
ctx)

ctx.setServletContext(getServletContext());

Attila

2011/2/9 Dmitriy Neretin dmitriy.nere...@googlemail.com

 Thank you for reply,

 yes! And I get then another exception :)

 Cannot resolve ServletContextResource without ServletContext

 Does andybody know how can I get/set the servletContext?

 Dmitriy

 On 8 February 2011 18:01, Igor Vaynberg igor.vaynb...@gmail.com wrote:

  did you call context.refresh() ? like the error message said?
 
  -igor
 
  On Tue, Feb 8, 2011 at 1:31 AM, Dmitriy Neretin
  dmitriy.nere...@googlemail.com wrote:
   Hi,
  
   my complete setUp looks like this:
  
   @Before
  public void setUp() {
  MworldWicketApplication wicketWebApp = new
  MworldWicketApplication()
   {
  
  ApplicationContext ctx = new XmlWebApplicationContext();
  
  @Override
  public void init() {
  addComponentInstantiationListener(new
   SpringComponentInjector(this, ctx, true));
  }
  };
  
  tester = new WicketTester(wicketWebApp);
  pageParams = new HashMapString, String();
  }
  
   So the wickettester instance is created after the Appllication class is
   overriden. Even if I extract the wickettester creation from setup and
  will
   make it in each test (it is actually the same) I have the same problem.
  
   After debuggin the tests I have seen that my appcontext instance was
  created
   and the .xml file was correctly recognized :( But I still get the
   exception...
  
   On 8 February 2011 07:37, Igor Vaynberg igor.vaynb...@gmail.com
 wrote:
  
   make sure your setup() code runs before wicket tester instance is
  created.
  
   -igor
  
   On Mon, Feb 7, 2011 at 7:41 AM, Dmitriy Neretin
  
  
  
 
  -
  To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
  For additional commands, e-mail: users-h...@wicket.apache.org
 
 




-- 
I would rather write programs to write programs than write programs.


Re: Question about Unit Testing with custom Session

2011-02-09 Thread Dmitriy Neretin
Hi,

thank you! Now I know how to get the ServletContext :) But it didn't solve
the main problem. This time I got following exception:

IOException parsing XML document from ServletContext resource
[/WEB-INF/applicationContext.xml]; nested exception is
java.io.FileNotFoundException: Could not open ServletContext resource
[/WEB-INF/applicationContext.xml]

This is the right path. The xml file is there. It also schouldn't be a
problem with file system permissions :(

On 9 February 2011 12:57, Attila Király kiralyattila...@gmail.com wrote:

 Hi,

 Try this in your application's #init() method (before calling #refresh() on
 ctx)

 ctx.setServletContext(getServletContext());

 Attila

 2011/2/9 Dmitriy Neretin dmitriy.nere...@googlemail.com

  Thank you for reply,
 
  yes! And I get then another exception :)
 
  Cannot resolve ServletContextResource without ServletContext
 
  Does andybody know how can I get/set the servletContext?
 
  Dmitriy
 
  On 8 February 2011 18:01, Igor Vaynberg igor.vaynb...@gmail.com wrote:
 
   did you call context.refresh() ? like the error message said?
  
   -igor
  
   On Tue, Feb 8, 2011 at 1:31 AM, Dmitriy Neretin
   dmitriy.nere...@googlemail.com wrote:
Hi,
   
my complete setUp looks like this:
   
@Before
   public void setUp() {
   MworldWicketApplication wicketWebApp = new
   MworldWicketApplication()
{
   
   ApplicationContext ctx = new XmlWebApplicationContext();
   
   @Override
   public void init() {
   addComponentInstantiationListener(new
SpringComponentInjector(this, ctx, true));
   }
   };
   
   tester = new WicketTester(wicketWebApp);
   pageParams = new HashMapString, String();
   }
   
So the wickettester instance is created after the Appllication class
 is
overriden. Even if I extract the wickettester creation from setup and
   will
make it in each test (it is actually the same) I have the same
 problem.
   
After debuggin the tests I have seen that my appcontext instance was
   created
and the .xml file was correctly recognized :( But I still get the
exception...
   
On 8 February 2011 07:37, Igor Vaynberg igor.vaynb...@gmail.com
  wrote:
   
make sure your setup() code runs before wicket tester instance is
   created.
   
-igor
   
On Mon, Feb 7, 2011 at 7:41 AM, Dmitriy Neretin
   
   
   
  
   -
   To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
   For additional commands, e-mail: users-h...@wicket.apache.org
  
  
 



 --
 I would rather write programs to write programs than write programs.



Re: Question about Unit Testing with custom Session

2011-02-09 Thread Attila Király
The problem is that your test is not actualy running in a servlet container,
only in a wicket mocked servlet context. To access webapp resources in the
test you have to specify in the second parameter of WicketTester constructor
where your web app's root is. Like this (in a maven project):

WicketTester tester = new WicketTester(new MockApplication(),
target/my-webapp-name);
Assert.assertNotNull(tester.getServletContext().getResource(WEB-INF/web.xml));

Attila

2011/2/9 Dmitriy Neretin dmitriy.nere...@googlemail.com

 Hi,

 thank you! Now I know how to get the ServletContext :) But it didn't solve
 the main problem. This time I got following exception:

 IOException parsing XML document from ServletContext resource
 [/WEB-INF/applicationContext.xml]; nested exception is
 java.io.FileNotFoundException: Could not open ServletContext resource
 [/WEB-INF/applicationContext.xml]

 This is the right path. The xml file is there. It also schouldn't be a
 problem with file system permissions :(

 On 9 February 2011 12:57, Attila Király kiralyattila...@gmail.com wrote:

  Hi,
 
  Try this in your application's #init() method (before calling #refresh()
 on
  ctx)
 
  ctx.setServletContext(getServletContext());
 
  Attila
 
  2011/2/9 Dmitriy Neretin dmitriy.nere...@googlemail.com
 
   Thank you for reply,
  
   yes! And I get then another exception :)
  
   Cannot resolve ServletContextResource without ServletContext
  
   Does andybody know how can I get/set the servletContext?
  
   Dmitriy
  
   On 8 February 2011 18:01, Igor Vaynberg igor.vaynb...@gmail.com
 wrote:
  
did you call context.refresh() ? like the error message said?
   
-igor
   
On Tue, Feb 8, 2011 at 1:31 AM, Dmitriy Neretin
dmitriy.nere...@googlemail.com wrote:
 Hi,

 my complete setUp looks like this:

 @Before
public void setUp() {
MworldWicketApplication wicketWebApp = new
MworldWicketApplication()
 {

ApplicationContext ctx = new XmlWebApplicationContext();

@Override
public void init() {
addComponentInstantiationListener(new
 SpringComponentInjector(this, ctx, true));
}
};

tester = new WicketTester(wicketWebApp);
pageParams = new HashMapString, String();
}

 So the wickettester instance is created after the Appllication
 class
  is
 overriden. Even if I extract the wickettester creation from setup
 and
will
 make it in each test (it is actually the same) I have the same
  problem.

 After debuggin the tests I have seen that my appcontext instance
 was
created
 and the .xml file was correctly recognized :( But I still get the
 exception...

 On 8 February 2011 07:37, Igor Vaynberg igor.vaynb...@gmail.com
   wrote:

 make sure your setup() code runs before wicket tester instance is
created.

 -igor

 On Mon, Feb 7, 2011 at 7:41 AM, Dmitriy Neretin



   
-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org
   
   
  
 
 
 
  --
  I would rather write programs to write programs than write programs.
 



Re: Question about Unit Testing with custom Session

2011-02-09 Thread Dmitriy Neretin
Thank you it finally works! :)

But what I still don't understand: the problem appeared after I inserted
following in the custom session constructor:

InjectorHolder.getInjector().inject(this);

And why it worked with only one WicketTester constructor parameter (new
MyApplication)? And after Spring integration there schould be 2 parameters?

Thank you!

P.S. My assertion for ServletContext looks like this:

Assert.assertNotNull(tester.getServletSession().getServletContext().getContext(WEB-INF/web.xml));

On 9 February 2011 14:27, Attila Király kiralyattila...@gmail.com wrote:

 The problem is that your test is not actualy running in a servlet
 container,
 only in a wicket mocked servlet context. To access webapp resources in the
 test you have to specify in the second parameter of WicketTester
 constructor
 where your web app's root is. Like this (in a maven project):

 WicketTester tester = new WicketTester(new MockApplication(),
 target/my-webapp-name);

 Assert.assertNotNull(tester.getServletContext().getResource(WEB-INF/web.xml));

 Attila

 2011/2/9 Dmitriy Neretin dmitriy.nere...@googlemail.com

  Hi,
 
  thank you! Now I know how to get the ServletContext :) But it didn't
 solve
  the main problem. This time I got following exception:
 
  IOException parsing XML document from ServletContext resource
  [/WEB-INF/applicationContext.xml]; nested exception is
  java.io.FileNotFoundException: Could not open ServletContext resource
  [/WEB-INF/applicationContext.xml]
 
  This is the right path. The xml file is there. It also schouldn't be a
  problem with file system permissions :(
 
  On 9 February 2011 12:57, Attila Király kiralyattila...@gmail.com
 wrote:
 
   Hi,
  
   Try this in your application's #init() method (before calling
 #refresh()
  on
   ctx)
  
   ctx.setServletContext(getServletContext());
  
   Attila
  
   2011/2/9 Dmitriy Neretin dmitriy.nere...@googlemail.com
  
Thank you for reply,
   
yes! And I get then another exception :)
   
Cannot resolve ServletContextResource without ServletContext
   
Does andybody know how can I get/set the servletContext?
   
Dmitriy
   
On 8 February 2011 18:01, Igor Vaynberg igor.vaynb...@gmail.com
  wrote:
   
 did you call context.refresh() ? like the error message said?

 -igor

 On Tue, Feb 8, 2011 at 1:31 AM, Dmitriy Neretin
 dmitriy.nere...@googlemail.com wrote:
  Hi,
 
  my complete setUp looks like this:
 
  @Before
 public void setUp() {
 MworldWicketApplication wicketWebApp = new
 MworldWicketApplication()
  {
 
 ApplicationContext ctx = new
 XmlWebApplicationContext();
 
 @Override
 public void init() {
 addComponentInstantiationListener(new
  SpringComponentInjector(this, ctx, true));
 }
 };
 
 tester = new WicketTester(wicketWebApp);
 pageParams = new HashMapString, String();
 }
 
  So the wickettester instance is created after the Appllication
  class
   is
  overriden. Even if I extract the wickettester creation from setup
  and
 will
  make it in each test (it is actually the same) I have the same
   problem.
 
  After debuggin the tests I have seen that my appcontext instance
  was
 created
  and the .xml file was correctly recognized :( But I still get the
  exception...
 
  On 8 February 2011 07:37, Igor Vaynberg igor.vaynb...@gmail.com
 
wrote:
 
  make sure your setup() code runs before wicket tester instance
 is
 created.
 
  -igor
 
  On Mon, Feb 7, 2011 at 7:41 AM, Dmitriy Neretin
 
 
 


 -
 To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
 For additional commands, e-mail: users-h...@wicket.apache.org


   
  
  
  
   --
   I would rather write programs to write programs than write programs.
  
 



Re: Question about Unit Testing with custom Session

2011-02-09 Thread Attila Király
Hi,

2011/2/9 Dmitriy Neretin dmitriy.nere...@googlemail.com

 Thank you it finally works! :)


Great!


 But what I still don't understand: the problem appeared after I inserted
 following in the custom session constructor:

 InjectorHolder.getInjector().inject(this);

 And why it worked with only one WicketTester constructor parameter (new
 MyApplication)? And after Spring integration there schould be 2 parameters?


Only spring's XmlWebApplicationContext needed the real web app resources
(the WEB-INF/applicationContext.xml file) wicket itself did not. So without
injection nothing was using it.

P.S. My assertion for ServletContext looks like this:


 Assert.assertNotNull(tester.getServletSession().getServletContext().getContext(WEB-INF/web.xml));


You are right. tester.getServletContext() is only available in 1.5, not in
1.4.

Attila



 On 9 February 2011 14:27, Attila Király kiralyattila...@gmail.com wrote:

  The problem is that your test is not actualy running in a servlet
  container,
  only in a wicket mocked servlet context. To access webapp resources in
 the
  test you have to specify in the second parameter of WicketTester
  constructor
  where your web app's root is. Like this (in a maven project):
 
  WicketTester tester = new WicketTester(new MockApplication(),
  target/my-webapp-name);
 
 
 Assert.assertNotNull(tester.getServletContext().getResource(WEB-INF/web.xml));
 
  Attila
 
  2011/2/9 Dmitriy Neretin dmitriy.nere...@googlemail.com
 
   Hi,
  
   thank you! Now I know how to get the ServletContext :) But it didn't
  solve
   the main problem. This time I got following exception:
  
   IOException parsing XML document from ServletContext resource
   [/WEB-INF/applicationContext.xml]; nested exception is
   java.io.FileNotFoundException: Could not open ServletContext resource
   [/WEB-INF/applicationContext.xml]
  
   This is the right path. The xml file is there. It also schouldn't be a
   problem with file system permissions :(
  
   On 9 February 2011 12:57, Attila Király kiralyattila...@gmail.com
  wrote:
  
Hi,
   
Try this in your application's #init() method (before calling
  #refresh()
   on
ctx)
   
ctx.setServletContext(getServletContext());
   
Attila
   
2011/2/9 Dmitriy Neretin dmitriy.nere...@googlemail.com
   
 Thank you for reply,

 yes! And I get then another exception :)

 Cannot resolve ServletContextResource without ServletContext

 Does andybody know how can I get/set the servletContext?

 Dmitriy

 On 8 February 2011 18:01, Igor Vaynberg igor.vaynb...@gmail.com
   wrote:

  did you call context.refresh() ? like the error message said?
 
  -igor
 
  On Tue, Feb 8, 2011 at 1:31 AM, Dmitriy Neretin
  dmitriy.nere...@googlemail.com wrote:
   Hi,
  
   my complete setUp looks like this:
  
   @Before
  public void setUp() {
  MworldWicketApplication wicketWebApp = new
  MworldWicketApplication()
   {
  
  ApplicationContext ctx = new
  XmlWebApplicationContext();
  
  @Override
  public void init() {
  addComponentInstantiationListener(new
   SpringComponentInjector(this, ctx, true));
  }
  };
  
  tester = new WicketTester(wicketWebApp);
  pageParams = new HashMapString, String();
  }
  
   So the wickettester instance is created after the Appllication
   class
is
   overriden. Even if I extract the wickettester creation from
 setup
   and
  will
   make it in each test (it is actually the same) I have the same
problem.
  
   After debuggin the tests I have seen that my appcontext
 instance
   was
  created
   and the .xml file was correctly recognized :( But I still get
 the
   exception...
  
   On 8 February 2011 07:37, Igor Vaynberg 
 igor.vaynb...@gmail.com
  
 wrote:
  
   make sure your setup() code runs before wicket tester instance
  is
  created.
  
   -igor
  
   On Mon, Feb 7, 2011 at 7:41 AM, Dmitriy Neretin
  
  
  
 
 
  -
  To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
  For additional commands, e-mail: users-h...@wicket.apache.org
 
 

   
   
   
--
I would rather write programs to write programs than write
 programs.
   
  
 



Re: Question about Unit Testing with custom Session

2011-02-08 Thread Dmitriy Neretin
Hi,

my complete setUp looks like this:

@Before
public void setUp() {
MworldWicketApplication wicketWebApp = new MworldWicketApplication()
{

ApplicationContext ctx = new XmlWebApplicationContext();

@Override
public void init() {
addComponentInstantiationListener(new
SpringComponentInjector(this, ctx, true));
}
};

tester = new WicketTester(wicketWebApp);
pageParams = new HashMapString, String();
}

So the wickettester instance is created after the Appllication class is
overriden. Even if I extract the wickettester creation from setup and will
make it in each test (it is actually the same) I have the same problem.

After debuggin the tests I have seen that my appcontext instance was created
and the .xml file was correctly recognized :( But I still get the
exception...

On 8 February 2011 07:37, Igor Vaynberg igor.vaynb...@gmail.com wrote:

 make sure your setup() code runs before wicket tester instance is created.

 -igor

 On Mon, Feb 7, 2011 at 7:41 AM, Dmitriy Neretin




Re: Question about Unit Testing with custom Session

2011-02-08 Thread Igor Vaynberg
did you call context.refresh() ? like the error message said?

-igor

On Tue, Feb 8, 2011 at 1:31 AM, Dmitriy Neretin
dmitriy.nere...@googlemail.com wrote:
 Hi,

 my complete setUp looks like this:

 @Before
    public void setUp() {
        MworldWicketApplication wicketWebApp = new MworldWicketApplication()
 {

            ApplicationContext ctx = new XmlWebApplicationContext();

            @Override
            public void init() {
                addComponentInstantiationListener(new
 SpringComponentInjector(this, ctx, true));
            }
        };

        tester = new WicketTester(wicketWebApp);
        pageParams = new HashMapString, String();
    }

 So the wickettester instance is created after the Appllication class is
 overriden. Even if I extract the wickettester creation from setup and will
 make it in each test (it is actually the same) I have the same problem.

 After debuggin the tests I have seen that my appcontext instance was created
 and the .xml file was correctly recognized :( But I still get the
 exception...

 On 8 February 2011 07:37, Igor Vaynberg igor.vaynb...@gmail.com wrote:

 make sure your setup() code runs before wicket tester instance is created.

 -igor

 On Mon, Feb 7, 2011 at 7:41 AM, Dmitriy Neretin




-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Question about Unit Testing with custom Session

2011-02-07 Thread Dmitriy Neretin
Hello everybody,

After integration with spring I have following problem:

if I add following to my CustomSession:

InjectorHolder.getInjector().inject(this); (because I store some spring
beans in the custom session)

My WicketTester doesn't work anymore. I get this exception:
BeanFactory not initialized or already closed - call 'refresh' before
accessing beans via the ApplicationContext

What I have done in my Unit Tests:

@Before
public void setUp() {
MworldWicketApplication wicketWebApp = new MworldWicketApplication()
{

ApplicationContext ctx = new XmlWebApplicationContext();

@Override
public void init() {
addComponentInstantiationListener(new
SpringComponentInjector(this, ctx, true));
}
};

And I don't really understand what to do now :)

Can somebody help me?

P. S. The Application works. Affected are only unit tests


Re: Question about Unit Testing with custom Session

2011-02-07 Thread Pedro Santos
I guess the problem is on the ApplicationContext object. Debug its creation
and see if it has all your beans. You can use another implementation for
tests, ex: FileSystemXmlApplicationContext

On Mon, Feb 7, 2011 at 11:10 AM, Dmitriy Neretin 
dmitriy.nere...@googlemail.com wrote:

 Hello everybody,

 After integration with spring I have following problem:

 if I add following to my CustomSession:

 InjectorHolder.getInjector().inject(this); (because I store some spring
 beans in the custom session)

 My WicketTester doesn't work anymore. I get this exception:
 BeanFactory not initialized or already closed - call 'refresh' before
 accessing beans via the ApplicationContext

 What I have done in my Unit Tests:

 @Before
public void setUp() {
MworldWicketApplication wicketWebApp = new MworldWicketApplication()
 {

ApplicationContext ctx = new XmlWebApplicationContext();

@Override
public void init() {
addComponentInstantiationListener(new
 SpringComponentInjector(this, ctx, true));
}
};

 And I don't really understand what to do now :)

 Can somebody help me?

 P. S. The Application works. Affected are only unit tests




-- 
Pedro Henrique Oliveira dos Santos


Re: Question about Unit Testing with custom Session

2011-02-07 Thread Martijn Dashorst
Did you provide the application to the wicket tester?

WicketTester tester = new WicketTester(myapp);

Martijn

On Mon, Feb 7, 2011 at 2:10 PM, Dmitriy Neretin
dmitriy.nere...@googlemail.com wrote:
 Hello everybody,

 After integration with spring I have following problem:

 if I add following to my CustomSession:

 InjectorHolder.getInjector().inject(this); (because I store some spring
 beans in the custom session)

 My WicketTester doesn't work anymore. I get this exception:
 BeanFactory not initialized or already closed - call 'refresh' before
 accessing beans via the ApplicationContext

 What I have done in my Unit Tests:

 @Before
    public void setUp() {
        MworldWicketApplication wicketWebApp = new MworldWicketApplication()
 {

            ApplicationContext ctx = new XmlWebApplicationContext();

            @Override
            public void init() {
                addComponentInstantiationListener(new
 SpringComponentInjector(this, ctx, true));
            }
        };

 And I don't really understand what to do now :)

 Can somebody help me?

 P. S. The Application works. Affected are only unit tests




-- 
Become a Wicket expert, learn from the best: http://wicketinaction.com

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Question about Unit Testing with custom Session

2011-02-07 Thread Dmitriy Neretin
Hi,

of course. The point is if I delete this:

InjectorHolder.getInjector().inject(this);

from my session class everything works fine :(

On 7 February 2011 15:27, Martijn Dashorst martijn.dasho...@gmail.comwrote:

 Did you provide the application to the wicket tester?

 WicketTester tester = new WicketTester(myapp);

 Martijn

 On Mon, Feb 7, 2011 at 2:10 PM, Dmitriy Neretin
 dmitriy.nere...@googlemail.com wrote:
  Hello everybody,
 
  After integration with spring I have following problem:
 
  if I add following to my CustomSession:
 
  InjectorHolder.getInjector().inject(this); (because I store some spring
  beans in the custom session)
 
  My WicketTester doesn't work anymore. I get this exception:
  BeanFactory not initialized or already closed - call 'refresh' before
  accessing beans via the ApplicationContext
 
  What I have done in my Unit Tests:
 
  @Before
 public void setUp() {
 MworldWicketApplication wicketWebApp = new
 MworldWicketApplication()
  {
 
 ApplicationContext ctx = new XmlWebApplicationContext();
 
 @Override
 public void init() {
 addComponentInstantiationListener(new
  SpringComponentInjector(this, ctx, true));
 }
 };
 
  And I don't really understand what to do now :)
 
  Can somebody help me?
 
  P. S. The Application works. Affected are only unit tests
 



 --
 Become a Wicket expert, learn from the best: http://wicketinaction.com

 -
 To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
 For additional commands, e-mail: users-h...@wicket.apache.org




Re: Question about Unit Testing with custom Session

2011-02-07 Thread Igor Vaynberg
make sure your setup() code runs before wicket tester instance is created.

-igor

On Mon, Feb 7, 2011 at 7:41 AM, Dmitriy Neretin
dmitriy.nere...@googlemail.com wrote:
 Hi,

 of course. The point is if I delete this:

 InjectorHolder.getInjector().inject(this);

 from my session class everything works fine :(

 On 7 February 2011 15:27, Martijn Dashorst martijn.dasho...@gmail.comwrote:

 Did you provide the application to the wicket tester?

 WicketTester tester = new WicketTester(myapp);

 Martijn

 On Mon, Feb 7, 2011 at 2:10 PM, Dmitriy Neretin
 dmitriy.nere...@googlemail.com wrote:
  Hello everybody,
 
  After integration with spring I have following problem:
 
  if I add following to my CustomSession:
 
  InjectorHolder.getInjector().inject(this); (because I store some spring
  beans in the custom session)
 
  My WicketTester doesn't work anymore. I get this exception:
  BeanFactory not initialized or already closed - call 'refresh' before
  accessing beans via the ApplicationContext
 
  What I have done in my Unit Tests:
 
  @Before
     public void setUp() {
         MworldWicketApplication wicketWebApp = new
 MworldWicketApplication()
  {
 
             ApplicationContext ctx = new XmlWebApplicationContext();
 
             @Override
             public void init() {
                 addComponentInstantiationListener(new
  SpringComponentInjector(this, ctx, true));
             }
         };
 
  And I don't really understand what to do now :)
 
  Can somebody help me?
 
  P. S. The Application works. Affected are only unit tests
 



 --
 Become a Wicket expert, learn from the best: http://wicketinaction.com

 -
 To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
 For additional commands, e-mail: users-h...@wicket.apache.org




-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org