Changed to unmaintained
[appc.git] / appc-adapters / appc-netconf-adapter / appc-netconf-adapter-bundle / src / test / java / org / onap / appc / adapter / netconf / internal / TestNetconfAdapter.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2017 Amdocs
8  * =============================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * 
21  * ============LICENSE_END=========================================================
22  */
23
24 package org.onap.appc.adapter.netconf.internal;
25
26 import org.junit.Assert;
27 import org.junit.Test;
28
29 import java.io.IOException;
30 import java.io.PipedInputStream;
31 import java.io.PipedOutputStream;
32
33 public class TestNetconfAdapter {
34
35         private static final String EOM = "]]>]]>";
36
37         @Test
38         public void testReceiveMessage() throws IOException {
39                 PipedOutputStream pos = new PipedOutputStream();
40                 PipedInputStream is = new PipedInputStream(pos);
41
42                 PipedInputStream pis = new PipedInputStream();
43                 PipedOutputStream os = new PipedOutputStream(pis);
44
45                 NetconfAdapter netconfAdapter = new NetconfAdapter(is, os);
46
47                 String request = "Hello, netconf!";
48                 pos.write(request.getBytes());
49                 pos.write(EOM.getBytes());
50                 String response = netconfAdapter.receiveMessage();
51                 Assert.assertNotNull(response);
52                 Assert.assertEquals(request, response.trim());
53         }
54
55         @Test
56         public void testSendMessage() throws IOException {
57                 PipedOutputStream pos = new PipedOutputStream();
58                 PipedInputStream is = new PipedInputStream(pos);
59
60                 PipedInputStream pis = new PipedInputStream();
61                 PipedOutputStream os = new PipedOutputStream(pis);
62
63                 NetconfAdapter netconfAdapter = new NetconfAdapter(is, os);
64
65                 String request = "Hello, netconf!";
66                 netconfAdapter.sendMessage(request);
67                 byte[] bytes = new byte[request.length()+EOM.length()+2];
68                 int count = pis.read(bytes);
69                 String response = new String(bytes, 0, count);
70                 Assert.assertNotNull(response);
71                 Assert.assertTrue(response.endsWith(EOM));
72                 response = response.substring(0, response.length() - EOM.length()).trim();
73                 Assert.assertEquals(request, response);
74         }
75
76         @Test
77         public void testSendReceive() throws IOException {
78                 PipedOutputStream os = new PipedOutputStream();
79                 PipedInputStream is = new PipedInputStream(os);
80
81                 NetconfAdapter netconfAdapter = new NetconfAdapter(is, os);
82
83                 String request = "Hello, netconf!";
84                 netconfAdapter.sendMessage(request);
85                 String response = netconfAdapter.receiveMessage();
86                 Assert.assertNotNull(response);
87                 Assert.assertEquals(request, response.trim());
88         }
89 }