Re: Injecting Static/Mock Resources into my Struts 2 Actions

2012-08-23 Thread CyberCom
On Thursday 23 August 2012 14:33:14 Davis, Chad wrote:
> >  > class="org.easymock.EasyMock"
> > factory-method="createStrictMock">
> > 
> >  
> > 
> > 
> 
> How do you control the correct injections for the various deployments?  Do
> you automate that with the build?  Scripted?

I use these in junit tests. I don't know if this is what you want to do the 
following is just codesnipplets hoping they are enough to show you how I use 
easymock with spring. But I guess I missed the part in your original message 
that you want to do UI testing. 

The unit test class:

import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.junit.Assert.assertEquals;
//more imports

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"applicationContextForThisUnitTest.xml"})
public class Tests extends StrutsSpringJUnit4TestCase {
  
@Autowired
private interface.for.the.service serviceWeNeed


@Before
public void setup(){
  ObjectFromService ofs = new ObjectFromService
expect(serviceWeNeed.methodeCalled).andReturn(ofs);
replay(serviceWeNeed);
}

@Test
public void test1() throws IOException, InteractionPackageUpdateExecption 
{
ActionProxy proxy = getActionProxy("/path/to/action.action");
TheActionToTest action = (TheActionToTest) proxy.getAction();
proxy.setExecuteResult(false);
try {
assertEquals("ExecutionCode", "input", proxy.execute());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

About using this method in UI test I'm not so sure. In our project I just 
wrote a second set of services return static data as need. Depending on the 
maven profile getting used for the build,  either the real services or just the 
dummys get include. Maybe this approache also works for you.

Regards,

Pascal



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



RE: Injecting Static/Mock Resources into my Struts 2 Actions

2012-08-23 Thread Davis, Chad

>  class="org.easymock.EasyMock"
> factory-method="createStrictMock">
>  
> 
> 

How do you control the correct injections for the various deployments?  Do you 
automate that with the build?  Scripted?  

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



RE: Injecting Static/Mock Resources into my Struts 2 Actions

2012-08-23 Thread Davis, Chad


> I do this all the time.

Then I'm not crazy ;)

> 
> Not sure what experiences you're looking for; if the data is _very_ complex it
> may be easier to just embed a DB and load it up with DBUnit or something
> like that.
> 

It's not the data that's complex so much as the whole distributed system that 
needs to be in place for the business objects to make actual queries . . .

> Basically any tutorial that talks about testing in Spring is applicable, the 
> only
> difference is the MVC layer.

I think I understand the Spring portion of this well enough.  One thing, 
however, that I'm not straight on is the build / deployment portion.  This is 
clearly off topic, for this list, but I wonder how to automate the spring 
config for the various deployment enivonments.  We have a maven build, and I'd 
like to use the build to configure the injections for the correct deployment 
target . . . but I'm leery of getting cross wise with Maven.



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



Re: Injecting Static/Mock Resources into my Struts 2 Actions

2012-08-22 Thread Per Pascal Grube
Hi

I use easymock  to mock service in the action classes.

In the spring context I add:


 
  

Hope thats enough to give you a idea how it could work

Regards,

Pascal

On Wednesday 22 August 2012 15:33:26 Davis, Chad wrote:
> I would like to deploy my app to a UI testing / demo environment.  In this
> environment, the regular business logic objects would be replaced ( via DI
> ) with mock implementations of those resources.  These mocks would return a
> static data set, thus giving a predictable behavior against which we can
> build automated UI tests, provide a lightweight demo environment that
> doesn't need integrated into our rather large and complex real world data
> context, etc.
> 
> My thoughts are to use the Spring integration to inject the mocks.  I'm new
> to doing DI / testing in this kind of setting.  Is anyone doing something
> like this?  Can you share some experiences?
> 
> -
> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
> For additional commands, e-mail: user-h...@struts.apache.org

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



Re: Injecting Static/Mock Resources into my Struts 2 Actions

2012-08-22 Thread Dave Newton
I do this all the time.

Not sure what experiences you're looking for; if the data is _very_ complex
it may be easier to just embed a DB and load it up with DBUnit or something
like that.

I've also used builders to load up data structures for more-complex data,
stuck that data into a map with an ID key, and use those as test/demo DAOs.
It also makes it easy to push a button in the app to restore values if you
need to show something again etc.

Basically any tutorial that talks about testing in Spring is applicable,
the only difference is the MVC layer.

Dave

On Wed, Aug 22, 2012 at 3:33 PM, Davis, Chad  wrote:

> I would like to deploy my app to a UI testing / demo environment.  In this
> environment, the regular business logic objects would be replaced ( via DI
> ) with mock implementations of those resources.  These mocks would return a
> static data set, thus giving a predictable behavior against which we can
> build automated UI tests, provide a lightweight demo environment that
> doesn't need integrated into our rather large and complex real world data
> context, etc.
>
> My thoughts are to use the Spring integration to inject the mocks.  I'm
> new to doing DI / testing in this kind of setting.  Is anyone doing
> something like this?  Can you share some experiences?
>
> -
> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
> For additional commands, e-mail: user-h...@struts.apache.org
>
>


-- 
e: davelnew...@gmail.com
m: 908-380-8699
s: davelnewton_skype
t: @dave_newton 
b: Bucky Bits 


Injecting Static/Mock Resources into my Struts 2 Actions

2012-08-22 Thread Davis, Chad
I would like to deploy my app to a UI testing / demo environment.  In this 
environment, the regular business logic objects would be replaced ( via DI ) 
with mock implementations of those resources.  These mocks would return a 
static data set, thus giving a predictable behavior against which we can build 
automated UI tests, provide a lightweight demo environment that doesn't need 
integrated into our rather large and complex real world data context, etc.  

My thoughts are to use the Spring integration to inject the mocks.  I'm new to 
doing DI / testing in this kind of setting.  Is anyone doing something like 
this?  Can you share some experiences?

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