Search in sources :

Example 1 with CoreRuntimePlugin

use of org.talend.core.runtime.CoreRuntimePlugin in project tmdm-studio-se by Talend.

the class AbstractSimpleAddActionTest 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(CoreRuntimePlugin.class);
    CoreRuntimePlugin coreRuntimePlugin = mock(CoreRuntimePlugin.class);
    when(CoreRuntimePlugin.getInstance()).thenReturn(coreRuntimePlugin);
    IProxyRepositoryFactory repositoryFactory = mock(IProxyRepositoryFactory.class);
    when(CoreRuntimePlugin.getInstance().getProxyRepositoryFactory()).thenReturn(repositoryFactory);
    RepositoryContext ontextMock = mock(RepositoryContext.class);
    when(repositoryFactory.getRepositoryContext()).thenReturn(ontextMock);
    PowerMockito.mockStatic(ProjectManager.class);
    ProjectManager pmMock = mock(ProjectManager.class);
    Project pMock = mock(Project.class);
    User userMock = mock(User.class);
    // $NON-NLS-1$
    when(userMock.getLogin()).thenReturn("a@b.cn");
    when(pMock.getAuthor()).thenReturn(userMock);
    when(pmMock.getCurrentProject()).thenReturn(pMock);
    when(ProjectManager.getInstance()).thenReturn(pmMock);
    when(ontextMock.getUser()).thenReturn(userMock);
    IRepositoryResourceUtilExAdapter mockAdapter = PowerMockito.mock(IRepositoryResourceUtilExAdapter.class);
    PowerMockito.mockStatic(ExAdapterManager.class);
    PowerMockito.when(ExAdapterManager.getAdapter(new RepositoryResourceUtil(), IRepositoryResourceUtilExAdapter.class)).thenReturn(mockAdapter);
    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);
    IRepositoryNodeResourceProvider resourceProviderM = mock(IRepositoryNodeResourceProvider.class);
    when(rncMock.getResourceProvider()).thenReturn(resourceProviderM);
    when(resourceProviderM.needSaveReferenceFile()).thenReturn(true);
    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) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) 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) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) Before(org.junit.Before)

Example 2 with CoreRuntimePlugin

use of org.talend.core.runtime.CoreRuntimePlugin 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 3 with CoreRuntimePlugin

use of org.talend.core.runtime.CoreRuntimePlugin 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 4 with CoreRuntimePlugin

use of org.talend.core.runtime.CoreRuntimePlugin in project tmdm-studio-se by Talend.

the class RepositoryResourceUtilTest 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);
    PowerMockito.mockStatic(RepositoryNodeProviderRegistryReader.class);
    RepositoryNodeProviderRegistryReader reader = mock(RepositoryNodeProviderRegistryReader.class);
    PowerMockito.when(RepositoryNodeProviderRegistryReader.getInstance()).thenReturn(reader);
}
Also used : RepositoryNodeProviderRegistryReader(org.talend.core.model.repository.RepositoryNodeProviderRegistryReader) ImageRegistry(org.eclipse.jface.resource.ImageRegistry) ResourceBundle(java.util.ResourceBundle) CoreRuntimePlugin(org.talend.core.runtime.CoreRuntimePlugin) Before(org.junit.Before)

Example 5 with CoreRuntimePlugin

use of org.talend.core.runtime.CoreRuntimePlugin in project tmdm-studio-se by Talend.

the class ValidateServiceTest method testValidateObjectExistence.

@Test
public void testValidateObjectExistence() {
    // $NON-NLS-1$
    String name = "Product";
    ERepositoryObjectType objectType = IServerObjectRepositoryType.TYPE_DATAMODEL;
    ValidateService validateService = new ValidateService();
    // 
    try {
        validateService.validateObjectExistence(null, null);
    } catch (Exception e) {
        assertTrue(e instanceof IllegalArgumentException);
    }
    try {
        validateService.validateObjectExistence(null, name);
    } catch (Exception e) {
        assertTrue(e instanceof IllegalArgumentException);
    }
    try {
        validateService.validateObjectExistence(objectType, null);
    } catch (Exception e) {
        assertTrue(e instanceof IllegalArgumentException);
    }
    try {
        PowerMockito.mockStatic(RepositoryResourceUtil.class);
        PowerMockito.when(RepositoryResourceUtil.findViewObjectByName(any(ERepositoryObjectType.class), anyString())).thenCallRealMethod();
        PowerMockito.when(RepositoryResourceUtil.findAllViewObjectsWithDeleted(any(ERepositoryObjectType.class))).thenCallRealMethod();
        PowerMockito.when(RepositoryResourceUtil.findAllViewObjects(any(ERepositoryObjectType.class), anyBoolean(), anyBoolean())).thenCallRealMethod();
        IRepositoryViewObject mockViewObj = PowerMockito.mock(IRepositoryViewObject.class);
        Property mockProperty = PowerMockito.mock(Property.class);
        PowerMockito.when(mockProperty.getLabel()).thenReturn(name);
        Item mockItem = PowerMockito.mock(Item.class);
        ItemState mockState = PowerMockito.mock(ItemState.class);
        // ////
        PowerMockito.when(mockState.isDeleted()).thenReturn(true);
        PowerMockito.when(mockItem.getState()).thenReturn(mockState);
        PowerMockito.when(mockProperty.getItem()).thenReturn(mockItem);
        PowerMockito.when(mockViewObj.getProperty()).thenReturn(mockProperty);
        IProxyRepositoryFactory mockRepositoryFactory = PowerMockito.mock(IProxyRepositoryFactory.class);
        List<IRepositoryViewObject> viewObjs = new ArrayList<IRepositoryViewObject>();
        viewObjs.add(mockViewObj);
        PowerMockito.when(mockRepositoryFactory.getAll(any(ERepositoryObjectType.class), anyBoolean())).thenReturn(viewObjs);
        PowerMockito.when(RepositoryResourceUtil.assertViewObject(any(IRepositoryViewObject.class))).thenReturn(mockViewObj);
        // $NON-NLS-1$
        PowerMockito.when(// $NON-NLS-1$
        RepositoryResourceUtil.class, // $NON-NLS-1$
        "getCacheViewObject", // $NON-NLS-1$
        any(Property.class), any(IRepositoryViewObject.class)).thenReturn(mockViewObj);
        PowerMockito.mockStatic(CoreRuntimePlugin.class);
        CoreRuntimePlugin mockCoreRuntimePlugin = PowerMockito.mock(CoreRuntimePlugin.class);
        PowerMockito.when(CoreRuntimePlugin.getInstance()).thenReturn(mockCoreRuntimePlugin);
        PowerMockito.when(mockCoreRuntimePlugin.getProxyRepositoryFactory()).thenReturn(mockRepositoryFactory);
        // check
        int validateResult = validateService.validateObjectExistence(objectType, name);
        assertEquals(IValidateService.STATUS_DELETED, validateResult);
        // 
        // ////
        PowerMockito.when(mockState.isDeleted()).thenReturn(false);
        validateResult = validateService.validateObjectExistence(objectType, name);
        assertEquals(IValidateService.STATUS_EXISTED, validateResult);
        // 
        // $NON-NLS-1$
        PowerMockito.when(// $NON-NLS-1$
        RepositoryResourceUtil.class, // $NON-NLS-1$
        "getCacheViewObject", // $NON-NLS-1$
        any(Property.class), any(IRepositoryViewObject.class)).thenReturn(PowerMockito.mock(IRepositoryViewObject.class));
        validateResult = validateService.validateObjectExistence(objectType, name);
        assertEquals(IValidateService.STATUS_OK, validateResult);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
}
Also used : ArrayList(java.util.ArrayList) Item(org.talend.core.model.properties.Item) ItemState(org.talend.core.model.properties.ItemState) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) RepositoryResourceUtil(org.talend.mdm.repository.utils.RepositoryResourceUtil) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) Property(org.talend.core.model.properties.Property) IValidateService(com.amalto.workbench.service.IValidateService) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) CoreRuntimePlugin(org.talend.core.runtime.CoreRuntimePlugin) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

CoreRuntimePlugin (org.talend.core.runtime.CoreRuntimePlugin)5 ResourceBundle (java.util.ResourceBundle)4 ImageRegistry (org.eclipse.jface.resource.ImageRegistry)4 Before (org.junit.Before)4 RepositoryResourceUtil (org.talend.mdm.repository.utils.RepositoryResourceUtil)4 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)4 RepositoryContext (org.talend.core.context.RepositoryContext)3 Project (org.talend.core.model.general.Project)3 User (org.talend.core.model.properties.User)3 IRepositoryFactory (org.talend.core.repository.model.IRepositoryFactory)3 ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)3 XmiResourceManager (org.talend.core.repository.utils.XmiResourceManager)3 IRepositoryNodeConfiguration (org.talend.mdm.repository.core.IRepositoryNodeConfiguration)3 IRepositoryNodeResourceProvider (org.talend.mdm.repository.core.IRepositoryNodeResourceProvider)3 RecycleBinNodeConfiguration (org.talend.mdm.repository.core.impl.recyclebin.RecycleBinNodeConfiguration)3 IRepositoryResourceUtilExAdapter (org.talend.mdm.repository.utils.IRepositoryResourceUtilExAdapter)3 ProjectManager (org.talend.repository.ProjectManager)3 IValidateService (com.amalto.workbench.service.IValidateService)1 ArrayList (java.util.ArrayList)1 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)1