|
|
|
@ -41,8 +41,10 @@ import java.util.ArrayList; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.Comparator; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.UUID; |
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
import static org.junit.Assert.assertEquals; |
|
|
|
import static org.junit.Assert.assertNotNull; |
|
|
|
|
|
|
|
@ -51,6 +53,26 @@ import static org.junit.Assert.assertNotNull; |
|
|
|
*/ |
|
|
|
public class JpaWidgetTypeDaoTest extends AbstractJpaDaoTest { |
|
|
|
|
|
|
|
// given search text should find a widget with tags, when searching by tags
|
|
|
|
final Map<String, String[]> SHOULD_FIND_SEARCH_TO_TAGS_MAP = Map.of( |
|
|
|
"A", new String[]{"a", "b", "c"}, |
|
|
|
"test A test", new String[]{"a", "b", "c"}, |
|
|
|
"test x y test", new String[]{"x y", "b", "c"}, |
|
|
|
"x y test", new String[]{"x y", "b", "c"}, |
|
|
|
"x y", new String[]{"x y", "b", "c"}, |
|
|
|
"test x y", new String[]{"x y", "b", "c"} |
|
|
|
); |
|
|
|
|
|
|
|
// given search text should not find a widget with tags, when searching by tags
|
|
|
|
final Map<String, String[]> SHOULDNT_FIND_SEARCH_TO_TAGS_MAP = Map.of( |
|
|
|
"testA test", new String[]{"a", "b", "c"}, |
|
|
|
"testx y test", new String[]{"x y", "b", "c"}, |
|
|
|
"testx ytest", new String[]{"x y", "b", "c"}, |
|
|
|
"x ytest", new String[]{"x y", "b", "c"}, |
|
|
|
"testx y", new String[]{"x y", "b", "c"}, |
|
|
|
"x", new String[]{"x y", "b", "c"} |
|
|
|
); |
|
|
|
|
|
|
|
final String BUNDLE_ALIAS = "BUNDLE_ALIAS"; |
|
|
|
final int WIDGET_TYPE_COUNT = 3; |
|
|
|
List<WidgetTypeDetails> widgetTypeList; |
|
|
|
@ -96,6 +118,19 @@ public class JpaWidgetTypeDaoTest extends AbstractJpaDaoTest { |
|
|
|
return widgetTypeDao.save(TenantId.SYS_TENANT_ID, widgetType); |
|
|
|
} |
|
|
|
|
|
|
|
WidgetTypeDetails createAndSaveWidgetType(TenantId tenantId, int number, String[] tags) { |
|
|
|
WidgetTypeDetails widgetType = new WidgetTypeDetails(); |
|
|
|
widgetType.setTenantId(tenantId); |
|
|
|
widgetType.setName("WIDGET_TYPE_" + number); |
|
|
|
widgetType.setDescription("WIDGET_TYPE_DESCRIPTION" + number); |
|
|
|
widgetType.setFqn("FQN_" + number); |
|
|
|
var descriptor = JacksonUtil.newObjectNode(); |
|
|
|
descriptor.put("type", number % 2 == 0 ? "latest" : "static"); |
|
|
|
widgetType.setDescriptor(descriptor); |
|
|
|
widgetType.setTags(tags); |
|
|
|
return widgetTypeDao.save(TenantId.SYS_TENANT_ID, widgetType); |
|
|
|
} |
|
|
|
|
|
|
|
@After |
|
|
|
public void tearDown() { |
|
|
|
widgetsBundleDao.removeById(TenantId.SYS_TENANT_ID, widgetsBundle.getUuidId()); |
|
|
|
@ -123,6 +158,40 @@ public class JpaWidgetTypeDaoTest extends AbstractJpaDaoTest { |
|
|
|
assertEquals(new WidgetTypeInfo(widgetTypeList.get(2)), widgetTypes.getData().get(0)); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testTagsSearchInFindBySystemWidgetTypes() { |
|
|
|
for (var entry : SHOULD_FIND_SEARCH_TO_TAGS_MAP.entrySet()) { |
|
|
|
String searchText = entry.getKey(); |
|
|
|
String[] tags = entry.getValue(); |
|
|
|
|
|
|
|
WidgetTypeDetails savedWidgetType = createAndSaveWidgetType(TenantId.SYS_TENANT_ID, WIDGET_TYPE_COUNT + 1, tags); |
|
|
|
|
|
|
|
PageData<WidgetTypeInfo> widgetTypes = widgetTypeDao.findSystemWidgetTypes( |
|
|
|
TenantId.SYS_TENANT_ID, true, DeprecatedFilter.ALL, null, new PageLink(10, 0, searchText) |
|
|
|
); |
|
|
|
|
|
|
|
assertThat(widgetTypes.getData()).hasSize(1); |
|
|
|
assertThat(widgetTypes.getData().get(0).getId()).isEqualTo(savedWidgetType.getId()); |
|
|
|
|
|
|
|
widgetTypeDao.removeById(TenantId.SYS_TENANT_ID, savedWidgetType.getUuidId()); |
|
|
|
} |
|
|
|
|
|
|
|
for (var entry : SHOULDNT_FIND_SEARCH_TO_TAGS_MAP.entrySet()) { |
|
|
|
String searchText = entry.getKey(); |
|
|
|
String[] tags = entry.getValue(); |
|
|
|
|
|
|
|
WidgetTypeDetails savedWidgetType = createAndSaveWidgetType(TenantId.SYS_TENANT_ID, WIDGET_TYPE_COUNT + 1, tags); |
|
|
|
|
|
|
|
PageData<WidgetTypeInfo> widgetTypes = widgetTypeDao.findSystemWidgetTypes( |
|
|
|
TenantId.SYS_TENANT_ID, true, DeprecatedFilter.ALL, null, new PageLink(10, 0, searchText) |
|
|
|
); |
|
|
|
|
|
|
|
assertThat(widgetTypes.getData()).hasSize(0); |
|
|
|
|
|
|
|
widgetTypeDao.removeById(TenantId.SYS_TENANT_ID, savedWidgetType.getUuidId()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testFindTenantWidgetTypesByTenantId() { |
|
|
|
UUID tenantId = Uuids.timeBased(); |
|
|
|
@ -138,6 +207,74 @@ public class JpaWidgetTypeDaoTest extends AbstractJpaDaoTest { |
|
|
|
assertEquals(new WidgetTypeInfo(widgetTypeList.get(5)), widgetTypes.getData().get(2)); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testTagsSearchInFindTenantWidgetTypesByTenantId() { |
|
|
|
for (var entry : SHOULD_FIND_SEARCH_TO_TAGS_MAP.entrySet()) { |
|
|
|
String searchText = entry.getKey(); |
|
|
|
String[] tags = entry.getValue(); |
|
|
|
|
|
|
|
WidgetTypeDetails savedWidgetType = createAndSaveWidgetType(TenantId.SYS_TENANT_ID, WIDGET_TYPE_COUNT + 1, tags); |
|
|
|
|
|
|
|
PageData<WidgetTypeInfo> widgetTypes = widgetTypeDao.findTenantWidgetTypesByTenantId( |
|
|
|
TenantId.SYS_TENANT_ID.getId(), true, DeprecatedFilter.ALL, null, new PageLink(10, 0, searchText) |
|
|
|
); |
|
|
|
|
|
|
|
assertThat(widgetTypes.getData()).hasSize(1); |
|
|
|
assertThat(widgetTypes.getData().get(0).getId()).isEqualTo(savedWidgetType.getId()); |
|
|
|
|
|
|
|
widgetTypeDao.removeById(TenantId.SYS_TENANT_ID, savedWidgetType.getUuidId()); |
|
|
|
} |
|
|
|
|
|
|
|
for (var entry : SHOULDNT_FIND_SEARCH_TO_TAGS_MAP.entrySet()) { |
|
|
|
String searchText = entry.getKey(); |
|
|
|
String[] tags = entry.getValue(); |
|
|
|
|
|
|
|
WidgetTypeDetails savedWidgetType = createAndSaveWidgetType(TenantId.SYS_TENANT_ID, WIDGET_TYPE_COUNT + 1, tags); |
|
|
|
|
|
|
|
PageData<WidgetTypeInfo> widgetTypes = widgetTypeDao.findTenantWidgetTypesByTenantId( |
|
|
|
TenantId.SYS_TENANT_ID.getId(), true, DeprecatedFilter.ALL, null, new PageLink(10, 0, searchText) |
|
|
|
); |
|
|
|
|
|
|
|
assertThat(widgetTypes.getData()).hasSize(0); |
|
|
|
|
|
|
|
widgetTypeDao.removeById(TenantId.SYS_TENANT_ID, savedWidgetType.getUuidId()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testTagsSearchInFindAllTenantWidgetTypesByTenantId() { |
|
|
|
for (var entry : SHOULD_FIND_SEARCH_TO_TAGS_MAP.entrySet()) { |
|
|
|
String searchText = entry.getKey(); |
|
|
|
String[] tags = entry.getValue(); |
|
|
|
|
|
|
|
WidgetTypeDetails savedWidgetType = createAndSaveWidgetType(TenantId.SYS_TENANT_ID, WIDGET_TYPE_COUNT + 1, tags); |
|
|
|
|
|
|
|
PageData<WidgetTypeInfo> widgetTypes = widgetTypeDao.findAllTenantWidgetTypesByTenantId( |
|
|
|
TenantId.SYS_TENANT_ID.getId(), true, DeprecatedFilter.ALL, null, new PageLink(10, 0, searchText) |
|
|
|
); |
|
|
|
|
|
|
|
assertThat(widgetTypes.getData()).hasSize(1); |
|
|
|
assertThat(widgetTypes.getData().get(0).getId()).isEqualTo(savedWidgetType.getId()); |
|
|
|
|
|
|
|
widgetTypeDao.removeById(TenantId.SYS_TENANT_ID, savedWidgetType.getUuidId()); |
|
|
|
} |
|
|
|
|
|
|
|
for (var entry : SHOULDNT_FIND_SEARCH_TO_TAGS_MAP.entrySet()) { |
|
|
|
String searchText = entry.getKey(); |
|
|
|
String[] tags = entry.getValue(); |
|
|
|
|
|
|
|
WidgetTypeDetails savedWidgetType = createAndSaveWidgetType(TenantId.SYS_TENANT_ID, WIDGET_TYPE_COUNT + 1, tags); |
|
|
|
|
|
|
|
PageData<WidgetTypeInfo> widgetTypes = widgetTypeDao.findAllTenantWidgetTypesByTenantId( |
|
|
|
TenantId.SYS_TENANT_ID.getId(), true, DeprecatedFilter.ALL, null, new PageLink(10, 0, searchText) |
|
|
|
); |
|
|
|
|
|
|
|
assertThat(widgetTypes.getData()).hasSize(0); |
|
|
|
|
|
|
|
widgetTypeDao.removeById(TenantId.SYS_TENANT_ID, savedWidgetType.getUuidId()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testFindByWidgetTypeInfosByBundleId() { |
|
|
|
PageData<WidgetTypeInfo> widgetTypes = widgetTypeDao.findWidgetTypesInfosByWidgetsBundleId(TenantId.SYS_TENANT_ID.getId(), widgetsBundle.getUuidId(),true, DeprecatedFilter.ALL, Collections.singletonList("latest"), |
|
|
|
@ -152,6 +289,42 @@ public class JpaWidgetTypeDaoTest extends AbstractJpaDaoTest { |
|
|
|
assertEquals(new WidgetTypeInfo(widgetTypeList.get(0)), widgetTypes.getData().get(0)); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testTagsSearchInFindByWidgetTypeInfosByBundleId() { |
|
|
|
for (var entry : SHOULD_FIND_SEARCH_TO_TAGS_MAP.entrySet()) { |
|
|
|
String searchText = entry.getKey(); |
|
|
|
String[] tags = entry.getValue(); |
|
|
|
|
|
|
|
WidgetTypeDetails savedWidgetType = createAndSaveWidgetType(TenantId.SYS_TENANT_ID, WIDGET_TYPE_COUNT + 1, tags); |
|
|
|
widgetTypeDao.saveWidgetsBundleWidget(new WidgetsBundleWidget(this.widgetsBundle.getId(), savedWidgetType.getId(), WIDGET_TYPE_COUNT + 1)); |
|
|
|
|
|
|
|
PageData<WidgetTypeInfo> widgetTypes = widgetTypeDao.findWidgetTypesInfosByWidgetsBundleId( |
|
|
|
TenantId.SYS_TENANT_ID.getId(), widgetsBundle.getUuidId(), true, DeprecatedFilter.ALL, null, new PageLink(10, 0, searchText) |
|
|
|
); |
|
|
|
|
|
|
|
assertThat(widgetTypes.getData()).hasSize(1); |
|
|
|
assertThat(widgetTypes.getData().get(0).getId()).isEqualTo(savedWidgetType.getId()); |
|
|
|
|
|
|
|
widgetTypeDao.removeById(TenantId.SYS_TENANT_ID, savedWidgetType.getUuidId()); |
|
|
|
} |
|
|
|
|
|
|
|
for (var entry : SHOULDNT_FIND_SEARCH_TO_TAGS_MAP.entrySet()) { |
|
|
|
String searchText = entry.getKey(); |
|
|
|
String[] tags = entry.getValue(); |
|
|
|
|
|
|
|
WidgetTypeDetails savedWidgetType = createAndSaveWidgetType(TenantId.SYS_TENANT_ID, WIDGET_TYPE_COUNT + 1, tags); |
|
|
|
widgetTypeDao.saveWidgetsBundleWidget(new WidgetsBundleWidget(this.widgetsBundle.getId(), savedWidgetType.getId(), WIDGET_TYPE_COUNT + 1)); |
|
|
|
|
|
|
|
PageData<WidgetTypeInfo> widgetTypes = widgetTypeDao.findWidgetTypesInfosByWidgetsBundleId( |
|
|
|
TenantId.SYS_TENANT_ID.getId(), widgetsBundle.getUuidId(), true, DeprecatedFilter.ALL, null, new PageLink(10, 0, searchText) |
|
|
|
); |
|
|
|
|
|
|
|
assertThat(widgetTypes.getData()).hasSize(0); |
|
|
|
|
|
|
|
widgetTypeDao.removeById(TenantId.SYS_TENANT_ID, savedWidgetType.getUuidId()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testFindByTenantIdAndFqn() { |
|
|
|
WidgetType result = widgetTypeList.get(0); |
|
|
|
|