|
|
@ -15,40 +15,69 @@ |
|
|
*/ |
|
|
*/ |
|
|
package org.thingsboard.server.dao.sql.widget; |
|
|
package org.thingsboard.server.dao.sql.widget; |
|
|
|
|
|
|
|
|
import com.github.springtestdbunit.annotation.DatabaseSetup; |
|
|
import org.junit.After; |
|
|
|
|
|
import org.junit.Before; |
|
|
import org.junit.Test; |
|
|
import org.junit.Test; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
import org.thingsboard.server.common.data.id.TenantId; |
|
|
import org.thingsboard.server.common.data.widget.WidgetType; |
|
|
import org.thingsboard.server.common.data.widget.WidgetType; |
|
|
|
|
|
import org.thingsboard.server.common.data.widget.WidgetTypeDetails; |
|
|
import org.thingsboard.server.dao.AbstractJpaDaoTest; |
|
|
import org.thingsboard.server.dao.AbstractJpaDaoTest; |
|
|
import org.thingsboard.server.dao.widget.WidgetTypeDao; |
|
|
import org.thingsboard.server.dao.widget.WidgetTypeDao; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
import java.util.UUID; |
|
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertEquals; |
|
|
import static org.junit.Assert.assertEquals; |
|
|
|
|
|
import static org.junit.Assert.assertNotNull; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Created by Valerii Sosliuk on 4/30/2017. |
|
|
* Created by Valerii Sosliuk on 4/30/2017. |
|
|
*/ |
|
|
*/ |
|
|
public class JpaWidgetTypeDaoTest extends AbstractJpaDaoTest { |
|
|
public class JpaWidgetTypeDaoTest extends AbstractJpaDaoTest { |
|
|
|
|
|
|
|
|
|
|
|
final String BUNDLE_ALIAS = "BUNDLE_ALIAS"; |
|
|
|
|
|
final int WIDGET_TYPE_COUNT = 3; |
|
|
|
|
|
List<WidgetType> widgetTypeList; |
|
|
|
|
|
|
|
|
@Autowired |
|
|
@Autowired |
|
|
private WidgetTypeDao widgetTypeDao; |
|
|
private WidgetTypeDao widgetTypeDao; |
|
|
|
|
|
|
|
|
|
|
|
@Before |
|
|
|
|
|
public void setUp() { |
|
|
|
|
|
widgetTypeList = new ArrayList<>(); |
|
|
|
|
|
for (int i = 0; i < WIDGET_TYPE_COUNT; i++) { |
|
|
|
|
|
widgetTypeList.add(createAndSaveWidgetType(i)); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
WidgetType createAndSaveWidgetType(int number) { |
|
|
|
|
|
WidgetTypeDetails widgetType = new WidgetTypeDetails(); |
|
|
|
|
|
widgetType.setTenantId(TenantId.SYS_TENANT_ID); |
|
|
|
|
|
widgetType.setName("WIDGET_TYPE_" + number); |
|
|
|
|
|
widgetType.setAlias("ALIAS_" + number); |
|
|
|
|
|
widgetType.setBundleAlias(BUNDLE_ALIAS); |
|
|
|
|
|
return widgetTypeDao.save(TenantId.SYS_TENANT_ID, widgetType); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@After |
|
|
|
|
|
public void deleteAllWidgetType() { |
|
|
|
|
|
for (WidgetType widgetType : widgetTypeList) { |
|
|
|
|
|
widgetTypeDao.removeById(TenantId.SYS_TENANT_ID, widgetType.getUuidId()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
@DatabaseSetup(("classpath:dbunit/widget_type.xml")) |
|
|
|
|
|
public void testFindByTenantIdAndBundleAlias() { |
|
|
public void testFindByTenantIdAndBundleAlias() { |
|
|
UUID tenantId = UUID.fromString("2b7e4c90-2dfe-11e7-94aa-f7f6dbfb4833"); |
|
|
List<WidgetType> widgetTypes = widgetTypeDao.findWidgetTypesByTenantIdAndBundleAlias(TenantId.SYS_TENANT_ID.getId(), BUNDLE_ALIAS); |
|
|
List<WidgetType> widgetTypes = widgetTypeDao.findWidgetTypesByTenantIdAndBundleAlias(tenantId, "BUNDLE_ALIAS_1"); |
|
|
assertEquals(WIDGET_TYPE_COUNT, widgetTypes.size()); |
|
|
assertEquals(3, widgetTypes.size()); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
@DatabaseSetup(("classpath:dbunit/widget_type.xml")) |
|
|
|
|
|
public void testFindByTenantIdAndBundleAliasAndAlias() { |
|
|
public void testFindByTenantIdAndBundleAliasAndAlias() { |
|
|
UUID tenantId = UUID.fromString("2b7e4c90-2dfe-11e7-94aa-f7f6dbfb4833"); |
|
|
WidgetType result = widgetTypeList.get(0); |
|
|
WidgetType widgetType = widgetTypeDao.findByTenantIdBundleAliasAndAlias(tenantId, "BUNDLE_ALIAS_1", "ALIAS3"); |
|
|
assertNotNull(result); |
|
|
UUID id = UUID.fromString("2b7e4c93-2dfe-11e7-94aa-f7f6dbfb4833"); |
|
|
WidgetType widgetType = widgetTypeDao.findByTenantIdBundleAliasAndAlias(TenantId.SYS_TENANT_ID.getId(), BUNDLE_ALIAS, "ALIAS_0"); |
|
|
assertEquals(id, widgetType.getId().getId()); |
|
|
assertEquals(result.getId(), widgetType.getId()); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|