Search in sources :

Example 1 with StarDomain

use of org.pentaho.di.starmodeler.StarDomain in project pentaho-kettle by pentaho.

the class StarDomainMetaStoreUtilTest method testLoadStarDomain.

@Test
public void testLoadStarDomain() throws Exception {
    final String id = "id";
    final String msName = "MSName";
    when(metaStore.getName()).thenReturn(msName);
    final DelegatingMetaStore delegatingMetaStore = spy(new DelegatingMetaStore(metaStore));
    delegatingMetaStore.setActiveMetaStoreName(msName);
    doAnswer(new Answer<IMetaStoreElementType>() {

        @Override
        public IMetaStoreElementType answer(InvocationOnMock invocationOnMock) throws Throwable {
            return metaStore.getElementTypeByName((String) invocationOnMock.getArguments()[0], (String) invocationOnMock.getArguments()[1]);
        }
    }).when(delegatingMetaStore).getElementTypeByName(anyString(), anyString());
    assertNull(StarDomainMetaStoreUtil.loadStarDomain(delegatingMetaStore, id));
    final IMetaStoreElement metaStoreElement = mock(IMetaStoreElement.class);
    final String name = "name";
    when(metaStoreElement.getName()).thenReturn(name);
    doReturn(metaStoreElement).when(delegatingMetaStore).getElement(anyString(), eq(metaStoreElementType), eq(id));
    final StarDomain starDomain = StarDomainMetaStoreUtil.loadStarDomain(delegatingMetaStore, id);
    assertEquals(id, starDomain.getObjectId().getId());
    assertEquals(name, starDomain.getName());
}
Also used : IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) StarDomain(org.pentaho.di.starmodeler.StarDomain) InvocationOnMock(org.mockito.invocation.InvocationOnMock) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement) Matchers.anyString(org.mockito.Matchers.anyString) DelegatingMetaStore(org.pentaho.metastore.stores.delegate.DelegatingMetaStore) Test(org.junit.Test)

Example 2 with StarDomain

use of org.pentaho.di.starmodeler.StarDomain in project pentaho-kettle by pentaho.

the class StarDomainMetaStoreUtil method loadStarDomain.

public static StarDomain loadStarDomain(DelegatingMetaStore metaStore, String id) throws MetaStoreException {
    IMetaStoreElementType elementType = getStarDomainElementType(metaStore);
    IMetaStoreElement element = metaStore.getElement(namespace, elementType, id);
    if (element == null) {
        return null;
    }
    StarDomain starDomain = new StarDomain();
    starDomain.setObjectId(new StringObjectId(id));
    starDomain.setName(element.getName());
    starDomain.setDescription(getChildString(element, Attribute.ID_STAR_DOMAIN_DESCRIPTION.id));
    return starDomain;
}
Also used : IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) StarDomain(org.pentaho.di.starmodeler.StarDomain) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement) StringObjectId(org.pentaho.di.repository.StringObjectId)

Example 3 with StarDomain

use of org.pentaho.di.starmodeler.StarDomain in project pentaho-kettle by pentaho.

the class JobGeneratorTest method setUp.

@Before
public void setUp() throws Exception {
    final StarDomain starDomain = mock(StarDomain.class);
    final Domain domain = mock(Domain.class);
    when(domain.getProperty(eq(DefaultIDs.DOMAIN_TARGET_DATABASE))).thenReturn("test_domain_target_db");
    when(starDomain.getDomain()).thenReturn(domain);
    final Repository repository = mock(Repository.class);
    final RepositoryDirectoryInterface targetDirectory = mock(RepositoryDirectoryInterface.class);
    final DatabaseMeta meta = Mockito.mock(DatabaseMeta.class);
    Mockito.when(meta.getName()).thenReturn("test_domain_target_db");
    final LinkedList<DatabaseMeta> databases = new LinkedList<DatabaseMeta>() {

        {
            add(meta);
        }
    };
    final String locale = Locale.US.toString();
    jobGenerator = new JobGenerator(starDomain, repository, targetDirectory, databases, locale);
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) Repository(org.pentaho.di.repository.Repository) StarDomain(org.pentaho.di.starmodeler.StarDomain) Domain(org.pentaho.metadata.model.Domain) StarDomain(org.pentaho.di.starmodeler.StarDomain) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) LinkedList(java.util.LinkedList) Before(org.junit.Before)

Example 4 with StarDomain

use of org.pentaho.di.starmodeler.StarDomain in project pentaho-kettle by pentaho.

the class StarDomainMetaStoreUtilTest method testSaveStarDomain.

@Test
public void testSaveStarDomain() throws Exception {
    final StarDomain starDomain = mock(StarDomain.class);
    final ObjectId objectId = mock(ObjectId.class);
    final String objectIdStr = "objectIdStr";
    when(objectId.toString()).thenReturn(objectIdStr);
    when(starDomain.getObjectId()).thenReturn(objectId);
    final String starDomainName = "starDomainName";
    when(starDomain.getName()).thenReturn(starDomainName);
    final IMetaStoreElement metaStoreElement = mock(IMetaStoreElement.class);
    when(metaStoreElement.getId()).thenReturn("id");
    when(metaStore.getElement(anyString(), eq(metaStoreElementType), eq(objectIdStr))).thenReturn(metaStoreElement);
    StarDomainMetaStoreUtil.saveStarDomain(metaStore, starDomain);
    verify(metaStoreElement, times(1)).setElementType(eq(metaStoreElementType));
    verify(metaStoreElement, times(1)).setName(eq(starDomainName));
    verify(metaStoreElement, times(1)).addChild(any(IMetaStoreAttribute.class));
    verify(metaStore, times(1)).updateElement(anyString(), eq(metaStoreElementType), eq(objectIdStr), eq(metaStoreElement));
    verify(starDomain, times(1)).setObjectId(any(ObjectId.class));
}
Also used : StarDomain(org.pentaho.di.starmodeler.StarDomain) ObjectId(org.pentaho.di.repository.ObjectId) IMetaStoreAttribute(org.pentaho.metastore.api.IMetaStoreAttribute) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

StarDomain (org.pentaho.di.starmodeler.StarDomain)4 IMetaStoreElement (org.pentaho.metastore.api.IMetaStoreElement)3 Test (org.junit.Test)2 Matchers.anyString (org.mockito.Matchers.anyString)2 IMetaStoreElementType (org.pentaho.metastore.api.IMetaStoreElementType)2 LinkedList (java.util.LinkedList)1 Before (org.junit.Before)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)1 ObjectId (org.pentaho.di.repository.ObjectId)1 Repository (org.pentaho.di.repository.Repository)1 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)1 StringObjectId (org.pentaho.di.repository.StringObjectId)1 Domain (org.pentaho.metadata.model.Domain)1 IMetaStoreAttribute (org.pentaho.metastore.api.IMetaStoreAttribute)1 DelegatingMetaStore (org.pentaho.metastore.stores.delegate.DelegatingMetaStore)1