Exemplo n.º 1
0
  public void testPie1() {
    try {

      String url = baseURL + "/rest/Pie/search;id=*/utensilCollection";

      WebClient client = WebClient.create(url);
      client.type("application/xml").accept("application/xml");
      Response response = client.get();

      if (response.getStatus() == Status.NOT_ACCEPTABLE.getStatusCode()) {
        InputStream is = (InputStream) response.getEntity();
        org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder(false);
        org.jdom.Document jDoc = builder.build(is);
        assertEquals(jDoc.getRootElement().getName(), "response");
      } else if (response.getStatus() == Status.NOT_FOUND.getStatusCode()) {
        InputStream is = (InputStream) response.getEntity();
        org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder(false);
        org.jdom.Document jDoc = builder.build(is);
        assertEquals(jDoc.getRootElement().getName(), "response");
      } else if (response.getStatus() != 200) {
        throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
      }

      File myFile = new File("Pie_Search" + "XML.xml");
      System.out.println("writing data to file " + myFile.getAbsolutePath());
      FileWriter myWriter = new FileWriter(myFile);

      BufferedReader br =
          new BufferedReader(new InputStreamReader(((InputStream) response.getEntity())));

      String output;
      System.out.println("Output from Server .... \n");
      while ((output = br.readLine()) != null) {
        myWriter.write(output);
        System.out.println(output);
      }

      myWriter.flush();
      myWriter.close();

    } catch (Exception e) {
      e.printStackTrace();
      ResponseBuilder builder = Response.status(Status.INTERNAL_SERVER_ERROR);
      builder.type("application/xml");
      StringBuffer buffer = new StringBuffer();
      buffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
      buffer.append("<response>");
      buffer.append("<type>ERROR</type>");
      buffer.append("<code>INTERNAL_ERROR_4</code>");
      buffer.append("<message>Failed to Query due to: " + e.getMessage() + "</message>");
      buffer.append("</response>");
      builder.entity(buffer.toString());
      throw new WebApplicationException(builder.build());
    }
  }
Exemplo n.º 2
0
  public void testDelete() throws Exception {

    try {

      Pie searchObject = new Pie();
      Collection results =
          getApplicationService()
              .search(
                  "gov.nih.nci.cacoresdk.domain.other.differentpackage.associations.Pie",
                  searchObject);
      String id = "";

      if (results != null && results.size() > 0) {
        Pie obj = (Pie) ((List) results).get(0);

        Integer idVal = obj.getId();

        id = new Integer(idVal).toString();

      } else return;

      if (id.equals("")) return;

      String url = baseURL + "/rest/Pie/" + id;
      WebClient client = WebClient.create(url);

      Response response = client.delete();

      if (response.getStatus() == Status.NOT_ACCEPTABLE.getStatusCode()) {
        InputStream is = (InputStream) response.getEntity();
        org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder(false);
        org.jdom.Document jDoc = builder.build(is);
        assertEquals(jDoc.getRootElement().getName(), "response");
      } else if (response.getStatus() == Status.NOT_FOUND.getStatusCode()) {
        InputStream is = (InputStream) response.getEntity();
        org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder(false);
        org.jdom.Document jDoc = builder.build(is);
        assertEquals(jDoc.getRootElement().getName(), "response");
      } else if (response.getStatus() != 200) {
        throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
      }
    } catch (Exception e) {
      e.printStackTrace();
      throw e;
    }
  }
Exemplo n.º 3
0
  public void testSearch() throws Exception {

    try {

      String url = baseURL + "/rest/Pupil/search;id=*";
      WebClient client = WebClient.create(url);
      client.type("application/xml").accept("application/xml");
      Response response = client.get();

      if (response.getStatus() == Status.NOT_ACCEPTABLE.getStatusCode()) {
        InputStream is = (InputStream) response.getEntity();
        org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder(false);
        org.jdom.Document jDoc = builder.build(is);
        assertEquals(jDoc.getRootElement().getName(), "response");
      } else if (response.getStatus() == Status.NOT_FOUND.getStatusCode()) {
        InputStream is = (InputStream) response.getEntity();
        org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder(false);
        org.jdom.Document jDoc = builder.build(is);
        assertEquals(jDoc.getRootElement().getName(), "response");
      } else if (response.getStatus() != 200) {
        throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
      }

      File myFile = new File("Pupil_Search" + "XML.xml");
      System.out.println("writing data to file " + myFile.getAbsolutePath());
      FileWriter myWriter = new FileWriter(myFile);

      BufferedReader br =
          new BufferedReader(new InputStreamReader(((InputStream) response.getEntity())));

      String output;
      System.out.println("Output from Server .... \n");
      while ((output = br.readLine()) != null) {
        myWriter.write(output);
        System.out.println(output);
      }

      myWriter.flush();
      myWriter.close();

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 4
0
  /**
   * Uses Nested Search Criteria for search Verifies that the results are returned Verifies size of
   * the result set Verifies that none of the attributes are null
   *
   * @throws Exception
   */
  public void testGet() throws Exception {

    try {

      Pupil searchObject = new Pupil();
      Collection results =
          getApplicationService()
              .search("gov.nih.nci.cacoresdk.domain.inheritance.abstrakt.Pupil", searchObject);
      String id = "";

      if (results != null && results.size() > 0) {
        Pupil obj = (Pupil) ((List) results).get(0);

        id = obj.getId().getExtension();

      } else return;

      if (id.equals("")) return;

      String url = baseURL + "/rest/Pupil/" + id;

      WebClient client = WebClient.create(url);
      client.type("application/xml").accept("application/xml");
      Response response = client.get();

      if (response.getStatus() == Status.NOT_ACCEPTABLE.getStatusCode()) {
        InputStream is = (InputStream) response.getEntity();
        org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder(false);
        org.jdom.Document jDoc = builder.build(is);
        assertEquals(jDoc.getRootElement().getName(), "response");
      } else if (response.getStatus() == Status.NOT_FOUND.getStatusCode()) {
        InputStream is = (InputStream) response.getEntity();
        org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder(false);
        org.jdom.Document jDoc = builder.build(is);
        assertEquals(jDoc.getRootElement().getName(), "response");
      } else if (response.getStatus() != 200) {
        throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
      }

      File myFile = new File("Pupil" + "XML.xml");

      System.out.println("writing data to file " + myFile.getAbsolutePath());
      FileWriter myWriter = new FileWriter(myFile);

      BufferedReader br =
          new BufferedReader(new InputStreamReader(((InputStream) response.getEntity())));

      String output;
      System.out.println("Output from Server .... \n");
      while ((output = br.readLine()) != null) {
        myWriter.write(output);
        System.out.println(output);
      }

      myWriter.flush();
      myWriter.close();
    } catch (Exception e) {
      e.printStackTrace();
      throw e;
    }
  }
Exemplo n.º 5
0
  public void testgetUtensilCollection() {
    try {
      Pie searchObject = new Pie();
      Collection results4 =
          getApplicationService()
              .search(
                  "gov.nih.nci.cacoresdk.domain.other.differentpackage.associations.Pie",
                  searchObject);
      String id = "";

      if (results4 != null && results4.size() > 0) {
        Pie obj = (Pie) ((List) results4).get(0);

        Integer idVal = obj.getId();

        id = new Integer(idVal).toString();

      } else return;

      if (id.equals("")) return;

      String url = baseURL + "/rest/Pie/" + id + "/utensilCollection";

      WebClient client = WebClient.create(url);
      client.type("application/xml").accept("application/xml");
      Response response = client.get();

      if (response.getStatus() == Status.NOT_ACCEPTABLE.getStatusCode()) {
        InputStream is = (InputStream) response.getEntity();
        org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder(false);
        org.jdom.Document jDoc = builder.build(is);
        assertEquals(jDoc.getRootElement().getName(), "response");
      } else if (response.getStatus() == Status.NOT_FOUND.getStatusCode()) {
        InputStream is = (InputStream) response.getEntity();
        org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder(false);
        org.jdom.Document jDoc = builder.build(is);
        assertEquals(jDoc.getRootElement().getName(), "response");
      } else if (response.getStatus() != 200) {
        throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
      }

      File myFile = new File("Pie_Search" + "XML.xml");
      System.out.println("writing data to file " + myFile.getAbsolutePath());
      FileWriter myWriter = new FileWriter(myFile);

      BufferedReader br =
          new BufferedReader(new InputStreamReader(((InputStream) response.getEntity())));

      String output;
      System.out.println("Output from Server .... \n");
      while ((output = br.readLine()) != null) {
        myWriter.write(output);
        System.out.println(output);
      }

      myWriter.flush();
      myWriter.close();
    } catch (Exception e) {
      e.printStackTrace();
      ResponseBuilder builder = Response.status(Status.INTERNAL_SERVER_ERROR);
      builder.type("application/xml");
      StringBuffer buffer = new StringBuffer();
      buffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
      buffer.append("<response>");
      buffer.append("<type>ERROR</type>");
      buffer.append("<code>INTERNAL_ERROR_4</code>");
      buffer.append("<message>Failed to Query due to: " + e.getMessage() + "</message>");
      buffer.append("</response>");
      builder.entity(buffer.toString());
      throw new WebApplicationException(builder.build());
    }
  }
 /** @return {@link Status#INTERNAL_SERVER_ERROR} */
 @Override
 public int getStatusCode() {
   return Status.NOT_ACCEPTABLE.getStatusCode();
 }