package com.peterphi.std.guice.hibernate.webquery;

import com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class WebQueryTest
{
	@Test
	public void testEncodeResultStable()
	{
		WebQuery query = new WebQuery()
				                 .orderDesc("id")
				                 .orderAsc("name")
				                 .orderAsc("name2")
				                 .limit(99)
				                 .computeSize(true)
				                 .or(g -> g.eq("id", 1).contains("id", "some_value"))
				                 .eq("name", "x");

		assertEquals(
				"{_compute_size=[true], _expand=[all], _fetch=[entity], _order=[id desc, name asc, name2 asc], _limit=[99], _offset=[0], name=[x], id=[1, _f_contains_some_value]}",
				query.encode().toString());
	}
}

@@ -126,17 +126,86 @@
 rg.j
-unit.Test
+boss.resteasy.spi.ResteasyUriInfo;%0Aimport org.junit.Test;%0A%0Aimport java.net.URI
 ;%0A%0Ai
@@ -882,10 +882,332 @@
 ());%0A%09%7D%0A
+%0A%0A%09@Test%0A%09public void testParseQueryStringToWebQuery()%0A%09%7B%0A%09%09WebQuery expected = new WebQuery().logSQL(true).eq(%22id%22, %22123%22);%0A%09%09WebQuery actual = new WebQuery().decode(new ResteasyUriInfo(URI.create(%22http://example.com?_log_sql=true&id=123%22)));%0A%0A%09%09assertEquals(expected.encode().toString(), actual.encode().toString());%0A%09%7D%0A
 %7D%0A

Add failing unit test to detect cases where setting _log_sql in a Query String results in the decoded WebQuery having expand set to a different value (the same value as _log_sql) due to case fallthrough