ca0a7439d88812a4c7dbdc725d805c27dfdfd2ca
[aaf/cadi.git] / client / src / test / java / org / onap / aaf / client / test / JU_PaulUzee.java
1 /*******************************************************************************\r
2  * ============LICENSE_START====================================================\r
3  * * org.onap.aaf\r
4  * * ===========================================================================\r
5  * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
6  * * ===========================================================================\r
7  * * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * * you may not use this file except in compliance with the License.\r
9  * * You may obtain a copy of the License at\r
10  * * \r
11  *  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * * \r
13  *  * Unless required by applicable law or agreed to in writing, software\r
14  * * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * * See the License for the specific language governing permissions and\r
17  * * limitations under the License.\r
18  * * ============LICENSE_END====================================================\r
19  * *\r
20  * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
21  * *\r
22  ******************************************************************************/\r
23 package org.onap.aaf.client.test;\r
24 \r
25 import java.io.IOException;\r
26 import java.io.InputStream;\r
27 import java.io.PrintStream;\r
28 import java.net.URI;\r
29 import java.util.Properties;\r
30 \r
31 import org.onap.aaf.cadi.Access;\r
32 import org.onap.aaf.cadi.Locator;\r
33 import org.onap.aaf.cadi.Access.Level;\r
34 import org.onap.aaf.cadi.Locator.Item;\r
35 import org.onap.aaf.cadi.dme2.DME2Locator;\r
36 \r
37 import com.att.aft.dme2.api.DME2Manager;\r
38 \r
39 public class JU_PaulUzee {\r
40         public static void main(String[] args) {\r
41                 try {\r
42                         // You'll want to put this on Command line "-D" probably\r
43                         Properties props = System.getProperties();\r
44                         props.put("AFT_LATITUDE","32.780140");\r
45                         props.put("AFT_LONGITUDE","-96.800451");\r
46                         props.put("AFT_ENVIRONMENT","AFTPRD");\r
47 \r
48                         //\r
49                         // Use an "Access" class to hook up logging, properties, etc.\r
50                         // Make one that ties into your code's logging, property mechanism, etc.\r
51                         //\r
52                         Access access = new PaulAccess();\r
53                         \r
54                         DME2Manager dm = new DME2Manager("Paul Uzee's Test",props);\r
55                         Locator loc = new DME2Locator(access ,dm,"com.att.authz.AuthorizationService","2.0","PROD","DEFAULT");\r
56 \r
57                         \r
58                         for(Item item = loc.first(); item!=null; item=loc.next(item)) {\r
59                                 URI location = (URI) loc.get(item);\r
60                                 access.log(Level.INFO,location);\r
61                                 access.log(Level.INFO,location.getScheme());\r
62                                 access.log(Level.INFO,location.getHost());\r
63                                 access.log(Level.INFO, location.getPort());\r
64                         }\r
65                 } catch (Exception e) {\r
66                         e.printStackTrace();\r
67                 }\r
68                         \r
69         }\r
70 \r
71         private static class PaulAccess implements Access {\r
72                 private Level willWrite = Level.INFO;\r
73 \r
74                 @Override\r
75                 public ClassLoader classLoader() {\r
76                         return getClass().getClassLoader();\r
77                 }\r
78 \r
79                 @Override\r
80                 public String decrypt(String data, boolean def) throws IOException {\r
81                         return data;\r
82                 }\r
83 \r
84                 @Override\r
85                 public String getProperty(String tag, String def) {\r
86                         return System.getProperty(tag, def);\r
87                 }\r
88 \r
89                 @Override\r
90                 public void load(InputStream is) throws IOException {\r
91                         System.getProperties().load(is);\r
92                 }\r
93 \r
94                 @Override\r
95                 public void log(Level level, Object... obj) {\r
96                         if(level.compareTo(willWrite)<0) return;\r
97                         PrintStream ps;\r
98                         switch(level) {\r
99                                 case DEBUG:\r
100                                 case AUDIT:\r
101                                 case ERROR:\r
102                                 case WARN:\r
103                                         ps = System.err;\r
104                                         break;\r
105                                 case INFO:\r
106                                 case INIT:\r
107                                 default:\r
108                                         ps = System.out;\r
109                         }\r
110                         boolean first = true;\r
111                         for(Object o : obj) {\r
112                                 if(first)first=false;\r
113                                 else ps.print(' ');\r
114                                 ps.print(o.toString());\r
115                         }\r
116                         ps.println();\r
117                 }\r
118 \r
119                 @Override\r
120                 public void log(Exception e, Object... obj) {\r
121                         Object[] objs = new Object[obj.length+1];\r
122                         objs[0]=e.getMessage();\r
123                         System.arraycopy(objs, 1, obj, 0, obj.length);\r
124                         log(Level.ERROR,e,objs);\r
125                 }\r
126 \r
127                 @Override\r
128                 public void setLogLevel(Level l) {\r
129                         willWrite = l;\r
130                 }\r
131 \r
132                 /* (non-Javadoc)\r
133                  * @see com.att.cadi.Access#willLog(com.att.cadi.Access.Level)\r
134                  */\r
135                 @Override\r
136                 public boolean willLog(Level level) {\r
137                         return true;\r
138                 }\r
139 \r
140                 @Override\r
141                 public void printf(Level level, String fmt, Object... elements) {\r
142                         // TODO Auto-generated method stub\r
143                         \r
144                 }\r
145         };\r
146 }\r