|
22 | 22 |
|
23 | 23 | import static org.junit.Assert.assertEquals; |
24 | 24 |
|
25 | | -@RunWith(Arquillian.class) public class EmployeeServiceLiveTest { |
26 | | - |
27 | | - private static final String APP_NAME = "jee7"; |
28 | | - private static final String WSDL_PATH = "EmployeeService?wsdl"; |
29 | | - private static QName SERVICE_NAME = new QName("http://jaxws.baeldung.com/", "EmployeeService"); |
30 | | - private static URL wsdlUrl; |
31 | | - |
32 | | - @ArquillianResource private URL deploymentUrl; |
33 | | - |
34 | | - private EmployeeService employeeServiceProxy; |
35 | | - |
36 | | - @Deployment(testable = false) public static WebArchive createDeployment() { |
37 | | - return ShrinkWrap.create(WebArchive.class, APP_NAME + ".war").addPackage(EmployeeService.class.getPackage()).addPackage(Employee.class.getPackage()).addPackage(EmployeeNotFound.class.getPackage()) |
38 | | - .addPackage(EmployeeRepository.class.getPackage()).addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); |
39 | | - } |
40 | | - |
41 | | - @Before public void setUp() { |
42 | | - try { |
43 | | - wsdlUrl = new URL(deploymentUrl, WSDL_PATH); |
44 | | - } catch (MalformedURLException e) { |
45 | | - e.printStackTrace(); |
46 | | - } |
47 | | - |
48 | | - Service service = Service.create(wsdlUrl, SERVICE_NAME); |
49 | | - employeeServiceProxy = service.getPort(EmployeeService.class); |
50 | | - } |
51 | | - |
52 | | - @Test public void givenGetAllEmployees_thenCorrectNumberOfEmployeesReturned() { |
53 | | - int employeeCount = employeeServiceProxy.countEmployees(); |
54 | | - List<Employee> employeeList = employeeServiceProxy.getAllEmployees(); |
55 | | - assertEquals(employeeList.size(), employeeCount); |
56 | | - } |
57 | | - |
58 | | - @Test public void givenEmployeeId_whenEmployeeExists_thenCorrectEmployeeReturned() throws EmployeeNotFound { |
59 | | - Employee employee = employeeServiceProxy.getEmployee(2); |
60 | | - assertEquals(employee.getFirstName(), "Jack"); |
61 | | - } |
62 | | - |
63 | | - @Test(expected = EmployeeNotFound.class) public void givenEmployeeId_whenEmployeeNotExists_thenEmployeeNotFoundExceptionReturned() throws EmployeeNotFound { |
64 | | - employeeServiceProxy.getEmployee(20); |
65 | | - } |
66 | | - |
67 | | - @Test public void givenAddEmployee_whenEmployeeDoesntAlreadyExist_thenEmployeeCountIncreased() throws EmployeeAlreadyExists { |
68 | | - int employeeCount = employeeServiceProxy.countEmployees(); |
69 | | - employeeServiceProxy.addEmployee(4, "Anna"); |
70 | | - assertEquals(employeeServiceProxy.countEmployees(), employeeCount + 1); |
71 | | - } |
72 | | - |
73 | | - @Test(expected = EmployeeAlreadyExists.class) public void givenAddEmployee_whenEmployeeAlreadyExist_thenEmployeeAlreadyExistsExceptionReturned() throws EmployeeAlreadyExists { |
74 | | - employeeServiceProxy.addEmployee(1, "Anna"); |
75 | | - } |
76 | | - |
77 | | - @Test public void givenUpdateEmployee_whenEmployeeExists_thenUpdatedEmployeeReturned() throws EmployeeNotFound { |
78 | | - Employee updated = employeeServiceProxy.updateEmployee(1, "Joan"); |
79 | | - assertEquals(updated.getFirstName(), "Joan"); |
80 | | - } |
81 | | - |
82 | | - @Test(expected = EmployeeNotFound.class) public void givenUpdateEmployee_whenEmployeeNotExists_thenUpdatedEmployeeReturned() throws EmployeeNotFound { |
83 | | - employeeServiceProxy.updateEmployee(20, "Joan"); |
| 25 | +@RunWith(Arquillian.class) |
| 26 | +public class EmployeeServiceLiveTest { |
| 27 | + |
| 28 | + private static final String APP_NAME = "jee7"; |
| 29 | + private static final String WSDL_PATH = "EmployeeService?wsdl"; |
| 30 | + private static QName SERVICE_NAME = new QName("http://jaxws.baeldung.com/", "EmployeeService"); |
| 31 | + private static URL wsdlUrl; |
| 32 | + |
| 33 | + @ArquillianResource |
| 34 | + private URL deploymentUrl; |
| 35 | + |
| 36 | + private EmployeeService employeeServiceProxy; |
| 37 | + |
| 38 | + @Deployment(testable = false) |
| 39 | + public static WebArchive createDeployment() { |
| 40 | + return ShrinkWrap.create(WebArchive.class, APP_NAME + ".war").addPackage(EmployeeService.class.getPackage()).addPackage(Employee.class.getPackage()).addPackage(EmployeeNotFound.class.getPackage()).addPackage(EmployeeRepository.class.getPackage()) |
| 41 | + .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); |
| 42 | + } |
| 43 | + |
| 44 | + @Before |
| 45 | + public void setUp() { |
| 46 | + try { |
| 47 | + wsdlUrl = new URL(deploymentUrl, WSDL_PATH); |
| 48 | + } catch (MalformedURLException e) { |
| 49 | + e.printStackTrace(); |
84 | 50 | } |
85 | 51 |
|
86 | | - @Test public void givenDeleteEmployee_whenEmployeeExists_thenCorrectStatusReturned() throws EmployeeNotFound { |
87 | | - boolean deleteEmployee = employeeServiceProxy.deleteEmployee(3); |
88 | | - assertEquals(deleteEmployee, true); |
89 | | - } |
90 | | - |
91 | | - @Test(expected = EmployeeNotFound.class) public void givenDeleteEmployee_whenEmployeeNotExists_thenEmployeeNotFoundExceptionReturned() throws EmployeeNotFound { |
92 | | - employeeServiceProxy.deleteEmployee(20); |
93 | | - } |
| 52 | + Service service = Service.create(wsdlUrl, SERVICE_NAME); |
| 53 | + employeeServiceProxy = service.getPort(EmployeeService.class); |
| 54 | + } |
| 55 | + |
| 56 | + @Test |
| 57 | + public void givenGetAllEmployees_thenCorrectNumberOfEmployeesReturned() { |
| 58 | + int employeeCount = employeeServiceProxy.countEmployees(); |
| 59 | + List<Employee> employeeList = employeeServiceProxy.getAllEmployees(); |
| 60 | + assertEquals(employeeList.size(), employeeCount); |
| 61 | + } |
| 62 | + |
| 63 | + @Test |
| 64 | + public void givenEmployeeId_whenEmployeeExists_thenCorrectEmployeeReturned() throws EmployeeNotFound { |
| 65 | + Employee employee = employeeServiceProxy.getEmployee(2); |
| 66 | + assertEquals(employee.getFirstName(), "Jack"); |
| 67 | + } |
| 68 | + |
| 69 | + @Test(expected = EmployeeNotFound.class) |
| 70 | + public void givenEmployeeId_whenEmployeeNotExists_thenEmployeeNotFoundExceptionReturned() throws EmployeeNotFound { |
| 71 | + employeeServiceProxy.getEmployee(20); |
| 72 | + } |
| 73 | + |
| 74 | + @Test |
| 75 | + public void givenAddEmployee_whenEmployeeDoesntAlreadyExist_thenEmployeeCountIncreased() throws EmployeeAlreadyExists { |
| 76 | + int employeeCount = employeeServiceProxy.countEmployees(); |
| 77 | + employeeServiceProxy.addEmployee(4, "Anna"); |
| 78 | + assertEquals(employeeServiceProxy.countEmployees(), employeeCount + 1); |
| 79 | + } |
| 80 | + |
| 81 | + @Test(expected = EmployeeAlreadyExists.class) |
| 82 | + public void givenAddEmployee_whenEmployeeAlreadyExist_thenEmployeeAlreadyExistsExceptionReturned() throws EmployeeAlreadyExists { |
| 83 | + employeeServiceProxy.addEmployee(1, "Anna"); |
| 84 | + } |
| 85 | + |
| 86 | + @Test |
| 87 | + public void givenUpdateEmployee_whenEmployeeExists_thenUpdatedEmployeeReturned() throws EmployeeNotFound { |
| 88 | + Employee updated = employeeServiceProxy.updateEmployee(1, "Joan"); |
| 89 | + assertEquals(updated.getFirstName(), "Joan"); |
| 90 | + } |
| 91 | + |
| 92 | + @Test(expected = EmployeeNotFound.class) |
| 93 | + public void givenUpdateEmployee_whenEmployeeNotExists_thenUpdatedEmployeeReturned() throws EmployeeNotFound { |
| 94 | + employeeServiceProxy.updateEmployee(20, "Joan"); |
| 95 | + } |
| 96 | + |
| 97 | + @Test |
| 98 | + public void givenDeleteEmployee_whenEmployeeExists_thenCorrectStatusReturned() throws EmployeeNotFound { |
| 99 | + boolean deleteEmployee = employeeServiceProxy.deleteEmployee(3); |
| 100 | + assertEquals(deleteEmployee, true); |
| 101 | + } |
| 102 | + |
| 103 | + @Test(expected = EmployeeNotFound.class) |
| 104 | + public void givenDeleteEmployee_whenEmployeeNotExists_thenEmployeeNotFoundExceptionReturned() throws EmployeeNotFound { |
| 105 | + employeeServiceProxy.deleteEmployee(20); |
| 106 | + } |
94 | 107 |
|
95 | 108 | } |
0 commit comments