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