Package org.rhq.enterprise.server.sync.validators

Examples of org.rhq.enterprise.server.sync.validators.DeployedAgentPluginsValidator


    private static final Log LOG = LogFactory.getLog(DeployedAgentPluginsValidator.class);
   
    public void testCanExportAndImportState() throws Exception {
        final PluginManagerLocal pluginManager = context.mock(PluginManagerLocal.class);
       
        final DeployedAgentPluginsValidator validator = new DeployedAgentPluginsValidator(pluginManager);
       
        context.checking(new Expectations() {
            {
                oneOf(pluginManager).getInstalledPlugins();
                will(returnValue(new ArrayList<Plugin>(getDeployedPlugins())));
            }
        });
       
        validator.initialize(null, null);
       
        StringWriter output = new StringWriter();
        try {
            XMLOutputFactory ofactory = XMLOutputFactory.newInstance();
           
            XMLStreamWriter wrt = ofactory.createXMLStreamWriter(output);
            //wrap the exported plugins in "something" so that we produce
            //a valid xml
            wrt.writeStartDocument();
            wrt.writeStartElement("root");
           
            validator.exportState(new ExportWriter(wrt));
       
            wrt.writeEndDocument();
           
            wrt.close();
           
            StringReader input = new StringReader(output.toString());
           
            try {
                XMLInputFactory ifactory = XMLInputFactory.newInstance();
                XMLStreamReader rdr = ifactory.createXMLStreamReader(input);
               
                //push the reader to the start of the plugin elements
                //this is what is expected by the validators
                rdr.nextTag();
               
                validator.initializeExportedStateValidation(new ExportReader(rdr));
               
                rdr.close();
               
                assertEquals(validator.getPluginsToValidate(), getDeployedPlugins());
            } finally {
                input.close();
            }
        } catch (Exception e) {
            LOG.error("Test failed. Output generated so far:\n" + output, e);
View Full Code Here


                allowing(pluginManager).getInstalledPlugins();
                will(returnValue(installedPlugins));
            }
        });
       
        DeployedAgentPluginsValidator validator = new DeployedAgentPluginsValidator(pluginManager);
       
        Set<DeployedAgentPluginsValidator.ConsistentPlugin> pluginsToValidate = getDeployedPlugins();
       
        validator.initialize(null, null);
       
        validator.setPluginsToValidate(pluginsToValidate);
       
        //this should validate cleanly
        validator.validateExportedState();
       
        //now add 1 plugin to the validated state
        DeployedAgentPluginsValidator.ConsistentPlugin newPlugin = createPlugin("superfluous", "1", "md5_4");
        pluginsToValidate.add(newPlugin);
       
        try {
            validator.validateExportedState();
            fail("validation should have detected that the current installation has one plugin less.");
        } catch (InconsistentStateException e) {
            //this is expected
        }
       
        //ok, remove the new plugin from the "exported state" and put it in the current state
        pluginsToValidate.remove(newPlugin);
        installedPlugins.add(newPlugin);
       
        try {
            validator.validateExportedState();
            fail("validation should have detected that the current installation has one plugin more.");
        } catch (InconsistentStateException e) {
            //ok
        }
       
        //make the current state and exported state be in sync again
        DeployedAgentPluginsValidator.ConsistentPlugin newPluginCopy = new DeployedAgentPluginsValidator.ConsistentPlugin(newPlugin);
        pluginsToValidate.add(newPluginCopy);
       
        //change the newPlugin to not be equal
        newPlugin.setMd5("md5_different");
       
        try {
            validator.validateExportedState();
            fail("validation should have failed because one of the plugins differs between current and exported states.");
        } catch (InconsistentStateException e) {
            //ok
        }
       
        newPlugin.setMd5(newPluginCopy.getMd5());
        newPluginCopy.setMd5("md5_different");
       
        try {
            validator.validateExportedState();
            fail("validation should have failed because one of the plugins differs between current and exported states.");
        } catch (InconsistentStateException e) {
            //ok
        }       
    }
View Full Code Here

    }
   
    public void testAllValidatorsEqual() {
        PluginManagerLocal pluginManager = context.mock(PluginManagerLocal.class);
       
        DeployedAgentPluginsValidator v1 = new DeployedAgentPluginsValidator(pluginManager);
        DeployedAgentPluginsValidator v2 = new DeployedAgentPluginsValidator(pluginManager);
        DeployedAgentPluginsValidator v3 = new DeployedAgentPluginsValidator(pluginManager);
        Object o = new Object();
       
        assertEquals(v1, v2);
        assertEquals(v1, v3);
        assertEquals(v2, v3);
       
        assertFalse(v1.equals(o));
        assertFalse(v2.equals(o));
        assertFalse(v3.equals(o));
    }
View Full Code Here

TOP

Related Classes of org.rhq.enterprise.server.sync.validators.DeployedAgentPluginsValidator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.