Search in sources :

Example 1 with IMatchRuleMapInfoService

use of org.talend.mdm.repository.core.service.IMatchRuleMapInfoService in project tmdm-studio-se by Talend.

the class NewDataModelActionTest method testCreateServerObject.

@Test
public void testCreateServerObject() throws Exception {
    // 
    ContainerItem newItem = MdmpropertiesFactory.eINSTANCE.createContainerItem();
    ContainerItem mockContainerItem = spy(newItem);
    PowerMockito.mockStatic(MDMWorbenchPlugin.class);
    when(MDMWorbenchPlugin.getImageDescriptor(anyString())).thenReturn(mock(ImageDescriptor.class));
    IMatchRuleMapInfoService mapInfoService = mock(IMatchRuleMapInfoService.class);
    PowerMockito.mockStatic(ServiceUtil.class);
    PowerMockito.when(ServiceUtil.getService(IMatchRuleMapInfoService.class)).thenReturn(mapInfoService);
    // new action
    NewDataModelAction action = new NewDataModelAction();
    NewDataModelAction spyAction = spy(action);
    // 
    // $NON-NLS-1$
    Whitebox.setInternalState(spyAction, "parentItem", mockContainerItem);
    ItemState itemState = mock(ItemState.class);
    when(mockContainerItem.getState()).thenReturn(itemState);
    // $NON-NLS-1$
    when(mockContainerItem.getState().getPath()).thenReturn("");
    WSDataModelItem item = MdmpropertiesFactory.eINSTANCE.createWSDataModelItem();
    WSDataModelItem spyModelItem = spy(item);
    Resource mockResource = mock(Resource.class);
    ResourceSet mockResourceSet = mock(ResourceSet.class);
    when(mockResource.getResourceSet()).thenReturn(mockResourceSet);
    when(spyModelItem.eResource()).thenReturn(mockResource);
    PowerMockito.whenNew(WSDataModelItemImpl.class).withNoArguments().thenReturn((WSDataModelItemImpl) spyModelItem);
    // run
    // $NON-NLS-1$
    Item addedItem = spyAction.createServerObject("abc");
    assertThat(addedItem, notNullValue());
}
Also used : WSDataModelItem(org.talend.mdm.repository.model.mdmproperties.WSDataModelItem) Item(org.talend.core.model.properties.Item) ContainerItem(org.talend.mdm.repository.model.mdmproperties.ContainerItem) ContainerItem(org.talend.mdm.repository.model.mdmproperties.ContainerItem) ItemState(org.talend.core.model.properties.ItemState) WSDataModelItem(org.talend.mdm.repository.model.mdmproperties.WSDataModelItem) Resource(org.eclipse.emf.ecore.resource.Resource) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) IMatchRuleMapInfoService(org.talend.mdm.repository.core.service.IMatchRuleMapInfoService) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) AbstractSimpleAddActionTest(org.talend.mdm.repository.ui.actions.AbstractSimpleAddActionTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Resource (org.eclipse.emf.ecore.resource.Resource)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 Item (org.talend.core.model.properties.Item)1 ItemState (org.talend.core.model.properties.ItemState)1 IMatchRuleMapInfoService (org.talend.mdm.repository.core.service.IMatchRuleMapInfoService)1 ContainerItem (org.talend.mdm.repository.model.mdmproperties.ContainerItem)1 WSDataModelItem (org.talend.mdm.repository.model.mdmproperties.WSDataModelItem)1 AbstractSimpleAddActionTest (org.talend.mdm.repository.ui.actions.AbstractSimpleAddActionTest)1