@Test public void GSONControlMessageTest() throws Exception { ControlMessageType messageType = ControlMessageType.GET_ATTRIBUTES; SpaceCard spaceCard = new SpaceCard(); spaceCard.setSpaceID("id"); spaceCard.setDescription("descrizione"); spaceCard.setPeerCoordinatorID("coord{ }&)?id"); spaceCard.setPeeringChannel("canale"); spaceCard.setPeeringChannelName("nome canaèle"); spaceCard.setProfile("profilo"); spaceCard.setRetry(10); ChannelDescriptor chd = new ChannelDescriptor("1339517729177690537L", "nome!", "http: List<org.universAAL.middleware.interfaces.ChannelDescriptor> brokerChannels = new ArrayList<org.universAAL.middleware.interfaces.ChannelDescriptor>(); brokerChannels.add(chd); SpaceDescriptor spaceDescriptor = new SpaceDescriptor(spaceCard, brokerChannels); PeerCard deployManager = new PeerCard(PeerRole.PEER, "stringa1", "stringa2"); spaceDescriptor.setDeployManager(deployManager); String id = "stringa id"; String payload = "blablabla"; String parsed = null; ArrayList<String> attributes = new ArrayList<String>(); attributes.add("ciao"); HashMap<String, Serializable> filter = new HashMap<String, Serializable>(); filter.put("filtro1", "hello"); filter.put("filtro2", null); filter.put("filtro3", 3); filter.put("filtro4", "{}\\}\\{"); filter.put("filtro5", "\"ci/a\n\r\u9922o}"); HashMap<String, Serializable> values = new HashMap<String, Serializable>(); values.put("one", "hello"); values.put("system", null); values.put("sysversion", 3); values.put("O7S", "{}\\}\\{"); values.put("sysyuem", "\"ci/a\n\r\u9922o}"); boolean match = true; String TransactionID = "id transazione"; ControlMessage sorgente = new ControlMessage(spaceDescriptor, attributes); Gson gson = GsonParserBuilder.getInstance(); String serializedMessage = gson.toJson(sorgente); ControlMessage destinazione = gson.fromJson(serializedMessage, ControlMessage.class); assertEquals(sorgente.toString(), destinazione.toString()); }
public String toString() { String serializedMessage = null; if (parsed == null) { try { Gson gson = GsonParserBuilder.getInstance(); serializedMessage = gson.toJson(this); } catch (Exception e) { e.printStackTrace(); } } parsed = serializedMessage; return parsed; }
ControlMessage implements BrokerMessage { public String toString() { String serializedMessage = null; if (parsed == null) { try { Gson gson = GsonParserBuilder.getInstance(); serializedMessage = gson.toJson(this); } catch (Exception e) { e.printStackTrace(); } } parsed = serializedMessage; return parsed; } }
ControlMessage implements BrokerMessage { public String toString() { String serializedMessage = null; if (parsed == null) { try { Gson gson = GsonParserBuilder.getInstance(); serializedMessage = gson.toJson(this); } catch (Exception e) { e.printStackTrace(); } } parsed = serializedMessage; return parsed; } ControlMessage(SpaceDescriptor space, List<String> attributes);  ControlMessage(SpaceDescriptor space, ControlMessageType type);  ControlMessage();  ControlMessage(SpaceDescriptor space, Map<String, Serializable> filter);  ControlMessage(SpaceDescriptor space, String id, HashMap<String, Serializable> map);  ControlMessage(SpaceDescriptor space, String id, HashMap<String, Serializable> map, boolean match);  ControlMessage(SpaceDescriptor space, ControlMessageType type, String id); }
ControlMessage implements BrokerMessage { public String toString() { String serializedMessage = null; if (parsed == null) { try { Gson gson = GsonParserBuilder.getInstance(); serializedMessage = gson.toJson(this); } catch (Exception e) { e.printStackTrace(); } } parsed = serializedMessage; return parsed; } ControlMessage(SpaceDescriptor space, List<String> attributes);  ControlMessage(SpaceDescriptor space, ControlMessageType type);  ControlMessage();  ControlMessage(SpaceDescriptor space, Map<String, Serializable> filter);  ControlMessage(SpaceDescriptor space, String id, HashMap<String, Serializable> map);  ControlMessage(SpaceDescriptor space, String id, HashMap<String, Serializable> map, boolean match);  ControlMessage(SpaceDescriptor space, ControlMessageType type, String id); String toString(); boolean getMatchFilter(); ControlMessageType getMessageType(); static ControlMessage unmarshall(String message); String getTransactionId(); Map<String, Serializable> getAttributeFilter(); Map<String, Serializable> getAttributeValues(); BrokerMessageTypes getMType(); List<String> getAttributes(); PeerCard[] getReceivers(); }
ControlMessage implements BrokerMessage { public String toString() { String serializedMessage = null; if (parsed == null) { try { Gson gson = GsonParserBuilder.getInstance(); serializedMessage = gson.toJson(this); } catch (Exception e) { e.printStackTrace(); } } parsed = serializedMessage; return parsed; } ControlMessage(SpaceDescriptor space, List<String> attributes);  ControlMessage(SpaceDescriptor space, ControlMessageType type);  ControlMessage();  ControlMessage(SpaceDescriptor space, Map<String, Serializable> filter);  ControlMessage(SpaceDescriptor space, String id, HashMap<String, Serializable> map);  ControlMessage(SpaceDescriptor space, String id, HashMap<String, Serializable> map, boolean match);  ControlMessage(SpaceDescriptor space, ControlMessageType type, String id); String toString(); boolean getMatchFilter(); ControlMessageType getMessageType(); static ControlMessage unmarshall(String message); String getTransactionId(); Map<String, Serializable> getAttributeFilter(); Map<String, Serializable> getAttributeValues(); BrokerMessageTypes getMType(); List<String> getAttributes(); PeerCard[] getReceivers();  }