Huijun Yang wrote:
> Damian,
> 
> Thanks for the comment on  XCF-2763.
> 
> For unit testing, I was trying to create mock SipxServiceManage so that
> it returns SipxRegistrarService. Part of the change is to loadSettings
> to SipxRegistrarService. The following is the code segment in
> PhoneTestDriver::PhoneTestDriver(Phone _phone, List<User> users, boolean
> phonebookManagementEnabled):
> 
>          SipxRegistrarService registrarService = new
> SipxRegistrarService();
>  
> registrarService.setSettings(TestHelper.loadSettings("/sipxregistrar/sip
> xregistrar.xml"));
> 
>         final SipxServiceManager sipxServiceManager =
> EasyMock.createMock(SipxServiceManager.class);
> 
>  
> sipxServiceManager.getServiceByBeanId(SipxRegistrarService.BEAN_ID);
>  
> EasyMock.expectLastCall().andReturn(registrarService).anyTimes();
> 
>         EasyMock.replay(sipxServiceManager);
>  
> m_phoneContext.getPhoneDefaults().setSipxServiceManager(sipxServiceManag
> er);
> 
> 
> 
> However, unit tests for phone plugins failed because the path of
> sipxregistrar.xml is not correct for plugins. For example, aastra is
> expecting:
> /home/huijun/Xecs/main/sipXconfig/plugins/aastra/etc/sipxregistrar/sipxr
> egistrar.xml
> 
> Any suggestion on this?
> 
> Thanks
> Huijun


That's how you can do that:

        SipxRegistrarService registrarService = new SipxRegistrarService();
        registrarService.setModelName("sipxregistrar.xml");
        registrarService.setModelDir("sipxregistrar");
        
registrarService.setModelFilesContext(TestHelper.getModelFilesContext());

        SipxServiceManager sipxServiceManager = 
EasyMock.createNiceMock(SipxServiceManager.class);
        sipxServiceManager.getServiceByBeanId(SipxRegistrarService.BEAN_ID);
        EasyMock.expectLastCall().andReturn(registrarService);
        EasyMock.replay(sipxServiceManager);
        defaults.setSipxServiceManager(sipxServiceManager);


In general case TestHelper contains a lot of methods that hide environment 
differences and set up things for you so that your test code does not have to 
be very complicated.

I noticed that you submitted a patch that just bypasses retrieving directed 
call pickup if SipxServiceManager is not set.
I'd rather not do that. After the closer the test is to the real time scenario 
the better.
So just fixed and committed your initial patch instead:

Please review:

http://sipxecs.sipfoundry.org/ViewVC/sipXecs?view=rev&rev=13328
http://sipxecs.sipfoundry.org/ViewVC/sipXecs?view=rev&rev=13329


Damian

_______________________________________________
sipx-dev mailing list
[email protected]
List Archive: http://list.sipfoundry.org/archive/sipx-dev
Unsubscribe: http://list.sipfoundry.org/mailman/listinfo/sipx-dev

Reply via email to