*/
public class QueryParamsTest {
@Test
public void shouldBuildQuery() {
QueryParams queryParams = new QueryParamsImpl();
String queryPath = "";
//add empty
{
queryPath = queryParams.buildQuery();
//
assertThat(queryPath, equalTo(""));
}
//add one Parameter
{
queryParams.clear();
queryParams.append(QueryParams.IDENTITY_ID_PARAM.setValue("1234"));
queryPath = queryParams.buildQuery();
//
final String expectedQuery1 = "identity_id=1234";
assertThat(queryPath, equalTo(expectedQuery1));
}
//add two Parameter
{
queryParams.clear();
queryParams.append(QueryParams.IDENTITY_ID_PARAM.setValue("1234")).append(QueryParams.NUMBER_OF_COMMENTS_PARAM.setValue(2));
queryPath = queryParams.buildQuery();
//
/*final String expectedQuery = "identity_id=1234&poster_identity=1&number_of_comments=10&number_of_likes=5" +
"&activity_stream=t&limit=20&since_id=234567&max_id=345678";*/
final String expectedQuery2 = "identity_id=1234&number_of_comments=2";
assertThat(queryPath, equalTo(expectedQuery2));
}
//Remove parameter
{
queryParams.clear();
queryParams.append(QueryParams.IDENTITY_ID_PARAM.setValue("1234"));
queryParams.remove(QueryParams.IDENTITY_ID_PARAM);
queryPath = queryParams.buildQuery();
//
final String expectedQuery3 = "";
assertThat(queryPath, equalTo(expectedQuery3));
}
//add the Query Param Option which is existing.
{
queryParams.clear();
queryParams.append(QueryParams.IDENTITY_ID_PARAM.setValue("1234")).append(QueryParams.NUMBER_OF_COMMENTS_PARAM.setValue(5));
queryPath = queryParams.buildQuery();
final String expectedQuery4 = "identity_id=1234&number_of_comments=5";
assertThat("QueryParamOption which is existing", queryPath, equalTo(expectedQuery4));
}
//add all parameter
{
queryParams.clear();
queryParams.append(QueryParams.IDENTITY_ID_PARAM.setValue("1234"))
.append(QueryParams.POSTER_IDENTITY_PARAM.setValue("1"))
.append(QueryParams.NUMBER_OF_COMMENTS_PARAM.setValue(10))
.append(QueryParams.NUMBER_OF_LIKES_PARAM.setValue(5))
.append(QueryParams.ACTIVITY_STREAM_PARAM.setValue("t"))
.append(QueryParams.LIMIT_PARAM.setValue(20))
.append(QueryParams.SINCE_ID_PARAM.setValue("234567"))
.append(QueryParams.MAX_ID_PARAM.setValue("345678"));
queryPath = queryParams.buildQuery();
final String expectedQuery5 = "identity_id=1234&poster_identity=1&number_of_comments=10&number_of_likes=5" +
"&activity_stream=t&limit=20&since_id=234567&max_id=345678";
assertThat("All of QueryParamOption which is existing", queryPath, equalTo(expectedQuery5));