/* (non-Javadoc) * @see org.springframework.jdbc.core.RowMapper#mapRow(java.sql.ResultSet, int) */ @Override public Event mapRow(ResultSet rs, int rowNum) throws SQLException { Event event = new Event(); event.setPersistedId(rs.getLong("ID")); event.setTimestamp(rs.getTimestamp("EI_TIMESTAMP")); event.setEventType(EventTypeEnum.valueOf(rs.getString("EI_EVENT_TYPE"))); Originator originator = new Originator(); originator.setProcessId(rs.getString("ORIG_PROCESS_ID")); originator.setIp(rs.getString("ORIG_IP")); originator.setHostname(rs.getString("ORIG_HOSTNAME")); originator.setCustomId(rs.getString("ORIG_CUSTOM_ID")); originator.setPrincipal(rs.getString("ORIG_PRINCIPAL")); event.setOriginator(originator); MessageInfo messageInfo = new MessageInfo(); messageInfo.setMessageId(rs.getString("MI_MESSAGE_ID")); messageInfo.setFlowId(rs.getString("MI_FLOW_ID")); messageInfo.setPortType(rs.getString("MI_PORT_TYPE")); messageInfo.setOperationName(rs.getString("MI_OPERATION_NAME")); messageInfo.setTransportType(rs.getString("MI_TRANSPORT_TYPE")); event.setMessageInfo(messageInfo); event.setContentCut(rs.getBoolean("CONTENT_CUT")); try { event.setContent(IOUtils.toString(rs.getClob("MESSAGE_CONTENT").getAsciiStream())); } catch (IOException e) { throw new RuntimeException("Error reading content", e); } return event; }
@Test public void testPing() throws Exception { WebClient client = WebClient.create(endpointUrl + "/hello/echo/SierraTangoNevada"); Response r = client.accept("text/plain").get(); assertEquals(Response.Status.OK.getStatusCode(), r.getStatus()); String value = IOUtils.toString((InputStream) r.getEntity()); assertEquals("SierraTangoNevada", value); }
private String readUrl(String address) { String content = null; try { URL url = new URL(address); assertNotNull(url.getContent()); content = IOUtils.toString((InputStream) url.getContent()); } catch (IOException e) { e.printStackTrace(System.err); Assert.fail("Couldn't read URL: " + e.getMessage()); } return content; }
@Test public void testPostRead() throws Exception { String dataConnectorReadUrl = environment.getProperty("ref_postgres_data_connector_read_url"); String analyticReadDataRequestJSON = IOUtils.toString( getClass().getClassLoader().getResourceAsStream("analytic-read-data-request.json")); ResponseEntity<String> response = postRequestWithJsonPayload(dataConnectorReadUrl, analyticReadDataRequestJSON); assertEquals(HttpStatus.OK, response.getStatusCode()); String expectedAnalyticReadDataResponseString = IOUtils.toString( getClass() .getClassLoader() .getResourceAsStream("expected-analytic-read-data-response.json")); String actualAnalyticReadDataResponseString = response.getBody(); JSONAssert.assertEquals( expectedAnalyticReadDataResponseString, actualAnalyticReadDataResponseString, JSONCompareMode.LENIENT); }
@Test public void testUpdateResource() { final String KEY_STRING = "stringAtt"; final String KEY_DATE = "dateAtt"; final Date origDate = new Date(); final String origString = "OrigStringValue"; Long rid; createDefaultCategory(); { RESTStoredData storedData = new RESTStoredData(); storedData.setData("we wish you a merry xmas and a happy new year"); List<ShortAttribute> attrList = new ArrayList<ShortAttribute>(); attrList.add(new ShortAttribute("string1", "value1", DataType.STRING)); attrList.add(new ShortAttribute("string2", "value2", DataType.STRING)); attrList.add(new ShortAttribute("string3", "value3", DataType.STRING)); String timeid = Long.toString(System.currentTimeMillis()); RESTResource origResource = new RESTResource(); origResource.setCategory(new RESTCategory(DEFAULTCATEGORYNAME)); origResource.setName("rest_test_resource_" + timeid); origResource.setStore(storedData); origResource.setAttribute(attrList); rid = client.insert(origResource); } System.out.println("RESOURCE has ID " + rid); // test getResource String name1 = "rest_test_resource_" + Long.toString(System.currentTimeMillis()); { RESTResource updResource = new RESTResource(); updResource.setName(name1); List<ShortAttribute> attrList = new ArrayList<ShortAttribute>(); attrList.add(new ShortAttribute("string1", "value1", DataType.STRING)); // same attrList.add(new ShortAttribute("string2", "value2.2", DataType.STRING)); // updated // attrList.add(new ShortAttribute("string3", "value3", DataType.STRING)); //removed attrList.add(new ShortAttribute("string4", "value4", DataType.STRING)); // added updResource.setAttribute(attrList); client.updateResource(rid, updResource); } { Resource loaded = client.getResource(rid); System.out.println("RESOURCE: " + loaded); // test reloaded attrs List<Attribute> loadedAttrs = loaded.getAttribute(); assertEquals(3, loadedAttrs.size()); Map<String, String> attMap = new HashMap<String, String>(); for (Attribute attribute : loadedAttrs) { attMap.put(attribute.getName(), attribute.getTextValue()); } assertEquals("value1", attMap.get("string1")); assertEquals("value2.2", attMap.get("string2")); assertEquals("value4", attMap.get("string4")); } // try bad update { RESTResource res = new RESTResource(); res.setCategory(new RESTCategory("TestCategory2")); try { client.updateResource(rid, res); fail("Undetected error"); } catch (UniformInterfaceException e) { String response = "COULD NOT READ RESPONSE"; try { response = IOUtils.toString(e.getResponse().getEntityInputStream()); } catch (Exception e2) { LOGGER.warn("Error reading response: " + e2.getMessage()); } LOGGER.info("Error condition successfully detected: " + response); } catch (Exception e) { LOGGER.info("Error condition successfully detected:" + e.getMessage(), e); } } client.deleteResource(rid); }
private String getStringFromInputStream(InputStream in) throws Exception { return IOUtils.toString(in); }