Search in sources :

Example 6 with IRepositoryNodeResourceProvider

use of org.talend.mdm.repository.core.IRepositoryNodeResourceProvider in project tmdm-studio-se by Talend.

the class RepositoryResourceUtilTest method testCreateItemWith2Args.

@Test
public void testCreateItemWith2Args() throws Exception {
    String propLabel = "this is propLabel";
    String nextId = "UUID_NEXT";
    Item mockItem = mock(Item.class);
    ItemState mockItemState = mock(ItemState.class);
    when(mockItem.getState()).thenReturn(mockItemState);
    when(mockItem.getState().getPath()).thenReturn("");
    IProxyRepositoryFactory repositoryFactory = mock(IProxyRepositoryFactory.class);
    when(CoreRuntimePlugin.getInstance().getProxyRepositoryFactory()).thenReturn(repositoryFactory);
    RepositoryContext mockContext = mock(RepositoryContext.class);
    when(repositoryFactory.getRepositoryContext()).thenReturn(mockContext);
    when(repositoryFactory.getNextId()).thenReturn(nextId);
    Property mockProperty = mock(Property.class);
    when(mockItem.getProperty()).thenReturn(mockProperty);
    PropertiesFactory proFactory = PropertiesFactory.eINSTANCE;
    PropertiesFactory spyProFactory = PowerMockito.spy(proFactory);
    when(spyProFactory.createProperty()).thenReturn(mockProperty);
    User user = mock(User.class);
    when(mockContext.getUser()).thenReturn(user);
    // following two lines code is handling errors when mockStatic class "RepositoryNodeConfigurationManager"
    RecycleBinNodeConfiguration mockRBNConf = mock(RecycleBinNodeConfiguration.class);
    PowerMockito.whenNew(RecycleBinNodeConfiguration.class).withNoArguments().thenReturn(mockRBNConf);
    PowerMockito.mockStatic(RepositoryNodeConfigurationManager.class);
    IRepositoryNodeConfiguration mockConfManager = mock(IRepositoryNodeConfiguration.class);
    when(RepositoryNodeConfigurationManager.getConfiguration(Mockito.any(Item.class))).thenReturn(mockConfManager);
    IRepositoryNodeResourceProvider mockResourceProvider = mock(IRepositoryNodeResourceProvider.class);
    when(mockConfManager.getResourceProvider()).thenReturn(mockResourceProvider);
    when(mockResourceProvider.needSaveReferenceFile()).thenReturn(true);
    when(repositoryFactory.isEditableAndLockIfPossible(mockItem)).thenReturn(true);
    Resource mockResource = mock(Resource.class);
    ResourceSet mockResourceSet = mock(ResourceSet.class);
    when(mockResource.getResourceSet()).thenReturn(mockResourceSet);
    when(mockItem.eResource()).thenReturn(mockResource);
    boolean createItem = RepositoryResourceUtil.createItem(mockItem, propLabel);
    verify(mockProperty, times(1)).setId(nextId);
    verify(mockProperty, times(1)).setVersion(Mockito.anyString());
    verify(mockProperty, times(1)).setAuthor(user);
    verify(mockProperty, times(1)).setLabel(propLabel);
    verify(repositoryFactory, times(1)).create(Mockito.any(Item.class), Mockito.any(IPath.class));
    verify(mockResourceProvider, times(1)).handleReferenceFile(mockItem);
    verify(repositoryFactory, times(1)).unlock(mockItem);
    assertTrue(createItem);
}
Also used : RepositoryContext(org.talend.core.context.RepositoryContext) User(org.talend.core.model.properties.User) IPath(org.eclipse.core.runtime.IPath) RecycleBinNodeConfiguration(org.talend.mdm.repository.core.impl.recyclebin.RecycleBinNodeConfiguration) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) Item(org.talend.core.model.properties.Item) ContainerItem(org.talend.mdm.repository.model.mdmproperties.ContainerItem) IRepositoryNodeResourceProvider(org.talend.mdm.repository.core.IRepositoryNodeResourceProvider) ItemState(org.talend.core.model.properties.ItemState) IRepositoryNodeConfiguration(org.talend.mdm.repository.core.IRepositoryNodeConfiguration) PropertiesFactory(org.talend.core.model.properties.PropertiesFactory) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with IRepositoryNodeResourceProvider

use of org.talend.mdm.repository.core.IRepositoryNodeResourceProvider in project tmdm-studio-se by Talend.

the class RepositoryResourceUtilTest method testSaveItem.

@Test
public void testSaveItem() throws Exception {
    // following two lines code is handling errors when mockStatic class "RepositoryNodeConfigurationManager"
    RecycleBinNodeConfiguration mockRBNConf = mock(RecycleBinNodeConfiguration.class);
    PowerMockito.whenNew(RecycleBinNodeConfiguration.class).withNoArguments().thenReturn(mockRBNConf);
    PowerMockito.mockStatic(RepositoryNodeConfigurationManager.class);
    Item mockItem = mock(Item.class);
    IRepositoryNodeConfiguration mockConf = mock(IRepositoryNodeConfiguration.class);
    when(RepositoryNodeConfigurationManager.getConfiguration(mockItem)).thenReturn(mockConf);
    IRepositoryNodeResourceProvider mockResourceProvider = mock(IRepositoryNodeResourceProvider.class);
    when(mockConf.getResourceProvider()).thenReturn(mockResourceProvider);
    when(mockResourceProvider.needSaveReferenceFile()).thenReturn(true);
    IProxyRepositoryFactory repositoryFactory = mock(IProxyRepositoryFactory.class);
    when(CoreRuntimePlugin.getInstance().getProxyRepositoryFactory()).thenReturn(repositoryFactory);
    RepositoryResourceUtil.saveItem(mockItem);
    verify(mockResourceProvider, Mockito.times(1)).handleReferenceFile(mockItem);
    verify(repositoryFactory, Mockito.times(1)).save(mockItem, false);
}
Also used : Item(org.talend.core.model.properties.Item) ContainerItem(org.talend.mdm.repository.model.mdmproperties.ContainerItem) IRepositoryNodeResourceProvider(org.talend.mdm.repository.core.IRepositoryNodeResourceProvider) RecycleBinNodeConfiguration(org.talend.mdm.repository.core.impl.recyclebin.RecycleBinNodeConfiguration) IRepositoryNodeConfiguration(org.talend.mdm.repository.core.IRepositoryNodeConfiguration) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with IRepositoryNodeResourceProvider

use of org.talend.mdm.repository.core.IRepositoryNodeResourceProvider in project tmdm-studio-se by Talend.

the class RepositoryResourceUtil method saveItem.

public static void saveItem(Item item, boolean triggerEvent) {
    IRepositoryNodeConfiguration configuration = RepositoryNodeConfigurationManager.getConfiguration(item);
    if (configuration != null) {
        IRepositoryNodeResourceProvider resourceProvider = configuration.getResourceProvider();
        if (resourceProvider.needSaveReferenceFile()) {
            item = assertItem(item);
            resourceProvider.handleReferenceFile(item);
        }
        // save
        IProxyRepositoryFactory factory = CoreRuntimePlugin.getInstance().getProxyRepositoryFactory();
        try {
            item = assertItem(item);
            factory.save(item, !triggerEvent);
        } catch (PersistenceException e) {
            log.error(e);
        }
    }
}
Also used : IRepositoryNodeResourceProvider(org.talend.mdm.repository.core.IRepositoryNodeResourceProvider) PersistenceException(org.talend.commons.exception.PersistenceException) IRepositoryNodeConfiguration(org.talend.mdm.repository.core.IRepositoryNodeConfiguration) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Aggregations

IRepositoryNodeConfiguration (org.talend.mdm.repository.core.IRepositoryNodeConfiguration)8 IRepositoryNodeResourceProvider (org.talend.mdm.repository.core.IRepositoryNodeResourceProvider)8 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)6 RepositoryContext (org.talend.core.context.RepositoryContext)4 RecycleBinNodeConfiguration (org.talend.mdm.repository.core.impl.recyclebin.RecycleBinNodeConfiguration)4 ContainerItem (org.talend.mdm.repository.model.mdmproperties.ContainerItem)4 Test (org.junit.Test)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 Item (org.talend.core.model.properties.Item)3 User (org.talend.core.model.properties.User)3 ResourceBundle (java.util.ResourceBundle)2 IPath (org.eclipse.core.runtime.IPath)2 ImageRegistry (org.eclipse.jface.resource.ImageRegistry)2 Before (org.junit.Before)2 PersistenceException (org.talend.commons.exception.PersistenceException)2 Project (org.talend.core.model.general.Project)2 Property (org.talend.core.model.properties.Property)2 IRepositoryFactory (org.talend.core.repository.model.IRepositoryFactory)2 ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)2 XmiResourceManager (org.talend.core.repository.utils.XmiResourceManager)2