JPA and Spring 3

View: New views
9 Messages — Rating Filter:   Alert me  

JPA and Spring 3

by kabilaw_101 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Guys,

I just want to share my tutorial on how to use JPA on Spring 3.

http://javapulutan.blogspot.com/2009/08/maven-2-jpa-and-spring-3-first-attempt.html

thanks!


Re: JPA and Spring 3

by Calen Martin D. Legaspi :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Good for you, Kabaliw_101!  I hope more of us Pinoy developers
contribute to the world's knowledge base rather than just consume.

Calen
Calen Legaspi <http://software.orangeandbronze.com>
<http://software.orangeandbronze.com>


kabilaw_101 wrote:

>  
>
> Hi Guys,
>
> I just want to share my tutorial on how to use JPA on Spring 3.
>
> http://javapulutan.blogspot.com/2009/08/maven-2-jpa-and-spring-3-first-attempt.html 
> <http://javapulutan.blogspot.com/2009/08/maven-2-jpa-and-spring-3-first-attempt.html>
>
> thanks!
>
>

JUnit 4 Rule Annotation

by Arche Type :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

To All;

Does anyone here knows the benefit of JUnit 4 especially the Rule Annotation?

Thanks,

Archetype



     

Re: JUnit 4 Rule Annotation

by franz see :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

JUnit's Rule used to be called an interceptor...and that's basically it
(AFAIK). And according to Kent Beck, it replaces most custom runners (
http://twitter.com/KentBeck/status/2753171192)

As for JUnit 4 in general, I think the major benefit is the readability of
the tests and they do tend to be much cleaner.

Cheers,

--
Franz Allan Valencia See | Java Software Engineer
franz.see@...
LinkedIn: http://www.linkedin.com/in/franzsee

On Wed, Aug 26, 2009 at 12:10 PM, Arche Type <type.arche@...> wrote:

>
>
> To All;
>
> Does anyone here knows the benefit of JUnit 4 especially the Rule
> Annotation?
>
> Thanks,
>
> Archetype
>
>  
>

Re: JUnit 4 Rule Annotation

by Alistair Israel :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, Aug 26, 2009 at 12:10 PM, Arche Type<type.arche@...> wrote:
>
> Does anyone here knows the benefit of JUnit 4 especially the Rule
> Annotation?

I assume you're asking about the benefits of JUnit 4.x, specifically, 4.7
over JUnit 3.x so I won't talk about the benefits of unit testing (using
JUnit or TestNG) in general.

JUnit 4.x allows you to use POJOs with annotations as tests. For example:

*public* *class* AdderTest {

  @Test
  *public* *void* testAdd() {
    Adder adder = *new* Adder(5);
    assertEquals(8, adder.add(3));
  }
}

The @Test annotation marks the method testAdd() as a test method. Note that
AdderTest is a POJO, and it could've just as well descended from any base
class (not constricted to junit.framework.TestCase).

Since AdderTest doesn't descend from junit.framework.TestCase, the
assert*()methods aren't available to it via the usual mechanism.
Instead, JUnit 4
embraces another Java 5's idiom to provide the same syntax/semantics: the
static import:

*import* *static* org.junit.Assert.assertEquals;

Finally, about JUnit interceptors or the @Rules: interceptors further
enhance the capability to write tests as POJOs.

Without interceptors before, you'd have to write something like:

*public* *class* TemporaryFolderTestBase {

  @Before
  *public void* createTemporaryFolder() {
    // ...
  }

  @After
  *public void* removeTemporaryFolder() {
    // ...
  }
}

Then extend it:

*public class* FileExporterTest *extends* TemporaryFolderTestBase {

 // ...

}

Now, you simply can use something like:

*public class* FileExporterTest {

  @Rule
  *public* TemporaryFolder folder = *new* TemporaryFolder();

  @Test
  *public* *void* testFileExport() {
    File file = folder.newFile("test");
    FileExport exporter = *new* FileExporter();
    exporter.export(file);
    assertTrue(file.exists());
  }

}

Note that the setup and tear down of the temporary folder and any files
created in it are all handled transparently by the TemporaryFolderinterceptor.

For further reading and more examples, see:

   - Interceptors in JUnit
<http://www.threeriversinstitute.org/blog/?p=155>(Kent Beck's blog)
   - dirty-mockito 0.2 <http://code.google.com/p/dirty-mockito/> now
   provides an interceptor that can create mocks, instantiate test objects and
   inject the mocks (using Spring) into the test objects

Hope this helps.

- a
--
http://alistairisrael.wordpress.com

Re: JUnit 4 Rule Annotation

by franz see :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

In addition, the Junit 4 annotations allows you to write cleaner tests
(err...specifications) as well :-)

If you follow the should<DoSomething> syntax, you can annotate it with @Test
instead of prefix it with the awkward 'test' word :-)

And if you follow Given-When-Then, then you can write your setUp() to
given<SomeFixtures> and annotate it with @Before. And your When-Then would
be your @Test.

Cheers,

--
Franz Allan Valencia See | Java Software Engineer
franz.see@...
LinkedIn: http://www.linkedin.com/in/franzsee

On Wed, Aug 26, 2009 at 2:34 PM, Alistair Israel <aisrael@...> wrote:

>
>
> On Wed, Aug 26, 2009 at 12:10 PM, Arche Type<type.arche@...> wrote:
> >
> > Does anyone here knows the benefit of JUnit 4 especially the Rule
> > Annotation?
>
> I assume you're asking about the benefits of JUnit 4.x, specifically, 4.7
> over JUnit 3.x so I won't talk about the benefits of unit testing (using
> JUnit or TestNG) in general.
>
> JUnit 4.x allows you to use POJOs with annotations as tests. For example:
>
> *public* *class* AdderTest {
>
>   @Test
>   *public* *void* testAdd() {
>     Adder adder = *new* Adder(5);
>     assertEquals(8, adder.add(3));
>   }
> }
>
> The @Test annotation marks the method testAdd() as a test method. Note
> that AdderTest is a POJO, and it could've just as well descended from any
> base class (not constricted to junit.framework.TestCase).
>
> Since AdderTest doesn't descend from junit.framework.TestCase, the
> assert*() methods aren't available to it via the usual mechanism. Instead,
> JUnit 4 embraces another Java 5's idiom to provide the same
> syntax/semantics: the static import:
>
> *import* *static* org.junit.Assert.assertEquals;
>
> Finally, about JUnit interceptors or the @Rules: interceptors further
> enhance the capability to write tests as POJOs.
>
> Without interceptors before, you'd have to write something like:
>
> *public* *class* TemporaryFolderTestBase {
>
>   @Before
>   *public void* createTemporaryFolder() {
>     // ...
>   }
>
>   @After
>   *public void* removeTemporaryFolder() {
>     // ...
>   }
> }
>
> Then extend it:
>
> *public class* FileExporterTest *extends* TemporaryFolderTestBase {
>
>  // ...
>
> }
>
> Now, you simply can use something like:
>
> *public class* FileExporterTest {
>
>   @Rule
>   *public* TemporaryFolder folder = *new* TemporaryFolder();
>
>   @Test
>   *public* *void* testFileExport() {
>     File file = folder.newFile("test");
>     FileExport exporter = *new* FileExporter();
>     exporter.export(file);
>     assertTrue(file.exists());
>   }
>
> }
>
> Note that the setup and tear down of the temporary folder and any files
> created in it are all handled transparently by the TemporaryFolderinterceptor.
>
> For further reading and more examples, see:
>
>    - Interceptors in JUnit<http://www.threeriversinstitute.org/blog/?p=155>(Kent Beck's blog)
>    - dirty-mockito 0.2 <http://code.google.com/p/dirty-mockito/> now
>    provides an interceptor that can create mocks, instantiate test objects and
>    inject the mocks (using Spring) into the test objects
>
> Hope this helps.
>
> - a
> --
> http://alistairisrael.wordpress.com
>
>  
>

Re: JUnit 4 Rule Annotation

by Arche Type :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks for the inputs. The reason I ask this because, I am migrating from version 3 to 4 with annotation. I agree, it's more cleaner to write a test.

Thanks again.




________________________________
From: Franz Allan Valencia See <franz.see@...>
To: pinoyjug@...
Sent: Wednesday, August 26, 2009 10:50:23 PM
Subject: Re: [pinoyjug] JUnit 4 Rule Annotation

   
In addition, the Junit 4 annotations allows you to write cleaner tests (err...specificatio ns) as well :-)

If you follow the should<DoSomething> syntax, you can annotate it with @Test instead of prefix it with the awkward 'test' word :-)

And if you follow Given-When-Then, then you can write your setUp() to given<SomeFixtures> and annotate it with @Before. And your When-Then would be your @Test.

Cheers,

--
Franz Allan Valencia See | Java Software Engineer
franz.see@gmail. com
LinkedIn: http://www.linkedin.com/in/franzsee


On Wed, Aug 26, 2009 at 2:34 PM, Alistair Israel <aisrael@gmail. com> wrote:

  >

>On Wed, Aug 26, 2009 at 12:10 PM, Arche Type<type.arche@yahoo. com> wrote:
>>
>
>> Does anyone here knows the benefit of JUnit 4 especially the Rule
>>> Annotation?
>
>I assume you're asking about the benefits of JUnit 4.x, specifically, 4.7 over JUnit 3.x so I won't talk about the benefits of unit testing (using JUnit or TestNG) in general.
>
>JUnit 4.x allows you to use POJOs with annotations as tests. For example:
>
>public class AdderTest {
>
>  @Test
>  public void testAdd() {
>    Adder adder = new Adder(5);
>    assertEquals( 8, adder.add(3) );
>  }
>}
>
>The @Test annotation marks the method testAdd() as a test method. Note that AdderTest is a POJO, and it could've just as well descended from any base class (not constricted to junit.framework. TestCase).
>
>Since AdderTest doesn't descend from junit.framework. TestCase, the assert*() methods aren't available to it via the usual mechanism. Instead, JUnit 4 embraces another Java 5's idiom to provide the same syntax/semantics: the static import:
>
>import static org.junit.Assert. assertEquals;
>
>Finally, about JUnit interceptors or the @Rules: interceptors further enhance the capability to write tests as POJOs.
>
>Without interceptors before, you'd have to write something like:
>
>public class TemporaryFolderTest Base {
>
>  @Before
>  public void createTemporaryFold er() {
>    // ...
>  }
>
>  @After
>  public void removeTemporaryFold er() {
>    // ...
>  }
>}
>
>Then extend it:
>
>public class FileExporterTest extends TemporaryFolderTest Base {
>
> // ...
>
>}
>
>Now, you simply can use something like:
>
>public class FileExporterTest {
>
>  @Rule
>  public TemporaryFolder folder = new TemporaryFolder( );
>
>  @Test
>  public void testFileExport( ) {
>    File file = folder.newFile("test");
>    FileExport exporter = new FileExporter( );
>    exporter.export( file);
>    assertTrue(file. exists()) ;
>  }
>
>}
>
>>
>
>Note that the setup and tear down of the temporary folder and any files created in it are all handled transparently by the TemporaryFolder interceptor.
>
>For further reading and more examples, see:
>
> * Interceptors in JUnit (Kent Beck's blog)
> * dirty-mockito 0.2 now provides an interceptor that can create mocks, instantiate test objects and inject the mocks (using Spring) into the test objectsHope this helps.
>
>- a
>--
>http://alistairisra el.wordpress. com
>
>



   


     

Re: JPA and Spring 3

by kabilaw_101 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks! My next post is about using the JSR 303 or the Bean Validation API.

http://javapulutan.blogspot.com/2009/08/basic-bean-validation-jsr-303.html   

--- In pinoyjug@..., "Calen Martin D. Legaspi" <calen@...> wrote:

>
> Good for you, Kabaliw_101!  I hope more of us Pinoy developers
> contribute to the world's knowledge base rather than just consume.
>
> Calen
> Calen Legaspi <http://software.orangeandbronze.com>
> <http://software.orangeandbronze.com>
>
>
> kabilaw_101 wrote:
> >  
> >
> > Hi Guys,
> >
> > I just want to share my tutorial on how to use JPA on Spring 3.
> >
> > http://javapulutan.blogspot.com/2009/08/maven-2-jpa-and-spring-3-first-attempt.html 
> > <http://javapulutan.blogspot.com/2009/08/maven-2-jpa-and-spring-3-first-attempt.html>
> >
> > thanks!
> >
> >
>



Re: JPA and Spring 3

by kabilaw_101 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message






My recent post about Spring 3 and JPA. Thanks!

http://javapulutan.blogspot.com/2009/10/dependency-injection-to-unmanaged.html


--- In pinoyjug@..., "kabilaw_101" <kabilaw_101@...> wrote:

>
> Thanks! My next post is about using the JSR 303 or the Bean Validation API.
>
> http://javapulutan.blogspot.com/2009/08/basic-bean-validation-jsr-303.html   
>
> --- In pinoyjug@..., "Calen Martin D. Legaspi" <calen@> wrote:
> >
> > Good for you, Kabaliw_101!  I hope more of us Pinoy developers
> > contribute to the world's knowledge base rather than just consume.
> >
> > Calen
> > Calen Legaspi <http://software.orangeandbronze.com>
> > <http://software.orangeandbronze.com>
> >
> >
> > kabilaw_101 wrote:
> > >  
> > >
> > > Hi Guys,
> > >
> > > I just want to share my tutorial on how to use JPA on Spring 3.
> > >
> > > http://javapulutan.blogspot.com/2009/08/maven-2-jpa-and-spring-3-first-attempt.html 
> > > <http://javapulutan.blogspot.com/2009/08/maven-2-jpa-and-spring-3-first-attempt.html>
> > >
> > > thanks!
> > >
> > >
> >
>