Improved test to check the organization filter
This commit is contained in:
parent
7a0dbf48a9
commit
06930ba4e1
|
@ -69,48 +69,56 @@ public class CKANPackageTest extends ContextTest {
|
||||||
parameters.put(CKANPackage.START_KEY, String.valueOf(0));
|
parameters.put(CKANPackage.START_KEY, String.valueOf(0));
|
||||||
|
|
||||||
boolean[] values = new boolean[]{true, false};
|
boolean[] values = new boolean[]{true, false};
|
||||||
|
for(boolean includeValidOrganization : values) {
|
||||||
for(boolean includeFakeOrganization : values) {
|
for(boolean includeFakeOrganization : values) {
|
||||||
|
|
||||||
MultivaluedMap<String,String> queryParameters = new MultivaluedHashMap<>();
|
|
||||||
if(includeFakeOrganization) {
|
|
||||||
queryParameters.add(GCatConstants.Q_KEY, "organization:ckand4scienceharvest OR organization:"+ckanOrganizationName);
|
|
||||||
}else {
|
|
||||||
queryParameters.add(GCatConstants.Q_KEY, "organization:"+ckanOrganizationName);
|
|
||||||
}
|
|
||||||
// parameters.put(GCatConstants.Q_KEY, "organization:ckand4scienceharvest");
|
|
||||||
// parameters.put(GCatConstants.Q_KEY, "organization:dorne");
|
|
||||||
|
|
||||||
/*
|
|
||||||
queryParameters.add(CKANPackage.ROWS_KEY, String.valueOf(10));
|
|
||||||
queryParameters.add(CKANPackage.START_KEY, String.valueOf(0));
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
MultivaluedMap<String,String> queryParameters = new MultivaluedHashMap<>();
|
||||||
parameters.put("fl","[\"name\"]");
|
StringWriter stringWriter = new StringWriter();
|
||||||
*/
|
|
||||||
|
boolean addOr = false;
|
||||||
/*
|
|
||||||
parameters.put("facet.field","[\"name\"]");
|
|
||||||
parameters.put("sort","name asc");
|
|
||||||
*/
|
|
||||||
|
|
||||||
try {
|
|
||||||
parameters = ckanPackage.checkListParameters(queryParameters, parameters);
|
|
||||||
}catch (ForbiddenException e) {
|
|
||||||
if(includeFakeOrganization) {
|
if(includeFakeOrganization) {
|
||||||
// This is the expected behaviour
|
stringWriter.append("organization:fakeorganization");
|
||||||
continue;
|
addOr = true;
|
||||||
}else {
|
|
||||||
throw e;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(includeValidOrganization) {
|
||||||
|
if(addOr) {
|
||||||
|
stringWriter.append(" OR ");
|
||||||
|
}
|
||||||
|
stringWriter.append("organization:");
|
||||||
|
stringWriter.append(ckanOrganizationName);
|
||||||
|
}
|
||||||
|
|
||||||
|
String filter = stringWriter.toString();
|
||||||
|
if(filter.length()>0) {
|
||||||
|
queryParameters.add(GCatConstants.Q_KEY, filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
parameters.put("fl","[\"name\"]");
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
parameters.put("facet.field","[\"name\"]");
|
||||||
|
parameters.put("sort","name asc");
|
||||||
|
*/
|
||||||
|
|
||||||
|
try {
|
||||||
|
parameters = ckanPackage.checkListParameters(queryParameters, parameters);
|
||||||
|
}catch (ForbiddenException e) {
|
||||||
|
if(includeFakeOrganization) {
|
||||||
|
// This is the expected behaviour
|
||||||
|
continue;
|
||||||
|
}else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String ret = ckanPackage.list(parameters);
|
||||||
|
JsonNode gotList = mapper.readTree(ret);
|
||||||
|
Assert.assertTrue(gotList instanceof ArrayNode);
|
||||||
|
|
||||||
|
logger.debug("List :\n{}", mapper.writeValueAsString(gotList));
|
||||||
}
|
}
|
||||||
|
|
||||||
String ret = ckanPackage.list(parameters);
|
|
||||||
JsonNode gotList = mapper.readTree(ret);
|
|
||||||
Assert.assertTrue(gotList instanceof ArrayNode);
|
|
||||||
|
|
||||||
logger.debug("List :\n{}", mapper.writeValueAsString(gotList));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue