2016-09-17 8 views
1

私はhybrisе-commerceで初心者です。私は、同期製品カタログを使った統合テストが必要ですが、同期している間は問題があります。私は新しい製品属性を追加しました - "classification"とテストのこの属性の設定値。次にperformCronJobメソッドはsyncJobからStaged製品カタログ、Online製品カタログになりました。今、Onlineカタログから製品を入手した場合、「classification」属性の値がなく、AssertionErrorが発生します。私に言いなさい、なぜこれが起こるか。これは私のテストです。Hybris商取引 - 同期統合テスト

@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()); 
    } 
} 

てAssertionError:

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)... 

ありがとうございました。

答えて

0

私は私の問題を決めました。私はちょうどトランザクションと同期なしでServicelayerTestを拡張します。しかし、なぜTransactionalで動作しないのかわかりません。 @Transactionalトランザクションがテストの初期化中に開始されたことを意味使用

0

と(@Afterが実行された後に)テスト後にロールバック(@Beforeが実行される前に)ので、すべてのデータは、あなたが実際に保存しますサービス層を使用することは決してデータベースにコミットされないため、新しい属性の変更を見ることができません。

これは、あなたの属性をテストする前に同期のcronjobが製品を同期させるのに十分な時間があることを確かめる方法がないため、予測できないようです。