Felix Meschberger | 42764b8 | 2009-08-18 07:51:00 +0000 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 19 | package org.apache.felix.cm.integration; |
| 20 | |
| 21 | |
| 22 | import junit.framework.TestCase; |
| 23 | |
Felix Meschberger | 8659e39 | 2009-08-19 05:46:49 +0000 | [diff] [blame^] | 24 | import org.apache.felix.cm.integration.helper.ManagedServiceTestActivator; |
Felix Meschberger | 42764b8 | 2009-08-18 07:51:00 +0000 | [diff] [blame] | 25 | import org.junit.Test; |
| 26 | import org.junit.runner.RunWith; |
| 27 | import org.ops4j.pax.exam.junit.JUnit4TestRunner; |
| 28 | import org.osgi.framework.BundleException; |
| 29 | |
| 30 | |
| 31 | @RunWith(JUnit4TestRunner.class) |
| 32 | public 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 Meschberger | 8659e39 | 2009-08-19 05:46:49 +0000 | [diff] [blame^] | 43 | final ManagedServiceTestActivator tester = ManagedServiceTestActivator.INSTANCE; |
Felix Meschberger | 42764b8 | 2009-08-18 07:51:00 +0000 | [diff] [blame] | 44 | 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 Meschberger | 8659e39 | 2009-08-19 05:46:49 +0000 | [diff] [blame^] | 51 | TestCase.assertEquals( "Expect no update call", 1, tester.numManagedServiceUpdatedCalls ); |
Felix Meschberger | 42764b8 | 2009-08-18 07:51:00 +0000 | [diff] [blame] | 52 | |
| 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 Meschberger | 8659e39 | 2009-08-19 05:46:49 +0000 | [diff] [blame^] | 59 | TestCase.assertEquals( "Expect a single update call", 2, tester.numManagedServiceUpdatedCalls ); |
Felix Meschberger | 42764b8 | 2009-08-18 07:51:00 +0000 | [diff] [blame] | 60 | |
| 61 | // stop the bundle now |
| 62 | bundle.stop(); |
| 63 | |
| 64 | // assert INSTANCE is null |
Felix Meschberger | 8659e39 | 2009-08-19 05:46:49 +0000 | [diff] [blame^] | 65 | TestCase.assertNull( ManagedServiceTestActivator.INSTANCE ); |
Felix Meschberger | 42764b8 | 2009-08-18 07:51:00 +0000 | [diff] [blame] | 66 | |
| 67 | delay(); |
| 68 | |
| 69 | // start the bundle again (and check) |
| 70 | bundle.start(); |
Felix Meschberger | 8659e39 | 2009-08-19 05:46:49 +0000 | [diff] [blame^] | 71 | final ManagedServiceTestActivator tester2 = ManagedServiceTestActivator.INSTANCE; |
Felix Meschberger | 42764b8 | 2009-08-18 07:51:00 +0000 | [diff] [blame] | 72 | 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 Meschberger | 8659e39 | 2009-08-19 05:46:49 +0000 | [diff] [blame^] | 80 | TestCase.assertEquals( "Expect a second update call", 1, tester2.numManagedServiceUpdatedCalls ); |
Felix Meschberger | 42764b8 | 2009-08-18 07:51:00 +0000 | [diff] [blame] | 81 | |
| 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 Meschberger | 8659e39 | 2009-08-19 05:46:49 +0000 | [diff] [blame^] | 100 | final ManagedServiceTestActivator tester = ManagedServiceTestActivator.INSTANCE; |
Felix Meschberger | 42764b8 | 2009-08-18 07:51:00 +0000 | [diff] [blame] | 101 | 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 Meschberger | 8659e39 | 2009-08-19 05:46:49 +0000 | [diff] [blame^] | 108 | TestCase.assertEquals( "Expect no update call", 1, tester.numManagedServiceUpdatedCalls ); |
Felix Meschberger | 42764b8 | 2009-08-18 07:51:00 +0000 | [diff] [blame] | 109 | |
| 110 | // stop the bundle now |
| 111 | bundle.stop(); |
| 112 | |
| 113 | // assert INSTANCE is null |
Felix Meschberger | 8659e39 | 2009-08-19 05:46:49 +0000 | [diff] [blame^] | 114 | TestCase.assertNull( ManagedServiceTestActivator.INSTANCE ); |
Felix Meschberger | 42764b8 | 2009-08-18 07:51:00 +0000 | [diff] [blame] | 115 | |
| 116 | delay(); |
| 117 | |
| 118 | // start the bundle again (and check) |
| 119 | bundle.start(); |
Felix Meschberger | 8659e39 | 2009-08-19 05:46:49 +0000 | [diff] [blame^] | 120 | final ManagedServiceTestActivator tester2 = ManagedServiceTestActivator.INSTANCE; |
Felix Meschberger | 42764b8 | 2009-08-18 07:51:00 +0000 | [diff] [blame] | 121 | 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 Meschberger | 8659e39 | 2009-08-19 05:46:49 +0000 | [diff] [blame^] | 129 | TestCase.assertEquals( "Expect a second update call", 1, tester2.numManagedServiceUpdatedCalls ); |
Felix Meschberger | 42764b8 | 2009-08-18 07:51:00 +0000 | [diff] [blame] | 130 | |
| 131 | // cleanup |
| 132 | bundle.uninstall(); |
| 133 | bundle = null; |
| 134 | |
| 135 | // remove the configuration for good |
| 136 | deleteConfig( pid ); |
| 137 | } |
| 138 | } |