Skip to content

Commit

Permalink
Bindu | BAH-3117 | fix testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
binduak committed Jul 23, 2023
1 parent b7536e3 commit 047d628
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@
import org.bahmni.module.bahmnicore.model.Note;
import org.bahmni.module.bahmnicore.model.NoteType;
import org.bahmni.module.bahmnicore.service.NoteService;
import org.hibernate.HibernateException;
import org.hibernate.PropertyValueException;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.openmrs.DrugOrder;
import org.openmrs.api.APIException;
import org.openmrs.api.context.Context;
import org.openmrs.module.emrapi.encounter.domain.EncounterTransaction;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -27,6 +32,9 @@ public void setUp() throws Exception {
executeDataSet("notesData.xml");
}

@Rule
public ExpectedException expectedException = ExpectedException.none();

@Test
public void shouldCreateNewNoteOfSpecificNoteType() {
NoteService noteService = Context.getService(NoteService.class);
Expand All @@ -36,6 +44,11 @@ public void shouldCreateNewNoteOfSpecificNoteType() {
note.setNoteText("note one");
note.setNoteDate(new Date());
noteService.createNote(note);
assertNotNull(note.getId());
assertNotNull(note.getUuid());
assertEquals(note.getNoteText(), "note one");
assertEquals(note.getNoteType().getName(), "OT module");
assertNotNull(note.getNoteDate());
}

@Test
Expand Down Expand Up @@ -74,30 +87,36 @@ public void shouldGetNoteOfSpecificTypeAndDate() throws Exception {
noteType.setName("OT module");
Note note = new Note();
note.setNoteType(noteType);
note.setLocationId(1);
note.setNoteDate(new Date());
DateFormat format = new SimpleDateFormat("dd/MM/yyyy");
Date date = format.parse("08/08/2023");
List<Note> notes = noteService.getNotes(date,date,"OT module" );
// System.out.println("note1"+note1.getNoteText());
DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
Date date = format.parse("2023-08-16 00:00:00.0");
note.setNoteDate(date);
Note noteResponse = noteService.getNote(date,"OT module" );
assertNotNull(noteResponse);
assertEquals(noteResponse.getNoteText(), "note one");
assertEquals(noteResponse.getNoteType().getName(), "OT module");
assertNotNull(noteResponse.getNoteDate());
}


@Test
public void shouldThrowValidationErrorWhenNoteTypeIsEmpty() {
public void shouldThrowExceptionWhenNoteTypeIsEmpty() throws Exception {
NoteService noteService = Context.getService(NoteService.class);
Note note = new Note();
note.setNoteText("Hello World");
note.setNoteDate(new Date());
expectedException.expect(HibernateException.class);
noteService.createNote(note);
}

@Test
public void shouldThrowValidationErrorWhenNoteDateIsEmpty() {
public void shouldExceptionWhenNoteDateIsEmpty() throws Exception {
NoteService noteService = Context.getService(NoteService.class);
Note note = new Note();
note.setNoteText("Hello World");
note.setNoteDate(new Date());
expectedException.expect(HibernateException.class);
noteService.createNote(note);

}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
//package org.bahmni.module.bahmnicore.validator;
//
//import org.bahmni.module.bahmnicore.model.Note;
//import org.junit.Assert;
//import org.junit.Test;
//import org.openmrs.RelationshipType;
//import org.openmrs.test.BaseContextSensitiveTest;
//import org.openmrs.validator.RelationshipTypeValidator;
//import org.springframework.validation.BindException;
//import org.springframework.validation.Errors;
//
//import static org.junit.jupiter.api.Assertions.*;
//
//public class NoteValidatorTest extends BaseContextSensitiveTest {
//
// public void validate_shouldFailValidationIfaIsToBIsNullOrEmptyOrWhitespace() throws Exception {
// Note type = new Note();
//
// Errors errors = new BindException(type, "type");
// new NoteValidator().validate(type, errors);
// Assert.assertTrue(errors.hasFieldErrors("aIsToB"));
// }
//
//}
package org.bahmni.module.bahmnicore.validator;

import org.bahmni.module.bahmnicore.model.Note;
import org.junit.Assert;
import org.junit.Test;
import org.openmrs.RelationshipType;
import org.openmrs.test.BaseContextSensitiveTest;
import org.openmrs.validator.RelationshipTypeValidator;
import org.springframework.validation.BindException;
import org.springframework.validation.Errors;

import static org.junit.jupiter.api.Assertions.*;

public class NoteValidatorTest extends BaseContextSensitiveTest {

public void validate_shouldFailValidationIfaIsToBIsNullOrEmptyOrWhitespace() throws Exception {
Note type = new Note();

Errors errors = new BindException(type, "type");
new NoteValidator().validate(type, errors);
Assert.assertTrue(errors.hasFieldErrors("aIsToB"));
}

}
14 changes: 10 additions & 4 deletions bahmnicore-omod/src/main/resources/liquibase.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4557,7 +4557,11 @@
</sql>
</changeSet>
<changeSet author="Bindu" id="notes-202307091606">
<!-- !&#45;&#45; precondition &#45;&#45;!-->
<preConditions onFail="MARK_RAN">
<not>
<tableExists tableName="notes"/>
</not>
</preConditions>
<createTable tableName="notes">
<column autoIncrement="true" name="note_id" type="INT">
<constraints nullable="false" primaryKey="true"/>
Expand Down Expand Up @@ -4610,7 +4614,11 @@

</changeSet>
<changeSet author="Bindu" id="note-type-202307101600">
<!-- !&#45;&#45; precondition &#45;&#45;!-->
<preConditions onFail="MARK_RAN">
<not>
<tableExists tableName="note_type"/>
</not>
</preConditions>
<createTable tableName="note_type">
<column defaultValueNumeric="0" name="note_type_id" type="INT">
<constraints nullable="false" primaryKey="true"/>
Expand All @@ -4631,8 +4639,6 @@
<createIndex tableName="note_type" unique="true" indexName="note_type_uuid_index" >
<column name="uuid" />
</createIndex>

</changeSet>

<include file="addAtomfeedMigrations.xml"/>
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.bahmni.module.bahmnicore.web.v1_0.controller;

import org.bahmni.module.bahmnicore.contract.NoteRequest;
import org.bahmni.module.bahmnicore.model.Note;
import org.bahmni.module.bahmnicore.model.NoteType;
import org.bahmni.module.bahmnicore.web.v1_0.BaseIntegrationTest;
Expand All @@ -10,6 +11,7 @@
import static org.junit.Assert.assertEquals;

import java.util.Date;
import java.util.List;

import static org.jcodec.common.Assert.assertNotNull;

Expand All @@ -25,17 +27,15 @@ public void setUp() throws Exception {

@Test
public void createNewNote() throws Exception {
String content = "{\"noteType\": {\"name\": \"OT module\"},\n" +
String content = "{\"noteTypeText\": \"OT module\"},\n" +
"\"noteDate\": \"2023-07-08\",\n" +
"\"text\": \"sample text\"}";
"\"noteText\": \"sample text\"}";

NoteType noteType = new NoteType();
noteType.setName("hello");
Note note = new Note();
note.setNoteType(noteType);
note.setText("Hello World");
bahmniNotesController.save(note);
note.setNoteText("Hello World");
bahmniNotesController.save((List<NoteRequest>) note);
}


}

0 comments on commit 047d628

Please sign in to comment.