WebPositionResource extends AbstractWebPositionResource { @GET @Produces(MediaType.APPLICATION_JSON) public String getJSON() { FlexiBean out = createRootData(); return getFreemarker().build(JSON_DIR + "position.ftl", out); } WebPositionResource(final AbstractWebPositionResource parent); @GET @Produces(MediaType.TEXT_HTML) String getHTML(); @GET @Produces(MediaType.APPLICATION_JSON) String getJSON(); @PUT @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Produces(MediaType.TEXT_HTML) Response putHTML(@FormParam(POSITION_XML) String positionXml); @PUT @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Produces(MediaType.APPLICATION_JSON) Response putJSON(@FormParam("quantity") String quantityStr, 
      @FormParam("tradesJson") String tradesJson, 
      @FormParam("type") String type, 
      @FormParam(POSITION_XML) String positionXml); @DELETE @Produces(MediaType.TEXT_HTML) Response deleteHTML(); @DELETE @Produces(MediaType.APPLICATION_JSON) Response deleteJSON(); @Path("versions") WebPositionVersionsResource findVersions(); static URI uri(final WebPositionsData data); static URI uri(final WebPositionsData data, final UniqueId overridePositionId);  }
@Test public void testGetPositionWithTrades() throws Exception { final ManageableTrade trade = new ManageableTrade(BigDecimal.valueOf(50), SEC_ID, LocalDate.parse("2011-12-07"), OffsetTime.of(LocalTime.of(15, 4), ZONE_OFFSET), COUNTER_PARTY); trade.setPremium(10.0); trade.setPremiumCurrency(Currency.USD); trade.setPremiumDate(LocalDate.parse("2011-12-08")); trade.setPremiumTime(OffsetTime.of(LocalTime.of(15, 4), ZONE_OFFSET)); final ManageablePosition manageablePosition = new ManageablePosition(trade.getQuantity(), SEC_ID); manageablePosition.addTrade(trade); final PositionDocument addedPos = _positionMaster.add(new PositionDocument(manageablePosition)); final WebPositionResource positionResource = _webPositionsResource.findPosition(addedPos.getUniqueId().toString()); final String json = positionResource.getJSON(); assertNotNull(json); assertJSONObjectEquals(loadJson("com/opengamma/web/position/position.txt"), new JSONObject(json)); }
@Test public void testGetPositionWithoutTrade() throws Exception { final ManageablePosition manageablePosition = new ManageablePosition(BigDecimal.valueOf(50), SEC_ID); final PositionDocument addedPos = _positionMaster.add(new PositionDocument(manageablePosition)); final WebPositionResource positionResource = _webPositionsResource.findPosition(addedPos.getUniqueId().toString()); final String json = positionResource.getJSON(); assertNotNull(json); assertJSONObjectEquals(loadJson("com/opengamma/web/position/positionWithoutTrades.txt"), new JSONObject(json)); }