Package org.jboss.on.embedded.manager.operationhistory

Source Code of org.jboss.on.embedded.manager.operationhistory.OperationHistoryManagerBeanTest

/*
* Embedded Jopr Project
* Copyright (C) 2006-2009 Red Hat, Inc.
* All rights reserved.
*
* This program 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 program 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 program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package org.jboss.on.embedded.manager.operationhistory;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.operation.HistoryJobId;
import org.rhq.core.domain.operation.OperationHistory;
import org.rhq.core.domain.resource.Resource;
import org.rhq.core.domain.resource.ResourceType;
import org.testng.annotations.BeforeClass;

import org.jboss.on.embedded.bean.history.operation.OperationHistoryManagerBean;
import org.jboss.on.embedded.manager.ResourceManager;
import org.jboss.on.embedded.util.EmbeddedPluginContainerHelper;

/**
* OperationHistoryManagerBean Tester.
*
* @author Mark Spritzler
*/
public class OperationHistoryManagerBeanTest extends EmbeddedPluginContainerHelper
{
    //Attributes
    private OperationHistoryManagerBean historyBean;
    private List<HistoryJobId> operationIds = new ArrayList<HistoryJobId>();
    private String[] operations =
            {
                    "testOperation1",
                    "testOperation2",
                    "testOperation3",
                    "testOperation4",
                    "testOperation5"
            };
    private Resource[] resources = new Resource[3];
    private ResourceType[] resourceTypes = new ResourceType[3];
    private Configuration[] configurations = new Configuration[3];

    private Resource singleResource;
    private ResourceType singleResourceType;
    private Configuration singleConfiguration;

    @Override
    protected String getScenario()
    {
        return "scenario4.xml";
    }

    @BeforeClass
    public void initializeTest()
    {
        historyBean = new OperationHistoryManagerBean();
        setResourceAttributes();
    }

    //@Test
    public void testAddOperationHistory()
    {
        for (int j = 0; j < 3; j++)
        {
            for (int l = 0; l < 5; l++)
            {
                OperationHistory history = historyBean.addOperationHistory(operations[l], configurations[j], resources[j], resourceTypes[j]);
                assert history != null : "History should not be null";
                operationIds.add(history.getJobId());
            }
        }

        for (int l = 0; l < 2; l++)
        {
            OperationHistory history = historyBean.addOperationHistory(
                    operations[l],
                    singleConfiguration,
                    singleResource,
                    singleResourceType);

            assert history != null : "History should not be null";
            operationIds.add(history.getJobId());
        }

    }

    //@Test(dependsOnMethods = {"testAddOperationHistory"})
    public void testGetOperationHistory()
    {
        for (HistoryJobId operationId : operationIds)
        {
            OperationHistory history = historyBean.getHistory(operationId.toString());
            assert history != null : "History should not be null";
        }
    }

    //@Test(dependsOnMethods = {"testAddOperationHistory"})
    public void testGetAllOperationHistory()
    {
        Collection<OperationHistory> histories = historyBean.getAllHistory();
        assert histories != null : "We should have retrieved all the histories";
        assert histories.size() == 17 : "The number of Operations in the historyBean should be 16";
    }

    //@Test(dependsOnMethods = {"testAddOperationHistory"})
    public void testGetOperationHistoryForResourceType()
    {
        for (ResourceType resourceType : resourceTypes)
        {
            Collection<OperationHistory> histories = historyBean.getHistoryForResourceType(resourceType);
            assert histories != null : "History should have been returned for each ResourceType";
            if (resourceType.getName().equals("jms-topic"))
            {
                assert histories.size() == 7 : "There should be 7 Operations for Resource Type jms-topic.";
            }
            else
            {
                assert histories.size() == 5 : "There should be 5 Operations for each Resource Type besides jms-topic.";
            }

        }
    }

    //@Test(dependsOnMethods = {"testAddOperationHistory"})
    public void testGetOperationHistoryForResource()
    {
        for (Resource resource : resources)
        {
            Collection<OperationHistory> histories = historyBean.getHistoryForResource(resource);
            assert histories != null : "History should have been returned for each Resource";
            assert histories.size() == 5 : "There should be 5 Operations for each Resource.";
        }
    }

    private void setResourceAttributes()
    {
        ResourceManager manager = getManager();
        ResourceType resourceType1 = manager.getResourceType("xa-datasource");

        // Find the datasource to be modified and ensure it's there
        Resource datasource1 = getResourceInstance(resourceType1, "RHQDS");

        assert datasource1 != null : "Test datasource could not be retrieved";

        // Rename the JNDI name for that resource

        Configuration configuration1 = manager.getResourceConfiguration(datasource1);
        resourceTypes[0] = resourceType1;
        resources[0] = datasource1;
        configurations[0] = configuration1;

        ResourceType resourceType2 = manager.getResourceType("jms-queue");

        // Find the Queue
        Resource queue2 = getResourceInstance(resourceType2, "EventQueue");

        assert queue2 != null : "Test queue could not be retrieved";

        // Setup the second array elements
        Configuration configuration2 = manager.getResourceConfiguration(queue2);
        resourceTypes[1] = resourceType2;
        resources[1] = queue2;
        configurations[1] = configuration2;

        ResourceType resourceType3 = manager.getResourceType("jms-topic");

        // Find the topic
        Resource topic3 = getResourceInstance(resourceType3, "InventoryTopic");
        assert topic3 != null : "Test topic could not be retrieved";

        Configuration configuration3 = manager.getResourceConfiguration(topic3);

        // Set the last elements in the array
        resourceTypes[2] = resourceType3;
        resources[2] = topic3;
        configurations[2] = configuration3;

        // Find the topic
        singleResourceType = resourceType3;
        singleResource = getResourceInstance(singleResourceType, "SingleTestTopic");
        assert singleResource != null : "Test singleResource topic could not be retrieved";

        singleConfiguration = manager.getResourceConfiguration(singleResource);

    }

}
TOP

Related Classes of org.jboss.on.embedded.manager.operationhistory.OperationHistoryManagerBeanTest

TOP
Copyright © 2018 www.massapi.com. 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.