package eu.dnetlib.ariadneplus.publisher;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

/**
 * Created by Alessia Bardi on 29/08/2017.
 *
 * @author Alessia Bardi
 */
@RunWith(SpringRunner.class)
@WebMvcTest(AriadnePlusPublisherController.class)
public class AriadnePlusPublisherControllerTest {
	@Autowired
	private MockMvc mvc;

	@MockBean
	private AriadnePlusPublisherHelper ariadneplusPublisherHelper;

	@Test
	public void publishOK() throws Exception {
		mvc.perform(post("/publish").param("record", "<aTestRecord>value</aTestRecord>").param("ariadneplusTarget", "VIRTUOSO"))
				.andExpect(status().isOk());
	}

	@Test
	public void textEx() throws Exception {
		mvc.perform(post("/publish")).andExpect(status().is4xxClientError());
	}

}
