blob: ff4695cab7cf6aae29eea84c2c7e89e570d4ddbb [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.sling.feature.extension.apiregions.analyser;
import org.apache.sling.feature.*;
import org.apache.sling.feature.analyser.task.AnalyserTaskContext;
import org.apache.sling.feature.extension.apiregions.api.ApiRegions;
import org.apache.sling.feature.scanner.BundleDescriptor;
import org.apache.sling.feature.scanner.FeatureDescriptor;
import org.apache.sling.feature.scanner.impl.BundleDescriptorImpl;
import org.apache.sling.feature.scanner.impl.FeatureDescriptorImpl;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.Mockito;
import java.io.File;
import java.io.IOException;
import static org.junit.Assert.assertEquals;
public class CheckApiRegionsBundleUnversionedPackagesTest {
private static File resourceRoot;
@BeforeClass
public static void setupClass() {
resourceRoot =
new File(CheckApiRegionsBundleUnversionedPackagesTest.class.
getResource("/test-framework.jar").getFile()).getParentFile();
}
@Test
public void testId() {
assertEquals(ApiRegions.EXTENSION_NAME + "-unversioned-packages", new CheckApiRegionsBundleUnversionedPackages().getId());
}
@Test
public void testBundleUnversionedPackage() throws Exception {
CheckApiRegionsBundleUnversionedPackages t = new CheckApiRegionsBundleUnversionedPackages();
Feature f = new Feature(ArtifactId.fromMvnId("f:f:1"));
f.setComplete(true);
FeatureDescriptor fd = new FeatureDescriptorImpl(f);
fdAddBundle(fd, "g:b1:1", "test-bundle5.jar");
AnalyserTaskContext ctx = Mockito.mock(AnalyserTaskContext.class);
Mockito.when(ctx.getFeature()).thenReturn(f);
Mockito.when(ctx.getFeatureDescriptor()).thenReturn(fd);
t.execute(ctx);
Mockito.verify(ctx, Mockito.times(2)).reportArtifactWarning(Mockito.any(), Mockito.anyString());
Mockito.verify(ctx).reportArtifactWarning(
Mockito.eq(ArtifactId.fromMvnId("g:b1:1")),
Mockito.contains("org.foo.i"));
Mockito.verify(ctx).reportArtifactWarning(
Mockito.eq(ArtifactId.fromMvnId("g:b1:1")),
Mockito.contains("org.foo.e"));
}
private void fdAddBundle(FeatureDescriptor fd, String id, String file, ArtifactId... origins) throws IOException {
Artifact artifact = new Artifact(ArtifactId.fromMvnId(id));
artifact.setFeatureOrigins(origins);
BundleDescriptor bd1 = new BundleDescriptorImpl(
artifact, new File(resourceRoot, file).toURI().toURL(), 0);
fd.getBundleDescriptors().add(bd1);
}
}