alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Glassfish example source code file (ListComponentsCommandTest.java)

This example Glassfish source code file (ListComponentsCommandTest.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Glassfish tags/keywords

applicationtest, bean, configbeanproxy, ducktyped, engine, io, javabean, list, list, moduletest, propertyvetoexception, propertyvetoexception, string, string, t, t, unsupportedoperationexception, util

The Glassfish ListComponentsCommandTest.java source code

/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright (c) 2008-2010 Oracle and/or its affiliates. All rights reserved.
 *
 * The contents of this file are subject to the terms of either the GNU
 * General Public License Version 2 only ("GPL") or the Common Development
 * and Distribution License("CDDL") (collectively, the "License").  You
 * may not use this file except in compliance with the License.  You can
 * obtain a copy of the License at
 * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
 * or packager/legal/LICENSE.txt.  See the License for the specific
 * language governing permissions and limitations under the License.
 *
 * When distributing the software, include this License Header Notice in each
 * file and include the License file at packager/legal/LICENSE.txt.
 *
 * GPL Classpath Exception:
 * Oracle designates this particular file as subject to the "Classpath"
 * exception as provided by Oracle in the GPL Version 2 section of the License
 * file that accompanied this code.
 *
 * Modifications:
 * If applicable, add the following below the License Header, with the fields
 * enclosed by brackets [] replaced by your own identifying information:
 * "Portions Copyright [year] [name of copyright owner]"
 *
 * Contributor(s):
 * If you wish your version of this file to be governed by only the CDDL or
 * only the GPL Version 2, indicate your decision by adding "[Contributor]
 * elects to include this software in this distribution under the [CDDL or GPL
 * Version 2] license."  If you don't indicate a single choice of license, a
 * recipient has the option to distribute your version of this file under
 * either the CDDL, the GPL Version 2 or to extend the choice of license to
 * its licensees as provided above.  However, if you add GPL Version 2 code
 * and therefore, elected the GPL Version 2 license, then the option applies
 * only if the new code is made subject to such option by the copyright
 * holder.
 */

package org.glassfish.deployment.admin;

import java.io.File;
import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.Before;
import org.jvnet.hk2.config.DuckTyped;
import org.jvnet.hk2.config.ConfigBeanProxy;
import org.jvnet.hk2.config.TransactionFailure;
import org.jvnet.hk2.config.types.Property;

import com.sun.enterprise.config.serverbeans.*;
import org.glassfish.api.deployment.DeployCommandParameters;

import java.beans.PropertyVetoException;
import java.util.List;
import java.util.Map;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Properties;


/**
 * junit test to test ListComponentsCommand class
 */
public class ListComponentsCommandTest {
    private ListComponentsCommand lcc = null;

    @Test
    public void isApplicationOfThisTypeTest() {
        try {
            ApplicationTest app = new ApplicationTest();
            Engine eng = new EngineTest();
            eng.setSniffer("web");
            List<Engine> engines = new ArrayList();
            engines.add(eng);
            List<Module> modules = new ArrayList();
            ModuleTest aModule = new ModuleTest();
            aModule.setEngines(engines);
            modules.add(aModule);
            app.setModules(modules);
        
            boolean ret = lcc.isApplicationOfThisType(app, "web");
            assertTrue("test app with sniffer engine=web", true==lcc.isApplicationOfThisType(app, "web"));
            //negative testcase
            assertFalse("test app with sniffer engine=web", true==lcc.isApplicationOfThisType(app, "ejb"));
        }
        catch (Exception ex) {
            //ignore exception
        } 
    }

        @Test
    public void getSnifferEnginesTest() {
        try {
            Engine eng1 = new EngineTest();
            eng1.setSniffer("web");
            Engine eng2 = new EngineTest();
            eng2.setSniffer("security");
            List<Engine> engines = new ArrayList();
            engines.add(eng1);
            engines.add(eng2);
            
            ApplicationTest app = new ApplicationTest();
            List<Module> modules = new ArrayList();              
            ModuleTest aModule = new ModuleTest();
            aModule.setEngines(engines);
            modules.add(aModule);
            app.setModules(modules);
            String snifferEngines = lcc.getSnifferEngines(app.getModule().get(0), true);
            assertEquals("compare all sniffer engines", "<web, security>",
                        snifferEngines);
        }
        catch (Exception ex) {
            //ignore exception
        } 
    }


    @Before
    public void setup() {
        lcc = new ListComponentsCommand();
    }

    public class RandomConfig implements ConfigBeanProxy {

        @DuckTyped
        public ConfigBeanProxy getParent() {
            // TODO
            throw new UnsupportedOperationException();
        }
        @DuckTyped
        public <T extends ConfigBeanProxy> T getParent(Class type) {
            // TODO
            throw new UnsupportedOperationException();
        }
        @DuckTyped
        public Property getProperty(String name) {
            // TODO
            throw new UnsupportedOperationException();
        }

        @DuckTyped
        public String getPropertyValue(String name) {
            // TODO
            throw new UnsupportedOperationException();
        }

        @DuckTyped
        public String getPropertyValue(String name, String defaultValue) {
            // TODO
            throw new UnsupportedOperationException();
        }

        @DuckTyped
        public <T extends ConfigBeanProxy> T createChild(Class type) throws TransactionFailure {
            throw new UnsupportedOperationException();
        }

        @Override
        public ConfigBeanProxy deepCopy(ConfigBeanProxy parent) {
            throw new UnsupportedOperationException();
        }

        //hk2's Injectable class
        public void injectedInto(Object target){}
    }

    public class ModuleTest extends RandomConfig implements Module {

        public String getName() {
            return null;
        }

        public void setName(String value) throws PropertyVetoException {}

        private List<Engine> engineList = null;

        public List<Engine> getEngines() {
            return engineList;
        }
        public Engine getEngine(String snifferType) {return null;}

        public void setEngines(List<Engine> engines) {
            this.engineList = engines;
        }

       public List<Property> getProperty() {return null;}
  public void setResources(com.sun.enterprise.config.serverbeans.Resources res){}
        public Resources  getResources(){return null;}


    }
        //mock-up Application object
    public class ApplicationTest extends RandomConfig implements Application {
        private List<Module> modules = null;
        
        public String getName() {
            return "hello";
        }
        public void setResources(com.sun.enterprise.config.serverbeans.Resources res){}
        public Resources  getResources(){return null;}
        public void setName(String value) throws PropertyVetoException {}
        public String getContextRoot() { return "hello";}
        public void setContextRoot(String value) throws PropertyVetoException {}
        public String getLocation(){ return "";}
        public void setLocation(String value) throws PropertyVetoException{}
        public String getObjectType(){ return "";}
        public void setObjectType(String value) throws PropertyVetoException{}
        public String getEnabled(){ return "";}
        public void setEnabled(String value) throws PropertyVetoException{}
        public String getLibraries(){ return "";}
        public void setLibraries(String value) throws PropertyVetoException{}
        public String getAvailabilityEnabled(){ return "";}
        public void setAvailabilityEnabled(String value) throws PropertyVetoException{}
        public String getAsyncReplication() { return "";}
        public void setAsyncReplication (String value) throws PropertyVetoException {}
        public String getDirectoryDeployed(){ return "";}
        public void setDirectoryDeployed(String value) throws PropertyVetoException{}
        public String getDescription(){ return "";}
        public void setDescription(String value) throws PropertyVetoException{}
        public List<Engine> getEngine(){ return null;}
        public List<Property> getProperty(){ return null;}
        public List<WebServiceEndpoint> getWebServiceEndpoint() {return null;}
        public <T extends ApplicationConfig> T getApplicationConfig(Class type) {return null;}
        public List<ApplicationConfig> getApplicationConfigs() {return null;}
        public Map<String, Properties> getModulePropertiesMap() {return null;}

        public Module getModule(String moduleName) {return null;}
        public boolean isStandaloneModule() {return false;}
        public boolean isLifecycleModule() {return false;}
        public boolean isOSGiModule() {return false;}
        public boolean containsSnifferType(String snifferType) {return false;}
        public List<Module> getModule() {
            return modules;
        }

        public void setModules(List<Module> modules) {
        this.modules = modules;
        }

            public Properties getDeployProperties() {
                return new Properties();
            }

            public DeployCommandParameters getDeployParameters(ApplicationRef appRef) {
                return new DeployCommandParameters();
            }
        
        public File application() {return null;}
        public File deploymentPlan() {return null;}
        public void recordFileLocations(File appFile, File deploymentPlanFile) {}
    }

            //mock-up Engine object
    public class EngineTest extends RandomConfig implements Engine {
        private String sniffer = "";
        public String getSniffer() {return sniffer;}
        public void setSniffer(String value) throws PropertyVetoException {
            sniffer = value;
        }
        public String getDescription() {return "";}
        public void setDescription(String value) {}
        public List<Property> getProperty() {return null;}

            //config.serverbeans.Modules
        public String getName() { 
            return "hello";
        }
        public void setName(String value) throws PropertyVetoException {}

        public ApplicationConfig getConfig() {
            return null;
        }

        public void setConfig(ApplicationConfig config) throws PropertyVetoException {}

        public List<ApplicationConfig> getApplicationConfigs() {
            return Collections.EMPTY_LIST;
        }

        public ApplicationConfig getApplicationConfig() {
            return null;
        }

        public void setApplicationConfig(ApplicationConfig config) {
            // no-op for this test
        }

        public <T extends ApplicationConfig> T newApplicationConfig(Class configType) throws TransactionFailure {
            return null;
        }
    }
}

Other Glassfish examples (source code examples)

Here is a short list of links related to this Glassfish ListComponentsCommandTest.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.