Search in sources :

Example 1 with NodeService

use of org.hudsonci.service.NodeService in project hudson-2.x by hudson.

the class NodeServiceImplTest method getNodesDoesNotIncludeMaster.

@Test
public void getNodesDoesNotIncludeMaster() {
    List<Node> nodes = new ArrayList<Node>();
    nodes.add(node);
    Node masterNode = hudson;
    NodeService inst = spy(getInst());
    doReturn(nodes).when(hudson).getNodes();
    doReturn(true).when(security).hasPermission(node, Permission.READ);
    // try to fake it out
    doReturn(hudson).when(inst).getMasterNode();
    doReturn(true).when(security).hasPermission(masterNode, Permission.READ);
    List<Node> result = inst.getNodes();
    assertThat(result, contains(node));
    assertThat(result, not(contains(masterNode)));
}
Also used : Node(hudson.model.Node) NodeService(org.hudsonci.service.NodeService) ArrayList(java.util.ArrayList) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with NodeService

use of org.hudsonci.service.NodeService in project hudson-2.x by hudson.

the class NodeServiceImplTest method getAllNodesSecurity.

@Test
public void getAllNodesSecurity() {
    List<Node> nodes = new ArrayList<Node>();
    nodes.add(node);
    Node masterNode = hudson;
    NodeService inst = spy(getInst());
    doReturn(nodes).when(hudson).getNodes();
    doReturn(hudson).when(inst).getMasterNode();
    doReturn(true).when(security).hasPermission(masterNode, Permission.READ);
    List<Node> result = inst.getAllNodes();
    assertThat(result, not(contains(node)));
    assertThat(result, contains(masterNode));
    Mockito.verify(security).hasPermission(node, Permission.READ);
    Mockito.verify(security).hasPermission(masterNode, Permission.READ);
}
Also used : Node(hudson.model.Node) NodeService(org.hudsonci.service.NodeService) ArrayList(java.util.ArrayList) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with NodeService

use of org.hudsonci.service.NodeService in project hudson-2.x by hudson.

the class NodeServiceImplTest method getNodesSecurity.

@Test
public void getNodesSecurity() {
    List<Node> nodes = new ArrayList<Node>();
    nodes.add(node);
    NodeService inst = spy(getInst());
    doReturn(nodes).when(hudson).getNodes();
    doReturn(true).when(security).hasPermission(node, Permission.READ);
    List<Node> result = inst.getNodes();
    assertThat(result, contains(node));
    Mockito.verify(security).hasPermission(node, Permission.READ);
}
Also used : Node(hudson.model.Node) NodeService(org.hudsonci.service.NodeService) ArrayList(java.util.ArrayList) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

Node (hudson.model.Node)3 ArrayList (java.util.ArrayList)3 NodeService (org.hudsonci.service.NodeService)3 Test (org.junit.Test)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3