@Test public void testProcessDep_withConditionalizedAlias() throws Exception { DependencyList depList = new DependencyList("test", new HashSet<String>(), mockAggregator, features, true, false); configRef.set( new ConfigImpl( mockAggregator, tmpDir, "{aliases:[[/^foo\\//, function(s){return (has('test')?'xxx':'yyy')+'/'}]]}")); depList.processDep("foo/test", explicitDeps, null, new HashSet<String>(), null); assertEquals( new HashSet<String>(Arrays.asList(new String[] {"yyy/test"})), explicitDeps.getModuleIds()); assertEquals( new HashSet<String>(Arrays.asList(new String[] {"test"})), depList.getDependentFeatures()); depList.getDependentFeatures().clear(); explicitDeps = new ModuleDeps(); features.put("test", true); depList.processDep("foo/test", explicitDeps, null, new HashSet<String>(), null); assertEquals( new HashSet<String>(Arrays.asList(new String[] {"xxx/test"})), explicitDeps.getModuleIds()); assertEquals( new HashSet<String>(Arrays.asList(new String[] {"test"})), depList.getDependentFeatures()); depList.getDependentFeatures().clear(); explicitDeps = new ModuleDeps(); features.put("test", false); depList.processDep("foo/test", explicitDeps, null, new HashSet<String>(), null); assertEquals( new HashSet<String>(Arrays.asList(new String[] {"yyy/test"})), explicitDeps.getModuleIds()); assertEquals( new HashSet<String>(Arrays.asList(new String[] {"test"})), depList.getDependentFeatures()); }
@Test(expected = IllegalStateException.class) public void recursionTests_withHasBranchingLoop() throws Exception { DependencyList depList = new DependencyList("test", new HashSet<String>(), mockAggregator, features, true, false); configRef.set( new ConfigImpl( mockAggregator, tmpDir, "{aliases:[['foo/test', 'dojo/has!test?foo/test:bar/test']]}")); depList.processDep("foo/test", explicitDeps, null, new HashSet<String>(), null); }
@Test public void testProcessDep_withAlias() throws Exception { DependencyList depList = new DependencyList("test", new HashSet<String>(), mockAggregator, features, true, false); configRef.set(new ConfigImpl(mockAggregator, tmpDir, "{aliases:[['foo/test', 'bar/test']]}")); depList.processDep("foo/test", explicitDeps, null, new HashSet<String>(), null); assertEquals( new HashSet<String>(Arrays.asList(new String[] {"bar/test"})), explicitDeps.getModuleIds()); assertTrue(depList.getDependentFeatures().isEmpty()); }
@Test public void loggingTests_withAliasing() throws Exception { DependencyList depList = new DependencyList("test", new HashSet<String>(), mockAggregator, features, true, true); configRef.set(new ConfigImpl(mockAggregator, tmpDir, "{aliases:[['foo/test', 'foo/bar']]}")); depList.processDep("foo/test", explicitDeps, null, new HashSet<String>(), null); assertEquals(1, explicitDeps.size()); assertEquals( new HashSet<String>(Arrays.asList(new String[] {"foo/bar"})), explicitDeps.getModuleIds()); assertEquals( MessageFormat.format(Messages.DependencyList_5, "test") + ", Aliased from: foo/test --> foo/bar", explicitDeps.get("foo/bar").getComment()); }
@Before public void setup() throws Exception { tmpDir = Files.createTempDir().toURI(); configRef = new Ref<IConfig>(null); mockAggregator = TestUtils.createMockAggregator(configRef, null); mockDependencies = createMock(IDependencies.class); expect(mockDependencies.getLastModified()).andReturn(0L).anyTimes(); expect(mockDependencies.getDelcaredDependencies("require")) .andReturn(Collections.<String>emptyList()) .anyTimes(); expect(mockAggregator.getDependencies()).andReturn(mockDependencies).anyTimes(); replay(mockAggregator, mockDependencies); configRef.set(new ConfigImpl(mockAggregator, tmpDir, "{}")); features = new Features(); explicitDeps = new ModuleDeps(); }
@Test public void testProcessDep_withAliasedPluginAndModule() throws Exception { DependencyList depList = new DependencyList("test", new HashSet<String>(), mockAggregator, features, true, false); configRef.set( new ConfigImpl( mockAggregator, tmpDir, "{aliases:[[/^foo\\//, function(s){return (has('testFoo')?'xxx':'yyy')+'/'}],[/^bar\\//, function(s){return (has('testBar')?'www':'zzz')+'/'}]]}")); depList.processDep("bar/plugin!foo/test", explicitDeps, null, new HashSet<String>(), null); assertEquals( new HashSet<String>(Arrays.asList(new String[] {"zzz/plugin!yyy/test", "zzz/plugin"})), explicitDeps.getModuleIds()); assertEquals( new HashSet<String>(Arrays.asList(new String[] {"testFoo", "testBar"})), depList.getDependentFeatures()); }
@Test public void testProcessDep_withAliasIntroducedHasPlugin() throws Exception { DependencyList depList = new DependencyList("test", new HashSet<String>(), mockAggregator, features, true, false); configRef.set( new ConfigImpl( mockAggregator, tmpDir, "{aliases:[['foo/test', 'dojo/has!test?foo/fooTest:foo/barTest']]}")); depList.processDep("foo/test", explicitDeps, null, new HashSet<String>(), null); assertEquals( new HashSet<String>( Arrays.asList( new String[] { "dojo/has", "dojo/has!test?foo/fooTest", "dojo/has!test?:foo/barTest" })), explicitDeps.getModuleIds()); assertEquals( new HashSet<String>(Arrays.asList(new String[] {"test"})), depList.getDependentFeatures()); }
@Test public void resolveAliasesDisabledAndHasBranchingDisabled_withDefinedFeatures() throws Exception { mockAggregator.getOptions().setOption(IOptions.DISABLE_HASPLUGINBRANCHING, true); configRef.set(new ConfigImpl(mockAggregator, tmpDir, "{aliases:[['foo1/test', 'bar/test']]}")); DependencyList depList = new DependencyList("test", new HashSet<String>(), mockAggregator, features, false, false); features.put("test", true); features.put("test1", true); depList.processDep( "dojo/has!test?test1?foo1/test:bar1/test:test2:foo2/test:bar2/test", explicitDeps, null, new HashSet<String>(), null); assertEquals(2, explicitDeps.size()); assertEquals( new HashSet<String>(Arrays.asList(new String[] {"dojo/has", "foo1/test"})), explicitDeps.getModuleIds()); assertEquals( new HashSet<String>(Arrays.asList(new String[] {"test", "test1"})), depList.getDependentFeatures()); }
@Test public void testProcessDep_withCompoundHasBranchingWithAliasResolution() throws Exception { DependencyList depList = new DependencyList("test", new HashSet<String>(), mockAggregator, features, true, false); configRef.set( new ConfigImpl( mockAggregator, tmpDir, "{aliases:[['foo/bar', 'dojo/has!test1?foo/test:bar/test'],['bar/test','dojo/has!test2?foo/xxx:foo/yyy']]}")); depList.processDep("foo/bar", explicitDeps, null, new HashSet<String>(), null); assertEquals( new HashSet<String>( Arrays.asList( new String[] { "dojo/has", "dojo/has!test1?foo/test", "dojo/has!test1?:test2?foo/xxx", "dojo/has!test1?:test2?:foo/yyy" })), explicitDeps.getModuleIds()); assertEquals( new HashSet<String>(Arrays.asList(new String[] {"test1", "test2"})), depList.getDependentFeatures()); }