01: /*
02: *
03: *
04: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
05: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License version
09: * 2 only, as published by the Free Software Foundation.
10: *
11: * This program is distributed in the hope that it will be useful, but
12: * WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * General Public License version 2 for more details (a copy is
15: * included at /legal/license.txt).
16: *
17: * You should have received a copy of the GNU General Public License
18: * version 2 along with this work; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA
21: *
22: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
23: * Clara, CA 95054 or visit www.sun.com if you need additional
24: * information or have any questions.
25: */
26:
27: package com.sun.midp.services;
28:
29: import com.sun.midp.security.*;
30: import com.sun.midp.links.*;
31: import java.io.*;
32: import java.util.*;
33: import com.sun.cldc.isolate.*;
34: import com.sun.midp.i3test.TestCase;
35:
36: public class TestSystemServiceManager extends TestCase {
37: public final static String SERVICE_ID = "42";
38:
39: private static SecurityToken token = SecurityTokenProvider
40: .getToken();
41:
42: class DummySystemService implements SystemService {
43: boolean wasRequested = false;
44: boolean wasStarted = false;
45: boolean wasStopped = false;
46:
47: public String getServiceID() {
48: return SERVICE_ID;
49: }
50:
51: public void start() {
52: wasStarted = true;
53: }
54:
55: public void stop() {
56: wasStopped = true;
57: }
58:
59: public void acceptConnection(SystemServiceConnection connection) {
60: wasRequested = true;
61: }
62: }
63:
64: void testActual() {
65: SystemServiceManager serviceManager = SystemServiceManager
66: .getInstance(token);
67: DummySystemService service = new DummySystemService();
68: serviceManager.registerService(service);
69:
70: SystemServiceRequestor serviceRequestor = SystemServiceRequestor
71: .getInstance(token);
72: serviceRequestor.requestService(SERVICE_ID);
73:
74: assertTrue("Service started", service.wasStarted);
75: assertTrue("Service requested", service.wasRequested);
76: }
77:
78: /**
79: * Runs all tests.
80: */
81: public void runTests() {
82: declare("testActual");
83: testActual();
84: }
85: }
|