use of org.sagebionetworks.repo.model.search.query.KeyValue in project Synapse-Repository-Services by Sage-Bionetworks.
the class SearchControllerTest method testSearch.
@Test
public void testSearch() throws Exception {
// Build a simple query.
SearchQuery query = new SearchQuery();
query.setBooleanQuery(new LinkedList<KeyValue>());
KeyValue kv = new KeyValue();
kv.setKey(SearchConstants.FIELD_ID);
kv.setValue(project.getId());
query.getBooleanQuery().add(kv);
// the mock request
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
request.setMethod("POST");
request.addHeader("Accept", "application/json");
request.addHeader("Content-Type", "application/json");
request.setRequestURI("/search");
request.setParameter(AuthorizationConstants.USER_ID_PARAM, TestUserDAO.TEST_USER_NAME);
request.setContent(EntityFactory.createJSONStringForEntity(query).getBytes("UTF-8"));
DispatchServletSingleton.getInstance().service(request, response);
if (response.getStatus() != HttpStatus.CREATED.value()) {
throw new RuntimeException(response.getContentAsString());
}
SearchResults results = EntityFactory.createEntityFromJSONString(response.getContentAsString(), SearchResults.class);
assertNotNull(results);
assertNotNull(results.getHits());
assertEquals(1l, results.getHits().size());
Hit hit = results.getHits().get(0);
assertNotNull(hit);
assertEquals(project.getId(), hit.getId());
}
use of org.sagebionetworks.repo.model.search.query.KeyValue in project Synapse-Repository-Services by Sage-Bionetworks.
the class IT510SynapseJavaClientSearchTest method testBooleanQuerySearch.
/**
* @throws Exception
*/
@Test
public void testBooleanQuerySearch() throws Exception {
SearchQuery searchQuery = new SearchQuery();
List<String> queryTerms = new ArrayList<String>();
queryTerms.add(distictValue1);
searchQuery.setQueryTerm(queryTerms);
List<String> returnFields = new ArrayList<String>();
returnFields.add("name");
searchQuery.setReturnFields(returnFields);
KeyValue booleanQueryClause = new KeyValue();
booleanQueryClause.setKey("node_type");
booleanQueryClause.setValue("data");
List<KeyValue> booleanQuery = new ArrayList<KeyValue>();
booleanQuery.add(booleanQueryClause);
searchQuery.setBooleanQuery(booleanQuery);
SearchResults results = synapse.search(searchQuery);
assertTrue(1 <= results.getFound());
}
use of org.sagebionetworks.repo.model.search.query.KeyValue in project Synapse-Repository-Services by Sage-Bionetworks.
the class IT510SynapseJavaClientSearchTest method testUpdateACLBooleanQuerySearch.
/**
* @throws Exception
*/
@Ignore
@Test
public void testUpdateACLBooleanQuerySearch() throws Exception {
SearchQuery searchQuery = new SearchQuery();
KeyValue booleanQueryClause = new KeyValue();
booleanQueryClause.setKey("update_acl");
booleanQueryClause.setValue("Sage Curators");
List<KeyValue> booleanQuery = new ArrayList<KeyValue>();
booleanQuery.add(booleanQueryClause);
searchQuery.setBooleanQuery(booleanQuery);
SearchResults results = synapse.search(searchQuery);
assertTrue(1 <= results.getFound());
}
use of org.sagebionetworks.repo.model.search.query.KeyValue in project Synapse-Repository-Services by Sage-Bionetworks.
the class IT510SynapseJavaClientSearchTest method testDescription.
/**
* @throws Exception
*/
@Test
public void testDescription() throws Exception {
// When descriptions are not null, make sure they are not just an empty
// json array (this was an old bug)
SearchQuery searchQuery = new SearchQuery();
List<String> returnFields = new ArrayList<String>();
returnFields.add("description");
searchQuery.setReturnFields(returnFields);
KeyValue booleanQueryClause = new KeyValue();
booleanQueryClause.setKey("node_type");
booleanQueryClause.setValue("*");
List<KeyValue> booleanQuery = new ArrayList<KeyValue>();
booleanQuery.add(booleanQueryClause);
searchQuery.setBooleanQuery(booleanQuery);
SearchResults results = synapse.search(searchQuery);
assertTrue(1 <= results.getFound());
for (Hit hit : results.getHits()) {
String description = hit.getDescription();
if (null != description) {
assertFalse("[]".equals(description));
}
}
}
use of org.sagebionetworks.repo.model.search.query.KeyValue in project Synapse-Repository-Services by Sage-Bionetworks.
the class IT510SynapseJavaClientSearchTest method testBadSearch.
@Test
public void testBadSearch() throws ServletException, IOException, JSONException, JSONObjectAdapterException, InterruptedException {
// First run query
SearchQuery query = new SearchQuery();
query.setBooleanQuery(new LinkedList<KeyValue>());
KeyValue kv = new KeyValue();
kv.setKey("ugh");
kv.setValue(project.getId());
query.getBooleanQuery().add(kv);
// this should throw an error
try {
synapse.search(query);
fail("This was a bad query");
} catch (SynapseException e) {
// did we get the expected message.
assertTrue(e.getMessage().indexOf("'ugh' is not defined in the metadata for this collection") > 0);
assertFalse("The error message contains the URL of the search index", e.getMessage().indexOf("http://search") > 0);
}
}
Aggregations