content: /*
   *
   *   Copyright 2016 alh Technology
   *  
   *   Licensed under the Apache License, Version 2.0 (the "License");
   *   you may not use this file except in compliance with the License.
   *   You may obtain a copy of the License at
   *
   *    http://www.apache.org/licenses/LICENSE-2.0
   *
   *   Unless required by applicable law or agreed to in writing, software
   *   distributed under the License is distributed on an "AS IS" BASIS,
   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *   See the License for the specific language governing permissions and
   *   limitations under the License.
   *
   */
  
  package com.alh.gatling;
  
  import com.fasterxml.jackson.core.JsonProcessingException;
  import com.fasterxml.jackson.databind.ObjectMapper;
  import org.junit.runner.RunWith;
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.boot.test.context.SpringBootTest;
  import org.springframework.boot.test.web.client.TestRestTemplate;
  import org.springframework.test.context.ActiveProfiles;
  import org.springframework.test.context.TestPropertySource;
  import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
  
  /**
   * Abstract helper class that defines necessary web integration testing annotations and common functions.
   * 
   * @author
   *
   */
  @RunWith(SpringJUnit4ClassRunner.class)
  @SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
  @TestPropertySource(locations = "classpath:application.yml")
  @ActiveProfiles({"testing"})
  public abstract class AbstractRestIntTest {
  
  	private static final Logger logger = LoggerFactory.getLogger(AbstractRestIntTest.class);
  	@Autowired
  	protected TestRestTemplate template ;
  	protected final String rootUrl = "/api/v1";
  
  	@Autowired
  	protected ObjectMapper mapper;
  
  
  	protected String toJson(Object obj) {
  		try {
  			return mapper.writeValueAsString(obj);
  		} catch (JsonProcessingException e) {
  			e.printStackTrace();
  			throw new RuntimeException("Error marshalling object '" + obj + "' to json string.", e);
  		}
  	}
  
  }
  