use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.
the class TestBinary method testSandBox.
@Test
public void testSandBox() {
NavajoFactory.getInstance().setSandboxMode(true);
Binary binaryx = new Binary(getClass().getResourceAsStream("binary1.txt"));
long l = binaryx.getLength();
Assert.assertEquals(7, l);
}
use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.
the class TestBinary method testBinaryDigest.
@Test
public void testBinaryDigest() {
Binary b1 = new Binary(getClass().getResourceAsStream("binary1.txt"));
Property p1 = NavajoFactory.getInstance().createProperty(null, "Binary", Property.BINARY_PROPERTY, "", 0, "", Property.DIR_IN);
Property p2 = NavajoFactory.getInstance().createProperty(null, "Binary2", Property.BINARY_PROPERTY, "", 0, "", Property.DIR_IN);
p1.setAnyValue(b1);
Assert.assertEquals(Property.BINARY_PROPERTY, p1.getType());
p2.setAnyValue(b1.getDigest());
Assert.assertEquals(Property.BINARY_DIGEST_PROPERTY, p2.getType());
}
use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.
the class NavajoDocumentTestFicture method setUp.
@Before
public void setUp() {
try {
testDoc = NavajoFactory.getInstance().createNavajo();
Message msg = NavajoFactory.getInstance().createMessage(testDoc, "testmessage");
Property prop = NavajoFactory.getInstance().createProperty(testDoc, "testprop1", "+", "", Property.DIR_IN);
msg.addProperty(prop);
Property prop2 = NavajoFactory.getInstance().createProperty(testDoc, "stringprop", Property.STRING_PROPERTY, "navajo", 10, "", Property.DIR_OUT);
msg.addProperty(prop2);
Property prop3 = NavajoFactory.getInstance().createProperty(testDoc, "integerprop", Property.INTEGER_PROPERTY, "2", 10, "", Property.DIR_OUT);
msg.addProperty(prop3);
Property prop4 = NavajoFactory.getInstance().createProperty(testDoc, "propfloat", Property.FLOAT_PROPERTY, "5.0", 10, "", Property.DIR_OUT);
msg.addProperty(prop4);
Property prop6 = NavajoFactory.getInstance().createProperty(testDoc, "selectietje", "1", "", "in");
prop6.addSelection(NavajoFactory.getInstance().createSelection(testDoc, "-", "-1", false));
msg.addProperty(prop6);
String binaryString = "ASSUMETHISISABINARY";
Binary b = new Binary(binaryString.getBytes());
Property prop7 = NavajoFactory.getInstance().createProperty(testDoc, "propbinary", Property.BINARY_PROPERTY, "", 10, "", Property.DIR_OUT);
prop7.setAnyValue(b);
msg.addProperty(prop7);
testDoc.addMessage(msg);
Message submsg1 = NavajoFactory.getInstance().createMessage(testDoc, "testmessage_sub1");
msg.addMessage(submsg1);
Message subsubmsg1 = NavajoFactory.getInstance().createMessage(testDoc, "testmessage_sub1_sub1");
submsg1.addMessage(subsubmsg1);
Property prop5 = NavajoFactory.getInstance().createProperty(testDoc, "proppie", Property.STRING_PROPERTY, "", 0, "", Property.DIR_INOUT);
subsubmsg1.addProperty(prop5);
Message subsubmsg2 = NavajoFactory.getInstance().createMessage(testDoc, "testmessage_sub1_sub2");
submsg1.addMessage(subsubmsg2);
Message subsubmsgje = NavajoFactory.getInstance().createMessage(testDoc, "testmessage_sub1_subje");
submsg1.addMessage(subsubmsgje);
Message subsubmsg3 = NavajoFactory.getInstance().createMessage(testDoc, "testmessage_sub1_sub3");
submsg1.addMessage(subsubmsg3);
Message submsg2 = NavajoFactory.getInstance().createMessage(testDoc, "testmessage_sub2");
msg.addMessage(submsg2);
Message sub2submsg1 = NavajoFactory.getInstance().createMessage(testDoc, "testmessage_sub2_sub1");
submsg2.addMessage(sub2submsg1);
Message sub2submsg2 = NavajoFactory.getInstance().createMessage(testDoc, "testmessage_sub2_sub2");
submsg2.addMessage(sub2submsg2);
Message sub2submsgje = NavajoFactory.getInstance().createMessage(testDoc, "testmessage_sub2_subje");
submsg2.addMessage(sub2submsgje);
Message sub2submsg3 = NavajoFactory.getInstance().createMessage(testDoc, "testmessage_sub2_sub3");
submsg2.addMessage(sub2submsg3);
Message submsg3 = NavajoFactory.getInstance().createMessage(testDoc, "testmessage_sub3");
msg.addMessage(submsg3);
Message msg2 = NavajoFactory.getInstance().createMessage(testDoc, "testmessage2");
testDoc.addMessage(msg2);
Message msg3 = NavajoFactory.getInstance().createMessage(testDoc, "testmessage3");
testDoc.addMessage(msg3);
} catch (Exception e) {
logger.error("Error: ", e);
}
}
use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.
the class TestProperty method tesSetAnyValue.
@Test
public void tesSetAnyValue() {
Navajo n = NavajoFactory.getInstance().createNavajo();
Property p1 = NavajoFactory.getInstance().createProperty(n, "Aap", "", "", "");
// String
p1.setAnyValue("Apenoot");
assertEquals("string", p1.getType());
assertEquals("Apenoot", p1.getValue());
assertTrue(p1.getTypedValue().equals("Apenoot"));
// Integer
p1.setAnyValue(Integer.valueOf(50));
assertEquals("integer", p1.getType());
assertEquals("50", p1.getValue());
assertTrue(p1.getTypedValue().equals(Integer.valueOf(50)));
// Double
p1.setAnyValue(Double.valueOf(50));
assertEquals("float", p1.getType());
assertEquals("50.0", p1.getValue());
assertTrue(p1.getTypedValue().equals(Double.valueOf(50)));
// Float
p1.setAnyValue(Float.valueOf(50));
assertEquals("float", p1.getType());
assertEquals("50.0", p1.getValue());
assertTrue(p1.getTypedValue().equals(Double.valueOf(50)));
// Date
Date d = new java.util.Date();
p1.setAnyValue(d);
String expectedFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SS").format(d);
assertEquals("date", p1.getType());
assertEquals(expectedFormat, p1.getValue());
assertTrue(p1.getTypedValue().equals(d));
// Long
p1.setAnyValue(Long.valueOf(10));
assertEquals("long", p1.getType());
assertEquals("10", p1.getValue());
assertTrue(p1.getTypedValue().equals(Long.valueOf(10)));
// Boolean
p1.setAnyValue(Boolean.TRUE);
assertEquals("boolean", p1.getType());
assertEquals("true", p1.getValue());
assertTrue(p1.getTypedValue().equals(Boolean.TRUE));
// Binary
Binary b = new Binary("Mooie array".getBytes());
p1.setAnyValue(b);
assertEquals("binary", p1.getType());
Binary b1 = (Binary) p1.getTypedValue();
String expected = new String(b1.getData());
assertEquals("Mooie array", expected);
// Money
p1.setAnyValue(new Money(5000));
assertEquals("money", p1.getType());
assertEquals("5000.00", p1.getValue());
assertTrue(p1.getTypedValue().equals(new Money(5000)));
// ClockTime
Date d1 = new java.util.Date();
ClockTime ct = new ClockTime(d1);
String expectedFormat2 = ct.toString();
p1.setAnyValue(ct);
assertEquals("clocktime", p1.getType());
assertEquals(expectedFormat2, p1.getValue());
assertTrue(p1.getTypedValue().equals(new ClockTime(d1)));
// StopwatchTime
Date d2 = new java.util.Date();
String format = new SimpleDateFormat("HH:mm:ss:SSS").format(d2);
StopwatchTime swt = new StopwatchTime(format);
p1.setAnyValue(swt);
assertEquals("stopwatchtime", p1.getType());
logger.info("FORM: {} val: {}", format, p1.getValue());
assertEquals(format, p1.getValue());
assertTrue(p1.getTypedValue().equals(new StopwatchTime(format)));
// Percentage
Percentage p = new Percentage(50);
p1.setAnyValue(p);
assertEquals("percentage", p1.getType());
assertEquals("50.0", p1.getValue());
assertTrue(p1.getTypedValue().equals(new Percentage(50)));
}
use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.
the class JDBCMap method getRecords.
/*
* (non-Javadoc)
*
* @see com.dexels.navajo.adapter.JDBCMappable#getRecords()
*/
@Override
public Binary getRecords() throws UserException {
ResultSet rs = null;
File tempFile;
try {
tempFile = File.createTempFile("sqlmap_records", "navajo");
} catch (IOException e1) {
throw new UserException("Temp file faillure", e1);
}
try (FileOutputStream fos = new FileOutputStream(tempFile);
OutputStreamWriter fw = new OutputStreamWriter(fos, StandardCharsets.UTF_8)) {
Binary b = null;
rs = getDBResultSet(false);
int columns = 0;
ResultSetMetaData meta = null;
try {
meta = rs.getMetaData();
columns = meta.getColumnCount();
if (this.showHeader) {
for (int j = 0; j < columns; j++) {
String column = meta.getColumnLabel(j + 1);
if (j == 0) {
fw.write(column);
} else {
fw.write(this.separator + column);
}
}
fw.write("\n");
}
} catch (Exception e) {
logger.error("Error writing output binary", e);
}
while (rs.next()) {
for (int j = 1; j <= columns; j++) {
String value = (rs.getObject(j) != null ? rs.getString(j) + "" : "");
if (j == 1) {
fw.write(value);
} else {
fw.write(this.separator + value);
}
}
fw.write("\n");
}
fw.flush();
b = new Binary(tempFile, false);
return b;
} catch (Exception ioe) {
throw new UserException(-1, ioe.getMessage(), ioe);
} finally {
if (rs != null) {
try {
rs.close();
rs = null;
resetAll();
} catch (SQLException e) {
logger.error("Error writing output binary", e);
}
}
if (tempFile != null) {
try {
Files.deleteIfExists(tempFile.toPath());
} catch (Exception ioe2) {
logger.error("Error writing output binary", ioe2);
}
}
}
}
Aggregations