001package org.apache.maven.scm.provider.accurev;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *    http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import org.apache.maven.scm.provider.ScmProviderRepository;
023import org.codehaus.plexus.util.StringUtils;
024import org.hamcrest.Description;
025import org.hamcrest.Matcher;
026import org.hamcrest.TypeSafeMatcher;
027
028public class AccuRevScmProviderRepositoryMatcher
029    extends TypeSafeMatcher<ScmProviderRepository>
030{
031
032    public static Matcher<ScmProviderRepository> isRepo( String user, String pass, String host, int port,
033                                                         String stream, String projectPath )
034
035    {
036        return new AccuRevScmProviderRepositoryMatcher( user, pass, host, port, stream, projectPath );
037    }
038
039    private String user;
040
041    private String pass;
042
043    private String host;
044
045    private String projectPath;
046
047    private String stream;
048
049    private int port;
050
051    public AccuRevScmProviderRepositoryMatcher( String user, String pass, String host, int port, String stream,
052                                                String projectPath )
053    {
054        this.user = user;
055        this.pass = pass;
056        this.host = host;
057        this.port = port;
058        this.stream = stream;
059        this.projectPath = projectPath;
060
061    }
062
063    public void describeTo( Description desc )
064    {
065        desc.appendText( "an AccuRev repo with" );
066        desc.appendText( " user=" );
067        desc.appendValue( user );
068        desc.appendText( " pass=" );
069        desc.appendValue( pass );
070        desc.appendText( " host=" );
071        desc.appendValue( host );
072        desc.appendText( " port=" );
073        desc.appendValue( port );
074        desc.appendText( " stream=" );
075        desc.appendValue( stream );
076        desc.appendText( " projectPath=" );
077        desc.appendValue( projectPath );
078
079    }
080
081    @Override
082    public boolean matchesSafely( ScmProviderRepository repo )
083    {
084        if ( !( repo instanceof AccuRevScmProviderRepository ) )
085        {
086            return false;
087        }
088        AccuRevScmProviderRepository accuRevRepo = (AccuRevScmProviderRepository) repo;
089        return StringUtils.equals( user, accuRevRepo.getUser() )
090            && StringUtils.equals( pass, accuRevRepo.getPassword() )
091            && StringUtils.equals( host, accuRevRepo.getHost() ) && port == accuRevRepo.getPort()
092            && StringUtils.equals( stream, accuRevRepo.getStreamName() )
093            && StringUtils.equals( projectPath, accuRevRepo.getProjectPath() );
094
095    }
096}