com.recursivechaos.clearent.controller.SaleControllerIntegrationTest.java Source code

Java tutorial

Introduction

Here is the source code for com.recursivechaos.clearent.controller.SaleControllerIntegrationTest.java

Source

/**
 * Created by Andrew Bell 2/1/2016
 * www.recursivechaos.com
 * andrew@recursivechaos.com
 * Licensed under MIT License 2016. See license.txt for details.
 */

package com.recursivechaos.clearent.controller;

import com.recursivechaos.clearent.ClearentDemoApplication;
import com.recursivechaos.clearent.IntegrationTest;
import com.recursivechaos.clearent.TestUtil;
import com.recursivechaos.clearent.domain.Sale;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;

import static org.junit.Assert.assertEquals;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = ClearentDemoApplication.class)
@WebAppConfiguration
@ActiveProfiles("test")
@Category(IntegrationTest.class)
public class SaleControllerIntegrationTest {

    @Autowired
    private SaleController saleController;

    @Test
    public void testPostSale() throws Exception {
        Sale saleRequest = TestUtil.createSaleRequest();

        ResponseEntity<Void> responseEntity = saleController.postSale(saleRequest);

        assertEquals(HttpStatus.CREATED, responseEntity.getStatusCode());
        assertEquals("/sales/1", responseEntity.getHeaders().getLocation().getPath());
    }

}