View Javadoc
1   package org.apache.archiva;
2   /*
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   */
20  
21  import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
22  import org.apache.archiva.web.api.RuntimeInfoService;
23  import org.apache.archiva.web.model.ApplicationRuntimeInfo;
24  import org.apache.commons.io.FileUtils;
25  import org.apache.commons.lang.StringUtils;
26  import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
27  import org.apache.archiva.redback.rest.services.AbstractRestServicesTest;
28  import org.apache.cxf.jaxrs.client.WebClient;
29  import org.junit.Before;
30  import org.junit.Test;
31  
32  import java.io.File;
33  import java.util.Collections;
34  import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
35  import org.junit.runner.RunWith;
36  
37  /**
38   * @author Olivier Lamy
39   */
40  @RunWith( ArchivaBlockJUnit4ClassRunner.class )
41  public class RuntimeInfoServiceTest
42      extends AbstractRestServicesTest
43  {
44      @Override
45      @Before
46      public void startServer()
47          throws Exception
48      {
49          File appServerBase = new File( System.getProperty( "appserver.base" ) );
50  
51          File jcrDirectory = new File( appServerBase, "jcr" );
52  
53          if ( jcrDirectory.exists() )
54          {
55              FileUtils.deleteDirectory( jcrDirectory );
56          }
57  
58          super.startServer();
59      }
60  
61      @Override
62      protected String getSpringConfigLocation()
63      {
64          return "classpath*:META-INF/spring-context.xml,classpath:/spring-context-with-jcr.xml";
65      }
66  
67      @Override
68      protected String getRestServicesPath()
69      {
70          return "restServices";
71      }
72  
73      protected String getBaseUrl()
74      {
75          String baseUrlSysProps = System.getProperty( "archiva.baseRestUrl" );
76          return StringUtils.isBlank( baseUrlSysProps ) ? "http://localhost:" + port : baseUrlSysProps;
77      }
78  
79      @Test
80      public void runtimeInfoService()
81          throws Exception
82      {
83          RuntimeInfoService service =
84              JAXRSClientFactory.create( getBaseUrl() + "/" + getRestServicesPath() + "/archivaUiServices/",
85                                         RuntimeInfoService.class,
86                                         Collections.singletonList( new JacksonJaxbJsonProvider() ) );
87  
88          WebClient.client(service).header("Referer","http://localhost");
89          ApplicationRuntimeInfo applicationRuntimeInfo = service.getApplicationRuntimeInfo( "en" );
90  
91          assertEquals( System.getProperty( "expectedVersion" ), applicationRuntimeInfo.getVersion() );
92          assertFalse( applicationRuntimeInfo.isJavascriptLog() );
93          assertTrue( applicationRuntimeInfo.isLogMissingI18n() );
94  
95      }
96  }