Package org.jmock

Examples of org.jmock.Mockery


    @Test
    public void test_provider_field() throws Exception {
        final ProviderTest test = new ProviderTest() {
            @MockContextProvider
            private Mockery m = new Mockery();
        };
        mockery.checking(new Expectations() {{
            allowing(ctx).getTest();
            will(returnValue(new TestInstance(test)));
            one(ctx).setAttribute(with("org.jmock.Mockery"), with(any(Mockery.class)));
View Full Code Here


    @Test
    public void test_provider_method() throws Exception {
        final ProviderTest test = new ProviderTest() {
            @MockContextProvider
            private Mockery build() {
                return new Mockery();
            }
        };
        mockery.checking(new Expectations() {{
            allowing(ctx).getTest();
            will(returnValue(new TestInstance(test)));
View Full Code Here

    @Test
    public void test_provider_method_before_field() throws Exception {
        final ProviderTest test = new ProviderTest() {
            @MockContextProvider
            private Mockery m = new Mockery();

            @MockContextProvider
            private Mockery build() {
                return JMock2TestPluginTest.this.mockery3;
            }
View Full Code Here

    }

    public void testNoIndexUpdate()
        throws Exception
    {
        Mockery mockery = new Mockery();

        final String indexUrl = repositoryUrl + ".index";
        final Date contextTimestamp = df.parse( "20081125010000.000 -0600" );

        final ResourceFetcher mockFetcher = mockery.mock( ResourceFetcher.class );

        final IndexingContext tempContext = mockery.mock( IndexingContext.class );

        final Properties localProps = new Properties();
        localProps.setProperty( IndexingContext.INDEX_CHUNK_COUNTER, "1" );
        localProps.setProperty( IndexingContext.INDEX_CHAIN_ID, "someid" );
        localProps.setProperty( IndexingContext.INDEX_TIMESTAMP, "20081125010000.000 -0600" );

        mockery.checking( new Expectations()
        {
            {
                allowing( tempContext ).getIndexDirectoryFile();
                will( new IndexDirectoryFileAction( localProps, testBasedir ) );

                allowing( tempContext ).getTimestamp();
                will( returnValue( contextTimestamp ) );

                allowing( tempContext ).getId();
                will( returnValue( repositoryId ) );

                allowing( tempContext ).commit();

                allowing( tempContext ).getIndexUpdateUrl();
                will( returnValue( indexUrl ) );

                allowing( tempContext ).getIndexCreators();
                will( returnValue( DEFAULT_CREATORS ) );

                oneOf( mockFetcher ).connect( repositoryId, indexUrl );

                oneOf( mockFetcher ).retrieve( //
                    with( IndexingContext.INDEX_REMOTE_PROPERTIES_FILE ) );
                will( new PropertiesAction()
                {
                    @Override
                    Properties getProperties()
                    {
                        Properties properties = new Properties();
                        properties.setProperty( IndexingContext.INDEX_ID, "central" );
                        properties.setProperty( IndexingContext.INDEX_TIMESTAMP, "20081125010000.000 -0600" );
                        return properties;
                    }
                } );

                allowing( tempContext ).getIndexDirectoryFile();

                oneOf( mockFetcher ).disconnect();
            }
        } );

        // tempContext.updateTimestamp( true, contextTimestamp );

        IndexUpdateRequest updateRequest = new IndexUpdateRequest( tempContext, mockFetcher );

        updater.fetchAndUpdateIndex( updateRequest );

        mockery.assertIsSatisfied();
    }
View Full Code Here

    }

    public void testFullIndexUpdate()
        throws Exception
    {
        Mockery mockery = new Mockery();

        final String indexUrl = repositoryUrl + ".index";
        final Date contextTimestamp = df.parse( "20081125010000.000 -0600" );

        final ResourceFetcher mockFetcher = mockery.mock( ResourceFetcher.class );

        final IndexingContext tempContext = mockery.mock( IndexingContext.class );

        mockery.checking( new Expectations()
        {
            {
                allowing( tempContext ).getIndexDirectoryFile();
                will( new ReturnValueAction( testBasedir ) );

                allowing( tempContext ).getTimestamp();
                will( returnValue( contextTimestamp ) );

                allowing( tempContext ).getId();
                will( returnValue( repositoryId ) );

                allowing( tempContext ).getIndexUpdateUrl();
                will( returnValue( indexUrl ) );

                allowing( tempContext ).commit();

                allowing( tempContext ).getIndexCreators();
                will( returnValue( DEFAULT_CREATORS ) );

                allowing( tempContext ).commit();

                oneOf( mockFetcher ).connect( repositoryId, indexUrl );

                oneOf( mockFetcher ).retrieve( //
                    with( IndexingContext.INDEX_REMOTE_PROPERTIES_FILE ) );
                will( new PropertiesAction()
                {
                    @Override
                    Properties getProperties()
                    {
                        Properties properties = new Properties();
                        properties.setProperty( IndexingContext.INDEX_ID, "central" );
                        properties.setProperty( IndexingContext.INDEX_TIMESTAMP, "20081126010000.000 -0600" );
                        return properties;
                    }
                } );

                allowing( tempContext ).getIndexDirectoryFile();

                oneOf( mockFetcher ).retrieve( //
                    with( IndexingContext.INDEX_FILE_PREFIX + ".gz" ) );
                will( returnValue( newInputStream( "/index-updater/server-root/nexus-maven-repository-index.gz" ) ) );

                oneOf( tempContext ).replace( with( any( Directory.class ) ) );

                oneOf( mockFetcher ).disconnect();
            }
        } );

        // tempContext.updateTimestamp( true, contextTimestamp );

        IndexUpdateRequest updateRequest = new IndexUpdateRequest( tempContext, mockFetcher );

        updater.fetchAndUpdateIndex( updateRequest );

        mockery.assertIsSatisfied();
    }
View Full Code Here

    }

    public void testIncrementalIndexUpdate()
        throws Exception
    {
        Mockery mockery = new Mockery();

        final String indexUrl = repositoryUrl + ".index";
        final Date contextTimestamp = df.parse( "20081128000000.000 -0600" );

        final ResourceFetcher mockFetcher = mockery.mock( ResourceFetcher.class );

        final IndexingContext tempContext = mockery.mock( IndexingContext.class );

        final Properties localProps = new Properties();
        localProps.setProperty( IndexingContext.INDEX_CHUNK_COUNTER, "1" );
        localProps.setProperty( IndexingContext.INDEX_CHAIN_ID, "someid" );

        mockery.checking( new Expectations()
        {
            {
                allowing( tempContext ).getTimestamp();
                will( returnValue( contextTimestamp ) );

                allowing( tempContext ).getId();
                will( returnValue( repositoryId ) );

                allowing( tempContext ).getIndexUpdateUrl();
                will( returnValue( indexUrl ) );

                allowing( tempContext ).commit();

                allowing( tempContext ).getIndexCreators();
                will( returnValue( DEFAULT_CREATORS ) );

                oneOf( mockFetcher ).connect( repositoryId, indexUrl );

                oneOf( mockFetcher ).retrieve( //
                    with( IndexingContext.INDEX_REMOTE_PROPERTIES_FILE ) );
                will( new PropertiesAction()
                {
                    @Override
                    Properties getProperties()
                    {
                        Properties properties = new Properties();
                        properties.setProperty( IndexingContext.INDEX_ID, "central" );
                        properties.setProperty( IndexingContext.INDEX_TIMESTAMP, "20081129174241.859 -0600" );
                        properties.setProperty( IndexingContext.INDEX_CHUNK_COUNTER, "3" );
                        properties.setProperty( IndexingContext.INDEX_CHAIN_ID, "someid" );
                        properties.setProperty( IndexingContext.INDEX_CHUNK_PREFIX + "0", "3" );
                        properties.setProperty( IndexingContext.INDEX_CHUNK_PREFIX + "1", "2" );
                        properties.setProperty( IndexingContext.INDEX_CHUNK_PREFIX + "2", "1" );
                        return properties;
                    }
                } );

                allowing( tempContext ).getIndexDirectoryFile();
                will( new IndexDirectoryFileAction( localProps, testBasedir ) );

                oneOf( mockFetcher ).retrieve( //
                    with( IndexingContext.INDEX_FILE_PREFIX + ".2.gz" ) );
                will( returnValue( newInputStream( "/index-updater/server-root/nexus-maven-repository-index.gz" ) ) );
                oneOf( mockFetcher ).retrieve( //
                    with( IndexingContext.INDEX_FILE_PREFIX + ".3.gz" ) );
                will( returnValue( newInputStream( "/index-updater/server-root/nexus-maven-repository-index.gz" ) ) );
                // could create index archive there and verify that it is merged correctly

                oneOf( tempContext ).merge( with( any( Directory.class ) ) );

                oneOf( tempContext ).merge( with( any( Directory.class ) ) );

                oneOf( mockFetcher ).disconnect();
            }
        } );

        // tempContext.updateTimestamp( true, contextTimestamp );

        IndexUpdateRequest updateRequest = new IndexUpdateRequest( tempContext, mockFetcher );

        updater.fetchAndUpdateIndex( updateRequest );

        mockery.assertIsSatisfied();
    }
View Full Code Here

    }

    public void testIncrementalIndexUpdateNoCounter()
        throws Exception
    {
        Mockery mockery = new Mockery();

        final String indexUrl = repositoryUrl + ".index";
        final Date contextTimestamp = df.parse( "20081128000000.000 -0600" );

        final ResourceFetcher mockFetcher = mockery.mock( ResourceFetcher.class );

        final IndexingContext tempContext = mockery.mock( IndexingContext.class );

        mockery.checking( new Expectations()
        {
            {
                allowing( tempContext ).getIndexDirectoryFile();
                will( new ReturnValueAction( testBasedir ) );

                allowing( tempContext ).getTimestamp();
                will( returnValue( contextTimestamp ) );

                allowing( tempContext ).getId();
                will( returnValue( repositoryId ) );

                allowing( tempContext ).getIndexUpdateUrl();
                will( returnValue( indexUrl ) );

                allowing( tempContext ).commit();

                allowing( tempContext ).getIndexCreators();
                will( returnValue( DEFAULT_CREATORS ) );

                oneOf( mockFetcher ).connect( repositoryId, indexUrl );

                oneOf( mockFetcher ).retrieve( //
                    with( IndexingContext.INDEX_REMOTE_PROPERTIES_FILE ) );
                will( new PropertiesAction()
                {
                    @Override
                    Properties getProperties()
                    {
                        Properties properties = new Properties();
                        properties.setProperty( IndexingContext.INDEX_ID, "central" );
                        properties.setProperty( IndexingContext.INDEX_TIMESTAMP, "20081129174241.859 -0600" );
                        properties.setProperty( IndexingContext.INDEX_CHUNK_COUNTER, "3" );
                        properties.setProperty( IndexingContext.INDEX_CHAIN_ID, "someid" );
                        properties.setProperty( IndexingContext.INDEX_CHUNK_PREFIX + "0", "3" );
                        properties.setProperty( IndexingContext.INDEX_CHUNK_PREFIX + "1", "2" );
                        properties.setProperty( IndexingContext.INDEX_CHUNK_PREFIX + "2", "1" );
                        return properties;
                    }
                } );

                oneOf( mockFetcher ).retrieve( //
                    with( IndexingContext.INDEX_FILE_PREFIX + ".gz" ) );
                will( returnValue( newInputStream( "/index-updater/server-root/nexus-maven-repository-index.gz" ) ) );
                // could create index archive there and verify that it is merged correctly

                oneOf( tempContext ).replace( with( any( Directory.class ) ) );

                never( mockFetcher ).retrieve( //
                    with( IndexingContext.INDEX_FILE_PREFIX + ".2.gz" ) );

                never( tempContext ).merge( with( any( Directory.class ) ) );

                oneOf( mockFetcher ).disconnect();
            }
        } );

        // tempContext.updateTimestamp( true, contextTimestamp );

        IndexUpdateRequest updateRequest = new IndexUpdateRequest( tempContext, mockFetcher );

        updater.fetchAndUpdateIndex( updateRequest );

        mockery.assertIsSatisfied();
    }
View Full Code Here

    }

    public void testIncrementalIndexUpdateNoUpdateNecessary()
        throws Exception
    {
        Mockery mockery = new Mockery();

        final String indexUrl = repositoryUrl + ".index";
        final Date contextTimestamp = df.parse( "20081128000000.000 -0600" );

        final ResourceFetcher mockFetcher = mockery.mock( ResourceFetcher.class );

        final IndexingContext tempContext = mockery.mock( IndexingContext.class );

        final Properties localProps = new Properties();
        localProps.setProperty( IndexingContext.INDEX_CHUNK_COUNTER, "3" );
        localProps.setProperty( IndexingContext.INDEX_CHAIN_ID, "someid" );

        mockery.checking( new Expectations()
        {
            {
                allowing( tempContext ).getTimestamp();
                will( returnValue( contextTimestamp ) );

                allowing( tempContext ).getId();
                will( returnValue( repositoryId ) );

                allowing( tempContext ).getIndexUpdateUrl();
                will( returnValue( indexUrl ) );

                allowing( tempContext ).getIndexCreators();
                will( returnValue( DEFAULT_CREATORS ) );

                allowing( tempContext ).commit();

                oneOf( mockFetcher ).connect( repositoryId, indexUrl );

                oneOf( mockFetcher ).retrieve( //
                    with( IndexingContext.INDEX_REMOTE_PROPERTIES_FILE ) );
                will( new PropertiesAction()
                {
                    @Override
                    Properties getProperties()
                    {
                        Properties properties = new Properties();
                        properties.setProperty( IndexingContext.INDEX_ID, "central" );
                        properties.setProperty( IndexingContext.INDEX_TIMESTAMP, "20081129174241.859 -0600" );
                        properties.setProperty( IndexingContext.INDEX_CHUNK_COUNTER, "3" );
                        properties.setProperty( IndexingContext.INDEX_CHAIN_ID, "someid" );
                        properties.setProperty( IndexingContext.INDEX_CHUNK_PREFIX + "0", "3" );
                        properties.setProperty( IndexingContext.INDEX_CHUNK_PREFIX + "1", "2" );
                        properties.setProperty( IndexingContext.INDEX_CHUNK_PREFIX + "2", "1" );
                        return properties;
                    }
                } );

                allowing( tempContext ).getIndexDirectoryFile();
                will( new IndexDirectoryFileAction( localProps, testBasedir ) );

                never( mockFetcher ).retrieve( //
                    with( IndexingContext.INDEX_FILE_PREFIX + ".gz" ) );
                // could create index archive there and verify that it is merged correctly

                never( mockFetcher ).retrieve( //
                    with( IndexingContext.INDEX_FILE_PREFIX + ".1.gz" ) );

                never( mockFetcher ).retrieve( //
                    with( IndexingContext.INDEX_FILE_PREFIX + ".2.gz" ) );

                never( mockFetcher ).retrieve( //
                    with( IndexingContext.INDEX_FILE_PREFIX + ".3.gz" ) );

                never( tempContext ).merge( with( any( Directory.class ) ) );

                never( tempContext ).replace( with( any( Directory.class ) ) );

                oneOf( mockFetcher ).disconnect();
            }
        } );

        // tempContext.updateTimestamp( true, contextTimestamp );

        IndexUpdateRequest updateRequest = new IndexUpdateRequest( tempContext, mockFetcher );

        updater.fetchAndUpdateIndex( updateRequest );

        mockery.assertIsSatisfied();
    }
View Full Code Here

    }

    public void testUpdateForceFullUpdate()
        throws Exception
    {
        Mockery mockery = new Mockery();

        final String indexUrl = repositoryUrl + ".index";
        final Date contextTimestamp = df.parse( "20081128000000.000 -0600" );

        final ResourceFetcher mockFetcher = mockery.mock( ResourceFetcher.class );

        final IndexingContext tempContext = mockery.mock( IndexingContext.class );

        mockery.checking( new Expectations()
        {
            {
                allowing( tempContext ).getIndexDirectoryFile();
                will( new ReturnValueAction( testBasedir ) );

                allowing( tempContext ).getTimestamp();
                will( returnValue( contextTimestamp ) );

                allowing( tempContext ).getId();
                will( returnValue( repositoryId ) );

                allowing( tempContext ).getIndexUpdateUrl();
                will( returnValue( indexUrl ) );

                allowing( tempContext ).commit();

                allowing( tempContext ).getIndexCreators();
                will( returnValue( DEFAULT_CREATORS ) );

                oneOf( mockFetcher ).connect( repositoryId, indexUrl );

                oneOf( mockFetcher ).retrieve( //
                    with( IndexingContext.INDEX_REMOTE_PROPERTIES_FILE ) );
                will( new PropertiesAction()
                {
                    @Override
                    Properties getProperties()
                    {
                        Properties properties = new Properties();
                        properties.setProperty( IndexingContext.INDEX_ID, "central" );
                        properties.setProperty( IndexingContext.INDEX_TIMESTAMP, "20081129174241.859 -0600" );
                        properties.setProperty( IndexingContext.INDEX_CHUNK_COUNTER, "3" );
                        properties.setProperty( IndexingContext.INDEX_CHAIN_ID, "someid" );
                        properties.setProperty( IndexingContext.INDEX_CHUNK_PREFIX + "0", "3" );
                        properties.setProperty( IndexingContext.INDEX_CHUNK_PREFIX + "1", "2" );
                        properties.setProperty( IndexingContext.INDEX_CHUNK_PREFIX + "2", "1" );
                        return properties;
                    }
                } );

                never( tempContext ).getIndexDirectoryFile();

                never( mockFetcher ).retrieve( //
                    with( IndexingContext.INDEX_FILE_PREFIX + ".1.gz" ) );

                never( mockFetcher ).retrieve( //
                    with( IndexingContext.INDEX_FILE_PREFIX + ".2.gz" ) );

                never( mockFetcher ).retrieve( //
                    with( IndexingContext.INDEX_FILE_PREFIX + ".3.gz" ) );

                oneOf( mockFetcher ).retrieve( with( IndexingContext.INDEX_FILE_PREFIX + ".gz" ) );
                will( returnValue( newInputStream( "/index-updater/server-root/nexus-maven-repository-index.gz" ) ) );

                never( tempContext ).merge( with( any( Directory.class ) ) );

                never( tempContext ).merge( with( any( Directory.class ) ) );

                oneOf( tempContext ).replace( with( any( Directory.class ) ) );

                oneOf( mockFetcher ).disconnect();
            }
        } );

        // tempContext.updateTimestamp( true, contextTimestamp );

        IndexUpdateRequest updateRequest = new IndexUpdateRequest( tempContext, mockFetcher );

        updateRequest.setForceFullUpdate( true );

        updater.fetchAndUpdateIndex( updateRequest );

        mockery.assertIsSatisfied();
    }
View Full Code Here

    }

    public void testUpdateForceFullUpdateNoGZ()
        throws Exception
    {
        Mockery mockery = new Mockery();

        final String indexUrl = repositoryUrl + ".index";
        final Date contextTimestamp = df.parse( "20081128000000.000 -0600" );

        final ResourceFetcher mockFetcher = mockery.mock( ResourceFetcher.class );

        final IndexingContext tempContext = mockery.mock( IndexingContext.class );

        mockery.checking( new Expectations()
        {
            {
                allowing( tempContext ).getIndexDirectoryFile();
                will( new ReturnValueAction( testBasedir ) );

                allowing( tempContext ).getTimestamp();
                will( returnValue( contextTimestamp ) );

                allowing( tempContext ).commit();

                allowing( tempContext ).getId();
                will( returnValue( repositoryId ) );

                allowing( tempContext ).getIndexUpdateUrl();
                will( returnValue( indexUrl ) );

                allowing( tempContext ).getIndexCreators();
                will( returnValue( DEFAULT_CREATORS ) );

                oneOf( mockFetcher ).connect( repositoryId, indexUrl );

                oneOf( mockFetcher ).retrieve( //
                    with( IndexingContext.INDEX_REMOTE_PROPERTIES_FILE ) );
                will( new PropertiesAction()
                {
                    @Override
                    Properties getProperties()
                    {
                        Properties properties = new Properties();
                        properties.setProperty( IndexingContext.INDEX_ID, "central" );
                        properties.setProperty( IndexingContext.INDEX_LEGACY_TIMESTAMP, "20081129174241.859 -0600" );
                        return properties;
                    }
                } );

                never( tempContext ).getIndexDirectoryFile();

                oneOf( mockFetcher ).retrieve( with( IndexingContext.INDEX_FILE_PREFIX + ".gz" ) );

                will( throwException( new IOException() ) );

                oneOf( mockFetcher ).retrieve( with( IndexingContext.INDEX_FILE_PREFIX + ".zip" ) );

                will( returnValue( newInputStream( "/index-updater/server-root/legacy/nexus-maven-repository-index.zip" ) ) );

                never( tempContext ).merge( with( any( Directory.class ) ) );

                never( tempContext ).merge( with( any( Directory.class ) ) );

                oneOf( tempContext ).replace( with( any( Directory.class ) ) );

                oneOf( mockFetcher ).disconnect();
            }
        } );

        // tempContext.updateTimestamp( true, contextTimestamp );

        IndexUpdateRequest updateRequest = new IndexUpdateRequest( tempContext, mockFetcher );

        updateRequest.setForceFullUpdate( true );

        updater.fetchAndUpdateIndex( updateRequest );

        mockery.assertIsSatisfied();
    }
View Full Code Here

TOP

Related Classes of org.jmock.Mockery

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.