Ejemplo n.º 1
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\":"));
  }
Ejemplo n.º 2
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());
  }
Ejemplo n.º 3
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\":"));
  }
Ejemplo n.º 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\":"));
  }
Ejemplo n.º 5
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());
  }
Ejemplo n.º 6
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\":"));
  }
Ejemplo n.º 7
0
  @Test(groups = {"webservice"})
  public void testInvalidProductSubmitReport() throws IOException {
    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("P10000");

    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 [P10000]\"}", responseEntity.getResponse());
  }
Ejemplo n.º 8
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\"}");
  }
Ejemplo n.º 9
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\"}");
  }