portal-auth-library/src/test/java/org/gcube/portal/auth/AppTest.java

93 lines
3.1 KiB
Java

package org.gcube.portal.auth;
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
import java.util.List;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.LaxRedirectStrategy;
import org.gcube.common.portal.PortalContext;
import org.gcube.common.resources.gcore.GCoreEndpoint;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import com.liferay.portal.kernel.json.JSONObject;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* Unit test for simple App.
*/
public class AppTest extends TestCase {
/**
* Create the test case
*
* @param testName name of the test case
*/
public AppTest( String testName )
{
super( testName );
}
/**
* @return the suite of tests being tested
*/
public static Test suite()
{
return new TestSuite( AppTest.class );
}
/**
* Rigourous Test :-)
*/
public void testApp() {
System.out.println("getAuthorisedRedirectURLsFromIs ... ");
try {
// ServiceEndpoint authorisedApp = AuthUtil.getAuthorisedApplicationInfoFromIsICClient(PortalContext.getConfiguration().getInfrastructureName(), "c96d4477-236c-4f98-ba7d-7897991ef412");
// List<String> authorisedRedirectURLs = AuthUtil.getAuthorisedRedirectURLsFromIs(authorisedApp);
//
// for (String red : authorisedRedirectURLs) {
System.out.println("");
List<GCoreEndpoint> endpoints = getRStudioServiceEndpoints("/d4science.research-infrastructures.eu/D4Research/ICES_MSY");
for (GCoreEndpoint gCoreEndpoint : endpoints) {
System.out.println(gCoreEndpoint);
}
String oauthendPoint = AuthUtil.getOAuthServiceEndPoint(PortalContext.getConfiguration().getInfrastructureName());
System.out.println(oauthendPoint);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static final String SERVICE_NAME = "RConnector";
private static final String SERVICECLASS = "DataAnalysis";
/**
*
* @return the
* @throws Exception
*/
private List<GCoreEndpoint> getRStudioServiceEndpoints(String scope) throws Exception {
String currScope = ScopeProvider.instance.get();
ScopeProvider.instance.set(scope);
SimpleQuery query = queryFor(GCoreEndpoint.class);
query.addCondition("$resource/Profile/ServiceName/text() eq '"+ SERVICE_NAME +"'");
query.addCondition("$resource/Profile/ServiceClass/text() eq '"+ SERVICECLASS +"'");
DiscoveryClient<GCoreEndpoint> client = clientFor(GCoreEndpoint.class);
List<GCoreEndpoint> toReturn = client.submit(query);
ScopeProvider.instance.set(currScope);
return toReturn;
}
}