Search in sources :

Example 11 with IRepositoryNodeConfiguration

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

the class RemoveFromRepositoryActionTest method setUp.

@Before
public void setUp() throws Exception {
    ResourceBundle rb = mock(ResourceBundle.class);
    // $NON-NLS-1$
    stub(method(ResourceBundle.class, "getBundle", String.class)).toReturn(rb);
    PowerMockito.mockStatic(JFaceResources.class);
    ImageRegistry registry = mock(ImageRegistry.class);
    when(JFaceResources.getImageRegistry()).thenReturn(registry);
    PowerMockito.mockStatic(DefaultMessagesImpl.class);
    // $NON-NLS-1$
    when(DefaultMessagesImpl.getString(anyString())).thenReturn("anyString()");
    IRepositoryResourceUtilExAdapter mockAdapter = PowerMockito.mock(IRepositoryResourceUtilExAdapter.class);
    PowerMockito.mockStatic(ExAdapterManager.class);
    PowerMockito.when(ExAdapterManager.getAdapter(new RepositoryResourceUtil(), IRepositoryResourceUtilExAdapter.class)).thenReturn(mockAdapter);
    PowerMockito.mockStatic(CoreRuntimePlugin.class);
    CoreRuntimePlugin coreRuntimePlugin = mock(CoreRuntimePlugin.class);
    when(CoreRuntimePlugin.getInstance()).thenReturn(coreRuntimePlugin);
    RepositoryContext contextMock = mock(RepositoryContext.class);
    PowerMockito.mockStatic(ProjectManager.class);
    ProjectManager pmMock = mock(ProjectManager.class);
    projectM = mock(Project.class);
    User userMock = mock(User.class);
    // $NON-NLS-1$
    when(userMock.getLogin()).thenReturn("a@b.cn");
    when(projectM.getAuthor()).thenReturn(userMock);
    when(pmMock.getCurrentProject()).thenReturn(projectM);
    when(ProjectManager.getInstance()).thenReturn(pmMock);
    when(contextMock.getUser()).thenReturn(userMock);
    repositoryFactory = mock(ProxyRepositoryFactory.class);
    RecycleBinNodeConfiguration recycleBinNodeConfiguration = mock(RecycleBinNodeConfiguration.class);
    PowerMockito.whenNew(RecycleBinNodeConfiguration.class).withNoArguments().thenReturn(recycleBinNodeConfiguration);
    // $NON-NLS-1$
    stub(method(ProxyRepositoryFactory.class, "getInstance")).toReturn(repositoryFactory);
    when(CoreRuntimePlugin.getInstance().getProxyRepositoryFactory()).thenReturn(repositoryFactory);
    IRepositoryFactory repositoryFactoryMock = mock(IRepositoryFactory.class);
    when(repositoryFactory.getRepositoryFactoryFromProvider()).thenReturn(repositoryFactoryMock);
    XmiResourceManager xmiResourceManager = mock(XmiResourceManager.class);
    when(repositoryFactoryMock.getResourceManager()).thenReturn(xmiResourceManager);
    PowerMockito.mockStatic(RepositoryNodeConfigurationManager.class);
    IRepositoryNodeConfiguration rncMock = mock(IRepositoryNodeConfiguration.class);
    when(RepositoryNodeConfigurationManager.getConfiguration((Item) anyObject())).thenReturn(rncMock);
    IRepositoryNodeResourceProvider resourceProviderM = mock(IRepositoryNodeResourceProvider.class);
    when(rncMock.getResourceProvider()).thenReturn(resourceProviderM);
    when(resourceProviderM.needSaveReferenceFile()).thenReturn(true);
    when(repositoryFactory.getRepositoryContext()).thenReturn(contextMock);
    when(repositoryFactory.isEditableAndLockIfPossible((Item) anyObject())).thenReturn(true);
}
Also used : RepositoryContext(org.talend.core.context.RepositoryContext) IRepositoryFactory(org.talend.core.repository.model.IRepositoryFactory) User(org.talend.core.model.properties.User) RecycleBinNodeConfiguration(org.talend.mdm.repository.core.impl.recyclebin.RecycleBinNodeConfiguration) IRepositoryResourceUtilExAdapter(org.talend.mdm.repository.utils.IRepositoryResourceUtilExAdapter) XmiResourceManager(org.talend.core.repository.utils.XmiResourceManager) ProjectManager(org.talend.repository.ProjectManager) Project(org.talend.core.model.general.Project) ImageRegistry(org.eclipse.jface.resource.ImageRegistry) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) IRepositoryNodeResourceProvider(org.talend.mdm.repository.core.IRepositoryNodeResourceProvider) IRepositoryNodeConfiguration(org.talend.mdm.repository.core.IRepositoryNodeConfiguration) ResourceBundle(java.util.ResourceBundle) RepositoryResourceUtil(org.talend.mdm.repository.utils.RepositoryResourceUtil) CoreRuntimePlugin(org.talend.core.runtime.CoreRuntimePlugin) Before(org.junit.Before)

Example 12 with IRepositoryNodeConfiguration

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

the class RenameObjectActionTest method setUp.

@Before
public void setUp() throws Exception {
    ResourceBundle rb = mock(ResourceBundle.class);
    // $NON-NLS-1$
    stub(method(ResourceBundle.class, "getBundle", String.class)).toReturn(rb);
    PowerMockito.mockStatic(JFaceResources.class);
    ImageRegistry registry = mock(ImageRegistry.class);
    when(JFaceResources.getImageRegistry()).thenReturn(registry);
    PowerMockito.mockStatic(DefaultMessagesImpl.class);
    // $NON-NLS-1$
    when(DefaultMessagesImpl.getString(anyString())).thenReturn("anyString()");
    IRepositoryResourceUtilExAdapter mockAdapter = PowerMockito.mock(IRepositoryResourceUtilExAdapter.class);
    PowerMockito.mockStatic(ExAdapterManager.class);
    PowerMockito.when(ExAdapterManager.getAdapter(new RepositoryResourceUtil(), IRepositoryResourceUtilExAdapter.class)).thenReturn(mockAdapter);
    PowerMockito.mockStatic(MDMWorbenchPlugin.class);
    when(MDMWorbenchPlugin.getImageDescriptor(anyString())).thenReturn(mock(ImageDescriptor.class));
    PowerMockito.mockStatic(ImageCache.class);
    ImageDescriptor imgDesc = mock(ImageDescriptor.class);
    when(ImageCache.getImage(anyString())).thenReturn(imgDesc);
    // 
    PowerMockito.mockStatic(CoreRuntimePlugin.class);
    CoreRuntimePlugin coreRuntimePlugin = mock(CoreRuntimePlugin.class);
    when(CoreRuntimePlugin.getInstance()).thenReturn(coreRuntimePlugin);
    RepositoryContext contextMock = mock(RepositoryContext.class);
    PowerMockito.mockStatic(ProjectManager.class);
    ProjectManager pmMock = mock(ProjectManager.class);
    projectM = mock(Project.class);
    User userMock = mock(User.class);
    // $NON-NLS-1$
    when(userMock.getLogin()).thenReturn("a@b.cn");
    when(projectM.getAuthor()).thenReturn(userMock);
    when(pmMock.getCurrentProject()).thenReturn(projectM);
    when(ProjectManager.getInstance()).thenReturn(pmMock);
    when(contextMock.getUser()).thenReturn(userMock);
    // 
    repositoryFactory = mock(IProxyRepositoryFactory.class);
    when(CoreRuntimePlugin.getInstance().getProxyRepositoryFactory()).thenReturn(repositoryFactory);
    RecycleBinNodeConfiguration recycleBinNodeConfiguration = mock(RecycleBinNodeConfiguration.class);
    PowerMockito.whenNew(RecycleBinNodeConfiguration.class).withNoArguments().thenReturn(recycleBinNodeConfiguration);
    PowerMockito.mockStatic(ProxyRepositoryFactory.class);
    ProxyRepositoryFactory proxyRepositoryFactory = mock(ProxyRepositoryFactory.class);
    when(ProxyRepositoryFactory.getInstance()).thenReturn(proxyRepositoryFactory);
    IRepositoryFactory repositoryFactoryMock = mock(IRepositoryFactory.class);
    when(proxyRepositoryFactory.getRepositoryFactoryFromProvider()).thenReturn(repositoryFactoryMock);
    XmiResourceManager xmiResourceManager = mock(XmiResourceManager.class);
    when(repositoryFactoryMock.getResourceManager()).thenReturn(xmiResourceManager);
    PowerMockito.mockStatic(RepositoryNodeConfigurationManager.class);
    IRepositoryNodeConfiguration rncMock = mock(IRepositoryNodeConfiguration.class);
    when(RepositoryNodeConfigurationManager.getConfiguration((Item) anyObject())).thenReturn(rncMock);
    resourceProviderM = mock(IRepositoryNodeResourceProvider.class);
    when(rncMock.getResourceProvider()).thenReturn(resourceProviderM);
    when(repositoryFactory.isEditableAndLockIfPossible((Item) anyObject())).thenReturn(true);
}
Also used : RepositoryContext(org.talend.core.context.RepositoryContext) IRepositoryFactory(org.talend.core.repository.model.IRepositoryFactory) User(org.talend.core.model.properties.User) RecycleBinNodeConfiguration(org.talend.mdm.repository.core.impl.recyclebin.RecycleBinNodeConfiguration) IRepositoryResourceUtilExAdapter(org.talend.mdm.repository.utils.IRepositoryResourceUtilExAdapter) XmiResourceManager(org.talend.core.repository.utils.XmiResourceManager) ProjectManager(org.talend.repository.ProjectManager) Project(org.talend.core.model.general.Project) ImageRegistry(org.eclipse.jface.resource.ImageRegistry) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) IRepositoryNodeResourceProvider(org.talend.mdm.repository.core.IRepositoryNodeResourceProvider) IRepositoryNodeConfiguration(org.talend.mdm.repository.core.IRepositoryNodeConfiguration) ResourceBundle(java.util.ResourceBundle) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) RepositoryResourceUtil(org.talend.mdm.repository.utils.RepositoryResourceUtil) CoreRuntimePlugin(org.talend.core.runtime.CoreRuntimePlugin) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) Before(org.junit.Before)

Example 13 with IRepositoryNodeConfiguration

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

the class RepositoryResourceUtilTest method testGetCategoryViewObject.

/**
 * Test for: getCategoryViewObject(IRepositoryNodeConfiguration conf)
 */
@Test
public void testGetCategoryViewObject() throws Exception {
    IRepositoryNodeConfiguration mockConfiguration = mock(IRepositoryNodeConfiguration.class);
    IRepositoryNodeResourceProvider mockResourceProvider = mock(IRepositoryNodeResourceProvider.class);
    when(mockConfiguration.getResourceProvider()).thenReturn(mockResourceProvider);
    ERepositoryObjectType mockType = mock(ERepositoryObjectType.class);
    when(mockConfiguration.getResourceProvider().getRepositoryObjectType(Mockito.any(Item.class))).thenReturn(mockType);
    IRepositoryNodeLabelProvider mockLabelProvider = mock(IRepositoryNodeLabelProvider.class);
    when(mockConfiguration.getLabelProvider()).thenReturn(mockLabelProvider);
    when(mockLabelProvider.getCategoryLabel(Mockito.any(ERepositoryObjectType.class))).thenReturn("anystring");
    PowerMockito.mockStatic(ContainerCacheService.class);
    PowerMockito.doNothing().when(ContainerCacheService.class, "putContainer", Mockito.any(IRepositoryViewObject.class));
    IRepositoryViewObject categoryViewObject = RepositoryResourceUtil.getCategoryViewObject(mockConfiguration);
    assertNotNull(categoryViewObject);
}
Also used : Item(org.talend.core.model.properties.Item) ContainerItem(org.talend.mdm.repository.model.mdmproperties.ContainerItem) IRepositoryNodeResourceProvider(org.talend.mdm.repository.core.IRepositoryNodeResourceProvider) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IRepositoryNodeConfiguration(org.talend.mdm.repository.core.IRepositoryNodeConfiguration) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) IRepositoryNodeLabelProvider(org.talend.mdm.repository.core.IRepositoryNodeLabelProvider) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 14 with IRepositoryNodeConfiguration

use of org.talend.mdm.repository.core.IRepositoryNodeConfiguration 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 15 with IRepositoryNodeConfiguration

use of org.talend.mdm.repository.core.IRepositoryNodeConfiguration 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)

Aggregations

IRepositoryNodeConfiguration (org.talend.mdm.repository.core.IRepositoryNodeConfiguration)24 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)13 IRepositoryNodeResourceProvider (org.talend.mdm.repository.core.IRepositoryNodeResourceProvider)9 Item (org.talend.core.model.properties.Item)8 ContainerItem (org.talend.mdm.repository.model.mdmproperties.ContainerItem)8 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)8 ERepositoryObjectType (org.talend.core.model.repository.ERepositoryObjectType)6 RepositoryContext (org.talend.core.context.RepositoryContext)5 RecycleBinNodeConfiguration (org.talend.mdm.repository.core.impl.recyclebin.RecycleBinNodeConfiguration)5 PersistenceException (org.talend.commons.exception.PersistenceException)4 Property (org.talend.core.model.properties.Property)4 User (org.talend.core.model.properties.User)4 ResourceBundle (java.util.ResourceBundle)3 ImageRegistry (org.eclipse.jface.resource.ImageRegistry)3 Before (org.junit.Before)3 Test (org.junit.Test)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 LoginException (org.talend.commons.exception.LoginException)3 Project (org.talend.core.model.general.Project)3 IRepositoryFactory (org.talend.core.repository.model.IRepositoryFactory)3