2020-12-14 20:32:46 +01:00
|
|
|
package org.gcube.vremanagement.contextmanager;
|
|
|
|
|
2020-12-23 10:42:07 +01:00
|
|
|
import static org.junit.Assert.assertTrue;
|
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
2020-12-14 20:32:46 +01:00
|
|
|
import javax.inject.Inject;
|
|
|
|
|
2020-12-23 10:42:07 +01:00
|
|
|
import org.gcube.common.resources.gcore.Resource;
|
|
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
|
|
|
import org.gcube.vremanagement.contextmanager.collector.LegacyISConnector;
|
|
|
|
import org.gcube.vremanagement.contextmanager.handlers.ContextContainer;
|
2020-12-14 20:32:46 +01:00
|
|
|
import org.gcube.vremanagement.contextmanager.handlers.impl.ContextContainerImpl;
|
2020-12-23 10:42:07 +01:00
|
|
|
import org.gcube.vremanagement.contextmanager.handlers.impl.DynamicResourceHandler;
|
|
|
|
import org.gcube.vremanagement.contextmanager.handlers.impl.StaticResourceHandler;
|
|
|
|
import org.gcube.vremanagement.contextmanager.model.collectors.CollectorsBackend;
|
|
|
|
import org.gcube.vremanagement.contextmanager.model.exceptions.InvalidContextException;
|
|
|
|
import org.gcube.vremanagement.contextmanager.model.types.Context;
|
|
|
|
import org.gcube.vremanagement.contextmanager.operations.MandatoryVREOperationTest;
|
2020-12-14 20:32:46 +01:00
|
|
|
import org.jglue.cdiunit.AdditionalClasses;
|
|
|
|
import org.jglue.cdiunit.CdiRunner;
|
2020-12-23 10:42:07 +01:00
|
|
|
import org.junit.Before;
|
2020-12-14 20:32:46 +01:00
|
|
|
import org.junit.Test;
|
|
|
|
import org.junit.runner.RunWith;
|
2020-12-23 10:42:07 +01:00
|
|
|
import org.slf4j.Logger;
|
2020-12-14 20:32:46 +01:00
|
|
|
|
|
|
|
@RunWith(CdiRunner.class)
|
2020-12-23 10:42:07 +01:00
|
|
|
@AdditionalClasses({ContextContainerImpl.class, Factories.class,
|
|
|
|
LegacyISConnector.class, DynamicResourceHandler.class, StaticResourceHandler.class, MandatoryVREOperationTest.class })
|
2020-12-14 20:32:46 +01:00
|
|
|
public class ScopeTester {
|
|
|
|
|
|
|
|
@Inject ScopeInitializer scopeInitializer;
|
|
|
|
|
2020-12-23 10:42:07 +01:00
|
|
|
@Inject ContextContainer container;
|
|
|
|
|
|
|
|
@Inject ContextManager contextManager;
|
|
|
|
|
|
|
|
@Inject CollectorsBackend is;
|
|
|
|
|
|
|
|
@Inject Logger log;
|
|
|
|
|
|
|
|
@Inject ResourceManager resourceManager;
|
|
|
|
|
|
|
|
private static String resourceId = "eabfe9bb-001d-48bc-92dc-586eefdc2006";
|
|
|
|
|
|
|
|
private static String context = "/gcube/devNext";
|
|
|
|
|
|
|
|
private static String vreContext = "/gcube/devNext/NextNext";
|
|
|
|
|
|
|
|
@Before
|
|
|
|
public void init() {
|
|
|
|
ScopeProvider.instance.set(context);
|
|
|
|
scopeInitializer.initScope(context);
|
|
|
|
|
|
|
|
}
|
2020-12-14 20:32:46 +01:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void initTest() {
|
2020-12-23 10:42:07 +01:00
|
|
|
|
|
|
|
container.getAvailableContexts().forEach(c -> {
|
|
|
|
try {
|
|
|
|
container.getResources(c).forEach(r-> log.debug(" {} res {} ",c,r));
|
|
|
|
} catch (InvalidContextException e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void addAndRemoveResourceScopeTest() throws InvalidContextException {
|
|
|
|
Context context = container.getContextById(vreContext);
|
|
|
|
resourceManager.addResourceToContext(context, resourceId);
|
|
|
|
assertTrue(container.getResources(vreContext).contains(resourceId));
|
|
|
|
Resource res = is.find(resourceId);
|
|
|
|
assertTrue(res.scopes().asCollection().contains(vreContext));
|
|
|
|
log.debug("scopes are {}",res.scopes().asCollection());
|
|
|
|
resourceManager.removeResourceFromContext(context, resourceId);
|
|
|
|
assertTrue(!container.getResources(vreContext).contains(resourceId));
|
|
|
|
assertTrue(!is.find(resourceId).scopes().contains(vreContext));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void createContextTest() throws InvalidContextException {
|
|
|
|
contextManager.createContext(context, "newVRE", Collections.emptyList());
|
2020-12-14 20:32:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|