<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Apr 18, 2016 at 12:10 PM, Roman Mohr <span dir="ltr"><<a href="mailto:rmohr@redhat.com" target="_blank">rmohr@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span class="">On Sun, Apr 17, 2016 at 9:49 PM, Martin Mucha <span dir="ltr"><<a href="mailto:mmucha@redhat.com" target="_blank">mmucha@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Having such builders would simplify our lives for sure. But I'd really try to avoid any autogeneration. I would cost lots of man hours to make it happen and result won't be good. If we agree to use this approach, and everyone write new methods as they're needed, 'some basic builders' come to life very easy and fast.</blockquote><div><br></div></span><div>That's what I had in mind and I have pretty good experience with that pattern from previous projects. I am also against autogeneration for the mentioned reasons in that case. If you are on a greenfield project, Lombok has a nice @Builder [1] in general but it does also not fit very well here.<br> </div><div><div class="h5"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> Also some places already has such similar builders — like org.ovirt.engine.core.bll.network.host.HostSetupNetworksValidatorTest.HostSetupNetworksValidatorBuilder.<br>
<span><font color="#888888"><br>
M.<br>
</font></span><div><div><br>
----- Original Message -----<br>
> Hi Roman,<br>
><br>
> I really like the idea behind domain object builders.<br>
><br>
> Maybe a silly question, but how much effort would it take<br>
> to autogenerate some "basic" builders from domain objects?<br>
> (without DAO/Integration test related stuff like prePersist<br>
> override etc.)<br>
><br>
> From the "basic" builders we could derive DAO/Integration<br>
> ones as subclasses. This way, the domain object specific<br>
> stuff wouldn't have to be kept in sync by hand, and we can<br>
> subclass only if we need to make a builder DAO/Integration<br>
> test aware.<br>
><br>
> Vojtech<br>
><br>
><br>
> ----- Original Message -----<br>
> > From: "Roman Mohr" <<a href="mailto:rmohr@redhat.com" target="_blank">rmohr@redhat.com</a>><br>
> > To: "Eyal Edri" <<a href="mailto:eedri@redhat.com" target="_blank">eedri@redhat.com</a>><br>
> > Cc: "Juan Antonio Hernandez Fernandez" <<a href="mailto:jhernand@redhat.com" target="_blank">jhernand@redhat.com</a>>, "devel"<br>
> > <<a href="mailto:devel@ovirt.org" target="_blank">devel@ovirt.org</a>><br>
> > Sent: Thursday, April 14, 2016 1:05:25 PM<br>
> > Subject: Re: [ovirt-devel] Integration tests future (and very nice<br>
> > alternative for the DAO fixture file)<br>
> ><br>
> ><br>
> ><br>
> > On Thu, Apr 14, 2016 at 12:32 PM, Eyal Edri < <a href="mailto:eedri@redhat.com" target="_blank">eedri@redhat.com</a> > wrote:<br>
> ><br>
> ><br>
> ><br>
> > Will that replace the current DAO tests running in CI?<br>
> ><br>
> ><br>
> > For now no. What you can do with the builders reagarding to the DAO tests<br>
> > is<br>
> > creating test scenarios for the database. So instead of adding entities to<br>
> > the fixture file you can set up clean sceanrios for your tests just with<br>
> > the<br>
> > builders in @Test or @Before methods.<br>
> ><br>
> > Integration tests are using Arqullian with the spring transaction manager<br>
> > and<br>
> > will probably an extra CI job which passes the right maven flags.<br>
> > Arquillian<br>
> > is nice here because we are much closer to a real JBoss than with Spring.<br>
> ><br>
> > The reason why we do not use Arquillian and only the builders for the DAO<br>
> > test is that you would need a full JBoss downloaded in the background to<br>
> > give us a transaction manager which does the same thing as springs<br>
> > transaction manager does during the build.<br>
> ><br>
> > The JBoss people are currently working on modularizing all their JBoss<br>
> > libraries (for JBoss Swarm) and I hope that in the future we can drop the<br>
> > spring transaction manager and do everything with arquillian and the JBoss<br>
> > transaction manager.<br>
> ><br>
> ><br>
> ><br>
> > On Wed, Apr 13, 2016 at 4:22 PM, Roman Mohr < <a href="mailto:rmohr@redhat.com" target="_blank">rmohr@redhat.com</a> > wrote:<br>
> ><br>
> ><br>
> ><br>
> > Hi all,<br>
> ><br>
> > In [1] you can find some patches which are meant to improve the test<br>
> > writing<br>
> > experience in ovirt-engine.<br>
> ><br>
> > They provide the following things:<br>
> ><br>
> > A) Domain Object builders which can be used for creating and/or persisting<br>
> > domain objects [2]<br>
> > B) DAO testing without writing fixtures because of the builders<br>
> > C) Integration testing for commands in conjunction with a real database<br>
> > Arquillian, injectable commands and the builders [3]<br>
> ><br>
> > # How to run what?<br>
> ><br>
> > A) In normal unit tests just create a new instance of a builder and use it.<br>
> > This should help us to get rid of all the small createDefaultVm(),<br>
> > createHostWithX() helper methods in our tests.<br>
> ><br>
> > B) In dao tests just inject them and go ahead. The advantage of not using<br>
> > the<br>
> > fixture file is that we can now set up clean scenarios for every test in a<br>
> > setup method. See example 2 below on how easy it is to set up a new<br>
> > cluster.<br>
> ><br>
> > C) Arquillian integration tests need to be marked with<br>
> > "@Category(IntegrationTest.class)" and can inherit from<br>
> > TransactionalTestBase. The @Category annotation makes sure that the<br>
> > integration tests are only run when<br>
> ><br>
> > mvn clean verify -DskipITs=false<br>
> ><br>
> > is invoked. Note that these tests are then executed in the integration test<br>
> > phase of maven. For them we use the maven-failsafe-plugin[5] which will<br>
> > also<br>
> > make sure that the testing database is up to date. See [4] for more<br>
> > details.<br>
> ><br>
> > # Examples<br>
> ><br>
> > 1) Add a running VM to a host, persist everything to the database and load<br>
> > all VMs which are running on the host:<br>
> ><br>
> > VDS host = vdsBuilder.cluster(persistedCluster).persist();<br>
> > vmBuilder.host(host).up().persist();<br>
> > List<VM> vms = vmDao.getAllRunningForVds(host.getId());<br>
> ><br>
> > 2) Add 10 hosts with 1 GB of RAM to a cluster, persist the hosts to the<br>
> > database in a DAO test:<br>
> ><br>
> > public class MyHostDaoTest extends BaseDaoTestCase {<br>
> ><br>
> > @Inject<br>
> > private VdsBuilder vdsBuilder;<br>
> ><br>
> > @Test<br>
> > public void createHosts() {<br>
> > VdsBuilder builder =<br>
> > vdsBuilder.cluster(persistedCluster).physicalMemory(1000);<br>
> > for (int x =0; x < 10; x++){<br>
> > <a href="http://builder.id" rel="noreferrer" target="_blank">builder.id</a> (Guid.newGuid()).persist();<br>
> > }<br>
> > }<br>
> > }<br>
> ><br>
> > 3) Full integration test with arquillian and the database<br>
> ><br>
> > @Category(IntegrationTest.class)<br>
> > public class VmDaoIntegrationTest extends TransactionalTestBase {<br>
> ><br>
> > @Inject<br>
> > VmDao vmDao;<br>
> ><br>
> > private final Guid VM1_GUID =<br>
> > Guid.createGuidFromString("0fe4bc81-5999-4ab6-80f8-7a4a2d4bfacd");<br>
> ><br>
> > @Deployment<br>
> > public static JavaArchive deploy(){<br>
> > return createDeployment();<br>
> > }<br>
> ><br>
> > @Test<br>
> > public void shouldFailOnExistingEntity() {<br>
> > vmBuilder.id(VM1_GUID).cluster(clusterBuilder.reset().persist()).persist();<br>
> > // This uses assertThat from assertj:<br>
> > assertThat(vmDao.get(VM1_GUID)).isNotNull();<br>
> > }<br>
> > }<br>
> ><br>
> > 4) Using the builders in a normal unit test without a database:<br>
> ><br>
> > VM vm = new VmBuilder().id(Guid.newGuid()).up().build();<br>
> ><br>
> ><br>
> > # How to add your own Domain objects?<br>
> ><br>
> > There are just a few simple rules:<br>
> ><br>
> > 1) Your builder should extend org.ovirt.engine.core.builder.AbstractBuilder<br>
> ><br>
> > 2) Make sure that you only access DAOs injected into the builder during<br>
> > #prePersist() and #persist(). This allows to use the #build() method also<br>
> > without injections<br>
> ><br>
> > 3) #prePersist() should set all fields which are necessary to suffice<br>
> > database constraints. The fields should only be set if they are not already<br>
> > set before by the builder. When following this rule we can always persist<br>
> > new objects to the database by simply calling myBuilder.reset().persist().<br>
> ><br></div></div></blockquote></div></div></div></div></div></blockquote><div><br></div><div>What I absolutely all in for this method is how elegant and easy is to create a dao test with it. Everything you need in the test class and quickly. Its a a big improvement cause its simple and readable and also nice to read and work with.<br>+1 <br><br></div><div>Auto-generating is a bit off-topic I prefer if we concentrate first on this effort.<br><br></div><div>Roy<br></div><div> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div class="h5"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div>
> > 4) Mark your builder with @Repository to make them useable for our Spring<br>
> > DAO<br>
> > tests and our Arquillian integration tests.<br>
> ><br>
> > So have a look at the patches at [1] and let me know what you think about<br>
> > them.<br>
> ><br>
> > Best Regards and happy testing,<br>
> ><br>
> > Roman<br>
> ><br>
> > [1] <a href="https://gerrit.ovirt.org/#/q/topic:integration" rel="noreferrer" target="_blank">https://gerrit.ovirt.org/#/q/topic:integration</a><br>
> > [2] <a href="https://gerrit.ovirt.org/#/c/47008/17" rel="noreferrer" target="_blank">https://gerrit.ovirt.org/#/c/47008/17</a><br>
> > [3] <a href="https://gerrit.ovirt.org/#/c/47007/10" rel="noreferrer" target="_blank">https://gerrit.ovirt.org/#/c/47007/10</a><br>
> > [4] <a href="https://gerrit.ovirt.org/#/c/47008/17" rel="noreferrer" target="_blank">https://gerrit.ovirt.org/#/c/47008/17</a><br>
> > [5] <a href="https://maven.apache.org/surefire/maven-failsafe-plugin/" rel="noreferrer" target="_blank">https://maven.apache.org/surefire/maven-failsafe-plugin/</a><br>
> ><br>
> > _______________________________________________<br>
> > Devel mailing list<br>
> > <a href="mailto:Devel@ovirt.org" target="_blank">Devel@ovirt.org</a><br>
> > <a href="http://lists.ovirt.org/mailman/listinfo/devel" rel="noreferrer" target="_blank">http://lists.ovirt.org/mailman/listinfo/devel</a><br>
> ><br>
> ><br>
> ><br>
> > --<br>
> > Eyal Edri<br>
> > Associate Manager<br>
> > RHEV DevOps<br>
> > EMEA ENG Virtualization R&D<br>
> > Red Hat Israel<br>
> ><br>
> > phone: <a href="tel:%2B972-9-7692018" value="+97297692018" target="_blank">+972-9-7692018</a><br>
> > irc: eedri (on #tlv #rhev-dev #rhev-integ)<br>
> ><br>
> ><br>
> > _______________________________________________<br>
> > Devel mailing list<br>
> > <a href="mailto:Devel@ovirt.org" target="_blank">Devel@ovirt.org</a><br>
> > <a href="http://lists.ovirt.org/mailman/listinfo/devel" rel="noreferrer" target="_blank">http://lists.ovirt.org/mailman/listinfo/devel</a><br>
> _______________________________________________<br>
> Devel mailing list<br>
> <a href="mailto:Devel@ovirt.org" target="_blank">Devel@ovirt.org</a><br>
> <a href="http://lists.ovirt.org/mailman/listinfo/devel" rel="noreferrer" target="_blank">http://lists.ovirt.org/mailman/listinfo/devel</a><br>
><br>
</div></div></blockquote></div></div></div><br>[6] <a href="https://projectlombok.org/features/Builder.html" target="_blank">https://projectlombok.org/features/Builder.html</a><br></div></div>
<br>_______________________________________________<br>
Devel mailing list<br>
<a href="mailto:Devel@ovirt.org">Devel@ovirt.org</a><br>
<a href="http://lists.ovirt.org/mailman/listinfo/devel" rel="noreferrer" target="_blank">http://lists.ovirt.org/mailman/listinfo/devel</a><br></blockquote></div><br></div></div>