/** * Prepare for tests. * * @throws Exception in case of error happens */ @SuppressWarnings("unchecked") @Before public void setUp() throws Exception { mockElasticPath = context.mock(ElasticPath.class); mockProductService = context.mock(ProductService.class); mockImportExportSearcher = context.mock(ImportExportSearcher.class); mockProductAdapter = context.mock(DomainAdapter.class); context.checking( new Expectations() { { allowing(mockProductService) .findByUids(with(any(Collection.class)), with(aNull(ProductLoadTuner.class))); will(returnValue(getFoundedProductsList())); allowing(mockProductAdapter) .populateDTO(with(any(Product.class)), with(any(ProductDTO.class))); allowing(mockProductAdapter).createDtoObject(); will(returnValue(new ProductDTO())); } }); productExporter = new ProductExporterImpl(); productExporter.setElasticPath(mockElasticPath); productExporter.setImportExportSearcher(mockImportExportSearcher); productExporter.setProductService(mockProductService); productExporter.setProductAdapter(mockProductAdapter); }
/** Check an export of one product with export criteria. */ @Test public void testProcessExportWithCriteria() throws Exception { testExporterInitializationWithCriteria(); productExporter.processExport(System.out); Summary summary = productExporter.getContext().getSummary(); assertEquals(1, summary.getCounters().size()); assertNotNull(summary.getCounters().get(JobType.PRODUCT)); assertEquals(1, summary.getCounters().get(JobType.PRODUCT).intValue()); assertEquals(0, summary.getFailures().size()); assertNotNull(summary.getStartDate()); assertNotNull(summary.getElapsedTime()); assertNotNull(summary.getElapsedTime().toString()); }
/** * Check that during initialization exporter prepares the list of UidPk for products to be * exported. Method searchCriteriaAdapter.populateDomain(exportSearchCriteria, searchCriteria) is * expected because exportConfiguration contains productExportCriteria to be transformed into * searchCriteria. */ @Test public void testExporterInitializationWithCriteria() throws Exception { final long uid = PRODUCT_UID; final List<Long> productUidPkList = new ArrayList<Long>(); productUidPkList.add(uid); setUpExportContextWithProductExportCriteria(); context.checking( new Expectations() { { oneOf(mockImportExportSearcher).searchUids(searchConfiguration, EPQueryType.PRODUCT); will(returnValue(productUidPkList)); } }); productExporter.initialize(exportContext); }
/** * Check that during initialization exporter prepares the list of UidPk for products to be * exported. */ @Test public void testExporterInitializationWithRetrieveAllProductsQuery() throws Exception { final long uid = PRODUCT_UID; final List<Long> productUidPkList = new ArrayList<Long>(); productUidPkList.add(uid); exportConfiguration = new ExportConfiguration(); ExporterConfiguration exporterConfiguration = new ExporterConfiguration(); List<OptionalExporterConfiguration> optionalExporterConfigurationList = new ArrayList<OptionalExporterConfiguration>(); OptionalExporterConfiguration optionalExporterConfiguration = new OptionalExporterConfiguration(); optionalExporterConfiguration.setType(JobType.PRODUCTASSOCIATION); List<ConfigurationOption> options = new ArrayList<ConfigurationOption>(); ConfigurationOption option = new ConfigurationOption(); option.setKey(ProductExporterImpl.DIRECT_ONLY); option.setValue(Boolean.TRUE.toString()); options.add(option); optionalExporterConfiguration.setOptions(options); optionalExporterConfigurationList.add(optionalExporterConfiguration); exporterConfiguration.setOptionalExporterConfigurationList(optionalExporterConfigurationList); exportConfiguration.setExporterConfiguration(exporterConfiguration); searchConfiguration = new SearchConfiguration(); searchConfiguration.setEpQLQuery(QUERY); exportContext = new ExportContext(exportConfiguration, searchConfiguration); exportContext.setDependencyRegistry(new DependencyRegistry(new ArrayList<Class<?>>())); exportContext.setSummary(new SummaryImpl()); context.checking( new Expectations() { { oneOf(mockImportExportSearcher).searchUids(searchConfiguration, EPQueryType.PRODUCT); will(returnValue(productUidPkList)); } }); productExporter.initialize(exportContext); }