package org.onap.aaf.cadi.oauth.test;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.lang.reflect.Field;
import java.net.ConnectException;
import java.util.Date;
import java.util.GregorianCalendar;
+import java.util.HashMap;
import org.junit.After;
import org.junit.AfterClass;
import org.onap.aaf.cadi.client.Result;
import org.onap.aaf.cadi.client.Retryable;
import org.onap.aaf.cadi.config.Config;
+import org.onap.aaf.cadi.config.SecurityInfoC;
import org.onap.aaf.cadi.oauth.TimedToken;
import org.onap.aaf.cadi.oauth.TokenClient;
import org.onap.aaf.cadi.oauth.TokenClientFactory;
public class JU_OAuthTest {
+ private ByteArrayOutputStream outStream;
+
private static PropAccess access;
private static TokenClientFactory tcf;
@BeforeClass
public static void setUpBeforeClass() {
+ ByteArrayOutputStream outStream = new ByteArrayOutputStream();
+ System.setOut(new PrintStream(outStream));
+
access = new PropAccess();
try {
tcf = TokenClientFactory.instance(access);
@AfterClass
public static void tearDownAfterClass() throws Exception {
+ Field field = SecurityInfoC.class.getDeclaredField("sicMap");
+ field.setAccessible(true);
+ field.set(null, new HashMap<Class<?>,SecurityInfoC<?>>());
}
@Before
public void setUp() throws Exception {
+ outStream = new ByteArrayOutputStream();
+ System.setOut(new PrintStream(outStream));
}
@After
public void tearDown() throws Exception {
+ System.setOut(System.out);
}
@Test
}
}
} catch (Exception e) {
- e.printStackTrace();
// 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) {
- tclient.password(user,password);
- }
- Result<TimedToken> rt = tclient.getToken(scope);
- if(rt.isOK()) {
- print(rt.value);
- Result<Introspect> rti = tclient.introspect(rt.value.getAccessToken());
- if(rti.isOK()) {
- print(rti.value);
- } else {
- printAndFail(rti);
- }
- } else {
- printAndFail(rt);
- }
- return tclient;
- }
+// 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) {
+// tclient.password(user,password);
+// }
+// Result<TimedToken> rt = tclient.getToken(scope);
+// if(rt.isOK()) {
+// print(rt.value);
+// Result<Introspect> rti = tclient.introspect(rt.value.getAccessToken());
+// if(rti.isOK()) {
+// print(rti.value);
+// } else {
+// printAndFail(rti);
+// }
+// } else {
+// printAndFail(rt);
+// }
+// return tclient;
+// }
private String serviceCall(TzClient tzClient) throws Exception {
return tzClient.best(new Retryable<String>() {
}
});
}
- private void printAndFail(Result<?> rt) {
- System.out.printf("HTTP Code %d: %s\n", rt.code, rt.error);
- Assert.fail(rt.toString());
- }
+// private void printAndFail(Result<?> rt) {
+// System.out.printf("HTTP Code %d: %s\n", rt.code, rt.error);
+// Assert.fail(rt.toString());
+// }
private void print(Token t) {
GregorianCalendar exp_date = new GregorianCalendar();