package org.sagebionetworks.repo.web.controller;

import javax.servlet.http.HttpServlet;

import junit.framework.Assert;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.sagebionetworks.repo.manager.TestUserDAO;
import org.sagebionetworks.repo.model.AuthorizationConstants;
import org.sagebionetworks.repo.web.UrlHelpers;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:test-context.xml" })
public class DoiControllerAutowiredTest {

	private final String adminUser = TestUserDAO.ADMIN_USER_NAME;
	private final String testUser = TestUserDAO.TEST_USER_NAME;

	@Before
	public void before() throws Exception {
	}

	@After
	public void after() throws Exception {
	}

	@Test
	public void testPutGet() throws Exception {

		final String uri = UrlHelpers.ENTITY + "/" + 1 + UrlHelpers.DOI;

		MockHttpServletRequest request = new MockHttpServletRequest();
		request.setMethod("PUT");
		request.addHeader("Accept", "application/json");
		request.setRequestURI(uri);
		request.setParameter(AuthorizationConstants.USER_ID_PARAM, testUser);
		MockHttpServletResponse response = new MockHttpServletResponse();
		HttpServlet servlet = DispatchServletSingleton.getInstance();
		servlet.service(request, response);
		Assert.assertEquals(202, response.getStatus());

		request = new MockHttpServletRequest();
		request.setMethod("GET");
		request.addHeader("Accept", "application/json");
		request.setRequestURI(uri);
		request.setParameter(AuthorizationConstants.USER_ID_PARAM, testUser);
		response = new MockHttpServletResponse();
		servlet = DispatchServletSingleton.getInstance();
		servlet.service(request, response);
		Assert.assertEquals(200, response.getStatus());
	}

	@Test
	public void testPutGetWithVersion() throws Exception {

		final String uri = UrlHelpers.ENTITY + "/" + 1 + UrlHelpers.VERSION + "/" + 1 + UrlHelpers.DOI;

		MockHttpServletRequest request = new MockHttpServletRequest();
		request.setMethod("PUT");
		request.addHeader("Accept", "application/json");
		request.setRequestURI(uri);
		request.setParameter(AuthorizationConstants.USER_ID_PARAM, testUser);
		MockHttpServletResponse response = new MockHttpServletResponse();
		HttpServlet servlet = DispatchServletSingleton.getInstance();
		servlet.service(request, response);
		Assert.assertEquals(202, response.getStatus());

		request = new MockHttpServletRequest();
		request.setMethod("GET");
		request.addHeader("Accept", "application/json");
		request.setRequestURI(uri);
		request.setParameter(AuthorizationConstants.USER_ID_PARAM, testUser);
		response = new MockHttpServletResponse();
		servlet = DispatchServletSingleton.getInstance();
		servlet.service(request, response);
		Assert.assertEquals(200, response.getStatus());
	}
}

@@ -794,71 +794,8 @@
  %7B%0A%0A
-%09private final String adminUser = TestUserDAO.ADMIN_USER_NAME;%0A
 %09pri
@@ -851,16 +851,16 @@
 R_NAME;%0A
+
 %0A%09@Befor
@@ -1050,33 +1050,49 @@
 .ENTITY + %22/%22 + 
-1
+%22syn324829389481%22
  + UrlHelpers.DO
@@ -1525,35 +1525,35 @@
 rt.assertEquals(
-202
+404
 , response.getSt
@@ -1933,35 +1933,35 @@
 rt.assertEquals(
-200
+404
 , response.getSt
@@ -2076,33 +2076,49 @@
 .ENTITY + %22/%22 + 
-1
+%22syn324829389481%22
  + UrlHelpers.VE
@@ -2594,11 +2594,11 @@
 als(
-202
+404
 , re
@@ -3002,11 +3002,11 @@
 als(
-200
+404
 , re

Fix failed test