Package org.apache.maven.archiva.database.constraints

Source Code of org.apache.maven.archiva.database.constraints.ArtifactsBySha1ChecksumConstraintTest

package org.apache.maven.archiva.database.constraints;

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied.  See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import org.apache.maven.archiva.database.AbstractArchivaDatabaseTestCase;
import org.apache.maven.archiva.database.ArchivaDAO;
import org.apache.maven.archiva.database.ArtifactDAO;
import org.apache.maven.archiva.model.ArchivaArtifact;

import java.util.Date;
import java.util.List;

/**
* ArtifactsBySha1ChecksumConstraintTest
*
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
* @version $Id: ArtifactsBySha1ChecksumConstraintTest.java 530395 2007-04-19 12:25:11Z joakime $
*/
public class ArtifactsBySha1ChecksumConstraintTest
    extends AbstractArchivaDatabaseTestCase
{
    private static final String HASH3 = "f3f653289f3217c65324830ab3415bc92feddefa";

    private static final String HASH2 = "a49810ad3eba8651677ab57cd40a0f76fdef9538";

    private static final String HASH1 = "232f01b24b1617c46a3d4b0ab3415bc9237dcdec";

    private ArtifactDAO artifactDao;

    protected void setUp()
        throws Exception
    {
        super.setUp();

        ArchivaDAO dao = (ArchivaDAO) lookup( ArchivaDAO.ROLE, "jdo" );
        artifactDao = dao.getArtifactDAO();
    }

    public ArchivaArtifact createArtifact( String artifactId, String version )
    {
        ArchivaArtifact artifact = artifactDao.createArtifact( "org.apache.maven.archiva.test", artifactId, version,
                                                               "", "jar" );
        artifact.getModel().setLastModified( new Date() );
        artifact.getModel().setRepositoryId( "testable_repo" );
        return artifact;
    }

    public void testConstraint()
        throws Exception
    {
        ArchivaArtifact artifact;

        // Setup artifacts in fresh DB.
        artifact = createArtifact( "test-one", "1.0" );
        artifact.getModel().setChecksumSHA1( HASH1 );
        artifactDao.saveArtifact( artifact );

        artifact = createArtifact( "test-one", "1.1" );
        artifact.getModel().setChecksumSHA1( HASH1 );
        artifactDao.saveArtifact( artifact );

        artifact = createArtifact( "test-one", "1.2" );
        artifact.getModel().setChecksumSHA1( HASH1 );
        artifactDao.saveArtifact( artifact );

        artifact = createArtifact( "test-two", "1.0" );
        artifact.getModel().setChecksumSHA1( HASH1 );
        artifactDao.saveArtifact( artifact );

        artifact = createArtifact( "test-two", "2.0" );
        artifact.getModel().setChecksumSHA1( HASH3 );
        artifactDao.saveArtifact( artifact );

        artifact = createArtifact( "test-two", "2.1" );
        artifact.getModel().setChecksumSHA1( HASH2 );
        artifactDao.saveArtifact( artifact );

        artifact = createArtifact( "test-two", "3.0" );
        artifact.getModel().setChecksumSHA1( HASH2 );
        artifactDao.saveArtifact( artifact );

        assertConstraint( "Artifacts by SHA1 Checksum", 4, new ArtifactsBySha1ChecksumConstraint( HASH1 ) );
        assertConstraint( "Artifacts by SHA1 Checksum", 2, new ArtifactsBySha1ChecksumConstraint( HASH2 ) );
        assertConstraint( "Artifacts by SHA1 Checksum", 1, new ArtifactsBySha1ChecksumConstraint( HASH3 ) );
    }

    private void assertConstraint( String msg, int count, ArtifactsBySha1ChecksumConstraint constraint )
        throws Exception
    {
        List results = artifactDao.queryArtifacts( constraint );
        assertNotNull( msg + ": Not Null", results );
        assertEquals( msg + ": Results.size", count, results.size() );
    }

}
TOP

Related Classes of org.apache.maven.archiva.database.constraints.ArtifactsBySha1ChecksumConstraintTest

TOP
Copyright © 2018 www.massapi.com. 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.