@Test public void testMissingConfig() throws Exception { ContainerConfig containerMissingConfig = mock(ContainerConfig.class); expect(containerMissingConfig.getContainers()) .andReturn(Arrays.asList(ContainerConfig.DEFAULT_CONTAINER)); replay(); lockedDomainService = new HashLockedDomainService(containerMissingConfig, true); assertFalse(lockedDomainService.gadgetCanRender("www.example.com", wantsLocked, "default")); assertTrue(lockedDomainService.gadgetCanRender("www.example.com", notLocked, "default")); }
@SuppressWarnings("unchecked") private Gadget makeGadget(boolean wantsLocked, boolean wantsSecurityToken, String url) { List<String> gadgetFeatures = Lists.newArrayList(); String requires = ""; if (wantsLocked || wantsSecurityToken) { gadgetFeatures.add("locked-domain"); if (wantsLocked) { requires += " <Require feature='locked-domain'/>"; } if (wantsSecurityToken) { requires += " <Require feature='security-token'/>"; gadgetFeatures.add("security-token"); } } String gadgetXml = "<Module><ModulePrefs title=''>" + requires + "</ModulePrefs><Content/></Module>"; GadgetSpec spec = null; try { spec = new GadgetSpec(Uri.parse(url), gadgetXml); } catch (GadgetException e) { return null; } FeatureRegistry registry = mock(FeatureRegistry.class); expect(registry.getFeatures(isA(Collection.class))).andReturn(gadgetFeatures).anyTimes(); return new Gadget().setSpec(spec).setGadgetFeatureRegistry(registry); }
@SuppressWarnings("unchecked") private Gadget makeGadget(boolean wantsLocked, boolean wantsSecurityToken, String url) { List<String> gadgetFeatures = Lists.newArrayList(); String requires = ""; if (wantsLocked || wantsSecurityToken) { gadgetFeatures.add("locked-domain"); if (wantsLocked) { requires += " <Require feature='locked-domain'/>"; } if (wantsSecurityToken) { requires += " <Require feature='security-token'/>"; gadgetFeatures.add("security-token"); } } String gadgetXml = "<Module><ModulePrefs title=''>" + requires + "</ModulePrefs><Content/></Module>"; GadgetSpec spec = null; try { spec = new GadgetSpec(Uri.parse(url), gadgetXml); } catch (GadgetException e) { return null; } FeatureRegistry registry = mock(FeatureRegistry.class); expect(registry.getFeatures(isA(Collection.class))).andReturn(gadgetFeatures).anyTimes(); return new Gadget().setSpec(spec).setContext(new GadgetContext()).setGadgetFeatureRegistry(registry); }
@SuppressWarnings("unchecked") private Gadget makeGadget(boolean wantsLocked, boolean wantsSecurityToken, String url) { List<String> gadgetFeatures = Lists.newArrayList(); String requires = ""; if (wantsLocked || wantsSecurityToken) { gadgetFeatures.add("locked-domain"); if (wantsLocked) { requires += " <Require feature='locked-domain'/>"; } if (wantsSecurityToken) { requires += " <Require feature='security-token'/>"; gadgetFeatures.add("security-token"); } } String gadgetXml = "<Module><ModulePrefs title=''>" + requires + "</ModulePrefs><Content/></Module>"; GadgetSpec spec = null; try { spec = new GadgetSpec(Uri.parse(url), gadgetXml); } catch (GadgetException e) { return null; } FeatureRegistry registry = mock(FeatureRegistry.class); expect(registry.getFeatures(isA(Collection.class))).andReturn(gadgetFeatures).anyTimes(); return new Gadget().setSpec(spec).setContext(new GadgetContext()).setGadgetFeatureRegistry(registry); }
@Test public void testMultiContainer() throws Exception { ContainerConfig inheritsConfig = mock(ContainerConfig.class); expect(inheritsConfig.getContainers()) .andReturn(Arrays.asList(ContainerConfig.DEFAULT_CONTAINER, "other")); expect(inheritsConfig.getBool(isA(String.class), eq(LOCKED_DOMAIN_REQUIRED_KEY))) .andReturn(true).anyTimes(); expect(inheritsConfig.getString(isA(String.class), eq(LOCKED_DOMAIN_SUFFIX_KEY))) .andReturn("-a.example.com:8080").anyTimes(); replay(); lockedDomainService = new HashLockedDomainService(inheritsConfig, true); assertFalse(lockedDomainService.gadgetCanRender("www.example.com", wantsLocked, "other")); assertFalse(lockedDomainService.gadgetCanRender("www.example.com", notLocked, "other")); assertTrue(lockedDomainService.gadgetCanRender( "8uhr00296d2o3sfhqilj387krjmgjv3v-a.example.com:8080", wantsLocked, "other")); } }