I was trying with mocks.

-----Original Message-----
From: Chiradeep Vittal [mailto:chiradeep.vit...@citrix.com]
Sent: Tuesday, October 30, 2012 12:04 AM
To: CloudStack DeveloperList; Alex Huang
Subject: Re: need help for test cases of api/commands

Are you writing mocks, or are you planning to use a framework like
Mockito?

On 10/29/12 11:29 AM, "Meghna Kale" <meghna.k...@sungard.com> wrote:

>Alex,
>
>A method from ActivateProjectCmd.java, the projectService call.
>
>     @Override
>
>    public long getEntityOwnerId() {
>
>        Project project= _projectService.getProject(id);
>
>        //verify input parameters
>
>        if (project == null) {
>
>                     throw new InvalidParameterValueException("Unable
>to find project by id " + id);
>
>        }
>
>       return _projectService.getProjectOwner(id).getId();
>
>    }
>
>
>
> I created a mock class of the service
>
>
>
>@Local(value = { ProjectService.*class* })
>
>*public* *class* MockProjectServiceImpl *implements* ProjectService,
>Manager{
>
>    public static final Logger s_logger =
>Logger.getLogger(MockProjectServiceImpl.class);
>
>
>
>       @Override
>
>       *public* *boolean* deleteProject(*long* id) {
>
>              // *TODO* Auto-generated method stub
>
>              *return* *false*;
>
>       }
>
>
>
>       @Override
>
>       *public* Project getProject(*long* id) {
>
>              // *TODO* Auto-generated method stub
>
>
>
>         // We Cannot mock the Project object as it an interface and
>return from this method.
>
>              *return* *null*;
>
>       }
>
>ŠŠŠŠ..
>
>
>
>}
>
>
>
>--   -  Meghna.
>
>
>
>
>On Mon, Oct 29, 2012 at 11:42 PM, Alex Huang <alex.hu...@citrix.com>
>wrote:
>
>> Meghna,
>>
>> Can you give an example of which call you're talking about and point
>> out the specific line of code you're having problem with?
>>
>> Thanks.
>>
>> --Alex
>>
>> > -----Original Message-----
>> > From: Meghna Kale [mailto:meghna.k...@sungard.com]
>> > Sent: Monday, October 29, 2012 9:51 AM
>> > To: cloudstack-dev@incubator.apache.org
>> > Subject: need help for test cases of api/commands
>> >
>> > Hi All,
>> >
>> >
>> >
>> > I was writing some test cases for the API layer
>> > api\src\com\cloud\api\commands.
>> >
>> > I facing some issue can someone help me.
>> >
>> >
>> >
>> > There are some service layer calls in the classes , I tried to mock
>>the
>> service
>> > layer.
>> >
>> > The Service layer internally calls the DAO, rather than calling the
>>mock
>> DAO I
>> > was thinking  of returning the object from the service layer.
>> >
>> > But as the return value of the DAO is an interface in the service
>>layer
>> I'm not
>> > able to mock the object and pass it on to the API layer.
>> >
>> >
>> >
>> > Is any other way or I will have to mock the DAO layer also ?
>> >
>> >
>> >
>> > -          Meghna.
>>
>>

Reply via email to