1 package org.iotivity.cloud.base;
3 import java.net.InetSocketAddress;
5 import org.iotivity.cloud.base.SessionManagerTest.CoapClientHandler;
6 import org.iotivity.cloud.base.protocols.coap.CoapRequest;
7 import org.iotivity.cloud.base.protocols.coap.enums.CoapMethod;
10 import io.netty.channel.ChannelHandlerContext;
12 public class ResourceManagerTest {
14 private static class SampleResource extends Resource {
16 public SampleResource() {
21 public void onRequestReceived(ChannelHandlerContext ctx,
22 CoapRequest request) {
23 // TODO Auto-generated method stub
28 public void testChannelRead0ChannelHandlerContextCoapRequest()
31 ResourceManager resourceManager = new ResourceManager();
33 resourceManager.registerResource(new SampleResource());
35 CoapServer coapServer = new CoapServer();
36 CoapClient coapClient = new CoapClient();
37 CoapClientHandler coapClientHandler = new CoapClientHandler();
38 coapServer.startServer(new InetSocketAddress(5683));
39 coapClient.addHandler(coapClientHandler);
40 coapClient.startClient(new InetSocketAddress("127.0.0.1", 5683));
42 CoapRequest request = new CoapRequest(CoapMethod.GET);
43 request.setUriPath("sampleUri");
45 resourceManager.channelRead0(coapClientHandler.connectCtx, request);
47 coapClient.stopClient();
48 coapServer.stopServer();
52 public void testRegisterResource() {
53 ResourceManager resourceManager = new ResourceManager();
55 resourceManager.registerResource(new SampleResource());
59 public void testUnregisterResource() {
60 SampleResource sampleResource = new SampleResource();
61 ResourceManager resourceManager = new ResourceManager();
63 resourceManager.registerResource(sampleResource);
64 resourceManager.unregisterResource(sampleResource);