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

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

public class WebQueryTest
{
	@Test
	public void testEncode()
	{
		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")
		              .encode();
	}
}

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());
	}
}

Update WebQueryTest to test that the encoding of a WebQuery is stable