Sonar Fixes, Formatting
[aaf/authz.git] / cadi / aaf / src / test / java / org / onap / aaf / cadi / oauth / test / JU_OAuthTest.java
index ef22b79..a0a6c10 100644 (file)
@@ -7,9 +7,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -67,6 +67,8 @@ public class JU_OAuthTest {
         System.setOut(new PrintStream(outStream));
 
         access = new PropAccess();
+        access.setProperty(Config.CADI_LATITUDE, "38");
+        access.setProperty(Config.CADI_LONGITUDE, "-72");
         try {
             tcf = TokenClientFactory.instance(access);
         } catch (Exception e) {
@@ -109,21 +111,21 @@ public class JU_OAuthTest {
 
             TokenClient tc;
             Result<TimedToken> rtt;
-            if(true) {
+            if (true) {
                 tc = tcf.newClient(tokenServiceURL, 3000);
                 tc.client_creds(client_id,client_secret);
                 tc.password(access.getProperty("cadi_username"),access.getProperty("cadi_password"));
                 rtt = tc.getToken(Kind.BASIC_AUTH,"org.osaaf.aaf","org.osaaf.test");
-                if(rtt.isOK()) {
+                if (rtt.isOK()) {
                     print(rtt.value);
                     rtt = tc.refreshToken(rtt.value);
-                    if(rtt.isOK()) {
+                    if (rtt.isOK()) {
                         print(rtt.value);
                         TokenClient ic = tcf.newClient(tokenIntrospectURL,3000);
                         ic.client_creds(client_id,client_secret);
 
                         Result<Introspect> ri = ic.introspect(rtt.value.getAccessToken());
-                        if(ri.isOK()) {
+                        if (ri.isOK()) {
                             print(ri.value);
                         } else {
                             System.out.println(ri.code + ' ' + ri.error);
@@ -143,30 +145,30 @@ public class JU_OAuthTest {
                     Assert.fail(rtt.code + ' ' + rtt.error);
                 }
             }
-        
+
             // ISAM Test
-            if(true) {
+            if (true) {
                 System.out.println("**** ISAM TEST ****");
                 tokenServiceURL=access.getProperty(Config.AAF_ALT_OAUTH2_TOKEN_URL);
                 client_id=access.getProperty(Config.AAF_ALT_CLIENT_ID);
                 client_secret=access.getProperty(Config.AAF_ALT_CLIENT_SECRET);
-                if(tokenServiceURL!=null) {
+                if (tokenServiceURL!=null) {
                     tc = tcf.newClient(tokenServiceURL, 3000);
                     tc.client_creds(client_id, client_secret);
                     int at = username.indexOf('@');
-                    
+
                     tc.password(at>=0?username.substring(0, at):username,access.getProperty("cadi_password"));
                     rtt = tc.getToken("org.osaaf.aaf","org.osaaf.test");
-                    if(rtt.isOK()) {
+                    if (rtt.isOK()) {
                         print(rtt.value);
                         rtt = tc.refreshToken(rtt.value);
-                        if(rtt.isOK()) {
+                        if (rtt.isOK()) {
                             print(rtt.value);
-                            
+
                             tc = tcf.newClient(tokenAltIntrospectURL, 3000);
                             tc.client_creds(client_id, client_secret);
                             Result<Introspect> rti = tc.introspect(rtt.value.getAccessToken());
-                            if(rti.isOK()) {
+                            if (rti.isOK()) {
                                 System.out.print("Normal ISAM ");
                                 print(rti.value);
                             } else {
@@ -177,12 +179,12 @@ public class JU_OAuthTest {
                             tc = tcf.newClient(tokenIntrospectURL, 3000);
                             tc.client_creds(client_id, client_secret);
                             rti = tc.introspect(rtt.value.getAccessToken());
-                            if(rti.isOK()) {
+                            if (rti.isOK()) {
                                 System.out.print("AAF with ISAM Token ");
                                 print(rti.value);
                             } else {
                                 System.out.println(rti.code + ' ' + rti.error);
-                                if(rti.code!=404) {
+                                if (rti.code!=404) {
                                     Assert.fail(rti.code + ' ' + rti.error);
                                 }
                             }
@@ -209,19 +211,19 @@ public class JU_OAuthTest {
 //            Assert.fail();
         }
     }
-    
-    
+
+
 //    private TokenClient testROPCFlow(final String url, final String client_id, final String client_secret, String user, String password, final String ... scope) throws Exception {
 //        TokenClient tclient = tcf.newClient(url,3000);
 //        tclient.client_creds(client_id, client_secret);
-//        if(user!=null && password!=null) {
+//        if (user!=null && password!=null) {
 //            tclient.password(user,password);
 //        }
 //        Result<TimedToken> rt = tclient.getToken(scope);
-//        if(rt.isOK()) {
+//        if (rt.isOK()) {
 //            print(rt.value);
 //            Result<Introspect> rti = tclient.introspect(rt.value.getAccessToken());
-//            if(rti.isOK()) {
+//            if (rti.isOK()) {
 //                print(rti.value);
 //            } else {
 //                printAndFail(rti);
@@ -231,13 +233,13 @@ public class JU_OAuthTest {
 //        }
 //        return tclient;
 //    }
-    
+
     private String serviceCall(TzClient tzClient) throws Exception {
         return tzClient.best(new Retryable<String>() {
             @Override
             public String code(Rcli<?> client) throws CadiException, ConnectException, APIException {
                 Future<String> future = client.read(null,"text/plain");
-                if(future.get(3000)) {
+                if (future.get(3000)) {
                     return future.value;
                 } else {
                     throw new APIException(future.code()  + future.body());
@@ -261,9 +263,9 @@ public class JU_OAuthTest {
         t.getScope(),
         t.getRefreshToken());
     }
-    
+
     private void print(Introspect ti) {
-        if(ti==null || ti.getClientId()==null) {
+        if (ti==null || ti.getClientId()==null) {
             System.out.println("Empty Introspect");
             return;
         }
@@ -286,7 +288,7 @@ public class JU_OAuthTest {
         Chrono.timeStamp(exp),
         ti.getScope(),
         ti.getContent()==null?"":ti.getContent());
-        
+
         System.out.println();
     }
 }