Search in sources :

Example 6 with Node

use of hudson.model.Node 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 7 with Node

use of hudson.model.Node in project hudson-2.x by hudson.

the class LegacyMatrixConfigurationTest method testLoadLegacyMatrixProject.

/**
     * Tests unmarshalls MatrixProject configuration and checks whether properties are loaded correctly.
     *
     * @throws Exception if any.
     */
@Test
@Ignore
public void testLoadLegacyMatrixProject() throws Exception {
    Hudson hudson = createMock(Hudson.class);
    expect(hudson.getNodes()).andReturn(Lists.<Node>newArrayList()).anyTimes();
    expect(hudson.getInitLevel()).andReturn(InitMilestone.STARTED).anyTimes();
    expect(hudson.getRootDir()).andReturn(new File("./target/matrix")).anyTimes();
    ExtensionList<TransientProjectActionFactory> actionList = ExtensionList.create(hudson, TransientProjectActionFactory.class);
    expect(hudson.getExtensionList(TransientProjectActionFactory.class)).andReturn(actionList).anyTimes();
    ExtensionList<SaveableListener> saveableListenerList = ExtensionList.create(hudson, SaveableListener.class);
    expect(hudson.getExtensionList(SaveableListener.class)).andReturn(saveableListenerList).anyTimes();
    expect(hudson.getAllItems(MatrixConfiguration.class)).andReturn(Lists.<MatrixConfiguration>newArrayList()).anyTimes();
    mockStatic(Hudson.class);
    expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
    replayAll();
    MatrixProject project = (MatrixProject) Items.getConfigFile(config).read();
    project.setAllowSave(false);
    project.initProjectProperties();
    project.buildProjectProperties();
    verifyAll();
    assertEquals("/tmp/1", project.getProperty(AbstractProject.CUSTOM_WORKSPACE_PROPERTY_NAME).getValue());
    assertEquals(new Integer(7), CascadingUtil.getIntegerProjectProperty(project, AbstractProject.QUIET_PERIOD_PROPERTY_NAME).getValue());
    assertTrue(CascadingUtil.getBooleanProjectProperty(project, MatrixProject.RUN_SEQUENTIALLY_PROPERTY_NAME).getValue());
    assertEquals("!(label==\"win\" && DB==\"oracle\")", project.getProperty(MatrixProject.COMBINATION_FILTER_PROPERTY_NAME).getValue());
    assertEquals("label==\"unix\" && DB==\"mysql\"", project.getProperty(MatrixProject.TOUCH_STONE_COMBINATION_FILTER_PROPERTY_NAME).getValue());
    assertEquals(Result.SUCCESS, CascadingUtil.getResultProjectProperty(project, MatrixProject.TOUCH_STONE_RESULT_CONDITION_PROPERTY_NAME).getValue());
    assertEquals(new LogRotator(7, 7, 7, 7), CascadingUtil.getLogRotatorProjectProperty(project, MatrixProject.LOG_ROTATOR_PROPERTY_NAME).getValue());
    AxisList axes = CascadingUtil.getAxesListProjectProperty(project, MatrixProject.AXES_PROPERTY_NAME).getValue();
    assertEquals(2, axes.size());
    assertEquals("DB", axes.get(0).getName());
    assertEquals(2, axes.get(0).getValues().size());
    assertEquals("oracle", axes.get(0).getValues().get(0));
    assertEquals("mysql", axes.get(0).getValues().get(1));
    assertEquals("label", axes.get(1).getName());
    assertEquals(2, axes.get(1).getValues().size());
    assertEquals("unix", axes.get(1).getValues().get(0));
    assertEquals("win", axes.get(1).getValues().get(1));
    assertEquals(3, project.getActiveConfigurations().size());
    assertEquals(2, project.getActiveConfigurations().iterator().next().getCombination().size());
}
Also used : SaveableListener(hudson.model.listeners.SaveableListener) LogRotator(hudson.tasks.LogRotator) Hudson(hudson.model.Hudson) Node(hudson.model.Node) File(java.io.File) TransientProjectActionFactory(hudson.model.TransientProjectActionFactory) Ignore(org.junit.Ignore) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with Node

use of hudson.model.Node in project hudson-2.x by hudson.

the class NodeServiceImplTest method findNodeReturnMaster.

@Test
public void findNodeReturnMaster() {
    Node masterNode = hudson;
    assertThat(getInst().findNode(""), equalTo(masterNode));
    Mockito.verify(hudson, Mockito.never()).getNode("");
}
Also used : Node(hudson.model.Node) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 9 with Node

use of hudson.model.Node 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)

Example 10 with Node

use of hudson.model.Node in project hudson-2.x by hudson.

the class NodeServiceImpl method getNodes.

public List<Node> getNodes() {
    List<Node> nodesToCheck = getHudson().getNodes();
    List<Node> nodesToReturn = new ArrayList<Node>(nodesToCheck.size());
    for (hudson.model.Node node : nodesToCheck) {
        if (this.security.hasPermission(node, Permission.READ)) {
            nodesToReturn.add(node);
        }
    }
    return nodesToReturn;
}
Also used : Node(hudson.model.Node) ArrayList(java.util.ArrayList) Node(hudson.model.Node)

Aggregations

Node (hudson.model.Node)13 Test (org.junit.Test)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 ArrayList (java.util.ArrayList)4 NodeService (org.hudsonci.service.NodeService)3 AbortException (hudson.AbortException)1 Computer (hudson.model.Computer)1 EnvironmentSpecific (hudson.model.EnvironmentSpecific)1 Executor (hudson.model.Executor)1 Hudson (hudson.model.Hudson)1 Run (hudson.model.Run)1 TransientProjectActionFactory (hudson.model.TransientProjectActionFactory)1 SaveableListener (hudson.model.listeners.SaveableListener)1 NodeSpecific (hudson.slaves.NodeSpecific)1 LogRotator (hudson.tasks.LogRotator)1 StreamTaskListener (hudson.util.StreamTaskListener)1 File (java.io.File)1 Ignore (org.junit.Ignore)1