@Test public void testDecodeWithData() throws IOException { JacksonJsonSupport jsonSupport = new JacksonJsonSupport(new Configuration()); jsonSupport.addEventMapping("edwald", HashMap.class, Integer.class, String.class); Decoder decoder = new Decoder(jsonSupport, ackManager); Packet packet = decoder.decodePacket("5:::{\"name\":\"edwald\",\"args\":[{\"a\": \"b\"},2,\"3\"]}", null); Assert.assertEquals(PacketType.EVENT, packet.getType()); Assert.assertEquals("edwald", packet.getName()); Assert.assertEquals(3, packet.getArgs().size()); Map obj = (Map) packet.getArgs().get(0); Assert.assertEquals("b", obj.get("a")); Assert.assertEquals(2, packet.getArgs().get(1)); Assert.assertEquals("3", packet.getArgs().get(2)); }
/* * Cria uma nova Tarefa. * Retorna true se foi criada com sucesso false caso contrário */ public boolean newTask(String type, Packet objects) { if (type.equals("")) return false; lock.lock(); try { if (this.tasks.containsKey(type)) { return false; } else { HashMap<String, String> aux = objects.getArgs(); HashMap<String, Integer> objs = new HashMap<>(); for (Map.Entry<String, String> entry : aux.entrySet()) { objs.put(entry.getKey(), Integer.parseInt((entry.getValue()))); } Task t = new Task(type, objs, lock); this.tasks.put(type, t); return true; } } finally { lock.unlock(); } }