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 private static final Person[] originalPeople = new Person[]{new Person("Barney", "Rubble"),
29 new Person("Fred", "Flintstone"), new Person("Wilma", "Flintstone")};
30
31 private final Map people = Collections.synchronizedMap(new HashMap());
32
33 public TestServiceComponent()
34 {
35 super();
36 people.put("Barney", originalPeople[0]);
37 people.put("Fred", originalPeople[1]);
38 people.put("Wilma", originalPeople[2]);
39 }
40
41 public String echo(String echo)
42 {
43 return echo;
44 }
45
46 public String getDate()
47 {
48 return new Date().toString();
49 }
50
51 public Person getPerson(String firstName)
52 {
53 if (StringUtils.isEmpty(firstName))
54 {
55 throw new IllegalArgumentException("Name parameter cannot be null");
56 }
57 return (Person)people.get(firstName);
58 }
59
60 public Person[] getPeople()
61 {
62 return originalPeople;
63 }
64
65 public void addPerson(Person person) throws Exception
66 {
67 if (person == null || person.getFirstName() == null || person.getLastName() == null)
68 {
69 throw new IllegalArgumentException("null person, first name or last name");
70 }
71 if (person.getFirstName().equals("Ross"))
72 {
73 throw new Exception("Ross is banned");
74 }
75 people.put(person.getFirstName(), person);
76 logger.debug("Added Person: " + person);
77 }
78
79 public Person addPerson(String firstname, String surname) throws Exception
80 {
81 Person p = new Person(firstname, surname);
82 addPerson(p);
83 logger.debug("Added Person: " + p);
84 return p;
85 }
86
87
88
89
90
91
92 public void dispose()
93 {
94 people.clear();
95 }
96
97 }