Exemplo n.º 1
0
  @Test
  public void addSetMembers() throws Exception {
    ConceptSetRow conceptRow = new ConceptSetRow();
    conceptRow.name = "New concept";
    conceptRow.conceptClass = "New Class";
    conceptRow.description = "some description";

    List<KeyValue> children = new ArrayList<>();
    children.add(new KeyValue("1", "Child1"));
    children.add(new KeyValue("2", "Child2"));
    conceptRow.children = children;
    Messages persistErrorMessages = conceptSetPersister.persist(conceptRow);
    assertTrue(persistErrorMessages.isEmpty());
    Context.openSession();
    Context.authenticate("admin", "test");
    Concept persistedConcept = conceptService.getConceptByName(conceptRow.name);
    assertNotNull(persistedConcept);
    assertEquals(conceptRow.name, persistedConcept.getName(Context.getLocale()).getName());
    assertEquals(conceptRow.conceptClass, persistedConcept.getConceptClass().getName());
    assertEquals("some description", persistedConcept.getDescription().getDescription());

    assertEquals(2, persistedConcept.getSetMembers().size());
    assertEquals("some description", persistedConcept.getDescription().getDescription());
    assertEquals(0, persistedConcept.getSynonyms().size());
    assertTrue(persistedConcept.isSet());
    Context.flushSession();
    Context.closeSession();
  }
Exemplo n.º 2
0
  @Test
  public void should_fail_to_persist_if_conceptSetRow_introduces_cycle() throws Exception {
    ConceptSetRow row1 = new ConceptSetRow();
    row1.name = "ConceptA";
    row1.conceptClass = "New Class";
    row1.description = "some description";
    List<KeyValue> children = new ArrayList<>();
    children.add(new KeyValue("1", "Child1"));
    children.add(new KeyValue("2", "Child2"));
    row1.children = children;

    Messages persistErrorMessages = conceptSetPersister.persist(row1);
    assertTrue(persistErrorMessages.isEmpty());
    Context.openSession();
    Context.authenticate("admin", "test");
    Concept persistedConcept = conceptService.getConceptByName(row1.name);
    assertNotNull(persistedConcept);

    ConceptSetRow row2 = new ConceptSetRow();
    row2.name = "Child2";
    row2.conceptClass = "New Class";
    row2.description = "some description";
    List<KeyValue> children1 = new ArrayList<>();
    children1.add(new KeyValue("1", "ConceptA"));
    children1.add(new KeyValue("2", "Child3"));
    row2.children = children1;

    Messages persistErrorMessages1 = conceptSetPersister.persist(row2);
    assertFalse(persistErrorMessages1.isEmpty());

    Context.flushSession();
    Context.closeSession();
  }
Exemplo n.º 3
0
 @Test
 public void shouldPersistNewConceptSetWithNameClassDescriptionInputOnly() throws Exception {
   ConceptSetRow conceptRow = new ConceptSetRow();
   conceptRow.name = "New concept";
   conceptRow.conceptClass = "New Class";
   conceptRow.description = "some description";
   Messages persistErrorMessages = conceptSetPersister.persist(conceptRow);
   assertTrue(persistErrorMessages.isEmpty());
   Context.openSession();
   Context.authenticate("admin", "test");
   Concept persistedConcept = conceptService.getConceptByName(conceptRow.name);
   assertNotNull(persistedConcept);
   assertEquals(conceptRow.name, persistedConcept.getName(Context.getLocale()).getName());
   assertEquals(conceptRow.conceptClass, persistedConcept.getConceptClass().getName());
   assertEquals("some description", persistedConcept.getDescription().getDescription());
   assertEquals(0, persistedConcept.getSynonyms().size());
   assertTrue(persistedConcept.isSet());
   Context.flushSession();
   Context.closeSession();
 }