use of org.talend.mdm.repository.core.IRepositoryNodeResourceProvider in project tmdm-studio-se by Talend.
the class RepositoryNodeConfigurationManager method getConfiguration.
public static IRepositoryNodeConfiguration getConfiguration(Item item) {
EClass eClass = item.eClass();
IRepositoryNodeConfiguration configuration = itemConfMap.get(eClass);
if (configuration != null) {
return configuration;
}
for (IRepositoryNodeConfiguration conf : getConfigurations()) {
IRepositoryNodeResourceProvider resourceProvider = conf.getResourceProvider();
if (resourceProvider != null) {
if (resourceProvider.canHandleItem(item)) {
if (!(item instanceof ContainerItem)) {
itemConfMap.put(eClass, conf);
}
return conf;
}
}
}
if (recycleBinNodeConfiguration.getResourceProvider().canHandleItem(item)) {
return recycleBinNodeConfiguration;
}
return null;
}
use of org.talend.mdm.repository.core.IRepositoryNodeResourceProvider in project tmdm-studio-se by Talend.
the class RepositoryResourceUtil method createItem.
public static boolean createItem(Item item, String propLabel, String version, boolean pushCommandStack, boolean triggerEvent) {
String name = propLabel;
IProxyRepositoryFactory factory = CoreRuntimePlugin.getInstance().getProxyRepositoryFactory();
RepositoryContext context = factory.getRepositoryContext();
Property prop = PropertiesFactory.eINSTANCE.createProperty();
item.setProperty(prop);
try {
String nextId = factory.getNextId();
Property property = item.getProperty();
property.setId(nextId);
property.setVersion(version);
property.setAuthor(context.getUser());
property.setLabel(propLabel);
//
factory.create(item, new Path(item.getState().getPath()));
item = assertItem(item);
//
IRepositoryNodeConfiguration configuration = RepositoryNodeConfigurationManager.getConfiguration(item);
if (configuration != null) {
IRepositoryNodeResourceProvider resourceProvider = configuration.getResourceProvider();
if (resourceProvider.needSaveReferenceFile()) {
resourceProvider.handleReferenceFile(item);
}
factory.save(item, !triggerEvent);
try {
factory.unlock(item);
} catch (LoginException e) {
log.error(e.getMessage(), e);
}
}
if (pushCommandStack) {
CommandManager.getInstance().pushCommand(ICommand.CMD_ADD, nextId, name);
}
return true;
} catch (PersistenceException e) {
log.error(e.getMessage(), e);
}
return false;
}
use of org.talend.mdm.repository.core.IRepositoryNodeResourceProvider 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);
}
use of org.talend.mdm.repository.core.IRepositoryNodeResourceProvider 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);
}
use of org.talend.mdm.repository.core.IRepositoryNodeResourceProvider 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);
}
Aggregations