Esempio n. 1
0
  @Test
  public void testSubscribe() throws Exception {
    // fill the model with data
    SignalKModel model = SignalKModelFactory.getMotuTestInstance();
    model.putAll(TestHelper.getBasicModel().getFullData());

    // create STOMP connection
    StompConnection connection = new StompConnection();
    connection.open("localhost", 61613);
    logger.debug("Opened STOMP socket, connecting.. ");
    StompFrame connect = connection.connect("system", "manager");
    // StompFrame connect = connection.receive();
    if (!connect.getAction().equals(Stomp.Responses.CONNECTED)) {
      throw new Exception("Not connected");
    }
    logger.debug("connected" + connect.getHeaders());

    // create a private receive queue
    String uuid = UUID.randomUUID().toString();
    connection.subscribe(
        "/queue/signalk." + uuid + ".vessels.motu.navigation", Subscribe.AckModeValues.AUTO);

    // subscribe
    Json subMsg =
        getSubscribe(
            "vessels." + SignalKConstants.self, "navigation", 1000, 0, FORMAT_DELTA, POLICY_FIXED);
    subMsg.set(
        nz.co.fortytwo.signalk.util.ConfigConstants.OUTPUT_TYPE,
        nz.co.fortytwo.signalk.util.ConfigConstants.OUTPUT_STOMP);
    subMsg.set(WebsocketConstants.CONNECTION_KEY, uuid);
    HashMap<String, String> headers = new HashMap<String, String>();

    // queue>signalk.3202a939-1681-4a74-ad4b-3a90212e4f33.vessels.motu.navigation
    // set private queue to receive data
    headers.put("reply-to", "/queue/signalk." + uuid + ".vessels.motu.navigation");
    headers.put(WebsocketConstants.CONNECTION_KEY, uuid);
    connection.send("/queue/signalk.put", subMsg.toString(), null, headers);

    // listen for messages
    StompFrame message = connection.receive();
    logger.debug("Body: " + message.getBody());
    assertNotNull(message);
    Json reply = Json.read(message.getBody());

    assertNotNull(reply.at(SignalKConstants.CONTEXT));
    assertNotNull(reply.at(SignalKConstants.UPDATES));
    // unsubscribe
    subMsg =
        getSubscribe(
            "vessels." + SignalKConstants.self, "navigation", 1000, 0, FORMAT_DELTA, POLICY_FIXED);
    connection.send("/queue/signalk.subscribe", subMsg.toString(), null, headers);
    connection.unsubscribe("/queue/signalk." + uuid + ".vessels.motu.navigation");
    // disconnect
    connection.disconnect();
  }
Esempio n. 2
0
  @Test
  public void testSendingGetFull() throws Exception {
    // fill the model with data
    SignalKModel model = SignalKModelFactory.getMotuTestInstance();
    model.putAll(TestHelper.getBasicModel().getFullData());

    // create STOMP connection
    StompConnection connection = new StompConnection();
    connection.open("localhost", 61613);
    logger.debug("Opened STOMP socket, connecting.. ");
    StompFrame connect = connection.connect("system", "manager");
    // StompFrame connect = connection.receive();
    if (!connect.getAction().equals(Stomp.Responses.CONNECTED)) {
      throw new Exception("Not connected");
    }
    logger.debug("connected" + connect.getHeaders());

    // create a private receive queue
    String uuid = UUID.randomUUID().toString();
    connection.subscribe(
        "/queue/signalk." + uuid + "." + vessels_dot_self_dot + env_wind,
        Subscribe.AckModeValues.AUTO);
    latch.await(2, TimeUnit.SECONDS);
    // send list
    Json subMsg =
        getGet("vessels." + SignalKConstants.self, env_wind + ".*", SignalKConstants.FORMAT_FULL);
    HashMap<String, String> headers = new HashMap<String, String>();
    logger.debug("sending" + subMsg);
    // queue>signalk.3202a939-1681-4a74-ad4b-3a90212e4f33.vessels.motu.navigation
    // set private queue to receive data
    headers.put("reply-to", "/queue/signalk." + uuid + dot + vessels_dot_self_dot + env_wind);
    headers.put(WebsocketConstants.CONNECTION_KEY, uuid);
    connection.send("/queue/signalk.put", subMsg.toString(), null, headers);

    // listen for messages
    StompFrame message = connection.receive();
    logger.debug("Body: " + message.getBody());
    assertNotNull(message);
    Json reply = Json.read(message.getBody());

    assertNotNull(reply.at(SignalKConstants.vessels));
    assertNotNull(reply.at(SignalKConstants.vessels).at(SignalKConstants.self).at(env).at("wind"));
    // unsubscribe
    connection.unsubscribe("/queue/signalk." + uuid + "." + vessels_dot_self_dot + env_wind);
    // disconnect
    connection.disconnect();
  }