Commit 24dbc06f authored by Björn Butzin's avatar Björn Butzin
Browse files

simplified plugtest project

added plugtest tests to general jCoAP automated tests
resolved ToDos
parent 8d2c40ab
......@@ -2,5 +2,4 @@
/log
/build.xml
/bin
/logref
*.class
/logref
\ No newline at end of file
This diff is collapsed.
#Organize Import Order
#Wed Apr 04 11:32:05 CDT 2007
4=javax
3=java
2=android
1=org
0=com
......@@ -3,3 +3,4 @@
/build.xml
/bin
/logref
/target/
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN"><!-- ALL | DEBUG | INFO | WARN | ERROR | FATAL | OFF: -->
<Configuration status="INFO"><!-- ALL | DEBUG | INFO | WARN | ERROR | FATAL | OFF: -->
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="WARN"><!-- ALL | DEBUG | INFO | WARN | ERROR | FATAL | OFF: -->
<Root level="INFO"><!-- ALL | DEBUG | INFO | WARN | ERROR | FATAL | OFF: -->
<AppenderRef ref="Console"/>
</Root>
</Loggers>
......
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/ws4d-jcoap"/>
<classpathentry kind="output" path="bin"/>
</classpath>
/**
* Server Application for Plugtest 2012, Paris, France
*
* Execute with argument Identifier (e.g., TD_COAP_CORE_01)
*/
package org.ws4d.coap.test;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.ws4d.coap.core.connection.BasicCoapChannelManager;
import org.ws4d.coap.core.connection.BasicCoapSocketHandler;
import org.ws4d.coap.core.rest.CoapResourceServer;
import org.ws4d.coap.test.resources.LongPathResource;
import org.ws4d.coap.test.resources.QueryResource;
import org.ws4d.coap.test.resources.TestResource;
/**
* @author Nico Laum <nico.laum@uni-rostock.de>
* @author Christian Lerche <christian.lerche@uni-rostock.de>
*
*/
public class CompletePlugtestServer {
private static CompletePlugtestServer plugtestServer;
private CoapResourceServer resourceServer;
private static Logger logger = Logger
.getLogger(BasicCoapSocketHandler.class.getName());
/**
* @param args
*/
public static void main(String[] args) {
logger.setLevel(Level.WARNING);
plugtestServer = new CompletePlugtestServer();
plugtestServer.start();
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
System.out.println("PlugtestServer is now stopping.");
System.out.println("===END===");
}
});
}
public void start() {
System.out.println("===Run Test Server ===");
init();
this.resourceServer.createResource(new TestResource());
this.resourceServer.createResource(new LongPathResource());
this.resourceServer.createResource(new QueryResource());
run();
}
private void init() {
BasicCoapChannelManager.getInstance().setMessageId(2000);
if (this.resourceServer != null)
this.resourceServer.stop();
this.resourceServer = new CoapResourceServer();
}
private void run() {
try {
this.resourceServer.start();
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* Client Application for Plugtest 2012, Paris, France
*
* Execute with argument Identifier (e.g., TD_COAP_CORE_01)
*/
package org.ws4d.coap.test;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.ws4d.coap.core.CoapClient;
import org.ws4d.coap.core.CoapConstants;
import org.ws4d.coap.core.connection.BasicCoapChannelManager;
import org.ws4d.coap.core.connection.BasicCoapSocketHandler;
import org.ws4d.coap.core.connection.api.CoapChannelManager;
import org.ws4d.coap.core.connection.api.CoapClientChannel;
import org.ws4d.coap.core.enumerations.CoapMediaType;
import org.ws4d.coap.core.enumerations.CoapRequestCode;
import org.ws4d.coap.core.messages.api.CoapRequest;
import org.ws4d.coap.core.messages.api.CoapResponse;
/**
* @author Nico Laum <nico.laum@uni-rostock.de>
* @author Christian Lerche <christian.lerche@uni-rostock.de>
* Client Application for Plugtest 2012, Paris, France Execute with argument
* Identifier (e.g., TD_COAP_CORE_01)
*
* @author Nico Laum
* @author Christian Lerche
*/
public class PlugtestClient implements CoapClient{
CoapChannelManager channelManager = null;
CoapClientChannel clientChannel = null;
HashMap<String, List<String> > serverList;
CoapRequest request = null;
private static Logger logger = Logger.getLogger(BasicCoapSocketHandler.class.getName());
boolean exitAfterResponse = true;
String serverAddress = null;
int serverPort = 0;
String filter = null;
public class PlugtestClient implements CoapClient {
private CoapChannelManager channelManager = null;
private CoapClientChannel clientChannel = null;
private CoapRequest request = null;
private String ip = null;
private int port = 0;
public static void main(String[] args) {
// if (args.length > 4 || args.length < 4) {
// System.err.println("illegal number of arguments");
// System.exit(1);
// }
logger.setLevel(Level.WARNING);
PlugtestClient client = new PlugtestClient();
//client.start(args[0], Integer.parseInt(args[1]), args[2], args[3]);
client.start("127.0.0.1", CoapConstants.COAP_DEFAULT_PORT, "TD_COAP_LINK_02", "");
}
public void start(String serverAddress, int serverPort, String testcase, String filter){
System.out.println("===START=== (Run Test Client: " + testcase + ")");
//String testId = testcase;
this.serverAddress = serverAddress;
this.serverPort = serverPort;
this.filter = filter;
this.serverList = new HashMap<>();
public void start(String serverAddress, int serverPort, String testcase, String filter) {
this.ip = serverAddress;
this.port = serverPort;
init(false, CoapRequestCode.GET);
this.request.setUriPath("/.well-known/core");
// request.setUriPath("/test");
System.out.println("QueryPath: " + this.request.getUriPath() );
/* if (testId.equals("TD_COAP_CORE_01")) {
System.out.println("QueryPath: " + this.request.getUriPath());
//reliable GET
if (testcase.equals("TD_COAP_CORE_01")) {
init(true, CoapRequestCode.GET);
request.setUriPath("/test");
}
else if (testId.equals("TD_COAP_CORE_02")) {
this.request.setUriPath("/test");
//reliable POST
} else if (testcase.equals("TD_COAP_CORE_02")) {
init(true, CoapRequestCode.POST);
request.setUriPath("/test");
request.setPayload("Content of new resource /test");
request.setContentType(CoapMediaType.text_plain);
}
else if (testId.equals("TD_COAP_CORE_03")) {
this.request.setUriPath("/test");
this.request.setPayload("Content of new resource /test");
this.request.setContentType(CoapMediaType.text_plain);
//reliable PUT
} else if (testcase.equals("TD_COAP_CORE_03")) {
init(true, CoapRequestCode.PUT);
request.setUriPath("/test");
request.setPayload("Content of new resource /test");
request.setContentType(CoapMediaType.text_plain);
}
else if (testId.equals("TD_COAP_CORE_04")) {
this.request.setUriPath("/test");
this.request.setPayload("Content of new resource /test");
this.request.setContentType(CoapMediaType.text_plain);
//reliable DELETE
} else if (testcase.equals("TD_COAP_CORE_04")) {
init(true, CoapRequestCode.DELETE);
request.setUriPath("/test");
}
else if (testId.equals("TD_COAP_CORE_05")) {
this.request.setUriPath("/test");
//UNreliable GET
} else if (testcase.equals("TD_COAP_CORE_05")) {
init(false, CoapRequestCode.GET);
request.setUriPath("/test");
}
else if (testId.equals("TD_COAP_CORE_06")) {
this.request.setUriPath("/test");
//UNreliable POST
} else if (testcase.equals("TD_COAP_CORE_06")) {
init(false, CoapRequestCode.POST);
request.setUriPath("/test");
request.setPayload("Content of new resource /test");
request.setContentType(CoapMediaType.text_plain);
}
else if (testId.equals("TD_COAP_CORE_07")) {
this.request.setUriPath("/test");
this.request.setPayload("Content of new resource /test");
this.request.setContentType(CoapMediaType.text_plain);
//UNreliable PUT
} else if (testcase.equals("TD_COAP_CORE_07")) {
init(false, CoapRequestCode.PUT);
request.setUriPath("/test");
request.setPayload("Content of new resource /test");
request.setContentType(CoapMediaType.text_plain);
}
else if (testId.equals("TD_COAP_CORE_08")) {
this.request.setUriPath("/test");
this.request.setPayload("Content of new resource /test");
this.request.setContentType(CoapMediaType.text_plain);
//UNreliable DELETE
} else if (testcase.equals("TD_COAP_CORE_08")) {
init(false, CoapRequestCode.DELETE);
request.setUriPath("/test");
}
else if (testId.equals("TD_COAP_CORE_09")) {
this.request.setUriPath("/test");
} else if (testcase.equals("TD_COAP_CORE_09")) {
init(true, CoapRequestCode.GET);
request.setUriPath("/separate");
}
else if (testId.equals("TD_COAP_CORE_10")) {
this.request.setUriPath("/separate");
} else if (testcase.equals("TD_COAP_CORE_10")) {
init(true, CoapRequestCode.GET);
request.setUriPath("/test");
request.setToken("AABBCCDD".getBytes());
}
else if (testId.equals("TD_COAP_CORE_11")) {
this.request.setUriPath("/test");
this.request.setToken("AABBCCDD".getBytes());
} else if (testcase.equals("TD_COAP_CORE_11")) {
init(true, CoapRequestCode.GET);
request.setUriPath("/test");
}
else if (testId.equals("TD_COAP_CORE_12")) {
this.request.setUriPath("/test");
} else if (testcase.equals("TD_COAP_CORE_12")) {
init(true, CoapRequestCode.GET);
request.setUriPath("/seg1/seg2/seg3");
}
else if (testId.equals("TD_COAP_CORE_13")) {
this.request.setUriPath("/seg1/seg2/seg3");
} else if (testcase.equals("TD_COAP_CORE_13")) {
init(true, CoapRequestCode.GET);
request.setUriPath("/query");
request.setUriQuery("first=1&second=2&third=3");
}
else if (testId.equals("TD_COAP_CORE_14")) {
this.request.setUriPath("/query");
this.request.setUriQuery("first=1&second=2&third=3");
} else if (testcase.equals("TD_COAP_CORE_14")) {
init(true, CoapRequestCode.GET);
request.setUriPath("/test");
}
else if (testId.equals("TD_COAP_CORE_15")) {
this.request.setUriPath("/test");
} else if (testcase.equals("TD_COAP_CORE_15")) {
init(true, CoapRequestCode.GET);
request.setUriPath("/separate");
}
else if (testId.equals("TD_COAP_CORE_16")) {jcoap-draft18/ws4d-jcoap-plugtest/src/org/ws4d/coap/test
this.request.setUriPath("/separate");
} else if (testcase.equals("TD_COAP_CORE_16")) { // jcoap-draft18/ws4d-jcoap-plugtest/src/org/ws4d/coap/test
init(false, CoapRequestCode.GET);
request.setUriPath("/separate");
}
else if (testId.equals("TD_COAP_LINK_01")) {
this.request.setUriPath("/separate");
} else if (testcase.equals("TD_COAP_LINK_01")) {
init(false, CoapRequestCode.GET);
request.setUriPath("/.well-known/core");
}
else if (testId.equals("TD_COAP_LINK_02")) {
this.request.setUriPath("/.well-known/core");
} else if (testcase.equals("TD_COAP_LINK_02")) {
init(false, CoapRequestCode.GET);
request.setUriPath("/.well-known/core");
request.setUriQuery("rt=" + this.filter);
}
else {
this.request.setUriPath("/.well-known/core");
this.request.setUriQuery("rt=" + filter);
} else {
System.out.println("===Failure=== (unknown test case)");
System.exit(-1);
} */
}
run();
}
public void init(boolean reliable, CoapRequestCode requestCode) {
this.channelManager = BasicCoapChannelManager.getInstance();
this.channelManager.setMessageId(1000);
try {
this.clientChannel = this.channelManager.connect(this, InetAddress.getByName(this.serverAddress), this.serverPort);
if (this.clientChannel == null){
this.clientChannel = this.channelManager.connect(this, InetAddress.getByName(this.ip), this.port);
if (this.clientChannel == null) {
System.out.println("Connect failed.");
System.exit(-1);
}
this.request = this.clientChannel.createRequest(reliable, requestCode);
} catch (UnknownHostException e) {
e.printStackTrace();
System.exit(-1);
......@@ -177,17 +158,15 @@ public class PlugtestClient implements CoapClient{
}
public void run() {
if(this.request.getPayload() != null){
System.out.println("Send Request: " + this.request.toString() + " (" + new String(this.request.getPayload()) +")");
}else {
if (this.request.getPayload() != null) {
System.out.println(
"Send Request: " + this.request.toString() + " (" + new String(this.request.getPayload()) + ")");
} else {
System.out.println("Send Request: " + this.request.toString());
}
this.clientChannel.sendMessage(this.request);
}
@Override
public void onConnectionFailed(CoapClientChannel channel, boolean notReachable, boolean resetByServer) {
System.out.println("Connection Failed");
......@@ -196,34 +175,16 @@ public class PlugtestClient implements CoapClient{
@Override
public void onResponse(CoapClientChannel channel, CoapResponse response) {
if (response.getPayload() != null){
System.out.println("Response: " + response.toString() + " (" + new String(response.getPayload()) +")");
if (response.getPayload() != null) {
System.out.println("Response: " + response.toString() + " (" + new String(response.getPayload()) + ")");
} else {
System.out.println("Response: " + response.toString());
}
if (this.exitAfterResponse){
System.out.println("===END===");
System.exit(0);
}
}
public class WaitAndExit implements Runnable
{
public void run()
{
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("===END===");
System.exit(0);
}
}
@Override
public void onMCResponse(CoapClientChannel channel, CoapResponse response, InetAddress srcAddress, int srcPort) {
System.out.println("Received Multicast Response");
}
}
\ No newline at end of file
......@@ -26,16 +26,14 @@ import org.ws4d.coap.core.messages.api.CoapResponse;
public class PlugtestSeparateResponseCoapServer implements CoapServer {
private static final int PORT = 5683;
static int counter = 0;
CoapResponse response = null;
CoapServerChannel channel = null;
int separateResponseTimeMs = 4000;
CoapServerChannel ch = null;
int responseTimeMs = 4000;
public void start(int separateResponseTimeMs) {
CoapChannelManager channelManager = BasicCoapChannelManager
.getInstance();
CoapChannelManager channelManager = BasicCoapChannelManager.getInstance();
channelManager.createServerListener(this, PORT);
this.separateResponseTimeMs = separateResponseTimeMs;
this.responseTimeMs = separateResponseTimeMs;
}
@Override
......@@ -48,22 +46,23 @@ public class PlugtestSeparateResponseCoapServer implements CoapServer {
public void onRequest(CoapServerChannel channel, CoapRequest request) {
System.out.println("Received message: " + request.toString());
this.channel = channel;
this.response = channel.createSeparateResponse(request,
CoapResponseCode.Content_205);
this.ch = channel;
this.response = channel.createSeparateResponse(request, CoapResponseCode.Content_205);
(new Thread(new SendDelayedResponse())).start();
}
public class SendDelayedResponse implements Runnable {
public void run() {
PlugtestSeparateResponseCoapServer.this.response.setContentType(CoapMediaType.text_plain);
PlugtestSeparateResponseCoapServer.this.response.setPayload("payload...".getBytes());
try {
Thread.sleep(PlugtestSeparateResponseCoapServer.this.separateResponseTimeMs);
Thread.sleep(PlugtestSeparateResponseCoapServer.this.responseTimeMs);
} catch (InterruptedException e) {
e.printStackTrace();
}
PlugtestSeparateResponseCoapServer.this.channel.sendSeparateResponse(PlugtestSeparateResponseCoapServer.this.response);
PlugtestSeparateResponseCoapServer.this.ch
.sendSeparateResponse(PlugtestSeparateResponseCoapServer.this.response);
System.out
.println("Send separate Response: " + PlugtestSeparateResponseCoapServer.this.response.toString());
}
......@@ -76,8 +75,6 @@ public class PlugtestSeparateResponseCoapServer implements CoapServer {
@Override
public void onReset(CoapRequest lastRequest) {
// TODO Auto-generated method stub
// empty
}
}
/**
* Server Application for Plugtest 2012, Paris, France
*
* Execute with argument Identifier (e.g., TD_COAP_CORE_01)
*/
package org.ws4d.coap.test;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.ws4d.coap.core.connection.BasicCoapChannelManager;
import org.ws4d.coap.core.connection.BasicCoapSocketHandler;
import org.ws4d.coap.core.rest.CoapResourceServer;
import org.ws4d.coap.test.resources.LongPathResource;
import org.ws4d.coap.test.resources.QueryResource;
import org.ws4d.coap.test.resources.TestResource;
/**
* @author Nico Laum <nico.laum@uni-rostock.de>
* @author Christian Lerche <christian.lerche@uni-rostock.de>
* Server Application for Plugtest 2012, Paris, France Execute with argument
* Identifier (e.g., TD_COAP_CORE_01)
*
* @author Nico Laum
* @author Christian Lerche
*/
public class PlugtestServer {
private static final int SEPARATE_RESPONSE_TIME_MS = 1000;
private static PlugtestServer plugtestServer;
private CoapResourceServer resourceServer;
private static Logger logger = Logger
.getLogger(BasicCoapSocketHandler.class.getName());
/**
* @param args
*/
public static void main(String[] args) {
if (args.length > 1 || args.length < 1) {
System.err.println("illegal number of arguments");
System.exit(1);
}
logger.setLevel(Level.WARNING);
plugtestServer = new PlugtestServer();
plugtestServer.start(args[0]);
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
System.out.println("PlugtestServer is now stopping.");
System.out.println("===END===");
}
});
}
public void start(String testId) {
System.out.println("===Run Test Server: " + testId + "===");
init();
if (testId.equals("TD_COAP_CORE_01")) {
this.resourceServer.createResource(new TestResource());
run();