|
|
|
@ -21,6 +21,7 @@ import org.junit.Before; |
|
|
|
import org.junit.Test; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.thingsboard.common.util.JacksonUtil; |
|
|
|
import org.thingsboard.server.common.data.StringUtils; |
|
|
|
import org.thingsboard.server.common.data.id.TenantId; |
|
|
|
import org.thingsboard.server.common.data.id.WidgetsBundleId; |
|
|
|
import org.thingsboard.server.common.data.page.PageData; |
|
|
|
@ -43,6 +44,7 @@ import java.util.Comparator; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.UUID; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
import static org.junit.Assert.assertEquals; |
|
|
|
@ -160,6 +162,30 @@ public class JpaWidgetTypeDaoTest extends AbstractJpaDaoTest { |
|
|
|
assertEquals(new WidgetTypeInfo(widgetTypeList.get(2)), widgetTypes.getData().get(0)); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testFindSystemWidgetTypesForSameName() throws InterruptedException { |
|
|
|
List<WidgetTypeDetails> sameNameList = new ArrayList<>(); |
|
|
|
|
|
|
|
for (int i = 0; i < 20; i++) { |
|
|
|
Thread.sleep(2); |
|
|
|
var widgetType = saveWidgetType(TenantId.SYS_TENANT_ID, "widgetName"); |
|
|
|
sameNameList.add(widgetType); |
|
|
|
widgetTypeList.add(widgetType); |
|
|
|
} |
|
|
|
sameNameList.sort(Comparator.comparing(BaseWidgetType::getName).thenComparing((BaseWidgetType baseWidgetType) -> baseWidgetType.getId().getId())); |
|
|
|
List<WidgetTypeInfo> expected = sameNameList.stream().map(WidgetTypeInfo::new).collect(Collectors.toList()); |
|
|
|
|
|
|
|
PageData<WidgetTypeInfo> widgetTypesFirstPage = widgetTypeDao.findSystemWidgetTypes(TenantId.SYS_TENANT_ID, true, DeprecatedFilter.ALL, Collections.singletonList("static"), |
|
|
|
new PageLink(10, 0, null, new SortOrder("name"))); |
|
|
|
assertEquals(10, widgetTypesFirstPage.getData().size()); |
|
|
|
assertThat(widgetTypesFirstPage.getData()).containsExactlyElementsOf(expected.subList(0, 10)); |
|
|
|
|
|
|
|
PageData<WidgetTypeInfo> widgetTypesSecondPage = widgetTypeDao.findSystemWidgetTypes(TenantId.SYS_TENANT_ID, true, DeprecatedFilter.ALL, Collections.singletonList("static"), |
|
|
|
new PageLink(10, 1, null, new SortOrder("name"))); |
|
|
|
assertEquals(10, widgetTypesSecondPage.getData().size()); |
|
|
|
assertThat(widgetTypesSecondPage.getData()).containsExactlyElementsOf(expected.subList(10, 20)); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testTagsSearchInFindBySystemWidgetTypes() { |
|
|
|
for (var entry : SHOULD_FIND_SEARCH_TO_TAGS_MAP.entrySet()) { |
|
|
|
@ -355,4 +381,15 @@ public class JpaWidgetTypeDaoTest extends AbstractJpaDaoTest { |
|
|
|
assertEquals(0, result.size()); |
|
|
|
widgetTypeDao.removeById(tenantId, details.getUuidId()); |
|
|
|
} |
|
|
|
|
|
|
|
private WidgetTypeDetails saveWidgetType(TenantId tenantId, String name) { |
|
|
|
WidgetTypeDetails widgetType = new WidgetTypeDetails(); |
|
|
|
widgetType.setTenantId(tenantId); |
|
|
|
widgetType.setDescription("WIDGET_TYPE_DESCRIPTION" + StringUtils.randomAlphabetic(7)); |
|
|
|
widgetType.setName(name); |
|
|
|
var descriptor = JacksonUtil.newObjectNode(); |
|
|
|
descriptor.put("type","static"); |
|
|
|
widgetType.setDescriptor(descriptor); |
|
|
|
return widgetTypeDao.save(TenantId.SYS_TENANT_ID, widgetType); |
|
|
|
} |
|
|
|
} |
|
|
|
|