use of org.jose4j.json.internal.json_simple.JSONObject in project open-ecard by ecsec.
the class TestRealVersionUpdate method validVersionUpdate.
@Test(enabled = true)
public void validVersionUpdate() throws InvalidUpdateDefinition, MalformedURLException {
// Same values as the default values of the JSONObjectBuilder
String downloadPage = "http://www.google.de/downloadpage";
String downloadUrl = "http://www.google.de/downloadurl";
String version = "1.3.0";
String status = Status.MAINTAINED.name();
JSONObject obj = new JSONObjectBuilder().build();
VersionUpdate update = VersionUpdate.fromJson(obj);
Assert.assertEquals(update.getDownloadPage(), new URL(downloadPage));
Assert.assertEquals(update.getDownloadLink(), new URL(downloadUrl));
Assert.assertEquals(update.getVersion().compareTo(new SemanticVersion(version)), 0);
Assert.assertEquals(update.getStatus(), Status.valueOf(status));
VersionUpdate newerVersion = new VersionUpdate(new SemanticVersion("1.3.1"), new URL(downloadPage), new URL(downloadUrl), Status.MAINTAINED);
Assert.assertEquals(update.compareTo(newerVersion), -1);
Assert.assertEquals(newerVersion.compareTo(update), 1);
}
use of org.jose4j.json.internal.json_simple.JSONObject in project open-ecard by ecsec.
the class TestRealVersionUpdate method versionUpdateinvalidDownloadURL.
@Test(enabled = true)
public void versionUpdateinvalidDownloadURL() {
try {
String invalidDownloadURL = "test";
JSONObject obj = new JSONObjectBuilder().downloadUrl(invalidDownloadURL).build();
VersionUpdate update = VersionUpdate.fromJson(obj);
// Exception expected
Assert.fail();
} catch (InvalidUpdateDefinition ex) {
Assert.assertEquals(ex.getMessage(), "Incomplete JSON data received.");
}
}
use of org.jose4j.json.internal.json_simple.JSONObject in project light-example-4j by networknt.
the class GetAllTodosIT method testGetAllTodos.
@Test
public void testGetAllTodos() throws ClientException, ApiException {
final Http2Client client = Http2Client.getInstance();
final CountDownLatch latch = new CountDownLatch(1);
final ClientConnection connection;
try {
connection = client.connect(new URI(url), Http2Client.WORKER, Http2Client.SSL, Http2Client.BUFFER_POOL, enableHttp2 ? OptionMap.create(UndertowOptions.ENABLE_HTTP2, true) : OptionMap.EMPTY).get();
} catch (Exception e) {
throw new ClientException(e);
}
Map<String, Object> map = new HashMap<String, Object>();
map.put("host", "lightapi.net");
map.put("service", "todo");
map.put("action", "gettodos");
map.put("version", "0.1.0");
JSONObject json = new JSONObject();
json.putAll(map);
System.out.printf("JSON: %s", json.toString());
final AtomicReference<ClientResponse> reference = new AtomicReference<>();
try {
ClientRequest request = new ClientRequest().setPath("/api/json").setMethod(Methods.POST);
request.getRequestHeaders().put(Headers.CONTENT_TYPE, "application/json");
request.getRequestHeaders().put(Headers.TRANSFER_ENCODING, "chunked");
connection.sendRequest(request, client.createClientCallback(reference, latch, json.toString()));
latch.await();
} catch (Exception e) {
logger.error("Exception: ", e);
throw new ClientException(e);
} finally {
IoUtils.safeClose(connection);
}
int statusCode = reference.get().getResponseCode();
String body = reference.get().getAttachment(Http2Client.RESPONSE_BODY);
Assert.assertEquals(200, statusCode);
Assert.assertNotNull(body);
}
use of org.jose4j.json.internal.json_simple.JSONObject in project light-example-4j by networknt.
the class DeleteTodoIT method testDeleteTodo.
@Test
public void testDeleteTodo() throws ClientException, ApiException {
final Http2Client client = Http2Client.getInstance();
final CountDownLatch latch = new CountDownLatch(1);
final ClientConnection connection;
try {
connection = client.connect(new URI(url), Http2Client.WORKER, Http2Client.SSL, Http2Client.BUFFER_POOL, enableHttp2 ? OptionMap.create(UndertowOptions.ENABLE_HTTP2, true) : OptionMap.EMPTY).get();
} catch (Exception e) {
throw new ClientException(e);
}
Map<String, Object> map = new HashMap<String, Object>();
map.put("host", "lightapi.net");
map.put("service", "todo");
map.put("action", "delete");
map.put("version", "0.1.0");
Map<String, Object> data = new HashMap<>();
data.put("id", "101010");
map.put("data", data);
JSONObject json = new JSONObject();
json.putAll(map);
System.out.printf("JSON: %s", json.toString());
final AtomicReference<ClientResponse> reference = new AtomicReference<>();
try {
ClientRequest request = new ClientRequest().setPath("/api/json").setMethod(Methods.POST);
request.getRequestHeaders().put(Headers.CONTENT_TYPE, "application/json");
request.getRequestHeaders().put(Headers.TRANSFER_ENCODING, "chunked");
connection.sendRequest(request, client.createClientCallback(reference, latch, json.toString()));
latch.await();
} catch (Exception e) {
logger.error("Exception: ", e);
throw new ClientException(e);
} finally {
IoUtils.safeClose(connection);
}
int statusCode = reference.get().getResponseCode();
String body = reference.get().getAttachment(Http2Client.RESPONSE_BODY);
Assert.assertEquals(200, statusCode);
Assert.assertNotNull(body);
}
use of org.jose4j.json.internal.json_simple.JSONObject in project light-example-4j by networknt.
the class UpdateTodoIT method testUpdateTodo.
@Test
public void testUpdateTodo() throws ClientException, ApiException {
final Http2Client client = Http2Client.getInstance();
final CountDownLatch latch = new CountDownLatch(1);
final ClientConnection connection;
try {
connection = client.connect(new URI(url), Http2Client.WORKER, Http2Client.SSL, Http2Client.BUFFER_POOL, enableHttp2 ? OptionMap.create(UndertowOptions.ENABLE_HTTP2, true) : OptionMap.EMPTY).get();
} catch (Exception e) {
throw new ClientException(e);
}
Map<String, Object> map = new HashMap<String, Object>();
map.put("host", "lightapi.net");
map.put("service", "todo");
map.put("action", "update");
map.put("version", "0.1.0");
Map<String, Object> data = new HashMap<>();
data.put("id", "101010");
data.put("title", "create todo from hybrid service unit test");
data.put("completed", false);
data.put("order", 1);
map.put("data", data);
JSONObject json = new JSONObject();
json.putAll(map);
System.out.printf("JSON: %s", json.toString());
final AtomicReference<ClientResponse> reference = new AtomicReference<>();
try {
ClientRequest request = new ClientRequest().setPath("/api/json").setMethod(Methods.POST);
request.getRequestHeaders().put(Headers.CONTENT_TYPE, "application/json");
request.getRequestHeaders().put(Headers.TRANSFER_ENCODING, "chunked");
connection.sendRequest(request, client.createClientCallback(reference, latch, json.toString()));
latch.await();
} catch (Exception e) {
logger.error("Exception: ", e);
throw new ClientException(e);
} finally {
IoUtils.safeClose(connection);
}
int statusCode = reference.get().getResponseCode();
String body = reference.get().getAttachment(Http2Client.RESPONSE_BODY);
Assert.assertEquals(200, statusCode);
Assert.assertNotNull(body);
}
Aggregations