Ejemplo n.º 1
0
  @SuppressWarnings("unchecked")
  public List<Group> getAllGroups() throws Exception {
    // {"vfwebqq":"3e99140e076c4dc3c8a774f1e3a37518055f3f39f94428a8eaa07c1f7c0ebfea3a18792878f2c061"}

    String url = "http://s.web2.qq.com/api/get_group_name_list_mask2";
    String content = "{\"vfwebqq\":\"" + vfwebqq + "\"}";
    PostMethodWebRequest post = new PostMethodWebRequest(url);
    post.setParameter("r", content);

    wc.setHeaderField("Referer", "http://s.web2.qq.com/proxy.html?v=20110412001&callback=1&id=2");

    WebResponse rs = wc.getResponse(post);
    log.info("sendMsg response:" + rs.getText());

    List<Group> groups = new ArrayList<Group>();

    JSONObject retJson = new JSONObject(rs.getText());
    if (retJson.getInt("retcode") == 0) {
      JSONArray infos = retJson.getJSONObject("result").getJSONArray("gnamelist");
      for (int i = 0; i < infos.length(); i++) {
        JSONObject obj = infos.getJSONObject(i);
        Group group = new Group();
        group.setGid(obj.getString("gid"));
        group.setName(obj.getString("name"));
        group.setCode(obj.getString("code"));
        groups.add(group);
      }
    }
    return groups;
  }
Ejemplo n.º 2
0
  private void assertDiffUris(
      String expectedLocation, String[] expectedContent, JSONObject jsonPart)
      throws JSONException, IOException, SAXException {
    JSONObject gitSection = jsonPart.getJSONObject(GitConstants.KEY_GIT);
    assertNotNull(gitSection);

    String fileOldUri = gitSection.getString(GitConstants.KEY_COMMIT_OLD);
    assertNotNull(fileOldUri);
    WebRequest request = getGetFilesRequest(fileOldUri);
    WebResponse response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    assertEquals(expectedContent[0], response.getText());

    String fileNewUri = gitSection.getString(GitConstants.KEY_COMMIT_NEW);
    assertNotNull(fileNewUri);
    request = getGetFilesRequest(fileNewUri);
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    assertEquals(expectedContent[1], response.getText());

    String fileBaseUri = gitSection.getString(GitConstants.KEY_COMMIT_BASE);
    assertNotNull(fileBaseUri);
    request = getGetFilesRequest(fileBaseUri);
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    assertEquals(expectedContent[2], response.getText());

    String diffUri = gitSection.getString(GitConstants.KEY_DIFF);
    assertNotNull(diffUri);
    assertEquals(expectedLocation, diffUri);
  }
Ejemplo n.º 3
0
  @Test
  public void testCreateDirectory() throws CoreException, IOException, SAXException, JSONException {
    String directoryPath = "sample/directory/path" + System.currentTimeMillis();
    createDirectory(directoryPath);

    String dirName = "testdir";
    webConversation.setExceptionsThrownOnErrorStatus(false);

    WebRequest request =
        getPostFilesRequest(directoryPath, getNewDirJSON(dirName).toString(), dirName);
    WebResponse response = webConversation.getResponse(request);

    assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode());
    assertTrue(
        "Create directory response was OK, but the directory does not exist",
        checkDirectoryExists(directoryPath + "/" + dirName));
    assertEquals(
        "Response should contain directory metadata in JSON, but was " + response.getText(),
        "application/json",
        response.getContentType());
    JSONObject responseObject = new JSONObject(response.getText());
    assertNotNull("No directory information in response", responseObject);
    checkDirectoryMetadata(responseObject, dirName, null, null, null, null, null);

    // should be able to perform GET on location header to obtain metadata
    String location = response.getHeaderField(ProtocolConstants.HEADER_LOCATION);
    request = getGetFilesRequest(location);
    response = webConversation.getResource(request);
    assertNotNull(location);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    responseObject = new JSONObject(response.getText());
    assertNotNull("No direcory information in responce", responseObject);
    checkDirectoryMetadata(responseObject, dirName, null, null, null, null, null);
  }
Ejemplo n.º 4
0
  /*
   * @author Jay Patel
   * HCP 9000000000 has viewed PHR of patient 2 on 11/11/2007.
   * Authenticate Patient
   * MID: 2
   * Password: pw
   * Choose option View Access Log
   * Choose date range 11/12/2015 through 11/11/2015
   * Invalid format in use yyyy/mm/dd
   */
  public void testViewAccessLogDateOrder() throws Exception {
    // clear operational profile
    gen.transactionLog();
    // login patient 2
    WebConversation wc = login("2", "pw");
    WebResponse wr = wc.getCurrentPage();
    assertEquals("iTrust - Patient Home", wr.getTitle());
    assertLogged(TransactionType.HOME_VIEW, 2L, 0L, "");

    // click on View Access Log
    wr = wr.getLinkWith("Access Log").click();
    // select the date range and submit
    WebForm form = wr.getForms()[0];
    form.setParameter("startDate", "11/12/2015");
    form.setParameter("endDate", "11/11/2015");
    form.getSubmitButtons()[0].click();
    WebResponse add = wc.getCurrentPage();

    // Since we are using a invalid format for dates putting
    // the format yyyy/mm/dd should return an "Information not valid"
    // response on the page

    assertFalse(add.getText().contains("Exception"));
    assertTrue(add.getText().contains("Information not valid"));
  }
Ejemplo n.º 5
0
  @Test
  public void testCreateTopLevelFile()
      throws CoreException, IOException, SAXException, JSONException {
    String directoryPath = "sample" + System.currentTimeMillis();
    createDirectory(directoryPath);
    String fileName = "testfile.txt";

    WebRequest request =
        getPostFilesRequest(directoryPath, getNewFileJSON(fileName).toString(), fileName);
    WebResponse response = webConversation.getResponse(request);

    assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode());
    assertTrue(
        "Create file response was OK, but the file does not exist",
        checkFileExists(directoryPath + "/" + fileName));
    assertEquals(
        "Response should contain file metadata in JSON, but was " + response.getText(),
        "application/json",
        response.getContentType());
    JSONObject responseObject = new JSONObject(response.getText());
    assertNotNull("No file information in responce", responseObject);
    checkFileMetadata(responseObject, fileName, null, null, null, null, null, null, null);

    // should be able to perform GET on location header to obtain metadata
    String location = response.getHeaderField("Location");
    request = getGetFilesRequest(location + "?parts=meta");
    response = webConversation.getResource(request);
    assertNotNull(location);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    responseObject = new JSONObject(response.getText());
    assertNotNull("No direcory information in responce", responseObject);
    checkFileMetadata(responseObject, fileName, null, null, null, null, null, null, null);
  }
Ejemplo n.º 6
0
  public void testRemoveAppt() throws Exception {
    // login hcp
    gen.uc22();
    WebConversation wc = login("9000000000", "pw");
    WebResponse wr = wc.getCurrentPage();
    assertEquals("iTrust - HCP Home", wr.getTitle());
    assertLogged(TransactionType.HOME_VIEW, 9000000000L, 0L, "");

    wr = wr.getLinkWith("View My Appointments").click();
    assertLogged(TransactionType.APPOINTMENT_ALL_VIEW, 9000000000L, 0L, "");

    WebTable table = wr.getTables()[0];
    int row = 0;
    for (int i = 0; i < table.getRowCount(); i++) {
      if (table.getCellAsText(i, 0).equals("Anakin Skywalker")) {
        row = i;
        break;
      }
    }

    wr = table.getTableCell(row, 5).getLinkWith("Edit/Remove").click();
    assertTrue(wr.getText().contains("Anakin Skywalker"));
    WebForm wf = wr.getFormWithID("mainForm");

    wf.getSubmitButtonWithID("removeButton").click();
    wr = wc.getCurrentPage();

    assertTrue(wr.getText().contains("Success: Appointment removed"));
    assertLogged(TransactionType.APPOINTMENT_REMOVE, 9000000000L, 100L, "");
  }
Ejemplo n.º 7
0
  /**
   * Check sorted column.
   *
   * @param jspName jsp name, with full path
   * @throws Exception any axception thrown during test.
   */
  @Test
  public void doTest() throws Exception {
    WebRequest request = new GetMethodWebRequest(getJspUrl(getJspName()));

    ParamEncoder encoder = new ParamEncoder("table");
    request.setParameter(encoder.encodeParameterName(TableTagParameters.PARAMETER_SORT), "1");
    request.setParameter(
        encoder.encodeParameterName(TableTagParameters.PARAMETER_SORTUSINGNAME), "1");

    WebResponse response = runner.getResponse(request);

    if (log.isDebugEnabled()) {
      log.debug(response.getText());
    }

    WebTable[] tables = response.getTables();
    Assert.assertEquals("Wrong number of tables in result.", 1, tables.length);
    Assert.assertEquals("Wrong number of rows in result.", 3, tables[0].getRowCount());

    if (log.isDebugEnabled()) {
      log.debug(response.getText());
    }

    Assert.assertEquals(
        "Wrong value in first row. Table incorrectly sorted?", "2", tables[0].getCellAsText(1, 1));
    Assert.assertEquals(
        "Column 1 should not be marked as sorted.",
        "sortable",
        tables[0].getTableCell(0, 1).getClassName());
    Assert.assertEquals(
        "Column 2 should be marked as sorted.",
        "sortable sorted order1",
        tables[0].getTableCell(0, 2).getClassName());
  }
Ejemplo n.º 8
0
  @Test
  public void testGetSingleConfigEntry() throws Exception {
    URI workspaceLocation = createWorkspace(getMethodName());
    IPath[] clonePaths = createTestProjects(workspaceLocation);

    for (IPath clonePath : clonePaths) {
      // clone a  repo
      String contentLocation = clone(clonePath).getString(ProtocolConstants.KEY_CONTENT_LOCATION);

      // get project metadata
      WebRequest request = getGetRequest(contentLocation);
      WebResponse response = webConversation.getResponse(request);
      assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
      JSONObject project = new JSONObject(response.getText());
      JSONObject gitSection = project.getJSONObject(GitConstants.KEY_GIT);
      String gitConfigUri = gitSection.getString(GitConstants.KEY_CONFIG);

      // set some dummy value
      final String ENTRY_KEY = "a.b.c";
      final String ENTRY_VALUE = "v";

      request = getPostGitConfigRequest(gitConfigUri, ENTRY_KEY, ENTRY_VALUE);
      response = webConversation.getResponse(request);
      assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode());
      JSONObject configResponse = new JSONObject(response.getText());
      String entryLocation = configResponse.getString(ProtocolConstants.KEY_LOCATION);

      JSONObject configEntry = listConfigEntries(entryLocation);
      assertConfigOption(configEntry, ENTRY_KEY, ENTRY_VALUE);
    }
  }
Ejemplo n.º 9
0
  public void testSetPassedDate() throws Exception {
    // login hcp
    gen.uc22();
    WebConversation wc = login("9000000000", "pw");
    WebResponse wr = wc.getCurrentPage();
    assertEquals("iTrust - HCP Home", wr.getTitle());
    assertLogged(TransactionType.HOME_VIEW, 9000000000L, 0L, "");
    wr = wr.getLinkWith("View My Appointments").click();
    assertLogged(TransactionType.APPOINTMENT_ALL_VIEW, 9000000000L, 0L, "");

    WebTable table = wr.getTables()[0];
    int row = 0;
    for (int i = 0; i < table.getRowCount(); i++) {
      if (table.getCellAsText(i, 0).equals("Anakin Skywalker")) {
        row = i;
        break;
      }
    }

    wr = table.getTableCell(row, 5).getLinkWith("Edit/Remove").click();
    assertTrue(wr.getText().contains("Anakin Skywalker"));
    WebForm wf = wr.getFormWithID("mainForm");
    wf.setParameter("schedDate", "10/10/2009");

    wf.getSubmitButtonWithID("changeButton").click();
    wr = wc.getCurrentPage();

    assertTrue(wr.getText().contains("The scheduled date of this appointment"));
    assertTrue(wr.getText().contains("has already passed."));
    assertNotLogged(TransactionType.APPOINTMENT_EDIT, 9000000000L, 100L, "");
  }
Ejemplo n.º 10
0
  @Test
  public void testCloneAndLinkToFolder() throws Exception {
    URI workspaceLocation = createWorkspace(getMethodName());
    JSONObject project = createProjectOrLink(workspaceLocation, getMethodName(), null);
    IPath clonePath =
        new Path("file").append(project.getString(ProtocolConstants.KEY_ID)).makeAbsolute();
    String contentLocation = clone(clonePath).getString(ProtocolConstants.KEY_CONTENT_LOCATION);

    File folder =
        new File(
            getRepositoryForContentLocation(contentLocation).getDirectory().getParentFile(),
            "folder");

    JSONObject newProject =
        createProjectOrLink(
            workspaceLocation, getMethodName() + "-link", folder.toURI().toString());
    String projectContentLocation = newProject.getString(ProtocolConstants.KEY_CONTENT_LOCATION);

    // http://<host>/file/<projectId>/
    WebRequest request = getGetFilesRequest(projectContentLocation);
    WebResponse response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    JSONObject link = new JSONObject(response.getText());
    String childrenLocation = link.getString(ProtocolConstants.KEY_CHILDREN_LOCATION);
    assertNotNull(childrenLocation);

    // http://<host>/file/<projectId>/?depth=1
    request = getGetFilesRequest(childrenLocation);
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    List<JSONObject> children = getDirectoryChildren(new JSONObject(response.getText()));
    String[] expectedChildren = new String[] {"folder.txt"};
    assertEquals("Wrong number of directory children", expectedChildren.length, children.size());
    assertEquals(expectedChildren[0], children.get(0).getString(ProtocolConstants.KEY_NAME));
  }
Ejemplo n.º 11
0
  public void testSubmitAndEditConsultation() throws Exception {

    WebConversation wc = login("9000000000", "pw");
    WebResponse wr = wc.getCurrentPage();
    assertEquals("iTrust - HCP Home", wr.getTitle());

    wr = wr.getLinkWith("Consultations").click();
    assertTrue(wr.getText().contains("HCP Consultations"));

    wr.getForms()[0].getButtons()[0].click();

    wr = wc.getCurrentPage();

    assertTrue(wr.getText().contains("Send a Consultation"));

    wr.getForms()[0].setParameter("patient", "5");
    wr.getForms()[0].setParameter("hcp", "9000000003");
    wr = wr.getForms()[0].submit();

    assertTrue(wr.getText().contains("Consultation Form"));

    wr.getForms()[0].setParameter("msg", "Test1");
    wr = wr.getForms()[0].submit();

    assertTrue(wr.getText().contains("Thank you, your Consultation Request was sent."));

    assertTrue(wr.getText().contains("Test1"));

    wr = wr.getLinkWith("Consultations").click();
    assertTrue(wr.getText().contains("HCP Consultations"));

    wr.getForms()[0].getButtons()[1].click();

    wr = wc.getCurrentPage();

    assertTrue(wr.getText().contains("View Pending Consultations"));

    assertTrue(wr.getText().contains("Baby Programmer (5)"));

    wr = wr.getLinkWith("edit").click();

    WebTable wt = wr.getTableStartingWith("Patient:");

    assertEquals("Baby Programmer", wt.getCellAsText(0, 1));
    assertEquals("Kelly Doctor", wt.getCellAsText(1, 1));
    assertEquals("Gandalf Stormcrow", wt.getCellAsText(2, 1));

    wr.getForms()[0].setParameter("refDetails", "Test2");
    wr = wr.getForms()[0].submit();

    assertTrue(wr.getText().contains("Consultation updated"));

    wr = wr.getLinkWith("Consultations").click();
    wr.getForms()[0].getButtons()[1].click();
    wr = wc.getCurrentPage();
    wr = wr.getLinkWith("edit").click();

    assertTrue(wr.getText().contains("Test2"));
  }
  @Test
  public void testRoom() throws Exception {
    // create room
    WebRequest request =
        new PostMethodWebRequest(
            getCreateUrl(),
            new ByteArrayInputStream(objectMapper.writeValueAsString(baseRoom).getBytes()),
            MediaType.APPLICATION_JSON_VALUE);
    WebResponse response = conversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode());
    assertEquals(MediaType.APPLICATION_JSON_VALUE, response.getContentType());
    Room room = objectMapper.readValue(response.getText(), Room.class);
    assertNotNull(room);
    assertTrue(room.getId() != 0);
    assertTrue(compare(baseRoom, room, "id"));

    // update room
    baseRoom = room;
    baseRoom.setName("New name");
    request =
        new PutMethodWebRequest(
            getUpdateUrl(),
            new ByteArrayInputStream(objectMapper.writeValueAsString(baseRoom).getBytes()),
            MediaType.APPLICATION_JSON_VALUE);
    response = conversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    assertEquals(MediaType.APPLICATION_JSON_VALUE, response.getContentType());
    room = objectMapper.readValue(response.getText(), Room.class);
    assertNotNull(room);
    assertEquals(room, baseRoom);

    // get room
    request = new GetMethodWebRequest(getViewUrl(baseRoom.getId()));
    response = conversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    assertEquals(MediaType.APPLICATION_JSON_VALUE, response.getContentType());
    room = objectMapper.readValue(response.getText(), Room.class);
    assertNotNull(room);
    assertEquals(room, baseRoom);

    // remove room
    request =
        new WebRequest(getDeleteUrl(baseRoom.getId())) {

          @Override
          public String getMethod() {
            return RequestMethod.DELETE.toString();
          }
        };
    response = conversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

    // check removed
    URL url = new URL(getViewUrl(baseRoom.getId()));
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.connect();
    assertEquals(HttpURLConnection.HTTP_NO_CONTENT, connection.getResponseCode());
  }
Ejemplo n.º 13
0
  @Test
  public void testMergeIntoLocalFailedDirtyWorkTree() throws Exception {
    // clone a repo
    createWorkspace(SimpleMetaStore.DEFAULT_WORKSPACE_NAME);
    String workspaceId = workspaceIdFromLocation(workspaceLocation);
    JSONObject project =
        createProjectOrLink(workspaceLocation, getMethodName().concat("Project"), null);
    IPath clonePath = getClonePath(workspaceId, project);
    clone(clonePath);

    // get project metadata
    WebRequest request = getGetRequest(project.getString(ProtocolConstants.KEY_CONTENT_LOCATION));
    WebResponse response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    project = new JSONObject(response.getText());
    JSONObject gitSection = project.getJSONObject(GitConstants.KEY_GIT);
    String gitHeadUri = gitSection.getString(GitConstants.KEY_HEAD);
    String gitRemoteUri = gitSection.getString(GitConstants.KEY_REMOTE);

    // add a parallel commit in secondary clone and push it to the remote
    JSONObject project2 =
        createProjectOrLink(workspaceLocation, getMethodName().concat("Project2"), null);
    IPath clonePath2 = getClonePath(workspaceId, project2);
    clone(clonePath2);

    // get project2 metadata
    request = getGetRequest(project2.getString(ProtocolConstants.KEY_CONTENT_LOCATION));
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    project2 = new JSONObject(response.getText());
    JSONObject gitSection2 = project2.getJSONObject(GitConstants.KEY_GIT);
    String gitRemoteUri2 = gitSection2.getString(GitConstants.KEY_REMOTE);

    JSONObject testTxt = getChild(project2, "test.txt");
    modifyFile(testTxt, "change in secondary");
    addFile(testTxt);
    commitFile(testTxt, "commit on branch", false);

    ServerStatus pushStatus = push(gitRemoteUri2, 1, 0, Constants.MASTER, Constants.HEAD, false);
    assertEquals(true, pushStatus.isOK());

    // modify on master and try to merge
    testTxt = getChild(project, "test.txt");
    modifyFile(testTxt, "dirty");

    JSONObject masterDetails = getRemoteBranch(gitRemoteUri, 1, 0, Constants.MASTER);
    String masterLocation = masterDetails.getString(ProtocolConstants.KEY_LOCATION);
    fetch(masterLocation);
    JSONObject merge = merge(gitHeadUri, Constants.DEFAULT_REMOTE_NAME + "/" + Constants.MASTER);

    MergeStatus mergeResult = MergeStatus.valueOf(merge.getString(GitConstants.KEY_RESULT));
    assertEquals(MergeStatus.FAILED, mergeResult);
    JSONObject failingPaths = merge.getJSONObject(GitConstants.KEY_FAILING_PATHS);
    assertEquals(1, failingPaths.length());
    assertEquals(
        MergeFailureReason.DIRTY_WORKTREE,
        MergeFailureReason.valueOf(failingPaths.getString("test.txt")));
  }
Ejemplo n.º 14
0
 public String getUserFriends(String url) throws Exception {
   // String url = "http://s.web2.qq.com/api/get_user_friends2";
   PostMethodWebRequest post = new PostMethodWebRequest(url);
   String r = "{\"h\":\"hello\",\"vfwebqq\":\"" + this.vfwebqq + "\"}";
   post.setParameter("r", r);
   WebResponse rs = wc.getResponse(post);
   log.info("getUserFriends2 response:" + rs.getText());
   return rs.getText();
 }
Ejemplo n.º 15
0
  @Test
  public void testAddConfigEntry() throws Exception {
    URI workspaceLocation = createWorkspace(getMethodName());
    IPath[] clonePaths = createTestProjects(workspaceLocation);

    for (IPath clonePath : clonePaths) {
      // clone a  repo
      String contentLocation = clone(clonePath).getString(ProtocolConstants.KEY_CONTENT_LOCATION);

      // get project metadata
      WebRequest request = getGetRequest(contentLocation);
      WebResponse response = webConversation.getResponse(request);
      assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
      JSONObject project = new JSONObject(response.getText());
      JSONObject gitSection = project.getJSONObject(GitConstants.KEY_GIT);
      String gitConfigUri = gitSection.getString(GitConstants.KEY_CONFIG);

      JSONObject configResponse = listConfigEntries(gitConfigUri);
      JSONArray configEntries = configResponse.getJSONArray(ProtocolConstants.KEY_CHILDREN);
      // initial number of config entries
      int initialConfigEntriesCount = configEntries.length();

      // set some dummy value
      final String ENTRY_KEY = "a.b.c";
      final String ENTRY_VALUE = "v";

      request = getPostGitConfigRequest(gitConfigUri, ENTRY_KEY, ENTRY_VALUE);
      response = webConversation.getResponse(request);
      assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode());
      configResponse = new JSONObject(response.getText());
      String entryLocation = configResponse.getString(ProtocolConstants.KEY_LOCATION);
      assertConfigUri(entryLocation);

      // get list of config entries again
      configResponse = listConfigEntries(gitConfigUri);
      configEntries = configResponse.getJSONArray(ProtocolConstants.KEY_CHILDREN);
      assertEquals(initialConfigEntriesCount + 1, configEntries.length());

      entryLocation = null;
      for (int i = 0; i < configEntries.length(); i++) {
        JSONObject configEntry = configEntries.getJSONObject(i);
        if (ENTRY_KEY.equals(configEntry.getString(GitConstants.KEY_CONFIG_ENTRY_KEY))) {
          assertConfigOption(configEntry, ENTRY_KEY, ENTRY_VALUE);
          break;
        }
      }

      // double check
      org.eclipse.jgit.lib.Config config =
          getRepositoryForContentLocation(contentLocation).getConfig();
      assertEquals(ENTRY_VALUE, config.getString("a", "b", "c"));
    }
  }
Ejemplo n.º 16
0
  @Test
  public void testRequestWithMissingArguments() throws Exception {
    URI workspaceLocation = createWorkspace(getMethodName());
    IPath[] clonePaths = createTestProjects(workspaceLocation);

    for (IPath clonePath : clonePaths) {
      // clone a  repo
      String contentLocation = clone(clonePath).getString(ProtocolConstants.KEY_CONTENT_LOCATION);

      // get project metadata
      WebRequest request = getGetRequest(contentLocation);
      WebResponse response = webConversation.getResponse(request);
      assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
      JSONObject project = new JSONObject(response.getText());
      JSONObject gitSection = project.getJSONObject(GitConstants.KEY_GIT);
      String gitConfigUri = gitSection.getString(GitConstants.KEY_CONFIG);

      final String ENTRY_KEY = "a.b.c";
      final String ENTRY_VALUE = "v";

      // missing key
      request = getPostGitConfigRequest(gitConfigUri, null, ENTRY_VALUE);
      response = webConversation.getResponse(request);
      assertEquals(HttpURLConnection.HTTP_BAD_REQUEST, response.getResponseCode());

      // missing value
      request = getPostGitConfigRequest(gitConfigUri, ENTRY_KEY, null);
      response = webConversation.getResponse(request);
      assertEquals(HttpURLConnection.HTTP_BAD_REQUEST, response.getResponseCode());

      // missing key and value
      request = getPostGitConfigRequest(gitConfigUri, null, null);
      response = webConversation.getResponse(request);
      assertEquals(HttpURLConnection.HTTP_BAD_REQUEST, response.getResponseCode());

      // add some config
      request = getPostGitConfigRequest(gitConfigUri, ENTRY_KEY, ENTRY_VALUE);
      response = webConversation.getResponse(request);
      assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode());
      JSONObject configResponse = new JSONObject(response.getText());
      String entryLocation = configResponse.getString(ProtocolConstants.KEY_LOCATION);

      // put without value
      request = getPutGitConfigRequest(entryLocation, null);
      response = webConversation.getResponse(request);
      assertEquals(HttpURLConnection.HTTP_BAD_REQUEST, response.getResponseCode());
    }
  }
Ejemplo n.º 17
0
  /**
   * Verifies that the access log correctly handle bad date inputs
   *
   * @throws Exception
   */
  public void testViewAccessLogBadDateHandling() throws Exception {
    gen.clearAllTables();
    gen.standardData();

    WebConversation wc = login("23", "pw");
    WebResponse wr = wc.getCurrentPage();
    assertEquals("iTrust - Patient Home", wr.getTitle());

    wr = wr.getLinkWith("Access Log").click();
    assertEquals("iTrust - View My Access Log", wr.getTitle());

    WebForm dateForm = wr.getForms()[0];
    dateForm.setParameter("startDate", "6/22/2007");
    dateForm.setParameter("endDate", "6/21/2007");
    dateForm.submit();

    wr = wc.getCurrentPage();
    assertEquals("iTrust - View My Access Log", wr.getTitle());
    assertTrue(
        wr.getText()
            .contains(
                "<h2>Information not valid</h2><div class=\"errorList\">Start date must be before end date!<br /></div>"));

    dateForm = wr.getForms()[0];
    dateForm.setParameter("startDate", "June 22nd, 2007");
    dateForm.setParameter("endDate", "6/23/2007");
    dateForm.submit();

    wr = wc.getCurrentPage();
    assertEquals("iTrust - View My Access Log", wr.getTitle());
    assertTrue(
        wr.getText()
            .contains(
                "<h2>Information not valid</h2><div class=\"errorList\">Enter dates in MM/dd/yyyy<br /></div>"));

    // This test is currently commented out because the bug is due to "functionality" in the
    // SimpleDataFormat class which assumes that month 13 === 1
    /*
    dateForm = wr.getForms()[0];
    dateForm.setParameter("startDate", "13/01/2010");
    dateForm.setParameter("endDate", "6/24/2011");
    dateForm.submit();

    wr = wc.getCurrentPage();
    assertEquals("iTrust - View My Access Log", wr.getTitle());
    assertTrue(wr.getText().contains("<h2>Information not valid</h2><div class=\"errorList\">Enter dates in MM/dd/yyyy<br /></div>"));
    */
  }
Ejemplo n.º 18
0
  @Test
  public void testReadDirectoryChildren()
      throws CoreException, IOException, SAXException, JSONException {
    String dirName = "path" + System.currentTimeMillis();
    String directoryPath = "sample/directory/" + dirName;
    createDirectory(directoryPath);

    String subDirectory = "subdirectory";
    createDirectory(directoryPath + "/" + subDirectory);

    String subFile = "subfile.txt";
    createFile(directoryPath + "/" + subFile, "Sample file");

    WebRequest request = getGetFilesRequest(directoryPath + "?depth=1");
    WebResponse response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

    List<JSONObject> children = getDirectoryChildren(new JSONObject(response.getText()));

    assertEquals("Wrong number of directory children", 2, children.size());

    for (JSONObject child : children) {
      if (child.getBoolean("Directory")) {
        checkDirectoryMetadata(child, subDirectory, null, null, null, null, null);
      } else {
        checkFileMetadata(child, subFile, null, null, null, null, null, null, null);
      }
    }
  }
Ejemplo n.º 19
0
  @Test
  public void testCopyFileOverwrite() throws Exception {
    String directoryPath = "/testCopyFile/directory/path" + System.currentTimeMillis();
    String sourcePath = directoryPath + "/source.txt";
    String destName = "destination.txt";
    String destPath = directoryPath + "/" + destName;
    createDirectory(directoryPath);
    createFile(sourcePath, "This is the contents");
    createFile(destPath, "Original file");

    // with no-overwrite, copy should fail
    JSONObject requestObject = new JSONObject();
    addSourceLocation(requestObject, sourcePath);
    WebRequest request =
        getPostFilesRequest(directoryPath, requestObject.toString(), "destination.txt");
    request.setHeaderField("X-Create-Options", "copy,no-overwrite");
    WebResponse response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_PRECON_FAILED, response.getResponseCode());

    // now omit no-overwrite and copy should succeed and return 200 instead of 201
    request = getPostFilesRequest(directoryPath, requestObject.toString(), "destination.txt");
    request.setHeaderField("X-Create-Options", "copy");
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    JSONObject responseObject = new JSONObject(response.getText());
    checkFileMetadata(responseObject, destName, null, null, null, null, null, null, null);
    assertTrue(checkFileExists(sourcePath));
    assertTrue(checkFileExists(destPath));
  }
Ejemplo n.º 20
0
  /**
   * Tests adding a lab procedure with no lab tech selected. Verifies that an error message is
   * displayed.
   *
   * @throws Exception
   */
  public void testAddLabProcedureWithoutLabTech() throws Exception {
    gen.clearAllTables();
    gen.standardData();

    WebConversation wc = login("9000000000", "pw");
    WebResponse wr = wc.getCurrentPage();
    assertEquals("iTrust - HCP Home", wr.getTitle());
    // click Document Office Visit
    wr = wr.getLinkWith("Document Office Visit").click();

    // select the patient
    WebForm form = wr.getForms()[0];
    form.getScriptableObject().setParameterValue("UID_PATIENTID", "2");
    form.getButtons()[1].click();
    wr = wc.getCurrentPage();
    assertEquals(ADDRESS + "auth/hcp-uap/documentOfficeVisit.jsp", wr.getURL().toString());
    // Select the office visit from specific date
    wr.getLinkWith("6/10/2007").click();

    wr = wc.getCurrentPage();
    assertEquals("iTrust - Document Office Visit", wr.getTitle());

    form = wr.getFormWithID("labProcedureForm");
    form.setParameter("loinc", "10666-6");
    form.setParameter("labProcPriority", "1");
    form.getButtonWithID("add_labProcedure").click();

    // check updated page
    wr = wc.getCurrentPage();
    assertTrue(
        wr.getText().contains("A lab tech must be selected before adding a laboratory procedure."));
  }
Ejemplo n.º 21
0
  /**
   * @param jspName jsp name, with full path
   * @throws Exception any axception thrown during test.
   */
  @Test
  public void doTest() throws Exception {

    WebRequest request = new GetMethodWebRequest(getJspUrl(getJspName()));

    WebResponse response = runner.getResponse(request);

    if (log.isDebugEnabled()) {
      log.debug(response.getText());
    }

    WebTable[] tables = response.getTables();
    Assert.assertEquals("Wrong number of tables.", 1, tables.length);

    Assert.assertEquals("Wrong number of columns.", 2, tables[0].getColumnCount());
    Assert.assertEquals("Wrong number of rows.", 3, tables[0].getRowCount()); // 2 plus header

    TableRow[] rows = tables[0].getRows();

    Assert.assertEquals("Wrong id for row 1", "idcamel0", rows[1].getID());
    Assert.assertEquals("Wrong id for row 2", "idcamel1", rows[2].getID());

    Assert.assertEquals("Wrong class for row 1", "odd classcamel0", rows[1].getClassName());
    Assert.assertEquals("Wrong class for row 2", "even classcamel1", rows[2].getClassName());
  }
Ejemplo n.º 22
0
  public void testViewAccessLogByDate() throws Exception {
    gen.transactionLog2();
    WebConversation wc = login("2", "pw");
    WebResponse wr = wc.getCurrentPage();
    assertEquals("iTrust - Patient Home", wr.getTitle());
    assertLogged(TransactionType.HOME_VIEW, 2L, 0L, "");

    wr = wr.getLinkWith("Access Log").click();
    assertFalse(wr.getText().contains("Exception"));

    WebForm form = wr.getForms()[0];
    form.setParameter("startDate", "03/01/2008");
    form.setParameter("endDate", "12/01/2008");
    form.getSubmitButtons()[0].click();

    wr = wr.getLinkWith("Date").click();
    /*
    WebTable table = wr.getTableStartingWithPrefix("Date");
    assertTrue(table.getCellAsText(1, 3).contains("View emergency report"));
    assertTrue(table.getCellAsText(2, 3).contains("Edit Office Visits"));
    assertTrue(table.getCellAsText(3, 3).contains("View prescription report"));
    assertTrue(table.getCellAsText(4, 3).contains("View risk factors"));
    assertLogged(TransactionType.ACCESS_LOG_VIEW, 2L, 0L, "");
    */

  }
Ejemplo n.º 23
0
  static String[] parseMultiPartResponse(WebResponse response) throws IOException {
    String typeHeader = response.getHeaderField(ProtocolConstants.HEADER_CONTENT_TYPE);
    String boundary =
        typeHeader.substring(
            typeHeader.indexOf("boundary=\"") + 10, typeHeader.length() - 1); // $NON-NLS-1$
    BufferedReader reader = new BufferedReader(new StringReader(response.getText()));

    StringBuilder buf = new StringBuilder();
    String line;
    List<String> parts = new ArrayList<String>();
    while ((line = reader.readLine()) != null) {
      if (line.equals("--" + boundary)) {
        line = reader.readLine(); // Content-Type:{...}
        if (buf.length() > 0) {
          parts.add(buf.toString());
          buf.setLength(0);
        }
      } else {
        if (buf.length() > 0) buf.append("\n");
        buf.append(line);
      }
    }
    parts.add(buf.toString());

    assertEquals(2, parts.size());
    // JSON
    assertTrue(parts.get(0).startsWith("{"));
    // diff or empty when there is no difference
    assertTrue(parts.get(1).length() == 0 || parts.get(1).startsWith("diff"));

    return parts.toArray(new String[0]);
  }
Ejemplo n.º 24
0
  public void testViewAccessLogByRole() throws Exception {
    gen.transactionLog3();
    WebConversation wc = login("1", "pw");
    WebResponse wr = wc.getCurrentPage();
    assertEquals("iTrust - Patient Home", wr.getTitle());
    assertLogged(TransactionType.HOME_VIEW, 1L, 0L, "");

    wr = wr.getLinkWith("Access Log").click();
    assertFalse(wr.getText().contains("Exception"));

    WebForm form = wr.getForms()[0];
    form.setParameter("startDate", "02/01/2008");
    form.setParameter("endDate", "09/22/2009");
    form.getSubmitButtons()[0].click();
    form.getScriptableObject().setParameterValue("sortBy", "role");
    wr = form.submit();

    WebTable table = wr.getTableStartingWithPrefix("Date");
    assertTrue(table.getCellAsText(1, 2).contains("Emergency Responder"));
    assertTrue(table.getCellAsText(2, 2).contains("LHCP"));
    assertTrue(table.getCellAsText(3, 2).contains("LHCP"));
    assertTrue(table.getCellAsText(4, 2).contains("LHCP"));
    assertTrue(table.getCellAsText(5, 2).contains("Personal Health Representative"));
    assertTrue(table.getCellAsText(6, 2).contains("UAP"));

    assertLogged(TransactionType.ACCESS_LOG_VIEW, 1L, 0L, "");
  }
Ejemplo n.º 25
0
  /**
   * Test as Html.
   *
   * @param jspName jsp name, with full path
   * @throws Exception any axception thrown during test.
   */
  public void doTest(String jspName) throws Exception {

    WebRequest request = new GetMethodWebRequest(jspName);

    WebResponse response = runner.getResponse(request);

    if (log.isDebugEnabled()) {
      log.debug("RESPONSE: " + response.getText());
    }

    WebTable[] tables = response.getTables();

    assertEquals("Wrong number of tables.", 1, tables.length);

    assertEquals("Bad number of generated columns.", 2, tables[0].getColumnCount());

    assertEquals(
        "Bad value in column header.", //
        StringUtils.capitalize(KnownValue.ANT),
        tables[0].getCellAsText(0, 0));
    assertEquals(
        "Bad value in column header.", //
        StringUtils.capitalize(KnownValue.CAMEL),
        tables[0].getCellAsText(0, 1));
  }
  public void testChangePassword_Invalid_Length() throws Exception {
    // Patient1 logs into iTrust
    WebConversation wc = login("1", "pw");
    WebResponse wr = wc.getCurrentPage();
    assertEquals("iTrust - Patient Home", wr.getTitle());

    // User goes to change password
    wr = wr.getLinkWith("Change Password").click();

    // User types in their current, new, and confirm passwords
    WebForm wf = wr.getFormWithID("mainForm");
    wf.setParameter("oldPass", "pw");
    wf.setParameter("newPass", "pas1");
    wf.setParameter("confirmPass", "pas1");

    // User submits password change. Change logged
    wf.submit(wf.getSubmitButtons()[0]);
    wr = wc.getCurrentPage();
    assertTrue(wr.getText().contains("Invalid password"));
    assertLogged(TransactionType.PASSWORD_CHANGE_FAILED, 1L, 0, "");

    // User logs out
    wr = wr.getLinkWith("Logout").click();

    // User can log in with old password, but can't with new one
    wc = login("1", "pas1");
    assertEquals("iTrust - Login", wc.getCurrentPage().getTitle());
    wc = login("1", "pw");
    assertEquals("iTrust - Patient Home", wc.getCurrentPage().getTitle());
  }
Ejemplo n.º 27
0
  @Test
  public void testGetNonexistingClone() throws Exception {
    URI workspaceLocation = createWorkspace(getMethodName());
    String workspaceId = getWorkspaceId(workspaceLocation);

    WebRequest request = listGitClonesRequest(workspaceId, null);
    WebResponse response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    JSONObject clones = new JSONObject(response.getText());
    JSONArray clonesArray = clones.getJSONArray(ProtocolConstants.KEY_CHILDREN);

    String dummyId = "dummyId";

    ensureCloneIdDoesntExist(clonesArray, dummyId);

    String requestURI =
        SERVER_LOCATION + GIT_SERVLET_LOCATION + Clone.RESOURCE + "/workspace/" + dummyId;
    request = getGetRequest(requestURI);
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_NOT_FOUND, response.getResponseCode());

    requestURI = SERVER_LOCATION + GIT_SERVLET_LOCATION + Clone.RESOURCE + "/file/" + dummyId;
    request = getGetRequest(requestURI);
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_NOT_FOUND, response.getResponseCode());
  }
Ejemplo n.º 28
0
  @Test
  public void testGetCloneAndPull() throws Exception {
    // see bug 339254
    URI workspaceLocation = createWorkspace(getMethodName());
    String workspaceId = getWorkspaceId(workspaceLocation);

    JSONObject project = createProjectOrLink(workspaceLocation, getMethodName(), null);
    IPath clonePath =
        new Path("file").append(project.getString(ProtocolConstants.KEY_ID)).makeAbsolute();
    String contentLocation = clone(clonePath).getString(ProtocolConstants.KEY_CONTENT_LOCATION);

    // get clones for workspace
    WebRequest request = listGitClonesRequest(workspaceId, null);
    WebResponse response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    JSONObject clones = new JSONObject(response.getText());
    JSONArray clonesArray = clones.getJSONArray(ProtocolConstants.KEY_CHILDREN);
    assertEquals(1, clonesArray.length());

    Git git = new Git(getRepositoryForContentLocation(contentLocation));
    // TODO: replace with RESTful API when ready, see bug 339114
    PullResult pullResult = git.pull().call();
    assertEquals(pullResult.getMergeResult().getMergeStatus(), MergeStatus.ALREADY_UP_TO_DATE);
    assertEquals(RepositoryState.SAFE, git.getRepository().getRepositoryState());
  }
Ejemplo n.º 29
0
  @Test
  public void testCloneEmptyPath() throws Exception {
    URI workspaceLocation = createWorkspace(getMethodName());
    IPath clonePath =
        new Path("workspace").append(getWorkspaceId(workspaceLocation)).makeAbsolute();

    AuthorizationService.removeUserRight("test", "/");
    AuthorizationService.removeUserRight("test", "/*");

    // /workspace/{id}
    JSONObject clone = clone(clonePath, null, null);

    String cloneContentLocation = clone.getString(ProtocolConstants.KEY_CONTENT_LOCATION);
    WebRequest request = getGetFilesRequest(cloneContentLocation);
    WebResponse response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    JSONObject project = new JSONObject(response.getText());
    assertEquals(gitDir.getName(), project.getString(ProtocolConstants.KEY_NAME));
    assertGitSectionExists(project);

    String childrenLocation = project.getString(ProtocolConstants.KEY_CHILDREN_LOCATION);
    assertNotNull(childrenLocation);

    // http://<host>/file/<projectId>/?depth=1
    request = getGetFilesRequest(childrenLocation);
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
  }
Ejemplo n.º 30
0
  @Test
  public void testCloneEmptyPathBadUrl() throws Exception {
    URI workspaceLocation = createWorkspace(getMethodName());
    IPath workspacePath =
        new Path("workspace").append(getWorkspaceId(workspaceLocation)).makeAbsolute();

    AuthorizationService.removeUserRight("test", "/");
    AuthorizationService.removeUserRight("test", "/*");

    // /workspace/{id} + {methodName}
    WebRequest request =
        new PostGitCloneRequest()
            .setURIish("I'm//bad!")
            .setWorkspacePath(workspacePath)
            .setName(getMethodName())
            .getWebRequest();
    WebResponse response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_BAD_REQUEST, response.getResponseCode());

    // no project should be created
    request = new GetMethodWebRequest(workspaceLocation.toString());
    setAuthentication(request);
    response = webConversation.getResponse(request);
    JSONObject workspace = new JSONObject(response.getText());
    assertEquals(0, workspace.getJSONArray(ProtocolConstants.KEY_CHILDREN).length());
  }