22 changed files with 702 additions and 41 deletions
@ -0,0 +1,71 @@ |
|||
/** |
|||
* 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.calculated_field; |
|||
|
|||
import com.fasterxml.jackson.databind.JsonNode; |
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
import org.thingsboard.server.common.data.BaseData; |
|||
import org.thingsboard.server.common.data.id.CalculatedFieldId; |
|||
import org.thingsboard.server.common.data.id.CalculatedFieldLinkId; |
|||
import org.thingsboard.server.common.data.id.EntityId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
|
|||
@Schema |
|||
@Data |
|||
@EqualsAndHashCode(callSuper = true) |
|||
public class CalculatedFieldLink extends BaseData<CalculatedFieldLinkId> { |
|||
|
|||
private static final long serialVersionUID = 6492846246722091530L; |
|||
|
|||
private TenantId tenantId; |
|||
private EntityId entityId; |
|||
|
|||
@Schema(description = "JSON object with the Calculated Field Id. ", accessMode = Schema.AccessMode.READ_ONLY) |
|||
private CalculatedFieldId calculatedFieldId; |
|||
@Schema(description = "JSON with the calculated field link configuration.", implementation = com.fasterxml.jackson.databind.JsonNode.class) |
|||
private transient JsonNode configuration; |
|||
|
|||
public CalculatedFieldLink() { |
|||
super(); |
|||
} |
|||
|
|||
public CalculatedFieldLink(CalculatedFieldLinkId id) { |
|||
super(id); |
|||
} |
|||
|
|||
public CalculatedFieldLink(TenantId tenantId, EntityId entityId, JsonNode configuration, CalculatedFieldId calculatedFieldId) { |
|||
this.tenantId = tenantId; |
|||
this.entityId = entityId; |
|||
this.configuration = configuration; |
|||
this.calculatedFieldId = calculatedFieldId; |
|||
} |
|||
|
|||
@Override |
|||
public String toString() { |
|||
return new StringBuilder() |
|||
.append("CalculatedFieldLink[") |
|||
.append("tenantId=").append(tenantId) |
|||
.append(", entityId=").append(entityId) |
|||
.append(", calculatedFieldId=").append(calculatedFieldId) |
|||
.append(", configuration=").append(configuration) |
|||
.append(", createdTime=").append(createdTime) |
|||
.append(", id=").append(id).append(']') |
|||
.toString(); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,45 @@ |
|||
/** |
|||
* 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; |
|||
|
|||
@Schema |
|||
public class CalculatedFieldLinkId extends UUIDBased implements EntityId { |
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
@JsonCreator |
|||
public CalculatedFieldLinkId(@JsonProperty("id") UUID id) { |
|||
super(id); |
|||
} |
|||
|
|||
public static CalculatedFieldLinkId fromString(String calculatedFieldLinkId) { |
|||
return new CalculatedFieldLinkId(UUID.fromString(calculatedFieldLinkId)); |
|||
} |
|||
|
|||
@Schema(requiredMode = Schema.RequiredMode.REQUIRED, description = "string", example = "CALCULATED_FIELD_LINK", allowableValues = "CALCULATED_FIELD_LINK") |
|||
@Override |
|||
public EntityType getEntityType() { |
|||
return EntityType.CALCULATED_FIELD_LINK; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,27 @@ |
|||
/** |
|||
* 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.calculated_field; |
|||
|
|||
import org.thingsboard.server.common.data.calculated_field.CalculatedFieldLink; |
|||
import org.thingsboard.server.dao.Dao; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
public interface CalculatedFieldLinkDao extends Dao<CalculatedFieldLink> { |
|||
|
|||
CalculatedFieldLink findCalculatedFieldLinkByEntityId(UUID tenantId, UUID entityId); |
|||
|
|||
} |
|||
@ -0,0 +1,92 @@ |
|||
/** |
|||
* 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 com.fasterxml.jackson.databind.JsonNode; |
|||
import jakarta.persistence.Column; |
|||
import jakarta.persistence.Convert; |
|||
import jakarta.persistence.Entity; |
|||
import jakarta.persistence.Table; |
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
import org.thingsboard.server.common.data.EntityType; |
|||
import org.thingsboard.server.common.data.calculated_field.CalculatedFieldLink; |
|||
import org.thingsboard.server.common.data.id.CalculatedFieldId; |
|||
import org.thingsboard.server.common.data.id.CalculatedFieldLinkId; |
|||
import org.thingsboard.server.common.data.id.EntityIdFactory; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.dao.model.BaseEntity; |
|||
import org.thingsboard.server.dao.model.BaseSqlEntity; |
|||
import org.thingsboard.server.dao.util.mapping.JsonConverter; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
import static org.thingsboard.server.dao.model.ModelConstants.CALCULATED_FIELD_LINK_CALCULATED_FIELD_ID; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.CALCULATED_FIELD_LINK_CONFIGURATION; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.CALCULATED_FIELD_LINK_ENTITY_ID; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.CALCULATED_FIELD_LINK_ENTITY_TYPE; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.CALCULATED_FIELD_LINK_TABLE_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.CALCULATED_FIELD_LINK_TENANT_ID_COLUMN; |
|||
|
|||
@Data |
|||
@EqualsAndHashCode(callSuper = true) |
|||
@Entity |
|||
@Table(name = CALCULATED_FIELD_LINK_TABLE_NAME) |
|||
public class CalculatedFieldLinkEntity extends BaseSqlEntity<CalculatedFieldLink> implements BaseEntity<CalculatedFieldLink> { |
|||
|
|||
@Column(name = CALCULATED_FIELD_LINK_TENANT_ID_COLUMN) |
|||
private UUID tenantId; |
|||
|
|||
@Column(name = CALCULATED_FIELD_LINK_ENTITY_TYPE) |
|||
private EntityType entityType; |
|||
|
|||
@Column(name = CALCULATED_FIELD_LINK_ENTITY_ID) |
|||
private UUID entityId; |
|||
|
|||
@Column(name = CALCULATED_FIELD_LINK_CALCULATED_FIELD_ID) |
|||
private UUID calculatedFieldId; |
|||
|
|||
@Convert(converter = JsonConverter.class) |
|||
@Column(name = CALCULATED_FIELD_LINK_CONFIGURATION) |
|||
private JsonNode configuration; |
|||
|
|||
|
|||
public CalculatedFieldLinkEntity() { |
|||
super(); |
|||
} |
|||
|
|||
public CalculatedFieldLinkEntity(CalculatedFieldLink calculatedFieldLink) { |
|||
this.setUuid(calculatedFieldLink.getUuidId()); |
|||
this.createdTime = calculatedFieldLink.getCreatedTime(); |
|||
this.tenantId = calculatedFieldLink.getTenantId().getId(); |
|||
this.entityType = calculatedFieldLink.getEntityId().getEntityType(); |
|||
this.entityId = calculatedFieldLink.getEntityId().getId(); |
|||
this.calculatedFieldId = calculatedFieldLink.getCalculatedFieldId().getId(); |
|||
this.configuration = calculatedFieldLink.getConfiguration(); |
|||
} |
|||
|
|||
@Override |
|||
public CalculatedFieldLink toData() { |
|||
CalculatedFieldLink calculatedFieldLink = new CalculatedFieldLink(new CalculatedFieldLinkId(id)); |
|||
calculatedFieldLink.setCreatedTime(createdTime); |
|||
calculatedFieldLink.setTenantId(TenantId.fromUUID(tenantId)); |
|||
calculatedFieldLink.setEntityId(EntityIdFactory.getByTypeAndUuid(entityType, entityId)); |
|||
calculatedFieldLink.setCalculatedFieldId(new CalculatedFieldId(calculatedFieldId)); |
|||
calculatedFieldLink.setConfiguration(configuration); |
|||
return calculatedFieldLink; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,41 @@ |
|||
/** |
|||
* 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.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.common.data.calculated_field.CalculatedField; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.dao.calculated_field.CalculatedFieldDao; |
|||
import org.thingsboard.server.dao.exception.DataValidationException; |
|||
import org.thingsboard.server.dao.service.DataValidator; |
|||
|
|||
@Component |
|||
public class CalculatedFieldDataValidator extends DataValidator<CalculatedField> { |
|||
|
|||
@Autowired |
|||
private CalculatedFieldDao calculatedFieldDao; |
|||
|
|||
@Override |
|||
protected CalculatedField validateUpdate(TenantId tenantId, CalculatedField calculatedField) { |
|||
CalculatedField old = calculatedFieldDao.findById(calculatedField.getTenantId(), calculatedField.getId().getId()); |
|||
if (old == null) { |
|||
throw new DataValidationException("Can't update non existing calculated field!"); |
|||
} |
|||
return old; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,41 @@ |
|||
/** |
|||
* 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.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.common.data.calculated_field.CalculatedFieldLink; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.dao.calculated_field.CalculatedFieldLinkDao; |
|||
import org.thingsboard.server.dao.exception.DataValidationException; |
|||
import org.thingsboard.server.dao.service.DataValidator; |
|||
|
|||
@Component |
|||
public class CalculatedFieldLinkDataValidator extends DataValidator<CalculatedFieldLink> { |
|||
|
|||
@Autowired |
|||
private CalculatedFieldLinkDao calculatedFieldLinkDao; |
|||
|
|||
@Override |
|||
protected CalculatedFieldLink validateUpdate(TenantId tenantId, CalculatedFieldLink calculatedFieldLink) { |
|||
CalculatedFieldLink old = calculatedFieldLinkDao.findById(calculatedFieldLink.getTenantId(), calculatedFieldLink.getId().getId()); |
|||
if (old == null) { |
|||
throw new DataValidationException("Can't update non existing calculated field link!"); |
|||
} |
|||
return old; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,27 @@ |
|||
/** |
|||
* 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.calculated_field; |
|||
|
|||
import org.springframework.data.jpa.repository.JpaRepository; |
|||
import org.thingsboard.server.dao.model.sql.CalculatedFieldLinkEntity; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
public interface CalculatedFieldLinkRepository extends JpaRepository<CalculatedFieldLinkEntity, UUID> { |
|||
|
|||
CalculatedFieldLinkEntity findByTenantIdAndEntityId(UUID tenantId, UUID entityId); |
|||
|
|||
} |
|||
@ -0,0 +1,54 @@ |
|||
/** |
|||
* 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.calculated_field; |
|||
|
|||
import lombok.AllArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.data.jpa.repository.JpaRepository; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.common.data.calculated_field.CalculatedFieldLink; |
|||
import org.thingsboard.server.dao.DaoUtil; |
|||
import org.thingsboard.server.dao.calculated_field.CalculatedFieldLinkDao; |
|||
import org.thingsboard.server.dao.model.sql.CalculatedFieldLinkEntity; |
|||
import org.thingsboard.server.dao.sql.JpaAbstractDao; |
|||
import org.thingsboard.server.dao.util.SqlDao; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
@Slf4j |
|||
@Component |
|||
@AllArgsConstructor |
|||
@SqlDao |
|||
public class JpaCalculatedFieldLinkDao extends JpaAbstractDao<CalculatedFieldLinkEntity, CalculatedFieldLink> implements CalculatedFieldLinkDao { |
|||
|
|||
private final CalculatedFieldLinkRepository calculatedFieldLinkRepository; |
|||
|
|||
@Override |
|||
public CalculatedFieldLink findCalculatedFieldLinkByEntityId(UUID tenantId, UUID entityId) { |
|||
return DaoUtil.getData(calculatedFieldLinkRepository.findByTenantIdAndEntityId(tenantId, entityId)); |
|||
} |
|||
|
|||
@Override |
|||
protected Class<CalculatedFieldLinkEntity> getEntityClass() { |
|||
return CalculatedFieldLinkEntity.class; |
|||
} |
|||
|
|||
@Override |
|||
protected JpaRepository<CalculatedFieldLinkEntity, UUID> getRepository() { |
|||
return calculatedFieldLinkRepository; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,57 @@ |
|||
/** |
|||
* 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.junit.jupiter.api.Test; |
|||
import org.springframework.boot.test.context.SpringBootTest; |
|||
import org.springframework.boot.test.mock.mockito.MockBean; |
|||
import org.springframework.boot.test.mock.mockito.SpyBean; |
|||
import org.thingsboard.server.common.data.calculated_field.CalculatedField; |
|||
import org.thingsboard.server.common.data.id.CalculatedFieldId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.dao.calculated_field.CalculatedFieldDao; |
|||
import org.thingsboard.server.dao.exception.DataValidationException; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
import static org.assertj.core.api.Assertions.assertThatThrownBy; |
|||
import static org.mockito.BDDMockito.given; |
|||
|
|||
@SpringBootTest(classes = CalculatedFieldDataValidator.class) |
|||
public class CalculatedFieldDataValidatorTest { |
|||
|
|||
private final TenantId TENANT_ID = TenantId.fromUUID(UUID.fromString("7b5229e9-166e-41a9-a257-3b1dafad1b04")); |
|||
private final CalculatedFieldId CALCULATED_FIELD_ID = new CalculatedFieldId(UUID.fromString("060fbe45-fbb2-4549-abf3-f72a6be3cb9f")); |
|||
|
|||
@MockBean |
|||
private CalculatedFieldDao calculatedFieldDao; |
|||
@SpyBean |
|||
private CalculatedFieldDataValidator validator; |
|||
|
|||
@Test |
|||
public void testUpdateNonExistingCalculatedField() { |
|||
CalculatedField calculatedField = new CalculatedField(CALCULATED_FIELD_ID); |
|||
calculatedField.setType("Simple"); |
|||
calculatedField.setName("Test"); |
|||
|
|||
given(calculatedFieldDao.findById(TENANT_ID, CALCULATED_FIELD_ID.getId())).willReturn(null); |
|||
|
|||
assertThatThrownBy(() -> validator.validateUpdate(TENANT_ID, calculatedField)) |
|||
.isInstanceOf(DataValidationException.class) |
|||
.hasMessage("Can't update non existing calculated field!"); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,57 @@ |
|||
/** |
|||
* 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.junit.jupiter.api.Test; |
|||
import org.springframework.boot.test.context.SpringBootTest; |
|||
import org.springframework.boot.test.mock.mockito.MockBean; |
|||
import org.springframework.boot.test.mock.mockito.SpyBean; |
|||
import org.thingsboard.server.common.data.calculated_field.CalculatedFieldLink; |
|||
import org.thingsboard.server.common.data.id.CalculatedFieldId; |
|||
import org.thingsboard.server.common.data.id.CalculatedFieldLinkId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.dao.calculated_field.CalculatedFieldLinkDao; |
|||
import org.thingsboard.server.dao.exception.DataValidationException; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
import static org.assertj.core.api.Assertions.assertThatThrownBy; |
|||
import static org.mockito.BDDMockito.given; |
|||
|
|||
@SpringBootTest(classes = CalculatedFieldLinkDataValidator.class) |
|||
public class CalculatedFieldLinkDataValidatorTest { |
|||
|
|||
private final TenantId TENANT_ID = TenantId.fromUUID(UUID.fromString("2ba09d99-6143-43dc-b645-381fc0c43ebe")); |
|||
private final CalculatedFieldLinkId CALCULATED_FIELD_LINK_ID = new CalculatedFieldLinkId(UUID.fromString("a5609ef4-cb42-43ce-9b23-e090a4878d1c")); |
|||
|
|||
@MockBean |
|||
private CalculatedFieldLinkDao calculatedFieldLinkDao; |
|||
@SpyBean |
|||
private CalculatedFieldLinkDataValidator validator; |
|||
|
|||
@Test |
|||
public void testUpdateNonExistingCalculatedField() { |
|||
CalculatedFieldLink calculatedFieldLink = new CalculatedFieldLink(CALCULATED_FIELD_LINK_ID); |
|||
calculatedFieldLink.setCalculatedFieldId(new CalculatedFieldId(UUID.fromString("136477af-fd07-4498-b9c9-54fe50e82992"))); |
|||
|
|||
given(calculatedFieldLinkDao.findById(TENANT_ID, CALCULATED_FIELD_LINK_ID.getId())).willReturn(null); |
|||
|
|||
assertThatThrownBy(() -> validator.validateUpdate(TENANT_ID, calculatedFieldLink)) |
|||
.isInstanceOf(DataValidationException.class) |
|||
.hasMessage("Can't update non existing calculated field link!"); |
|||
} |
|||
|
|||
} |
|||
Loading…
Reference in new issue