Added Test

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@85121 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2013-11-06 17:12:38 +00:00
parent 23355f90de
commit 453ba17dc0
1 changed files with 91 additions and 0 deletions

View File

@ -0,0 +1,91 @@
package org.gcube.portlets.user.td.gwtservice.client;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.data.analysis.tabulardata.model.table.Table;
import org.gcube.data.analysis.tabulardata.operation.worker.ActivityStatus;
import org.gcube.data.analysis.tabulardata.operation.worker.EligibleOperation;
import org.gcube.data.analysis.tabulardata.operation.worker.OperationInvocation;
import org.gcube.data.analysis.tabulardata.query.parameters.QueryPage;
import org.gcube.data.analysis.tabulardata.service.TabularDataService;
import org.gcube.data.analysis.tabulardata.service.impl.TabularDataServiceFactory;
import org.gcube.data.analysis.tabulardata.service.operation.Task;
import org.gcube.data.analysis.tabulardata.service.tabular.TabularResource;
import org.gcube.data.analysis.tabulardata.service.tabular.TabularResourceId;
import org.gcube.data.analysis.tabulardata.service.tabular.metadata.NameMetadata;
import org.junit.Assert;
import org.junit.Test;
public class TestService {
protected Map<String, Object> getParameterInvocation() {
Map<String, Object> parameterInstances = new HashMap<String, Object>();
parameterInstances
.put("registryBaseUrl",
"http://node8.d.d4science.research-infrastructures.eu:8080/FusionRegistry/ws/rest/");
parameterInstances.put("id", "CL_SPECIES");
parameterInstances.put("version", "1.0");
parameterInstances.put("agency", "FAO");
return parameterInstances;
}
@Test
public void create() throws Exception {
ScopeProvider.instance.set("/gcube/devsec");
TabularDataService service = TabularDataServiceFactory
.getService("giancarlo.panichi");
TabularResource resource = service.createTabularResource();
System.out.println("after createTabResource "
+ ScopeProvider.instance.get());
System.out.println("name: "
+ ((NameMetadata) resource.getMetadata(NameMetadata.class))
.getValue());
System.out.println("tabular data id: " + resource.getId().getValue());
TabularResourceId resourceId = resource.getId();
List<EligibleOperation> ops = service.getCapabilities();
EligibleOperation csvop = null;
for (EligibleOperation op : ops) {
System.out.println(op.getOperationDescriptor().getName());
if (op.getOperationDescriptor().getName().equals("SDMX Codelist import"))
csvop = op;
}
OperationInvocation opInvocation = csvop
.createOperationInvocation(getParameterInvocation());
Task task = service.execute(opInvocation, resource.getId());
while (task.getStatus() != ActivityStatus.FAILED
&& task.getStatus() != ActivityStatus.SUCCEDED) {
System.out.println(task.getStatus() + " "
+ task.getStartTime().getTime());
Thread.sleep(3000);
}
System.out.println(task.getStatus() + " "
+ task.getStartTime().getTime() + " "
+ task.getEndTime().getTime());
System.out.println("Task Progress:"+task.getProgress());
Assert.assertNotNull(task.getResult());
System.out.println("Task getResult: "+task.getResult());
Table resultTable = task.getResult().getOutput();
System.out.println("resultTable :" + resultTable);
System.out.println(service.getLastTable(resourceId).getName());
System.out.println(service.getQueryLenght(resultTable.getId(), null));
System.out.println(service.queryAsJson(resultTable.getId(),
new QueryPage(0, 200)));
}
}