use of org.talend.mdm.repository.model.mdmserverobject.MDMServerObject in project tmdm-studio-se by Talend.
the class ConsistencyServiceTest method testGetLocalDigestValue.
@Test
public void testGetLocalDigestValue() {
assertNull(ConsistencyService.getInstance().getLocalDigestValue(null));
// $NON-NLS-1$
String localDigestValue = "local_digest_value_0123";
MDMServerObject mockMDMServerObj = Mockito.mock(MDMServerObject.class);
Mockito.when(mockMDMServerObj.getDigestValue()).thenReturn(localDigestValue);
MDMServerObjectItem mockItem = Mockito.mock(MDMServerObjectItem.class);
Mockito.when(mockItem.getMDMServerObject()).thenReturn(mockMDMServerObj);
//
assertEquals(localDigestValue, ConsistencyService.getInstance().getLocalDigestValue(mockItem));
EMap mockProperties = Mockito.mock(EMap.class);
// $NON-NLS-1$
Mockito.when(mockProperties.get(eq("digestValue"))).thenReturn(localDigestValue);
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(localDigestValue, ConsistencyService.getInstance().getLocalDigestValue(mockProcessItem));
}
use of org.talend.mdm.repository.model.mdmserverobject.MDMServerObject 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.mdmserverobject.MDMServerObject in project tmdm-studio-se by Talend.
the class Bean2EObjUtilTest method testWrapEObjWithTreeObject2Args.
/**
* test wrapEObjWithTreeObject with two input parameters
*/
@Test
public void testWrapEObjWithTreeObject2Args() {
EObject eobj = null;
Object wsObj = null;
Bean2EObjUtil util = Bean2EObjUtil.getInstance();
TreeObject treeObject = util.wrapEObjWithTreeObject(eobj, wsObj);
assertNull(treeObject);
MDMServerObject mdmServerObject = PowerMockito.mock(MDMServerObject.class);
when(mdmServerObject.getName()).thenReturn("name");
when(mdmServerObject.getType()).thenReturn(2);
eobj = mdmServerObject;
treeObject = util.wrapEObjWithTreeObject(eobj, wsObj);
assertNotNull(treeObject);
Mockito.verify(mdmServerObject, Mockito.atLeastOnce()).getName();
Mockito.verify(mdmServerObject, Mockito.atLeastOnce()).getType();
assertEquals("name", treeObject.getName());
assertEquals(2, treeObject.getType());
}
use of org.talend.mdm.repository.model.mdmserverobject.MDMServerObject 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.mdmserverobject.MDMServerObject 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