|
|
|
@ -1,13 +1,9 @@
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
package org.gcube.resourcemanagement.manager.webapp.context;
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.*;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
import java.util.Properties;
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
|
@ -31,89 +27,94 @@ import org.junit.runners.MethodSorters;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test cases for {@link Queries}
|
|
|
|
|
*
|
|
|
|
|
* @author Manuele Simi (ISTI CNR)
|
|
|
|
|
*
|
|
|
|
|
* @author Manuele Simi (ISTI CNR)
|
|
|
|
|
*/
|
|
|
|
|
@RunWith(BlockJUnit4ClassRunner.class)
|
|
|
|
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
|
|
|
|
public class QueriesTest {
|
|
|
|
|
|
|
|
|
|
private final static String RR = "http://manuele-registry.dev.d4science.org/resource-registry";
|
|
|
|
|
|
|
|
|
|
public static String DEFAULT_TEST_SCOPE ="";
|
|
|
|
|
|
|
|
|
|
public static final UUID context1UUID = RMContextTest.context1UUID;
|
|
|
|
|
|
|
|
|
|
private static boolean skipTest = false;
|
|
|
|
|
|
|
|
|
|
static {
|
|
|
|
|
Properties properties = new Properties();
|
|
|
|
|
try (InputStream input = RMContextTest.class.getClassLoader().getResourceAsStream("token.properties")) {
|
|
|
|
|
// load the properties file
|
|
|
|
|
properties.load(input);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
skipTest = true;
|
|
|
|
|
//throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DEFAULT_TEST_SCOPE = properties.getProperty("DEFAULT_SCOPE_TOKEN");
|
|
|
|
|
if (DEFAULT_TEST_SCOPE.isEmpty())
|
|
|
|
|
skipTest = true;
|
|
|
|
|
}
|
|
|
|
|
@BeforeClass
|
|
|
|
|
public static void beforeClass() throws Exception {
|
|
|
|
|
setContext(DEFAULT_TEST_SCOPE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void setContext(String token) throws ObjectNotFound, Exception {
|
|
|
|
|
if (DEFAULT_TEST_SCOPE.isEmpty()) {
|
|
|
|
|
skipTest = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
SecurityTokenProvider.instance.set(token);
|
|
|
|
|
ScopeProvider.instance.set(getCurrentScope(token));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String getCurrentScope(String token) throws ObjectNotFound, Exception {
|
|
|
|
|
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
|
|
|
|
|
String context = authorizationEntry.getContext();
|
|
|
|
|
return context;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@AfterClass
|
|
|
|
|
public static void afterClass() throws Exception {
|
|
|
|
|
SecurityTokenProvider.instance.reset();
|
|
|
|
|
ScopeProvider.instance.reset();
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Test method for {@link org.gcube.resourcemanagement.manager.webapp.context.Queries#contextExists(UUID)}.
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
public void testContextExists() {
|
|
|
|
|
if (skipTest)
|
|
|
|
|
return;
|
|
|
|
|
ResourceRegistryContextClient cclient = new ResourceRegistryContextClientImpl(RR);
|
|
|
|
|
ResourceRegistryClient rclient = new ResourceRegistryClientImpl(RR);
|
|
|
|
|
Queries queries = new Queries(cclient, rclient);
|
|
|
|
|
assertFalse("Context does exist, but it should not", queries.contextExists(RMContextTest.context1UUID));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test method for {@link org.gcube.resourcemanagement.manager.webapp.context.Queries#fetchContext(UUID)} .
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
public void testFetchContext() {
|
|
|
|
|
if (skipTest)
|
|
|
|
|
return;
|
|
|
|
|
ResourceRegistryContextClient cclient = new ResourceRegistryContextClientImpl(RR);
|
|
|
|
|
ResourceRegistryClient rclient = new ResourceRegistryClientImpl(RR);
|
|
|
|
|
Queries queries = new Queries(cclient, rclient);
|
|
|
|
|
Context context = queries.fetchContext(context1UUID);
|
|
|
|
|
assertNotNull("Context does not exist.", context);
|
|
|
|
|
assertEquals("Unexpected uuid for context", context1UUID, context.getHeader().getUUID());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Resource Registry to contact
|
|
|
|
|
*/
|
|
|
|
|
private static String RR = "";
|
|
|
|
|
|
|
|
|
|
public static String DEFAULT_TEST_SCOPE = "";
|
|
|
|
|
|
|
|
|
|
public static final UUID context1UUID = RMContextTest.context1UUID;
|
|
|
|
|
|
|
|
|
|
private static boolean skipTest = false;
|
|
|
|
|
|
|
|
|
|
static {
|
|
|
|
|
Properties properties = new Properties();
|
|
|
|
|
try (InputStream input = RMContextTest.class.getClassLoader().getResourceAsStream("token.properties")) {
|
|
|
|
|
// load the properties file
|
|
|
|
|
properties.load(input);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
skipTest = true;
|
|
|
|
|
//throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DEFAULT_TEST_SCOPE = properties.getProperty("DEFAULT_SCOPE_TOKEN");
|
|
|
|
|
if (DEFAULT_TEST_SCOPE.isEmpty())
|
|
|
|
|
skipTest = true;
|
|
|
|
|
RR = properties.getProperty("RR");
|
|
|
|
|
if (RR.isEmpty())
|
|
|
|
|
skipTest = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@BeforeClass
|
|
|
|
|
public static void beforeClass() throws Exception {
|
|
|
|
|
setContext(DEFAULT_TEST_SCOPE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void setContext(String token) throws ObjectNotFound, Exception {
|
|
|
|
|
if (DEFAULT_TEST_SCOPE.isEmpty()) {
|
|
|
|
|
skipTest = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
SecurityTokenProvider.instance.set(token);
|
|
|
|
|
ScopeProvider.instance.set(getCurrentScope(token));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String getCurrentScope(String token) throws ObjectNotFound, Exception {
|
|
|
|
|
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
|
|
|
|
|
String context = authorizationEntry.getContext();
|
|
|
|
|
return context;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@AfterClass
|
|
|
|
|
public static void afterClass() throws Exception {
|
|
|
|
|
SecurityTokenProvider.instance.reset();
|
|
|
|
|
ScopeProvider.instance.reset();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test method for {@link org.gcube.resourcemanagement.manager.webapp.context.Queries#contextExists(UUID)}.
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
public void testContextExists() {
|
|
|
|
|
if (skipTest)
|
|
|
|
|
return;
|
|
|
|
|
ResourceRegistryContextClient cclient = new ResourceRegistryContextClientImpl(RR);
|
|
|
|
|
ResourceRegistryClient rclient = new ResourceRegistryClientImpl(RR);
|
|
|
|
|
Queries queries = new Queries(cclient, rclient);
|
|
|
|
|
assertFalse("Context does exist, but it should not", queries.contextExists(RMContextTest.context1UUID));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test method for {@link org.gcube.resourcemanagement.manager.webapp.context.Queries#fetchContext(UUID)} .
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
public void testFetchContext() {
|
|
|
|
|
if (skipTest)
|
|
|
|
|
return;
|
|
|
|
|
ResourceRegistryContextClient cclient = new ResourceRegistryContextClientImpl(RR);
|
|
|
|
|
ResourceRegistryClient rclient = new ResourceRegistryClientImpl(RR);
|
|
|
|
|
Queries queries = new Queries(cclient, rclient);
|
|
|
|
|
Context context = queries.fetchContext(context1UUID);
|
|
|
|
|
assertNotNull("Context does not exist.", context);
|
|
|
|
|
assertEquals("Unexpected uuid for context", context1UUID, context.getHeader().getUUID());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|