From beddee26b53aa2b883fd2987b7bd21a635a6b1ac Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 2 Mar 2021 18:29:26 +0100 Subject: [PATCH] added JUnit Test Case --- .classpath | 11 +- .settings/org.eclipse.wst.common.component | 1 + .../TestPublishingWidget.java | 107 ++++++++++++++++++ src/test/resources/.gitignore | 3 + 4 files changed, 114 insertions(+), 8 deletions(-) create mode 100644 src/test/java/org/gcube/portlets/widgets/ckandatapublisherwidget/TestPublishingWidget.java create mode 100644 src/test/resources/.gitignore diff --git a/.classpath b/.classpath index ce7b7f2..510cf3c 100644 --- a/.classpath +++ b/.classpath @@ -6,13 +6,7 @@ - - - - - - - + @@ -25,8 +19,8 @@ - + @@ -34,5 +28,6 @@ + diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 0190c48..5c79e39 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -5,6 +5,7 @@ + diff --git a/src/test/java/org/gcube/portlets/widgets/ckandatapublisherwidget/TestPublishingWidget.java b/src/test/java/org/gcube/portlets/widgets/ckandatapublisherwidget/TestPublishingWidget.java new file mode 100644 index 0000000..6b26f4a --- /dev/null +++ b/src/test/java/org/gcube/portlets/widgets/ckandatapublisherwidget/TestPublishingWidget.java @@ -0,0 +1,107 @@ +package org.gcube.portlets.widgets.ckandatapublisherwidget; + + +import java.util.Arrays; +import java.util.Calendar; + +import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.common.storagehubwrapper.server.StorageHubWrapper; +import org.gcube.datacatalogue.utillibrary.server.DataCatalogueFactory; +import org.gcube.portlets.widgets.ckandatapublisherwidget.server.utils.WorkspaceUtils; +import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.DatasetBean; +import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.OrganizationBean; +import org.junit.Test; +import org.slf4j.LoggerFactory; + + + +/** + * The Class TestDataCatalogueLib. + * + * @author Francesco Mangiacrapa at ISTI-CNR Pisa (Italy) + * Jun 1, 2020 + */ +public class TestPublishingWidget { + + private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(TestPublishingWidget.class); + + private String scope = "/gcube"; + //private String testUser = "costantino_perciante"; + private String testUser = "francesco.mangiacrapa"; + private String authorizationToken = ""; + + /** + * Before. + * + * @throws Exception the exception + */ + //@Before + public void before() throws Exception{ + } + + /** + * Factory test. + * + * @throws Exception the exception + */ + //@Test + public void factoryTest() throws Exception{ + + DataCatalogueFactory factory = DataCatalogueFactory.getFactory(); + + while(true){ + factory.getUtilsPerScope(scope); + Thread.sleep(60* 1000 * 3); + factory.getUtilsPerScope(scope); + break; + } + + for (int i = 0; i < 5; i++) { + Thread.sleep(1000); + factory.getUtilsPerScope(scope); + } + + } + + @Test + public void getDatasetBeanTest() throws Exception{ + ScopeProvider.instance.set(scope); + String userName = testUser; + String token = authorizationToken; + + String folderId = "6399daa7-2173-4314-b4f7-2afa24eae8f8"; + DatasetBean bean; + try{ + bean = new DatasetBean(); + bean.setId(folderId); + bean.setDescription("This is a fantastic description"); + bean.setVersion(1); + String onlyAlphanumeric = "test-creation-blablabla".replaceAll("[^A-Za-z0-9]", ""); + bean.setTitle(onlyAlphanumeric + Calendar.getInstance().getTimeInMillis()); + bean.setAuthorName("Francesco"); + bean.setAuthorSurname("Mangiacrapa"); + bean.setAuthorEmail("francesco.mangiacrapa@isti.cnr.it"); + bean.setMaintainer("Francesco Mangiacrapa"); + bean.setMaintainerEmail("francesco.mangiacrapa@isti.cnr.it"); + + //UPDATED By Francesco + String vreName = scope.substring(scope.lastIndexOf("/")+1,scope.length()); + LOG.debug("In dev mode using the scope: "+scope+" and VRE name: "+vreName); + bean.setOrganizationList(Arrays.asList(new OrganizationBean(vreName, vreName.toLowerCase(), true))); + + bean.setOwnerIdentifier(userName); + + if(folderId != null && !folderId.isEmpty()){ + StorageHubWrapper storageHubWrapper = new StorageHubWrapper(scope, token, false, false, true); + WorkspaceUtils.handleWorkspaceResources(folderId, userName, bean, storageHubWrapper.getWorkspace()); + } + }catch(Exception e){ + LOG.error("Error while building bean into dev mode", e); + throw new Exception("Error while retrieving basic information " + e.getMessage()); + } + + LOG.info("Got dataset: "+bean); + } + + +} diff --git a/src/test/resources/.gitignore b/src/test/resources/.gitignore new file mode 100644 index 0000000..abcb271 --- /dev/null +++ b/src/test/resources/.gitignore @@ -0,0 +1,3 @@ +/devsec.gcubekey +/gcube.gcubekey +/log4j.properties