001package org.apache.maven.wagon.events; 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 junit.framework.TestCase; 023import org.apache.maven.wagon.ConnectionException; 024import org.apache.maven.wagon.Wagon; 025import org.apache.maven.wagon.authentication.AuthenticationException; 026import org.apache.maven.wagon.repository.Repository; 027import org.apache.maven.wagon.resource.Resource; 028import org.easymock.EasyMock; 029 030/** 031 * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a> 032 * 033 */ 034public class TransferEventTest 035 extends TestCase 036{ 037 /* 038 * Class to test for void TransferEvent(Wagon, Repository, String, int, 039 * int) 040 */ 041 public void testTransferEventProperties() 042 throws ConnectionException, AuthenticationException 043 { 044 final Wagon wagon = EasyMock.createMock( Wagon.class ); 045 046 final Repository repo = new Repository(); 047 048 wagon.connect( repo ); 049 050 final long timestamp = System.currentTimeMillis(); 051 052 final Exception exception = new AuthenticationException( "dummy" ); 053 054 Resource resource = new Resource(); 055 056 resource.setName( "mm" ); 057 058 TransferEvent event = new TransferEvent( wagon, resource, TransferEvent.TRANSFER_COMPLETED, 059 TransferEvent.REQUEST_GET ); 060 061 assertEquals( wagon, event.getWagon() ); 062 063 assertEquals( "mm", event.getResource().getName() ); 064 065 assertEquals( TransferEvent.TRANSFER_COMPLETED, event.getEventType() ); 066 067 assertEquals( TransferEvent.REQUEST_GET, event.getRequestType() ); 068 069 Resource res = new Resource(); 070 071 res.setName( "mm" ); 072 073 event = new TransferEvent( wagon, res, exception, TransferEvent.REQUEST_GET ); 074 075 assertEquals( wagon, event.getWagon() ); 076 077 assertEquals( "mm", event.getResource().getName() ); 078 079 assertEquals( TransferEvent.TRANSFER_ERROR, event.getEventType() ); 080 081 assertEquals( TransferEvent.REQUEST_GET, event.getRequestType() ); 082 083 assertEquals( exception, event.getException() ); 084 085 event.setResource( null ); 086 087 assertEquals( null, event.getResource() ); 088 089 res.setName( "/foo/baa" ); 090 091 event.setResource( res ); 092 093 assertEquals( "/foo/baa", event.getResource().getName() ); 094 095 event.setTimestamp( timestamp ); 096 097 assertEquals( timestamp, event.getTimestamp() ); 098 099 event.setRequestType( TransferEvent.REQUEST_PUT ); 100 101 assertEquals( TransferEvent.REQUEST_PUT, event.getRequestType() ); 102 103 event.setRequestType( TransferEvent.REQUEST_GET ); 104 105 assertEquals( TransferEvent.REQUEST_GET, event.getRequestType() ); 106 107 try 108 { 109 event.setRequestType( -1 ); 110 111 fail( "Exception expected" ); 112 } 113 catch ( IllegalArgumentException e ) 114 { 115 assertTrue( true ); 116 } 117 118 event.setEventType( TransferEvent.TRANSFER_COMPLETED ); 119 120 assertEquals( TransferEvent.TRANSFER_COMPLETED, event.getEventType() ); 121 122 event.setEventType( TransferEvent.TRANSFER_ERROR ); 123 124 assertEquals( TransferEvent.TRANSFER_ERROR, event.getEventType() ); 125 126 event.setEventType( TransferEvent.TRANSFER_STARTED ); 127 128 assertEquals( TransferEvent.TRANSFER_STARTED, event.getEventType() ); 129 130 event.setEventType( TransferEvent.TRANSFER_PROGRESS ); 131 132 assertEquals( TransferEvent.TRANSFER_PROGRESS, event.getEventType() ); 133 134 try 135 { 136 event.setEventType( -1 ); 137 138 fail( "Exception expected" ); 139 } 140 catch ( IllegalArgumentException e ) 141 { 142 assertTrue( true ); 143 } 144 145 } 146 147 public void testConstantValueConflict() 148 { 149 final int[] values = {TransferEvent.TRANSFER_COMPLETED, TransferEvent.TRANSFER_ERROR, 150 TransferEvent.TRANSFER_STARTED, TransferEvent.TRANSFER_PROGRESS, 151 TransferEvent.REQUEST_GET, TransferEvent.REQUEST_PUT}; 152 153 for ( int i = 0; i < values.length; i++ ) 154 { 155 for ( int j = i + 1; j < values.length; j++ ) 156 { 157 158 final String msg = "Value confict at [i,j]=[" + i + "," + j + "]"; 159 160 assertTrue( msg, values[i] != values[j] ); 161 } 162 } 163 164 } 165 166}