Пример #1
0
  @Test(groups = {"webservice"})
  public void testMasterTemplateValidationMissingBothMandatoryUserInputFields()
      throws SQLException, IOException {
    HttpClient client = new HttpClient();
    client.createContext();
    dbWrapper.updateConfigureTemplate("HIV", "source", "U", "true", "stockInHand");
    dbWrapper.updateConfigureTemplate("HIV", "source", "U", "true", "quantityDispensed");
    Report reportFromJson =
        JsonUtility.readObjectFromFile(MINIMUM_JSON_TXT_FILE_NAME, Report.class);
    reportFromJson.setAgentCode("V10");
    reportFromJson.setProgramCode("HIV");
    reportFromJson.getProducts().get(0).setProductCode("P10");
    reportFromJson.getProducts().get(0).setBeginningBalance(1);
    reportFromJson.getProducts().get(0).setQuantityReceived(4);
    reportFromJson.getProducts().get(0).setQuantityDispensed(null);
    reportFromJson.getProducts().get(0).setStockInHand(null);
    ResponseEntity responseEntity =
        client.SendJSON(
            getJsonStringFor(reportFromJson),
            "http://localhost:9091/rest-api/requisitions.json",
            POST,
            "commTrack",
            "Admin123");

    assertEquals(400, responseEntity.getStatus());
    assertEquals(
        "{\"error\":\"R&R has errors, please correct them to proceed.\"}",
        responseEntity.getResponse());
  }
Пример #2
0
  @Test(groups = {"webservice"})
  public void testSubmitReportRnRWithoutFillingInactiveRegimen() throws SQLException, IOException {
    dbWrapper.insertRegimenTemplateColumnsForProgram("HIV");
    dbWrapper.insertRegimenTemplateConfiguredForProgram(
        "HIV", "ADULTS", "Regimen", "Regimen1", false);
    dbWrapper.updateFieldValue("programs", "regimenTemplateConfigured", "true", null, null);
    HttpClient client = new HttpClient();
    client.createContext();

    Report reportFromJson = readObjectFromFile(FULL_JSON_TXT_FILE_NAME, Report.class);
    reportFromJson.setAgentCode("V10");
    reportFromJson.setProgramCode("HIV");
    reportFromJson.getProducts().get(0).setProductCode("P10");
    reportFromJson.getProducts().get(0).setBeginningBalance(10);
    reportFromJson.getProducts().get(0).setQuantityDispensed(10);
    reportFromJson.getProducts().get(0).setQuantityReceived(10);

    String jsonStringFor = getJsonStringFor(reportFromJson);
    ResponseEntity responseEntity =
        client.SendJSON(
            jsonStringFor,
            "http://localhost:9091/rest-api/requisitions.json",
            POST,
            "commTrack",
            "Admin123");

    assertEquals(201, responseEntity.getStatus());
    assertTrue(responseEntity.getResponse().contains("{\"requisitionId\":"));
  }
Пример #3
0
  @Test(groups = {"webservice"})
  public void testMultipleSubmitReportForParentFacility() throws SQLException, IOException {
    dbWrapper.updateProgramsSupportedByField("startDate", "NOW()", "F10");
    HttpClient client = new HttpClient();
    client.createContext();

    Report reportFromJson = JsonUtility.readObjectFromFile(FULL_JSON_TXT_FILE_NAME, Report.class);
    reportFromJson.setAgentCode("F10");
    reportFromJson.setProgramCode("HIV");
    reportFromJson.getProducts().get(0).setProductCode("P10");

    ResponseEntity responseEntity =
        client.SendJSON(
            getJsonStringFor(reportFromJson),
            "http://localhost:9091/rest-api/requisitions.json",
            POST,
            "commTrack",
            "Admin123");

    assertEquals(201, responseEntity.getStatus());
    assertTrue(responseEntity.getResponse().contains("{\"requisitionId\":"));

    responseEntity =
        client.SendJSON(
            getJsonStringFor(reportFromJson),
            "http://localhost:9091/rest-api/requisitions.json",
            POST,
            "commTrack",
            "Admin123");
    assertEquals(400, responseEntity.getStatus());
    assertEquals("{\"error\":\"Program configuration missing\"}", responseEntity.getResponse());
  }
Пример #4
0
  @Test(groups = {"webservice"})
  public void testCommTrackSubmitReportValidRnR() throws SQLException, IOException {
    dbWrapper.deleteConfigureTemplate("HIV");
    dbWrapper.configureTemplateForCommTrack("HIV");
    dbWrapper.insertPastPeriodRequisitionAndLineItems("F10", "HIV", "Period1", "P10");
    HttpClient client = new HttpClient();
    client.createContext();

    Report reportFromJson = readObjectFromFile("CommTrackReportJson.txt", Report.class);
    reportFromJson.setAgentCode("V10");
    reportFromJson.setProgramCode("HIV");
    reportFromJson.getProducts().get(0).setProductCode("P10");
    reportFromJson.getProducts().get(0).setBeginningBalance(10);
    reportFromJson.getProducts().get(0).setQuantityDispensed(10);
    reportFromJson.getProducts().get(0).setQuantityReceived(10);

    ResponseEntity responseEntity =
        client.SendJSON(
            getJsonStringFor(reportFromJson),
            "http://localhost:9091/rest-api/requisitions.json",
            "POST",
            "commTrack",
            "Admin123");

    assertEquals(201, responseEntity.getStatus());
    assertTrue(responseEntity.getResponse().contains("{\"requisitionId\":"));
  }
Пример #5
0
  @Test(groups = {"webservice"})
  public void shouldSubmitDuplicateReport() throws IOException {
    HttpClient client = new HttpClient();
    client.createContext();

    Report reportFromJson = readObjectFromFile(FULL_JSON_TXT_FILE_NAME, Report.class);
    reportFromJson.setAgentCode("V10");
    reportFromJson.setProgramCode("HIV");
    reportFromJson.getProducts().get(0).setProductCode("P10");

    String jsonStringFor = getJsonStringFor(reportFromJson);
    client.SendJSON(
        jsonStringFor,
        "http://localhost:9091/rest-api/requisitions.json",
        POST,
        "commTrack",
        "Admin123");

    ResponseEntity responseEntity =
        client.SendJSON(
            jsonStringFor,
            "http://localhost:9091/rest-api/requisitions.json",
            POST,
            "commTrack",
            "Admin123");

    assertEquals(201, responseEntity.getStatus());
    assertTrue(responseEntity.getResponse().contains("{\"requisitionId\":"));
  }
Пример #6
0
  @Test(groups = {"webservice"})
  public void testInitiateRnrWhenProgramStartDateIsAfterCurrentDateAndInCurrentPeriod()
      throws SQLException, IOException {
    dbWrapper.updateProgramsSupportedByField("startDate", "2015-01-01", "V10");
    HttpClient client = new HttpClient();
    client.createContext();
    Report reportFromJson =
        JsonUtility.readObjectFromFile(PRODUCT_JSON_TXT_FILE_NAME, Report.class);
    reportFromJson.setAgentCode("V10");
    reportFromJson.setProgramCode("HIV");
    reportFromJson.getProducts().get(0).setProductCode("P10");
    reportFromJson.getProducts().get(0).setBeginningBalance(1);
    reportFromJson.getProducts().get(0).setQuantityDispensed(1);
    reportFromJson.getProducts().get(0).setQuantityReceived(4);
    reportFromJson.getProducts().get(0).setStockInHand(4);

    ResponseEntity responseEntity =
        client.SendJSON(
            getJsonStringFor(reportFromJson),
            "http://localhost:9091/rest-api/requisitions.json",
            POST,
            "commTrack",
            "Admin123");

    assertEquals(201, responseEntity.getStatus());
    assertTrue(responseEntity.getResponse().contains("{\"requisitionId\":"));
  }
Пример #7
0
  @Test(groups = {"webservice"})
  public void testSubmitReportMandatoryFieldsMissing() throws IOException {
    HttpClient client = new HttpClient();
    client.createContext();
    Report reportFromJson = JsonUtility.readObjectFromFile(FULL_JSON_TXT_FILE_NAME, Report.class);
    reportFromJson.setAgentCode("V10");

    ResponseEntity responseEntity =
        client.SendJSON(
            getJsonStringFor(reportFromJson),
            "http://localhost:9091/rest-api/requisitions.json",
            POST,
            "commTrack",
            "Admin123");

    assertEquals(400, responseEntity.getStatus());
    assertEquals("{\"error\":\"Missing mandatory fields\"}", responseEntity.getResponse());

    reportFromJson = JsonUtility.readObjectFromFile(FULL_JSON_TXT_FILE_NAME, Report.class);
    reportFromJson.setProgramCode("HIV");

    responseEntity =
        client.SendJSON(
            getJsonStringFor(reportFromJson),
            "http://localhost:9091/rest-api/requisitions.json",
            POST,
            "commTrack",
            "Admin123");

    assertEquals(400, responseEntity.getStatus());
    assertEquals("{\"error\":\"Missing mandatory fields\"}", responseEntity.getResponse());
  }
Пример #8
0
  @Test(groups = {"webservice"})
  public void testSubmitReportWithoutHeaders() throws IOException {
    HttpClient client = new HttpClient();
    client.createContext();
    Report reportFromJson = readObjectFromFile(FULL_JSON_TXT_FILE_NAME, Report.class);
    reportFromJson.setAgentCode("V10");
    reportFromJson.setProgramCode("HIV");

    ResponseEntity responseEntity =
        client.SendJSONWithoutHeaders(
            getJsonStringFor(reportFromJson),
            "http://localhost:9091/rest-api/requisitions.json",
            POST,
            "",
            "");
    assertEquals(401, responseEntity.getStatus());
  }
Пример #9
0
  @Test(groups = {"webserviceSmoke"})
  public void shouldReturn401StatusWhenSubmittingReportWithInvalidAPIUser() throws IOException {
    HttpClient client = new HttpClient();
    client.createContext();

    Report reportFromJson =
        JsonUtility.readObjectFromFile(MINIMUM_JSON_TXT_FILE_NAME, Report.class);
    reportFromJson.setAgentCode("V10");
    reportFromJson.setProgramCode("HIV");

    ResponseEntity responseEntity =
        client.SendJSON(
            getJsonStringFor(reportFromJson),
            "http://localhost:9091/rest-api/requisitions.json",
            POST,
            "commTrack1000",
            "Admin123");

    assertEquals(401, responseEntity.getStatus());
  }
Пример #10
0
  @Test(groups = {"webservice"})
  public void testSubmitReportWhenParentFacilityInactive() throws SQLException, IOException {
    dbWrapper.updateFieldValue("facilities", "active", "false", "code", "V10");
    HttpClient client = new HttpClient();
    client.createContext();
    Report reportFromJson = JsonUtility.readObjectFromFile(FULL_JSON_TXT_FILE_NAME, Report.class);
    reportFromJson.setAgentCode("V10");
    reportFromJson.setProgramCode("HIV");

    ResponseEntity responseEntity =
        client.SendJSON(
            getJsonStringFor(reportFromJson),
            "http://localhost:9091/rest-api/requisitions.json",
            POST,
            "commTrack",
            "Admin123");

    assertEquals(400, responseEntity.getStatus());
    assertEquals("{\"error\":\"Facility is inoperative\"}", responseEntity.getResponse());
  }
Пример #11
0
  @Test(groups = {"webservice"})
  public void testSubmitReportWhenUserWithoutRights() throws IOException, SQLException {
    dbWrapper.deleteSupervisoryRoleFromRoleAssignment();
    HttpClient client = new HttpClient();
    client.createContext();

    Report reportFromJson = readObjectFromFile(FULL_JSON_TXT_FILE_NAME, Report.class);
    reportFromJson.setAgentCode("V10");
    reportFromJson.setProgramCode("HIV");

    ResponseEntity responseEntity =
        client.SendJSON(
            getJsonStringFor(reportFromJson),
            "http://localhost:9091/rest-api/requisitions.json",
            POST,
            "commTrack",
            "Admin123");

    assertEquals(400, responseEntity.getStatus());
    assertEquals(responseEntity.getResponse(), "{\"error\":\"User does not have permission\"}");
  }
Пример #12
0
  @Test(groups = {"webservice"})
  public void testProductNotAvailableAtFacilitySubmitReport() throws SQLException, IOException {
    dbWrapper.deleteProductAvailableAtFacility("P10", "HIV", "V10");
    HttpClient client = new HttpClient();
    client.createContext();

    Report reportFromJson = JsonUtility.readObjectFromFile(FULL_JSON_TXT_FILE_NAME, Report.class);
    reportFromJson.setAgentCode("V10");
    reportFromJson.setProgramCode("HIV");
    reportFromJson.getProducts().get(0).setProductCode("P10");

    ResponseEntity responseEntity =
        client.SendJSON(
            getJsonStringFor(reportFromJson),
            "http://localhost:9091/rest-api/requisitions.json",
            POST,
            "commTrack",
            "Admin123");

    assertEquals(400, responseEntity.getStatus());
    assertEquals("{\"error\":\"Invalid product codes [P10]\"}", responseEntity.getResponse());
  }
Пример #13
0
  @Test(groups = {"webservice"})
  public void testInitiateRnrWhenCurrentPeriodNotDefined() throws IOException, SQLException {
    dbWrapper.deleteCurrentPeriod();
    HttpClient client = new HttpClient();
    client.createContext();
    Report reportFromJson =
        JsonUtility.readObjectFromFile(PRODUCT_JSON_TXT_FILE_NAME, Report.class);
    reportFromJson.setAgentCode("V10");
    reportFromJson.setProgramCode("HIV");
    reportFromJson.getProducts().get(0).setProductCode("P10");

    ResponseEntity responseEntity =
        client.SendJSON(
            getJsonStringFor(reportFromJson),
            "http://localhost:9091/rest-api/requisitions.json",
            POST,
            "commTrack",
            "Admin123");

    assertEquals(400, responseEntity.getStatus());
    assertEquals(responseEntity.getResponse(), "{\"error\":\"Program configuration missing\"}");
  }
Пример #14
0
  @Test(groups = {"webservice"})
  public void testSubmitReportWhenTemplateNotConfigured() throws SQLException, IOException {
    dbWrapper.deleteTable("program_rnr_columns");
    HttpClient client = new HttpClient();
    client.createContext();
    Report reportFromJson = JsonUtility.readObjectFromFile(FULL_JSON_TXT_FILE_NAME, Report.class);
    reportFromJson.setAgentCode("V10");
    reportFromJson.setProgramCode("HIV");

    ResponseEntity responseEntity =
        client.SendJSON(
            getJsonStringFor(reportFromJson),
            "http://localhost:9091/rest-api/requisitions.json",
            POST,
            "commTrack",
            "Admin123");

    assertEquals(400, responseEntity.getStatus());
    assertEquals(
        "{\"error\":\"Please contact admin to define R&R template for this program\"}",
        responseEntity.getResponse());
  }
Пример #15
0
  @Test(groups = {"webservice"})
  public void testPreviousPeriodSubmitReportForParentFacility() throws IOException {
    HttpClient client = new HttpClient();
    client.createContext();

    Report reportFromJson = JsonUtility.readObjectFromFile(FULL_JSON_TXT_FILE_NAME, Report.class);
    reportFromJson.setAgentCode("F10");
    reportFromJson.setProgramCode("HIV");
    reportFromJson.getProducts().get(0).setProductCode("P10");

    ResponseEntity responseEntity =
        client.SendJSON(
            getJsonStringFor(reportFromJson),
            "http://localhost:9091/rest-api/requisitions.json",
            POST,
            "commTrack",
            "Admin123");

    assertEquals(400, responseEntity.getStatus());
    assertEquals(
        "{\"error\":\"Please finish all R&R of previous period(s)\"}",
        responseEntity.getResponse());
  }
Пример #16
0
  @Test(groups = {"webservice"})
  public void testInitiateRnrWhenProgramStartDateIsAfterCurrentDateAndCurrentPeriodEndDate()
      throws SQLException, IOException {
    dbWrapper.insertProcessingPeriod("future", "future period", "2016-01-30", "2017-01-30", 1, "M");
    dbWrapper.updateProgramsSupportedByField("startDate", "2017-01-01", "V10");
    HttpClient client = new HttpClient();
    client.createContext();
    Report reportFromJson =
        JsonUtility.readObjectFromFile(PRODUCT_JSON_TXT_FILE_NAME, Report.class);
    reportFromJson.setAgentCode("V10");
    reportFromJson.setProgramCode("HIV");
    reportFromJson.getProducts().get(0).setProductCode("P10");

    ResponseEntity responseEntity =
        client.SendJSON(
            getJsonStringFor(reportFromJson),
            "http://localhost:9091/rest-api/requisitions.json",
            POST,
            "commTrack",
            "Admin123");

    assertEquals(400, responseEntity.getStatus());
    assertEquals(responseEntity.getResponse(), "{\"error\":\"Program configuration missing\"}");
  }