JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> implements AssetDao { @Override public Optional<Asset> findAssetsByTenantIdAndName(UUID tenantId, String name) { Asset asset = DaoUtil.getData(assetRepository.findByTenantIdAndName(fromTimeUUID(tenantId), name)); return Optional.ofNullable(asset); }  @Override List<Asset> findAssetsByTenantId(UUID tenantId, TextPageLink pageLink); @Override ListenableFuture<List<Asset>> findAssetsByTenantIdAndIdsAsync(UUID tenantId, List<UUID> assetIds); @Override List<Asset> findAssetsByTenantIdAndCustomerId(UUID tenantId, UUID customerId, TextPageLink pageLink); @Override ListenableFuture<List<Asset>> findAssetsByTenantIdAndCustomerIdAndIdsAsync(UUID tenantId, UUID customerId, List<UUID> assetIds); @Override Optional<Asset> findAssetsByTenantIdAndName(UUID tenantId, String name); @Override List<Asset> findAssetsByTenantIdAndType(UUID tenantId, String type, TextPageLink pageLink); @Override List<Asset> findAssetsByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, TextPageLink pageLink); @Override ListenableFuture<List<EntitySubtype>> findTenantAssetTypesAsync(UUID tenantId);  }
@Test public void testFindAssetsByTenantIdAndName() { UUID assetId1 = UUIDs.timeBased(); UUID assetId2 = UUIDs.timeBased(); UUID tenantId1 = UUIDs.timeBased(); UUID tenantId2 = UUIDs.timeBased(); UUID customerId1 = UUIDs.timeBased(); UUID customerId2 = UUIDs.timeBased(); String name = "TEST_ASSET"; saveAsset(assetId1, tenantId1, customerId1, name, "TYPE_1"); saveAsset(assetId2, tenantId2, customerId2, name, "TYPE_1"); Optional<Asset> assetOpt1 = assetDao.findAssetsByTenantIdAndName(tenantId2, name); assertTrue("Optional expected to be non-empty", assetOpt1.isPresent()); assertEquals(assetId2, assetOpt1.get().getId().getId()); Optional<Asset> assetOpt2 = assetDao.findAssetsByTenantIdAndName(tenantId2, "NON_EXISTENT_NAME"); assertFalse("Optional expected to be empty", assetOpt2.isPresent()); }