blob: c2ed2e9f60f44d49beb2d6ab4d82637f7b63181f [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2010 IBM Corporation and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.equinox.metatype.tests;
import junit.framework.TestCase;
import org.eclipse.equinox.compendium.tests.Activator;
import org.eclipse.osgi.tests.bundles.BundleInstaller;
import org.osgi.framework.Bundle;
import org.osgi.framework.ServiceReference;
import org.osgi.service.metatype.MetaTypeInformation;
import org.osgi.service.metatype.MetaTypeService;
public class SameOcdPidFactoryPidTest extends TestCase {
private Bundle bundle;
private BundleInstaller bundleInstaller;
private MetaTypeService metaType;
private ServiceReference metaTypeReference;
protected void setUp() throws Exception {
Activator.getBundle(Activator.BUNDLE_METATYPE).start();
metaTypeReference = Activator.getBundleContext().getServiceReference(MetaTypeService.class.getName());
metaType = (MetaTypeService) Activator.getBundleContext().getService(metaTypeReference);
bundleInstaller = new BundleInstaller("bundle_tests/metatype", Activator.getBundleContext()); //$NON-NLS-1$
bundleInstaller.refreshPackages(null);
bundle = bundleInstaller.installBundle("tb2"); //$NON-NLS-1$
bundle.start();
}
protected void tearDown() throws Exception {
bundleInstaller.shutdown();
Activator.getBundleContext().ungetService(metaTypeReference);
Activator.getBundle(Activator.BUNDLE_METATYPE).stop();
}
/*
* Ensures the same OCD referred to by two Designate elements, one using
* the factoryPid attribute and the other only the pid attribute, is
* accessible via both getPids() and getFactoryPids().
*/
public void test1() {
MetaTypeInformation mti = metaType.getMetaTypeInformation(bundle);
String[] pids = mti.getPids();
assertNotNull("The pid 'singleton' was not present.", pids); //$NON-NLS-1$
assertEquals("Not the expected number of pids.", 1, pids.length); //$NON-NLS-1$
assertEquals("Expected pid was not present.", "singleton", pids[0]); //$NON-NLS-1$ //$NON-NLS-2$
String[] factoryPids = mti.getFactoryPids();
assertNotNull("The factory pid 'factory' was not present.", factoryPids); //$NON-NLS-1$
assertEquals("Not the expected number of factory pids.", 1, factoryPids.length); //$NON-NLS-1$
assertEquals("Expected factory pid was not present.", "factory", factoryPids[0]); //$NON-NLS-1$ //$NON-NLS-2$
}
}