Package javaflow.network.definer

Source Code of javaflow.network.definer.PortReferenceTest

package javaflow.network.definer;

import javaflow.network.api.MalformedPortReference;
import javaflow.network.api.PortReference;
import org.testng.Assert;
import org.testng.annotations.Test;

public class PortReferenceTest {

    @Test
    public void simplePort() {
        PortReference ref = PortReference.parse("in.OUT");
        Assert.assertEquals(ref.componentName(), "in");
        Assert.assertEquals(ref.portName(), "OUT");
        Assert.assertEquals(ref.componentAndPortName(), "in.OUT");
        Assert.assertFalse(ref.isArrayPort());
        Assert.assertEquals(ref.toString(), "in.OUT");
    }

    @Test(expectedExceptions = Error.class)
    public void simplePortArrayIndexThrowsError() {
        PortReference ref = PortReference.parse("in.OUT");
        ref.portIndex();
    }

    @Test
    public void arrayPort() {
        PortReference ref = PortReference.parse("in.BLAAH[0]");
        Assert.assertEquals(ref.componentName(), "in");
        Assert.assertEquals(ref.portName(), "BLAAH");
        Assert.assertEquals(ref.componentAndPortName(), "in.BLAAH");
        Assert.assertTrue(ref.isArrayPort());
        Assert.assertEquals(ref.portIndex(), 0);
        Assert.assertEquals(ref.toString(), "in.BLAAH[0]");
    }

    @Test
    public void simplePortNoComponent() {
        PortReference ref = PortReference.parse("OUT");
        Assert.assertEquals(ref.componentName(), null);
        Assert.assertEquals(ref.portName(), "OUT");
        Assert.assertEquals(ref.componentAndPortName(), null);
        Assert.assertFalse(ref.isArrayPort());
        Assert.assertEquals(ref.toString(), "OUT");
    }

    @Test
    public void arrayPortNoComponent() {
        PortReference ref = PortReference.parse("BLAAH[0]");
        Assert.assertEquals(ref.componentName(), null);
        Assert.assertEquals(ref.portName(), "BLAAH");
        Assert.assertEquals(ref.componentAndPortName(), null);
        Assert.assertTrue(ref.isArrayPort());
        Assert.assertEquals(ref.portIndex(), 0);
        Assert.assertEquals(ref.toString(), "BLAAH[0]");
    }

    @Test(expectedExceptions = MalformedPortReference.class)
    public void malformedInput2() {
        PortReference.parse("in.");
    }

    @Test(expectedExceptions = MalformedPortReference.class)
    public void malformedInput3() {
        PortReference.parse("in.asd[");
    }
}
TOP

Related Classes of javaflow.network.definer.PortReferenceTest

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.