2 import java.nio.file.Path;
3 import java.util.ArrayList;
4 import java.util.Iterator;
5 import org.json.JSONArray;
6 import org.json.JSONObject;
8 public class SimpleTests {
11 private static void testURI()
13 String uri="/ms/1/api/";
14 String query="task=getconfig";
18 uri = uri.substring("/ms/".length());
21 id = Long.parseLong(uri.substring(0, uri.indexOf("/")));
22 uri=uri.substring(uri.indexOf("/"));
23 } catch (Exception err) {
24 System.out.println(err.getMessage());
29 remoteUrl=baseUrl(id)+uri;
30 if (query != null && query.length() > 0)
31 remoteUrl += "?" + query;
33 System.out.println("url="+remoteUrl);
35 private static void testMSDBDataParser()
37 String resp="{\"took\":6,\"timed_out\":false,\"_shards\":{\"total\":5,\"successful\":5,\"failed\":0},\"hits\":{\"total\":2,\"max_score\":1.0,\"hits\":[{\"_index\":\"mwtn_v1\",\"_type\":\"mediator-server\",\"_id\":\"2\",\"_score\":1.0,\"_source\":{\"id\":2,\"name\":\"Server 2\",\"url\":\"http://mediatorsnmp.fritz.box:7070\"}},{\"_index\":\"mwtn_v1\",\"_type\":\"mediator-server\",\"_id\":\"1\",\"_score\":1.0,\"_source\":{\"id\":1,\"name\":\"Server 1\",\"url\":\"http://192.168.11.44:7070\"}}]}}";
38 JSONObject ro=new JSONObject(resp);
39 JSONArray a=ro.getJSONObject("hits").getJSONArray("hits");
40 for(int i=0;i<a.length();i++)
42 JSONObject x=a.getJSONObject(i).getJSONObject("_source");
43 System.out.println("id="+x.getLong("id")+" name=\""+x.getString("name")+"\" url=\""+x.getString("url")+"\"");
48 public static void walk(ArrayList<File> results, String path ) {
50 File root = new File( path );
51 File[] list = root.listFiles();
53 if (list == null) return;
55 for ( File f : list ) {
56 if ( f.isDirectory() ) {
57 walk(results, f.getAbsolutePath() );
58 //System.out.println( "Dir:" + f.getAbsoluteFile() );
61 //System.out.println( "File:" + f.getAbsoluteFile() );
62 if(f.isFile() && f.getName().endsWith(".md") )
67 private static void testFindMDs()
69 final String BASEURI = "/help";
70 final int MAX_DEPTH = 10;
71 String uri="/help/";//req.getRequestURI();
72 Path basePath=new File("/home/herbert/odl/distribution-karaf-0.5.3-Boron-SR3").toPath();
73 uri=uri.substring(BASEURI.length());
76 ArrayList<File> mdfiles=new ArrayList<>();
77 walk(mdfiles,basePath.toAbsolutePath().toString());
78 JSONArray a=new JSONArray();
79 Iterator<File> it=mdfiles.iterator();
81 a.put(it.next().toString().substring(basePath.toAbsolutePath().toString().length()));
82 //resp.getOutputStream().println(a.toString());
83 System.out.println(a.toString());
88 err.printStackTrace();
91 private static void folderTests()
93 Path basePath=new File("/home/herbert/odl/distribution-karaf-0.5.3-Boron-SR3").toPath();
94 Path pHelp=basePath.resolve("help/");
95 String uri="0.1.0-SNAPSHOT/OpenDaylight";
96 System.out.println("phelp="+pHelp.toString());
97 Path pUri=pHelp.resolve(uri);
98 System.out.println("puri="+pUri.toString());
101 public static void main(String[] args)
104 //testMSDBDataParser();
108 private static String baseUrl(long id) {
109 return "http://test.tld:7021";