21 changed files with 642 additions and 1 deletions
@ -0,0 +1,28 @@ |
|||
/** |
|||
* Copyright © 2016-2020 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.dao.usagerecord; |
|||
|
|||
import org.thingsboard.server.common.data.UsageRecord; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
|
|||
public interface UsageRecordService { |
|||
|
|||
UsageRecord findTenantUsageRecord(TenantId tenantId); |
|||
|
|||
void deleteUsageRecordsByTenantId(TenantId tenantId); |
|||
|
|||
void createDefaultUsageRecord(TenantId id); |
|||
} |
|||
@ -0,0 +1,65 @@ |
|||
/** |
|||
* Copyright © 2016-2020 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.common.data; |
|||
|
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.ToString; |
|||
import org.thingsboard.server.common.data.id.EntityId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.id.UsageRecordId; |
|||
import org.thingsboard.server.common.data.id.UserId; |
|||
|
|||
@ToString |
|||
@EqualsAndHashCode(callSuper = true) |
|||
public class UsageRecord extends BaseData<UsageRecordId> implements HasTenantId { |
|||
|
|||
private static final long serialVersionUID = 8250339805336035966L; |
|||
|
|||
private TenantId tenantId; |
|||
private EntityId entityId; |
|||
|
|||
public UsageRecord() { |
|||
super(); |
|||
} |
|||
|
|||
public UsageRecord(UsageRecordId id) { |
|||
super(id); |
|||
} |
|||
|
|||
public UsageRecord(UsageRecord ur) { |
|||
super(ur); |
|||
this.tenantId = ur.getTenantId(); |
|||
this.entityId = ur.getEntityId(); |
|||
} |
|||
|
|||
@Override |
|||
public TenantId getTenantId() { |
|||
return tenantId; |
|||
} |
|||
|
|||
public void setTenantId(TenantId tenantId) { |
|||
this.tenantId = tenantId; |
|||
} |
|||
|
|||
public EntityId getEntityId() { |
|||
return entityId; |
|||
} |
|||
|
|||
public void setEntityId(EntityId entityId) { |
|||
this.entityId = entityId; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,27 @@ |
|||
/** |
|||
* Copyright © 2016-2020 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.common.data; |
|||
|
|||
public enum UsageRecordKey { |
|||
|
|||
MSG_COUNT, |
|||
MSG_BYTES_COUNT, |
|||
DP_TRANSPORT_COUNT, |
|||
DP_STORAGE_COUNT, |
|||
RE_EXEC_COUNT, |
|||
JS_EXEC_COUNT |
|||
|
|||
} |
|||
@ -0,0 +1,42 @@ |
|||
/** |
|||
* Copyright © 2016-2020 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.common.data.id; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonCreator; |
|||
import com.fasterxml.jackson.annotation.JsonIgnore; |
|||
import com.fasterxml.jackson.annotation.JsonProperty; |
|||
import org.thingsboard.server.common.data.EntityType; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
public class UsageRecordId extends UUIDBased implements EntityId { |
|||
|
|||
@JsonCreator |
|||
public UsageRecordId(@JsonProperty("id") UUID id) { |
|||
super(id); |
|||
} |
|||
|
|||
public static UsageRecordId fromString(String userId) { |
|||
return new UsageRecordId(UUID.fromString(userId)); |
|||
} |
|||
|
|||
@JsonIgnore |
|||
@Override |
|||
public EntityType getEntityType() { |
|||
return EntityType.USAGE_RECORD; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,93 @@ |
|||
/** |
|||
* Copyright © 2016-2020 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.dao.model.sql; |
|||
|
|||
import com.fasterxml.jackson.databind.JsonNode; |
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
import org.hibernate.annotations.Type; |
|||
import org.hibernate.annotations.TypeDef; |
|||
import org.thingsboard.server.common.data.UsageRecord; |
|||
import org.thingsboard.server.common.data.User; |
|||
import org.thingsboard.server.common.data.id.CustomerId; |
|||
import org.thingsboard.server.common.data.id.EntityIdFactory; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.id.UsageRecordId; |
|||
import org.thingsboard.server.common.data.id.UserId; |
|||
import org.thingsboard.server.common.data.security.Authority; |
|||
import org.thingsboard.server.dao.model.BaseEntity; |
|||
import org.thingsboard.server.dao.model.BaseSqlEntity; |
|||
import org.thingsboard.server.dao.model.ModelConstants; |
|||
import org.thingsboard.server.dao.model.SearchTextEntity; |
|||
import org.thingsboard.server.dao.util.mapping.JsonStringType; |
|||
|
|||
import javax.persistence.Column; |
|||
import javax.persistence.Entity; |
|||
import javax.persistence.EnumType; |
|||
import javax.persistence.Enumerated; |
|||
import javax.persistence.Table; |
|||
import java.util.UUID; |
|||
|
|||
/** |
|||
* Created by Valerii Sosliuk on 4/21/2017. |
|||
*/ |
|||
@Data |
|||
@EqualsAndHashCode(callSuper = true) |
|||
@Entity |
|||
@TypeDef(name = "json", typeClass = JsonStringType.class) |
|||
@Table(name = ModelConstants.UR_TABLE_NAME) |
|||
public class UsageRecordEntity extends BaseSqlEntity<UsageRecord> implements BaseEntity<UsageRecord> { |
|||
|
|||
@Column(name = ModelConstants.UR_TENANT_ID_COLUMN) |
|||
private UUID tenantId; |
|||
|
|||
@Column(name = ModelConstants.UR_ENTITY_TYPE_COLUMN) |
|||
private String entityType; |
|||
|
|||
@Column(name = ModelConstants.UR_ENTITY_ID_COLUMN) |
|||
private UUID entityId; |
|||
|
|||
public UsageRecordEntity() { |
|||
} |
|||
|
|||
public UsageRecordEntity(UsageRecord ur) { |
|||
if (ur.getId() != null) { |
|||
this.setUuid(ur.getId().getId()); |
|||
} |
|||
this.setCreatedTime(ur.getCreatedTime()); |
|||
if (ur.getTenantId() != null) { |
|||
this.tenantId = ur.getTenantId().getId(); |
|||
} |
|||
if (ur.getEntityId() != null) { |
|||
this.entityType = ur.getEntityId().getEntityType().name(); |
|||
this.entityId = ur.getEntityId().getId(); |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public UsageRecord toData() { |
|||
UsageRecord ur = new UsageRecord(new UsageRecordId(this.getUuid())); |
|||
ur.setCreatedTime(createdTime); |
|||
if (tenantId != null) { |
|||
ur.setTenantId(new TenantId(tenantId)); |
|||
} |
|||
if (entityId != null) { |
|||
ur.setEntityId(EntityIdFactory.getByTypeAndUuid(entityType, entityId)); |
|||
} |
|||
return ur; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,60 @@ |
|||
/** |
|||
* Copyright © 2016-2020 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.dao.sql.usagerecord; |
|||
|
|||
import org.springframework.data.repository.CrudRepository; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.common.data.UsageRecord; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.dao.DaoUtil; |
|||
import org.thingsboard.server.dao.model.sql.UsageRecordEntity; |
|||
import org.thingsboard.server.dao.sql.JpaAbstractDao; |
|||
import org.thingsboard.server.dao.usagerecord.UsageRecordDao; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
/** |
|||
* @author Andrii Shvaika |
|||
*/ |
|||
@Component |
|||
public class JpaUsageRecordDao extends JpaAbstractDao<UsageRecordEntity, UsageRecord> implements UsageRecordDao { |
|||
|
|||
private final UsageRecordRepository usageRecordRepository; |
|||
|
|||
public JpaUsageRecordDao(UsageRecordRepository usageRecordRepository) { |
|||
this.usageRecordRepository = usageRecordRepository; |
|||
} |
|||
|
|||
@Override |
|||
protected Class<UsageRecordEntity> getEntityClass() { |
|||
return UsageRecordEntity.class; |
|||
} |
|||
|
|||
@Override |
|||
protected CrudRepository<UsageRecordEntity, UUID> getCrudRepository() { |
|||
return usageRecordRepository; |
|||
} |
|||
|
|||
@Override |
|||
public UsageRecord findTenantUsageRecord(UUID tenantId) { |
|||
return DaoUtil.getData(usageRecordRepository.findByTenantId(tenantId)); |
|||
} |
|||
|
|||
@Override |
|||
public void deleteUsageRecordsByTenantId(TenantId tenantId) { |
|||
usageRecordRepository.deleteUsageRecordsByTenantId(tenantId.getId()); |
|||
} |
|||
} |
|||
@ -0,0 +1,43 @@ |
|||
/** |
|||
* Copyright © 2016-2020 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.dao.sql.usagerecord; |
|||
|
|||
import org.springframework.data.jpa.repository.Modifying; |
|||
import org.springframework.data.jpa.repository.Query; |
|||
import org.springframework.data.repository.CrudRepository; |
|||
import org.springframework.data.repository.query.Param; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
import org.thingsboard.server.common.data.UsageRecord; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.dao.model.sql.UsageRecordEntity; |
|||
import org.thingsboard.server.dao.model.sql.UserEntity; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
/** |
|||
* @author Valerii Sosliuk |
|||
*/ |
|||
public interface UsageRecordRepository extends CrudRepository<UsageRecordEntity, UUID> { |
|||
|
|||
@Query("SELECT ur FROM UsageRecordEntity ur WHERE ur.tenantId = :tenantId " + |
|||
"AND ur.entityId = :tenantId AND ur.entityType = 'TENANT' ") |
|||
UsageRecordEntity findByTenantId(@Param("tenantId") UUID tenantId); |
|||
|
|||
@Transactional |
|||
@Modifying |
|||
@Query("DELETE FROM UsageRecordEntity ur WHERE ur.tenantId = :tenantId") |
|||
void deleteUsageRecordsByTenantId(@Param("tenantId") UUID tenantId); |
|||
} |
|||
@ -0,0 +1,51 @@ |
|||
/** |
|||
* Copyright © 2016-2020 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.dao.usagerecord; |
|||
|
|||
import org.thingsboard.server.common.data.UsageRecord; |
|||
import org.thingsboard.server.common.data.User; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.page.PageData; |
|||
import org.thingsboard.server.common.data.page.PageLink; |
|||
import org.thingsboard.server.dao.Dao; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
public interface UsageRecordDao extends Dao<UsageRecord> { |
|||
|
|||
/** |
|||
* Save or update usage record object |
|||
* |
|||
* @param usageRecord the usage record |
|||
* @return saved usage record entity |
|||
*/ |
|||
UsageRecord save(TenantId tenantId, UsageRecord usageRecord); |
|||
|
|||
/** |
|||
* Find usage record by tenantId. |
|||
* |
|||
* @param tenantId the tenantId |
|||
* @return the corresponding usage record |
|||
*/ |
|||
UsageRecord findTenantUsageRecord(UUID tenantId); |
|||
|
|||
/** |
|||
* Delete usage record by tenantId. |
|||
* |
|||
* @param tenantId the tenantId |
|||
*/ |
|||
void deleteUsageRecordsByTenantId(TenantId tenantId); |
|||
} |
|||
@ -0,0 +1,112 @@ |
|||
/** |
|||
* Copyright © 2016-2020 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.dao.usagerecord; |
|||
|
|||
import com.fasterxml.jackson.databind.JsonNode; |
|||
import com.fasterxml.jackson.databind.node.ObjectNode; |
|||
import com.google.common.util.concurrent.ListenableFuture; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.apache.commons.lang3.RandomStringUtils; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.util.StringUtils; |
|||
import org.thingsboard.server.common.data.Customer; |
|||
import org.thingsboard.server.common.data.EntityType; |
|||
import org.thingsboard.server.common.data.Tenant; |
|||
import org.thingsboard.server.common.data.UsageRecord; |
|||
import org.thingsboard.server.common.data.User; |
|||
import org.thingsboard.server.common.data.id.CustomerId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.id.UserCredentialsId; |
|||
import org.thingsboard.server.common.data.id.UserId; |
|||
import org.thingsboard.server.common.data.page.PageData; |
|||
import org.thingsboard.server.common.data.page.PageLink; |
|||
import org.thingsboard.server.common.data.security.UserCredentials; |
|||
import org.thingsboard.server.dao.entity.AbstractEntityService; |
|||
import org.thingsboard.server.dao.exception.DataValidationException; |
|||
import org.thingsboard.server.dao.exception.IncorrectParameterException; |
|||
import org.thingsboard.server.dao.model.ModelConstants; |
|||
import org.thingsboard.server.dao.service.DataValidator; |
|||
import org.thingsboard.server.dao.tenant.TenantDao; |
|||
|
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
|
|||
import static org.thingsboard.server.dao.service.Validator.validateId; |
|||
import static org.thingsboard.server.dao.service.Validator.validatePageLink; |
|||
import static org.thingsboard.server.dao.service.Validator.validateString; |
|||
|
|||
@Service |
|||
@Slf4j |
|||
public class UsageRecordServiceImpl extends AbstractEntityService implements UsageRecordService { |
|||
public static final String INCORRECT_TENANT_ID = "Incorrect tenantId "; |
|||
|
|||
private final UsageRecordDao usageRecordDao; |
|||
private final TenantDao tenantDao; |
|||
|
|||
public UsageRecordServiceImpl(TenantDao tenantDao, UsageRecordDao usageRecordDao) { |
|||
this.tenantDao = tenantDao; |
|||
this.usageRecordDao = usageRecordDao; |
|||
} |
|||
|
|||
@Override |
|||
public void deleteUsageRecordsByTenantId(TenantId tenantId) { |
|||
log.trace("Executing deleteUsageRecordsByTenantId [{}]", tenantId); |
|||
validateId(tenantId, INCORRECT_TENANT_ID + tenantId); |
|||
usageRecordDao.deleteUsageRecordsByTenantId(tenantId); |
|||
} |
|||
|
|||
@Override |
|||
public void createDefaultUsageRecord(TenantId tenantId) { |
|||
log.trace("Executing createDefaultUsageRecord [{}]", tenantId); |
|||
validateId(tenantId, INCORRECT_TENANT_ID + tenantId); |
|||
UsageRecord usageRecord = new UsageRecord(); |
|||
usageRecord.setTenantId(tenantId); |
|||
usageRecord.setEntityId(tenantId); |
|||
usageRecordValidator.validate(usageRecord, UsageRecord::getTenantId); |
|||
usageRecordDao.save(usageRecord.getTenantId(), usageRecord); |
|||
} |
|||
|
|||
@Override |
|||
public UsageRecord findTenantUsageRecord(TenantId tenantId) { |
|||
log.trace("Executing findTenantUsageRecord, tenantId [{}]", tenantId); |
|||
validateId(tenantId, INCORRECT_TENANT_ID + tenantId); |
|||
return usageRecordDao.findTenantUsageRecord(tenantId.getId()); |
|||
} |
|||
|
|||
private DataValidator<UsageRecord> usageRecordValidator = |
|||
new DataValidator<UsageRecord>() { |
|||
@Override |
|||
protected void validateDataImpl(TenantId requestTenantId, UsageRecord usageRecord) { |
|||
if (usageRecord.getTenantId() == null) { |
|||
throw new DataValidationException("UsageRecord should be assigned to tenant!"); |
|||
} else { |
|||
Tenant tenant = tenantDao.findById(requestTenantId, usageRecord.getTenantId().getId()); |
|||
if (tenant == null) { |
|||
throw new DataValidationException("Asset is referencing to non-existent tenant!"); |
|||
} |
|||
} |
|||
if (usageRecord.getEntityId() == null) { |
|||
throw new DataValidationException("UsageRecord should be assigned to entity!"); |
|||
} else if (!EntityType.TENANT.equals(usageRecord.getEntityId().getEntityType())) { |
|||
throw new DataValidationException("Only Tenant Usage Records are supported!"); |
|||
} else if (!usageRecord.getTenantId().getId().equals(usageRecord.getEntityId().getId())) { |
|||
throw new DataValidationException("Can't assign one Usage Record to multiple tenants!"); |
|||
} |
|||
} |
|||
}; |
|||
|
|||
} |
|||
@ -0,0 +1,56 @@ |
|||
/** |
|||
* Copyright © 2016-2020 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.dao.service; |
|||
|
|||
import org.junit.After; |
|||
import org.junit.Assert; |
|||
import org.junit.Before; |
|||
import org.junit.Test; |
|||
import org.thingsboard.server.common.data.Customer; |
|||
import org.thingsboard.server.common.data.Tenant; |
|||
import org.thingsboard.server.common.data.UsageRecord; |
|||
import org.thingsboard.server.common.data.User; |
|||
import org.thingsboard.server.common.data.id.CustomerId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.dao.service.AbstractServiceTest; |
|||
import org.thingsboard.server.dao.service.DaoSqlTest; |
|||
|
|||
|
|||
public abstract class BaseUsageRecordServiceTest extends AbstractServiceTest { |
|||
|
|||
private TenantId tenantId; |
|||
|
|||
@Before |
|||
public void before() { |
|||
Tenant tenant = new Tenant(); |
|||
tenant.setTitle("My tenant"); |
|||
Tenant savedTenant = tenantService.saveTenant(tenant); |
|||
Assert.assertNotNull(savedTenant); |
|||
tenantId = savedTenant.getId(); |
|||
} |
|||
|
|||
@After |
|||
public void after() { |
|||
tenantService.deleteTenant(tenantId); |
|||
} |
|||
|
|||
@Test |
|||
public void testFindUsageRecordByTenantId() { |
|||
UsageRecord usageRecord = usageRecordService.findTenantUsageRecord(tenantId); |
|||
Assert.assertNotNull(usageRecord); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,24 @@ |
|||
/** |
|||
* Copyright © 2016-2020 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.dao.service.sql; |
|||
|
|||
import org.thingsboard.server.dao.service.BaseUsageRecordServiceTest; |
|||
import org.thingsboard.server.dao.service.BaseUserServiceTest; |
|||
import org.thingsboard.server.dao.service.DaoSqlTest; |
|||
|
|||
@DaoSqlTest |
|||
public class UsageRecordServiceSqlTest extends BaseUsageRecordServiceTest { |
|||
} |
|||
Loading…
Reference in new issue