Return-Path: X-Original-To: apmail-incubator-cloudstack-dev-archive@minotaur.apache.org Delivered-To: apmail-incubator-cloudstack-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C4951D74A for ; Sat, 26 Jan 2013 01:32:11 +0000 (UTC) Received: (qmail 26742 invoked by uid 500); 26 Jan 2013 01:32:11 -0000 Delivered-To: apmail-incubator-cloudstack-dev-archive@incubator.apache.org Received: (qmail 26695 invoked by uid 500); 26 Jan 2013 01:32:11 -0000 Mailing-List: contact cloudstack-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: cloudstack-dev@incubator.apache.org Delivered-To: mailing list cloudstack-dev@incubator.apache.org Received: (qmail 26683 invoked by uid 99); 26 Jan 2013 01:32:11 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 26 Jan 2013 01:32:11 +0000 X-ASF-Spam-Status: No, hits=-5.0 required=5.0 tests=RCVD_IN_DNSWL_HI,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of Alex.Huang@citrix.com designates 66.165.176.89 as permitted sender) Received: from [66.165.176.89] (HELO SMTP.CITRIX.COM) (66.165.176.89) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 26 Jan 2013 01:32:06 +0000 X-IronPort-AV: E=Sophos;i="4.84,542,1355097600"; d="scan'208";a="5173430" Received: from sjcpmailmx02.citrite.net ([10.216.14.75]) by FTLPIPO01.CITRIX.COM with ESMTP/TLS/RC4-MD5; 26 Jan 2013 01:31:44 +0000 Received: from SJCPMAILBOX01.citrite.net ([10.216.4.73]) by SJCPMAILMX02.citrite.net ([10.216.14.75]) with mapi; Fri, 25 Jan 2013 17:31:44 -0800 From: Alex Huang To: "cloudstack-dev@incubator.apache.org" Date: Fri, 25 Jan 2013 17:31:46 -0800 Subject: RE: Writing unit tests after javelin is merged in. Thread-Topic: Writing unit tests after javelin is merged in. Thread-Index: Ac36kTvpQUE7885ERye/7xKAb4edcAACfrmAACN1DFAADO3VoAABEF5gAADlPbA= Message-ID: References: <9C78603E253E334CA9FD181550B021D601701220@adcexmbx02.tw.trendnet.org> <93099572B72EB341B81A644E134F240B012F747FE602@SJCPMAILBOX01.citrite.net> <93099572B72EB341B81A644E134F240B012F747FE603@SJCPMAILBOX01.citrite.net> In-Reply-To: <93099572B72EB341B81A644E134F240B012F747FE603@SJCPMAILBOX01.citrite.net> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US Content-Type: text/plain; charset="iso-2022-jp" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Virus-Checked: Checked by ClamAV on apache.org Frank, Great! Two questions. - How does it work when the unit test itself needs a component injected? S= etup() is only called before the test but not before the unit test is initi= alized. - What about the aop extras that Kelven has added in the xml file? I don't= see them specified in the setup() method. How does that get loaded? Thanks. --Alex =20 > -----Original Message----- > From: Frank Zhang [mailto:Frank.Zhang@citrix.com] > Sent: Friday, January 25, 2013 5:06 PM > To: cloudstack-dev@incubator.apache.org > Subject: RE: Writing unit tests after javelin is merged in. >=20 > I think the former mail is too verbose. Let me summarize: >=20 > For a unit test case, all necessary to do is: >=20 > @Before > public void setup() throws Exception { > ComponentContext.setComponentsToLoad(Class[] > { SecurityGroupRulesDaoImpl.class, > UserVmDaoImpl.class, > AccountDaoImpl.class,}); >=20 > ComponentContext. initComponentsLifeCycle(); > } >=20 > To achieve this. Dynamically generate spring xml configure file including > beans specified in setComponentsToLoad(), use the generated file to creat= e > Spring ApplicationContext. >=20 >=20 >=20 > > -----Original Message----- > > From: Frank Zhang [mailto:Frank.Zhang@citrix.com] > > Sent: Friday, January 25, 2013 4:59 PM > > To: cloudstack-dev@incubator.apache.org > > Subject: RE: Writing unit tests after javelin is merged in. > > > > Alex, I feel the wiki you post is too complex to write a unit case. > > If I understand correctly, the whole purpose about configuration.xml an= d > > "test configuration" class is to load components needed by unit test ca= se. > > From a programmer's perspective, all things I think are necessary to do= is > like > > below: > > > > @Before > > public void setup() throws Exception { > > ComponentContext.setComponentsToLoad(Class[] > > { SecurityGroupRulesDaoImpl.class, > > UserVmDaoImpl.class, > > AccountDaoImpl.class,}); > > ComponentContext. initComponentsLifeCycle(); } > > > > For these mock component, test case itself should know where to get it, > for > > example, by calling Mockito.mock(). > > > > To achieve this, ComponentContext needs below enhancements: > > 1. add method setComponentsToLoad() that receives a list of Class of > > components 2. save configuration.xml to a well-know place in classpath= . > The > > content of configuration.xml is 99% the same as you post, except removi= ng: > > > > > class=3D"[Test Configuration]" /> > > > > then the file works as a template for Spring beans. > > > > 3. ComponentContext generates a new xml file from configuration.xml > > template when initComponentsLifeCycle() gets called, the new xml file > > would contain all bean declarations for classes specified in > > setComponentsToLoad(). as aforementioned example, the new generated > > xml will contain extra 3 items like > > > > > SecurityGroupRulesDaoImpl" /> > class=3D"full_class_name_of_UserVmDaoImpl" /> > AccountDaoImpl " class=3D"full_class_name_of_AccountDaoImpl " /> > > > > 4. save the new xml file generated in step 3 to root class path of unit= test > > case with a new name. For standard maven it is test/target/test-classes= /, > but > > I didn't see this hierarchy in our code base, let's assume the path is > > test/classes/. So the new xml file would be saved as: > > > > test/classes/spring_configuration_for_test_case_xxx.xml > > > > 5. create Spring ApplicationContext using the new generated configurati= on > > file in initComponentsLifeCycle(). > > > > 6. don't use @ContextConfiguration(locations =3D > > "classpath:/[configuration.xml]") as we use dynamic Spring configuratio= n > > > > > > > > > > > > > -----Original Message----- > > > From: Alex Huang [mailto:Alex.Huang@citrix.com] > > > Sent: Friday, January 25, 2013 10:25 AM > > > To: cloudstack-dev@incubator.apache.org > > > Subject: RE: Writing unit tests after javelin is merged in. > > > > > > Hi Howie, > > > > > > Thanks for the offer to help. I believe we finally converted all > > > tests yesterday but turns out the tests are not running because > > > they've been disabled on master branch due to no db access on the bui= ld > > machines. > > > > > > The code is on javelin on asf. You're welcome to peruse and make any > > > suggestions about how we're using spring in the unit tests. Would > > > love to find a way to stop creating 3 different files for every unit = test. > > > > > > Thanks again. > > > > > > --Alex > > > > > > > -----Original Message----- > > > > From: Howie Yu [mailto:howie_yu@trend.com.tw] > > > > Sent: Thursday, January 24, 2013 5:28 PM > > > > To: cloudstack-dev@incubator.apache.org > > > > Subject: Re: Writing unit tests after javelin is merged in. > > > > > > > > Hi Alex > > > > > > > > I would like to help~ > > > > > > > > But which repository should I use? Form github's javelin or asf's j= avelin ? > > > > > > > > > > > > On 13/1/25 =1B$B>e8a=1B(B8:17, "Alex Huang" = wrote: > > > > > > > > >I wrote up a page on how to write unit tests after the Spring > > > > >injection framework is in. Please see here. > > > > > > > > > >https://cwiki.apache.org/confluence/display/CLOUDSTACK/Unit+Testi > n > > g > > > + > > > > with+J > > > > >Unit+and+Spring > > > > > > > > > >We also need help in javelin to finish converting the unit tests > > > > >over to this format. If you can help, let me know. > > > > > > > > > >Thanks. > > > > > > > > > >--Alex > > > > > > > > > > > > > > > > > > > > > >
> > > > TREND MICRO EMAIL NOTICE
> > > > The information contained in this email and any attachments is
> > > > confidential and may be subject to copyright or other intellectual
> > > > property
> > > protection.
> > > > If you are not the intended recipient, you are not authorized to us=
e
> > > > or disclose this information, and we request that you notify us by
> > > > reply mail or telephone and delete the original message from your
> > > > mail
> > > system.
> > > >