use of org.apache.karaf.features.Dependency in project ddf by codice.
the class ApplicationServiceImplTest method testStopApplicationMainFeature.
/**
* Tests the {@link ApplicationServiceImpl#stopApplication(Application)} method
* for the case where a main feature exists
*
* @throws Exception
*/
@Test
public void testStopApplicationMainFeature() throws Exception {
Set<Repository> activeRepos = new HashSet<Repository>(Arrays.asList(mainFeatureRepo, noMainFeatureRepo1, noMainFeatureRepo2));
FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
ApplicationService appService = new ApplicationServiceImpl(bundleStateServices) {
@Override
protected BundleContext getContext() {
return bundleContext;
}
};
Application testApp1 = mock(ApplicationImpl.class);
Feature testFeature1 = mock(Feature.class);
Dependency testDependency1 = mock(Dependency.class);
List<Dependency> dependencyList1 = new ArrayList<>();
Set<Feature> featureSet1 = new HashSet<>();
dependencyList1.add(testDependency1);
featureSet1.add(testFeature1);
when(testFeature1.getName()).thenReturn(TEST_FEATURE_1_NAME);
when(testApp1.getMainFeature()).thenReturn(testFeature1);
when(testApp1.getFeatures()).thenReturn(featureSet1);
when(featuresService.isInstalled(testFeature1)).thenReturn(true);
when(testFeature1.getDependencies()).thenReturn(dependencyList1);
when(testDependency1.getVersion()).thenReturn(TEST_FEATURE_VERSION);
when(testFeature1.getVersion()).thenReturn(TEST_FEATURE_VERSION);
appService.stopApplication(testApp1);
verify(featuresService, atLeastOnce()).uninstallFeature(TEST_FEATURE_1_NAME, TEST_FEATURE_VERSION, EnumSet.of(Option.NoAutoRefreshBundles));
}
use of org.apache.karaf.features.Dependency in project admin-console-beta by connexta.
the class FeatureUtils method featureToField.
private FeatureField featureToField(Feature feat, Map<String, BundleField> bundlesByLocation) {
List<String> featDeps = feat.getDependencies().stream().map(Dependency::getName).collect(Collectors.toList());
List<BundleField> bundleDepLocations = feat.getBundles().stream().map(BundleInfo::getLocation).map(loc -> createBundleFromLocation(loc, bundlesByLocation)).collect(Collectors.toList());
return new FeatureField().name(feat.getName()).featDescription(feat.getDescription()).state(feat.getInstall()).id(feat.getId()).repoUrl(feat.getRepositoryUrl()).addFeatureDeps(featDeps).addBundleDeps(bundleDepLocations);
}
use of org.apache.karaf.features.Dependency in project ddf by codice.
the class ProfileListCommandTest method setup.
@Before
public void setup() throws IOException {
ddfHome.newFolder("etc", "profiles");
profilePath = Paths.get(ddfHome.getRoot().toString(), "etc", "profiles");
Files.copy(this.getClass().getResourceAsStream("/profiles/devProfile.json"), Paths.get(profilePath.toAbsolutePath().toString(), "devProfile.json"));
Files.copy(this.getClass().getResourceAsStream("/profiles/profileWithDuplicates.json"), Paths.get(profilePath.toAbsolutePath().toString(), "profileWithDuplicates.json"));
this.applicationService = mock(ApplicationServiceImpl.class);
this.featuresService = mock(FeaturesServiceImpl.class);
this.bundleService = mock(BundleServiceImpl.class);
out = new ByteArrayOutputStream();
console = new PrintStream(out);
profileListCommand = getProfileListCommand(profilePath, console);
Feature feature = createMockFeature("standard");
List<Dependency> deps = Arrays.asList(createMockDependency("app1"), createMockDependency("app2"), createMockDependency("app3"));
when(feature.getDependencies()).thenReturn(deps);
when(applicationService.getInstallationProfiles()).thenReturn(Collections.singletonList(feature));
}
use of org.apache.karaf.features.Dependency in project ddf by codice.
the class ApplicationServiceImplTest method createMockFeaturesService.
/**
* Creates a mock {@code FeaturesService} object consisting of all of the features contained in a
* {@code Set} of {@code Repository} objects. Each {@code Feature} will be in the <i>installed</i>
* state unless it is contained in the received set of features that are not to be installed. Each
* {@code Bundle} will be in the {@code Bundle#ACTIVE} state and the {@code BundleState#Active}
* extended bundle state (as reported by a dependency injection framework) unless it is contained
* in the received set of {@code Bundle}s that are not to be active, in which case the {@code
* Bundle} will be in the {@code Bundle#INSTALLED} state and the {@code BundleState#Installed}
* extended bundle state.
*
* <p>Note that not all of the state and {@code Bundle} information is contained in the {@code
* FeaturesService}. As such, this method stores some of the required information in the class's
* {@code #bundleContext} and {@code bundleStateServices}. As such, these objects must be
* re-instantiated for each test (i.e., they must be instantiated in the {@link #setUp()} method).
*
* @param repos A {@code Set} of {@link Repository} objects from which to obtain the {@link
* Feature}s that are to be included in the mock {@code FeaturesService}
* @param notInstalledFeatures A {@code Set} of {@code Feature}s that the {@code FeaturesService}
* should report as not installed
* @param inactiveBundles A {@code Set} of {@link BundleInfo}s containing the locations of {@code
* Bundle}s that should be set to inactive and for which the {@link BundleStateService}
* contained in index 0 of {@link #bundleStateServices} should report a {@link
* BundleState#Installed} state.
* @return A mock {@link FeaturesService} with {@link Feature}s and {@link Bundle}s in the
* requested states.
* @throws Exception
*/
private FeaturesService createMockFeaturesService(Set<Repository> repos, Set<Feature> notInstalledFeatures, Set<BundleInfo> inactiveBundles) throws Exception {
if (LOGGER.isTraceEnabled()) {
for (Repository repo : repos) {
for (Feature feature : repo.getFeatures()) {
LOGGER.trace("Repo Feature: {}", feature);
LOGGER.trace("Repo Feature name/version: {}/{}", feature.getName(), feature.getVersion());
LOGGER.trace("Dependencies: ");
for (Dependency depFeature : feature.getDependencies()) {
LOGGER.trace("Dependency Feature: {}", depFeature);
LOGGER.trace("Dependency Feature name/version: {}/{}", depFeature.getName(), depFeature.getVersion());
}
}
}
}
if (null == notInstalledFeatures) {
notInstalledFeatures = new HashSet<>();
}
if (null == inactiveBundles) {
inactiveBundles = new HashSet<>();
}
Set<String> installedBundleLocations = new HashSet<>();
for (BundleInfo bundleInfo : inactiveBundles) {
installedBundleLocations.add(bundleInfo.getLocation());
}
FeaturesService featuresService = mock(FeaturesService.class);
Set<Feature> featuresSet = new HashSet<>();
BundleRevision mockBundleRevision = mock(BundleRevision.class);
when(mockBundleRevision.getTypes()).thenReturn(0);
for (Repository curRepo : repos) {
for (Feature curFeature : curRepo.getFeatures()) {
featuresSet.add(curFeature);
when(featuresService.getFeature(curFeature.getName())).thenReturn(curFeature);
when(featuresService.getFeature(curFeature.getName(), curFeature.getVersion())).thenReturn(curFeature);
// TODO: File Karaf bug that necessitates this, then reference
// it here.
when(featuresService.getFeature(curFeature.getName(), "0.0.0")).thenReturn(curFeature);
when(featuresService.isInstalled(curFeature)).thenReturn(!notInstalledFeatures.contains(curFeature));
// of that bundle, this logic will need to be modified.
for (BundleInfo bundleInfo : curFeature.getBundles()) {
if (installedBundleLocations.contains(bundleInfo.getLocation())) {
Bundle mockInstalledBundle = mock(Bundle.class);
when(mockInstalledBundle.getState()).thenReturn(Bundle.INSTALLED);
when(mockInstalledBundle.adapt(BundleRevision.class)).thenReturn(mockBundleRevision);
when(bundleContext.getBundle(bundleInfo.getLocation())).thenReturn(mockInstalledBundle);
when(bundleStateServices.get(0).getState(mockInstalledBundle)).thenReturn(BundleState.Installed);
} else {
Bundle mockActiveBundle = mock(Bundle.class);
when(mockActiveBundle.getState()).thenReturn(Bundle.ACTIVE);
when(mockActiveBundle.adapt(BundleRevision.class)).thenReturn(mockBundleRevision);
when(bundleContext.getBundle(bundleInfo.getLocation())).thenReturn(mockActiveBundle);
when(bundleStateServices.get(0).getState(mockActiveBundle)).thenReturn(BundleState.Active);
}
}
}
}
when(featuresService.listRepositories()).thenReturn(repos.toArray(new Repository[repos.size()]));
when(featuresService.listFeatures()).thenReturn(featuresSet.toArray(new Feature[] {}));
return featuresService;
}
Aggregations