Search in sources :

Example 1 with MockBuildAgent

use of jetbrains.buildServer.serverSide.impl.MockBuildAgent in project teamcity-rest by JetBrains.

the class AgentPoolMutationTest method testBulkMoveAgentsToPool.

@Test
public void testBulkMoveAgentsToPool() throws NoSuchAgentPoolException, AgentTypeCannotBeMovedException, PoolQuotaExceededException, AgentPoolCannotBeRenamedException {
    AgentPool sourcePool1 = myFixture.getAgentPoolManager().createNewAgentPool("sourcePool1");
    AgentPool sourcePool2 = myFixture.getAgentPoolManager().createNewAgentPool("sourcePool2");
    AgentPool targetPool = myFixture.getAgentPoolManager().createNewAgentPool("targetPool");
    MockBuildAgent agent1 = myFixture.createEnabledAgent("smth");
    registerAndEnableAgent(agent1);
    MockBuildAgent agent2 = myFixture.createEnabledAgent("smth");
    registerAndEnableAgent(agent2);
    myFixture.getAgentPoolManager().moveAgentToPool(sourcePool1.getAgentPoolId(), agent1);
    myFixture.getAgentPoolManager().moveAgentToPool(sourcePool2.getAgentPoolId(), agent2);
    BulkMoveAgentsToAgentPoolInput input = new BulkMoveAgentsToAgentPoolInput();
    input.setAgentRawIds(Arrays.asList(agent1.getId(), agent2.getId()));
    input.setTargetAgentPoolRawId(targetPool.getAgentPoolId());
    MockDataFetchingEnvironment dfe = new MockDataFetchingEnvironment();
    DataFetcherResult<BulkMoveAgentToAgentsPoolPayload> result = myMutation.bulkMoveAgentsToAgentPool(input);
    assertNotNull(result);
    assertFalse(result.hasErrors());
    assertNotNull(result.getData());
    BulkMoveAgentToAgentsPoolPayload payload = result.getData();
    assertEquals(targetPool.getName(), payload.getTargetAgentPool().getName());
    Collection<Integer> agentsInPool = myFixture.getAgentPoolManager().getAgentTypeIdsByPool(targetPool.getAgentPoolId());
    assertContains(agentsInPool, agent1.getAgentTypeId(), agent2.getAgentTypeId());
}
Also used : MockBuildAgent(jetbrains.buildServer.serverSide.impl.MockBuildAgent) Test(org.testng.annotations.Test)

Example 2 with MockBuildAgent

use of jetbrains.buildServer.serverSide.impl.MockBuildAgent in project teamcity-rest by JetBrains.

the class AgentFinderTest method testMisc.

@Test
public void testMisc() {
    myAgent1.addConfigParameter("x", "1");
    myAgent1.pushAgentTypeData();
    MockBuildAgent agent10 = myFixture.createEnabledAgent("agent10", "Ant");
    agent10.addConfigParameter("a", "b");
    agent10.addConfigParameter("x", "1");
    agent10.pushAgentTypeData();
    checkAgents(null, myAgent1, myAgent2, agent10);
    checkAgents("name:" + myAgent1.getName(), myAgent1);
    checkAgents("name:" + myAgent3.getName(), myAgent3);
    checkAgents("id:" + myAgent1.getId(), myAgent1);
    checkAgents("id:" + myAgent3.getId(), myAgent3);
    checkAgents("parameter:(name:a)", agent10);
    checkAgents("parameter:(name:zzz,value:1,matchType:does-not-equal,matchScope:all)", myAgent1, myAgent2, agent10);
    myAgent2.addConfigParameter("x", "3");
    myAgent2.pushAgentTypeData();
    checkAgents("parameter:(name:(matchType:any),value:1,matchType:does-not-equal,matchScope:all)", myAgent2);
}
Also used : MockBuildAgent(jetbrains.buildServer.serverSide.impl.MockBuildAgent) Test(org.testng.annotations.Test)

Example 3 with MockBuildAgent

use of jetbrains.buildServer.serverSide.impl.MockBuildAgent in project teamcity-rest by JetBrains.

the class BuildTypeTest method testAgents.

@Test
public void testAgents() {
    // we will need the agent license
    myBuildAgent.setAuthorized(false, null, "");
    ProjectEx project10 = createProject("project10", "project 10");
    BuildTypeEx bt10 = project10.createBuildType("bt10", "bt 10");
    bt10.addRequirement(myFixture.findSingletonService(RequirementFactory.class).createRequirement("a", null, RequirementType.EXISTS));
    BuildTypeEx bt20 = project10.createBuildType("bt20", "bt 20");
    // not compatible
    MockBuildAgent agent10 = myFixture.createEnabledAgent("agent10", "Ant");
    // compatible
    MockBuildAgent agent20 = myFixture.createEnabledAgent("agent20", "Ant");
    agent20.addConfigParameter("a", "b");
    agent20.pushAgentTypeData();
    // compatible
    MockBuildAgent agent30 = myFixture.createEnabledAgent("agent30", "Ant");
    agent30.addConfigParameter("a", "b");
    agent30.pushAgentTypeData();
    agent30.setAuthorized(false, null, "");
    {
        BuildType buildType = new BuildType(new BuildTypeOrTemplate(bt10), Fields.LONG, myBeanContext);
        assertNotNull(buildType.getCompatibleAgents());
        assertNull(buildType.getCompatibleAgents().count);
        assertNotNull(buildType.getCompatibleAgents().href);
        assertContains(buildType.getCompatibleAgents().href, "compatible:(buildType:(id:" + bt10.getExternalId() + "))");
        assertNull(buildType.getCompatibleAgents().agents);
    }
    {
        BuildType buildType = new BuildType(new BuildTypeOrTemplate(bt10), new Fields("compatibleAgents($long)"), myBeanContext);
        assertNotNull(buildType.getCompatibleAgents());
        assertEquals(Integer.valueOf(1), buildType.getCompatibleAgents().count);
        assertContains(buildType.getCompatibleAgents().href, "compatible:(buildType:(id:" + bt10.getExternalId() + "))");
        assertNotNull(buildType.getCompatibleAgents().agents);
        assertEquals(1, buildType.getCompatibleAgents().agents.size());
    }
    {
        BuildType buildType = new BuildType(new BuildTypeOrTemplate(bt10), new Fields("compatibleAgents($long,$locator(authorized:any))"), myBeanContext);
        assertNotNull(buildType.getCompatibleAgents());
        assertEquals(Integer.valueOf(2), buildType.getCompatibleAgents().count);
        // assertContains(buildType.getCompatibleAgents().href, "compatible:(buildType:(id:" + bt10.getExternalId() + ")),authorized:any");
        assertNotNull(buildType.getCompatibleAgents().agents);
        assertEquals(2, buildType.getCompatibleAgents().agents.size());
    }
}
Also used : ProjectEx(jetbrains.buildServer.serverSide.impl.ProjectEx) BuildTypeOrTemplate(jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate) BuildType(jetbrains.buildServer.server.rest.model.buildType.BuildType) MockBuildAgent(jetbrains.buildServer.serverSide.impl.MockBuildAgent) Test(org.testng.annotations.Test) ProjectRequestTest(jetbrains.buildServer.server.rest.request.ProjectRequestTest) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest)

Example 4 with MockBuildAgent

use of jetbrains.buildServer.serverSide.impl.MockBuildAgent in project teamcity-rest by JetBrains.

the class AgentTest method testEnabledComment.

@Test
public void testEnabledComment() throws ParseException {
    final MockBuildAgent agent1 = myFixture.createEnabledAgent("agent1", "runType");
    agent1.setEnabled(false, null, "test");
    assertFalse(agent1.isEnabled());
    Agent.setFieldValue(agent1, "enabled", "true", myFixture);
    assertTrue(agent1.isEnabled());
    AgentRequest resource = AgentRequest.createForTests(getBeanContext(myFixture));
    {
        AgentEnabledInfo enabledInfo = resource.getEnabledInfo("id:" + agent1.getId(), "$long");
        assertEquals(Boolean.TRUE, enabledInfo.status);
        assertEquals(null, enabledInfo.comment.text);
        assertEquals(null, enabledInfo.statusSwitchTime);
    }
    AgentEnabledInfo newEnabledInfo = new AgentEnabledInfo();
    newEnabledInfo.status = Boolean.FALSE;
    newEnabledInfo.comment = new Comment();
    newEnabledInfo.comment.text = "custom comment";
    newEnabledInfo.statusSwitchTime = "+10m";
    resource.setEnabledInfo("id:" + agent1.getId(), newEnabledInfo, "$long");
    {
        AgentEnabledInfo enabledInfo = resource.getEnabledInfo("id:" + agent1.getId(), "$long");
        assertEquals(Boolean.FALSE, enabledInfo.status);
        assertEquals("custom comment", enabledInfo.comment.text);
        assertTrue(new SimpleDateFormat("yyyyMMdd'T'HHmmssZ").parse(enabledInfo.statusSwitchTime).getTime() - new Date().getTime() - 10 * 60 * 60 * 1000 < 1000);
    }
}
Also used : AgentEnabledInfo(jetbrains.buildServer.server.rest.model.agent.AgentEnabledInfo) AgentRequest(jetbrains.buildServer.server.rest.request.AgentRequest) MockBuildAgent(jetbrains.buildServer.serverSide.impl.MockBuildAgent) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest) Test(org.testng.annotations.Test)

Example 5 with MockBuildAgent

use of jetbrains.buildServer.serverSide.impl.MockBuildAgent in project teamcity-rest by JetBrains.

the class AbstractAgentPoolResolverTest method basicAgentsConnection.

public void basicAgentsConnection() throws AgentPoolCannotBeRenamedException, NoSuchAgentPoolException, AgentTypeCannotBeMovedException, PoolQuotaExceededException {
    AgentPoolManager manager = myFixture.getAgentPoolManager();
    jetbrains.buildServer.serverSide.agentPools.AgentPool evenAgents = manager.createNewAgentPool("evenAgents");
    jetbrains.buildServer.serverSide.agentPools.AgentPool oddAgents = manager.createNewAgentPool("oddAgents");
    final int num = 2;
    for (int i = 0; i < num * 2; i++) {
        MockBuildAgent agent = myFixture.createEnabledAgent("agent_" + i);
        registerAndEnableAgent(agent);
        manager.moveAgentToPool((i % 2 == 0) ? evenAgents.getAgentPoolId() : oddAgents.getAgentPoolId(), agent);
    }
    AgentPoolAgentsConnection evenConnection = myResolver.agents(new AgentPool(evenAgents), myDataFetchingEnvironment);
    assertEquals(num, evenConnection.getCount());
    for (AgentPoolAgentsConnection.AgentPoolAgentsConnectionEdge edge : evenConnection.getEdges().getData()) {
        assertEquals(evenAgents.getAgentPoolId(), edge.getNode().getData().getRealAgent().getAgentPoolId());
    }
    AgentPoolAgentsConnection oddConnection = myResolver.agents(new AgentPool(oddAgents), myDataFetchingEnvironment);
    assertEquals(num, oddConnection.getCount());
    for (AgentPoolAgentsConnection.AgentPoolAgentsConnectionEdge edge : oddConnection.getEdges().getData()) {
        assertEquals(oddAgents.getAgentPoolId(), edge.getNode().getData().getRealAgent().getAgentPoolId());
    }
}
Also used : AgentPoolAgentsConnection(jetbrains.buildServer.server.graphql.model.connections.agentPool.AgentPoolAgentsConnection) MockBuildAgent(jetbrains.buildServer.serverSide.impl.MockBuildAgent) jetbrains.buildServer.serverSide.agentPools(jetbrains.buildServer.serverSide.agentPools) AgentPool(jetbrains.buildServer.server.graphql.model.agentPool.AgentPool)

Aggregations

MockBuildAgent (jetbrains.buildServer.serverSide.impl.MockBuildAgent)8 Test (org.testng.annotations.Test)7 ProjectEx (jetbrains.buildServer.serverSide.impl.ProjectEx)4 BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)2 SkipException (org.testng.SkipException)2 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 AgentPool (jetbrains.buildServer.server.graphql.model.agentPool.AgentPool)1 AgentPoolAgentsConnection (jetbrains.buildServer.server.graphql.model.connections.agentPool.AgentPoolAgentsConnection)1 AgentEnabledInfo (jetbrains.buildServer.server.rest.model.agent.AgentEnabledInfo)1 BuildType (jetbrains.buildServer.server.rest.model.buildType.BuildType)1 AgentRequest (jetbrains.buildServer.server.rest.request.AgentRequest)1 ProjectRequestTest (jetbrains.buildServer.server.rest.request.ProjectRequestTest)1 BuildTypeOrTemplate (jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate)1 jetbrains.buildServer.serverSide.agentPools (jetbrains.buildServer.serverSide.agentPools)1