import org.osgi.service.component.annotations.Component;
import org.osgi.service.log.LogService;
import org.osgi.service.log.Logger;
import org.osgi.service.transaction.control.TransactionControl;
import org.junit.Assert;
import org.junit.runner.RunWith;
import org.osgi.test.common.annotation.InjectService;
import org.osgi.test.common.context.Exported;
import org.osgi.test.common.annotation.Property;
import org.osgi.test.junit5.context.BundleContextExtension;
import org.osgi.test.junit5.service.ServiceExtension;
import org.osgi.test.junit5.service.ServiceExtension.Service;
import org.osgi.test.junit5.testutils.OSGiSoftAssertions;
@RunWith(org.osgi.test.junit5.TestServiceProvider.class)
@Extension(linkedExtensions = {BundleContextExtension.class, ServiceExtension.class})
public class ExampleTest {
@InjectService
private Logger logger;
@InjectService
private TransactionControl transactionControl;
@InjectService(cardinality = MULTIPLE, filter = "(source=test)")
private LogService[] logServices;
@InjectService
private ExampleService exampleService;
@InjectService
@Exported
@Property(name = "size", value = "10")
private Service specialService;
@Test
void testTransactionControl() {
Assert.assertNotNull("Transaction control service not found.", transactionControl);
}
@Test
void testLogServices() {
Assert.assertNotNull("Log services not found.", logServices);
Assert.assertEquals("Unexpected number of log services found.", 2, logServices.length);
}
@Test
void testExampleService() {
Assert.assertNotNull("Example service not found.", exampleService);
}
@Test
void testSpecialService() {
OSGiSoftAssertions softly = new OSGiSoftAssertions();
softly.assertThat(specialService).hasFieldOrPropertyWithValue("size", 10);
softly.assertAll();
}
}