Update AAF Version 1.0.0
[aaf/cadi.git] / client / src / test / java / com / client / test / 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 com.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 com.att.aft.dme2.api.DME2Manager;\r
32 import com.att.cadi.Access;\r
33 import com.att.cadi.Locator;\r
34 import com.att.cadi.Access.Level;\r
35 import com.att.cadi.Locator.Item;\r
36 import com.att.cadi.dme2.DME2Locator;\r
37 \r
38 public class PaulUzee {\r
39         public static void main(String[] args) {\r
40                 try {\r
41                         // You'll want to put this on Command line "-D" probably\r
42                         Properties props = System.getProperties();\r
43                         props.put("AFT_LATITUDE","32.780140");\r
44                         props.put("AFT_LONGITUDE","-96.800451");\r
45                         props.put("AFT_ENVIRONMENT","AFTPRD");\r
46 \r
47                         //\r
48                         // Use an "Access" class to hook up logging, properties, etc.\r
49                         // Make one that ties into your code's logging, property mechanism, etc.\r
50                         //\r
51                         Access access = new PaulAccess();\r
52                         \r
53                         DME2Manager dm = new DME2Manager("Paul Uzee's Test",props);\r
54                         Locator loc = new DME2Locator(access ,dm,"com.att.authz.AuthorizationService","2.0","PROD","DEFAULT");\r
55 \r
56                         \r
57                         for(Item item = loc.first(); item!=null; item=loc.next(item)) {\r
58                                 URI location = (URI) loc.get(item);\r
59                                 access.log(Level.INFO,location);\r
60                                 access.log(Level.INFO,location.getScheme());\r
61                                 access.log(Level.INFO,location.getHost());\r
62                                 access.log(Level.INFO, location.getPort());\r
63                         }\r
64                 } catch (Exception e) {\r
65                         e.printStackTrace();\r
66                 }\r
67                         \r
68         }\r
69 \r
70         private static class PaulAccess implements Access {\r
71                 private Level willWrite = Level.INFO;\r
72 \r
73                 @Override\r
74                 public ClassLoader classLoader() {\r
75                         return getClass().getClassLoader();\r
76                 }\r
77 \r
78                 @Override\r
79                 public String decrypt(String data, boolean def) throws IOException {\r
80                         return data;\r
81                 }\r
82 \r
83                 @Override\r
84                 public String getProperty(String tag, String def) {\r
85                         return System.getProperty(tag, def);\r
86                 }\r
87 \r
88                 @Override\r
89                 public void load(InputStream is) throws IOException {\r
90                         System.getProperties().load(is);\r
91                 }\r
92 \r
93                 @Override\r
94                 public void log(Level level, Object... obj) {\r
95                         if(level.compareTo(willWrite)<0) return;\r
96                         PrintStream ps;\r
97                         switch(level) {\r
98                                 case DEBUG:\r
99                                 case AUDIT:\r
100                                 case ERROR:\r
101                                 case WARN:\r
102                                         ps = System.err;\r
103                                         break;\r
104                                 case INFO:\r
105                                 case INIT:\r
106                                 default:\r
107                                         ps = System.out;\r
108                         }\r
109                         boolean first = true;\r
110                         for(Object o : obj) {\r
111                                 if(first)first=false;\r
112                                 else ps.print(' ');\r
113                                 ps.print(o.toString());\r
114                         }\r
115                         ps.println();\r
116                 }\r
117 \r
118                 @Override\r
119                 public void log(Exception e, Object... obj) {\r
120                         Object[] objs = new Object[obj.length+1];\r
121                         objs[0]=e.getMessage();\r
122                         System.arraycopy(objs, 1, obj, 0, obj.length);\r
123                         log(Level.ERROR,e,objs);\r
124                 }\r
125 \r
126                 @Override\r
127                 public void setLogLevel(Level l) {\r
128                         willWrite = l;\r
129                 }\r
130 \r
131                 /* (non-Javadoc)\r
132                  * @see com.att.cadi.Access#willLog(com.att.cadi.Access.Level)\r
133                  */\r
134                 @Override\r
135                 public boolean willLog(Level level) {\r
136                         return true;\r
137                 }\r
138 \r
139                 @Override\r
140                 public void printf(Level level, String fmt, Object... elements) {\r
141                         // TODO Auto-generated method stub\r
142                         \r
143                 }\r
144         };\r
145 }\r