From embjopr-commits at lists.jboss.org Thu Jul 23 12:06:02 2009 Content-Type: multipart/mixed; boundary="===============0328163460858457000==" MIME-Version: 1.0 From: embjopr-commits at lists.jboss.org To: embjopr-commits at lists.jboss.org Subject: [embjopr-commits] EMBJOPR SVN: r575 - trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/app/ear. Date: Wed, 22 Jul 2009 15:23:36 -0400 Message-ID: <200907221923.n6MJNaxQ000709@svn01.web.mwc.hst.phx2.redhat.com> --===============0328163460858457000== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: ozizka(a)redhat.com Date: 2009-07-22 15:23:36 -0400 (Wed, 22 Jul 2009) New Revision: 575 Added: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/app/ear/ProfileSe= rviceTest.java Removed: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/app/ear/AbstractP= rofileServiceTest.java Log: * ProfileServiceTest test listing now uses current PS spi. Deleted: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/app/ear/Abs= tractProfileServiceTest.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/app/ear/Abstract= ProfileServiceTest.java 2009-07-22 16:20:31 UTC (rev 574) +++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/app/ear/Abstract= ProfileServiceTest.java 2009-07-22 19:23:36 UTC (rev 575) @@ -1,256 +0,0 @@ -/* - * JBoss, Home of Professional Open Source. - * Copyright 2008, Red Hat Middleware LLC, and individual contributors - * as indicated by the @author tags. See the copyright.txt file in the - * distribution for a full listing of individual contributors. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ -package org.jboss.jopr.jsfunit.as5.app.ear; - -import java.util.Collections; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import javax.naming.InitialContext; - -import javax.naming.NamingException; -import org.jboss.deployers.spi.management.ManagementView; -import org.jboss.deployers.spi.management.deploy.DeploymentManager; -import org.jboss.deployers.spi.management.deploy.DeploymentProgress; -import org.jboss.jopr.jsfunit.EmbjoprTestCase; -import org.jboss.managed.api.ComponentType; -import org.jboss.managed.api.DeploymentTemplateInfo; -import org.jboss.managed.api.ManagedComponent; -import org.jboss.managed.api.ManagedProperty; -import org.jboss.metatype.api.values.MetaValue; -import org.jboss.metatype.api.values.MetaValueFactory; -import org.jboss.profileservice.spi.ProfileKey; -import org.jboss.profileservice.spi.ProfileService; -import org.jboss.virtual.VFS; - -/** - * @author Alexey Loubyansky - * @version $Revision: 87016 $ - */ -public abstract class AbstractProfileServiceTest - extends EmbjoprTestCase -{ - = - /** We use the default profile, defined by DeploymentManager to deploy = apps. */ - public static final ProfileKey defaultProfile =3D new ProfileKey(Profil= eKey.DEFAULT); - = - protected ManagementView activeView; - protected DeploymentManager deployMgr; - private MetaValueFactory metaValueFactory; - - public AbstractProfileServiceTest(String name){ - //super(name); - super(); - } - public AbstractProfileServiceTest(){ - super(); - } - = - /** - * @return the ProfileKey.name to use when loading the profile - */ - protected String getProfileName() - { - return null; - } - = - protected ProfileKey getProfileKey() - { - if(getProfileName() =3D=3D null) - return defaultProfile; - = - return new ProfileKey(getProfileName()); - } - - protected void removeDeployment(String deployment) - throws Exception - { - String names[] =3D new String[] {deployment}; - DeploymentManager deployMgr =3D getDeploymentManager(); - try - { - DeploymentProgress progress =3D deployMgr.stop(names); - progress.run(); - assertFalse("failed: " + progress.getDeploymentStatus().getFailur= e(), progress.getDeploymentStatus().isFailed()); - } - finally - { - DeploymentProgress progress =3D deployMgr.remove(names); - progress.run(); - assertFalse("failed: " + progress.getDeploymentStatus().getFailur= e(), progress.getDeploymentStatus().isFailed()); - } - } - - protected void createComponentTest(String templateName, - Map propValues, - String deploymentName, - ComponentType componentType, String componentName) - throws Exception - { - createComponentTest(templateName, propValues, deploymentName, compon= entType, componentName, true); - } - - protected void createComponentTest(String templateName, - Map propValues, - String deploymentName, - ComponentType componentType, String componentName, - boolean processChanges) - throws Exception - { - Set removedPropNames =3D Collections.emptySet(); - createComponentTest(templateName, propValues, removedPropNames, - deploymentName, componentType, componentName, processChanges); - } - protected void createComponentTest(String templateName, - Map propValues, - Set removedPropNames, - String deploymentName, - ComponentType componentType, String = componentName, - boolean processChanges) - throws Exception - { - ManagementView mgtView =3D getManagementView(); - DeploymentTemplateInfo info =3D mgtView.getTemplate(templateName); - assertNotNull("template " + templateName + " found", info); - Map props =3D info.getProperties(); - for(String propName : propValues.keySet()) - { - ManagedProperty prop =3D props.get(propName); - log.debug("createComponentTest("+propName+") before: "+prop.getVa= lue()); - assertNotNull("property " + propName + " found in template " + te= mplateName, prop); - prop.setValue(propValues.get(propName)); - log.debug("createComponentTest("+propName+") after: "+prop.getVal= ue()); - } - for(String propName : removedPropNames) - { - ManagedProperty prop =3D props.get(propName); - prop.setRemoved(true); - log.debug("removed property: "+propName); - } - - mgtView.applyTemplate(deploymentName, info); - if(processChanges) - { - mgtView.process(); - = - // reload the view - activeView =3D null; - mgtView =3D getManagementView(); - ManagedComponent dsMC =3D getManagedComponent(mgtView, componentT= ype, componentName); - assertNotNull(dsMC); - = - Set mcPropNames =3D new HashSet(dsMC.getPropertyN= ames()); - for(String propName : propValues.keySet()) - { - ManagedProperty prop =3D dsMC.getProperty(propName); - assertNotNull(prop); - Object propValue =3D prop.getValue(); - Object expectedValue =3D propValues.get(propName); - assertEquals(prop.getName(), expectedValue, propValue); - = - mcPropNames.remove(propName); - } - = - if(!mcPropNames.isEmpty()) - { - log.warn(getName() + "> untested properties: " + mcPropNames); - } - } - } - - /** - * Obtain the ProfileService.ManagementView - * @return - * @throws Exception - */ - protected ManagementView getManagementView() - throws Exception - { - if( activeView =3D=3D null ) - { - InitialContext ctx =3D getInitialContext(); - ProfileService ps =3D (ProfileService) ctx.lookup("ProfileService= "); - activeView =3D ps.getViewManager(); - // Init the VFS to setup the vfs* protocol handlers - VFS.init(); - } - // Reload - activeView.load(); - return activeView; - } - /** - * Obtain the ProfileService.ManagementView - * @return - * @throws Exception - */ - protected DeploymentManager getDeploymentManager() - throws Exception - { - if( deployMgr =3D=3D null ) - { - InitialContext ctx =3D getInitialContext(); - ProfileService ps =3D (ProfileService) ctx.lookup("ProfileService= "); - deployMgr =3D ps.getDeploymentManager(); - deployMgr.loadProfile(getProfileKey()); - // Init the VFS to setup the vfs* protocol handlers - VFS.init(); - } - return deployMgr; - } - - /** - * Locate the given ComponentType with the given component name. - * - * @param mgtView - - * @return the matching ManagedComponent if found, null otherwise - * @throws Exception - */ - protected ManagedComponent getManagedComponent(ManagementView mgtView, = ComponentType type, String name) - throws Exception - { - Set comps =3D mgtView.getComponentsForType(type); - ManagedComponent mc =3D null; - for (ManagedComponent comp : comps) - { - String cname =3D comp.getName(); - if( cname.endsWith(name) ) - { - mc =3D comp; - break; - } - } - return mc; - } - - protected MetaValueFactory getMetaValueFactory() - { - if(metaValueFactory =3D=3D null) - metaValueFactory =3D MetaValueFactory.getInstance(); - return metaValueFactory; - } - - InitialContext getInitialContext() throws NamingException{ - return new InitialContext(); - } - -} Copied: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/app/ear/Prof= ileServiceTest.java (from rev 568, trunk/jsfunit/src/test/java/org/jboss/jo= pr/jsfunit/as5/app/ear/AbstractProfileServiceTest.java) =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/app/ear/ProfileS= erviceTest.java (rev 0) +++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/app/ear/ProfileS= erviceTest.java 2009-07-22 19:23:36 UTC (rev 575) @@ -0,0 +1,285 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2008, Red Hat Middleware LLC, and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.jboss.jopr.jsfunit.as5.app.ear; + +import java.util.Collections; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import javax.naming.InitialContext; + +import javax.naming.NamingException; +import org.jboss.deployers.spi.management.ManagementView; +import org.jboss.deployers.spi.management.deploy.DeploymentManager; +import org.jboss.deployers.spi.management.deploy.DeploymentProgress; +import org.jboss.jopr.jsfunit.EmbjoprTestCase; +import org.jboss.jopr.jsfunit.util.jaas.JaasUtils; +import org.jboss.managed.api.ComponentType; +import org.jboss.managed.api.DeploymentTemplateInfo; +import org.jboss.managed.api.ManagedComponent; +import org.jboss.managed.api.ManagedProperty; +import org.jboss.metatype.api.values.MetaValue; +import org.jboss.metatype.api.values.MetaValueFactory; +import org.jboss.profileservice.spi.ProfileKey; +import org.jboss.profileservice.spi.ProfileService; +import org.jboss.virtual.VFS; + + + +/** + * @author Ondrej Zizka, original class by Alexey Loubyansky + */ +public class ProfileServiceTest + extends EmbjoprTestCase +{ + = + /** We use the default profile, defined by DeploymentManager to deploy = apps. */ + public static final ProfileKey defaultProfile =3D new ProfileKey(Profil= eKey.DEFAULT); + = + protected ManagementView activeView; + protected DeploymentManager deployMgr; + private MetaValueFactory metaValueFactory; + + public ProfileServiceTest(String name){ + super(); + } + public ProfileServiceTest(){ + super(); + } + + + /** + * List the contents of ProfileService. + */ + public void testProfileServiceListContent() throws NamingException, Exce= ption{ + ManagementView managementView =3D JaasUtils.getInstance().getManagement= View(); + + log.info("List of ProfileService contents (default profile):"); + + StringBuilder sb =3D new StringBuilder(4*1024); + for( ComponentType type : managementView.getComponentTypes() ){ + sb.append(" * Type: ").append(type.toString()).append("\n"); + for( ManagedComponent component : managementView.getComponentsForType(= type) ){ + sb.append(" * Component: ").append(component.toString()).append("\n= "); + } + } + + log.info(sb.toString()); + } + + + + + = + /** + * @return the ProfileKey.name to use when loading the profile + */ + protected String getProfileName(){ return null; } + = + protected ProfileKey getProfileKey() + { + if(getProfileName() =3D=3D null) + return defaultProfile; + = + return new ProfileKey(getProfileName()); + } + + protected void removeDeployment(String deployment) + throws Exception + { + String names[] =3D new String[] {deployment}; + DeploymentManager deployMgr_ =3D getDeploymentManager(); + try + { + DeploymentProgress progress =3D deployMgr_.stop(names); + progress.run(); + assertFalse("failed: " + progress.getDeploymentStatus().getFailur= e(), progress.getDeploymentStatus().isFailed()); + } + finally + { + DeploymentProgress progress =3D deployMgr_.remove(names); + progress.run(); + assertFalse("failed: " + progress.getDeploymentStatus().getFailur= e(), progress.getDeploymentStatus().isFailed()); + } + } + + protected void createComponentTest(String templateName, + Map propValues, + String deploymentName, + ComponentType componentType, String componentName) + throws Exception + { + createComponentTest(templateName, propValues, deploymentName, compon= entType, componentName, true); + } + + protected void createComponentTest(String templateName, + Map propValues, + String deploymentName, + ComponentType componentType, String componentName, + boolean processChanges) + throws Exception + { + Set removedPropNames =3D Collections.emptySet(); + createComponentTest(templateName, propValues, removedPropNames, + deploymentName, componentType, componentName, processChanges); + } + protected void createComponentTest(String templateName, + Map propValues, + Set removedPropNames, + String deploymentName, + ComponentType componentType, String = componentName, + boolean processChanges) + throws Exception + { + ManagementView mgtView =3D getManagementView(); + DeploymentTemplateInfo info =3D mgtView.getTemplate(templateName); + assertNotNull("template " + templateName + " found", info); + Map props =3D info.getProperties(); + for(String propName : propValues.keySet()) + { + ManagedProperty prop =3D props.get(propName); + log.debug("createComponentTest("+propName+") before: "+prop.getVa= lue()); + assertNotNull("property " + propName + " found in template " + te= mplateName, prop); + prop.setValue(propValues.get(propName)); + log.debug("createComponentTest("+propName+") after: "+prop.getVal= ue()); + } + for(String propName : removedPropNames) + { + ManagedProperty prop =3D props.get(propName); + prop.setRemoved(true); + log.debug("removed property: "+propName); + } + + mgtView.applyTemplate(deploymentName, info); + if(processChanges) + { + mgtView.process(); + = + // reload the view + activeView =3D null; + mgtView =3D getManagementView(); + ManagedComponent dsMC =3D getManagedComponent(mgtView, componentT= ype, componentName); + assertNotNull(dsMC); + = + Set mcPropNames =3D new HashSet(dsMC.getPropertyN= ames()); + for(String propName : propValues.keySet()) + { + ManagedProperty prop =3D dsMC.getProperty(propName); + assertNotNull(prop); + Object propValue =3D prop.getValue(); + Object expectedValue =3D propValues.get(propName); + assertEquals(prop.getName(), expectedValue, propValue); + = + mcPropNames.remove(propName); + } + = + if(!mcPropNames.isEmpty()) + { + log.warn(getName() + "> untested properties: " + mcPropNames); + } + } + } + + /** + * Obtain the ProfileService.ManagementView + * @return + * @throws Exception + */ + protected ManagementView getManagementView() + throws Exception + { + /* + if( activeView =3D=3D null ) + { + InitialContext ctx =3D getInitialContext(); + ProfileService ps =3D (ProfileService) ctx.lookup("ProfileService= "); + activeView =3D ps.getViewManager(); + // Init the VFS to setup the vfs* protocol handlers + VFS.init(); + } + // Reload + activeView.load(); + return activeView; + /**/ + + return JaasUtils.getInstance().getManagementView(); + } + /** + * Obtain the ProfileService.ManagementView + * @return + * @throws Exception + */ + protected DeploymentManager getDeploymentManager() + throws Exception + { + /* + if( deployMgr =3D=3D null ) + { + InitialContext ctx =3D getInitialContext(); + ProfileService ps =3D (ProfileService) ctx.lookup("ProfileService= "); + deployMgr =3D ps.getDeploymentManager(); + deployMgr.loadProfile(getProfileKey()); + // Init the VFS to setup the vfs* protocol handlers + VFS.init(); + } + return deployMgr; + /**/ + return JaasUtils.getInstance().getDeploymentManager(); + } + + /** + * Locate the given ComponentType with the given component name. + * + * @param mgtView - + * @return the matching ManagedComponent if found, null otherwise + * @throws Exception + */ + protected ManagedComponent getManagedComponent(ManagementView mgtView, = ComponentType type, String name) + throws Exception + { + Set comps =3D mgtView.getComponentsForType(type); + ManagedComponent mc =3D null; + for (ManagedComponent comp : comps) + { + String cname =3D comp.getName(); + if( cname.endsWith(name) ) + { + mc =3D comp; + break; + } + } + return mc; + } + + protected MetaValueFactory getMetaValueFactory() + { + if(metaValueFactory =3D=3D null) + metaValueFactory =3D MetaValueFactory.getInstance(); + return metaValueFactory; + } + + InitialContext getInitialContext() throws NamingException{ + return new InitialContext(); + } + +} --===============0328163460858457000==--