Merge "Merge branch '1.1-rel'"
[platform/upstream/iotivity.git] / cloud / stack / src / test / java / org / iotivity / cloud / base / ResourceManagerTest.java
1 package org.iotivity.cloud.base;
2
3 import java.net.InetSocketAddress;
4
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;
8 import org.junit.Test;
9
10 import io.netty.channel.ChannelHandlerContext;
11
12 public class ResourceManagerTest {
13
14     private static class SampleResource extends Resource {
15
16         public SampleResource() {
17             setUri("sampleUri");
18         }
19
20         @Override
21         public void onRequestReceived(ChannelHandlerContext ctx,
22                 CoapRequest request) {
23             // TODO Auto-generated method stub
24         }
25     }
26
27     @Test
28     public void testChannelRead0ChannelHandlerContextCoapRequest()
29             throws Exception {
30
31         ResourceManager resourceManager = new ResourceManager();
32
33         resourceManager.registerResource(new SampleResource());
34
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));
41
42         CoapRequest request = new CoapRequest(CoapMethod.GET);
43         request.setUriPath("sampleUri");
44
45         resourceManager.channelRead0(coapClientHandler.connectCtx, request);
46
47         coapClient.stopClient();
48         coapServer.stopServer();
49     }
50
51     @Test
52     public void testRegisterResource() {
53         ResourceManager resourceManager = new ResourceManager();
54
55         resourceManager.registerResource(new SampleResource());
56     }
57
58     @Test
59     public void testUnregisterResource() {
60         SampleResource sampleResource = new SampleResource();
61         ResourceManager resourceManager = new ResourceManager();
62
63         resourceManager.registerResource(sampleResource);
64         resourceManager.unregisterResource(sampleResource);
65     }
66 }