Search in sources :

Example 16 with MDMServerObject

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));
}
Also used : ProcessItem(org.talend.core.model.properties.ProcessItem) MDMServerObjectItem(org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem) EMap(org.eclipse.emf.common.util.EMap) Property(org.talend.core.model.properties.Property) MDMServerObject(org.talend.mdm.repository.model.mdmserverobject.MDMServerObject) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 17 with MDMServerObject

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);
    }
}
Also used : Item(org.talend.core.model.properties.Item) MDMServerObjectItem(org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem) TMDMService(com.amalto.workbench.webservices.TMDMService) MDMServerObjectItem(org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) AbstractDeployCommand(org.talend.mdm.repository.core.command.deploy.AbstractDeployCommand) MDMServerObject(org.talend.mdm.repository.model.mdmserverobject.MDMServerObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) Property(org.talend.core.model.properties.Property) MDMServerObject(org.talend.mdm.repository.model.mdmserverobject.MDMServerObject) Test(org.junit.Test)

Example 18 with MDMServerObject

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());
}
Also used : EObject(org.eclipse.emf.ecore.EObject) TreeObject(com.amalto.workbench.models.TreeObject) EObject(org.eclipse.emf.ecore.EObject) TreeObject(com.amalto.workbench.models.TreeObject) MDMServerObject(org.talend.mdm.repository.model.mdmserverobject.MDMServerObject) MDMServerObject(org.talend.mdm.repository.model.mdmserverobject.MDMServerObject) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 19 with MDMServerObject

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));
}
Also used : ProcessItem(org.talend.core.model.properties.ProcessItem) MDMServerObjectItem(org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem) EMap(org.eclipse.emf.common.util.EMap) Property(org.talend.core.model.properties.Property) MDMServerObject(org.talend.mdm.repository.model.mdmserverobject.MDMServerObject) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 20 with MDMServerObject

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();
}
Also used : ContainerItem(org.talend.mdm.repository.model.mdmproperties.ContainerItem) CommonViewer(org.eclipse.ui.navigator.CommonViewer) MDMServerObjectItem(org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem) ArrayList(java.util.ArrayList) FolderRepositoryObject(org.talend.mdm.repository.models.FolderRepositoryObject) RepositoryNodeProviderRegistryReader(org.talend.core.model.repository.RepositoryNodeProviderRegistryReader) Shell(org.eclipse.swt.widgets.Shell) Control(org.eclipse.swt.widgets.Control) FolderItem(org.talend.core.model.properties.FolderItem) ItemState(org.talend.core.model.properties.ItemState) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) MDMServerObject(org.talend.mdm.repository.model.mdmserverobject.MDMServerObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) FolderRepositoryObject(org.talend.mdm.repository.models.FolderRepositoryObject) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) Property(org.talend.core.model.properties.Property) MDMServerObject(org.talend.mdm.repository.model.mdmserverobject.MDMServerObject) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

MDMServerObject (org.talend.mdm.repository.model.mdmserverobject.MDMServerObject)37 MDMServerObjectItem (org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem)33 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)19 Item (org.talend.core.model.properties.Item)13 TreeObject (com.amalto.workbench.models.TreeObject)11 Property (org.talend.core.model.properties.Property)11 PersistenceException (org.talend.commons.exception.PersistenceException)9 Test (org.junit.Test)7 ERepositoryObjectType (org.talend.core.model.repository.ERepositoryObjectType)7 MDMServerDef (org.talend.mdm.repository.model.mdmmetadata.MDMServerDef)7 ContainerItem (org.talend.mdm.repository.model.mdmproperties.ContainerItem)7 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 LoginException (org.talend.commons.exception.LoginException)6 EObject (org.eclipse.emf.ecore.EObject)5 ArrayList (java.util.ArrayList)4 FolderItem (org.talend.core.model.properties.FolderItem)4 TMDMService (com.amalto.workbench.webservices.TMDMService)3 LinkedList (java.util.LinkedList)3 ItemState (org.talend.core.model.properties.ItemState)3