package org.sagebionetworks;

import static org.junit.Assert.assertEquals;

import org.junit.BeforeClass;
import org.junit.Test;
import org.sagebionetworks.client.SynapseClient;
import org.sagebionetworks.client.SynapseClientImpl;
import org.sagebionetworks.repo.web.UrlHelpers;
import org.sagebionetworks.simpleHttpClient.SimpleHttpClient;
import org.sagebionetworks.simpleHttpClient.SimpleHttpClientImpl;
import org.sagebionetworks.simpleHttpClient.SimpleHttpRequest;
import org.sagebionetworks.simpleHttpClient.SimpleHttpResponse;
import org.springframework.http.HttpStatus;

/**
 * Test class created to make API calls that we don't want to extend to the
 * Synapse Java Client.
 */
public class ITUnsupportedMethodTest {

	private static SynapseClient synapse;
	private static SimpleHttpClient simpleHttpClient;

	@BeforeClass
	public static void beforeClass() {
		synapse = new SynapseClientImpl();
		simpleHttpClient = new SimpleHttpClientImpl();
	}

	@Test
	public void testUnsupportedMethodResponse() throws Exception {
		// For more info, see PLFM-3574
		SimpleHttpRequest invalidMethodRequest = new SimpleHttpRequest();
		// Create a request that doesn't exist (POST /version)
		invalidMethodRequest.setUri(synapse.getRepoEndpoint() + UrlHelpers.VERSION);

		// Call under test
		SimpleHttpResponse response = simpleHttpClient.post(invalidMethodRequest, "body");
		assertEquals(HttpStatus.METHOD_NOT_ALLOWED.value(), response.getStatusCode());
	}

}

@@ -992,24 +992,25 @@
 edMethod
-Response
+WrongVerb
 () throw
@@ -1156,21 +1156,38 @@
 hat 
-doesn't exist
+exists, but use the wrong verb
  (PO
@@ -1470,10 +1470,461 @@
 ));%0A%09%7D%0A%0A
+%09@Test%0A%09public void testUnsupportedMethodCallUnknownUri() throws Exception %7B%0A%09%09SimpleHttpRequest invalidMethodRequest = new SimpleHttpRequest();%0A%09%09// Create a request that doesn't exist with any verb%0A%09%09invalidMethodRequest.setUri(synapse.getRepoEndpoint() + %22nonsenserequest%22);%0A%0A%09%09// Call under test%0A%09%09SimpleHttpResponse response = simpleHttpClient.get(invalidMethodRequest);%0A%09%09assertEquals(HttpStatus.NOT_FOUND.value(), response.getStatusCode());%0A%09%7D%0A
 %7D%0A

test a 404 when calling an unknown URI