use of org.apache.aries.util.VersionRange in project aries by apache.
the class ManifestHeaderProcessorTest method testVersionRange.
/**
* Test the version range created correctly
* @throws Exception
*/
@Test
public void testVersionRange() throws Exception {
String version1 = "[1.2.3, 4.5.6]";
String version2 = "(1, 2]";
String version3 = "[2,4)";
String version4 = "(1,2)";
String version5 = "2";
String version6 = "2.3";
String version7 = "[1.2.3.q, 2.3.4.p)";
String version8 = "1.2.2.5";
String version9 = "a.b.c";
String version10 = null;
String version11 = "";
String version12 = "\"[1.2.3, 4.5.6]\"";
VersionRange vr = ManifestHeaderProcessor.parseVersionRange(version1);
assertEquals("The value is wrong", "1.2.3", vr.getMinimumVersion().toString());
assertFalse("The value is wrong", vr.isMinimumExclusive());
assertEquals("The value is wrong", "4.5.6", vr.getMaximumVersion().toString());
assertFalse("The value is wrong", vr.isMaximumExclusive());
vr = ManifestHeaderProcessor.parseVersionRange(version2);
assertEquals("The value is wrong", "1.0.0", vr.getMinimumVersion().toString());
assertTrue("The value is wrong", vr.isMinimumExclusive());
assertEquals("The value is wrong", "2.0.0", vr.getMaximumVersion().toString());
assertFalse("The value is wrong", vr.isMaximumExclusive());
vr = ManifestHeaderProcessor.parseVersionRange(version3);
assertEquals("The value is wrong", "2.0.0", vr.getMinimumVersion().toString());
assertFalse("The value is wrong", vr.isMinimumExclusive());
assertEquals("The value is wrong", "4.0.0", vr.getMaximumVersion().toString());
assertTrue("The value is wrong", vr.isMaximumExclusive());
vr = ManifestHeaderProcessor.parseVersionRange(version4);
assertEquals("The value is wrong", "1.0.0", vr.getMinimumVersion().toString());
assertTrue("The value is wrong", vr.isMinimumExclusive());
assertEquals("The value is wrong", "2.0.0", vr.getMaximumVersion().toString());
assertTrue("The value is wrong", vr.isMaximumExclusive());
vr = ManifestHeaderProcessor.parseVersionRange(version5);
assertEquals("The value is wrong", "2.0.0", vr.getMinimumVersion().toString());
assertFalse("The value is wrong", vr.isMinimumExclusive());
assertNull("The value is wrong", vr.getMaximumVersion());
assertFalse("The value is wrong", vr.isMaximumExclusive());
vr = ManifestHeaderProcessor.parseVersionRange(version6);
assertEquals("The value is wrong", "2.3.0", vr.getMinimumVersion().toString());
assertFalse("The value is wrong", vr.isMinimumExclusive());
assertNull("The value is wrong", vr.getMaximumVersion());
assertFalse("The value is wrong", vr.isMaximumExclusive());
vr = ManifestHeaderProcessor.parseVersionRange(version7);
assertEquals("The value is wrong", "1.2.3.q", vr.getMinimumVersion().toString());
assertFalse("The value is wrong", vr.isMinimumExclusive());
assertEquals("The value is wrong", "2.3.4.p", vr.getMaximumVersion().toString());
assertTrue("The value is wrong", vr.isMaximumExclusive());
vr = ManifestHeaderProcessor.parseVersionRange(version8);
assertEquals("The value is wrong", "1.2.2.5", vr.getMinimumVersion().toString());
assertFalse("The value is wrong", vr.isMinimumExclusive());
assertNull("The value is wrong", vr.getMaximumVersion());
assertFalse("The value is wrong", vr.isMaximumExclusive());
boolean exception = false;
try {
vr = ManifestHeaderProcessor.parseVersionRange(version9);
} catch (Exception e) {
exception = true;
}
assertTrue("The value is wrong", exception);
boolean exceptionNull = false;
try {
vr = ManifestHeaderProcessor.parseVersionRange(version10);
} catch (Exception e) {
exceptionNull = true;
}
assertTrue("The value is wrong", exceptionNull);
// empty version should be defaulted to >=0.0.0
vr = ManifestHeaderProcessor.parseVersionRange(version11);
assertEquals("The value is wrong", "0.0.0", vr.getMinimumVersion().toString());
assertFalse("The value is wrong", vr.isMinimumExclusive());
assertNull("The value is wrong", vr.getMaximumVersion());
assertFalse("The value is wrong", vr.isMaximumExclusive());
vr = ManifestHeaderProcessor.parseVersionRange(version12);
assertEquals("The value is wrong", "1.2.3", vr.getMinimumVersion().toString());
assertFalse("The value is wrong", vr.isMinimumExclusive());
assertEquals("The value is wrong", "4.5.6", vr.getMaximumVersion().toString());
assertFalse("The value is wrong", vr.isMaximumExclusive());
}
use of org.apache.aries.util.VersionRange in project aries by apache.
the class ManifestHeaderProcessorTest method testExactVersion.
@Test
public void testExactVersion() throws Exception {
VersionRange vr;
try {
vr = ManifestHeaderProcessor.parseVersionRange("[1.0.0, 2.0.0]", true);
fail("should not get here 1");
} catch (IllegalArgumentException e) {
// expected
}
vr = ManifestHeaderProcessor.parseVersionRange("[1.0.0, 1.0.0]", true);
assertTrue(vr.isExactVersion());
try {
vr = ManifestHeaderProcessor.parseVersionRange("(1.0.0, 1.0.0]", true);
fail("should not get here 2");
} catch (IllegalArgumentException e) {
// expected
}
try {
vr = ManifestHeaderProcessor.parseVersionRange("[1.0.0, 1.0.0)", true);
fail("should not get here 3");
} catch (IllegalArgumentException e) {
// expected
}
vr = ManifestHeaderProcessor.parseVersionRange("[1.0.0, 2.0.0]");
assertFalse(vr.isExactVersion());
vr = ManifestHeaderProcessor.parseVersionRange("[1.0.0, 1.0.0]");
assertTrue(vr.isExactVersion());
}
use of org.apache.aries.util.VersionRange in project aries by apache.
the class UpdateAppTest method updateApp.
private AriesApplicationContext updateApp(AriesApplicationManager manager, AriesApplication app) throws Exception {
IsolationTestUtils.prepareSampleBundleV2(bundleContext, context().getService(RepositoryGenerator.class), context().getService(RepositoryAdmin.class), context().getService(ModellingManager.class));
AriesApplication newApp = manager.resolve(app, new ResolveConstraint() {
public String getBundleName() {
return "org.apache.aries.isolated.sample";
}
public VersionRange getVersionRange() {
return ManifestHeaderProcessor.parseVersionRange("[2.0.0,2.0.0]", true);
}
});
return manager.update(app, newApp.getDeploymentMetadata());
}
use of org.apache.aries.util.VersionRange in project aries by apache.
the class OBRAriesResolver method getBundleInfo.
@Override
public BundleInfo getBundleInfo(String bundleSymbolicName, Version bundleVersion) {
Map<String, String> attribs = new HashMap<String, String>();
// bundleVersion is an exact version - so ensure right version filter is generated
VersionRange range = ManifestHeaderProcessor.parseVersionRange(bundleVersion.toString(), true);
attribs.put(Resource.VERSION, range.toString());
String filterString = ManifestHeaderProcessor.generateFilter(Resource.SYMBOLIC_NAME, bundleSymbolicName, attribs);
Resource[] resources;
try {
resources = repositoryAdmin.discoverResources(filterString);
if (resources != null && resources.length > 0) {
return toBundleInfo(resources[0], false);
} else {
return null;
}
} catch (InvalidSyntaxException e) {
log.error("Invalid filter", e);
return null;
}
}
use of org.apache.aries.util.VersionRange in project aries by apache.
the class DeploymentGeneratorTest method mockContent.
private Content mockContent(String symbolicName, String version) {
Content bundle = Skeleton.newMock(Content.class);
VersionRange vr = new VersionRange(version);
Skeleton.getSkeleton(bundle).setReturnValue(new MethodCall(Content.class, "getContentName"), symbolicName);
Skeleton.getSkeleton(bundle).setReturnValue(new MethodCall(Content.class, "getVersion"), vr);
return bundle;
}
Aggregations