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());
}
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);
}
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());
}
}
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);
}
}
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());
}
}
Aggregations