package org.sagebionetworks.web.unitclient.place;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;
import org.sagebionetworks.repo.model.ObjectType;
import org.sagebionetworks.web.client.place.ParameterizedPlace;
import org.sagebionetworks.web.client.place.ParameterizedToken;
import org.sagebionetworks.web.client.place.Wiki;

/**
 * Wiki Place token test
 * @author jayhodgson
 *
 */
public class ParameterizedPlaceTest {
	
	@Test
	public void testStandardCase() {
		String testToken = "a=1&b=2&c=&d&";
		ParameterizedPlace place = new ParameterizedPlace(testToken);
		assertEquals("1", place.getParam("a"));
		assertEquals("2", place.getParam("b"));
		assertEquals(null, place.getParam("c"));
		assertEquals(null, place.getParam("d"));
		String newToken = place.toToken();
		assertTrue(newToken.contains("a=1"));
		assertTrue(newToken.contains("b=2"));
		assertTrue(!newToken.endsWith("&"));
	}
	
	@Test
	public void testNoParams() {
		String testToken = "";
		ParameterizedPlace place = new ParameterizedPlace(testToken);
		//revert to the default token
		String newToken = place.toToken();
		assertEquals(newToken, ParameterizedToken.DEFAULT_TOKEN);
	}
	
}

@@ -1186,12 +1186,319 @@
 EN);%0A%09%7D%0A
-%09
+%0A%09@Test%0A%09public void testClearParams() %7B%0A%09%09String testToken = %22a=1&b=2&c=&d&%22;%0A%09%09ParameterizedPlace place = new ParameterizedPlace(testToken);%0A%09%09assertEquals(%221%22, place.getParam(%22a%22));%0A%09%09place.clearParams();%0A%09%09String newToken = place.toToken();%0A%09%09assertEquals(newToken, ParameterizedToken.DEFAULT_TOKEN);%0A%09%7D%0A
 %0A%7D%0A

test clear params