Commit 2625ac8b authored by Ricco Førgaard's avatar Ricco Førgaard

Added Level 2.

Level 2 is about searching.
parent fb16e489
...@@ -26,5 +26,4 @@ public class Level01 { ...@@ -26,5 +26,4 @@ public class Level01 {
assertEquals("nesstar-nightly", server.getId()); assertEquals("nesstar-nightly", server.getId());
} }
} }
package com.nesstar.tutorial;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import com.nesstar.api.NesstarObject;
import com.nesstar.api.Server;
import com.nesstar.api.Study;
import com.nesstar.api.Variable;
import com.nesstar.api.search.SearchQuery;
import com.nesstar.api.search.SearchResult;
import com.nesstar.api.search.SearchResultItem;
/**
* Nesstar API Tutorial Level 2
* ============================
*
* This tutorial will teach you about searching.
*
* You need to connect to the server as you learned
* on Level 1.
*
*/
public class Level02 {
private Server server;
/**
* Here you can connect to the server once and for all.
*/
@Before
public void connectToServer() {
server = null;
}
/**
* Do a simple search for the term "employment". It should
* return 1 study.
*
*/
@Test
public void performSimpleSearch() {
SearchQuery query = new SearchQuery();
SearchResult result = null;
assertEquals(1, result.getListOfHits());
assertEquals("some studylabel here", result.getListOfHits().get(0).getLabel());
}
/**
* Now search for the term "<term that appears in one study and 1 or more other objects>".
* Tell the search query to return Studies only.
*
*/
@Test
public void searchForStudy() {
SearchQuery query = new SearchQuery();
SearchResult result = null;
assertEquals(1, result.getListOfHits().size());
NesstarObject study = result.getListOfHits().get(0).getObject();
assertTrue(study instanceof Study);
}
/**
* If your search returns many hits, you can tell the
* search query to limit the number of results. Try
* searching for the term "<very common term here>" and
* limit the results to 5 hits.
*/
@Test
public void limitNumberOfSearchResults() {
SearchQuery query = new SearchQuery();
SearchResult result = null;
assertEquals(5, result.getListOfHits().size());
}
/**
* This time you need to do a more complex search. The term
* to search for is "<some term>" but you must use the exclude
* method to narrow your search down to 1 result.
*/
@Test
public void searchWithBooleanOperators() {
SearchQuery query = new SearchQuery();
SearchResult result = null;
assertEquals(1, result.getListOfHits().size());
}
/**
* Now you must find all studies that were authored by
* Han Solo.
* Hint: use the DDI, Luke!
*/
@Test
public void searchInSpecificDDIelements() {
SearchQuery query = new SearchQuery();
SearchResult result = null;
assertEquals(1, result.getListOfHits().size());
//assert that author is Han Solo
}
/**
* Finally a challenge. Using the knowlede from the previous
* lessons, you must find 4 variables that have something to
* do with "<term>".
*/
@Test
public void findOnlyVariables() {
SearchQuery query = new SearchQuery();
SearchResult result = null;
List<SearchResultItem> listOfResults = result.getListOfHits();
assertEquals(4, listOfResults.size());
for (int i = 0; i < 4; i++) {
NesstarObject item = listOfResults.get(i).getObject();
assertTrue(item instanceof Variable);
}
}
}
Markdown is supported
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