[flexcoders] Re: Simulating Flex Client requests using Java?

2008-02-15 Thread Anthony DeBonis
Yes it supports Async calls using addAsync

Here is a snip

beerDataService.addEventListener(ResultEvent.RESULT, addAsync(result, 
3000));
beerDataService.send();



[flexcoders] Re: Simulating Flex Client requests using Java?

2008-02-15 Thread aduston1976
Yes it does. But using flex unit for a purpose like this cannot really
be properly called a "unit test" but rather an "integration test". I
typically find that the cost-to-benefit ratio of testing -- which can
become arbitrarily high -- is lower when I am testing my java code and
my as3 code separately.

--- In flexcoders@yahoogroups.com, "Marvin Froeder" <[EMAIL PROTECTED]> wrote:
>
> Does flexunit support as3flexunitlib asynchronous call?
> 
> VELO
> 
> On Fri, Jan 4, 2008 at 2:23 PM, Jeffry Houser <[EMAIL PROTECTED]> wrote:
> 
> >
> > I'm speaking a bit "off the cuff" here, but...
> >
> > Would it make sense to look into FlexUnit (
> > http://code.google.com/p/as3flexunitlib/ ) for these type of things?
> >
> >
> > Robert Csiki wrote:
> > >
> > >
> > > Hello,
> > >
> > > For server-side testing purposes (e.g. testing custom LCDS
> > > Assemblers, remote service destinations etc) using the JUnit testing
> > > framework, I need to somehow simulate Flex Client requests to LCDS,
> > > programatically, through Java code (the test cases). Is that
possible,
> > > if so, *how* please? Basically I need to have access to LCDS's
> > > FlexSession, FlexClient objects (Java objects) without having to
use the
> >
> > > Flex Client / browser to generate requests to LCDS.
> > >
> > > Thanks.
> >
> > --
> > Jeffry Houser, Technical Entrepreneur, Software Developer, Author,
> > Recording Engineer
> > AIM: Reboog711 | Phone: 1-203-379-0773
> > --
> > My Company: 
> > My Podcast: 
> > My Blog: 
> >
> >  
> >
>




[flexcoders] Re: Simulating Flex Client requests using Java?

2008-02-14 Thread aduston1976
Hi Robert, I came across your posts while searching the lists for a
solution to the FlexSession problem I recently posted. I think I'm a
bit late, but will post this anyway in case it helps. When we are
testing with external dependencies, we stub or mock them out. Why
don't you do that? On a daily basis I imitate a flex client in junit
tests on my service layer. Here is how I do it. 

1. Define a class called UserPrincipal that inherits from
java.security.Principal and contains whatever identifying information
you have for principals. For example, mine has an id and a name.
2. Define an interface that your services can use to set and get the
principal, e.g.:

public interface PrincipalManager {
void setSessionUser(UserPrincipal u);
UserPrincipal getSessionUser();
}
3. I use Spring to give my service layer classes a concrete
PrincipalManager instance, but really you can do it however you want,
so long as the services aren't coupled to the concrete type. For
example, you can use an abstract factory.
4. Your login service method will call
principalManager.setSessionUser(loggedInUser). Now, during subsequent
RPC calls, service methods can access
principalManager.getSessionUser() to obtain user identity.
5. For non-testing, define a PrincipalManager concrete class that
looks like this:
public class LCDSPrincipalManager implements PrincipalManager {
public UserPrincipal getSessionUser() {
// FIXME: see
http://tech.groups.yahoo.com/group/flexcoders/message/102380
for (Object o : FlexContext.getFlexClient().getFlexSessions()) {
FlexSession fs = (FlexSession)o;
if (fs.getUserPrincipal() != null)
return (UserPrincipal)fs.getUserPrincipal();
}
return null;
}
public void setSessionUser(UserPrincipal u) {
FlexContext.setUserPrincipal(u);
}
}
As soon as my post is answered, you can replace the "FIXME" part :) .
Or, if you are not using modules, just change that method body to
"return FlexContext.getUserPrincipal()".

6. For testing, use a stub that looks like this:
public class FakePrincipalManager implements PrincipalManager {
private UserPrincipal sessionUser;

public UserPrincipal getSessionUser() {
return sessionUser;
}
public void setSessionUser(UserPrincipal u) {
sessionUser = u;
}
}

Now, at the beginning of your test method, call setSessionUser with
your fake user info. All "RPC calls" that occur in your test after
that will use the fake user. To imitate interactions between different
users, you can call setSessionUser with different fake users.

Adam


--- In flexcoders@yahoogroups.com, "Robert Csiki" <[EMAIL PROTECTED]> wrote:
>
> 
> 
> You are right in your way ... I was trying to analyze how well the
> testing of the server code covered (using a Java code coverage tool -
> like "Clover" - which works together with JUnit). If I'm using FlexUnit,
> I'm testing the client (Actionscript) code, not the server (Java) one.
> Of course I can test the service layer hit, but that is still part of
> the client code test suite. What I want is to initiate the test from
> Java side, to get the Java code coverage reports.
> 
> Robert
> 
> --- In flexcoders@yahoogroups.com, Jeffry Houser  wrote:
> >
> >
> > I'm still speaking for a stance of borderline ignorance here...
> >
> > I don't think I understand why you want to simulate a Flex call from
> > Java + JUnit instead of making an real Flex call, triggered by
> FlexUnit.
> >
> > Instead of trying to simulate a Flex call from the server side,
> > wouldn't you want to trigger the remote call from the Client? ( I
> > assumed using FlexUnit ). In theory, you use JUnit to test your Java
> > Objects, but can use FlexUnit to test hit the "service" layer. Am I
> > greatly oversimplifying things? Or just completely wrong?
> >
> >
> >
> >
> > Robert Csiki wrote:
> > >
> > >
> > > Thanks for your reply Jeffry, yes, we're using FlexUnit too, for
> testing
> > > the client code. FlexUnit is some kind of JUnit but for Flex code
> > > (Actionscript). I was talking about server side testing. What I want
> is
> > > my Java JUnit test case code to somehow act as a Flex client
> simulator
> > > and generate requests to Adobe LCDS Server, then interpret the
> server
> > > response etc.
> > >
> > > Cheers, Robert
> > >
> > >
> > > --- In flexcoders@yahoogroups.com, Jeffry Houser jeff@ wrote:
> > > >
> > > >
> > > > I'm speaking a bit "off the cuff" here, but...
> > > >
> > > > Would it make sense to look into FlexUnit (
> > > > http://code.google.com/p/as3flexunitlib/ ) for these type of
> things?
> > > >
> > > > Robert Csiki wrote:
> > > > >
> > > > >
> > > > > Hello,
> > > > >
> > > > > For server-side testing purposes (e.g. testing custom LCDS
> > > > > Assemblers, remote service destinations etc) using the JUnit
>

[flexcoders] Re: Simulating Flex Client requests using Java?

2008-01-04 Thread Robert Csiki


You are right in your way ... I was trying to analyze how well the
testing of the server code covered (using a Java code coverage tool -
like "Clover" - which works together with JUnit). If I'm using FlexUnit,
I'm testing the client (Actionscript) code, not the server (Java) one.
Of course I can test the service layer hit, but that is still part of
the client code test suite. What I want is to initiate the test from
Java side, to get the Java code coverage reports.

Robert

--- In flexcoders@yahoogroups.com, Jeffry Houser <[EMAIL PROTECTED]> wrote:
>
>
> I'm still speaking for a stance of borderline ignorance here...
>
> I don't think I understand why you want to simulate a Flex call from
> Java + JUnit instead of making an real Flex call, triggered by
FlexUnit.
>
> Instead of trying to simulate a Flex call from the server side,
> wouldn't you want to trigger the remote call from the Client? ( I
> assumed using FlexUnit ). In theory, you use JUnit to test your Java
> Objects, but can use FlexUnit to test hit the "service" layer. Am I
> greatly oversimplifying things? Or just completely wrong?
>
>
>
>
> Robert Csiki wrote:
> >
> >
> > Thanks for your reply Jeffry, yes, we're using FlexUnit too, for
testing
> > the client code. FlexUnit is some kind of JUnit but for Flex code
> > (Actionscript). I was talking about server side testing. What I want
is
> > my Java JUnit test case code to somehow act as a Flex client
simulator
> > and generate requests to Adobe LCDS Server, then interpret the
server
> > response etc.
> >
> > Cheers, Robert
> >
> >
> > --- In flexcoders@yahoogroups.com, Jeffry Houser jeff@ wrote:
> > >
> > >
> > > I'm speaking a bit "off the cuff" here, but...
> > >
> > > Would it make sense to look into FlexUnit (
> > > http://code.google.com/p/as3flexunitlib/ ) for these type of
things?
> > >
> > > Robert Csiki wrote:
> > > >
> > > >
> > > > Hello,
> > > >
> > > > For server-side testing purposes (e.g. testing custom LCDS
> > > > Assemblers, remote service destinations etc) using the JUnit
testing
> > > > framework, I need to somehow simulate Flex Client requests to
LCDS,
> > > > programatically, through Java code (the test cases). Is that
possible,
> > > > if so, *how* please? Basically I need to have access to LCDS's
> > > > FlexSession, FlexClient objects (Java objects) without having to
> > use the
> > > > Flex Client / browser to generate requests to LCDS.
> > > >
> > > > Thanks.
>
> --
> Jeffry Houser, Technical Entrepreneur, Software Developer, Author,
> Recording Engineer
> AIM: Reboog711 | Phone: 1-203-379-0773
> --
> My Company: 
> My Podcast: 
> My Blog: 
>




Re: [flexcoders] Re: Simulating Flex Client requests using Java?

2008-01-04 Thread Jeffry Houser

  I'm still speaking for a stance of borderline ignorance here...

  I don't think I understand why you want to simulate a Flex call from 
Java + JUnit instead of making an real Flex call, triggered by FlexUnit.

  Instead of trying to simulate a Flex call from the server side, 
wouldn't you want to trigger the remote call from the Client?  ( I 
assumed using FlexUnit ).  In theory, you use JUnit to test your Java 
Objects, but can use FlexUnit to test hit the "service" layer.  Am I 
greatly oversimplifying things?  Or just completely wrong?




Robert Csiki wrote:
> 
> 
> Thanks for your reply Jeffry, yes, we're using FlexUnit too, for testing 
> the client code. FlexUnit is some kind of JUnit but for Flex code 
> (Actionscript). I was talking about server side testing. What I want is 
> my Java JUnit test case code to somehow act as a Flex client simulator 
> and generate requests to Adobe LCDS Server, then interpret the server 
> response etc.
> 
> Cheers, Robert
> 
> 
> --- In flexcoders@yahoogroups.com, Jeffry Houser <[EMAIL PROTECTED]> wrote:
>  >
>  >
>  > I'm speaking a bit "off the cuff" here, but...
>  >
>  > Would it make sense to look into FlexUnit (
>  > http://code.google.com/p/as3flexunitlib/ ) for these type of things?
>  >
>  > Robert Csiki wrote:
>  > >
>  > >
>  > > Hello,
>  > >
>  > > For server-side testing purposes (e.g. testing custom LCDS
>  > > Assemblers, remote service destinations etc) using the JUnit testing
>  > > framework, I need to somehow simulate Flex Client requests to LCDS,
>  > > programatically, through Java code (the test cases). Is that possible,
>  > > if so, *how* please? Basically I need to have access to LCDS's
>  > > FlexSession, FlexClient objects (Java objects) without having to 
> use the
>  > > Flex Client / browser to generate requests to LCDS.
>  > >
>  > > Thanks.

-- 
Jeffry Houser, Technical Entrepreneur, Software Developer, Author, 
Recording Engineer
AIM: Reboog711  | Phone: 1-203-379-0773
--
My Company: 
My Podcast: 
My Blog: 



[flexcoders] Re: Simulating Flex Client requests using Java?

2008-01-04 Thread Robert Csiki

Thanks for your reply Jeffry, yes, we're using FlexUnit too, for testing
the client code. FlexUnit is some kind of JUnit but for Flex code
(Actionscript). I was talking about server side testing. What I want is
my Java JUnit test case code to somehow act as a Flex client simulator
and generate requests to Adobe LCDS Server, then interpret the server
response etc.

Cheers, Robert


--- In flexcoders@yahoogroups.com, Jeffry Houser <[EMAIL PROTECTED]> wrote:
>
>
> I'm speaking a bit "off the cuff" here, but...
>
> Would it make sense to look into FlexUnit (
> http://code.google.com/p/as3flexunitlib/ ) for these type of things?
>
> Robert Csiki wrote:
> >
> >
> > Hello,
> >
> > For server-side testing purposes (e.g. testing custom LCDS
> > Assemblers, remote service destinations etc) using the JUnit testing
> > framework, I need to somehow simulate Flex Client requests to LCDS,
> > programatically, through Java code (the test cases). Is that
possible,
> > if so, *how* please? Basically I need to have access to LCDS's
> > FlexSession, FlexClient objects (Java objects) without having to use
the
> > Flex Client / browser to generate requests to LCDS.
> >
> > Thanks.
>
> --
> Jeffry Houser, Technical Entrepreneur, Software Developer, Author,
> Recording Engineer
> AIM: Reboog711 | Phone: 1-203-379-0773
> --
> My Company: 
> My Podcast: 
> My Blog: 
>