WIP
[demos/example-siren] / spring-consumer / src / test / java / de / juplo / demos / pact / ContractTest.java
index d500fa5..ad2835f 100644 (file)
@@ -12,7 +12,6 @@ import org.springframework.boot.web.client.RestTemplateBuilder;
 import org.springframework.web.client.RestTemplate;
 
 import java.util.Map;
-import java.util.regex.Pattern;
 
 import static org.assertj.core.api.Assertions.fail;
 
@@ -33,15 +32,62 @@ public class ContractTest
             .headers(Map.of("Content-Type", "application/vnd.siren+json"))
             .body(LambdaDsl.newJsonBody(body ->
             {
+              body.array("class", classArray ->
+              {
+                classArray.stringValue("entity");
+              });
               body.array("entities", entities ->
               {
-                body.arrayContaining("actions", actions ->
+                entities.eachLike(entity ->
+                {
+                  entity.arrayContaining("actions", actionsArray->
+                  {
+                    actionsArray.object(object ->
+                    {
+                      object.stringType("name","update");
+                      object.stringType("method", "PUT");
+                      object.matchUrl2("href", Matchers.regexp("\\d+", "1234").getValue());
+                    });
+                    actionsArray.object(object ->
+                    {
+                      object.stringType("name","delete");
+                      object.stringType("method", "DELETE");
+                      object.matchUrl2("href", Matchers.regexp("\\d+", "1234").getValue());
+                    });
+                  });
+                  entity.array("class", classArray ->
+                  {
+                    classArray.stringValue("entity");
+                  });
+                  entity.array("links", linksArray ->
+                  {
+                    linksArray.object(object->
+                    {
+                      object.matchUrl2("href", "orders", Matchers.regexp("\\d+", "1234"));
+                      object.array("rel", relArray ->
+                      {
+                        relArray.stringValue("self");
+                      });
+                    });
+                  });
+                  entity.object("properties", object->
+                  {
+                    object.stringType("id", "1234");
+                    object.array("rel", relArray ->
+                    {
+                      relArray.stringValue("item");
+                    });
+                  });
+                });
+              });
+              body.array("links", linksArray ->
+              {
+                linksArray.object(object->
                 {
-                  actions.object(object ->
+                  object.matchUrl2("href", "orders");
+                  object.array("rel", relArray ->
                   {
-                    object.stringType("name","update");
-                    object.stringType("method", "PUT");
-                    object.matchUrl2("href", Matchers.regexp("\\d+", "1234"));
+                    relArray.stringValue("self");
                   });
                 });
               });