committed by
GitHub
46 changed files with 966 additions and 102 deletions
@ -0,0 +1,37 @@ |
|||
/** |
|||
* Copyright © 2016-2024 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.queue; |
|||
|
|||
import org.thingsboard.server.common.data.id.QueueStatsId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.queue.QueueStats; |
|||
import org.thingsboard.server.dao.entity.EntityDaoService; |
|||
|
|||
import java.util.List; |
|||
|
|||
public interface QueueStatsService extends EntityDaoService { |
|||
|
|||
QueueStats save(TenantId tenantId, QueueStats queueStats); |
|||
|
|||
QueueStats findQueueStatsById(TenantId tenantId, QueueStatsId queueStatsId); |
|||
|
|||
QueueStats findByTenantIdAndNameAndServiceId(TenantId tenantId, String queueName, String serviceId); |
|||
|
|||
List<QueueStats> findByTenantId(TenantId tenantId); |
|||
|
|||
void deleteByTenantId(TenantId tenantId); |
|||
|
|||
} |
|||
@ -0,0 +1,43 @@ |
|||
/** |
|||
* Copyright © 2016-2024 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.JsonProperty; |
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import org.thingsboard.server.common.data.EntityType; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
public class QueueStatsId extends UUIDBased implements EntityId { |
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
@JsonCreator |
|||
public QueueStatsId(@JsonProperty("id") UUID id) { |
|||
super(id); |
|||
} |
|||
|
|||
public static QueueStatsId fromString(String queueId) { |
|||
return new QueueStatsId(UUID.fromString(queueId)); |
|||
} |
|||
|
|||
@Schema(required = true, description = "string", example = "QUEUE_STATS", allowableValues = "QUEUE_STATS") |
|||
@Override |
|||
public EntityType getEntityType() { |
|||
return EntityType.QUEUE_STATS; |
|||
} |
|||
} |
|||
@ -0,0 +1,39 @@ |
|||
/** |
|||
* Copyright © 2016-2024 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.queue; |
|||
|
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
import org.thingsboard.server.common.data.BaseData; |
|||
import org.thingsboard.server.common.data.HasTenantId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.id.QueueStatsId; |
|||
|
|||
@EqualsAndHashCode(callSuper = true) |
|||
@Data |
|||
public class QueueStats extends BaseData<QueueStatsId> implements HasTenantId { |
|||
private TenantId tenantId; |
|||
private String queueName; |
|||
private String serviceId; |
|||
|
|||
public QueueStats() { |
|||
} |
|||
|
|||
public QueueStats(QueueStatsId id) { |
|||
super(id); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,69 @@ |
|||
/** |
|||
* Copyright © 2016-2024 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 lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
import org.thingsboard.server.common.data.id.QueueStatsId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.queue.QueueStats; |
|||
import org.thingsboard.server.dao.DaoUtil; |
|||
import org.thingsboard.server.dao.model.BaseSqlEntity; |
|||
import org.thingsboard.server.dao.model.ModelConstants; |
|||
|
|||
import jakarta.persistence.Column; |
|||
import jakarta.persistence.Entity; |
|||
import jakarta.persistence.Table; |
|||
import java.util.UUID; |
|||
|
|||
@Data |
|||
@EqualsAndHashCode(callSuper = true) |
|||
@Entity |
|||
@Table(name = ModelConstants.QUEUE_STATS_TABLE_NAME) |
|||
public class QueueStatsEntity extends BaseSqlEntity<QueueStats> { |
|||
|
|||
@Column(name = ModelConstants.QUEUE_STATS_TENANT_ID_PROPERTY) |
|||
private UUID tenantId; |
|||
|
|||
@Column(name = ModelConstants.QUEUE_STATS_QUEUE_NAME_PROPERTY) |
|||
private String queueName; |
|||
|
|||
@Column(name = ModelConstants.QUEUE_STATS_SERVICE_ID_PROPERTY) |
|||
private String serviceId; |
|||
|
|||
public QueueStatsEntity() { |
|||
} |
|||
|
|||
public QueueStatsEntity(QueueStats queueStats) { |
|||
if (queueStats.getId() != null) { |
|||
this.setId(queueStats.getId().getId()); |
|||
} |
|||
this.setCreatedTime(queueStats.getCreatedTime()); |
|||
this.tenantId = DaoUtil.getId(queueStats.getTenantId()); |
|||
this.queueName = queueStats.getQueueName(); |
|||
this.serviceId = queueStats.getServiceId(); |
|||
} |
|||
|
|||
@Override |
|||
public QueueStats toData() { |
|||
QueueStats queueStats = new QueueStats(new QueueStatsId(getUuid())); |
|||
queueStats.setCreatedTime(createdTime); |
|||
queueStats.setTenantId(new TenantId(tenantId)); |
|||
queueStats.setQueueName(queueName); |
|||
queueStats.setServiceId(serviceId); |
|||
return queueStats; |
|||
} |
|||
} |
|||
@ -0,0 +1,90 @@ |
|||
/** |
|||
* Copyright © 2016-2024 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.queue; |
|||
|
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Service; |
|||
import org.thingsboard.server.common.data.EntityType; |
|||
import org.thingsboard.server.common.data.id.EntityId; |
|||
import org.thingsboard.server.common.data.id.HasId; |
|||
import org.thingsboard.server.common.data.id.QueueStatsId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.queue.QueueStats; |
|||
import org.thingsboard.server.dao.entity.AbstractEntityService; |
|||
import org.thingsboard.server.dao.service.DataValidator; |
|||
|
|||
import java.util.List; |
|||
import java.util.Optional; |
|||
|
|||
import static org.thingsboard.server.dao.service.Validator.validateId; |
|||
|
|||
@Service("QueueStatsDaoService") |
|||
@Slf4j |
|||
@RequiredArgsConstructor |
|||
public class BaseQueueStatsService extends AbstractEntityService implements QueueStatsService { |
|||
|
|||
public static final String INCORRECT_TENANT_ID = "Incorrect tenantId "; |
|||
|
|||
private final QueueStatsDao queueStatsDao; |
|||
|
|||
private final DataValidator<QueueStats> queueStatsValidator; |
|||
|
|||
@Override |
|||
public QueueStats save(TenantId tenantId, QueueStats queueStats) { |
|||
log.trace("Executing save [{}]", queueStats); |
|||
queueStatsValidator.validate(queueStats, QueueStats::getTenantId); |
|||
return queueStatsDao.save(tenantId, queueStats); |
|||
} |
|||
|
|||
@Override |
|||
public QueueStats findQueueStatsById(TenantId tenantId, QueueStatsId queueStatsId) { |
|||
log.trace("Executing findQueueStatsById [{}]", queueStatsId); |
|||
validateId(queueStatsId, "Incorrect queueStatsId " + queueStatsId); |
|||
return queueStatsDao.findById(tenantId, queueStatsId.getId()); |
|||
} |
|||
|
|||
@Override |
|||
public QueueStats findByTenantIdAndNameAndServiceId(TenantId tenantId, String queueName, String serviceId) { |
|||
log.trace("Executing findByTenantIdAndNameAndServiceId, tenantId: [{}], queueName: [{}], serviceId: [{}]", tenantId, queueName, serviceId); |
|||
validateId(tenantId, INCORRECT_TENANT_ID + tenantId); |
|||
return queueStatsDao.findByTenantIdQueueNameAndServiceId(tenantId, queueName, serviceId); |
|||
} |
|||
|
|||
@Override |
|||
public List<QueueStats> findByTenantId(TenantId tenantId) { |
|||
log.trace("Executing findByTenantId, tenantId: [{}]", tenantId); |
|||
validateId(tenantId, INCORRECT_TENANT_ID + tenantId); |
|||
return queueStatsDao.findByTenantId(tenantId); |
|||
} |
|||
|
|||
@Override |
|||
public void deleteByTenantId(TenantId tenantId) { |
|||
log.trace("Executing deleteByTenantId, tenantId [{}]", tenantId); |
|||
validateId(tenantId, INCORRECT_TENANT_ID + tenantId); |
|||
queueStatsDao.deleteByTenantId(tenantId); |
|||
} |
|||
|
|||
@Override |
|||
public Optional<HasId<?>> findEntity(TenantId tenantId, EntityId entityId) { |
|||
return Optional.ofNullable(findQueueStatsById(tenantId, new QueueStatsId(entityId.getId()))); |
|||
} |
|||
|
|||
@Override |
|||
public EntityType getEntityType() { |
|||
return EntityType.QUEUE_STATS; |
|||
} |
|||
} |
|||
@ -0,0 +1,32 @@ |
|||
/** |
|||
* Copyright © 2016-2024 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.queue; |
|||
|
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.queue.QueueStats; |
|||
import org.thingsboard.server.dao.Dao; |
|||
|
|||
import java.util.List; |
|||
|
|||
public interface QueueStatsDao extends Dao<QueueStats> { |
|||
|
|||
QueueStats findByTenantIdQueueNameAndServiceId(TenantId tenantId, String queueName, String serviceId); |
|||
|
|||
List<QueueStats> findByTenantId(TenantId tenantId); |
|||
|
|||
void deleteByTenantId(TenantId tenantId); |
|||
|
|||
} |
|||
@ -0,0 +1,40 @@ |
|||
/** |
|||
* Copyright © 2016-2024 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.validator; |
|||
|
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.common.data.StringUtils; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.queue.QueueStats; |
|||
import org.thingsboard.server.dao.exception.DataValidationException; |
|||
import org.thingsboard.server.dao.service.DataValidator; |
|||
|
|||
@Component |
|||
public class QueueStatsDataValidator extends DataValidator<QueueStats> { |
|||
|
|||
@Override |
|||
protected void validateDataImpl(TenantId tenantId, QueueStats queueStats) { |
|||
if (queueStats.getTenantId() == null) { |
|||
throw new DataValidationException("Tenant id should be specified!."); |
|||
} |
|||
if (queueStats.getQueueName() == null) { |
|||
throw new DataValidationException("Queue name should be specified!."); |
|||
} |
|||
if (StringUtils.isEmpty(queueStats.getServiceId())) { |
|||
throw new DataValidationException("Service id should be specified!."); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,66 @@ |
|||
/** |
|||
* Copyright © 2016-2024 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.queue; |
|||
|
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.data.jpa.repository.JpaRepository; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.queue.QueueStats; |
|||
import org.thingsboard.server.dao.DaoUtil; |
|||
import org.thingsboard.server.dao.model.sql.QueueStatsEntity; |
|||
import org.thingsboard.server.dao.queue.QueueStatsDao; |
|||
import org.thingsboard.server.dao.sql.JpaAbstractDao; |
|||
import org.thingsboard.server.dao.util.SqlDao; |
|||
|
|||
import java.util.List; |
|||
import java.util.UUID; |
|||
|
|||
@Slf4j |
|||
@Component |
|||
@SqlDao |
|||
public class JpaQueueStatsDao extends JpaAbstractDao<QueueStatsEntity, QueueStats> implements QueueStatsDao { |
|||
|
|||
@Autowired |
|||
private QueueStatsRepository queueStatsRepository; |
|||
|
|||
@Override |
|||
protected Class<QueueStatsEntity> getEntityClass() { |
|||
return QueueStatsEntity.class; |
|||
} |
|||
|
|||
@Override |
|||
protected JpaRepository<QueueStatsEntity, UUID> getRepository() { |
|||
return queueStatsRepository; |
|||
} |
|||
|
|||
@Override |
|||
public QueueStats findByTenantIdQueueNameAndServiceId(TenantId tenantId, String queueName, String serviceId) { |
|||
return DaoUtil.getData(queueStatsRepository.findByTenantIdAndQueueNameAndServiceId(tenantId.getId(), queueName, serviceId)); |
|||
} |
|||
|
|||
@Override |
|||
public List<QueueStats> findByTenantId(TenantId tenantId) { |
|||
return DaoUtil.convertDataList(queueStatsRepository.findByTenantId(tenantId.getId())); |
|||
} |
|||
|
|||
@Override |
|||
public void deleteByTenantId(TenantId tenantId) { |
|||
queueStatsRepository.deleteByTenantId(tenantId.getId()); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,39 @@ |
|||
/** |
|||
* Copyright © 2016-2024 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.queue; |
|||
|
|||
import org.springframework.data.jpa.repository.JpaRepository; |
|||
import org.springframework.data.jpa.repository.Modifying; |
|||
import org.springframework.data.jpa.repository.Query; |
|||
import org.springframework.data.repository.query.Param; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
import org.thingsboard.server.dao.model.sql.QueueStatsEntity; |
|||
|
|||
import java.util.List; |
|||
import java.util.UUID; |
|||
|
|||
public interface QueueStatsRepository extends JpaRepository<QueueStatsEntity, UUID> { |
|||
|
|||
QueueStatsEntity findByTenantIdAndQueueNameAndServiceId(UUID tenantId, String queueName, String serviceId); |
|||
|
|||
List<QueueStatsEntity> findByTenantId(UUID tenantId); |
|||
|
|||
@Transactional |
|||
@Modifying |
|||
@Query("DELETE FROM QueueStatsEntity t WHERE t.tenantId = :tenantId") |
|||
void deleteByTenantId(@Param("tenantId") UUID tenantId); |
|||
|
|||
} |
|||
@ -0,0 +1,134 @@ |
|||
/** |
|||
* Copyright © 2016-2024 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.junit.jupiter.api.Assertions; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.thingsboard.server.common.data.StringUtils; |
|||
import org.thingsboard.server.common.data.Tenant; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.queue.QueueStats; |
|||
import org.thingsboard.server.dao.exception.DataValidationException; |
|||
import org.thingsboard.server.dao.queue.QueueStatsService; |
|||
|
|||
import java.util.List; |
|||
|
|||
import static org.assertj.core.api.Assertions.assertThat; |
|||
|
|||
|
|||
@DaoSqlTest |
|||
public class QueueStatsServiceTest extends AbstractServiceTest { |
|||
|
|||
@Autowired |
|||
QueueStatsService queueStatsService; |
|||
|
|||
private TenantId tenantId; |
|||
|
|||
@Before |
|||
public void before() throws NoSuchFieldException, IllegalAccessException { |
|||
|
|||
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 testSaveQueueStats() { |
|||
QueueStats queueStats = new QueueStats(); |
|||
queueStats.setTenantId(tenantId); |
|||
String queueName = StringUtils.randomAlphabetic(8); |
|||
queueStats.setQueueName(queueName); |
|||
queueStats.setServiceId(StringUtils.randomAlphabetic(8)); |
|||
|
|||
QueueStats savedQueueStats = queueStatsService.save(tenantId, queueStats); |
|||
Assert.assertNotNull(savedQueueStats); |
|||
Assert.assertNotNull(savedQueueStats.getId()); |
|||
Assert.assertTrue(savedQueueStats.getCreatedTime() > 0); |
|||
Assert.assertEquals(queueStats.getTenantId(), savedQueueStats.getTenantId()); |
|||
Assert.assertEquals(savedQueueStats.getQueueName(), queueStats.getQueueName()); |
|||
|
|||
QueueStats retrievedQueueStatsById = queueStatsService.findQueueStatsById(tenantId, savedQueueStats.getId()); |
|||
Assert.assertEquals(retrievedQueueStatsById.getQueueName(), queueName); |
|||
|
|||
String secondQueueName = StringUtils.randomAlphabetic(8); |
|||
queueStats.setQueueName(secondQueueName); |
|||
QueueStats savedQueueStats2 = queueStatsService.save(tenantId, queueStats); |
|||
QueueStats retrievedQueueStatsById2 = queueStatsService.findQueueStatsById(tenantId, savedQueueStats2.getId()); |
|||
Assert.assertEquals(retrievedQueueStatsById2.getQueueName(), secondQueueName); |
|||
|
|||
List<QueueStats> queueStatsList = queueStatsService.findByTenantId(tenantId); |
|||
Assert.assertEquals(2, queueStatsList.size()); |
|||
assertThat(queueStatsList).containsOnly(retrievedQueueStatsById, retrievedQueueStatsById2); |
|||
|
|||
queueStatsService.deleteByTenantId(tenantId); |
|||
QueueStats retrievedQueueStatsAfterDelete = queueStatsService.findQueueStatsById(tenantId, savedQueueStats.getId()); |
|||
Assert.assertNull(retrievedQueueStatsAfterDelete); |
|||
} |
|||
|
|||
@Test |
|||
public void testSaveWithNullQueueName() { |
|||
QueueStats queueStats = new QueueStats(); |
|||
queueStats.setTenantId(tenantId); |
|||
queueStats.setQueueName(null); |
|||
queueStats.setServiceId(StringUtils.randomAlphabetic(8)); |
|||
|
|||
Assertions.assertThrows(DataValidationException.class, () -> { |
|||
queueStatsService.save(tenantId, queueStats); |
|||
}); |
|||
} |
|||
|
|||
@Test |
|||
public void testSaveWithNullServiceId() { |
|||
QueueStats queueStats = new QueueStats(); |
|||
queueStats.setTenantId(tenantId); |
|||
queueStats.setQueueName(StringUtils.randomAlphabetic(8)); |
|||
queueStats.setServiceId(null); |
|||
|
|||
Assertions.assertThrows(DataValidationException.class, () -> { |
|||
queueStatsService.save(tenantId, queueStats); |
|||
}); |
|||
} |
|||
|
|||
@Test |
|||
public void testFindByTenantIdAndNameAndServiceId() { |
|||
QueueStats queueStats = new QueueStats(); |
|||
queueStats.setTenantId(tenantId); |
|||
queueStats.setQueueName(StringUtils.randomAlphabetic(8)); |
|||
queueStats.setServiceId(StringUtils.randomAlphabetic(8)); |
|||
QueueStats savedQueueStats = queueStatsService.save(tenantId, queueStats); |
|||
|
|||
QueueStats queueStats2 = new QueueStats(); |
|||
queueStats2.setTenantId(tenantId); |
|||
queueStats2.setQueueName(StringUtils.randomAlphabetic(8)); |
|||
queueStats2.setServiceId(StringUtils.randomAlphabetic(8)); |
|||
queueStatsService.save(tenantId, queueStats2); |
|||
|
|||
QueueStats retrievedQueueStatsById = queueStatsService.findByTenantIdAndNameAndServiceId(tenantId, queueStats.getQueueName(), queueStats.getServiceId()); |
|||
assertThat(retrievedQueueStatsById).isEqualTo(savedQueueStats); |
|||
} |
|||
|
|||
} |
|||
Loading…
Reference in new issue