Search in sources :

Example 1 with AgentEnabledInfo

use of jetbrains.buildServer.server.rest.model.agent.AgentEnabledInfo 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)

Aggregations

SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)1 AgentEnabledInfo (jetbrains.buildServer.server.rest.model.agent.AgentEnabledInfo)1 AgentRequest (jetbrains.buildServer.server.rest.request.AgentRequest)1 MockBuildAgent (jetbrains.buildServer.serverSide.impl.MockBuildAgent)1 Test (org.testng.annotations.Test)1