Package org.rioproject.test.associations

Source Code of org.rioproject.test.associations.AssociationVersionTest

/*
* Copyright to the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.rioproject.test.associations;

import junit.framework.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.rioproject.associations.Association;
import org.rioproject.associations.AssociationDescriptor;
import org.rioproject.associations.AssociationManagement;
import org.rioproject.impl.associations.DefaultAssociationManagement;
import org.rioproject.test.RioTestRunner;

import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

/**
* @author Dennis Reedy
*/
@RunWith(RioTestRunner.class)
public class AssociationVersionTest {

    @Test
    public void testVersionedAssociations() throws ExecutionException, InterruptedException, IOException {
        AssociationManagement aMgr = new DefaultAssociationManagement();
        AssociationDescriptor descriptor = AssociationDescriptor.create("Dummy", Dummy.class, System.getProperty("org.rioproject.groups"));
        descriptor.setMatchOnName(false);
        descriptor.setVersion("2.1");
        Association<Dummy> association = aMgr.addAssociationDescriptor(descriptor);
        Dummy dummy = association.getServiceFuture().get();
        Assert.assertNotNull(dummy);
        Assert.assertEquals("Expected 1 got " + association.getServiceCount(), 1, association.getServiceCount());
        Assert.assertTrue("Expected \'His Brother Darrel\', got " + dummy.getName(), "His Brother Darrel".equals(dummy.getName()));
    }

    @Test
    public void testVersionedAssociationRange() throws ExecutionException, InterruptedException, IOException {
        AssociationManagement aMgr = new DefaultAssociationManagement();
        AssociationDescriptor descriptor = AssociationDescriptor.create("Dummy", Dummy.class, System.getProperty("org.rioproject.groups"));
        descriptor.setMatchOnName(false);
        descriptor.setVersion("2.8");
        Association<Dummy> association = aMgr.addAssociationDescriptor(descriptor);
        Dummy dummy = association.getServiceFuture().get();
        Assert.assertNotNull(dummy);
        Assert.assertEquals("Expected 1 got "+association.getServiceCount(), 1, association.getServiceCount());
        Assert.assertTrue("Expected \'His Other Brother Darrel\', got "+dummy.getName(), "His Other Brother Darrel".equals(dummy.getName()));
    }

    @Test
    public void testVersionedAssociationNoMatches() throws ExecutionException, InterruptedException, IOException {
        AssociationManagement aMgr = new DefaultAssociationManagement();
        AssociationDescriptor descriptor = AssociationDescriptor.create("Dummy", Dummy.class, System.getProperty("org.rioproject.groups"));
        descriptor.setMatchOnName(false);
        descriptor.setVersion("1.0");
        Association<Dummy> association = aMgr.addAssociationDescriptor(descriptor);
        Dummy dummy = null;
        try {
            dummy = association.getServiceFuture().get(5, TimeUnit.SECONDS);
        } catch (TimeoutException e) {
            System.out.println("Received expected TimeoutException");
        }
        Assert.assertNull(dummy);
        Assert.assertEquals("Expected 0 got "+association.getServiceCount(), 0, association.getServiceCount());
    }

    @Test
    public void testVersionedAssociationMatchesAll() throws ExecutionException, InterruptedException, IOException {
        AssociationManagement aMgr = new DefaultAssociationManagement();
        AssociationDescriptor descriptor = AssociationDescriptor.create("Dummy", Dummy.class, System.getProperty("org.rioproject.groups"));
        descriptor.setMatchOnName(false);
        Association<Dummy> association = aMgr.addAssociationDescriptor(descriptor);
        Dummy dummy = null;
        TimeoutException timeoutException = null;
        try {
            dummy = association.getServiceFuture().get(5, TimeUnit.SECONDS);
        } catch (TimeoutException e) {
            timeoutException = e;
        }
        Assert.assertNull(timeoutException);
        Assert.assertNotNull(dummy);
        Assert.assertEquals("Expected 4 got "+association.getServiceCount(), 4, association.getServiceCount());
    }
}
TOP

Related Classes of org.rioproject.test.associations.AssociationVersionTest

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.