This repository has been archived by the owner on Aug 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 370
/
IXITest.java
95 lines (80 loc) · 3.04 KB
/
IXITest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package com.iota.iri;
import com.iota.iri.conf.Configuration;
import com.iota.iri.service.dto.AbstractResponse;
import com.iota.iri.service.dto.ErrorResponse;
import com.iota.iri.service.dto.IXIResponse;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
import static java.nio.file.StandardOpenOption.CREATE;
import static org.junit.Assert.*;
/**
* Created by paul on 1/4/17.
*/
public class IXITest {
static TemporaryFolder ixiDir = new TemporaryFolder();
static IXI ixi;
@BeforeClass
public static void setUp() throws Exception {
ixiDir.create();
ixi = new IXI();
ixi.init(ixiDir.getRoot().getAbsolutePath().toString());
}
@AfterClass
public static void tearDown() throws Exception {
ixi.shutdown();
ixiDir.delete();
}
@Test
public void init() throws Exception {
AbstractResponse response;
IXIResponse ixiResponse;
/*
final String testJs =
"var Callable = Java.type(\"com.iota.iri.service.CallableRequest\");\n" +
"print(\"hello world\");\n" +
"var IXIResponse = Java.type(\"com.iota.iri.service.dto.IXIResponse\");\n" +
"API.put(\"getParser\", new Callable({\n" +
"call: function(req) {\n" +
"var IntArray = Java.type(\"int[]\");\n" +
"var out = new IntArray(Math.floor(Math.random()*9)+1);\n" +
"out[0] = 2;\n" +
"var r = IXIResponse.create({\n" +
"myArray: out,\n" +
"name: \"Foo\"\n" +
"});\n" +
"return r;\n" +
"}\n" +
"}));";
final String testPackage = "{\"main\": \"index.js\"}";
ixiDir.newFolder("test");
try (OutputStream out = new BufferedOutputStream(
Files.newOutputStream(Paths.get(ixiDir.getRoot().toString(),"test", "index.js"), CREATE))) {
out.write(testJs.getBytes());
}
try (OutputStream out = new BufferedOutputStream(
Files.newOutputStream(Paths.get(ixiDir.getRoot().toString(),"test", "package.json"), CREATE))) {
out.write(testPackage.getBytes());
}
// Allow IXI to load the file
Map<String, Object> request = new HashMap<>();
Thread.sleep(1000);
response = IXI.instance().processCommand("test.getParser", request);
assertFalse(response instanceof ErrorResponse);
assertTrue(response instanceof IXIResponse);
ixiResponse = ((IXIResponse) response);
assertNotNull(ixiResponse.getResponse());
*/
}
@Test
public void processCommand() throws Exception {
}
}