import jetbrains.buildServer.BaseTestCase;
import jetbrains.buildServer.util.FileUtil;
import jetbrains.buildServer.vsoRooms.rest.TeamRoom;
import jetbrains.buildServer.vsoRooms.rest.TeamRoomMessage;
import jetbrains.buildServer.vsoRooms.rest.VSOTeamRoomsAPI;
import jetbrains.buildServer.vsoRooms.rest.VSOTeamRoomsAPIConnection;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import java.io.File;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

public class VSOAPIIntegrationTest extends BaseTestCase {

  private static final String TESTS_CREDENTIALS_TXT = "tests-credentials.txt";

  private VSOTeamRoomsAPIConnection myAPIConnection;
  private String myAccount;

  @Override
  @BeforeMethod
  public void setUp() throws Exception {
    super.setUp();

    String username;
    String password;

    final Map<String, String> localCredentials = new HashMap<String, String>();

    final File localCredentialsStorage = new File(TESTS_CREDENTIALS_TXT);
    if(localCredentialsStorage.isFile()){
      for(String line : FileUtil.readFile(localCredentialsStorage)){
        final int separatorLocation = line.indexOf(" ");
        if(separatorLocation == -1) continue;
        localCredentials.put(line.substring(0, separatorLocation).trim(), line.substring(separatorLocation).trim());
      }
    }

    myAccount = localCredentials.containsKey("TEST_VSO_ACCOUNT") ? localCredentials.get("TEST_VSO_ACCOUNT") : System.getenv("TC_TEST_VSO_ACCOUNT");
    assertNotNull(myAccount);

    username = localCredentials.containsKey("TEST_VSO_USERNAME") ? localCredentials.get("TEST_VSO_USERNAME") : System.getenv("TC_TEST_VSO_USERNAME");
    assertNotNull(username);

    password = localCredentials.containsKey("TEST_VSO_PASSWORD") ? localCredentials.get("TEST_VSO_PASSWORD") : System.getenv("TC_TEST_VSO_PASSWORD");
    assertNotNull(password);

    myAPIConnection = VSOTeamRoomsAPI.createConnection(username, password);
  }

  @Test
  public void testSendMessage() {
    final TeamRoomMessage message = myAPIConnection.sendMessageToRoom(myAccount, 16343L, "hello!");
    assertNotNull(message);
    assertEquals("hello!", message.getContent());
  }

  @Test
  public void testGetListOfRooms() {
    final Collection<TeamRoom> rooms = myAPIConnection.getListOfRooms(myAccount);
    assertNotEmpty(rooms);
    for (TeamRoom room : rooms){
      log(room.getName() + " " + room.getId());
    }
  }
}

@@ -2446,11 +2446,209 @@
    %7D%0A  %7D
+%0A%0A  @Test%0A  public void testGetListOfRoomsOnBehalfOfUnknownUser() throws Exception %7B%0A    assertEmpty(VSOTeamRoomsAPI.createConnection(%22unknown_user%22, %22some_password%22).getListOfRooms(myAccount));%0A  %7D
 %0A%7D%0A

test added