Skip to content

Commit

Permalink
Add tests for menu items
Browse files Browse the repository at this point in the history
Fixes #430 - controller tests
Fixes #431 - renderer tests
  • Loading branch information
dickschoeller committed Jun 18, 2017
1 parent 676b796 commit 59b849e
Show file tree
Hide file tree
Showing 21 changed files with 114,518 additions and 29 deletions.
2 changes: 1 addition & 1 deletion gedbrowser-renderer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
<build>
<testResources>
<testResource>
<directory>src/test/java</directory>
<directory>src/test/resources</directory>
<filtering>false</filtering>
<includes>
<include>**/*.ged</include>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public interface IndexHrefRenderer<T extends GedObject> {
*/
T getGedObject();


/**
* @return the href string to the index page containing this person.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,11 @@ public Collection<String> getLetters() {
logger.info("Ending getLetters");
return indexLetters;
}

/**
* @return the href string to the same page were we are now
*/
public String getIndexHref() {
return "surnames?db=" + getGedObject().getDbName() + "&letter=" + base;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,88 @@ public void testHeadRenderer() throws IOException {
final int expected = 6;
assertEquals("should not be empty", expected, attrRenderers.size());
}

/**
* Test whether the menu items are as expected.
*
* @throws IOException if can't read data file
*/
@Test
public void testHeaderMenuItem() throws IOException {
final Root root = reader.readFileTestSource();
for (final Head head : root.find(Head.class)) {
final HeadRenderer renderer = createRenderer(head);
assertEquals("head href mismatch",
"head?db=gl120368", renderer.getHeaderHref());
}
}

/**
* Test whether the menu items are as expected.
*
* @throws IOException if can't read data file
*/
@Test
public void testIndexMenuItem() throws IOException {
final Root root = reader.readFileTestSource();
for (final Head head : root.find(Head.class)) {
final HeadRenderer renderer = createRenderer(head);
assertEquals("index href mismatch",
"surnames?db=gl120368&letter=A", renderer.getIndexHref());
}
}

/**
* Test whether the menu items are as expected.
*
* @throws IOException if can't read data file
*/
@Test
public void testLivingMenuItem() throws IOException {
final Root root = reader.readFileTestSource();
for (final Head head : root.find(Head.class)) {
final HeadRenderer renderer = createRenderer(head);
assertEquals("living href mismatch",
"living?db=gl120368", renderer.getLivingHref());
}
}

/**
* Test whether the menu items are as expected.
*
* @throws IOException if can't read data file
*/
@Test
public void testSourcesMenuItem() throws IOException {
final Root root = reader.readFileTestSource();
for (final Head head : root.find(Head.class)) {
final HeadRenderer renderer = createRenderer(head);
assertEquals("sources href mismatch",
"sources?db=gl120368", renderer.getSourcesHref());
}
}

/**
* Test whether the menu items are as expected.
*
* @throws IOException if can't read data file
*/
@Test
public void testSubmittorsMenuItem() throws IOException {
final Root root = reader.readFileTestSource();
for (final Head head : root.find(Head.class)) {
final HeadRenderer renderer = createRenderer(head);
assertEquals("submittors href mismatch",
"submittors?db=gl120368", renderer.getSubmittorsHref());
}
}

/**
* @param head the head to render
* @return the renderer
*/
private HeadRenderer createRenderer(final Head head) {
return new HeadRenderer(head, new GedRendererFactory(),
anonymousContext);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,74 @@ public void testIndexBase() throws IOException {
anonymousContext);
assertEquals("Mismatch index letter", "S", ir.getBase());
}

/**
* Test whether the menu items are as expected.
*
* @throws IOException if can't read data file
*/
@Test
public void testHeaderMenuItem() throws IOException {
final Root root = reader.readFileTestSource();
final IndexRenderer renderer = new IndexRenderer(root, "A",
anonymousContext);
assertEquals("head href mismatch",
"head?db=gl120368", renderer.getHeaderHref());
}

/**
* Test whether the menu items are as expected.
*
* @throws IOException if can't read data file
*/
@Test
public void testIndexMenuItem() throws IOException {
final Root root = reader.readFileTestSource();
final IndexRenderer renderer = new IndexRenderer(root, "A",
anonymousContext);
assertEquals("index href mismatch",
"surnames?db=gl120368&letter=A", renderer.getIndexHref());
}

/**
* Test whether the menu items are as expected.
*
* @throws IOException if can't read data file
*/
@Test
public void testLivingMenuItem() throws IOException {
final Root root = reader.readFileTestSource();
final IndexRenderer renderer = new IndexRenderer(root, "A",
anonymousContext);
assertEquals("living href mismatch",
"living?db=gl120368", renderer.getLivingHref());
}

/**
* Test whether the menu items are as expected.
*
* @throws IOException if can't read data file
*/
@Test
public void testSourcesMenuItem() throws IOException {
final Root root = reader.readFileTestSource();
final IndexRenderer renderer = new IndexRenderer(root, "A",
anonymousContext);
assertEquals("submittors href mismatch",
"sources?db=gl120368", renderer.getSourcesHref());
}

/**
* Test whether the menu items are as expected.
*
* @throws IOException if can't read data file
*/
@Test
public void testSubmittorsMenuItem() throws IOException {
final Root root = reader.readFileTestSource();
final IndexRenderer renderer = new IndexRenderer(root, "A",
anonymousContext);
assertEquals("sources href mismatch",
"submittors?db=gl120368", renderer.getSubmittorsHref());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,75 @@ private boolean checkBucketRanges(final int limit, final int expectedLower,
}
return (expectedLower < limit);
}


/**
* Test whether the menu items are as expected.
*
* @throws IOException if can't read data file
*/
@Test
public void testHeaderMenuItem() throws IOException {
final Root root1 = reader.readFileTestSource();
final LivingRenderer renderer = new LivingRenderer(root1,
userContext);
assertEquals("head href mismatch",
"head?db=gl120368", renderer.getHeaderHref());
}

/**
* Test whether the menu items are as expected.
*
* @throws IOException if can't read data file
*/
@Test
public void testIndexMenuItem() throws IOException {
final Root root1 = reader.readFileTestSource();
final LivingRenderer renderer = new LivingRenderer(root1,
userContext);
assertEquals("index href mismatch",
"surnames?db=gl120368&letter=A", renderer.getIndexHref());
}

/**
* Test whether the menu items are as expected.
*
* @throws IOException if can't read data file
*/
@Test
public void testLivingMenuItem() throws IOException {
final Root root1 = reader.readFileTestSource();
final LivingRenderer renderer = new LivingRenderer(root1,
userContext);
assertEquals("living href mismatch",
"living?db=gl120368", renderer.getLivingHref());
}

/**
* Test whether the menu items are as expected.
*
* @throws IOException if can't read data file
*/
@Test
public void testSourcesMenuItem() throws IOException {
final Root root1 = reader.readFileTestSource();
final LivingRenderer renderer = new LivingRenderer(root1,
userContext);
assertEquals("submittors href mismatch",
"sources?db=gl120368", renderer.getSourcesHref());
}

/**
* Test whether the menu items are as expected.
*
* @throws IOException if can't read data file
*/
@Test
public void testSubmittorsMenuItem() throws IOException {
final Root root1 = reader.readFileTestSource();
final LivingRenderer renderer = new LivingRenderer(root1,
userContext);
assertEquals("sources href mismatch",
"submittors?db=gl120368", renderer.getSubmittorsHref());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static org.junit.Assert.assertTrue;

import java.io.IOException;
import java.util.Collection;
import java.util.List;

import org.junit.Before;
Expand Down Expand Up @@ -1424,6 +1425,98 @@ public void testVivianAttributesAdmin() throws IOException {
assertEquals("Attribute list size mismatch",
expectedLength, personRenderer.getAttributes().size());
}

/**
* Test whether the menu items are as expected.
*
* @throws IOException if can't read data file
*/
@Test
public void testHeaderMenuItem() throws IOException {
final Root root = reader.readFileTestSource();
final Collection<Person> persons = root.find(Person.class);
for (final Person person : persons) {
final PersonRenderer renderer = createRenderer(person);
assertEquals("head href mismatch",
"head?db=gl120368", renderer.getHeaderHref());
}
}

/**
* Test whether the menu items are as expected.
*
* @throws IOException if can't read data file
*/
@Test
public void testIndexMenuItem() throws IOException {
final Root root = reader.readFileTestSource();
final Collection<Person> persons = root.find(Person.class);
for (final Person person : persons) {
final PersonRenderer renderer = createRenderer(person);
final String expected = "surnames?db=gl120368&letter=";
final int expectedLength = expected.length();
assertEquals("index href mismatch",
expected,
renderer.getIndexHref().substring(0, expectedLength));
}
}

/**
* Test whether the menu items are as expected.
*
* @throws IOException if can't read data file
*/
@Test
public void testLivingMenuItem() throws IOException {
final Root root = reader.readFileTestSource();
final Collection<Person> persons = root.find(Person.class);
for (final Person person : persons) {
final PersonRenderer renderer = createRenderer(person);
assertEquals("living href mismatch",
"living?db=gl120368", renderer.getLivingHref());
}
}

/**
* Test whether the menu items are as expected.
*
* @throws IOException if can't read data file
*/
@Test
public void testSourcesMenuItem() throws IOException {
final Root root = reader.readFileTestSource();
final Collection<Person> persons = root.find(Person.class);
for (final Person person : persons) {
final PersonRenderer renderer = createRenderer(person);
assertEquals("sources href mismatch",
"sources?db=gl120368", renderer.getSourcesHref());
}
}

/**
* Test whether the menu items are as expected.
*
* @throws IOException if can't read data file
*/
@Test
public void testSubmittorsMenuItem() throws IOException {
final Root root = reader.readFileTestSource();
final Collection<Person> persons = root.find(Person.class);
for (final Person person : persons) {
final PersonRenderer renderer = createRenderer(person);
assertEquals("submittors href mismatch",
"submittors?db=gl120368", renderer.getSubmittorsHref());
}
}

/**
* @param person the person
* @return the renderer
*/
private PersonRenderer createRenderer(final Person person) {
return new PersonRenderer(person,
new GedRendererFactory(), userContext);
}
// TODO test tree rendering for Vivian both Admin and Anon

// TODO test renderAsSection and renderAsListItem
Expand Down
Loading

0 comments on commit 59b849e

Please sign in to comment.