Skip to content

Commit

Permalink
Merge c5356c7 into e715076
Browse files Browse the repository at this point in the history
  • Loading branch information
dickschoeller committed Aug 17, 2018
2 parents e715076 + c5356c7 commit 9d08d56
Show file tree
Hide file tree
Showing 14 changed files with 1,833 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.schoellerfamily.gedbrowser.api.datamodel.ApiNote;
import org.schoellerfamily.gedbrowser.api.datamodel.ApiObject;
import org.schoellerfamily.gedbrowser.datamodel.Note;
import org.schoellerfamily.gedbrowser.persistence.domain.NoteDocument;
import org.schoellerfamily.gedbrowser.persistence.mongo.gedconvert.GedObjectToGedDocumentMongoConverter;
Expand Down Expand Up @@ -54,7 +53,7 @@ public Class<Note> getGedClass() {
* @param note the data for the note
* @return the note as created
*/
public ApiObject createNote(final String db,
public ApiNote createNote(final String db,
final ApiNote note) {
logger.info("Entering create note in db: " + db);
return create(readRoot(db), note, (i, id) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.apache.commons.logging.LogFactory;
import org.schoellerfamily.gedbrowser.api.datamodel.ApiAttribute;
import org.schoellerfamily.gedbrowser.api.datamodel.ApiFamily;
import org.schoellerfamily.gedbrowser.api.datamodel.ApiObject;
import org.schoellerfamily.gedbrowser.api.datamodel.ApiPerson;
import org.schoellerfamily.gedbrowser.persistence.mongo.gedconvert.GedObjectToGedDocumentMongoConverter;
import org.schoellerfamily.gedbrowser.persistence.mongo.loader.GedDocumentFileLoader;
Expand Down Expand Up @@ -34,7 +33,7 @@ public ParentCrud(final GedDocumentFileLoader loader,
* @param person the data for the parent
* @return the person returned from the db
*/
public ApiObject createParent(final String db, final String id,
public ApiPerson createParent(final String db, final String id,
final ApiPerson person) {
logger.info(
"Entering create parent in db: " + db + " for person " + id);
Expand All @@ -52,7 +51,7 @@ public ApiObject createParent(final String db, final String id,
* @param person the data for the spouse
* @return the person returned from the db
*/
public ApiObject linkParent(final String db, final String id,
public ApiPerson linkParent(final String db, final String id,
final ApiPerson person) {
logger.info(
"Entering link person: " + person.getString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.schoellerfamily.gedbrowser.api.datamodel.ApiAttribute;
import org.schoellerfamily.gedbrowser.api.datamodel.ApiObject;
import org.schoellerfamily.gedbrowser.api.datamodel.ApiSource;
import org.schoellerfamily.gedbrowser.datamodel.Source;
import org.schoellerfamily.gedbrowser.persistence.domain.SourceDocument;
Expand Down Expand Up @@ -55,7 +54,7 @@ public Class<Source> getGedClass() {
* @param source the data for the source
* @return the source as created
*/
public ApiObject createSource(final String db,
public ApiSource createSource(final String db,
final ApiSource source) {
logger.info("Entering create source in db: " + db);
return create(readRoot(db), source, (i, id) -> new ApiSource(i, id));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
package org.schoellerfamily.gedbrowser.api.crud.test;

import static org.assertj.core.api.BDDAssertions.then;
import static org.junit.Assert.assertEquals;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.schoellerfamily.gedbrowser.api.Application;
import org.schoellerfamily.gedbrowser.api.crud.ChildCrud;
import org.schoellerfamily.gedbrowser.api.crud.FamilyCrud;
import org.schoellerfamily.gedbrowser.api.crud.PersonCrud;
import org.schoellerfamily.gedbrowser.api.datamodel.ApiFamily;
import org.schoellerfamily.gedbrowser.api.datamodel.ApiPerson;
import org.schoellerfamily.gedbrowser.persistence.mongo.gedconvert.GedObjectToGedDocumentMongoConverter;
import org.schoellerfamily.gedbrowser.persistence.mongo.loader.GedDocumentFileLoader;
import org.schoellerfamily.gedbrowser.persistence.mongo.repository.RepositoryManagerMongo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
* @author Dick Schoeller
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = Application.class,
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@TestPropertySource(properties = {"management.port=0"})
@SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert")
public class ChildCrudTest {
/** Logger. */
private final transient Log logger = LogFactory.getLog(getClass());

/** */
@Autowired
private transient GedDocumentFileLoader loader;

/** */
@Autowired
private transient GedObjectToGedDocumentMongoConverter toDocConverter;

/** */
@Autowired
private transient RepositoryManagerMongo repositoryManager;

/** */
private ChildCrud crud;

/** */
private CrudTestHelper helper;

/** */
@Before
public void setUp() {
helper = new CrudTestHelper(
new PersonCrud(loader, toDocConverter, repositoryManager),
new FamilyCrud(loader, toDocConverter, repositoryManager));
crud = new ChildCrud(loader, toDocConverter, repositoryManager);
}

/** */
@Test
public final void testCreateChild() {
logger.info("Beginning testCreateChildInFamily2");
final ApiPerson parent = helper.createPerson();
final ApiPerson child = createChildOfParent(parent);
logger.info("famc: " + child.getFamc().get(0).getString());
final ApiPerson gotParent = helper.getPerson(parent);
assertEquals("Child should be in family",
child.getFamc().get(0).getString(),
gotParent.getFams().get(0).getString());
}

/** */
@Test
public final void testLinkChildInFamily() {
logger.info("Beginning testLinkChildInFamily");
final ApiPerson parent = helper.createPerson();
final ApiPerson child = createChildOfParent(parent);
String famID = child.getFamc().get(0).getString();
logger.info("famc: " + famID);

final ApiPerson secondChild = helper.createPerson();
crud.linkChildInFamily(helper.getDb(), famID, secondChild);

final ApiFamily family = helper.readFamily(famID);
assertEquals(family.getChildren().get(1).getString(),
secondChild.getString());
}

/** */
@Test
public final void testLinkChild() {
logger.info("Beginning testLinkChild");
final ApiPerson parent = helper.createPerson();
final ApiPerson child = helper.createPerson();
final ApiPerson gotChild = crud.linkChild(helper.getDb(),
parent.getString(), child);
then(gotChild.getString()).isEqualTo(child.getString());
then(gotChild.getFamc().size()).isEqualTo(1);
final ApiPerson gotParent = helper.getPerson(parent);
then(gotParent.getFams().size()).isEqualTo(1);
assertEquals("check ids",
gotParent.getFams().get(0).getString(),
gotChild.getFamc().get(0).getString());
}

/** */
@Test
public final void testUnlinkChild() {
final ApiPerson parent = helper.createPerson();

final ApiPerson child = createChildOfParent(parent);
final String famID = child.getFamc().get(0).getString();
logger.info("famc: " + famID);
crud.unlinkChild(helper.getDb(), famID, child.getString());
final ApiPerson gotChild = helper.getPerson(child);
assertEquals("not in family", 0, gotChild.getFamc().size());
}

private ApiPerson createChildOfParent(final ApiPerson parent) {
final ApiPerson child = helper.buildPerson();
return crud.createChild(helper.getDb(), parent.getString(), child);
}

/** */
@Test
public final void testCreateChildInFamily() {
logger.info("Beginning testCreateChildInFamily");
final ApiPerson reqPerson = helper.createAlexandra();
final ApiPerson resPerson = crud.createChildInFamily(helper.getDb(), "F1", reqPerson);

then(resPerson.getType()).isEqualTo(reqPerson.getType());
then(resPerson.getSurname()).isEqualTo(reqPerson.getSurname());
then(resPerson.getIndexName()).isEqualTo(reqPerson.getIndexName());
then(resPerson.getFamc().get(0).getString()).isEqualTo("F1");
}

/** */
@Test
public final void testCreateChildInFamily2() {
logger.info("Beginning testCreateChildInFamily2");
final ApiPerson reqPerson = helper.createAlexander();
final ApiPerson resPerson = crud.createChildInFamily(helper.getDb(), "F4", reqPerson);
then(resPerson.getType()).isEqualTo(reqPerson.getType());
then(resPerson.getSurname()).isEqualTo(reqPerson.getSurname());
then(resPerson.getIndexName()).isEqualTo(reqPerson.getIndexName());
then(resPerson.getFamc().get(0).getString()).isEqualTo("F4");
}

/** */
@Test
public final void testGetPersonsMiniSchoellerI2AddChild() {
logger.info("Beginning testGetPersonsMiniSchoellerI2AddChild");
final ApiPerson reqChild = helper.createAlexander();
final ApiPerson resChild = crud.createChild("mini-schoeller", "I9",
reqChild);
then(resChild.getType()).isEqualTo(reqChild.getType());
then(resChild.getSurname()).isEqualTo(reqChild.getSurname());
then(resChild.getIndexName()).isEqualTo(reqChild.getIndexName());
}

/** */
@Test
public final void testGetPersonsMiniSchoellerI2AddChild2() {
logger.info("Beginning testGetPersonsMiniSchoellerI2AddChild2");
final ApiPerson reqChild = helper.createAlexandra();
final ApiPerson resChild = crud.createChild("mini-schoeller", "I10",
reqChild);
then(resChild.getType()).isEqualTo(reqChild.getType());
then(resChild.getSurname()).isEqualTo(reqChild.getSurname());
then(resChild.getIndexName()).isEqualTo(reqChild.getIndexName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package org.schoellerfamily.gedbrowser.api.crud.test;

import org.schoellerfamily.gedbrowser.api.crud.FamilyCrud;
import org.schoellerfamily.gedbrowser.api.crud.PersonCrud;
import org.schoellerfamily.gedbrowser.api.datamodel.ApiAttribute;
import org.schoellerfamily.gedbrowser.api.datamodel.ApiFamily;
import org.schoellerfamily.gedbrowser.api.datamodel.ApiPerson;

/**
* @author Dick Schoeller
*/
public class CrudTestHelper {
/** */
private final ApiPerson.Builder builder;

/** */
private final PersonCrud personCrud;

/** */
private final FamilyCrud familyCrud;

CrudTestHelper(final PersonCrud personCrud, final FamilyCrud familyCrud) {
this.personCrud = personCrud;
this.familyCrud = familyCrud;
builder = new ApiPerson.Builder().build();
}

/**
* @return the DB string
*/
public String getDb() {
return "gl120368";
}

/**
* @return the person builder
*/
public ApiPerson.Builder getPersonBuilder() {
return builder;
}

/**
* @return a newly created, very simple person
*/
public ApiPerson createPerson() {
return personCrud.createPerson(getDb(), buildPerson());
}

/**
* @return a new person object
*/
public ApiPerson buildPerson() {
return new ApiPerson(builder);
}

/**
* @param person the person that we are "regetting"
* @return the newly gotten person
*/
public ApiPerson getPerson(final ApiPerson person) {
return personCrud.readPerson(getDb(), person.getString());
}

/**
* @param famID the ID of the family to read
* @return the family
*/
public ApiFamily readFamily(String famID) {
return familyCrud.readFamily(getDb(), famID);
}


/**
* @return the newly created person
*/
public ApiPerson createAlexander() {
final ApiPerson.Builder builder = new ApiPerson.Builder()
.id("")
.add(new ApiAttribute("name", "Alexander/Romanov/", ""))
.add(new ApiAttribute("attribute", "Sex", "M"))
.surname("Romanov")
.indexName("Romanov, Alexander")
.build();
return new ApiPerson(builder);
}

/**
* @return the newly created person
*/
public ApiPerson createAlexandra() {
final ApiPerson.Builder builder = new ApiPerson.Builder()
.id("")
.add(new ApiAttribute("name", "Alexandra/Romanov/", ""))
.add(new ApiAttribute("attribute", "Sex", "F"))
.surname("Romanov")
.indexName("Romanov, Alexandra")
.build();
return new ApiPerson(builder);
}

}
Loading

0 comments on commit 9d08d56

Please sign in to comment.