1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.tck.testmodels.services; |
8 | |
|
9 | |
import org.mule.api.component.simple.EchoService; |
10 | |
import org.mule.api.lifecycle.Disposable; |
11 | |
import org.mule.tck.functional.FunctionalTestComponent; |
12 | |
import org.mule.util.StringUtils; |
13 | |
|
14 | |
import java.util.Collections; |
15 | |
import java.util.Date; |
16 | |
import java.util.HashMap; |
17 | |
import java.util.Map; |
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
public class TestServiceComponent extends FunctionalTestComponent |
23 | |
implements EchoService, DateService, PeopleService, Disposable |
24 | |
{ |
25 | |
|
26 | |
|
27 | |
|
28 | 0 | private static final Person[] originalPeople = new Person[]{new Person("Barney", "Rubble"), |
29 | |
new Person("Fred", "Flintstone"), new Person("Wilma", "Flintstone")}; |
30 | |
|
31 | 0 | private final Map people = Collections.synchronizedMap(new HashMap()); |
32 | |
|
33 | |
public TestServiceComponent() |
34 | |
{ |
35 | 0 | super(); |
36 | 0 | people.put("Barney", originalPeople[0]); |
37 | 0 | people.put("Fred", originalPeople[1]); |
38 | 0 | people.put("Wilma", originalPeople[2]); |
39 | 0 | } |
40 | |
|
41 | |
public String echo(String echo) |
42 | |
{ |
43 | 0 | return echo; |
44 | |
} |
45 | |
|
46 | |
public String getDate() |
47 | |
{ |
48 | 0 | return new Date().toString(); |
49 | |
} |
50 | |
|
51 | |
public Person getPerson(String firstName) |
52 | |
{ |
53 | 0 | if (StringUtils.isEmpty(firstName)) |
54 | |
{ |
55 | 0 | throw new IllegalArgumentException("Name parameter cannot be null"); |
56 | |
} |
57 | 0 | return (Person)people.get(firstName); |
58 | |
} |
59 | |
|
60 | |
public Person[] getPeople() |
61 | |
{ |
62 | 0 | return originalPeople; |
63 | |
} |
64 | |
|
65 | |
public void addPerson(Person person) throws Exception |
66 | |
{ |
67 | 0 | if (person == null || person.getFirstName() == null || person.getLastName() == null) |
68 | |
{ |
69 | 0 | throw new IllegalArgumentException("null person, first name or last name"); |
70 | |
} |
71 | 0 | if (person.getFirstName().equals("Ross")) |
72 | |
{ |
73 | 0 | throw new Exception("Ross is banned"); |
74 | |
} |
75 | 0 | people.put(person.getFirstName(), person); |
76 | 0 | logger.debug("Added Person: " + person); |
77 | 0 | } |
78 | |
|
79 | |
public Person addPerson(String firstname, String surname) throws Exception |
80 | |
{ |
81 | 0 | Person p = new Person(firstname, surname); |
82 | 0 | addPerson(p); |
83 | 0 | logger.debug("Added Person: " + p); |
84 | 0 | return p; |
85 | |
} |
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
public void dispose() |
93 | |
{ |
94 | 0 | people.clear(); |
95 | 0 | } |
96 | |
|
97 | |
} |