use of com.serotonin.json.type.JsonTypeReader in project ma-core-public by infiniteautomation.
the class StoreLatestSnapshotTest method testThreeTwoReleaseVersion.
// @Test
public void testThreeTwoReleaseVersion() throws JsonException, IOException, HttpException {
// Setup json
json.put("upgradeVersionState", UpgradeVersionState.PRODUCTION);
json.put("currentVersionState", UpgradeVersionState.PRODUCTION);
jsonModules.put("core", "3.2.1");
jsonModules.put("mangoApi", "3.2.1");
String url = baseUrl + "/servlet/versionCheck";
HttpPost post = new HttpPost(url);
StringWriter stringWriter = new StringWriter();
new JsonWriter(JSON_CONTEXT, stringWriter).writeObject(json);
String requestData = stringWriter.toString();
post.setEntity(new StringEntity(requestData));
String responseData = HttpUtils4.getTextContent(getHttpClient(30000), post, 1);
JsonTypeReader jsonReader = new JsonTypeReader(responseData);
JsonValue response = jsonReader.read();
printResponse(response);
Assert.assertNull(response.getJsonValue("versionState"));
// Assert newInstalls-oldCore should be empty
Assert.assertNotNull(response.getJsonValue("newInstalls-oldCore"));
JsonArray newInstallsOldCore = response.getJsonValue("newInstalls-oldCore").toJsonArray();
Assert.assertEquals(true, newInstallsOldCore.size() == 0);
// Assert update-versionState
Assert.assertNull(response.getJsonValue("update-versionState"));
// Assert updates for this core iff major upgrade available
Assert.assertNotNull(response.getJsonValue("updates"));
JsonArray updates = response.getJsonValue("updates").toJsonArray();
Assert.assertEquals(true, updates.size() == 0);
// Assert upgrades
Assert.assertNotNull(response.getJsonValue("upgrades"));
JsonArray upgrades = response.getJsonValue("upgrades").toJsonArray();
Assert.assertEquals(true, upgrades.size() == 1);
Assert.assertEquals(true, upgrades.get(0).getJsonValue("name").toString().equals("mangoApi"));
Assert.assertEquals(true, upgrades.get(0).getJsonValue("fullVersion").toString().equals("3.2.2"));
// Assert newInstalls should be for latest production core
Assert.assertNotNull(response.getJsonValue("newInstalls"));
JsonArray newInstalls = response.getJsonValue("newInstalls").toJsonArray();
Assert.assertEquals(true, newInstalls.size() > 0);
for (JsonValue install : newInstalls) {
Assert.assertEquals(true, install.getJsonValue("fullVersion").toString().startsWith(latestProductionCorePrefix));
}
}
use of com.serotonin.json.type.JsonTypeReader in project ma-core-public by infiniteautomation.
the class StreamTest method main.
public static void main(String[] args) throws Exception {
StringWriter out = new StringWriter();
JsonStreamWriter w = new JsonStreamWriter(out);
w.startObject();
{
w.writeObjectString("command", "echo");
w.startObjectArray("parameters");
{
w.writeArrayNull();
w.writeArrayNumber(123);
w.writeArrayString("str");
w.writeArrayBoolean(true);
w.startArrayObject();
{
w.writeObjectString("nullStr", null);
w.writeObjectString("quote", "\"'\t");
}
w.endObject();
}
w.endArray();
}
w.endObject();
System.out.println(out);
String s = "{\"id\":\"1234\",\"result\":{\"node\":{\"path\":\"/DGBox/Data Sources/Anders\",\"name\":\"Anders\",\"hasChildren\":true,\"icon\":\"../../../modules/modbus/web/modbusIcon.png\"},\"node\":{\"path\":\"/DGBox/Data Sources/bnip\",\"name\":\"bnip\",\"hasChildren\":true,\"icon\":\"../../../modules/BACnet/web/bacnetIcon.png\"},\"node\":{\"path\":\"/DGBox/Data Sources/bnmstp\",\"name\":\"bnmstp\",\"hasChildren\":false,\"icon\":\"../../../modules/BACnet/web/bacnetIcon.png\"},\"node\":{\"path\":\"/DGBox/Data Sources/Calculations\",\"name\":\"Calculations\",\"hasChildren\":true,\"icon\":\"../../../images/icon_ds.png\"},\"node\":{\"path\":\"/DGBox/Data Sources/Cylon test\",\"name\":\"Cylon test\",\"hasChildren\":true,\"icon\":\"../../../modules/BACnet/web/bacnetIcon.png\"},\"node\":{\"path\":\"/DGBox/Data Sources/Discover test\",\"name\":\"Discover test\",\"hasChildren\":true,\"icon\":\"../../../modules/modbus/web/modbusIcon.png\"},\"node\":{\"path\":\"/DGBox/Data Sources/EnOcean 315\",\"name\":\"EnOcean 315\",\"hasChildren\":true,\"icon\":\"../../../modules/enocean/web/enoceanIcon.png\"},\"node\":{\"path\":\"/DGBox/Data Sources/EnOcean 902\",\"name\":\"EnOcean 902\",\"hasChildren\":true,\"icon\":\"../../../modules/enocean/web/enoceanIcon.png\"},\"node\":{\"path\":\"/DGBox/Data Sources/House lights\",\"name\":\"House lights\",\"hasChildren\":true,\"icon\":\"../../../images/icon_ds.png\"},\"node\":{\"path\":\"/DGBox/Data Sources/http\",\"name\":\"http\",\"hasChildren\":true,\"icon\":\"../../../modules/http/web/httpIcon.png\"},\"node\":{\"path\":\"/DGBox/Data Sources/Insteon\",\"name\":\"Insteon\",\"hasChildren\":true,\"icon\":\"../../../modules/insteon/web/insteon_5.png\"},\"node\":{\"path\":\"/DGBox/Data Sources/Internal\",\"name\":\"Internal\",\"hasChildren\":true,\"icon\":\"../../../images/icon_ds.png\"},\"node\":{\"path\":\"/DGBox/Data Sources/KNX\",\"name\":\"KNX\",\"hasChildren\":true,\"icon\":\"../../../modules/knx/web/knx.png\"},\"node\":{\"path\":\"/DGBox/Data Sources/MatthewWS\",\"name\":\"MatthewWS\",\"hasChildren\":true,\"icon\":\"../../../images/icon_ds.png\"},\"node\":{\"path\":\"/DGBox/Data Sources/Maverick\",\"name\":\"Maverick\",\"hasChildren\":true,\"icon\":\"../../../modules/mamac/web/mamacIcon.png\"},\"node\":{\"path\":\"/DGBox/Data Sources/mbus test\",\"name\":\"mbus test\",\"hasChildren\":true,\"icon\":\"../../../modules/mbus/web/mbusIcon.png\"},\"node\":{\"path\":\"/DGBox/Data Sources/Modbus Serial\",\"name\":\"Modbus Serial\",\"hasChildren\":true,\"icon\":\"../../../modules/modbus/web/modbusIcon.png\"},\"node\":{\"path\":\"/DGBox/Data Sources/OPC\",\"name\":\"OPC\",\"hasChildren\":true,\"icon\":\"../../../modules/opcda/web/opcIcon.png\"},\"node\":{\"path\":\"/DGBox/Data Sources/Set test\",\"name\":\"Set test\",\"hasChildren\":true,\"icon\":\"../../../modules/BACnet/web/bacnetIcon.png\"},\"node\":{\"path\":\"/DGBox/Data Sources/SNMP\",\"name\":\"SNMP\",\"hasChildren\":true,\"icon\":\"../../../modules/snmp/web/snmpIcon.png\"},\"node\":{\"path\":\"/DGBox/Data Sources/SQL\",\"name\":\"SQL\",\"hasChildren\":true,\"icon\":\"../../../modules/sqlds/web/sqlIcon.png\"},\"node\":{\"path\":\"/DGBox/Data Sources/test\",\"name\":\"test\",\"hasChildren\":true,\"icon\":\"../../../modules/mamac/web/mamacIcon.png\"},\"node\":{\"path\":\"/DGBox/Data Sources/virt test\",\"name\":\"virt test\",\"hasChildren\":true,\"icon\":\"../../../images/icon_ds.png\"},\"node\":{\"path\":\"/DGBox/Data Sources/Virtual\",\"name\":\"Virtual\",\"hasChildren\":true,\"icon\":\"../../../images/icon_ds.png\"}}}";
System.out.println(new JsonTypeReader(s).read());
}
use of com.serotonin.json.type.JsonTypeReader in project ma-core-public by infiniteautomation.
the class LengthTest method main.
public static void main(String[] args) throws Exception {
String data = "{\"bigDecimal\":1.1,\"bigInteger\":2,\"boolean1\":false,\"byte1\":-4,\"double1\":5,\"float1\":6.1,\"int1\":7,\"long1\":-8,\"short1\":9,\"string1\":\"i'm a read string\"}";
System.out.println(data.length());
new JsonTypeReader(new StringReader(data), -1).read();
new JsonTypeReader(new StringReader(data), 150).read();
new JsonTypeReader(new StringReader(data), 149).read();
new JsonTypeReader(new StringReader(data), 148).read();
new JsonTypeReader(new StringReader(data), 147).read();
new JsonTypeReader(new StringReader(data), 146).read();
new JsonTypeReader(new StringReader(data), 100).read();
}
use of com.serotonin.json.type.JsonTypeReader in project ma-core-public by infiniteautomation.
the class EventDetectorRowMapper method mapRow.
/* (non-Javadoc)
* @see org.springframework.jdbc.core.RowMapper#mapRow(java.sql.ResultSet, int)
*/
@Override
public AbstractEventDetectorVO<?> mapRow(ResultSet rs, int rowNum) throws SQLException {
EventDetectorDefinition<?> definition = ModuleRegistry.getEventDetectorDefinition(rs.getString(this.firstColumn + 3));
if (definition == null)
throw new ShouldNeverHappenException("Event Detector defintion of type: " + rs.getString(this.firstColumn + 3) + " not found.");
AbstractEventDetectorVO<?> vo = definition.baseCreateEventDetectorVO();
vo.setId(rs.getInt(this.firstColumn));
vo.setXid(rs.getString(this.firstColumn + 1));
vo.setDefinition(definition);
// Extract the source id
int sourceIdColumnIndex;
if (this.sourceIdColumnOffset < 0)
sourceIdColumnIndex = this.firstColumn + 5 + EventDetectorDao.instance.getSourceIdIndex(definition.getSourceTypeName());
else
sourceIdColumnIndex = this.firstColumn + this.sourceIdColumnOffset;
vo.setSourceId(rs.getInt(sourceIdColumnIndex));
// Read Into Detector
JsonTypeReader typeReader = new JsonTypeReader(rs.getString(this.firstColumn + 4));
try {
JsonValue value = typeReader.read();
JsonObject root = value.toJsonObject();
JsonReader reader = new JsonReader(Common.JSON_CONTEXT, root);
root.remove("handlers");
reader.readInto(vo);
} catch (ClassCastException | IOException | JsonException e) {
LOG.error(e.getMessage(), e);
}
return vo;
}
Aggregations