1 package org.springframework.richclient.application.support;
2
3 import java.util.HashMap;
4
5 import org.springframework.binding.value.ValueChangeDetector;
6 import org.springframework.binding.value.support.DefaultValueChangeDetector;
7 import org.springframework.context.MessageSource;
8 import org.springframework.context.support.StaticMessageSource;
9 import org.springframework.richclient.application.ServiceNotFoundException;
10 import org.springframework.richclient.image.IconSource;
11 import org.springframework.richclient.test.SpringRichTestCase;
12 import org.springframework.rules.RulesSource;
13
14
15
16
17
18
19
20 public class DefaultApplicationServicesTests extends SpringRichTestCase {
21
22 public void testRegisteredServiceIsReturned() {
23 ValueChangeDetector vcd = new DefaultValueChangeDetector();
24 getApplicationServices().setValueChangeDetector(vcd);
25 assertSame("Expected same object back", vcd, getApplicationServices().getService(ValueChangeDetector.class));
26
27 MessageSource msrc = new StaticMessageSource();
28 getApplicationServices().setMessageSource(msrc);
29 assertSame("Expected same object back", msrc, getApplicationServices().getService(MessageSource.class));
30 }
31
32 public void testUnknownServiceFails() {
33 try {
34 getApplicationServices().getService(getClass());
35 fail("Unknown service should have caused an exception");
36 } catch( ServiceNotFoundException e ) {
37 ;
38 }
39 }
40
41 public void testSetRegistryEntries() {
42 ValueChangeDetector vcd = new DefaultValueChangeDetector();
43 MessageSource msrc = new StaticMessageSource();
44
45 HashMap entries = new HashMap();
46 entries.put("org.springframework.binding.value.ValueChangeDetector", vcd);
47 entries.put("org.springframework.context.MessageSource", msrc);
48
49 getApplicationServices().setRegistryEntries(entries);
50
51 assertSame("Expected same object back", vcd, getApplicationServices().getService(ValueChangeDetector.class));
52 assertSame("Expected same object back", msrc, getApplicationServices().getService(MessageSource.class));
53 }
54
55 public void testDefaultServicesImplementInterface() {
56 Object rulesSource = getApplicationServices().getService(RulesSource.class);
57 assertTrue("Returned service must implement service type", rulesSource instanceof RulesSource);
58
59 Object iconSource = getApplicationServices().getService(IconSource.class);
60 assertTrue("Returned service must implement service type", iconSource instanceof IconSource);
61 }
62 }