@Test public void getGeneCountsFromPhenotypesPanelSmallerThanRequestedNumberOfTermsReturnsCorrectResponse() { final List<Object> presentTermList = Arrays.asList(HP1, HP3, HP4, HP5, HP6); final List<Object> absentTermList = Collections.singletonList(HP2); when(this.request.getProperties(PRESENT_TERMS_LABEL)).thenReturn(presentTermList); when(this.request.getProperties(ABSENT_TERMS_LABEL)).thenReturn(absentTermList); when(this.request.getProperties(REJECTED_GENES_LABEL)).thenReturn(Collections.emptyList()); when(this.request.getProperty(OFFSET_LABEL)).thenReturn("3"); final JSONObject testObj = new JSONObject().put(GENE_LABEL, GENE_DATA_PLACEHOLDER); when(this.panel.toJSON(2, 5)).thenReturn(testObj); final Response response = this.component.getGeneCountsFromPhenotypes(); verify(this.panel, times(1)).toJSON(2, 5); Assert.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); Assert.assertTrue(new JSONObject().put(GENE_LABEL, GENE_DATA_PLACEHOLDER).put(REQ_NO_LABEL, 5) .put(OFFSET_LABEL, 3).similar(response.getEntity())); }
@Override public Response getGeneCountsFromPhenotypes() { final Request request = this.container.getRequest(); final Set<String> present = extractTerms("present-term", request); final Set<String> absent = extractTerms("absent-term", request); final Set<String> rejected = extractTerms("rejected-gene", request); final boolean withMatchCount = Boolean.parseBoolean((String) request.getProperty("with-match-count")); if (CollectionUtils.isEmpty(present) && CollectionUtils.isEmpty(absent)) { this.slf4Jlogger.error("No content provided."); return Response.status(Response.Status.NO_CONTENT).build(); } final int offset = NumberUtils.toInt((String) request.getProperty(OFFSET_LABEL), 1); final int limit = NumberUtils.toInt((String) request.getProperty(LIMIT_LABEL), -1); final int reqNo = NumberUtils.toInt((String) request.getProperty(REQ_NO), 0); try { final JSONObject panelJSON = getPanelData(present, absent, rejected, withMatchCount, offset, limit); panelJSON.put(REQ_NO, reqNo); panelJSON.put(OFFSET_LABEL, offset); return Response.ok(panelJSON, MediaType.APPLICATION_JSON_TYPE).build(); } catch (final ExecutionException e) { this.slf4Jlogger.warn("No content associated with [present-term: {}, absent-term: {}].", present, absent); return Response.status(Response.Status.NO_CONTENT).build(); } catch (final IndexOutOfBoundsException e) { this.slf4Jlogger.error("The requested [{}: {}] is out of bounds.", OFFSET_LABEL, offset); return Response.status(Response.Status.BAD_REQUEST).build(); } catch (final Exception e) { this.slf4Jlogger.error("Unexpected exception while generating gene panel JSON: {}", e.getMessage()); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } }
DefaultGenePanelsLiveTableResourceImpl extends XWikiResource implements GenePanelsLiveTableResource { @Override public Response getGeneCountsFromPhenotypes() { final Request request = this.container.getRequest(); final Set<String> present = extractTerms("present-term", request); final Set<String> absent = extractTerms("absent-term", request); final Set<String> rejected = extractTerms("rejected-gene", request); final boolean withMatchCount = Boolean.parseBoolean((String) request.getProperty("with-match-count")); if (CollectionUtils.isEmpty(present) && CollectionUtils.isEmpty(absent)) { this.slf4Jlogger.error("No content provided."); return Response.status(Response.Status.NO_CONTENT).build(); } final int offset = NumberUtils.toInt((String) request.getProperty(OFFSET_LABEL), 1); final int limit = NumberUtils.toInt((String) request.getProperty(LIMIT_LABEL), -1); final int reqNo = NumberUtils.toInt((String) request.getProperty(REQ_NO), 0); try { final JSONObject panelJSON = getPanelData(present, absent, rejected, withMatchCount, offset, limit); panelJSON.put(REQ_NO, reqNo); panelJSON.put(OFFSET_LABEL, offset); return Response.ok(panelJSON, MediaType.APPLICATION_JSON_TYPE).build(); } catch (final ExecutionException e) { this.slf4Jlogger.warn("No content associated with [present-term: {}, absent-term: {}].", present, absent); return Response.status(Response.Status.NO_CONTENT).build(); } catch (final IndexOutOfBoundsException e) { this.slf4Jlogger.error("The requested [{}: {}] is out of bounds.", OFFSET_LABEL, offset); return Response.status(Response.Status.BAD_REQUEST).build(); } catch (final Exception e) { this.slf4Jlogger.error("Unexpected exception while generating gene panel JSON: {}", e.getMessage()); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } } }
DefaultGenePanelsLiveTableResourceImpl extends XWikiResource implements GenePanelsLiveTableResource { @Override public Response getGeneCountsFromPhenotypes() { final Request request = this.container.getRequest(); final Set<String> present = extractTerms("present-term", request); final Set<String> absent = extractTerms("absent-term", request); final Set<String> rejected = extractTerms("rejected-gene", request); final boolean withMatchCount = Boolean.parseBoolean((String) request.getProperty("with-match-count")); if (CollectionUtils.isEmpty(present) && CollectionUtils.isEmpty(absent)) { this.slf4Jlogger.error("No content provided."); return Response.status(Response.Status.NO_CONTENT).build(); } final int offset = NumberUtils.toInt((String) request.getProperty(OFFSET_LABEL), 1); final int limit = NumberUtils.toInt((String) request.getProperty(LIMIT_LABEL), -1); final int reqNo = NumberUtils.toInt((String) request.getProperty(REQ_NO), 0); try { final JSONObject panelJSON = getPanelData(present, absent, rejected, withMatchCount, offset, limit); panelJSON.put(REQ_NO, reqNo); panelJSON.put(OFFSET_LABEL, offset); return Response.ok(panelJSON, MediaType.APPLICATION_JSON_TYPE).build(); } catch (final ExecutionException e) { this.slf4Jlogger.warn("No content associated with [present-term: {}, absent-term: {}].", present, absent); return Response.status(Response.Status.NO_CONTENT).build(); } catch (final IndexOutOfBoundsException e) { this.slf4Jlogger.error("The requested [{}: {}] is out of bounds.", OFFSET_LABEL, offset); return Response.status(Response.Status.BAD_REQUEST).build(); } catch (final Exception e) { this.slf4Jlogger.error("Unexpected exception while generating gene panel JSON: {}", e.getMessage()); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } }  }
DefaultGenePanelsLiveTableResourceImpl extends XWikiResource implements GenePanelsLiveTableResource { @Override public Response getGeneCountsFromPhenotypes() { final Request request = this.container.getRequest(); final Set<String> present = extractTerms("present-term", request); final Set<String> absent = extractTerms("absent-term", request); final Set<String> rejected = extractTerms("rejected-gene", request); final boolean withMatchCount = Boolean.parseBoolean((String) request.getProperty("with-match-count")); if (CollectionUtils.isEmpty(present) && CollectionUtils.isEmpty(absent)) { this.slf4Jlogger.error("No content provided."); return Response.status(Response.Status.NO_CONTENT).build(); } final int offset = NumberUtils.toInt((String) request.getProperty(OFFSET_LABEL), 1); final int limit = NumberUtils.toInt((String) request.getProperty(LIMIT_LABEL), -1); final int reqNo = NumberUtils.toInt((String) request.getProperty(REQ_NO), 0); try { final JSONObject panelJSON = getPanelData(present, absent, rejected, withMatchCount, offset, limit); panelJSON.put(REQ_NO, reqNo); panelJSON.put(OFFSET_LABEL, offset); return Response.ok(panelJSON, MediaType.APPLICATION_JSON_TYPE).build(); } catch (final ExecutionException e) { this.slf4Jlogger.warn("No content associated with [present-term: {}, absent-term: {}].", present, absent); return Response.status(Response.Status.NO_CONTENT).build(); } catch (final IndexOutOfBoundsException e) { this.slf4Jlogger.error("The requested [{}: {}] is out of bounds.", OFFSET_LABEL, offset); return Response.status(Response.Status.BAD_REQUEST).build(); } catch (final Exception e) { this.slf4Jlogger.error("Unexpected exception while generating gene panel JSON: {}", e.getMessage()); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } }  @Override Response getGeneCountsFromPhenotypes(); }
DefaultGenePanelsLiveTableResourceImpl extends XWikiResource implements GenePanelsLiveTableResource { @Override public Response getGeneCountsFromPhenotypes() { final Request request = this.container.getRequest(); final Set<String> present = extractTerms("present-term", request); final Set<String> absent = extractTerms("absent-term", request); final Set<String> rejected = extractTerms("rejected-gene", request); final boolean withMatchCount = Boolean.parseBoolean((String) request.getProperty("with-match-count")); if (CollectionUtils.isEmpty(present) && CollectionUtils.isEmpty(absent)) { this.slf4Jlogger.error("No content provided."); return Response.status(Response.Status.NO_CONTENT).build(); } final int offset = NumberUtils.toInt((String) request.getProperty(OFFSET_LABEL), 1); final int limit = NumberUtils.toInt((String) request.getProperty(LIMIT_LABEL), -1); final int reqNo = NumberUtils.toInt((String) request.getProperty(REQ_NO), 0); try { final JSONObject panelJSON = getPanelData(present, absent, rejected, withMatchCount, offset, limit); panelJSON.put(REQ_NO, reqNo); panelJSON.put(OFFSET_LABEL, offset); return Response.ok(panelJSON, MediaType.APPLICATION_JSON_TYPE).build(); } catch (final ExecutionException e) { this.slf4Jlogger.warn("No content associated with [present-term: {}, absent-term: {}].", present, absent); return Response.status(Response.Status.NO_CONTENT).build(); } catch (final IndexOutOfBoundsException e) { this.slf4Jlogger.error("The requested [{}: {}] is out of bounds.", OFFSET_LABEL, offset); return Response.status(Response.Status.BAD_REQUEST).build(); } catch (final Exception e) { this.slf4Jlogger.error("Unexpected exception while generating gene panel JSON: {}", e.getMessage()); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } }  @Override Response getGeneCountsFromPhenotypes();  }