View Javadoc
1   package org.apache.archiva.rest.services;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.archiva.rest.api.services.PingService;
23  import org.apache.cxf.jaxrs.client.WebClient;
24  import org.junit.Ignore;
25  import org.junit.Test;
26  
27  import javax.ws.rs.ForbiddenException;
28  
29  /**
30   * @author Olivier Lamy
31   * @since 1.4-M1
32   */
33  public class PingServiceTest
34      extends AbstractArchivaRestTest
35  {
36  
37  
38      @Test
39      public void ping()
40          throws Exception
41      {
42          // 1000000L
43          //WebClient.getConfig( userService ).getHttpConduit().getClient().setReceiveTimeout(3000);
44  
45          String res = getPingService().ping();
46          assertEquals( "Yeah Baby It rocks!", res );
47      }
48  
49      @Test( expected = ForbiddenException.class )
50      public void pingWithAuthzFailed()
51          throws Exception
52      {
53  
54          try
55          {
56              String res = getPingService().pingWithAuthz();
57              fail( "not in exception" );
58          }
59          catch ( ForbiddenException e )
60          {
61              assertEquals( 403, e.getResponse().getStatus() );
62              throw e;
63          }
64      }
65  
66      @Test
67      public void pingWithAuthz()
68          throws Exception
69      {
70  
71          PingService service = getPingService();
72          WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 300000 );
73          WebClient.client( service ).header( "Authorization", authorizationHeader );
74          String res = service.pingWithAuthz();
75          assertEquals( "Yeah Baby It rocks!", res );
76      }
77  
78      @Ignore( "FIXME guest failed ???" )
79      public void pingWithAuthzGuest()
80          throws Exception
81      {
82  
83          PingService service = getPingService();
84          WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 300000 );
85          WebClient.client( service ).header( "Authorization", guestAuthzHeader );
86          String res = service.pingWithAuthz();
87          assertEquals( "Yeah Baby It rocks!", res );
88      }
89  }