1 package org.apache.maven.archiva.web.action.reports;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
22 import com.google.common.collect.Lists;
23 import com.opensymphony.xwork2.Action;
24 import org.apache.archiva.metadata.model.MetadataFacet;
25 import org.apache.archiva.metadata.repository.MetadataRepository;
26 import org.apache.archiva.metadata.repository.RepositorySession;
27 import org.apache.archiva.metadata.repository.memory.TestRepositorySessionFactory;
28 import org.apache.archiva.metadata.repository.stats.RepositoryStatistics;
29 import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager;
30 import org.apache.archiva.reports.RepositoryProblemFacet;
31 import org.apache.commons.io.IOUtils;
32 import org.apache.maven.archiva.security.UserRepositoriesStub;
33 import org.apache.maven.archiva.web.action.AbstractActionTestCase;
34 import org.easymock.MockControl;
35 import org.junit.After;
37 import java.io.IOException;
38 import java.util.ArrayList;
39 import java.util.Arrays;
40 import java.util.Collections;
41 import java.util.Date;
42 import java.util.List;
44 import static org.mockito.Mockito.mock;
45 import static org.mockito.Mockito.when;
48 * Test the GenerationReportAction. Note that we are testing for <i>current</i> behaviour, however there are several
49 * instances below where other behaviour may actually be more appropriate (eg the error handling, download stats should
50 * never forward to HTML page, etc). This is also missing tests for various combinations of paging at this point.
52 public class GenerateReportActionTest
53 extends AbstractActionTestCase
55 private GenerateReportAction action;
57 private static final String SNAPSHOTS = "snapshots";
59 private static final String INTERNAL = "internal";
61 private static final String GROUP_ID = "groupId";
63 private RepositoryStatisticsManager repositoryStatisticsManager;
65 private MockControl repositoryStatisticsManagerControl;
67 private MockControl metadataRepositoryControl;
69 private MetadataRepository metadataRepository;
71 private static final String PROBLEM = "problem";
74 protected void setUp()
79 //action = (GenerateReportAction) lookup( Action.class, "generateReport" );
81 UserRepositoriesStub stub = applicationContext.getBean( "userRepositories", UserRepositoriesStub.class );
82 stub.setRepoIds( Lists.<String>newArrayList( "internal", "snapshots" ) );
84 action = (GenerateReportAction) getActionProxy( "/report/generateReport.action" ).getAction();
86 repositoryStatisticsManagerControl = MockControl.createControl( RepositoryStatisticsManager.class );
87 repositoryStatisticsManager = (RepositoryStatisticsManager) repositoryStatisticsManagerControl.getMock();
88 action.setRepositoryStatisticsManager( repositoryStatisticsManager );
90 metadataRepositoryControl = MockControl.createControl( MetadataRepository.class );
91 metadataRepository = (MetadataRepository) metadataRepositoryControl.getMock();
93 RepositorySession repositorySession = mock( RepositorySession.class );
94 when( repositorySession.getRepository() ).thenReturn( metadataRepository );
96 //TestRepositorySessionFactory factory = (TestRepositorySessionFactory) lookup( RepositorySessionFactory.class );
98 TestRepositorySessionFactory factory = new TestRepositorySessionFactory();
99 factory.setRepositorySession( repositorySession );
103 public void tearDown()
106 UserRepositoriesStub stub = applicationContext.getBean( "userRepositories", UserRepositoriesStub.class );
107 stub.setRepoIds( Lists.<String>newArrayList( "test-repo" ) );
112 private void prepareAction( List<String> selectedRepositories, List<String> availableRepositories )
114 action.setSelectedRepositories( selectedRepositories );
117 assertEquals( Arrays.asList( GenerateReportAction.ALL_REPOSITORIES, INTERNAL, SNAPSHOTS ),
118 action.getRepositoryIds() );
119 assertEquals( availableRepositories, action.getAvailableRepositories() );
122 public void testGenerateStatisticsInvalidRowCount()
124 repositoryStatisticsManagerControl.replay();
125 prepareAction( Collections.singletonList( INTERNAL ), Collections.singletonList( SNAPSHOTS ) );
127 action.setRowCount( 0 );
128 String result = action.generateStatistics();
129 assertEquals( Action.INPUT, result );
130 assertTrue( action.hasFieldErrors() );
131 repositoryStatisticsManagerControl.verify();
134 public void testGenerateStatisticsInvalidEndDate()
136 repositoryStatisticsManagerControl.replay();
137 prepareAction( Collections.singletonList( INTERNAL ), Collections.singletonList( SNAPSHOTS ) );
139 action.setStartDate( "2009/12/12" );
140 action.setEndDate( "2008/11/11" );
141 String result = action.generateStatistics();
142 assertEquals( Action.INPUT, result );
143 assertTrue( action.hasFieldErrors() );
144 repositoryStatisticsManagerControl.verify();
147 public void testGenerateStatisticsMalformedEndDate()
149 repositoryStatisticsManagerControl.replay();
150 prepareAction( Collections.singletonList( INTERNAL ), Collections.singletonList( SNAPSHOTS ) );
152 action.setEndDate( "This is not a date" );
153 String result = action.generateStatistics();
155 // TODO: should be an input error
156 assertEquals( Action.ERROR, result );
157 assertTrue( action.hasActionErrors() );
158 repositoryStatisticsManagerControl.verify();
161 public void testGenerateStatisticsInvalidEndDateMultiRepo()
163 repositoryStatisticsManagerControl.replay();
164 prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() );
166 action.setStartDate( "2009/12/12" );
167 action.setEndDate( "2008/11/11" );
168 String result = action.generateStatistics();
169 assertEquals( Action.INPUT, result );
170 assertTrue( action.hasFieldErrors() );
171 repositoryStatisticsManagerControl.verify();
174 public void testGenerateStatisticsMalformedEndDateMultiRepo()
176 repositoryStatisticsManagerControl.replay();
177 prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() );
179 action.setEndDate( "This is not a date" );
180 String result = action.generateStatistics();
182 // TODO: should be an input error
183 assertEquals( Action.ERROR, result );
184 assertTrue( action.hasActionErrors() );
185 repositoryStatisticsManagerControl.verify();
188 public void testGenerateStatisticsNoRepos()
190 repositoryStatisticsManagerControl.replay();
191 prepareAction( Collections.<String>emptyList(), Arrays.asList( SNAPSHOTS, INTERNAL ) );
193 String result = action.generateStatistics();
194 assertEquals( Action.INPUT, result );
195 assertTrue( action.hasFieldErrors() );
196 repositoryStatisticsManagerControl.verify();
199 public void testGenerateStatisticsSingleRepo()
202 repositoryStatisticsManagerControl.expectAndReturn(
203 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, INTERNAL, null, null ),
204 Collections.singletonList( createDefaultStats() ) );
206 repositoryStatisticsManagerControl.replay();
207 prepareAction( Collections.singletonList( INTERNAL ), Collections.singletonList( SNAPSHOTS ) );
209 String result = action.generateStatistics();
210 assertSuccessResult( result );
211 repositoryStatisticsManagerControl.verify();
214 public void testGenerateStatisticsSingleRepoNoStats()
218 repositoryStatisticsManagerControl.expectAndReturn(
219 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, INTERNAL, null, null ),
220 Collections.<Object>emptyList() );
221 repositoryStatisticsManagerControl.replay();
222 prepareAction( Collections.singletonList( INTERNAL ), Collections.singletonList( SNAPSHOTS ) );
224 String result = action.generateStatistics();
225 assertEquals( Action.ERROR, result );
226 assertTrue( action.hasActionErrors() );
228 repositoryStatisticsManagerControl.verify();
231 public void testGenerateStatisticsOvershotPages()
235 repositoryStatisticsManagerControl.expectAndReturn(
236 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, INTERNAL, null, null ),
237 Collections.singletonList( createDefaultStats() ) );
238 repositoryStatisticsManagerControl.replay();
240 prepareAction( Collections.singletonList( INTERNAL ), Collections.singletonList( SNAPSHOTS ) );
242 String result = action.generateStatistics();
243 assertEquals( Action.ERROR, result );
244 assertTrue( action.hasActionErrors() );
245 repositoryStatisticsManagerControl.verify();
248 public void testGenerateStatisticsMultipleRepoNoResults()
252 repositoryStatisticsManagerControl.expectAndReturn(
253 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, SNAPSHOTS, null, null ),
254 Collections.<Object>emptyList() );
255 repositoryStatisticsManagerControl.expectAndReturn(
256 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, INTERNAL, null, null ),
257 Collections.<Object>emptyList() );
258 repositoryStatisticsManagerControl.replay();
259 prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() );
261 String result = action.generateStatistics();
262 assertEquals( GenerateReportAction.BLANK, result );
263 assertFalse( action.hasActionErrors() );
264 assertFalse( action.hasActionMessages() );
265 assertFalse( action.hasFieldErrors() );
267 repositoryStatisticsManagerControl.verify();
270 public void testGenerateStatisticsMultipleRepo()
274 repositoryStatisticsManagerControl.expectAndReturn(
275 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, SNAPSHOTS, null, null ),
276 Collections.singletonList( createDefaultStats() ) );
277 repositoryStatisticsManagerControl.expectAndReturn(
278 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, INTERNAL, null, null ),
279 Collections.singletonList( createDefaultStats() ) );
281 repositoryStatisticsManagerControl.replay();
282 prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() );
284 String result = action.generateStatistics();
285 assertSuccessResult( result );
286 repositoryStatisticsManagerControl.verify();
289 public void testDownloadStatisticsSingleRepo()
292 Date date = new Date();
293 repositoryStatisticsManagerControl.expectAndReturn(
294 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, SNAPSHOTS, null, null ),
295 Collections.singletonList( createStats( date ) ) );
296 repositoryStatisticsManagerControl.replay();
298 prepareAction( Arrays.asList( SNAPSHOTS ), Arrays.asList( INTERNAL ) );
300 String result = action.downloadStatisticsReport();
301 assertEquals( GenerateReportAction.SEND_FILE, result );
302 assertFalse( action.hasActionErrors() );
303 assertFalse( action.hasFieldErrors() );
306 "Date of Scan,Total File Count,Total Size,Artifact Count,Group Count,Project Count,Plugins,Archetypes,Jars,Wars\n"
307 + date + ",0,0,0,0,0,0,0,0,0\n", IOUtils.toString( action.getInputStream() ) );
308 repositoryStatisticsManagerControl.verify();
311 public void testDownloadStatisticsMultipleRepos()
314 repositoryStatisticsManagerControl.expectAndReturn(
315 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, SNAPSHOTS, null, null ),
316 Collections.singletonList( createDefaultStats() ) );
317 repositoryStatisticsManagerControl.expectAndReturn(
318 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, INTERNAL, null, null ),
319 Collections.singletonList( createDefaultStats() ) );
320 repositoryStatisticsManagerControl.replay();
321 prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() );
323 String result = action.downloadStatisticsReport();
324 assertEquals( GenerateReportAction.SEND_FILE, result );
325 assertFalse( action.hasActionErrors() );
326 assertFalse( action.hasFieldErrors() );
328 assertMultiRepoCsvResult();
329 repositoryStatisticsManagerControl.verify();
332 public void testDownloadStatisticsMalformedEndDateMultiRepo()
334 repositoryStatisticsManagerControl.replay();
335 prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() );
337 action.setEndDate( "This is not a date" );
338 String result = action.downloadStatisticsReport();
340 // TODO: should be an input error
341 assertEquals( Action.ERROR, result );
342 assertTrue( action.hasActionErrors() );
343 repositoryStatisticsManagerControl.verify();
346 public void testDownloadStatisticsMalformedEndDateSingleRepo()
348 repositoryStatisticsManagerControl.replay();
349 prepareAction( Arrays.asList( SNAPSHOTS ), Arrays.asList( INTERNAL ) );
351 action.setEndDate( "This is not a date" );
352 String result = action.downloadStatisticsReport();
354 // TODO: should be an input error
355 assertEquals( Action.ERROR, result );
356 assertTrue( action.hasActionErrors() );
357 repositoryStatisticsManagerControl.verify();
360 public void testDownloadStatisticsInvalidEndDateMultiRepo()
362 repositoryStatisticsManagerControl.replay();
363 prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() );
365 action.setStartDate( "2009/12/12" );
366 action.setEndDate( "2008/11/11" );
367 String result = action.downloadStatisticsReport();
368 assertEquals( Action.INPUT, result );
369 assertTrue( action.hasFieldErrors() );
370 repositoryStatisticsManagerControl.verify();
373 public void testDownloadStatisticsInvalidEndDateSingleRepo()
375 repositoryStatisticsManagerControl.replay();
376 prepareAction( Arrays.asList( SNAPSHOTS ), Arrays.asList( INTERNAL ) );
378 action.setStartDate( "2009/12/12" );
379 action.setEndDate( "2008/11/11" );
380 String result = action.downloadStatisticsReport();
381 assertEquals( Action.INPUT, result );
382 assertTrue( action.hasFieldErrors() );
383 repositoryStatisticsManagerControl.verify();
386 public void testDownloadStatisticsSingleRepoNoStats()
390 repositoryStatisticsManagerControl.expectAndReturn(
391 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, INTERNAL, null, null ),
392 Collections.<Object>emptyList() );
393 repositoryStatisticsManagerControl.replay();
394 prepareAction( Collections.singletonList( INTERNAL ), Collections.singletonList( SNAPSHOTS ) );
396 String result = action.downloadStatisticsReport();
397 assertEquals( Action.ERROR, result );
398 assertTrue( action.hasActionErrors() );
399 repositoryStatisticsManagerControl.verify();
402 public void testDownloadStatisticsNoRepos()
404 repositoryStatisticsManagerControl.replay();
405 prepareAction( Collections.<String>emptyList(), Arrays.asList( SNAPSHOTS, INTERNAL ) );
407 String result = action.downloadStatisticsReport();
408 assertEquals( Action.INPUT, result );
409 assertTrue( action.hasFieldErrors() );
410 repositoryStatisticsManagerControl.verify();
413 public void testDownloadStatisticsMultipleRepoNoResults()
417 repositoryStatisticsManagerControl.expectAndReturn(
418 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, SNAPSHOTS, null, null ),
419 Collections.<Object>emptyList() );
420 repositoryStatisticsManagerControl.expectAndReturn(
421 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, INTERNAL, null, null ),
422 Collections.<Object>emptyList() );
423 repositoryStatisticsManagerControl.replay();
424 prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() );
426 String result = action.downloadStatisticsReport();
427 assertEquals( GenerateReportAction.BLANK, result );
428 assertFalse( action.hasActionErrors() );
429 assertFalse( action.hasActionMessages() );
430 assertFalse( action.hasFieldErrors() );
431 repositoryStatisticsManagerControl.verify();
434 public void testDownloadStatisticsMultipleRepoInStrutsFormat()
437 repositoryStatisticsManagerControl.expectAndReturn(
438 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, SNAPSHOTS, null, null ),
439 Collections.singletonList( createDefaultStats() ) );
440 repositoryStatisticsManagerControl.expectAndReturn(
441 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, INTERNAL, null, null ),
442 Collections.singletonList( createDefaultStats() ) );
443 repositoryStatisticsManagerControl.replay();
444 prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() );
446 action.setSelectedRepositories( Collections.singletonList( "[" + SNAPSHOTS + "],[" + INTERNAL + "]" ) );
447 String result = action.downloadStatisticsReport();
448 assertEquals( GenerateReportAction.SEND_FILE, result );
449 assertFalse( action.hasActionErrors() );
450 assertFalse( action.hasFieldErrors() );
452 assertMultiRepoCsvResult();
453 repositoryStatisticsManagerControl.verify();
456 public void testHealthReportSingleRepo()
459 RepositoryProblemFacet problem1 = createProblem( GROUP_ID, "artifactId", INTERNAL );
460 RepositoryProblemFacet problem2 = createProblem( GROUP_ID, "artifactId-2", INTERNAL );
462 metadataRepositoryControl.expectAndReturn(
463 metadataRepository.getMetadataFacets( INTERNAL, RepositoryProblemFacet.FACET_ID ),
464 Arrays.asList( problem1.getName(), problem2.getName() ) );
465 metadataRepositoryControl.expectAndReturn(
466 metadataRepository.getMetadataFacet( INTERNAL, RepositoryProblemFacet.FACET_ID, problem1.getName() ),
468 metadataRepositoryControl.expectAndReturn(
469 metadataRepository.getMetadataFacet( INTERNAL, RepositoryProblemFacet.FACET_ID, problem2.getName() ),
471 metadataRepositoryControl.replay();
473 action.setRepositoryId( INTERNAL );
475 prepareAction( Collections.<String>emptyList(), Arrays.asList( SNAPSHOTS, INTERNAL ) );
477 String result = action.execute();
478 assertSuccessResult( result );
480 assertEquals( Collections.singleton( INTERNAL ), action.getRepositoriesMap().keySet() );
481 assertEquals( Arrays.asList( problem1, problem2 ), action.getRepositoriesMap().get( INTERNAL ) );
483 metadataRepositoryControl.verify();
486 public void testHealthReportInvalidRowCount()
489 metadataRepositoryControl.replay();
491 action.setRowCount( 0 );
492 action.setRepositoryId( INTERNAL );
494 prepareAction( Collections.<String>emptyList(), Arrays.asList( SNAPSHOTS, INTERNAL ) );
496 String result = action.execute();
497 assertEquals( Action.INPUT, result );
498 assertFalse( action.hasActionErrors() );
499 assertTrue( action.hasFieldErrors() );
501 metadataRepositoryControl.verify();
504 public void testHealthReportAllRepos()
507 RepositoryProblemFacet problem1 = createProblem( GROUP_ID, "artifactId", INTERNAL );
508 RepositoryProblemFacet problem2 = createProblem( GROUP_ID, "artifactId-2", SNAPSHOTS );
509 metadataRepositoryControl.expectAndReturn(
510 metadataRepository.getMetadataFacets( INTERNAL, RepositoryProblemFacet.FACET_ID ),
511 Arrays.asList( problem1.getName() ) );
512 metadataRepositoryControl.expectAndReturn(
513 metadataRepository.getMetadataFacets( SNAPSHOTS, RepositoryProblemFacet.FACET_ID ),
514 Arrays.asList( problem2.getName() ) );
515 metadataRepositoryControl.expectAndReturn(
516 metadataRepository.getMetadataFacet( INTERNAL, RepositoryProblemFacet.FACET_ID, problem1.getName() ),
518 metadataRepositoryControl.expectAndReturn(
519 metadataRepository.getMetadataFacet( SNAPSHOTS, RepositoryProblemFacet.FACET_ID, problem2.getName() ),
521 metadataRepositoryControl.replay();
523 action.setRepositoryId( GenerateReportAction.ALL_REPOSITORIES );
525 prepareAction( Collections.<String>emptyList(), Arrays.asList( SNAPSHOTS, INTERNAL ) );
527 String result = action.execute();
528 assertSuccessResult( result );
530 assertEquals( Arrays.asList( INTERNAL, SNAPSHOTS ),
531 new ArrayList<String>( action.getRepositoriesMap().keySet() ) );
532 assertEquals( Arrays.asList( problem1 ), action.getRepositoriesMap().get( INTERNAL ) );
533 assertEquals( Arrays.asList( problem2 ), action.getRepositoriesMap().get( SNAPSHOTS ) );
535 metadataRepositoryControl.verify();
538 public void testHealthReportSingleRepoByCorrectGroupId()
541 RepositoryProblemFacet problem1 = createProblem( GROUP_ID, "artifactId", INTERNAL );
542 RepositoryProblemFacet problem2 = createProblem( GROUP_ID, "artifactId-2", INTERNAL );
543 metadataRepositoryControl.expectAndReturn(
544 metadataRepository.getMetadataFacets( INTERNAL, RepositoryProblemFacet.FACET_ID ),
545 Arrays.asList( problem1.getName(), problem2.getName() ) );
546 metadataRepositoryControl.expectAndReturn(
547 metadataRepository.getMetadataFacet( INTERNAL, RepositoryProblemFacet.FACET_ID, problem1.getName() ),
549 metadataRepositoryControl.expectAndReturn(
550 metadataRepository.getMetadataFacet( INTERNAL, RepositoryProblemFacet.FACET_ID, problem2.getName() ),
552 metadataRepositoryControl.replay();
554 action.setGroupId( GROUP_ID );
555 action.setRepositoryId( INTERNAL );
557 prepareAction( Collections.<String>emptyList(), Arrays.asList( SNAPSHOTS, INTERNAL ) );
559 String result = action.execute();
560 assertSuccessResult( result );
562 assertEquals( Collections.singleton( INTERNAL ), action.getRepositoriesMap().keySet() );
563 assertEquals( Arrays.asList( problem1, problem2 ), action.getRepositoriesMap().get( INTERNAL ) );
565 metadataRepositoryControl.verify();
568 public void testHealthReportSingleRepoByCorrectGroupIdAllRepositories()
571 RepositoryProblemFacet problem1 = createProblem( GROUP_ID, "artifactId", INTERNAL );
572 RepositoryProblemFacet problem2 = createProblem( GROUP_ID, "artifactId-2", SNAPSHOTS );
573 metadataRepositoryControl.expectAndReturn(
574 metadataRepository.getMetadataFacets( INTERNAL, RepositoryProblemFacet.FACET_ID ),
575 Arrays.asList( problem1.getName() ) );
576 metadataRepositoryControl.expectAndReturn(
577 metadataRepository.getMetadataFacets( SNAPSHOTS, RepositoryProblemFacet.FACET_ID ),
578 Arrays.asList( problem2.getName() ) );
579 metadataRepositoryControl.expectAndReturn(
580 metadataRepository.getMetadataFacet( INTERNAL, RepositoryProblemFacet.FACET_ID, problem1.getName() ),
582 metadataRepositoryControl.expectAndReturn(
583 metadataRepository.getMetadataFacet( SNAPSHOTS, RepositoryProblemFacet.FACET_ID, problem2.getName() ),
585 metadataRepositoryControl.replay();
587 action.setGroupId( GROUP_ID );
588 action.setRepositoryId( GenerateReportAction.ALL_REPOSITORIES );
590 prepareAction( Collections.<String>emptyList(), Arrays.asList( SNAPSHOTS, INTERNAL ) );
592 String result = action.execute();
593 assertSuccessResult( result );
595 assertEquals( Arrays.asList( INTERNAL, SNAPSHOTS ),
596 new ArrayList<String>( action.getRepositoriesMap().keySet() ) );
597 assertEquals( Arrays.asList( problem1 ), action.getRepositoriesMap().get( INTERNAL ) );
598 assertEquals( Arrays.asList( problem2 ), action.getRepositoriesMap().get( SNAPSHOTS ) );
600 metadataRepositoryControl.verify();
603 public void testHealthReportSingleRepoByIncorrectGroupId()
606 metadataRepositoryControl.expectAndReturn(
607 metadataRepository.getMetadataFacets( INTERNAL, RepositoryProblemFacet.FACET_ID ),
608 Collections.<MetadataFacet>emptyList() );
609 metadataRepositoryControl.replay();
611 action.setGroupId( "not.it" );
612 action.setRepositoryId( INTERNAL );
614 prepareAction( Collections.<String>emptyList(), Arrays.asList( SNAPSHOTS, INTERNAL ) );
616 String result = action.execute();
617 assertEquals( GenerateReportAction.BLANK, result );
618 assertFalse( action.hasActionErrors() );
619 assertFalse( action.hasFieldErrors() );
621 metadataRepositoryControl.verify();
624 private void assertMultiRepoCsvResult()
628 "Repository,Total File Count,Total Size,Artifact Count,Group Count,Project Count,Plugins,Archetypes,Jars,Wars\n"
629 + "snapshots,0,0,0,0,0,0,0,0,0\n" + "internal,0,0,0,0,0,0,0,0,0\n",
630 IOUtils.toString( action.getInputStream() ) );
633 private RepositoryProblemFacet createProblem( String groupId, String artifactId, String repoId )
635 RepositoryProblemFacet problem = new RepositoryProblemFacet();
636 problem.setRepositoryId( repoId );
637 problem.setNamespace( groupId );
638 problem.setProject( artifactId );
639 problem.setProblem( PROBLEM );
643 public void testHealthReportNoRepositoryId()
646 prepareAction( Collections.<String>emptyList(), Arrays.asList( SNAPSHOTS, INTERNAL ) );
648 String result = action.execute();
649 assertEquals( Action.INPUT, result );
650 assertTrue( action.hasFieldErrors() );
653 private void assertSuccessResult( String result )
655 assertEquals( Action.SUCCESS, result );
656 assertFalse( action.hasActionErrors() );
657 assertFalse( action.hasFieldErrors() );
660 private RepositoryStatistics createDefaultStats()
662 return createStats( new Date() );
665 private RepositoryStatistics createStats( Date date )
667 RepositoryStatistics stats = new RepositoryStatistics();
668 stats.setScanStartTime( date );