package gov.nih.nci.cananolab.restful;

import static org.junit.Assert.*;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;

import org.glassfish.jersey.client.ClientConfig;
import org.junit.Before;
import org.junit.Test;

public class SecurityServicesTest {
	
	String urlbase = "http://localhost:8080/caNanoLab/rest/";
	Client client; 

	@Before
	public void setUp() throws Exception {
		client = ClientBuilder.newClient(new ClientConfig()
		//.register(MyClientResponseFilter.class)
		//.register(new AnotherClientFilter())
				);
	}

	@Test
	public void testLogin() {
		String jsonString = client.target(urlbase)
				.register(SampleServices.class)
				.path("security/login")
				.queryParam("username", "canano_res").queryParam("password", "Quality@6")
				.request("application/json")
				.header("some-header", "true")
				.get(String.class);

		assertNotNull(jsonString);
		assertTrue(jsonString.length() > 0);
		
		jsonString = client.target(urlbase)
				.register(SampleServices.class)
				.path("security/logout")
				.request("application/json")
				.header("some-header", "true")
				.get(String.class);
		
		assertNotNull(jsonString);
		assertTrue(jsonString.contains("success"));
	}

	//@Test
	public void testRegister() {
		fail("Not yet implemented");
	}

	@Test
	public void testLogout() {
		String jsonString = client.target(urlbase)
				.register(SampleServices.class)
				.path("security/logout")
				.request("application/json")
				.header("some-header", "true")
				.get(String.class);
		
		assertNotNull(jsonString);
		assertTrue(jsonString.contains("success"));
	}

	@Test
	public void testGetUserGroups() {
		fail("Not yet implemented");
	}

}

@@ -798,17 +798,15 @@
 %22, %22
-Quality@6
+sfsfasf
 %22)%0D%0A
@@ -1173,32 +1173,61 @@
 ng.class);%0D%0A%09%09%0D%0A
+%09%09//test with fake password%0D%0A
 %09%09assertNotNull(
@@ -1245,32 +1245,33 @@
 ;%0D%0A%09%09assertTrue(
+!
 jsonString.conta
@@ -1298,85 +1298,8 @@
 %0D%0A%0D%0A
-%09//@Test%0D%0A%09public void testRegister() %7B%0D%0A%09%09fail(%22Not yet implemented%22);%0D%0A%09%7D%0D%0A
 %0D%0A%09@

Test with fake password only