Package io.ebean.test

Class DbJson


  • public class DbJson
    extends Object
    Helper for testing to assert that the JSON form of an entity or list of entities is as expected.

    Using assertContains() we can match the JSON form of an entity against a subset of JSON content. Typically the subset of JSON excludes generated properties like id, when created and when modified properties.

    Assert contains

    
    
        DbJson.of(order)
          .assertContains("/order-partial.json");
    
     

    Assert content matches

    Using assertContentMatches() we are doing an exact content match. We typically need to replace generated property values. This assert will start to fail if the model changes like adding a property to the entity so we should use it less widely due to the maintenance burden we have with it.

    
    
        DbJson.of(order)
          .replace("id", "whenCreated", "whenModified)
          .assertContentMatches("/order-full.json");
    
     
    • Constructor Detail

      • DbJson

        public DbJson()
    • Method Detail

      • of

        public static DbJson.PrettyJson of​(Object bean)
        Create a PrettyJson object that has the JSON form of the entity bean or beans.

        Assert contains

        
        
            DbJson.of(order)
              .assertContains("/order-partial.json");
        
         

        Assert content matches

        
        
            DbJson.of(order)
              .replace("id", "whenCreated", "whenModified)
              .assertContentMatches("/order-full.json");
        
         
      • readResource

        public static String readResource​(String resourcePath)
        Read the content for the given resource path.