Search in sources :

Example 66 with Mockery

use of org.jmock.Mockery in project data-access by pentaho.

the class MetadataDatasourceServiceTest method setUp.

@Before
public void setUp() throws Exception {
    Mockery context = new JUnit4Mockery();
    manager = new MockBackingRepositoryLifecycleManager(new MockSecurityHelper());
    booter = new MicroPlatform("test-res");
    // Clear up the cache
    final ICacheManager cacheMgr = PentahoSystem.getCacheManager(null);
    cacheMgr.clearRegionCache(MondrianCatalogHelper.MONDRIAN_CATALOG_CACHE_REGION);
    // Define a repository for testing
    repository = new MockUnifiedRepository(new MockUserProvider());
    repository.createFolder(repository.getFile("/etc").getId(), new RepositoryFile.Builder("metadata").folder(true).build(), "initialization");
    final IAuthorizationPolicy policy = context.mock(IAuthorizationPolicy.class);
    booter.defineInstance(IAuthorizationPolicy.class, policy);
    booter.defineInstance(IUnifiedRepository.class, repository);
    booter.start();
    logout();
    manager.startup();
    context.checking(new Expectations() {

        {
            oneOf(policy);
            will(returnValue(true));
            oneOf(policy);
            will(returnValue(true));
            oneOf(policy);
            will(returnValue(true));
        }
    });
}
Also used : MockSecurityHelper(org.pentaho.test.platform.engine.security.MockSecurityHelper) Expectations(org.jmock.Expectations) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) IAuthorizationPolicy(org.pentaho.platform.api.engine.IAuthorizationPolicy) MicroPlatform(org.pentaho.test.platform.engine.core.MicroPlatform) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) ICacheManager(org.pentaho.platform.api.engine.ICacheManager) MockUnifiedRepository(org.pentaho.test.platform.repository2.unified.MockUnifiedRepository) Mockery(org.jmock.Mockery) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) Before(org.junit.Before)

Example 67 with Mockery

use of org.jmock.Mockery in project data-access by pentaho.

the class DatasourceResourceIT method testImportZipFile.

private void testImportZipFile(String filePath, final String expectedSchemaName, boolean annotated) throws Exception {
    FormDataContentDisposition schemaFileInfo = mock(FormDataContentDisposition.class);
    File f = new File(filePath);
    when(schemaFileInfo.getFileName()).thenReturn(f.getName());
    Mockery mockery = new Mockery();
    final IPlatformImporter mockImporter = mockery.mock(IPlatformImporter.class);
    mp.defineInstance(IPlatformImporter.class, mockImporter);
    if (annotated) {
        mockery.checking(new Expectations() {

            {
                exactly(2).of(mockImporter).importFile(with(match(new TypeSafeMatcher<IPlatformImportBundle>() {

                    public boolean matchesSafely(IPlatformImportBundle bundle) {
                        return true;
                    }

                    public void describeTo(Description description) {
                        description.appendText("bundle with zipped mondrian schema");
                    }
                })));
            }
        });
    } else {
        mockery.checking(new Expectations() {

            {
                oneOf(mockImporter).importFile(with(match(new TypeSafeMatcher<IPlatformImportBundle>() {

                    public boolean matchesSafely(IPlatformImportBundle bundle) {
                        return bundle.getProperty("domain-id").equals(expectedSchemaName);
                    }

                    public void describeTo(Description description) {
                        description.appendText("bundle with zipped mondrian schema");
                    }
                })));
            }
        });
    }
    AnalysisService service = new AnalysisService();
    FileInputStream in = new FileInputStream(filePath);
    try {
        service.putMondrianSchema(in, schemaFileInfo, null, null, null, false, false, "Datasource=SampleData;overwrite=false", null);
        mockery.assertIsSatisfied();
    } finally {
        IOUtils.closeQuietly(in);
    }
}
Also used : Expectations(org.jmock.Expectations) IPlatformImportBundle(org.pentaho.platform.api.repository2.unified.IPlatformImportBundle) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) FormDataContentDisposition(com.sun.jersey.core.header.FormDataContentDisposition) IPlatformImporter(org.pentaho.platform.plugin.services.importer.IPlatformImporter) AnalysisService(org.pentaho.platform.dataaccess.datasource.api.AnalysisService) ZipFile(java.util.zip.ZipFile) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) File(java.io.File) Mockery(org.jmock.Mockery) FileInputStream(java.io.FileInputStream)

Example 68 with Mockery

use of org.jmock.Mockery in project data-access by pentaho.

the class DatasourceResourceIT method testImportFile.

private void testImportFile(String filePath, final String expectedSchemaName) throws Exception {
    FormDataContentDisposition schemaFileInfo = mock(FormDataContentDisposition.class);
    when(schemaFileInfo.getFileName()).thenReturn("stubFileName");
    Mockery mockery = new Mockery();
    final IPlatformImporter mockImporter = mockery.mock(IPlatformImporter.class);
    mp.defineInstance(IPlatformImporter.class, mockImporter);
    mockery.checking(new Expectations() {

        {
            oneOf(mockImporter).importFile(with(match(new TypeSafeMatcher<IPlatformImportBundle>() {

                public boolean matchesSafely(IPlatformImportBundle bundle) {
                    return bundle.getProperty("domain-id").equals(expectedSchemaName) && bundle.getMimeType().equals("application/vnd.pentaho.mondrian+xml");
                }

                public void describeTo(Description description) {
                    description.appendText("bundle with mondrian schema");
                }
            })));
        }
    });
    AnalysisService service = new AnalysisService();
    FileInputStream in = new FileInputStream(filePath);
    try {
        service.putMondrianSchema(in, schemaFileInfo, null, null, null, false, false, "Datasource=SampleData;overwrite=false", null);
        mockery.assertIsSatisfied();
    } finally {
        IOUtils.closeQuietly(in);
    }
}
Also used : Expectations(org.jmock.Expectations) IPlatformImportBundle(org.pentaho.platform.api.repository2.unified.IPlatformImportBundle) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) FormDataContentDisposition(com.sun.jersey.core.header.FormDataContentDisposition) IPlatformImporter(org.pentaho.platform.plugin.services.importer.IPlatformImporter) AnalysisService(org.pentaho.platform.dataaccess.datasource.api.AnalysisService) Mockery(org.jmock.Mockery) FileInputStream(java.io.FileInputStream)

Example 69 with Mockery

use of org.jmock.Mockery in project lispflowmapping by opendaylight.

the class BaseExpectations method before.

@Before
public void before() throws Exception {
    context = new Mockery() {

        {
            setImposteriser(ClassImposteriser.INSTANCE);
            // otherwise we get errors on the finalizer thread:
            setThreadingPolicy(synchroniser);
        }
    };
    defaultAction = new ReturnDefaultValueAction(ClassImposteriser.INSTANCE);
}
Also used : ReturnDefaultValueAction(org.jmock.internal.ReturnDefaultValueAction) Mockery(org.jmock.Mockery) Before(org.junit.Before)

Example 70 with Mockery

use of org.jmock.Mockery in project teamcity-powershell by JetBrains.

the class RegistryPowerShellDetectorTest method setUp.

@Override
@BeforeMethod
public void setUp() throws Exception {
    super.setUp();
    m = new Mockery();
    acc = m.mock(Win32RegistryAccessor.class);
}
Also used : Win32RegistryAccessor(jetbrains.buildServer.util.Win32RegistryAccessor) Mockery(org.jmock.Mockery) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

Mockery (org.jmock.Mockery)148 Expectations (org.jmock.Expectations)118 Test (org.junit.Test)77 Before (org.junit.Before)28 ArrayList (java.util.ArrayList)24 Date (java.util.Date)21 JUnit4Mockery (org.jmock.integration.junit4.JUnit4Mockery)17 File (java.io.File)15 BeforeMethod (org.testng.annotations.BeforeMethod)15 Synchroniser (org.jmock.lib.concurrent.Synchroniser)14 List (java.util.List)11 ActorDTO (com.management.dto.ActorDTO)7 FanZoneDTO (com.management.dto.FanZoneDTO)6 PropsDTO (com.management.dto.PropsDTO)6 ActorPerformancesRepository (com.management.repositories.ActorPerformancesRepository)6 ActorRepository (com.management.repositories.ActorRepository)6 CinemaTheatreRepository (com.management.repositories.CinemaTheatreRepository)6 EventRepository (com.management.repositories.EventRepository)6 FriendsListRepository (com.management.repositories.FriendsListRepository)6 PerformanceRepository (com.management.repositories.PerformanceRepository)6