View Javadoc

1   package org.apache.maven.index.incremental;
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 java.io.File;
23  import java.io.FileNotFoundException;
24  import java.io.IOException;
25  import java.io.InputStream;
26  import java.util.List;
27  import java.util.Properties;
28  
29  import org.apache.maven.index.AbstractIndexCreatorHelper;
30  import org.apache.maven.index.NexusIndexer;
31  import org.apache.maven.index.context.IndexingContext;
32  import org.apache.maven.index.packer.IndexPackingRequest;
33  import org.apache.maven.index.updater.IndexUpdateRequest;
34  import org.apache.maven.index.updater.ResourceFetcher;
35  import org.codehaus.plexus.util.FileUtils;
36  
37  public class DefaultIncrementalHandlerTest
38      extends AbstractIndexCreatorHelper
39  {
40      IncrementalHandler handler = null;
41  
42      NexusIndexer indexer = null;
43  
44      IndexingContext context = null;
45  
46      File indexDir = null;
47  
48      File repoDir = null;
49  
50      @Override
51      protected void setUp()
52          throws Exception
53      {
54          super.setUp();
55  
56          indexer = lookup( NexusIndexer.class );
57          handler = lookup( IncrementalHandler.class );
58  
59          indexDir = new File( getBasedir(), "target/index/nexus-incremental-test" );
60          repoDir = new File( getBasedir(), "target/repos/nexus-incremental-test" );
61          FileUtils.deleteDirectory( indexDir );
62          FileUtils.deleteDirectory( repoDir );
63  
64          context = indexer.addIndexingContext( "test", "test", repoDir, indexDir, null, null, DEFAULT_CREATORS );
65      }
66  
67      @Override
68      protected void tearDown()
69          throws Exception
70      {
71          super.tearDown();
72  
73          indexer.removeIndexingContext( context, true );
74      }
75  
76      public void testUpdateInvalidProperties()
77          throws Exception
78      {
79          Properties properties = new Properties();
80  
81          IndexPackingRequest request = new IndexPackingRequest( context, indexDir );
82  
83          // No properties definite fail
84          assertNull( handler.getIncrementalUpdates( request, properties ) );
85  
86          properties.setProperty( IndexingContext.INDEX_TIMESTAMP, "junk" );
87  
88          // property set, but invalid
89          assertNull( handler.getIncrementalUpdates( request, properties ) );
90  
91          properties.setProperty( IndexingContext.INDEX_TIMESTAMP, "19991112182432.432 -0600" );
92  
93          List<Integer> updates = handler.getIncrementalUpdates( request, properties );
94  
95          assertEquals( updates.size(), 0 );
96      }
97  
98      public void testUpdateValid()
99          throws Exception
100     {
101         Properties properties = new Properties();
102 
103         IndexPackingRequest request = new IndexPackingRequest( context, indexDir );
104 
105         properties.setProperty( IndexingContext.INDEX_TIMESTAMP, "19991112182432.432 -0600" );
106 
107         FileUtils.copyDirectoryStructure( new File( getBasedir(), "src/test/repo/ch" ), new File( repoDir, "ch" ) );
108 
109         indexer.scan( context );
110 
111         List<Integer> updates = handler.getIncrementalUpdates( request, properties );
112 
113         assertEquals( updates.size(), 1 );
114     }
115 
116     public void testRemoteUpdatesInvalidProperties()
117         throws Exception
118     {
119         // just a dummy fetcher, it's not used here anyway
120         IndexUpdateRequest request = new IndexUpdateRequest( context, new ResourceFetcher()
121         {
122             public InputStream retrieve( String name )
123                 throws IOException, FileNotFoundException
124             {
125                 // TODO Auto-generated method stub
126                 return null;
127             }
128 
129             public void retrieve( String name, File targetFile )
130                 throws IOException, FileNotFoundException
131             {
132                 // TODO Auto-generated method stub
133 
134             }
135 
136             public void disconnect()
137                 throws IOException
138             {
139                 // TODO Auto-generated method stub
140 
141             }
142 
143             public void connect( String id, String url )
144                 throws IOException
145             {
146                 // TODO Auto-generated method stub
147 
148             }
149         } );
150 
151         Properties localProperties = new Properties();
152         Properties remoteProperties = new Properties();
153 
154         List<String> filenames = handler.loadRemoteIncrementalUpdates( request, localProperties, remoteProperties );
155 
156         assertNull( filenames );
157     }
158 }