/** Test check if Overwriting of unique key attribute cache is working */ @Test public void testOverwriteUniqueKeyAttributeCache() { final ComposedType priceRowComposedTypeSpy = Mockito.spy(TypeManager.getInstance().getComposedType(PriceRow.class)); final CatalogManager catalogManager = CatalogManager.getInstance(); final Map args = new HashMap(); args.put(CatalogVersionSyncJob.CODE, "foo"); args.put(CatalogVersionSyncJob.SOURCEVERSION, srcCatalogVersion); args.put(CatalogVersionSyncJob.TARGETVERSION, tgtCatalogVersion); args.put(CatalogVersionSyncJob.MAXTHREADS, Integer.valueOf(1)); final CatalogVersionSyncJob job = catalogManager.createCatalogVersionSyncJob(args); final CatalogVersionSyncCronJob cjob = (CatalogVersionSyncCronJob) job.newExecution(); ctx = Mockito.spy(new CatalogVersionSyncCopyContext(job, cjob, null)); Mockito.when(priceRowComposedTypeSpy.getAttributeDescriptorsIncludingPrivate()) .thenReturn(Collections.EMPTY_SET); Mockito.when(priceRowSpy.getComposedType()).thenReturn(priceRowComposedTypeSpy); ctx.queryNonCatalogItemCopy(priceRowSpy); ctx.queryCatalogItemCopy(priceRowSpy); }
@Test public void testGetAttributesForModiferCriteria() { final AttributeDescriptorModel declaredDescriptor = mock(AttributeDescriptorModel.class); when(declaredDescriptor.getModifiers()).thenReturn(Integer.valueOf(AttributeModifiers.READ)); final AttributeDescriptorModel privateDescriptor = mock(AttributeDescriptorModel.class); when(privateDescriptor.getModifiers()) .thenReturn(Integer.valueOf(AttributeModifiers.READ | AttributeModifiers.PRIVATE)); when(privateDescriptor.getPrivate()).thenReturn(Boolean.TRUE); final AttributeDescriptorModel inheritedDescriptor = mock(AttributeDescriptorModel.class); when(inheritedDescriptor.getModifiers()) .thenReturn(Integer.valueOf(AttributeModifiers.READ | AttributeModifiers.INHERITED)); final AttributeDescriptorModel writableDescriptor = mock(AttributeDescriptorModel.class); when(writableDescriptor.getModifiers()) .thenReturn(Integer.valueOf(AttributeModifiers.READ | AttributeModifiers.WRITE)); when(writableDescriptor.getWritable()).thenReturn(Boolean.TRUE); final AttributeDescriptorModel partofDescriptor = mock(AttributeDescriptorModel.class); when(partofDescriptor.getModifiers()) .thenReturn( Integer.valueOf( AttributeModifiers.READ | AttributeModifiers.PARTOF | AttributeModifiers.WRITE)); when(partofDescriptor.getWritable()).thenReturn(Boolean.TRUE); when(partofDescriptor.getPartOf()).thenReturn(Boolean.TRUE); final Set<AttributeDescriptorModel> declaredDescriptorModels = new HashSet<AttributeDescriptorModel>(); declaredDescriptorModels.add(declaredDescriptor); declaredDescriptorModels.add(writableDescriptor); declaredDescriptorModels.add(partofDescriptor); final Set<AttributeDescriptorModel> inheritedDescriptorModels = new HashSet<AttributeDescriptorModel>(); inheritedDescriptorModels.add(inheritedDescriptor); final ComposedTypeModel typeModel = mock(ComposedTypeModel.class); when((typeModel).getDeclaredattributedescriptors()).thenReturn(declaredDescriptorModels); when((typeModel).getInheritedattributedescriptors()).thenReturn(inheritedDescriptorModels); final PK descriptorPk = PK.fromLong(1234567890); final AttributeDescriptor privateDescriptorItem = mock(AttributeDescriptor.class); when(privateDescriptorItem.getPK()).thenReturn(descriptorPk); when(Boolean.valueOf(privateDescriptorItem.isPrivate())).thenReturn(Boolean.TRUE); final Set<AttributeDescriptor> privateDescriptorItems = new HashSet<AttributeDescriptor>(); privateDescriptorItems.add(privateDescriptorItem); final ComposedType composedType = mock(ComposedType.class); when(modelService.getSource(typeModel)).thenReturn(composedType); when(composedType.getAttributeDescriptorsIncludingPrivate()).thenReturn(privateDescriptorItems); when(modelService.get(privateDescriptorItem)).thenReturn(privateDescriptor); when(typeDao.findComposedTypeByCode("modifierTest")).thenReturn(typeModel); final AttributeModifierCriteria modifierCriteria = new AttributeModifierCriteria(0, AttributeModifiers.ALL, 0); Assert.assertEquals( "Five declared descriptors expected", 5, typeService.getAttributesForModifiers("modifierTest", modifierCriteria).size()); modifierCriteria.addDisallowed(AttributeModifiers.PRIVATE); Assert.assertEquals( "Four declared descriptors expected", 4, typeService.getAttributesForModifiers("modifierTest", modifierCriteria).size()); modifierCriteria.addDisallowed(AttributeModifiers.INHERITED); Assert.assertEquals( "Three declared descriptors expected", 3, typeService.getAttributesForModifiers("modifierTest", modifierCriteria).size()); modifierCriteria.addRequired(AttributeModifiers.WRITE); Assert.assertEquals( "Two declared descriptors expected", 2, typeService.getAttributesForModifiers("modifierTest", modifierCriteria).size()); modifierCriteria.addRequired(AttributeModifiers.PARTOF); Assert.assertEquals( "One declared descriptor expected", 1, typeService.getAttributesForModifiers("modifierTest", modifierCriteria).size()); }