serviceTests.CountEmployeesTestNGTest.java Source code

Java tutorial

Introduction

Here is the source code for serviceTests.CountEmployeesTestNGTest.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package serviceTests;

import com.pharmacy.pharmacyweb.configuration.ConnectionConfig;
import com.pharmacy.pharmacyweb.domain.staff.Cashier;
import com.pharmacy.pharmacyweb.domain.staff.Doctor;
import com.pharmacy.pharmacyweb.domain.staff.ITSupport;
import com.pharmacy.pharmacyweb.domain.staff.Packer;
import com.pharmacy.pharmacyweb.domain.staff.StaffMember;
import com.pharmacy.pharmacyweb.domain.staff.StoreManager;
import com.pharmacy.pharmacyweb.repository.CashierRepository;
import com.pharmacy.pharmacyweb.repository.DoctorRepository;
import com.pharmacy.pharmacyweb.repository.ITSupportRepository;
import com.pharmacy.pharmacyweb.repository.PackerRepository;
import com.pharmacy.pharmacyweb.repository.StaffMemberRepository;
import com.pharmacy.pharmacyweb.repository.StoreManagerRepository;
import com.pharmacy.pharmacyweb.services.Impl.CountEmployees;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import static org.testng.Assert.*;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

/**
 *
 * @author J3nny
 */
public class CountEmployeesTestNGTest {
    public static ApplicationContext ctx;
    private static CashierRepository cashierRepo;
    private static DoctorRepository doctorRepo;
    private static ITSupportRepository iTSupportRepo;
    private static PackerRepository packerRepo;
    private static StaffMemberRepository staffMemberRepo;
    private static StoreManagerRepository storeManagerRepo;
    private static CountEmployees counter;

    public CountEmployeesTestNGTest() {
    }

    // TODO add test methods here.
    // The methods must be annotated with annotation @Test. For example:
    //
    // @Test
    // public void hello() {}

    @BeforeClass
    public static void setUpClass() throws Exception {
        ctx = new AnnotationConfigApplicationContext(ConnectionConfig.class);
        counter = new CountEmployees();

        cashierRepo = ctx.getBean(CashierRepository.class);
        doctorRepo = ctx.getBean(DoctorRepository.class);
        iTSupportRepo = ctx.getBean(ITSupportRepository.class);
        packerRepo = ctx.getBean(PackerRepository.class);
        staffMemberRepo = ctx.getBean(StaffMemberRepository.class);
        storeManagerRepo = ctx.getBean(StoreManagerRepository.class);

        cashierRepo.deleteAll();
        doctorRepo.deleteAll();
        iTSupportRepo.deleteAll();
        packerRepo.deleteAll();
        staffMemberRepo.deleteAll();
        storeManagerRepo.deleteAll();

        StoreManager storeManager = new StoreManager.Builder().id(0).name("Kurt").Surname("Davids")
                .position("StoreManager").age(22).contactNumber("0800223450").build();

        StaffMember staffMember = new StaffMember.Builder().id(0).name("Colijn").Surname("Hahndiek")
                .position("StaffMember").age(22).contactNumber("0800123450").build();

        Packer packer = new Packer.Builder().id(0).name("Robyn").Surname("Davids").position("Packer").age(22)
                .contactNumber("0800123459").build();

        ITSupport iTSupport = new ITSupport.Builder().id(0).name("Wesley").surname("De Wet").position("ITSupport")
                .age(22).contactNumber("0800123458").build();

        Doctor doctor = new Doctor.Builder().id(0).name("Taswell").Surname("Salie").position("Doctor").age(22)
                .contactNumber("0800123457").build();

        Cashier cashier = new Cashier.Builder().id(0).name("Alexander").surname("Daniels").position("Cashier")
                .age(22).contactNumber("0800123456").build();

        cashierRepo.save(cashier);
        doctorRepo.save(doctor);
        iTSupportRepo.save(iTSupport);
        packerRepo.save(packer);
        staffMemberRepo.save(staffMember);
        storeManagerRepo.save(storeManager);
    }

    @AfterClass
    public static void tearDownClass() throws Exception {
    }

    @BeforeMethod
    public void setUpMethod() throws Exception {
    }

    @AfterMethod
    public void tearDownMethod() throws Exception {
    }

    @Test
    public void countEmployeesTest() {
        assertEquals(counter.count(), 6);
    }

}