package marketing.heyday.hartmann.fotodocumentation.rest;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.IOException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpResponse;
import org.apache.http.client.fluent.Request;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;

/**
 * 
 * <p>Copyright: Copyright (c) 2024</p>
 * <p>Company: heyday Marketing GmbH</p>
 * @author <a href="mailto:p.verboom@heyday.marketing">Patrick Verboom</a>
 * @version 1.0
 * 
 * created: 14 Nov 2024
 */
@TestMethodOrder(OrderAnnotation.class)
public class PictureResourceTest extends AbstractRestTest {
	private static final Log LOG = LogFactory.getLog(PictureResourceTest.class);
	private static final String PATH = "api/picture";

	@BeforeAll
	public static void init() {
		initDB();
	}

	@Test
	@Order(1)
	public void doDelete() throws IOException {
		LOG.info("doDelete");

		assertEquals(5, pictureCount());

		String path = deploymentURL + PATH + "/1";
		Request request = Request.Delete(path).addHeader("Accept", "application/json; charset=utf-8")
				.addHeader("Authorization", getAuthorization());

		HttpResponse httpResponse = executeRequest(request);
		int code = httpResponse.getStatusLine().getStatusCode();
		assertEquals(200, code);

		assertEquals(4, pictureCount());
	}

	@Test
	@Order(1)
	public void doDeleteNotFound() throws IOException {
		LOG.info("doDeleteNotFound");

		assertEquals(5, pictureCount());

		String path = deploymentURL + PATH + "/6000";
		Request request = Request.Delete(path).addHeader("Accept", "application/json; charset=utf-8")
				.addHeader("Authorization", getAuthorization());

		HttpResponse httpResponse = executeRequest(request);
		int code = httpResponse.getStatusLine().getStatusCode();
		assertEquals(404, code);

		assertEquals(5, pictureCount());
	}

}
