1+ package com .baeldung .cxf .introduction ;
2+
3+ import static org .junit .Assert .assertEquals ;
4+
5+ import org .junit .Before ;
6+ import org .junit .Test ;
7+
8+ import java .util .Map ;
9+
10+ import javax .xml .namespace .QName ;
11+ import javax .xml .ws .Service ;
12+ import javax .xml .ws .soap .SOAPBinding ;
13+
14+ import com .baeldung .cxf .introduction .Baeldung ;
15+ import com .baeldung .cxf .introduction .Student ;
16+ import com .baeldung .cxf .introduction .StudentImpl ;
17+
18+ public class StudentTest {
19+ private static QName SERVICE_NAME = new QName ("http://introduction.cxf.baeldung.com/" , "Baeldung" );
20+ private static QName PORT_NAME = new QName ("http://introduction.cxf.baeldung.com/" , "BaeldungPort" );
21+
22+ private Service service ;
23+ private Baeldung baeldungProxy ;
24+ private BaeldungImpl baeldungImpl ;
25+
26+ {
27+ service = Service .create (SERVICE_NAME );
28+ String endpointAddress = "http://localhost:8080/baeldung" ;
29+ service .addPort (PORT_NAME , SOAPBinding .SOAP11HTTP_BINDING , endpointAddress );
30+ }
31+
32+ @ Before
33+ public void reinstantiateBaeldungInstances () {
34+ baeldungImpl = new BaeldungImpl ();
35+ baeldungProxy = service .getPort (PORT_NAME , Baeldung .class );
36+ }
37+
38+ @ Test
39+ public void whenUsingHelloMethod_thenCorrect () {
40+ String endpointResponse = baeldungProxy .hello ("Baeldung" );
41+ String localResponse = baeldungImpl .hello ("Baeldung" );
42+ assertEquals (localResponse , endpointResponse );
43+ }
44+
45+ @ Test
46+ public void whenUsingHelloStudentMethod_thenCorrect () {
47+ Student student = new StudentImpl ("John Doe" );
48+ String endpointResponse = baeldungProxy .helloStudent (student );
49+ String localResponse = baeldungImpl .helloStudent (student );
50+ assertEquals (localResponse , endpointResponse );
51+ }
52+
53+ @ Test
54+ public void usingGetStudentsMethod_thenCorrect () {
55+ Student student1 = new StudentImpl ("Adam" );
56+ baeldungProxy .helloStudent (student1 );
57+
58+ Student student2 = new StudentImpl ("Eve" );
59+ baeldungProxy .helloStudent (student2 );
60+
61+ Map <Integer , Student > students = baeldungProxy .getStudents ();
62+ assertEquals ("Adam" , students .get (1 ).getName ());
63+ assertEquals ("Eve" , students .get (2 ).getName ());
64+ }
65+ }
0 commit comments