BlueprintURLContext implements Context { public static int getGracePeriod(Bundle b) { int result = 300000; boolean gracePeriodSet = true; String bundleSymbolicName = b.getHeaders().get(Constants.BUNDLE_SYMBOLICNAME); Matcher m = graceP.matcher(bundleSymbolicName); if (m.matches()) { String gracePeriod = m.group(1); gracePeriodSet = !gracePeriod.equalsIgnoreCase("false"); } if (!gracePeriodSet) { result = -1; } else { m = timeoutP.matcher(bundleSymbolicName); if (m.matches()) { String timeout = m.group(1); try { result = Integer.valueOf(timeout); } catch (NumberFormatException nfx) { } } } return result; } @SuppressWarnings("unchecked")  BlueprintURLContext(Bundle callersBundle, Hashtable<?, ?> env); private  BlueprintURLContext(Bundle callersBundle, BlueprintName parentName, Map<String, Object> env); static int getGracePeriod(Bundle b); @Override Object addToEnvironment(String propName, Object propVal); @Override void bind(Name n, Object o); @Override void bind(String s, Object o); @Override void close(); @Override Name composeName(Name name, Name prefix); @Override String composeName(String name, String prefix); @Override Context createSubcontext(Name n); @Override Context createSubcontext(String s); @Override void destroySubcontext(Name n); @Override void destroySubcontext(String s); @Override Hashtable<?, ?> getEnvironment(); @Override String getNameInNamespace(); @Override NameParser getNameParser(Name n); @Override NameParser getNameParser(String s); @Override NamingEnumeration<NameClassPair> list(Name name); @Override NamingEnumeration<NameClassPair> list(String s); @Override NamingEnumeration<Binding> listBindings(Name name); @Override NamingEnumeration<Binding> listBindings(String name); @Override Object lookup(Name name); @Override Object lookup(String name); @Override Object lookupLink(Name n); @Override Object lookupLink(String s); @Override void rebind(Name n, Object o); @Override void rebind(String s, Object o); @Override Object removeFromEnvironment(String propName); @Override void rename(Name nOld, Name nNew); @Override void rename(String sOld, String sNew); @Override void unbind(Name n); @Override void unbind(String s);  }
@Test public void testBlueprintTimeoutExtractionBothSpecified() { Bundle b = bundleMock ("bundle.name;x=y;p:=q;blueprint.graceperiod:=true;blueprint.timeout:=10000;a=b;c:=d"); int timeout = BlueprintURLContext.getGracePeriod(b); assertEquals ("graceperiod wrong", 10000, timeout); }
@Test public void testGracePeriodFalseHandled() throws Exception { Bundle b = bundleMock ("bundle.name;x=y;p:=q;blueprint.graceperiod:=false;blueprint.timeout:=10000;a=b;c:=d"); int timeout = BlueprintURLContext.getGracePeriod(b); assertEquals ("graceperiod wrong", -1, timeout); b = bundleMock ("bundle.name;x=y;p:=q;blueprint.graceperiod:=false;a=b;c:=d"); timeout = BlueprintURLContext.getGracePeriod(b); assertEquals ("graceperiod wrong", -1, timeout); }
@Test public void testDefaultsReturnedByDefault() throws Exception { Bundle b = bundleMock("bundle.name;x=y;p:=q;blueprint.graceperiod:=true;a=b;c:=d"); int timeout = BlueprintURLContext.getGracePeriod(b); assertEquals ("graceperiod wrong", 300000, timeout); b = bundleMock ("bundle.name;x=y;p:=q;a=b;c:=d"); timeout = BlueprintURLContext.getGracePeriod(b); assertEquals ("graceperiod wrong", 300000, timeout); }