/*
* JBoss, Home of Professional Open Source.
* Copyright 2009, 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.ps;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import org.jboss.deployers.spi.management.ManagementView;
import org.jboss.jopr.jsfunit.*;
import java.io.*;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.commons.lang.StringUtils;
import org.jboss.jopr.jsfunit.exceptions.*;
import org.jboss.jopr.jsfunit.util.EmbJoprTestToolkit.*;
import org.jboss.managed.api.ComponentType;
import org.jboss.managed.api.DeploymentTemplateInfo;
import org.jboss.managed.api.ManagedComponent;
import org.jboss.managed.api.ManagedDeployment;
import org.jboss.profileservice.spi.*;
/**
* This class contains tests for testing the EmbJopr Application
* Management Functions for Enterprise Application archives with JBoss AS 5.
*
* @author Ondrej Zizka
*
*/
public class ProfileServiceTest extends ApplicationTestBaseAS5 {
/**
* @return the suite of tests being tested
*/
public static Test suite(){
return new TestSuite(ProfileServiceTest.class);
}
/*
* Disabled: ProfileService is JAAS-secured.
* Candidate for deletion.
*/
public void DISABLEDtestManagedView() throws IOException, Exception
{
log.info(" ------ LISTING PROFILES -------- ");
ProfileService ps = this.getProfileService();
Collection<ProfileKey> profileKeys = ps.getProfileKeys();
printProfiles( profileKeys, ps, 0);
log.info(" ------ DUMPING VIEWMANAGER -------- ");
ManagementView viewManager = ps.getViewManager();
for( String name : viewManager.getTemplateNames() ){
DeploymentTemplateInfo template = viewManager.getTemplate(name);
log.debug(" * Template: "+name+"; Desc: "+template.getDescription());
}
viewManager.getComponentsForType( new ComponentType() );
for( String name : viewManager.getDeploymentNames() ){
ManagedDeployment deployment = viewManager.getDeployment(name);
log.info( " * Deployment name: "+ deployment.getName() );
log.info( " Deployment properties: "+ deployment.getProperties() );
}
}// testManagedView()
/*
* Lists everything that is in ProfileService.
*/
public void testManagedView() throws IOException, Exception
{
log.info(" ------ LISTING PROFILES -------- ");
ProfileService ps = ejtt.profileService.getProfileService();
Collection<ProfileKey> profileKeys = ps.getProfileKeys();
printProfiles( profileKeys, ps, 0);
log.info(" ------ DUMPING VIEWMANAGER -------- ");
ManagementView viewManager = ejtt.profileService.getManagementView();
for( String name : viewManager.getTemplateNames() ){
DeploymentTemplateInfo template = viewManager.getTemplate(name);
log.debug(" * Template: "+name+"; Desc: "+template.getDescription());
}
for( ComponentType type : viewManager.getComponentTypes() ){
log.info(" * Type: "+type.toString());
for( ManagedComponent component : viewManager.getComponentsForType(type) ){
log.info(" * Component: "+component.toString());
}
}
for( String name : viewManager.getDeploymentNames() ){
ManagedDeployment deployment = viewManager.getDeployment(name);
log.info( " * Deployment name: "+ deployment.getName() );
log.info( " Deployment properties: "+ deployment.getProperties() );
}
}// testManagedView()
public void printProfiles( Collection<ProfileKey> profileKeys, ProfileService ps, int level ) throws NoSuchProfileException{
String spaces = StringUtils.repeat(" ", level);
for (ProfileKey profileKey : profileKeys) {
Profile profile = ps.getProfile(profileKey);
log.info( spaces + " * Profile: "+ profile.getKey().toString() );
Collection<ProfileDeployment> deployments = profile.getDeployments();
for (ProfileDeployment deployment : deployments) {
log.info( spaces + " * Deployment name: "+ deployment.getName() );
log.info( spaces + " Deployment root: "+ deployment.getRoot() );
Map<String, Object> attachments = deployment.getAttachments();
for ( String key : attachments.keySet() ) {
log.info( spaces + " * Attachment: "+ key + " = " + attachments.get(key) );
}// attachments
}// deployments
// deployments
log.info( spaces + " * Subprofiles:");
Collection<ProfileKey> subProfiles = profile.getSubProfiles();
printProfiles(subProfiles, ps, level+1);
}// profileKeys
}
}// class ProfileServiceTest