archive-se.com » SE » S » SAWANO.SE

Total: 50

Choose link from "Titles, links and description words view":

Or switch to "Titles and links view".
  • sôft'wâr': September 2012
    didn t have things like O R mappings and nice transactional APIs but had to fiddle around with JDBC connections rolling back transactions reading from result sets and whatnot 1 But still pretty much all of the work you do every time you create a repository class for your entities is plumbing You are creating nothing but boiler plate code And time spent on boilerplate code is time wasted because you are writing code that adds no real value but still needs to be tested and maintained Read more Posted by Daniel Sawano 3 comments Email This BlogThis Share to Twitter Share to Facebook Share to Pinterest Links to this post Labels Java JPA persistence Spring Data Newer Posts Older Posts Home Subscribe to Posts Atom soft ware noun sôft wâr The programs and other operating information used by a computer About Me Daniel Sawano Developer architect public speaker agile dude and sporadic blogger Loves creativity beautiful software TDD BDD DDD and a whole bunch of other acronyms Tweets by DanielSawano Labels Java Spring Spring MVC JSON Jackson Maven Scala XML Clean Code JAXB REST RESTful Agile Akka Concurrency Continuous Delivery Conway s Law HATEOAS IntelliJ JPA JSR 303 Mockito

    Original URL path: http://software.sawano.se/2012_09_01_archive.html (2016-05-02)
    Open archived version from archive


  • sôft'wâr': July 2012
    cause a nullpointer exception The stack trace of that exception will quite easily give away that the cause was an unstubbed method However if the tested code calls an unstubbed method and instead of using the null value directly stores it and uses it later Then the stack trace of the nullpointer exception will no longer reveal that the cause was an unstubbed method but will point to some random code line that can be far away from where the unstubbed call actually took place When this happens it usually takes some time to figure out what the root cause was Lets take a look at how we would approach this situation and how we can get a more informative error when it occurs Read more Posted by Daniel Sawano 2 comments Email This BlogThis Share to Twitter Share to Facebook Share to Pinterest Links to this post Labels Java Mockito TDD Newer Posts Older Posts Home Subscribe to Posts Atom soft ware noun sôft wâr The programs and other operating information used by a computer About Me Daniel Sawano Developer architect public speaker agile dude and sporadic blogger Loves creativity beautiful software TDD BDD DDD and a whole bunch

    Original URL path: http://software.sawano.se/2012_07_01_archive.html (2016-05-02)
    Open archived version from archive

  • sôft'wâr': May 2012
    Scala to get the job done In this third and last post of our Spring MVC and Scala experiment we will continue to work on the web application that we used in the previous posts so you might want to get the example code on GitHub so you can try out the examples on your own as we go along JSR 303 Validation Another very common use case when building web services is the use of JSR 303 Bean Validation for validating input data Lets take a look on how the Spring MVC support for JSR 303 will work together with Scala by adding some more functionality to our web service Read more Posted by Daniel Sawano 1 comments Email This BlogThis Share to Twitter Share to Facebook Share to Pinterest Links to this post Labels Java JSON JSR 303 Maven Scala Spring Spring MVC Newer Posts Older Posts Home Subscribe to Posts Atom soft ware noun sôft wâr The programs and other operating information used by a computer About Me Daniel Sawano Developer architect public speaker agile dude and sporadic blogger Loves creativity beautiful software TDD BDD DDD and a whole bunch of other acronyms Tweets by DanielSawano Labels

    Original URL path: http://software.sawano.se/2012_05_01_archive.html (2016-05-02)
    Open archived version from archive

  • sôft'wâr': April 2012
    later find yourself facing issues around mixing Java and Scala code together if your current systems are written in Java Spring MVC is a well known framework and is extensively used in a wide variety of applications and chances are you already have a well functioning Spring MVC application Maybe you also have a lot of infrastructure build around it and integrated to it like access control and logging for example And since that infrastructure is written in Java you need to be able to take advantage of those available systems to make the most out of your Scala API Ok so all you need to do is hook up your new shiny Scala API that you have developed But how do you do it And does it work Those are some of the questions that I asked myself and I will try to share some of my findings on the subject here Read more Posted by Daniel Sawano 2 comments Email This BlogThis Share to Twitter Share to Facebook Share to Pinterest Links to this post Labels Java Maven Scala Spring Spring MVC April 4 2012 Take your REST API to the next level with HATEOAS A pragmatic approach to understanding HATEOAS HATEOAS or Hypermedia As The Engine Of Application State is a lot about the discoverability in a RESTful API And it is also the part that most REST APIs misses out on This is sad because there are a lot of benefits to reap if you take your API to the next level Especially for the developers using your API Some of the benefits of using HATEOAS include simpler clients simplified authorization control on the client side and making your API self documenting If you are all new to the concept then Martin Fowler s article on

    Original URL path: http://software.sawano.se/2012_04_01_archive.html (2016-05-02)
    Open archived version from archive

  • sôft'wâr': March 2012
    behavior of our web service is simply a matter of defining our own order for the message converters and make sure the JSON converter comes before the Jaxb converter Read more Posted by Daniel Sawano 2 comments Email This BlogThis Share to Twitter Share to Facebook Share to Pinterest Links to this post Labels Jackson Java JAXB JSON Spring Spring MVC XML March 14 2012 Combining JSON and XML in RESTful web services with Spring MVC There are occasions when you need to support multiple representations of the same resource in a REST API For example a smartphone client might want the resource to be represented in JSON while your B2B partner s application that is integrating through your API wants the representation to be XML Willie Wheeler wrote an excellent blog post about how to support both XML and JSON from a web service endpoint using the new features of the RequestMapping annotation in Spring 3 1 The example in the blog post by intention uses two different URLs for the two different representations However when dealing with RESTful services the preferred approach to design your API would usually be to have a single URL for the resource regardless of what representation the requesting client is asking for A way to solve this is to let the requesting client specify what representation it prefers via the Accept header in the HTTP request The server will examine the request header and send back the resource in the proper representation This can very easily be implemented by using Spring MVC and I figured I will show you how this can be accomplished with the following example Read more Posted by Daniel Sawano 18 comments Email This BlogThis Share to Twitter Share to Facebook Share to Pinterest Links to this post Labels

    Original URL path: http://software.sawano.se/2012_03_01_archive.html (2016-05-02)
    Open archived version from archive

  • sôft'wâr': Controlling message converters with Spring MVC 3.1
    simply a matter of defining our own order for the message converters and make sure the JSON converter comes before the Jaxb converter We can do this by using the new mvc message converters configuration element in Spring MVC 3 1 If we change our configuration from this mvc annotation driven to a configuration that specifies the order of the message converters explicitly like this mvc annotation driven mvc message converters bean class org springframework http converter json MappingJacksonHttpMessageConverter bean class org springframework http converter xml Jaxb2RootElementHttpMessageConverter mvc message converters mvc annotation driven we will get the desired result If you run the above integration test again you will now see that the data is returned in JSON format If you want to prevent any default message converters to be added in addition to the ones you explicitly specify then you can control that with the register default attribute An example of that would be mvc message converters register defaults false With the new features in Spring MVC 3 1 controlling message converters has become really easy and we have now enhanced our REST API to return JSON by default Posted by Daniel Sawano Email This BlogThis Share to Twitter Share to Facebook Share to Pinterest Labels Jackson Java JAXB JSON Spring Spring MVC XML 2 comments Anonymous 12 June 2012 04 14 Hi Daniel I read your previous and this post I tried to implement the similar thing but unfortunately it is always returning XML regardless of the message converters defined Any idea Reply Delete Replies Daniel Sawano 13 June 2012 12 57 Hi remember that you need to remove the previous line in the example Otherwise it will interfere Also it is all based on the accept header so if you are testing with a browser you need

    Original URL path: http://software.sawano.se/2012/03/controlling-message-converters-with.html (2016-05-02)
    Open archived version from archive

  • sôft'wâr': Mockito: Default values and how to get more out of them
    use the RETURNS SMART NULLS answer in Mockito see the javadoc You can specify the RETURNS SMART NULLS default answer when you are creating your mock like User userMock mock User class Mockito RETURNS SMART NULLS When using RETURNS SMART NULLS the mock will return a SmartNull instead of a null When your code tries to use the SmartNull value you will get a SmartNullPointerException instead of a nullpointer exception and the stack trace will show you where the call to the unstubbed method was made This is really helpful compared to the previous staktrace that revealed nothing You should also notice that RETURNS SMART NULLS will return null SmartNull in fewer cases than default Ok that second solution will help us avoid those awful nullpointer exceptions but you might still get some unwanted or unexpected results since there are a lot of cases where the default value is not null Sometimes you may want a way to totally forbid calls to unstubbed methods and when such a call is made you want to throw an exception letting everybody know about the horrible violation You can achieve this behavior by providing your own custom default answer A mock with such an exception throwing answer would look like this User userMock mock User class new Answer Override public Object answer InvocationOnMock invocation throws Throwable throw new MockitoException Unstubbed method call So what happens when you start writing your givens when userMock getAddress thenReturn new Address Duckburg Or given userMock getAddress willReturn new Address Duckburg if you prefer the BDD style Well you will get that Unstubbed method call stack trace from your default answer Not exactly the result we wanted It turns out that the method you are trying to stub actually gets called when you are stubbing the method catch 22 implementation of Mockito We need to find a new mocking framework Start googling Quick Wait Before you start whipping out your googling skills take a deep breath and start surfing the documentation of Mockito instead or just read this blog post and we will find the third solution It turns out the developers of Mockito have already thought of our problem There is another way you can write your givens doReturn new Address Duckburg when userMock getAddress This way the method getAddress will not be called when you are stubbing it to return an actual value To me this syntax feels very backwards and does not read as well as using the when then syntax and though I know about it I hardly ever uses it And you shouldn t either since the when then syntax is the preferred and recommended way to use Mockito But this reversed notation can indeed be a handy trick when you actually need it And now you know it too so you can take advantage of it and you also know that you should use it sparingly The afterthought As I mentioned in the beginning of this post the need for doing more

    Original URL path: http://software.sawano.se/2012/07/mockito-default-values-and-how-to-get.html?showComment=1341344916444 (2016-05-02)
    Open archived version from archive

  • sôft'wâr': Mockito: Default values and how to get more out of them
    use the RETURNS SMART NULLS answer in Mockito see the javadoc You can specify the RETURNS SMART NULLS default answer when you are creating your mock like User userMock mock User class Mockito RETURNS SMART NULLS When using RETURNS SMART NULLS the mock will return a SmartNull instead of a null When your code tries to use the SmartNull value you will get a SmartNullPointerException instead of a nullpointer exception and the stack trace will show you where the call to the unstubbed method was made This is really helpful compared to the previous staktrace that revealed nothing You should also notice that RETURNS SMART NULLS will return null SmartNull in fewer cases than default Ok that second solution will help us avoid those awful nullpointer exceptions but you might still get some unwanted or unexpected results since there are a lot of cases where the default value is not null Sometimes you may want a way to totally forbid calls to unstubbed methods and when such a call is made you want to throw an exception letting everybody know about the horrible violation You can achieve this behavior by providing your own custom default answer A mock with such an exception throwing answer would look like this User userMock mock User class new Answer Override public Object answer InvocationOnMock invocation throws Throwable throw new MockitoException Unstubbed method call So what happens when you start writing your givens when userMock getAddress thenReturn new Address Duckburg Or given userMock getAddress willReturn new Address Duckburg if you prefer the BDD style Well you will get that Unstubbed method call stack trace from your default answer Not exactly the result we wanted It turns out that the method you are trying to stub actually gets called when you are stubbing the method catch 22 implementation of Mockito We need to find a new mocking framework Start googling Quick Wait Before you start whipping out your googling skills take a deep breath and start surfing the documentation of Mockito instead or just read this blog post and we will find the third solution It turns out the developers of Mockito have already thought of our problem There is another way you can write your givens doReturn new Address Duckburg when userMock getAddress This way the method getAddress will not be called when you are stubbing it to return an actual value To me this syntax feels very backwards and does not read as well as using the when then syntax and though I know about it I hardly ever uses it And you shouldn t either since the when then syntax is the preferred and recommended way to use Mockito But this reversed notation can indeed be a handy trick when you actually need it And now you know it too so you can take advantage of it and you also know that you should use it sparingly The afterthought As I mentioned in the beginning of this post the need for doing more

    Original URL path: http://software.sawano.se/2012/07/mockito-default-values-and-how-to-get.html?showComment=1341513144013 (2016-05-02)
    Open archived version from archive