gcube-cms-suite/sdi-plugins/src/test/java/org/gcube/application/cms/sdi/plugins/IndexerTest.java

48 lines
2.1 KiB
Java

package org.gcube.application.cms.sdi.plugins;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.bson.Document;
import org.gcube.application.cms.plugins.IndexerPluginInterface;
import org.gcube.application.cms.plugins.faults.PluginExecutionException;
import org.gcube.application.cms.plugins.reports.IndexDocumentReport;
import org.gcube.application.cms.plugins.reports.Report;
import org.gcube.application.cms.plugins.requests.IndexDocumentRequest;
import org.gcube.application.cms.serialization.Serialization;
import org.gcube.application.cms.tests.BasicPluginTest;
import org.gcube.application.cms.tests.TestDocuments;
import org.gcube.application.cms.tests.TestProfiles;
import org.gcube.application.geoportal.common.model.document.Project;
import org.gcube.application.geoportal.common.utils.tests.GCubeTest;
import org.junit.Test;
import static junit.framework.TestCase.assertTrue;
import static org.junit.Assume.assumeTrue;
public class IndexerTest extends BasicPluginTest {
@Test
public void testIndexRequest() throws PluginExecutionException, JsonProcessingException {
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
IndexDocumentRequest request=new IndexDocumentRequest();
Project doc= TestDocuments.documentMap.get("profiledConcessioniExample.json");
request.setUseCaseDescriptor(TestProfiles.profiles.get(doc.getProfileID()));
request.setDocument(doc);
Document parameters = new Document();
parameters.put("workspace", "testing_workspace");
parameters.put("indexName", "unique_index"+System.currentTimeMillis());
request.setCallParameters(parameters);
IndexerPluginInterface plugin = (IndexerPluginInterface) plugins.get(SDIIndexerPlugin.DESCRIPTOR.getId());
IndexDocumentReport response = plugin.index(request);
assertTrue(response!=null);
response.validate();
System.out.println("Response is "+Serialization.write(response));
assertTrue(response.getStatus().equals(Report.Status.OK));
assertTrue(response.prepareResult().getSpatialReference()!=null);
}
}