blob: 1a4257f5c425c1a9d978d35f478dc38d5f834bf4 [file] [log] [blame]
Felix Meschberger42764b82009-08-18 07:51:00 +00001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19package org.apache.felix.cm.integration;
20
21
22import junit.framework.TestCase;
23
Felix Meschberger8659e392009-08-19 05:46:49 +000024import org.apache.felix.cm.integration.helper.ManagedServiceTestActivator;
Felix Meschberger42764b82009-08-18 07:51:00 +000025import org.junit.Test;
26import org.junit.runner.RunWith;
27import org.ops4j.pax.exam.junit.JUnit4TestRunner;
28import org.osgi.framework.BundleException;
29
30
31@RunWith(JUnit4TestRunner.class)
32public class ConfigurationBaseTest extends ConfigurationTestBase
33{
34
35 @Test
36 public void test_start_bundle_configure_stop_start_bundle() throws BundleException
37 {
38 String pid = "test_start_bundle_configure_stop_start_bundle";
39
40 // start the bundle and assert this
41 bundle = installBundle( pid );
42 bundle.start();
Felix Meschberger8659e392009-08-19 05:46:49 +000043 final ManagedServiceTestActivator tester = ManagedServiceTestActivator.INSTANCE;
Felix Meschberger42764b82009-08-18 07:51:00 +000044 TestCase.assertNotNull( "Activator not started !!", tester );
45
46 // give cm time for distribution
47 delay();
48
49 // assert activater has no configuration
50 TestCase.assertNull( "Expect no Properties after Service Registration", tester.props );
Felix Meschberger8659e392009-08-19 05:46:49 +000051 TestCase.assertEquals( "Expect no update call", 1, tester.numManagedServiceUpdatedCalls );
Felix Meschberger42764b82009-08-18 07:51:00 +000052
53 // configure after ManagedServiceRegistration --> configure via update
54 configure( pid );
55 delay();
56
57 // assert activater has configuration
58 TestCase.assertNotNull( "Expect Properties after Service Registration", tester.props );
Felix Meschberger8659e392009-08-19 05:46:49 +000059 TestCase.assertEquals( "Expect a single update call", 2, tester.numManagedServiceUpdatedCalls );
Felix Meschberger42764b82009-08-18 07:51:00 +000060
61 // stop the bundle now
62 bundle.stop();
63
64 // assert INSTANCE is null
Felix Meschberger8659e392009-08-19 05:46:49 +000065 TestCase.assertNull( ManagedServiceTestActivator.INSTANCE );
Felix Meschberger42764b82009-08-18 07:51:00 +000066
67 delay();
68
69 // start the bundle again (and check)
70 bundle.start();
Felix Meschberger8659e392009-08-19 05:46:49 +000071 final ManagedServiceTestActivator tester2 = ManagedServiceTestActivator.INSTANCE;
Felix Meschberger42764b82009-08-18 07:51:00 +000072 TestCase.assertNotNull( "Activator not started the second time!!", tester2 );
73 TestCase.assertNotSame( "Instances must not be the same", tester, tester2 );
74
75 // give cm time for distribution
76 delay();
77
78 // assert activater has configuration
79 TestCase.assertNotNull( "Expect Properties after Service Registration", tester2.props );
Felix Meschberger8659e392009-08-19 05:46:49 +000080 TestCase.assertEquals( "Expect a second update call", 1, tester2.numManagedServiceUpdatedCalls );
Felix Meschberger42764b82009-08-18 07:51:00 +000081
82 // cleanup
83 bundle.uninstall();
84 bundle = null;
85
86 // remove the configuration for good
87 deleteConfig( pid );
88 }
89
90
91 @Test
92 public void test_configure_start_bundle_stop_start_bundle() throws BundleException
93 {
94 String pid = "test_configure_start_bundle_stop_start_bundle";
95 configure( pid );
96
97 // start the bundle and assert this
98 bundle = installBundle( pid );
99 bundle.start();
Felix Meschberger8659e392009-08-19 05:46:49 +0000100 final ManagedServiceTestActivator tester = ManagedServiceTestActivator.INSTANCE;
Felix Meschberger42764b82009-08-18 07:51:00 +0000101 TestCase.assertNotNull( "Activator not started !!", tester );
102
103 // give cm time for distribution
104 delay();
105
106 // assert activater has configuration
107 TestCase.assertNotNull( "Expect Properties after Service Registration", tester.props );
Felix Meschberger8659e392009-08-19 05:46:49 +0000108 TestCase.assertEquals( "Expect no update call", 1, tester.numManagedServiceUpdatedCalls );
Felix Meschberger42764b82009-08-18 07:51:00 +0000109
110 // stop the bundle now
111 bundle.stop();
112
113 // assert INSTANCE is null
Felix Meschberger8659e392009-08-19 05:46:49 +0000114 TestCase.assertNull( ManagedServiceTestActivator.INSTANCE );
Felix Meschberger42764b82009-08-18 07:51:00 +0000115
116 delay();
117
118 // start the bundle again (and check)
119 bundle.start();
Felix Meschberger8659e392009-08-19 05:46:49 +0000120 final ManagedServiceTestActivator tester2 = ManagedServiceTestActivator.INSTANCE;
Felix Meschberger42764b82009-08-18 07:51:00 +0000121 TestCase.assertNotNull( "Activator not started the second time!!", tester2 );
122 TestCase.assertNotSame( "Instances must not be the same", tester, tester2 );
123
124 // give cm time for distribution
125 delay();
126
127 // assert activater has configuration
128 TestCase.assertNotNull( "Expect Properties after Service Registration", tester2.props );
Felix Meschberger8659e392009-08-19 05:46:49 +0000129 TestCase.assertEquals( "Expect a second update call", 1, tester2.numManagedServiceUpdatedCalls );
Felix Meschberger42764b82009-08-18 07:51:00 +0000130
131 // cleanup
132 bundle.uninstall();
133 bundle = null;
134
135 // remove the configuration for good
136 deleteConfig( pid );
137 }
138}