Commit e8ec943c authored by Piotr Gawron's avatar Piotr Gawron
Browse files

when searching for element that doesn't exist return empty list instead of NPE

parent bf084656
......@@ -245,7 +245,10 @@ public class SearchService implements ISearchService {
if (query.startsWith(REACTION_SEARCH_PREFIX)) {
return getReactionById(model, query.replaceFirst(REACTION_SEARCH_PREFIX, "").toLowerCase());
} else if (query.startsWith(SPECIES_SEARCH_PREFIX)) {
result.add(fullAliasViewFactory.create(model.getElementByElementId(query.replaceFirst(SPECIES_SEARCH_PREFIX, ""))));
Element element = model.getElementByElementId(query.replaceFirst(SPECIES_SEARCH_PREFIX, ""));
if (element !=null) {
result.add(fullAliasViewFactory.create(element));
}
} else if (query.startsWith(ELEMENT_SEARCH_PREFIX)) {
return getElementById(model, query.replaceFirst(ELEMENT_SEARCH_PREFIX, "").toLowerCase());
} else {
......
......@@ -139,20 +139,35 @@ public class SearchServiceTest extends ServiceTestFunctions {
}
}
@Test
public void testSearchByElementId() throws Exception {
try {
Model model = createFullModel();
Element element =model.getElements().iterator().next();
element.setId(907);
SearchElementResult global = searchService.searchByQuery(model, "element:907", 50, null, "127.0.0.1");
assertNotNull(global);
assertEquals(1, global.size());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testSearchByElementId() throws Exception {
try {
Model model = createFullModel();
Element element =model.getElements().iterator().next();
element.setId(907);
SearchElementResult global = searchService.searchByQuery(model, "element:907", 50, null, "127.0.0.1");
assertNotNull(global);
assertEquals(1, global.size());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testSearchByUnknwonElementId() throws Exception {
try {
Model model = createFullModel();
Element element =model.getElements().iterator().next();
element.setId(907);
SearchElementResult global = searchService.searchByQuery(model, "species:90111117", 50, null, "127.0.0.1");
assertNotNull(global);
assertEquals(0, global.size());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testSearchByName4() throws Exception {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment