

package org.apache.flink.runtime.rest.messages.job.metrics;

import org.apache.flink.runtime.rest.HttpMethodWrapper;
import org.apache.flink.runtime.rest.messages.EmptyMessageParameters;
import org.apache.flink.runtime.rest.messages.EmptyRequestBody;
import org.apache.flink.util.TestLogger;

import org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus;

import org.junit.Before;
import org.junit.Test;

import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;

/**
 * Tests for {@link AbstractMetricsHeaders}.
 */
public class AbstractMetricsHeadersTest extends TestLogger {

	private AbstractMetricsHeaders<EmptyMessageParameters> metricsHandlerHeaders;

	@Before
	public void setUp() throws Exception {
		metricsHandlerHeaders = new AbstractMetricsHeaders<EmptyMessageParameters>() {
			@Override
			public EmptyMessageParameters getUnresolvedMessageParameters() {
				return EmptyMessageParameters.getInstance();
			}

			@Override
			public String getTargetRestEndpointURL() {
				return "/";
			}
		};
	}

	@Test
	public void testHttpMethod() {
		assertThat(metricsHandlerHeaders.getHttpMethod(), equalTo(HttpMethodWrapper.GET));
	}

	@Test
	public void testResponseStatus() {
		assertThat(metricsHandlerHeaders.getResponseStatusCode(), equalTo(HttpResponseStatus.OK));
	}

	@Test
	public void testRequestClass() {
		assertThat(metricsHandlerHeaders.getRequestClass(), equalTo(EmptyRequestBody.class));
	}

	@Test
	public void testResponseClass() {
		assertThat(metricsHandlerHeaders.getResponseClass(), equalTo(MetricCollectionResponseBody.class));
	}

}
