package com.rewedigital.examples.msintegration.productinformation.product;

import com.rewedigital.examples.msintegration.productinformation.ProductInformationApplication;
import com.rewedigital.examples.msintegration.productinformation.product.Product;
import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.test.context.junit4.SpringRunner;

import javax.inject.Inject;
import java.util.Random;

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = ProductInformationApplication.class)
public class ProductRestControllerTest {

    @Inject private TestRestTemplate restTemplate;

    @Test
    public void testProductInsert() {

        Product product = new Product();
        product.setName("Bla!");

        Product response = restTemplate.postForObject("/products", product, Product.class);

        Assertions.assertThat(response).isNotNull();
    }

    @Test
    public void testProductBadInsert() {

        Product product = new Product();
        product.setId("108");

        Product response = restTemplate.postForObject("/products", product, Product.class);

        Assertions.assertThat(response).isNotNull();
    }
}

@@ -287,16 +287,46 @@
 rtions;%0A
+import org.junit.BeforeClass;%0A
 import o
@@ -500,16 +500,108 @@
 mplate;%0A
+import org.springframework.http.HttpStatus;%0Aimport org.springframework.http.ResponseEntity;%0A
 import o
@@ -708,16 +708,75 @@
 andom;%0A%0A
+import static org.assertj.core.api.Assertions.assertThat;%0A%0A
 @RunWith
@@ -1234,35 +1234,24 @@
 );%0A%0A        
-Assertions.
 assertThat(r
@@ -1403,39 +1403,46 @@
 108%22);%0A%0A        
-Product
+ResponseEntity
  response = rest
@@ -1449,38 +1449,38 @@
 Template.postFor
-Object
+Entity
 (%22/products%22, pr
@@ -1478,37 +1478,36 @@
 ucts%22, product, 
-Produ
+Obje
 ct.class);%0A%0A    
@@ -1510,33 +1510,22 @@
         
-A
+a
 ssert
-ions.assert
 That(res
@@ -1533,27 +1533,118 @@
 onse).isNotNull(
+);%0A        assertThat(response.getStatusCode()).isEqualByComparingTo(HttpStatus.BAD_REQUEST
 );%0A    %7D%0A%7D%0A

Test fixed.