001package edu.pdx.cs.joy.family;
002
003import org.junit.jupiter.api.Assertions;
004import static org.junit.jupiter.api.Assertions.assertTrue;
005import static org.junit.jupiter.api.Assertions.assertNull;
006import org.junit.jupiter.api.Test;
007
008import java.rmi.RemoteException;
009import java.util.Date;
010
011/**
012 * This class tests the functionality of implementors of
013 * <code>RemotePerson</code>.  Note that it just looks up a
014 * <code>RemotePerson</code> in the RMI namespace.  It doesn't pay any
015 * matter what the concrete implementation of
016 * <code>RemotePerson</code> is.
017 */
018public class RemotePersonTest extends RemoteTestCase {
019
020  @Test
021  public void testGetId() throws RemoteException{
022    RemoteFamilyTree tree = getTree();
023    assertTrue(tree.createPerson(Person.MALE).getId() >= 0);
024  }
025
026  @Test
027  public void testGetGenderMale() throws RemoteException {
028    RemotePerson male = getTree().createPerson(Person.MALE);
029    Assertions.assertEquals(Person.MALE, male.getGender());
030  }
031
032  @Test
033  public void testGetGenderFemale() throws RemoteException {
034    RemotePerson female = getTree().createPerson(Person.FEMALE);
035    Assertions.assertEquals(Person.FEMALE, female.getGender());
036  }
037
038  @Test
039  public void testGetFirstName() throws RemoteException {
040    RemotePerson person = getTree().createPerson(Person.FEMALE);
041    String firstName = "firstName";
042    person.setFirstName(firstName);
043    Assertions.assertEquals(firstName, person.getFirstName());
044  }
045
046  @Test
047  public void testGetFirstNameNull() throws RemoteException {
048    RemotePerson person = getTree().createPerson(Person.FEMALE);
049    assertNull(person.getFirstName());
050  }
051
052  @Test
053  public void testGetMiddleName() throws RemoteException {
054    RemotePerson person = getTree().createPerson(Person.FEMALE);
055    String middleName = "middleName";
056    person.setMiddleName(middleName);
057    Assertions.assertEquals(middleName, person.getMiddleName());
058  }
059
060  @Test
061  public void testGetMiddleNameNull() throws RemoteException {
062    RemotePerson person = getTree().createPerson(Person.FEMALE);
063    assertNull(person.getMiddleName());
064  }
065
066  @Test
067  public void testGetLastName() throws RemoteException {
068    RemotePerson person = getTree().createPerson(Person.FEMALE);
069    String lastName = "lastName";
070    person.setLastName(lastName);
071    Assertions.assertEquals(lastName, person.getLastName());
072  }
073
074  @Test
075  public void testGetLastNameNull() throws RemoteException {
076    RemotePerson person = getTree().createPerson(Person.FEMALE);
077    assertNull(person.getLastName());
078  }
079
080  @Test
081  public void testGetFatherId() throws RemoteException {
082    RemoteFamilyTree tree = getTree();
083    RemotePerson person = tree.createPerson(Person.MALE);
084    RemotePerson father = tree.createPerson(Person.MALE);
085    person.setFatherId(father.getId());
086
087    Assertions.assertEquals(father.getId(), person.getFatherId());
088  }
089
090  @Test
091  public void testSetFatherIdBadId() throws RemoteException {
092    RemoteFamilyTree tree = getTree();
093    RemotePerson person = tree.createPerson(Person.MALE);
094    try {
095      person.setFatherId(40000);
096      Assertions.fail("Should have thrown FamilyTreeException");
097
098    } catch (FamilyTreeException ex) {
099      // pass...
100    }
101  }
102
103  @Test
104  public void testSetFatherIdNotMale() throws RemoteException {
105    RemoteFamilyTree tree = getTree();
106    RemotePerson person = tree.createPerson(Person.MALE);
107    RemotePerson father = tree.createPerson(Person.FEMALE);
108
109    try {
110      person.setFatherId(father.getId());
111      Assertions.fail("Should have thrown an FamilyTreeException");
112
113    } catch (FamilyTreeException ex) {
114      // pass...
115    }
116  }
117
118  @Test
119  public void testGetMotherId() throws RemoteException {
120    RemoteFamilyTree tree = getTree();
121    RemotePerson person = tree.createPerson(Person.MALE);
122    RemotePerson mother = tree.createPerson(Person.FEMALE);
123    person.setMotherId(mother.getId());
124
125    Assertions.assertEquals(mother.getId(), person.getMotherId());
126  }
127
128  @Test
129  public void testSetMotherIdBadId() throws RemoteException {
130    RemoteFamilyTree tree = getTree();
131    RemotePerson person = tree.createPerson(Person.MALE);
132    try {
133      person.setMotherId(40000);
134      Assertions.fail("Should have thrown FamilyTreeException");
135
136    } catch (FamilyTreeException ex) {
137      // pass...
138    }
139  }
140
141  @Test
142  public void testSetMotherIdNotFemale() throws RemoteException {
143    RemoteFamilyTree tree = getTree();
144    RemotePerson person = tree.createPerson(Person.MALE);
145    RemotePerson mother = tree.createPerson(Person.MALE);
146
147    try {
148      person.setMotherId(mother.getId());
149      Assertions.fail("Should have thrown an FamilyTreeException");
150
151    } catch (FamilyTreeException ex) {
152      // pass...
153    }
154  }
155
156  @Test
157  public void testSetDateOfBirth() throws RemoteException {
158    Date dob = new Date();
159    RemotePerson person = getTree().createPerson(Person.MALE);
160    person.setDateOfBirth(dob);
161    assertEquals(dob, person.getDateOfBirth());
162  }
163
164  @Test
165  public void testSetDateOfDeath() throws RemoteException {
166    Date dob = new Date();
167    RemotePerson person = getTree().createPerson(Person.MALE);
168    person.setDateOfDeath(dob);
169    assertEquals(dob, person.getDateOfDeath());
170  }
171
172}