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