on 2021 Sep 21 1:23 PM
I'm trying to run impex import (insert Products) in the integration test (ServiceLayerTest). No additional mandatory attributes were added to Product itemtype.
The problem, is that the same script works well via hac, but from the test it throws strange exception message:
" (junit) (00000001) [ImpExImportReader] line 3 at main script: dumped unresolved line ValueLine[unresolvable:error creating item despite missing mandatory/initial columns : line 5: cannot create Product with values ItemAttributeMap[ registry: null, type: <null>, data: {onlinedate=Sat Sep 11 00:00:00 EEST 2021, code=testingimpex, approvalstatus=ArticleApprovalStatus.check(check(8796093087835))} ] due to [de.hybris.platform.servicelayer. interceptor.impl.MandatoryAttributesValidator@7c78d028]:missing values for [catalogVersion] in model ProductModel (<unsaved>) to create a new Product| column 3: could not resolve item for Default;column 4: could not resolve item for Default:Staged, error creating item despite missing mandatory/initial columns : line 3: cannot create Product with values ItemAttributeMap[ registry: null, type: <null>, data: {onlinedate=Sat Sep 11 00:00:00 EEST 2021, code=testin gimpex, approvalstatus=ArticleApprovalStatus.check(check(8796093087835))} ] due to [de.hybris.platform.servicelayer.interceptor.impl.MandatoryAttributesValidator@7c78d028]:missing values for [catalogVersion] in model ProductModel (< unsaved>) to create a new Product,line 3 at main script,null,HeaderDescriptor[line 2 at main script, insert_update, Product, {}, [code, approvalstatus, catalog, catalogversion, onlineDate] ],{1=ValueEntry('testingimpex'=testingimpex ,unresolved=false,ignore=false), 2=ValueEntry(''=ArticleApprovalStatus.check(check(8796093087835)),unresolved=false,ignore=false), 3=ValueEntry('Default'=null,unresolved=true,reason:could not resolve item for Default,ignore=false), 4=ValueEntry('Default:Staged'=null,unresolved=true,reason:could not resolve item for Default:Staged,ignore=false), 5=ValueEntry('11.09.2021'=Sat Sep 11 00:00:00 EEST 2021,unresolved=false,ignore=false)}] [yunitint] INFO [main] (junit) (00000001) [Importer] Finished 2 pass in 0d 00h:00m:00s:061ms - processed: 1, dumped: 1 (last pass: 1) [yunitint] INFO [main] (junit) (00000001) [DefaultDumpHandler] Dump file is located at C:\Users\jfiek\AppData\Local\Temp\dumpfile4713950563692886948.tmp [yunitint] WARN [main] (junit) (00000001) [Importer] Import aborted after 0d 00h:00m:00s:728ms [yunitint] ERROR [main] (junit) (00000001) [DefaultCsvImportService] line 3 at main script: Can not resolve any more lines ... Aborting further passes (at pass 2). Finally could not import 1 lines! [yunitint] ERROR [main] (junit) [LogRunListener] Test method testExecuteCronJob(com.training.jobs.ImpexImportCronJobIntegrationTest) failed!! [yunitint] java.lang.AssertionError: Something went wrong expected:<SUCCESS> but was:<FAILURE> [yunitint] at org.junit.Assert.fail(Assert.java:89) ~[junit-4.13.1.jar:4.13.1]"
The script:
$catalog=catalog(id)
$catalogVersion=catalogversion($catalog, version)
$approved=approvalstatus(code)[default='check']
INSERT_UPDATE Product;code[unique=true];$approved;$catalog;$catalogVersion;onlineDate[dateformat=dd.MM.yyyy]
;testingimpex1;;Default;Default:Staged;11.09.2021
Test class:
package com.training.jobs;
import com.training.model.ImpexCronJobModel;
import de.hybris.bootstrap.annotations.IntegrationTest;
import de.hybris.platform.cronjob.enums.CronJobResult;
import de.hybris.platform.servicelayer.ServicelayerTest;
import de.hybris.platform.servicelayer.cronjob.CronJobService;
import de.hybris.platform.servicelayer.exceptions.ModelNotFoundException;
import de.hybris.platform.servicelayer.internal.model.ServicelayerJobModel;
import de.hybris.platform.servicelayer.model.ModelService;
import de.hybris.platform.servicelayer.search.FlexibleSearchService;
import org.apache.log4j.Logger;
import org.junit.Before;
import org.junit.Test;
import javax.annotation.Resource;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@IntegrationTest
public class ImpexImportCronJobIntegrationTest extends ServicelayerTest {
private static final Logger LOGGER = Logger.getLogger(ImpexImportCronJobIntegrationTest.class);
@Resource
private ModelService modelService;
@Resource
private CronJobService cronJobService;
@Resource
private FlexibleSearchService flexibleSearchService;
ServicelayerJobModel servicelayerJob;
ImpexCronJobModel impexCronJob;
@Before
public void setUp() {
ServicelayerJobModel sjm = new ServicelayerJobModel();
sjm.setSpringId("impexImportJob");
try{
servicelayerJob = flexibleSearchService.getModelByExample(sjm);
} catch (ModelNotFoundException e) {
servicelayerJob = modelService.create(ServicelayerJobModel.class);
servicelayerJob.setSpringId("impexImportJob");
servicelayerJob.setCode("impexImportJob");
modelService.save(servicelayerJob);
}
impexCronJob = modelService.create(ImpexCronJobModel.class);
impexCronJob.setActive(Boolean.TRUE);
impexCronJob.setJob(servicelayerJob);
modelService.save(impexCronJob);
}
@Test
public void testCheckIfJobPerformableExists() {
assertNotNull("***************No performable with springID *impexImportJob* found perhaps you have to "
+ "Update your JunitTenant to let create an instance!", servicelayerJob);
}
@Test
public void testExecuteCronJob() {
assertNotNull("***************CronJob initialized from setUp() method is null", impexCronJob);
cronJobService.performCronJob(impexCronJob, true);
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
LOGGER.error(e.getMessage());
}
assertEquals("Something went wrong", CronJobResult.SUCCESS, impexCronJob.getResult());
}
}
Request clarification before answering.
Mykhailo,
the problem is caused by absence of Default catalog and Staged catalogVersion in yunit tenant. Tests are executed against that tenant and there is pretty much no data in it. Therefore you need to create the catalog and the catalog version first. We use impex extensively in our integration tests and learned that it's better to create test specific catalogs and versions. For example, we would create a catalog named Test and a version named after the test. But this is not strictly needed. You may use the Default:Staged catalog version but you need to create that version and the catalog first.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
22 | |
16 | |
4 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.