Search in sources :

Example 21 with MDMServerObjectItem

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);
    }
}
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 22 with MDMServerObjectItem

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));
}
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 23 with MDMServerObjectItem

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);
    }
}
Also used : WSLong(com.amalto.workbench.webservices.WSLong) TMDMService(com.amalto.workbench.webservices.TMDMService) MDMServerObjectItem(org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) WSDigest(com.amalto.workbench.webservices.WSDigest) Property(org.talend.core.model.properties.Property) MDMServerDef(org.talend.mdm.repository.model.mdmmetadata.MDMServerDef) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 24 with MDMServerObjectItem

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));
}
Also used : ContainerItem(org.talend.mdm.repository.model.mdmproperties.ContainerItem) MDMServerObjectItem(org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem) ItemState(org.talend.core.model.properties.ItemState) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) Property(org.talend.core.model.properties.Property) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 25 with MDMServerObjectItem

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();
}
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

MDMServerObjectItem (org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem)50 MDMServerObject (org.talend.mdm.repository.model.mdmserverobject.MDMServerObject)33 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)28 Item (org.talend.core.model.properties.Item)22 Property (org.talend.core.model.properties.Property)15 PersistenceException (org.talend.commons.exception.PersistenceException)13 ContainerItem (org.talend.mdm.repository.model.mdmproperties.ContainerItem)12 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)11 ERepositoryObjectType (org.talend.core.model.repository.ERepositoryObjectType)10 LoginException (org.talend.commons.exception.LoginException)9 MDMServerDef (org.talend.mdm.repository.model.mdmmetadata.MDMServerDef)9 TreeObject (com.amalto.workbench.models.TreeObject)7 Test (org.junit.Test)7 TMDMService (com.amalto.workbench.webservices.TMDMService)6 LinkedList (java.util.LinkedList)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 BusinessException (org.talend.commons.exception.BusinessException)5 FolderItem (org.talend.core.model.properties.FolderItem)5 ProcessItem (org.talend.core.model.properties.ProcessItem)5 ArrayList (java.util.ArrayList)4