Compare commits
8 Commits
Author | SHA1 | Date |
---|---|---|
Luca Frosini | 6c67cccd63 | |
Luca Frosini | 0c547f14e3 | |
lucio | 7ecf6a2f77 | |
lucio | 3a69a8dfca | |
luca.frosini | 3910ed1bf0 | |
lucio | bdc6998f6d | |
Lucio Lelii | 96979e9289 | |
Luca Frosini | 7c0c1b1c90 |
|
@ -2,3 +2,4 @@ target
|
|||
.classpath
|
||||
.project
|
||||
/.settings/
|
||||
/.DS_Store
|
||||
|
|
|
@ -2,6 +2,12 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||
|
||||
# Changelog for Accounting Library
|
||||
|
||||
## [v5.0.0-SNAPSHOT]
|
||||
|
||||
- removed old Providers
|
||||
- Added compatibility between smartgears 3 and smartgears 4 component
|
||||
|
||||
|
||||
## [v4.1.0]
|
||||
|
||||
- Deprecated not needed properties to reduce data and improve aggregation
|
||||
|
|
24
pom.xml
24
pom.xml
|
@ -5,43 +5,34 @@
|
|||
<parent>
|
||||
<groupId>org.gcube.tools</groupId>
|
||||
<artifactId>maven-parent</artifactId>
|
||||
<version>1.1.0</version>
|
||||
<version>1.2.0</version>
|
||||
</parent>
|
||||
|
||||
<groupId>org.gcube.accounting</groupId>
|
||||
<artifactId>accounting-lib</artifactId>
|
||||
<version>4.1.0</version>
|
||||
<version>5.0.0-SNAPSHOT</version>
|
||||
<name>Accounting Library</name>
|
||||
<description>Accounting Library</description>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<serviceClass>Accounting</serviceClass>
|
||||
</properties>
|
||||
|
||||
<scm>
|
||||
<connection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</connection>
|
||||
<developerConnection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</developerConnection>
|
||||
<url>https://code-repo.d4science.org/gCubeSystem/${project.artifactId}</url>
|
||||
</scm>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.gcube.distribution</groupId>
|
||||
<artifactId>gcube-bom</artifactId>
|
||||
<version>2.0.1</version>
|
||||
<version>3.0.0</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>authorization-client</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.data.publishing</groupId>
|
||||
<artifactId>document-store-lib</artifactId>
|
||||
|
@ -62,7 +53,16 @@
|
|||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>gcube-jackson-databind</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>common-utility-sg4</artifactId>
|
||||
</dependency>
|
||||
<!-- Test Dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.gcube.common.security</groupId>
|
||||
<artifactId>gcube-secrets</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
|
|
|
@ -10,10 +10,7 @@ import java.util.SortedSet;
|
|||
import org.gcube.accounting.datamodel.validations.annotations.ValidOperationResult;
|
||||
import org.gcube.accounting.datamodel.validations.validators.ValidOperationResultValidator;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import org.gcube.common.authorization.client.Constants;
|
||||
import org.gcube.common.authorization.library.AuthorizationEntry;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.context.ContextUtility;
|
||||
import org.gcube.documentstore.exception.InvalidValueException;
|
||||
import org.gcube.documentstore.records.implementation.AbstractRecord;
|
||||
import org.gcube.documentstore.records.implementation.RequiredField;
|
||||
|
@ -45,23 +42,7 @@ public abstract class BasicUsageRecord extends AbstractRecord implements UsageRe
|
|||
@ValidOperationResult
|
||||
public static final String OPERATION_RESULT = UsageRecord.OPERATION_RESULT;
|
||||
|
||||
public static String getContextFromToken() {
|
||||
|
||||
String scope = ScopeProvider.instance.get();
|
||||
if (scope == null) {
|
||||
String token = SecurityTokenProvider.instance.get();
|
||||
|
||||
AuthorizationEntry authorizationEntry;
|
||||
try {
|
||||
authorizationEntry = Constants.authorizationService().get(token);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
scope = authorizationEntry.getContext();
|
||||
}
|
||||
return scope;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initialize variable
|
||||
*/
|
||||
|
@ -69,10 +50,11 @@ public abstract class BasicUsageRecord extends AbstractRecord implements UsageRe
|
|||
super.init();
|
||||
// Backward compatibility
|
||||
try {
|
||||
this.setScope(getContextFromToken());
|
||||
} catch (Exception e) {
|
||||
String context = ContextUtility.getCurrentContextFullName();
|
||||
this.setScope(context);
|
||||
} catch (Throwable t) {
|
||||
logger.warn(
|
||||
"Unable to automaticcally set the scope using scope provider. The record will not be valid if the scope will not be explicitly set.");
|
||||
"Unable to automatically set the context using the known providers. The record will not be valid if the scope will not be explicitly set.");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -71,6 +71,7 @@ public abstract class AbstractStorageStatusRecord extends BasicUsageRecord {
|
|||
* KEY for : providerId the identifier of the provider which is the target of a read/write operation
|
||||
*/
|
||||
@ValidURI @MoveToProviderURI
|
||||
@Deprecated
|
||||
public static final String PROVIDER_ID = "providerId";
|
||||
|
||||
@RequiredField @ValidURI
|
||||
|
|
|
@ -6,7 +6,7 @@ package org.gcube.accounting.persistence;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.accounting.datamodel.BasicUsageRecord;
|
||||
import org.gcube.common.context.ContextUtility;
|
||||
import org.gcube.common.encryption.encrypter.StringEncrypter;
|
||||
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
|
||||
|
@ -45,8 +45,9 @@ public class AccountingPersistenceConfiguration extends PersistenceBackendConfig
|
|||
ServiceEndpoint serviceEndpoint = getServiceEndpoint(SERVICE_ENDPOINT_CATEGORY, SERVICE_ENDPOINT_NAME, clz);
|
||||
setValues(serviceEndpoint, clz);
|
||||
}catch (Exception e) {
|
||||
logger.error("Error while instancing {} in context {}", this.getClass().getSimpleName(),
|
||||
BasicUsageRecord.getContextFromToken(), e);
|
||||
String context = ContextUtility.getCurrentContextFullName();
|
||||
logger.error("Error while instancing {} in context {}",
|
||||
this.getClass().getSimpleName(), context, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,7 +66,7 @@ public class AccountingPersistenceConfiguration extends PersistenceBackendConfig
|
|||
DiscoveryClient<ServiceEndpoint> client = ICFactory.clientFor(ServiceEndpoint.class);
|
||||
List<ServiceEndpoint> serviceEndpoints = client.submit(query);
|
||||
if(serviceEndpoints.size()>1){
|
||||
String scope = BasicUsageRecord.getContextFromToken();
|
||||
String scope = ContextUtility.getCurrentContextFullName();
|
||||
query.addCondition(String.format("$resource/Profile/AccessPoint/Properties/Property/Name/text() eq '%s'", TARGET_SCOPE));
|
||||
query.addCondition(String.format("$resource/Profile/AccessPoint/Properties/Property/Value/text() eq '%s'", scope));
|
||||
serviceEndpoints = client.submit(query);
|
||||
|
|
|
@ -7,8 +7,6 @@ import java.util.Set;
|
|||
|
||||
import org.gcube.accounting.datamodel.usagerecords.JobUsageRecord;
|
||||
import org.gcube.accounting.datamodel.usagerecords.JobUsageRecordTest;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.documentstore.exception.InvalidValueException;
|
||||
import org.gcube.documentstore.exception.NotAggregatableRecordsExceptions;
|
||||
import org.gcube.testutility.ContextTest;
|
||||
|
@ -27,8 +25,6 @@ public class AggregatedJobUsageRecordTest extends ContextTest {
|
|||
|
||||
@Test
|
||||
public void testRequiredFields() throws InvalidValueException {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
|
||||
JobUsageRecord jobUsageRecord = TestUsageRecord.createTestJobUsageRecord();
|
||||
Assert.assertTrue(jobUsageRecord.getScope()==null);
|
||||
|
@ -56,9 +52,7 @@ public class AggregatedJobUsageRecordTest extends ContextTest {
|
|||
|
||||
@Test
|
||||
public void secondAsNotAggregated() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
|
||||
|
||||
JobUsageRecord jobUsageRecord = TestUsageRecord.createTestJobUsageRecord();
|
||||
Assert.assertTrue(jobUsageRecord.getScope()==null);
|
||||
jobUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
|
@ -105,8 +99,6 @@ public class AggregatedJobUsageRecordTest extends ContextTest {
|
|||
|
||||
@Test
|
||||
public void secondAsAggregated() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
|
||||
JobUsageRecord jobUsageRecord = TestUsageRecord.createTestJobUsageRecord();
|
||||
Assert.assertTrue(jobUsageRecord.getScope()==null);
|
||||
|
@ -158,8 +150,6 @@ public class AggregatedJobUsageRecordTest extends ContextTest {
|
|||
|
||||
@Test
|
||||
public void aggregationStressTest() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
|
||||
JobUsageRecord jobUsageRecord = TestUsageRecord.createTestJobUsageRecord();
|
||||
Assert.assertTrue(jobUsageRecord.getScope()==null);
|
||||
|
|
|
@ -8,8 +8,6 @@ import java.util.Set;
|
|||
import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord;
|
||||
import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecordTest;
|
||||
import org.gcube.com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.documentstore.exception.InvalidValueException;
|
||||
import org.gcube.documentstore.exception.NotAggregatableRecordsExceptions;
|
||||
import org.gcube.documentstore.records.DSMapper;
|
||||
|
@ -30,8 +28,6 @@ public class AggregatedServiceUsageRecordTest extends ContextTest {
|
|||
|
||||
@Test
|
||||
public void testRequiredFields() throws InvalidValueException {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
ServiceUsageRecord serviceUsageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
||||
Assert.assertTrue(serviceUsageRecord.getScope()==null);
|
||||
serviceUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
|
@ -58,8 +54,6 @@ public class AggregatedServiceUsageRecordTest extends ContextTest {
|
|||
|
||||
@Test
|
||||
public void secondAsNotAggregated() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
ServiceUsageRecord serviceUsageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
||||
Assert.assertTrue(serviceUsageRecord.getScope()==null);
|
||||
serviceUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
|
@ -105,8 +99,6 @@ public class AggregatedServiceUsageRecordTest extends ContextTest {
|
|||
|
||||
@Test
|
||||
public void secondAsAggregated() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
ServiceUsageRecord serviceUsageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
||||
Assert.assertTrue(serviceUsageRecord.getScope()==null);
|
||||
serviceUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
|
@ -155,8 +147,6 @@ public class AggregatedServiceUsageRecordTest extends ContextTest {
|
|||
|
||||
@Test
|
||||
public void aggregationStressTest() throws InvalidValueException, NotAggregatableRecordsExceptions, JsonProcessingException {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
ServiceUsageRecord serviceUsageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
||||
Assert.assertTrue(serviceUsageRecord.getScope()==null);
|
||||
serviceUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
|
|
|
@ -7,8 +7,6 @@ import java.util.Set;
|
|||
|
||||
import org.gcube.accounting.datamodel.usagerecords.StorageStatusRecord;
|
||||
import org.gcube.accounting.datamodel.usagerecords.StorageStatusRecordTest;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.documentstore.exception.InvalidValueException;
|
||||
import org.gcube.documentstore.exception.NotAggregatableRecordsExceptions;
|
||||
import org.gcube.testutility.ContextTest;
|
||||
|
@ -28,8 +26,6 @@ public class AggregatedStorageStatusRecordTest extends ContextTest {
|
|||
|
||||
@Test
|
||||
public void testRequiredFields() throws InvalidValueException {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
StorageStatusRecord storageVolumeUsageRecord = TestUsageRecord.createTestStorageVolumeUsageRecord();
|
||||
Assert.assertTrue(storageVolumeUsageRecord.getScope()==null);
|
||||
storageVolumeUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
|
@ -52,8 +48,6 @@ public class AggregatedStorageStatusRecordTest extends ContextTest {
|
|||
|
||||
@Test
|
||||
public void secondAsNotAggregated() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
StorageStatusRecord storageStatusUsageRecord = TestUsageRecord.createTestStorageVolumeUsageRecord();
|
||||
Assert.assertTrue(storageStatusUsageRecord.getScope()==null);
|
||||
storageStatusUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
|
@ -90,8 +84,6 @@ public class AggregatedStorageStatusRecordTest extends ContextTest {
|
|||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void secondAsAggregated() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
StorageStatusRecord storageStatusUsageRecord = TestUsageRecord.createTestStorageVolumeUsageRecord();
|
||||
storageStatusUsageRecord.setDataServiceClass("DataServiceClass1");
|
||||
storageStatusUsageRecord.setDataServiceName("DataServiceName1");
|
||||
|
@ -138,8 +130,6 @@ public class AggregatedStorageStatusRecordTest extends ContextTest {
|
|||
|
||||
@Test
|
||||
public void aggregationStressTest() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
StorageStatusRecord storageVolumeUsageRecord = TestUsageRecord.createTestStorageVolumeUsageRecord();
|
||||
Assert.assertTrue(storageVolumeUsageRecord.getScope()==null);
|
||||
storageVolumeUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
|
|
|
@ -8,8 +8,6 @@ import java.util.Set;
|
|||
|
||||
import org.gcube.accounting.datamodel.usagerecords.StorageUsageRecord;
|
||||
import org.gcube.accounting.datamodel.usagerecords.StorageUsageRecordTest;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.documentstore.exception.InvalidValueException;
|
||||
import org.gcube.documentstore.exception.NotAggregatableRecordsExceptions;
|
||||
import org.gcube.testutility.ContextTest;
|
||||
|
@ -29,8 +27,6 @@ public class AggregatedStorageUsageRecordTest extends ContextTest {
|
|||
|
||||
@Test
|
||||
public void testRequiredFields() throws InvalidValueException {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
StorageUsageRecord storageUsageRecord = TestUsageRecord.createTestStorageUsageRecord();
|
||||
Assert.assertTrue(storageUsageRecord.getScope()==null);
|
||||
storageUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
|
@ -53,8 +49,6 @@ public class AggregatedStorageUsageRecordTest extends ContextTest {
|
|||
|
||||
@Test
|
||||
public void secondAsNotAggregated() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
StorageUsageRecord storageUsageRecord = TestUsageRecord.createTestStorageUsageRecord();
|
||||
Assert.assertTrue(storageUsageRecord.getScope()==null);
|
||||
storageUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
|
@ -88,8 +82,6 @@ public class AggregatedStorageUsageRecordTest extends ContextTest {
|
|||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void secondAsAggregated() throws Exception {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
StorageUsageRecord storageUsageRecord = TestUsageRecord.createTestStorageUsageRecord();
|
||||
storageUsageRecord.setResourceScope("/gcube");
|
||||
storageUsageRecord.setResourceURI(new URI("resourceURI"));
|
||||
|
@ -130,8 +122,6 @@ public class AggregatedStorageUsageRecordTest extends ContextTest {
|
|||
|
||||
@Test
|
||||
public void aggregationStressTest() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
StorageUsageRecord storageUsageRecord = TestUsageRecord.createTestStorageUsageRecord();
|
||||
Assert.assertTrue(storageUsageRecord.getScope()==null);
|
||||
storageUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
|
|
|
@ -8,8 +8,6 @@ import java.util.Set;
|
|||
|
||||
import org.gcube.accounting.datamodel.UsageRecord;
|
||||
import org.gcube.accounting.datamodel.basetypes.AbstractJobUsageRecord;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.documentstore.exception.InvalidValueException;
|
||||
import org.gcube.documentstore.records.Record;
|
||||
import org.gcube.testutility.ContextTest;
|
||||
|
@ -46,8 +44,6 @@ public class JobUsageRecordTest extends ContextTest {
|
|||
|
||||
@Test(expected=InvalidValueException.class)
|
||||
public void scopeNotSetValidationError() throws InvalidValueException {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
JobUsageRecord usageRecord = TestUsageRecord.createTestJobUsageRecord();
|
||||
usageRecord.validate();
|
||||
logger.debug("{}", usageRecord);
|
||||
|
@ -55,8 +51,6 @@ public class JobUsageRecordTest extends ContextTest {
|
|||
|
||||
@Test
|
||||
public void testRequiredFields() throws InvalidValueException{
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
JobUsageRecord usageRecord = TestUsageRecord.createTestJobUsageRecord();
|
||||
Assert.assertTrue(usageRecord.getScope()==null);
|
||||
usageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
|
|
|
@ -13,8 +13,6 @@ import org.gcube.accounting.datamodel.UsageRecord;
|
|||
import org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord;
|
||||
import org.gcube.accounting.datamodel.basetypes.AbstractServiceUsageRecord;
|
||||
import org.gcube.accounting.datamodel.validations.validators.MatcherReplace;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.documentstore.exception.InvalidValueException;
|
||||
import org.gcube.documentstore.records.DSMapper;
|
||||
import org.gcube.documentstore.records.Record;
|
||||
|
@ -53,8 +51,6 @@ public class ServiceUsageRecordTest extends ContextTest {
|
|||
|
||||
@Test(expected=InvalidValueException.class)
|
||||
public void scopeNotSetValidationError() throws InvalidValueException {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
ServiceUsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
||||
usageRecord.validate();
|
||||
logger.debug("{}", usageRecord);
|
||||
|
@ -62,8 +58,6 @@ public class ServiceUsageRecordTest extends ContextTest {
|
|||
|
||||
@Test
|
||||
public void testRequiredFields() throws InvalidValueException{
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
ServiceUsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
||||
Assert.assertTrue(usageRecord.getScope()==null);
|
||||
usageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
|
|
|
@ -8,8 +8,6 @@ import java.util.Set;
|
|||
|
||||
import org.gcube.accounting.datamodel.UsageRecord;
|
||||
import org.gcube.accounting.datamodel.basetypes.AbstractStorageStatusRecord;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.documentstore.exception.InvalidValueException;
|
||||
import org.gcube.documentstore.records.Record;
|
||||
import org.gcube.testutility.ContextTest;
|
||||
|
@ -44,8 +42,6 @@ public class StorageStatusRecordTest extends ContextTest {
|
|||
|
||||
@Test(expected=InvalidValueException.class)
|
||||
public void scopeNotSetValidationError() throws InvalidValueException {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
StorageStatusRecord usageRecord = TestUsageRecord.createTestStorageVolumeUsageRecord();
|
||||
usageRecord.validate();
|
||||
logger.debug("{}", usageRecord);
|
||||
|
@ -53,8 +49,6 @@ public class StorageStatusRecordTest extends ContextTest {
|
|||
|
||||
@Test
|
||||
public void testRequiredFields() throws InvalidValueException{
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
StorageStatusRecord usageRecord = TestUsageRecord.createTestStorageVolumeUsageRecord();
|
||||
Assert.assertTrue(usageRecord.getScope()==null);
|
||||
usageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
|
|
|
@ -8,8 +8,6 @@ import java.util.Set;
|
|||
|
||||
import org.gcube.accounting.datamodel.UsageRecord;
|
||||
import org.gcube.accounting.datamodel.basetypes.AbstractStorageUsageRecord;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.documentstore.exception.InvalidValueException;
|
||||
import org.gcube.documentstore.records.Record;
|
||||
import org.gcube.testutility.ContextTest;
|
||||
|
@ -45,8 +43,6 @@ public class StorageUsageRecordTest extends ContextTest {
|
|||
|
||||
@Test(expected=InvalidValueException.class)
|
||||
public void scopeNotSetValidationError() throws InvalidValueException {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
StorageUsageRecord usageRecord = TestUsageRecord.createTestStorageUsageRecord();
|
||||
usageRecord.validate();
|
||||
logger.debug("{}", usageRecord);
|
||||
|
@ -54,8 +50,6 @@ public class StorageUsageRecordTest extends ContextTest {
|
|||
|
||||
@Test
|
||||
public void testRequiredFields() throws InvalidValueException{
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
StorageUsageRecord usageRecord = TestUsageRecord.createTestStorageUsageRecord();
|
||||
Assert.assertTrue(usageRecord.getScope()==null);
|
||||
usageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
|
|
|
@ -23,7 +23,7 @@ public class ValidTimeValidatorTest {
|
|||
@Test
|
||||
public void testClassLong() throws InvalidValueException{
|
||||
ValidLongValidator validTimeValidator = new ValidLongValidator();
|
||||
Long myLong = new Long(4);
|
||||
Long myLong = 4l;
|
||||
validTimeValidator.validate(null, myLong, null);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,14 +7,9 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.gcube.common.authorization.client.Constants;
|
||||
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
|
||||
import org.gcube.common.authorization.library.AuthorizationEntry;
|
||||
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
||||
import org.gcube.common.authorization.library.provider.ClientInfo;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.authorization.library.utils.Caller;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.security.Owner;
|
||||
import org.gcube.common.security.secrets.GCubeSecret;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -67,8 +62,8 @@ public class ContextTest {
|
|||
}
|
||||
|
||||
public static String getCurrentScope(String token) throws ObjectNotFound, Exception {
|
||||
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
|
||||
String context = authorizationEntry.getContext();
|
||||
GCubeSecret secret = new GCubeSecret(token);
|
||||
String context = secret.getContext();
|
||||
logger.info("Context of token {} is {}", token, context);
|
||||
return context;
|
||||
}
|
||||
|
@ -79,14 +74,9 @@ public class ContextTest {
|
|||
}
|
||||
|
||||
private static void setContext(String token) throws ObjectNotFound, Exception {
|
||||
SecurityTokenProvider.instance.set(token);
|
||||
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
|
||||
ClientInfo clientInfo = authorizationEntry.getClientInfo();
|
||||
logger.debug("User : {} - Type : {}", clientInfo.getId(), clientInfo.getType().name());
|
||||
String qualifier = authorizationEntry.getQualifier();
|
||||
Caller caller = new Caller(clientInfo, qualifier);
|
||||
AuthorizationProvider.instance.set(caller);
|
||||
ScopeProvider.instance.set(getCurrentScope(token));
|
||||
GCubeSecret secret = new GCubeSecret(token);
|
||||
Owner clientInfo = secret.getOwner();
|
||||
logger.debug("User : {} - external client? ok: {}", clientInfo.getId(), clientInfo.isExternalClient());
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
|
@ -96,8 +86,6 @@ public class ContextTest {
|
|||
|
||||
@AfterClass
|
||||
public static void afterClass() throws Exception {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue