Author: rob.stryker(a)jboss.com
Date: 2012-01-30 11:12:30 -0500 (Mon, 30 Jan 2012)
New Revision: 38274
Modified:
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/publishing/v2/PublishingFilterTest.java
Log:
Test for nested projects using filter
Modified:
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/publishing/v2/PublishingFilterTest.java
===================================================================
---
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/publishing/v2/PublishingFilterTest.java 2012-01-30
16:01:15 UTC (rev 38273)
+++
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/publishing/v2/PublishingFilterTest.java 2012-01-30
16:12:30 UTC (rev 38274)
@@ -44,7 +44,7 @@
ProjectUtility.deleteAllProjects();
ASTest.clearStateLocation();
}
-
+
public void testPublishingFilter() throws Exception {
publishingFilterTest(createProject("module1"), "**/*",
"**/DONTincludeme.txt", 1);
}
@@ -59,7 +59,7 @@
}
private IProject createProject(String name) throws Exception {
- IDataModel dm = ProjectCreationUtil.getWebDataModel("module1", null, null,
+ IDataModel dm = ProjectCreationUtil.getWebDataModel(name, null, null,
"myContent", null, JavaEEFacetConstants.WEB_25, false);
OperationTestCase.runAndVerify(dm);
IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject(name);
@@ -69,6 +69,28 @@
IOUtil.setContents(f2, "leave me out");
return p;
}
+
+ private IProject[] createProjectWithNested(String earName, String webName) throws
Exception {
+ IDataModel dm = ProjectCreationUtil.getEARDataModel(earName, "earContent",
null, null, JavaEEFacetConstants.EAR_5, false);
+ IDataModel dm2 = ProjectCreationUtil.getWebDataModel(webName, earName, null,
"webContent", null, JavaEEFacetConstants.WEB_25, false);
+
+ OperationTestCase.runAndVerify(dm);
+ OperationTestCase.runAndVerify(dm2);
+
+ IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject(earName);
+ IFile f = p.getFile(new Path("earContent/includeme.txt"));
+ IOUtil.setContents(f, "includeMe");
+ IFile f2 = p.getFile(new Path("earContent/DONTincludeme.txt"));
+ IOUtil.setContents(f2, "leave me out");
+
+ IProject p2 = ResourcesPlugin.getWorkspace().getRoot().getProject(webName);
+ IFile f3 = p2.getFile(new Path("webContent/includeme.txt"));
+ IOUtil.setContents(f3, "includeMe");
+ IFile f4 = p2.getFile(new Path("webContent/DONTincludeme.txt"));
+ IOUtil.setContents(f4, "leave me out");
+ return new IProject[]{p, p2};
+ }
+
private void publishingFilterTest(IProject p, String inc, String exc, int difference)
throws Exception {
IVirtualComponent vc = ComponentCore.createComponent(p);
vc.setMetaProperty("component.inclusion.patterns", inc);
@@ -145,7 +167,95 @@
server.publish(IServer.PUBLISH_FULL, new NullProgressMonitor());
ArrayList<IPath> changed = MockPublishMethod.changed;
assertEquals(changed.size(),fCount+1); // addition of 'root'
+ }
+
+ public void testServerIntegration_NestedProject() throws CoreException, IOException,
Exception {
+ IServer server =
ServerRuntimeUtils.createMockServerWithRuntime(IJBossToolingConstants.SERVER_AS_60,
+ "name1", "default");
+ server = ServerRuntimeUtils.useMock2PublishMethod(server);
+ IProject[] projects = createProjectWithNested("MyEar", "MyWeb");
+ ServerPreferences.getInstance().setAutoPublishing(false);
+ IModule earMod = ServerUtil.getModule(projects[0]);
+ server = ServerRuntimeUtils.addModule(server, earMod);
+ ModuleDelegate earDel = (ModuleDelegate)earMod.loadAdapter(ModuleDelegate.class,
null);
+ DelegatingServerBehavior beh =
(DelegatingServerBehavior)server.loadAdapter(DelegatingServerBehavior.class, null);
+ Mock2BehaviourDelegate del = (Mock2BehaviourDelegate)beh.getDelegate();
+ del.setUseSuperclassBehaviour(true);
+ IModulePathFilter earFilter = del.getPathFilter(new IModule[]{earMod});
+ IModuleResource[] originalMembers = earDel.members();
+ IModuleResource[] filteredMembers = earFilter == null ? originalMembers :
earFilter.getFilteredMembers();
+ int oCount = PublishFilterDirectoryScannerTest.countAllResources(originalMembers);
+ int fCount = PublishFilterDirectoryScannerTest.countAllResources(filteredMembers);
+ assertEquals(oCount, fCount);
+
+ IVirtualComponent vc = ComponentCore.createComponent(earMod.getProject());
+
+ vc.setMetaProperty("component.inclusion.patterns", "**/*");
+ vc.setMetaProperty("component.exclusion.patterns", "**/*.txt");
+
+ earFilter = del.getPathFilter(new IModule[]{earMod});
+ originalMembers = earDel.members();
+ filteredMembers = earFilter.getFilteredMembers();
+ oCount = PublishFilterDirectoryScannerTest.countAllResources(originalMembers);
+ fCount = PublishFilterDirectoryScannerTest.countAllResources(filteredMembers);
+ assertEquals(oCount, fCount+2);
+
+ vc.setMetaProperty("component.inclusion.patterns", "**/*");
+ vc.setMetaProperty("component.exclusion.patterns", "**/DON*");
+
+ earFilter = del.getPathFilter(new IModule[]{earMod});
+ originalMembers = earDel.members();
+ filteredMembers = earFilter.getFilteredMembers();
+ oCount = PublishFilterDirectoryScannerTest.countAllResources(originalMembers);
+ fCount = PublishFilterDirectoryScannerTest.countAllResources(filteredMembers);
+ assertEquals(oCount, fCount+1);
+
+
+ IModuleResource r = PublishFilterDirectoryScanner.findResource(originalMembers, null,
+ new Path("DONTincludeme.txt"));
+ assertNotNull(r);
+ assertFalse(earFilter.shouldInclude(r));
+ r = PublishFilterDirectoryScanner.findResource(originalMembers, null,
+ new Path("includeme.txt"));
+ assertNotNull(r);
+ assertTrue(earFilter.shouldInclude(r));
+
+ IModule webMod = ServerUtil.getModule(projects[1]);
+ ModuleDelegate webDel = (ModuleDelegate)webMod.loadAdapter(ModuleDelegate.class,
null);
+ IModulePathFilter webFilter = del.getPathFilter(new IModule[]{webMod});
+ IModuleResource[] webOriginalMembers = webDel.members();
+ IModuleResource[] webFilteredMembers = webFilter == null ? webOriginalMembers :
webFilter.getFilteredMembers();
+ int webOCount =
PublishFilterDirectoryScannerTest.countAllResources(webOriginalMembers);
+ int webFCount =
PublishFilterDirectoryScannerTest.countAllResources(webFilteredMembers);
+
+ // Test the actual publish
+ MockPublishMethod.reset();
+ server.publish(IServer.PUBLISH_FULL, new NullProgressMonitor());
+ ArrayList<IPath> changed = MockPublishMethod.changed;
+ assertEquals(changed.size(),
+ fCount +1 /* root folder */ +1 /* application.xml, touched by our logic*/
+ + webFCount + 1 /* .war root */
+ );
+
+
+ IVirtualComponent webVC= ComponentCore.createComponent(earMod.getProject());
+ webVC.setMetaProperty("component.inclusion.patterns", "**/*");
+ webVC.setMetaProperty("component.exclusion.patterns", "**/DON*");
+ webFilteredMembers = webFilter == null ? webOriginalMembers :
webFilter.getFilteredMembers();
+ webOCount = PublishFilterDirectoryScannerTest.countAllResources(webOriginalMembers);
+ webFCount = PublishFilterDirectoryScannerTest.countAllResources(webFilteredMembers);
+
+ // Test the actual publish
+ MockPublishMethod.reset();
+ server.publish(IServer.PUBLISH_FULL, new NullProgressMonitor());
+ changed = MockPublishMethod.changed;
+ assertEquals(changed.size(),
+ fCount +1 /* root folder */ +1 /* application.xml, touched by our logic*/
+ + webFCount + 1 /* .war root */
+ );
+
}
-}
+
+}
\ No newline at end of file