//
//  TestAcceleratorSeq.java
//  xal
//
//  Created by Tom Pelaia on 8/24/2011.
//  Copyright 2011 Oak Ridge National Lab. All rights reserved.
//

package xal.smf;

import xal.smf.data.XMLDataManager;
import xal.smf.impl.*;
import xal.smf.impl.qualify.*;

import java.util.*;
import java.net.URL;
import org.junit.*;


/** test the AcceleratorSeq class */
public class TestAcceleratorSeq {
    /** default accelerator */
    final private Accelerator DEFAULT_ACCELERATOR;
    
    
    /** Constructor */
    public TestAcceleratorSeq() {
        final URL opticsURL = getClass().getResource( "/xal/config/main.xal" );
        DEFAULT_ACCELERATOR = opticsURL != null ? XMLDataManager.getInstance( opticsURL ).getAccelerator() : null;
    }
    
    
    @Test
    /** test that we got a default accelerator */
    public void testForDefaultAccelerator() {
        Assert.assertTrue( DEFAULT_ACCELERATOR != null );
    }
    
    
    @Test
    /** test fetching nodes by type and verify that we got just that type */
    public void testNodeFetchingByType() {
        final AcceleratorSeq ring = DEFAULT_ACCELERATOR.findSequence( "Ring" );
        final List<AcceleratorNode> nodes = ring.getNodesOfType( "BPM" );
        Assert.assertTrue( nodes.size() > 0 );
        for ( final AcceleratorNode node : nodes ) {
            Assert.assertTrue( node instanceof BPM );
        }
    }
    
    
    @Test
    /** test fetching nodes by qualifier using a strong typing during the fetch */
    public void testNodeFetchingByStrongType() {
        final AcceleratorSeq ring = DEFAULT_ACCELERATOR.findSequence( "Ring" );
        final List<BPM> nodes = ring.getNodesOfClassWithStatus( BPM.class, true );
        Assert.assertTrue( nodes.size() > 0 );
        for ( final BPM node : nodes ) {
            Assert.assertTrue( node instanceof BPM );
        }
    }
}
//
//  TestAcceleratorSeq.java
//  xal
//
//  Created by Tom Pelaia on 8/24/2011.
//  Copyright 2011 Oak Ridge National Lab. All rights reserved.
//

package xal.smf;

import xal.smf.data.XMLDataManager;
import xal.smf.impl.*;
import xal.smf.impl.qualify.*;

import java.util.*;
import java.net.URL;
import org.junit.*;


/** test the AcceleratorSeq class */
public class TestAcceleratorSeq {
    /** default accelerator */
    static private Accelerator DEFAULT_ACCELERATOR;
    
    
    @BeforeClass
    public static void commonSetup() {
        final URL opticsURL = TestAcceleratorSeq.class.getResource( "/xal/config/main.xal" );
        DEFAULT_ACCELERATOR = opticsURL != null ? XMLDataManager.getInstance( opticsURL ).getAccelerator() : null;
    }
    
    
    @AfterClass
    public static void commonCleanup() {
        DEFAULT_ACCELERATOR = null;
    }
    
    
    @Test
    /** test that we got a default accelerator */
    public void testForDefaultAccelerator() {
        Assert.assertTrue( DEFAULT_ACCELERATOR != null );
    }
    
    
    @Test
    /** test fetching nodes by type and verify that we got just that type */
    public void testNodeFetchingByType() {
        final AcceleratorSeq ring = DEFAULT_ACCELERATOR.findSequence( "Ring" );
        final List<AcceleratorNode> nodes = ring.getNodesOfType( "BPM" );
        Assert.assertTrue( nodes.size() > 0 );
        for ( final AcceleratorNode node : nodes ) {
            Assert.assertTrue( node instanceof BPM );
        }
    }
    
    
    @Test
    /** test fetching nodes by qualifier using a strong typing during the fetch */
    public void testNodeFetchingByStrongType() {
        final AcceleratorSeq ring = DEFAULT_ACCELERATOR.findSequence( "Ring" );
        final List<BPM> nodes = ring.getNodesOfClassWithStatus( BPM.class, true );
        Assert.assertTrue( nodes.size() > 0 );
        for ( final BPM node : nodes ) {
            Assert.assertTrue( node instanceof BPM );
        }
    }
}
Load the accelerator once for the Accelerator sequence test suite.