/******************************************************************************* | |
* Copyright (c) 2013 IBM Corp. | |
* | |
* All rights reserved. This program and the accompanying materials | |
* are made available under the terms of the Eclipse Public License v1.0 | |
* and Eclipse Distribution License v1.0 which accompany this distribution. | |
* | |
* The Eclipse Public License is available at | |
* http://www.eclipse.org/legal/epl-v10.html | |
* and the Eclipse Distribution License is available at | |
* http://www.eclipse.org/org/documents/edl-v10.php. | |
* | |
* Contributors: | |
* Takahiro Inaba - initial API and implementation and/or initial | |
* documentation | |
*******************************************************************************/ | |
package com.ibm.jmeter.protocol.mqtt; | |
import java.util.ArrayList; | |
import java.util.List; | |
public class MockClient implements IMqttClient { | |
public boolean hadBeenConnected; | |
public boolean connected; | |
public int numOfPublish; | |
public List<String> givenTopicStrings = new ArrayList<String>(); | |
public List<MqttMessage> givenMessages = new ArrayList<MqttMessage>(); | |
public boolean failOnPublish; | |
public void connect() throws MqttException { | |
hadBeenConnected = true; | |
connected = true; | |
} | |
public boolean isConnected() { | |
return connected; | |
} | |
public void publish(String topicString, MqttMessage message) | |
throws MqttException { | |
givenTopicStrings.add(topicString); | |
givenMessages.add(message); | |
numOfPublish++; | |
if (failOnPublish) { | |
throw new MqttException("TEST"); | |
} | |
} | |
public void close() throws MqttException { | |
if (!connected) { | |
throw new MqttException("Client is closed."); | |
} | |
connected = false; | |
} | |
public String getClientId() { | |
return "DEFAULT_CLIENT_ID"; | |
} | |
} |