Search in sources :

Example 1 with SkipBaseSetup

use of org.openmrs.test.SkipBaseSetup in project openmrs-core by openmrs.

the class UserServiceTest method getUserByUuid_shouldFetchUserWithGivenUuid.

@Test
@SkipBaseSetup
public void getUserByUuid_shouldFetchUserWithGivenUuid() throws SQLException {
    initializeInMemoryDatabase();
    executeDataSet(XML_FILENAME);
    authenticate();
    User user = userService.getUserByUuid("013c49c6-e132-11de-babe-001e378eb67e");
    assertEquals("Did not fetch user with given uuid", user, userService.getUser(5505));
}
Also used : User(org.openmrs.User) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) SkipBaseSetup(org.openmrs.test.SkipBaseSetup)

Example 2 with SkipBaseSetup

use of org.openmrs.test.SkipBaseSetup in project openmrs-core by openmrs.

the class PatientServiceTest method shouldGetPatientsByIdentifierAndIdentifierType.

/**
 * Test the PatientService.getPatients(String, String, List) method with both an identifier and
 * an identifiertype
 *
 * @throws Exception
 */
@Test
@SkipBaseSetup
public void shouldGetPatientsByIdentifierAndIdentifierType() throws Exception {
    initializeInMemoryDatabase();
    executeDataSet(FIND_PATIENTS_XML);
    authenticate();
    updateSearchIndex();
    List<PatientIdentifierType> types = new ArrayList<>();
    types.add(new PatientIdentifierType(1));
    // make sure we get back only one patient
    List<Patient> patients = patientService.getPatients("1234", null, types, false);
    assertEquals(1, patients.size());
    // make sure we get back only one patient
    patients = patientService.getPatients("1234", null, null, false);
    assertEquals(1, patients.size());
    // make sure we can search a padded identifier
    patients = patientService.getPatients("00000001234", null, null, false);
    assertEquals(1, patients.size());
}
Also used : ArrayList(java.util.ArrayList) Patient(org.openmrs.Patient) PatientIdentifierType(org.openmrs.PatientIdentifierType) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test) SkipBaseSetup(org.openmrs.test.SkipBaseSetup)

Example 3 with SkipBaseSetup

use of org.openmrs.test.SkipBaseSetup in project openmrs-core by openmrs.

the class PatientServiceTest method purgePatient_shouldDeletePatientFromDatabase.

@SkipBaseSetup
@Test
public void purgePatient_shouldDeletePatientFromDatabase() throws Exception {
    initializeInMemoryDatabase();
    executeDataSet(FIND_PATIENTS_XML);
    authenticate();
    // verify patient with ID 2 exists in database
    Patient patientToPurge = patientService.getPatient(2);
    assertNotNull(patientToPurge);
    // purge the patient
    patientService.purgePatient(patientToPurge);
    // if the patient doesn't exist in the database, getPatient should
    // return null now
    assertNull(patientService.getPatient(2));
}
Also used : Patient(org.openmrs.Patient) SkipBaseSetup(org.openmrs.test.SkipBaseSetup) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 4 with SkipBaseSetup

use of org.openmrs.test.SkipBaseSetup in project openmrs-core by openmrs.

the class UserServiceTest method createUser_shouldShouldCreateUserWhoIsPatientAlready.

@Test
@SkipBaseSetup
public void createUser_shouldShouldCreateUserWhoIsPatientAlready() throws SQLException {
    // create the basic user and give it full rights
    initializeInMemoryDatabase();
    // authenticate to the temp database
    authenticate();
    assertTrue("The context needs to be correctly authenticated to by a user", Context.isAuthenticated());
    // add in some basic data
    executeDataSet(XML_FILENAME);
    // the user should not exist yet
    User preliminaryFetchedUser = userService.getUser(2);
    assertNull(preliminaryFetchedUser);
    // get the person object we'll make into a user
    Person personToMakeUser = Context.getPersonService().getPerson(2);
    // this avoids a lazy init exception, since we're going to clear the session
    ((Patient) personToMakeUser).getIdentifiers().size();
    Context.clearSession();
    // this is the user object we'll be saving
    User user = new User(personToMakeUser);
    user.setUsername("bwolfe");
    user.setSystemId("asdf");
    // included in xml file
    user.addRole(new Role("Some Role", "This is a test role"));
    // make sure everything was added to the user correctly
    assertTrue(user.getUsername().equals("bwolfe"));
    assertTrue(user.hasRole("Some Role"));
    // do the actual creating of the user object
    userService.createUser(user, "Openmr5xy");
    Assert.assertNotNull("User was not created", userService.getUser(user.getUserId()));
    Integer shouldCreateUserWhoIsPatientAlreadyTestUserIdCreated = user.getUserId();
    Context.flushSession();
    // get the same user we just created and make sure the user portion exists
    User fetchedUser = userService.getUser(shouldCreateUserWhoIsPatientAlreadyTestUserIdCreated);
    User fetchedUser3 = userService.getUser(3);
    if (fetchedUser3 != null) {
        throw new RuntimeException("There is a user with id #3");
    }
    assertNotNull("Uh oh, the user object was not created", fetchedUser);
    assertNotNull("Uh oh, the username was not saved", fetchedUser.getUsername());
    assertTrue("Uh oh, the username was not saved", fetchedUser.getUsername().equals("bwolfe"));
    assertTrue("Uh oh, the role was not assigned", fetchedUser.hasRole("Some Role"));
    Context.clearSession();
    List<User> allUsers = userService.getAllUsers();
    assertEquals(11, allUsers.size());
    // there should still only be the one patient we created in the xml file
    List<Patient> allPatientsSet = Context.getPatientService().getAllPatients();
    assertEquals(1, allPatientsSet.size());
}
Also used : Role(org.openmrs.Role) User(org.openmrs.User) Patient(org.openmrs.Patient) Person(org.openmrs.Person) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) SkipBaseSetup(org.openmrs.test.SkipBaseSetup)

Aggregations

Test (org.junit.Test)4 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)4 SkipBaseSetup (org.openmrs.test.SkipBaseSetup)4 Patient (org.openmrs.Patient)3 User (org.openmrs.User)2 PatientServiceImplTest (org.openmrs.api.impl.PatientServiceImplTest)2 ArrayList (java.util.ArrayList)1 PatientIdentifierType (org.openmrs.PatientIdentifierType)1 Person (org.openmrs.Person)1 Role (org.openmrs.Role)1