Testing Hybris commerce-同步集成测试

Testing Hybris commerce-同步集成测试,testing,integration,hybris,Testing,Integration,Hybris,我是海布里斯商务的初学者。我需要同步产品目录的集成测试,但是我在同步时遇到了一个问题。我在测试中添加了新的产品属性-“分类””和该属性的设置值。然后performCronJob方法从Staged产品目录执行syncJob到Online产品目录。现在,当从在线目录获取产品时,它没有“分类”属性的值,并且出现断言错误。请告诉我,为什么会这样。这是我的测试 @RunWith(HybrisJUnit4ClassRunner.class) @RunListeners( { TransactionRunLi

我是海布里斯商务的初学者。我需要同步产品目录的集成测试,但是我在同步时遇到了一个问题。我在测试中添加了新的产品属性-“
分类”
”和该属性的设置值。然后
performCronJob
方法从
Staged
产品目录执行
syncJob
Online
产品目录。现在,当从
在线
目录获取产品时,它没有“
分类
”属性的值,并且出现
断言错误
。请告诉我,为什么会这样。这是我的测试

@RunWith(HybrisJUnit4ClassRunner.class)
@RunListeners(
{ TransactionRunListener.class, ItemCreationListener.class, LogRunListener.class, PlatformRunListener.class })
@Transactional
public class ProductMyIntegrationTest extends ServicelayerTransactionalTest
{
    @Resource
    private TypeService typeService;
    @Resource
    private ModelService modelService;
    @Resource
    private CatalogVersionService catalogVersionService;
    @Resource
    private ProductService productService;
    @Resource
    private CronJobService cronJobService;

    public ProductService getProductService()
    {
        return productService;
    }

    public CatalogVersionService getCatalogVersionService()
    {
        return catalogVersionService;
    }

    public TypeService getTypeService()
    {
        return typeService;
    }

    public ModelService getModelService()
    {
        return modelService;
    }

    @Test
    public void testProductSyncBehavior()
    {
        final CatalogVersionModel catalogStagedVersionModel = getCatalogVersionService().getCatalogVersion("hybrisProductCatalog",
                "Staged");
        final CatalogVersionModel catalogOnlineVersionModel = getCatalogVersionService().getCatalogVersion("hybrisProductCatalog",
                "Online");
        final Collection<CatalogVersionModel> coll = new ArrayList<>();
        coll.add(catalogOnlineVersionModel);
        coll.add(catalogStagedVersionModel);
        catalogVersionService.setSessionCatalogVersions(coll);

        final ProductModel product = productService.getProduct(catalogStagedVersionModel, "0100");
        product.setClassification("RRRRRRR");
        getModelService().save(product);

        cronJobService.performCronJob((CatalogVersionSyncCronJobModel) modelService.get(PK.fromLong(8796453503477L)), true);

        final ProductModel prodOnline = modelService.get(productService.getProduct(catalogOnlineVersionModel, "0100").getPk());
        final ProductModel prodStaged = modelService.get(productService.getProduct(catalogStagedVersionModel, "0100").getPk());
        Assert.assertNotNull(prodOnline.getClassification());
    }
}

非常感谢。

我决定了我的问题。我只是扩展了
ServicelayerTest
,但没有成功地进行事务和同步。但是我不明白为什么使用
事务性
不起作用。

我决定了我的问题。我只是扩展了
ServicelayerTest
,但没有成功地进行事务和同步。但我不明白为什么使用
Transactional
不起作用。

使用@Transactional意味着在测试初始化期间(在执行@before之前)启动事务,并在测试之后(在执行@after之后)回滚事务,因此使用服务层实际保存的所有数据永远不会提交到数据库,这就是为什么您无法看到新属性的更改

这似乎是不可预测的,因为在测试属性之前,无法确保同步cronjob有足够的时间同步产品。

使用@Transactional意味着在测试初始化期间(在执行@before之前)启动事务,并在测试后回滚(在执行@after之后),因此您使用服务层实际保存的所有数据永远不会提交到数据库,这就是为什么您无法看到新属性的更改

这似乎是不可预测的,因为在测试属性之前,无法确保同步cronjob有足够的时间同步产品

java.lang.AssertionError
    at org.junit.Assert.fail(Assert.java:86)
    at org.junit.Assert.assertTrue(Assert.java:41)
    at org.junit.Assert.assertNotNull(Assert.java:712)
    at org.junit.Assert.assertNotNull(Assert.java:722)
    at de.hybris.merchandise.core.product.classification.ProductMyIntegrationTest.testProductSyncBehavior(ProductMyIntegrationTest.java:91)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)...