Skip to content

Commit

Permalink
Merge pull request #47 from elwyncrestha/feature/help-reply-test
Browse files Browse the repository at this point in the history
Feature: Added help desk reply test
  • Loading branch information
elwyncrestha committed Jul 25, 2020
2 parents eb6f662 + 0534daa commit cec5e92
Showing 1 changed file with 42 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
package com.pemits.webcare.api.helpdesk.repository;

import com.github.springtestdbunit.annotation.DatabaseSetup;
import com.pemits.webcare.BaseJpaTest;
import com.pemits.webcare.api.department.entity.Department;
import com.pemits.webcare.api.helpdesk.entity.HelpDesk;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.emptyString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;

import java.time.LocalDate;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.Matchers.hasSize;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import com.github.springtestdbunit.annotation.DatabaseSetup;
import com.pemits.webcare.BaseJpaTest;
import com.pemits.webcare.api.helpdesk.entity.HelpDesk;

/**
* @Author Mohammad Hussain
Expand All @@ -27,7 +32,7 @@ public class HelpDeskRepositoryTest extends BaseJpaTest {
private static final long MOCK_HELP_DESK_ID_3 = 3;

@Autowired
private HelpDeskRepository helpDeskRepository;
private HelpDeskRepository repository;

@Test
public void testSaveShouldReturnSavedHelpDesk() {
Expand All @@ -37,7 +42,7 @@ public void testSaveShouldReturnSavedHelpDesk() {
helpDesk.setContactNumber("1234567890");
helpDesk.setQuery("My first query");

HelpDesk saved = helpDeskRepository.save(helpDesk);
HelpDesk saved = repository.save(helpDesk);

assertThat(saved.getId(), notNullValue());
}
Expand All @@ -56,18 +61,30 @@ public void testSaveAllShouldReturnAllSavedHelpDesk() {
helpDesk2.setContactNumber("1234567890");
helpDesk2.setQuery("My second query");

List<HelpDesk> saved = helpDeskRepository.saveAll(Arrays.asList(helpDesk1, helpDesk2));
List<HelpDesk> saved = repository.saveAll(Arrays.asList(helpDesk1, helpDesk2));

assertThat(saved, hasSize(2));
assertThat(saved.get(0).getId(), notNullValue());
assertThat(saved.get(1).getId(), notNullValue());
}

@Test
@DatabaseSetup("/dataset/helpdesk/helpdesk-config.xml")
public void testSaveShouldAddHelpDeskReply() {
HelpDesk helpDesk = repository.getOne(MOCK_HELP_DESK_ID_1);

assertThat(helpDesk.getReply(), equalTo(null));

helpDesk.setReply("This is a dummy reply.");
repository.save(helpDesk);

assertThat(repository.getOne(MOCK_HELP_DESK_ID_1).getReply(), not(emptyString()));
}

@Test
@DatabaseSetup("/dataset/helpdesk/helpdesk-config.xml")
public void testFindHelpDeskByIdShouldReturnHelpDesk() {
final Optional<HelpDesk> helpDesk = helpDeskRepository.findById(MOCK_HELP_DESK_ID_1);
final Optional<HelpDesk> helpDesk = repository.findById(MOCK_HELP_DESK_ID_1);

assertThat(helpDesk.isPresent(), equalTo(true));
assertThat(helpDesk.get().getName(), is("Smith"));
Expand All @@ -76,46 +93,46 @@ public void testFindHelpDeskByIdShouldReturnHelpDesk() {
@Test
@DatabaseSetup("/dataset/helpdesk/helpdesk-config.xml")
public void testFindAllShouldReturnNotEmptyList() {
final List<HelpDesk> helpDeskList = helpDeskRepository.findAll();
final List<HelpDesk> helpDeskList = repository.findAll();

assertThat(helpDeskList.size(), greaterThan(0));
}

@Test
@DatabaseSetup("/dataset/helpdesk/helpdesk-config.xml")
public void testGetOneShouldReturnHelpDesk() {
final HelpDesk helpDesk = helpDeskRepository.getOne(MOCK_HELP_DESK_ID_2);
final HelpDesk helpDesk = repository.getOne(MOCK_HELP_DESK_ID_2);

assertThat(helpDesk.getName(), is("Jack"));
}

@Test
@DatabaseSetup("/dataset/helpdesk/helpdesk-config.xml")
public void testDeleteByIdShouldDeleteHelpDesk() {
long count = helpDeskRepository.count();
long count = repository.count();

helpDeskRepository.deleteById(MOCK_HELP_DESK_ID_3);
repository.deleteById(MOCK_HELP_DESK_ID_3);

assertThat(helpDeskRepository.findAll(), hasSize((int) count - 1));
assertThat(repository.findAll(), hasSize((int) count - 1));
}

@Test
@DatabaseSetup("/dataset/helpdesk/helpdesk-config.xml")
public void testDeleteShouldDeleteHelpDesk() {
long count = helpDeskRepository.count();
long count = repository.count();

final HelpDesk helpDesk = helpDeskRepository.getOne(MOCK_HELP_DESK_ID_2);
helpDeskRepository.delete(helpDesk);
final HelpDesk helpDesk = repository.getOne(MOCK_HELP_DESK_ID_2);
repository.delete(helpDesk);

assertThat(helpDeskRepository.findAll(), hasSize((int) count - 1));
assertThat(repository.findAll(), hasSize((int) count - 1));
}

@Test
@DatabaseSetup("/dataset/helpdesk/helpdesk-config.xml")
public void testDeleteAllShouldReturnCountZero() {
helpDeskRepository.deleteAll();
repository.deleteAll();

assertThat(helpDeskRepository.findAll(), hasSize(0));
assertThat(repository.findAll(), hasSize(0));
}

}

0 comments on commit cec5e92

Please sign in to comment.