use of org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem in project tmdm-studio-se by Talend.
the class AbstractInteractiveHandlerTest method testDeploy.
@Test
public void testDeploy() {
MDMServerObject mockServerObject = PowerMockito.mock(MDMServerObject.class);
MDMServerObjectItem mockServerObjectItem = PowerMockito.mock(MDMServerObjectItem.class);
PowerMockito.when(mockServerObjectItem.getMDMServerObject()).thenReturn(mockServerObject);
Property mockProperty = PowerMockito.mock(Property.class);
PowerMockito.when(mockProperty.getItem()).thenReturn(mockServerObjectItem);
IRepositoryViewObject mockViewObj = PowerMockito.mock(IRepositoryViewObject.class);
PowerMockito.when(mockViewObj.getProperty()).thenReturn(mockProperty);
AbstractDeployCommand mockDeployCommand = PowerMockito.mock(AbstractDeployCommand.class);
PowerMockito.when(mockDeployCommand.getViewObject()).thenReturn(mockViewObj);
AbstractInteractiveHandler mockInteractiveHandler = PowerMockito.mock(AbstractInteractiveHandler.class);
try {
PowerMockito.when(mockInteractiveHandler.deploy(any(AbstractDeployCommand.class))).thenCallRealMethod();
PowerMockito.when(mockInteractiveHandler.doDeployWSObject(any(TMDMService.class), any())).thenReturn(true);
TMDMService mockService = PowerMockito.mock(TMDMService.class);
// $NON-NLS-1$
PowerMockito.when(mockInteractiveHandler, "getService", any(MDMServerDef.class)).thenReturn(mockService);
Object mockWsObj = new Object();
PowerMockito.when(mockInteractiveHandler.convert(any(Item.class), any(MDMServerObject.class))).thenReturn(mockWsObj);
boolean deployed = mockInteractiveHandler.deploy(mockDeployCommand);
assertTrue(deployed);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
use of org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem in project tmdm-studio-se by Talend.
the class ConsistencyServiceTest method testGetCurrentDigestValue.
@Test
public void testGetCurrentDigestValue() {
assertNull(ConsistencyService.getInstance().getCurrentDigestValue(null));
// $NON-NLS-1$
String currentDigestValue = "current_digest_value_0123";
MDMServerObject mockMDMServerObj = Mockito.mock(MDMServerObject.class);
Mockito.when(mockMDMServerObj.getCurrentDigestValue()).thenReturn(currentDigestValue);
MDMServerObjectItem mockItem = Mockito.mock(MDMServerObjectItem.class);
Mockito.when(mockItem.getMDMServerObject()).thenReturn(mockMDMServerObj);
//
assertEquals(currentDigestValue, ConsistencyService.getInstance().getCurrentDigestValue(mockItem));
EMap mockProperties = Mockito.mock(EMap.class);
// $NON-NLS-1$
Mockito.when(mockProperties.get(eq("currentDigestValue"))).thenReturn(currentDigestValue);
Property mockProperty = Mockito.mock(Property.class);
Mockito.when(mockProperty.getAdditionalProperties()).thenReturn(mockProperties);
ProcessItem mockProcessItem = Mockito.mock(ProcessItem.class);
Mockito.when(mockProcessItem.getProperty()).thenReturn(mockProperty);
//
assertEquals(currentDigestValue, ConsistencyService.getInstance().getCurrentDigestValue(mockProcessItem));
}
use of org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem in project tmdm-studio-se by Talend.
the class ConsistencyServiceTest method testUpdateDigestValue.
@Test
public void testUpdateDigestValue() {
PowerMockito.mockStatic(RepositoryResourceUtil.class);
IRepositoryViewObject mockViewObj = PowerMockito.mock(IRepositoryViewObject.class);
MDMServerObjectItem mockItem = PowerMockito.mock(MDMServerObjectItem.class);
Property mockProperty = PowerMockito.mock(Property.class);
PowerMockito.when(mockProperty.getItem()).thenReturn(mockItem);
PowerMockito.when(mockItem.getProperty()).thenReturn(mockProperty);
PowerMockito.when(mockViewObj.getProperty()).thenReturn(mockProperty);
PowerMockito.when(RepositoryResourceUtil.assertItem(mockItem)).thenReturn(mockItem);
PowerMockito.when(mockViewObj.getRepositoryObjectType()).thenReturn(IServerObjectRepositoryType.TYPE_DATAMODEL);
try {
TMDMService mockService = PowerMockito.mock(TMDMService.class);
MDMServerDef mockServerDef = PowerMockito.mock(MDMServerDef.class);
PowerMockito.mockStatic(RepositoryWebServiceAdapter.class);
PowerMockito.when(RepositoryWebServiceAdapter.getMDMService(mockServerDef)).thenReturn(mockService);
WSLong timeValue = new WSLong(11);
PowerMockito.when(mockService.updateDigest(any(WSDigest.class))).thenReturn(timeValue);
ConsistencyService mockCService = PowerMockito.mock(ConsistencyService.class);
// $NON-NLS-1$
PowerMockito.doNothing().when(mockCService, "updateLocalDigestValue", mockViewObj);
// $NON-NLS-1$
String label = "Product";
// $NON-NLS-1$
PowerMockito.when(mockCService, "getObjectName", mockViewObj).thenReturn(label);
PowerMockito.when(mockCService.getLocalDigestValue(mockItem)).thenReturn(label);
PowerMockito.when(mockCService, "updateDigestValue", any(MDMServerDef.class), any(IRepositoryViewObject.class)).thenCallRealMethod();
mockCService.updateDigestValue(mockServerDef, mockViewObj);
// check
Mockito.verify(mockCService, times(1)).updateLocalDigestValue(mockViewObj);
Mockito.verify(mockService, Mockito.times(1)).updateDigest(any(WSDigest.class));
PowerMockito.verifyStatic();
RepositoryResourceUtil.saveItem(mockItem);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
use of org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem in project tmdm-studio-se by Talend.
the class ContainerCacheServiceTest method testPutContainer.
@Test
public void testPutContainer() {
// $NON-NLS-1$
String path = "/path";
ERepositoryObjectType repositoryType = IServerObjectRepositoryType.TYPE_DATAMODEL;
ItemState mockState = PowerMockito.mock(ItemState.class);
PowerMockito.when(mockState.getPath()).thenReturn(path);
MDMServerObjectItem mockItem = PowerMockito.mock(MDMServerObjectItem.class);
PowerMockito.when(mockItem.getState()).thenReturn(mockState);
Property mockProperty = PowerMockito.mock(Property.class);
PowerMockito.when(mockProperty.getItem()).thenReturn(mockItem);
IRepositoryViewObject mockViewObj = PowerMockito.mock(IRepositoryViewObject.class);
PowerMockito.when(mockViewObj.getProperty()).thenReturn(mockProperty);
PowerMockito.when(mockViewObj.getRepositoryObjectType()).thenReturn(repositoryType);
// not container item
ContainerCacheService.putContainer(mockViewObj);
assertNull(ContainerCacheService.get(repositoryType, path));
// container item
ContainerItem mockContainerItem = PowerMockito.mock(ContainerItem.class);
PowerMockito.when(mockContainerItem.getState()).thenReturn(mockState);
PowerMockito.when(mockContainerItem.getRepObjType()).thenReturn(repositoryType);
PowerMockito.when(mockProperty.getItem()).thenReturn(mockContainerItem);
ContainerCacheService.putContainer(mockViewObj);
assertEquals(mockViewObj, ContainerCacheService.get(repositoryType, path));
}
use of org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem in project tmdm-studio-se by Talend.
the class RemoveFromRepositoryActionTest method doRunTest.
@Test
public void doRunTest() throws Exception {
PowerMockito.mockStatic(MDMWorbenchPlugin.class);
when(MDMWorbenchPlugin.getImageDescriptor(anyString())).thenReturn(mock(ImageDescriptor.class));
RemoveFromRepositoryAction removeAction = new RemoveFromRepositoryAction();
RemoveFromRepositoryAction removeActionM = PowerMockito.spy(removeAction);
CommonViewer commonViewerM = mock(CommonViewer.class);
// $NON-NLS-1$
Whitebox.setInternalState(removeActionM, "commonViewer", commonViewerM);
// $NON-NLS-1$
PowerMockito.doReturn(true).when(removeActionM, "confirm", 2);
// $NON-NLS-1$
PowerMockito.doNothing().when(removeActionM, "warn");
// mock a mdm repositoryViewObject
IRepositoryViewObject objectRVO = mock(IRepositoryViewObject.class);
MDMServerObjectItem mdmItemM = mock(MDMServerObjectItem.class);
Property propertyM = mock(Property.class);
when(objectRVO.getProperty()).thenReturn(propertyM);
when(propertyM.getItem()).thenReturn(mdmItemM);
// mock a FolderRepositoryObject
FolderRepositoryObject folderRO = mock(FolderRepositoryObject.class);
Property foldePropertyM = mock(Property.class);
ContainerItem containerItem = mock(ContainerItem.class);
when(folderRO.getProperty()).thenReturn(foldePropertyM);
when(foldePropertyM.getItem()).thenReturn(containerItem);
ItemState itemState = mock(ItemState.class);
when(containerItem.getState()).thenReturn(itemState);
// $NON-NLS-1$
when(itemState.getPath()).thenReturn("");
PowerMockito.mockStatic(RepositoryNodeProviderRegistryReader.class);
RepositoryNodeProviderRegistryReader reader = mock(RepositoryNodeProviderRegistryReader.class);
PowerMockito.when(RepositoryNodeProviderRegistryReader.getInstance()).thenReturn(reader);
ERepositoryObjectType typeM = ERepositoryObjectType.PROCESS;
when(containerItem.getRepObjType()).thenReturn(typeM);
MDMServerObject mdmServerObjectM = mock(MDMServerObject.class);
when(mdmItemM.getMDMServerObject()).thenReturn(mdmServerObjectM);
Shell shellM = mock(Shell.class);
Control controlM = mock(Control.class);
when(commonViewerM.getControl()).thenReturn(controlM);
when(controlM.getShell()).thenReturn(shellM);
List<Object> selectedObjects = new ArrayList<Object>();
selectedObjects.add(objectRVO);
selectedObjects.add(folderRO);
when(removeActionM.getSelectedObject()).thenReturn(selectedObjects);
// $NON-NLS-1$
Whitebox.setInternalState(removeActionM, "lockedObjs", Collections.EMPTY_LIST);
PowerMockito.mockStatic(MessageDialog.class);
when(MessageDialog.openConfirm((Shell) anyObject(), anyString(), anyString())).thenReturn(true);
PowerMockito.mockStatic(RepositoryResourceUtil.class);
when(RepositoryResourceUtil.isOpenedInEditor((IRepositoryViewObject) anyObject())).thenReturn(null);
when(RepositoryResourceUtil.hasContainerItem(anyObject(), eq(FolderType.FOLDER_LITERAL))).thenReturn(true);
PowerMockito.mockStatic(ContainerCacheService.class);
FolderItem folderItemM = mock(FolderItem.class);
when(repositoryFactory.getFolderItem(eq(projectM), eq(typeM), (IPath) anyObject())).thenReturn(folderItemM);
when(folderItemM.getState()).thenReturn(itemState);
removeActionM.doRun();
}
Aggregations