use of org.talend.core.model.properties.PropertiesFactory 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);
}
Aggregations