@Override protected Map<String, List<StagedModel>> addDependentStagedModelsMap(Group group) throws Exception { Map<String, List<StagedModel>> dependentStagedModelsMap = new HashMap<>(); AssetVocabulary vocabulary = AssetTestUtil.addVocabulary(group.getGroupId()); addDependentStagedModel(dependentStagedModelsMap, AssetVocabulary.class, vocabulary); AssetCategory category = AssetTestUtil.addCategory(group.getGroupId(), vocabulary.getVocabularyId()); addDependentStagedModel(dependentStagedModelsMap, AssetCategory.class, category); return dependentStagedModelsMap; }
@Before public void setUp() throws Exception { _assetCategoryPersistence = AssetCategoryUtil.getPersistence(); _sessionFactoryInvocationHandler = new SessionFactoryInvocationHandler( ReflectionTestUtil.getFieldValue(_assetCategoryPersistence, "_sessionFactory")); ReflectionTestUtil.setFieldValue( _assetCategoryPersistence, "_sessionFactory", ProxyUtil.newProxyInstance( SessionFactory.class.getClassLoader(), new Class<?>[] {SessionFactory.class}, _sessionFactoryInvocationHandler)); _assetCategoryPersistence.setRebuildTreeEnabled(false); _nestedSetsTreeManager = new PersistenceNestedSetsTreeManager<AssetCategory>( (BasePersistenceImpl<?>) _assetCategoryPersistence, "AssetCategory", "AssetCategory", AssetCategoryImpl.class, "categoryId", "groupId", "leftCategoryId", "rightCategoryId"); _group = GroupTestUtil.addGroup(); _assetVocabulary = AssetTestUtil.addVocabulary(_group.getGroupId()); _assetCategories = new AssetCategory[9]; for (int i = 0; i < 9; i++) { _assetCategories[i] = AssetTestUtil.addCategory(_group.getGroupId(), _assetVocabulary.getVocabularyId()); } PropsValues.SPRING_HIBERNATE_SESSION_DELEGATED = false; }
@Override protected StagedModel addStagedModel( Group group, Map<String, List<StagedModel>> dependentStagedModelsMap) throws Exception { List<StagedModel> vocabularyDependentStagedModels = dependentStagedModelsMap.get(AssetVocabulary.class.getSimpleName()); AssetVocabulary vocabulary = (AssetVocabulary) vocabularyDependentStagedModels.get(0); List<StagedModel> categoryDependentStagedModels = dependentStagedModelsMap.get(AssetCategory.class.getSimpleName()); AssetCategory category = (AssetCategory) categoryDependentStagedModels.get(0); return AssetTestUtil.addCategory( group.getGroupId(), vocabulary.getVocabularyId(), category.getCategoryId()); }
@Test public void testDeleteLinksByAssetEntryGroupId() throws Exception { // Add link between entries in group 1 AssetEntry assetEntry1 = AssetTestUtil.addAssetEntry(_group1.getGroupId()); AssetEntry assetEntry2 = AssetTestUtil.addAssetEntry(_group1.getGroupId()); AssetLinkLocalServiceUtil.addLink( TestPropsValues.getUserId(), assetEntry1.getEntryId(), assetEntry2.getEntryId(), 0, 0); // Add link between entries in different groups assetEntry1 = AssetTestUtil.addAssetEntry(_group1.getGroupId()); assetEntry2 = AssetTestUtil.addAssetEntry(_group2.getGroupId()); AssetLinkLocalServiceUtil.addLink( TestPropsValues.getUserId(), assetEntry1.getEntryId(), assetEntry2.getEntryId(), 0, 0); // Add link between entries in group 2 assetEntry1 = AssetTestUtil.addAssetEntry(_group2.getGroupId()); assetEntry2 = AssetTestUtil.addAssetEntry(_group2.getGroupId()); AssetLinkLocalServiceUtil.addLink( TestPropsValues.getUserId(), assetEntry1.getEntryId(), assetEntry2.getEntryId(), 0, 0); AssetLinkLocalServiceUtil.deleteGroupLinks(_group1.getGroupId()); List<AssetLink> assetLinks = AssetLinkLocalServiceUtil.getAssetLinks(QueryUtil.ALL_POS, QueryUtil.ALL_POS); Assert.assertNotNull(assetLinks); Assert.assertTrue(assetLinks.size() > 0); for (AssetLink assetLink : assetLinks) { AssetEntry assetEntry = AssetEntryLocalServiceUtil.getEntry(assetLink.getEntryId1()); Assert.assertTrue(assetEntry.getGroupId() != _group1.getGroupId()); assetEntry = AssetEntryLocalServiceUtil.getEntry(assetLink.getEntryId2()); Assert.assertTrue(assetEntry.getGroupId() != _group1.getGroupId()); } }
@Override protected StagedModel addStagedModel( Group group, Map<String, List<StagedModel>> dependentStagedModelsMap) throws Exception { return AssetTestUtil.addTag(group.getGroupId()); }