package forklift.source.sources;

import forklift.source.SourceUtil;
import forklift.source.decorators.RoleInput;

import org.junit.Assert;
import org.junit.Test;

public class RoleInputSourceTest {
    @Test
    public void testUndefinedRoles() {
        Assert.assertFalse(new RoleInputSource((String) null).isRoleDefined());
        Assert.assertFalse(new RoleInputSource("").isRoleDefined());
    }

    @Test
    public void testUndefinedRolesAreEqual() {
        Assert.assertEquals(new RoleInputSource((String) null),
                            new RoleInputSource(""));
    }

    @Test
    public void testEqualityCorrespondsRoleEquality() {
        final String testRole = "test-role";
        final String otherRole = "other-role";

        Assert.assertEquals(new RoleInputSource(testRole),
                            new RoleInputSource(testRole));
        Assert.assertNotEquals(new RoleInputSource(testRole),
                               new RoleInputSource(otherRole));
    }

    @Test
    public void testRoleInputHasDefaultRoleWithNoGivenRole() {
        final RoleInputSource source = (RoleInputSource) SourceUtil.getSources(DefaultRoleConsumer.class, RoleInputSource.class).findFirst().get();
        Assert.assertEquals("DefaultRoleConsumer", source.getRole());
    }

    @Test
    public void testRoleInputHasGivenRole() {
        final RoleInputSource source = (RoleInputSource) SourceUtil.getSources(TestRoleConsumer.class, RoleInputSource.class).findFirst().get();
        Assert.assertEquals("test-role", source.getRole());
    }

    @RoleInput
    public class DefaultRoleConsumer {}

    @RoleInput(role = "test-role")
    public class TestRoleConsumer {}
}

@@ -27,16 +27,61 @@
 urces;%0A%0A
+import forklift.source.LogicalSourceContext;%0A
 import f
@@ -107,16 +107,16 @@
 ceUtil;%0A
-
 import f
@@ -616,32 +616,692 @@
 ce(%22%22));%0A    %7D%0A%0A
+    @Test%0A    public void testIsLogicalSource() %7B%0A        Assert.assertTrue(new RoleInputSource(%22TestRole%22).isLogicalSource());%0A    %7D%0A%0A    @Test%0A    public void testActionSourceIsTakenFromContext() %7B%0A        final LogicalSourceContext testContext = source -%3E %7B%0A            return source%0A                .apply(RoleInputSource.class, roleSource -%3E new QueueSource(%22action-role-%22 + roleSource.getRole()))%0A                .get();%0A        %7D;%0A%0A        final RoleInputSource roleInput = new RoleInputSource(%22TestRole%22);%0A%0A        Assert.assertEquals(new QueueSource(%22action-role-TestRole%22),%0A                            roleInput.getActionSource(testContext));%0A    %7D%0A%0A
     @Test%0A    pu
@@ -1333,16 +1333,18 @@
 responds
+To
 RoleEqua

Add test for RoleInput as a LogicalSource