如何为closeablehttpclient httpclient=gethttpclient()编写junit测试?

nzrxty8p  于 2021-07-23  发布在  Java
关注(0)|答案(0)|浏览(214)

对于这样的函数,如何进行junit测试?

try {
          HttpPost httppost = new HttpPost("http://tbird2:80/uws/archive/QueryDicom");
          httppost.addHeader("content-type", "application/xml");

          String quoteRequestPayLoad = DMUtils.getQueryDicomXmlPayload(studyInstanceUUID);

          StringEntity userEntity = new StringEntity(quoteRequestPayLoad);
          httppost.setEntity(userEntity);

          HttpResponse httpresponse = httpClient.execute(httppost);

          HttpEntity entity = httpresponse.getEntity();
          String responseString = EntityUtils.toString(entity, "UTF-8");

          List<String> SOPInstanceUUIDs = DMUtils.parseSopIdFromQuteResponse(responseString);

          SOPInstanceUUIDs.forEach(
              SOPInstanceUUID -> {
                try {
                  // remove " first and last char as this is coming from xml &quote
                  SOPInstanceUUID = SOPInstanceUUID.substring(1, SOPInstanceUUID.length() - 1);
                  dicomObjectList.add(fetchDicomObjectFromSOPInstanceUUID(SOPInstanceUUID));
                } catch (Exception e) {
                  e.printStackTrace();
                }
              });

          return dicomObjectList;}

如何使用apache?我想不出一个开门红的主意。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题