1 package org.apache.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.admin.model.beans.ManagedRepository;
25 import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
26 import org.apache.archiva.metadata.model.MetadataFacet;
27 import org.apache.archiva.metadata.repository.MetadataRepository;
28 import org.apache.archiva.metadata.repository.RepositorySession;
29 import org.apache.archiva.metadata.repository.memory.TestRepositorySessionFactory;
30 import org.apache.archiva.metadata.repository.stats.RepositoryStatistics;
31 import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager;
32 import org.apache.archiva.reports.RepositoryProblemFacet;
33 import org.apache.archiva.security.UserRepositoriesStub;
34 import org.apache.commons.io.IOUtils;
35 import org.apache.archiva.web.action.AbstractActionTestCase;
36 import org.easymock.MockControl;
37 import org.junit.After;
39 import java.io.IOException;
40 import java.util.ArrayList;
41 import java.util.Arrays;
42 import java.util.Collections;
43 import java.util.Date;
44 import java.util.HashMap;
45 import java.util.List;
48 import static org.mockito.Mockito.mock;
49 import static org.mockito.Mockito.when;
52 * Test the GenerationReportAction. Note that we are testing for <i>current</i> behaviour, however there are several
53 * instances below where other behaviour may actually be more appropriate (eg the error handling, download stats should
54 * never forward to HTML page, etc). This is also missing tests for various combinations of paging at this point.
56 public class GenerateReportActionTest
57 extends AbstractActionTestCase
59 private GenerateReportAction action;
61 private static final String SNAPSHOTS = "snapshots";
63 private static final String INTERNAL = "internal";
65 private static final String GROUP_ID = "groupId";
67 private RepositoryStatisticsManager repositoryStatisticsManager;
69 private MockControl repositoryStatisticsManagerControl;
71 private MockControl metadataRepositoryControl;
73 private MetadataRepository metadataRepository;
75 private static final String PROBLEM = "problem";
79 protected void setUp()
84 UserRepositoriesStub stub = applicationContext.getBean( "userRepositories", UserRepositoriesStub.class );
85 stub.setRepoIds( Lists.<String>newArrayList( "internal", "snapshots" ) );
87 action = (GenerateReportAction) getActionProxy( "/report/generateReport.action" ).getAction();
89 repositoryStatisticsManagerControl = MockControl.createControl( RepositoryStatisticsManager.class );
90 repositoryStatisticsManager = (RepositoryStatisticsManager) repositoryStatisticsManagerControl.getMock();
91 action.setRepositoryStatisticsManager( repositoryStatisticsManager );
93 metadataRepositoryControl = MockControl.createControl( MetadataRepository.class );
94 metadataRepository = (MetadataRepository) metadataRepositoryControl.getMock();
96 RepositorySession repositorySession = mock( RepositorySession.class );
97 when( repositorySession.getRepository() ).thenReturn( metadataRepository );
99 TestRepositorySessionFactory factory =
100 applicationContext.getBean( "repositorySessionFactory#test", TestRepositorySessionFactory.class );
101 factory.setRepositorySession( repositorySession );
105 public void tearDown()
108 UserRepositoriesStub stub = applicationContext.getBean( "userRepositories", UserRepositoriesStub.class );
109 stub.setRepoIds( Lists.<String>newArrayList( "test-repo" ) );
115 private void prepareAction( List<String> selectedRepositories, List<String> availableRepositories )
118 MockControl managedRepositoryControl = MockControl.createControl( ManagedRepositoryAdmin.class );
119 ManagedRepositoryAdmin managedRepositoryAdmin = (ManagedRepositoryAdmin) managedRepositoryControl.getMock();
121 Map<String, ManagedRepository> map = new HashMap<String, ManagedRepository>( availableRepositories.size() );
122 for ( String repoId : availableRepositories )
124 map.put( repoId, new ManagedRepository() );
127 managedRepositoryControl.expectAndReturn( managedRepositoryAdmin.getManagedRepositoriesAsMap(), map, 1, 10 );
129 managedRepositoryControl.replay();
130 action.setManagedRepositoryAdmin( managedRepositoryAdmin );
133 action.setSelectedRepositories( selectedRepositories );
136 List<String> repos = Arrays.asList( GenerateReportAction.ALL_REPOSITORIES, INTERNAL, SNAPSHOTS );
138 Collections.sort( repos );
140 Collections.sort( action.getRepositoryIds() );
142 assertEquals( repos, action.getRepositoryIds() );
143 Collections.sort( action.getAvailableRepositories() );
145 availableRepositories = new ArrayList<String>( availableRepositories );
146 Collections.sort( availableRepositories );
149 assertEquals( availableRepositories, action.getAvailableRepositories() );
152 public void testGenerateStatisticsInvalidRowCount()
155 repositoryStatisticsManagerControl.replay();
156 prepareAction( Collections.singletonList( INTERNAL ), Collections.singletonList( SNAPSHOTS ) );
158 action.setRowCount( 0 );
159 String result = action.generateStatistics();
160 assertEquals( Action.INPUT, result );
161 assertTrue( action.hasFieldErrors() );
162 repositoryStatisticsManagerControl.verify();
165 public void testGenerateStatisticsInvalidEndDate()
168 repositoryStatisticsManagerControl.replay();
169 prepareAction( Collections.singletonList( INTERNAL ), Collections.singletonList( SNAPSHOTS ) );
171 action.setStartDate( "2009/12/12" );
172 action.setEndDate( "2008/11/11" );
173 String result = action.generateStatistics();
174 assertEquals( Action.INPUT, result );
175 assertTrue( action.hasFieldErrors() );
176 repositoryStatisticsManagerControl.verify();
179 public void testGenerateStatisticsMalformedEndDate()
182 repositoryStatisticsManagerControl.replay();
183 prepareAction( Collections.singletonList( INTERNAL ), Collections.singletonList( SNAPSHOTS ) );
185 action.setEndDate( "This is not a date" );
186 String result = action.generateStatistics();
188 // TODO: should be an input error
189 assertEquals( Action.ERROR, result );
190 assertTrue( action.hasActionErrors() );
191 repositoryStatisticsManagerControl.verify();
194 public void testGenerateStatisticsInvalidEndDateMultiRepo()
197 repositoryStatisticsManagerControl.replay();
198 prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() );
200 action.setStartDate( "2009/12/12" );
201 action.setEndDate( "2008/11/11" );
202 String result = action.generateStatistics();
203 assertEquals( Action.INPUT, result );
204 assertTrue( action.hasFieldErrors() );
205 repositoryStatisticsManagerControl.verify();
208 public void testGenerateStatisticsMalformedEndDateMultiRepo()
211 repositoryStatisticsManagerControl.replay();
212 prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() );
214 action.setEndDate( "This is not a date" );
215 String result = action.generateStatistics();
217 // TODO: should be an input error
218 assertEquals( Action.ERROR, result );
219 assertTrue( action.hasActionErrors() );
220 repositoryStatisticsManagerControl.verify();
223 public void testGenerateStatisticsNoRepos()
226 repositoryStatisticsManagerControl.replay();
227 prepareAction( Collections.<String>emptyList(), Arrays.asList( SNAPSHOTS, INTERNAL ) );
229 String result = action.generateStatistics();
230 assertEquals( Action.INPUT, result );
231 assertTrue( action.hasFieldErrors() );
232 repositoryStatisticsManagerControl.verify();
235 public void testGenerateStatisticsSingleRepo()
238 repositoryStatisticsManagerControl.expectAndReturn(
239 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, INTERNAL, null, null ),
240 Collections.singletonList( createDefaultStats() ) );
242 repositoryStatisticsManagerControl.replay();
243 prepareAction( Collections.singletonList( INTERNAL ), Collections.singletonList( SNAPSHOTS ) );
245 String result = action.generateStatistics();
246 assertSuccessResult( result );
247 repositoryStatisticsManagerControl.verify();
250 public void testGenerateStatisticsSingleRepoNoStats()
254 repositoryStatisticsManagerControl.expectAndReturn(
255 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, INTERNAL, null, null ),
256 Collections.<Object>emptyList() );
257 repositoryStatisticsManagerControl.replay();
258 prepareAction( Collections.singletonList( INTERNAL ), Collections.singletonList( SNAPSHOTS ) );
260 String result = action.generateStatistics();
261 assertEquals( Action.ERROR, result );
262 assertTrue( action.hasActionErrors() );
264 repositoryStatisticsManagerControl.verify();
267 public void testGenerateStatisticsOvershotPages()
271 repositoryStatisticsManagerControl.expectAndReturn(
272 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, INTERNAL, null, null ),
273 Collections.singletonList( createDefaultStats() ) );
274 repositoryStatisticsManagerControl.replay();
276 prepareAction( Collections.singletonList( INTERNAL ), Collections.singletonList( SNAPSHOTS ) );
278 String result = action.generateStatistics();
279 assertEquals( Action.ERROR, result );
280 assertTrue( action.hasActionErrors() );
281 repositoryStatisticsManagerControl.verify();
284 public void testGenerateStatisticsMultipleRepoNoResults()
288 repositoryStatisticsManagerControl.expectAndReturn(
289 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, SNAPSHOTS, null, null ),
290 Collections.<Object>emptyList() );
291 repositoryStatisticsManagerControl.expectAndReturn(
292 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, INTERNAL, null, null ),
293 Collections.<Object>emptyList() );
294 repositoryStatisticsManagerControl.replay();
295 prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() );
297 String result = action.generateStatistics();
298 assertEquals( GenerateReportAction.BLANK, result );
299 assertFalse( action.hasActionErrors() );
300 assertFalse( action.hasActionMessages() );
301 assertFalse( action.hasFieldErrors() );
303 repositoryStatisticsManagerControl.verify();
306 public void testGenerateStatisticsMultipleRepo()
310 repositoryStatisticsManagerControl.expectAndReturn(
311 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, SNAPSHOTS, null, null ),
312 Collections.singletonList( createDefaultStats() ) );
313 repositoryStatisticsManagerControl.expectAndReturn(
314 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, INTERNAL, null, null ),
315 Collections.singletonList( createDefaultStats() ) );
317 repositoryStatisticsManagerControl.replay();
318 prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() );
320 String result = action.generateStatistics();
321 assertSuccessResult( result );
322 repositoryStatisticsManagerControl.verify();
325 public void testDownloadStatisticsSingleRepo()
328 Date date = new Date();
329 repositoryStatisticsManagerControl.expectAndReturn(
330 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, SNAPSHOTS, null, null ),
331 Collections.singletonList( createStats( date ) ) );
332 repositoryStatisticsManagerControl.replay();
334 prepareAction( Arrays.asList( SNAPSHOTS ), Arrays.asList( INTERNAL ) );
336 String result = action.downloadStatisticsReport();
337 assertEquals( GenerateReportAction.SEND_FILE, result );
338 assertFalse( action.hasActionErrors() );
339 assertFalse( action.hasFieldErrors() );
342 "Date of Scan,Total File Count,Total Size,Artifact Count,Group Count,Project Count,Plugins,Archetypes,Jars,Wars\n"
343 + date + ",0,0,0,0,0,0,0,0,0\n", IOUtils.toString( action.getInputStream() ) );
344 repositoryStatisticsManagerControl.verify();
347 public void testDownloadStatisticsMultipleRepos()
350 repositoryStatisticsManagerControl.expectAndReturn(
351 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, SNAPSHOTS, null, null ),
352 Collections.singletonList( createDefaultStats() ) );
353 repositoryStatisticsManagerControl.expectAndReturn(
354 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, INTERNAL, null, null ),
355 Collections.singletonList( createDefaultStats() ) );
356 repositoryStatisticsManagerControl.replay();
357 prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() );
359 String result = action.downloadStatisticsReport();
360 assertEquals( GenerateReportAction.SEND_FILE, result );
361 assertFalse( action.hasActionErrors() );
362 assertFalse( action.hasFieldErrors() );
364 assertMultiRepoCsvResult();
365 repositoryStatisticsManagerControl.verify();
368 public void testDownloadStatisticsMalformedEndDateMultiRepo()
371 repositoryStatisticsManagerControl.replay();
372 prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() );
374 action.setEndDate( "This is not a date" );
375 String result = action.downloadStatisticsReport();
377 // TODO: should be an input error
378 assertEquals( Action.ERROR, result );
379 assertTrue( action.hasActionErrors() );
380 repositoryStatisticsManagerControl.verify();
383 public void testDownloadStatisticsMalformedEndDateSingleRepo()
386 repositoryStatisticsManagerControl.replay();
387 prepareAction( Arrays.asList( SNAPSHOTS ), Arrays.asList( INTERNAL ) );
389 action.setEndDate( "This is not a date" );
390 String result = action.downloadStatisticsReport();
392 // TODO: should be an input error
393 assertEquals( Action.ERROR, result );
394 assertTrue( action.hasActionErrors() );
395 repositoryStatisticsManagerControl.verify();
398 public void testDownloadStatisticsInvalidEndDateMultiRepo()
401 repositoryStatisticsManagerControl.replay();
402 prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() );
404 action.setStartDate( "2009/12/12" );
405 action.setEndDate( "2008/11/11" );
406 String result = action.downloadStatisticsReport();
407 assertEquals( Action.INPUT, result );
408 assertTrue( action.hasFieldErrors() );
409 repositoryStatisticsManagerControl.verify();
412 public void testDownloadStatisticsInvalidEndDateSingleRepo()
415 repositoryStatisticsManagerControl.replay();
416 prepareAction( Arrays.asList( SNAPSHOTS ), Arrays.asList( INTERNAL ) );
418 action.setStartDate( "2009/12/12" );
419 action.setEndDate( "2008/11/11" );
420 String result = action.downloadStatisticsReport();
421 assertEquals( Action.INPUT, result );
422 assertTrue( action.hasFieldErrors() );
423 repositoryStatisticsManagerControl.verify();
426 public void testDownloadStatisticsSingleRepoNoStats()
430 repositoryStatisticsManagerControl.expectAndReturn(
431 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, INTERNAL, null, null ),
432 Collections.<Object>emptyList() );
433 repositoryStatisticsManagerControl.replay();
434 prepareAction( Collections.singletonList( INTERNAL ), Collections.singletonList( SNAPSHOTS ) );
436 String result = action.downloadStatisticsReport();
437 assertEquals( Action.ERROR, result );
438 assertTrue( action.hasActionErrors() );
439 repositoryStatisticsManagerControl.verify();
442 public void testDownloadStatisticsNoRepos()
445 repositoryStatisticsManagerControl.replay();
446 prepareAction( Collections.<String>emptyList(), Arrays.asList( SNAPSHOTS, INTERNAL ) );
448 String result = action.downloadStatisticsReport();
449 assertEquals( Action.INPUT, result );
450 assertTrue( action.hasFieldErrors() );
451 repositoryStatisticsManagerControl.verify();
454 public void testDownloadStatisticsMultipleRepoNoResults()
458 repositoryStatisticsManagerControl.expectAndReturn(
459 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, SNAPSHOTS, null, null ),
460 Collections.<Object>emptyList() );
461 repositoryStatisticsManagerControl.expectAndReturn(
462 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, INTERNAL, null, null ),
463 Collections.<Object>emptyList() );
464 repositoryStatisticsManagerControl.replay();
465 prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() );
467 String result = action.downloadStatisticsReport();
468 assertEquals( GenerateReportAction.BLANK, result );
469 assertFalse( action.hasActionErrors() );
470 assertFalse( action.hasActionMessages() );
471 assertFalse( action.hasFieldErrors() );
472 repositoryStatisticsManagerControl.verify();
475 public void testDownloadStatisticsMultipleRepoInStrutsFormat()
478 repositoryStatisticsManagerControl.expectAndReturn(
479 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, SNAPSHOTS, null, null ),
480 Collections.singletonList( createDefaultStats() ) );
481 repositoryStatisticsManagerControl.expectAndReturn(
482 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, INTERNAL, null, null ),
483 Collections.singletonList( createDefaultStats() ) );
484 repositoryStatisticsManagerControl.replay();
485 prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() );
487 action.setSelectedRepositories( Collections.singletonList( "[" + SNAPSHOTS + "],[" + INTERNAL + "]" ) );
488 String result = action.downloadStatisticsReport();
489 assertEquals( GenerateReportAction.SEND_FILE, result );
490 assertFalse( action.hasActionErrors() );
491 assertFalse( action.hasFieldErrors() );
493 assertMultiRepoCsvResult();
494 repositoryStatisticsManagerControl.verify();
497 public void testHealthReportSingleRepo()
500 RepositoryProblemFacet problem1 = createProblem( GROUP_ID, "artifactId", INTERNAL );
501 RepositoryProblemFacet problem2 = createProblem( GROUP_ID, "artifactId-2", INTERNAL );
503 metadataRepositoryControl.expectAndReturn(
504 metadataRepository.getMetadataFacets( INTERNAL, RepositoryProblemFacet.FACET_ID ),
505 Arrays.asList( problem1.getName(), problem2.getName() ) );
506 metadataRepositoryControl.expectAndReturn(
507 metadataRepository.getMetadataFacet( INTERNAL, RepositoryProblemFacet.FACET_ID, problem1.getName() ),
509 metadataRepositoryControl.expectAndReturn(
510 metadataRepository.getMetadataFacet( INTERNAL, RepositoryProblemFacet.FACET_ID, problem2.getName() ),
512 metadataRepositoryControl.replay();
514 action.setRepositoryId( INTERNAL );
516 prepareAction( Collections.<String>emptyList(), Arrays.asList( SNAPSHOTS, INTERNAL ) );
518 String result = action.execute();
519 assertSuccessResult( result );
521 assertEquals( Collections.singleton( INTERNAL ), action.getRepositoriesMap().keySet() );
522 assertEquals( Arrays.asList( problem1, problem2 ), action.getRepositoriesMap().get( INTERNAL ) );
524 metadataRepositoryControl.verify();
527 public void testHealthReportInvalidRowCount()
530 metadataRepositoryControl.replay();
532 action.setRowCount( 0 );
533 action.setRepositoryId( INTERNAL );
535 prepareAction( Collections.<String>emptyList(), Arrays.asList( SNAPSHOTS, INTERNAL ) );
537 String result = action.execute();
538 assertEquals( Action.INPUT, result );
539 assertFalse( action.hasActionErrors() );
540 assertTrue( action.hasFieldErrors() );
542 metadataRepositoryControl.verify();
545 public void testHealthReportAllRepos()
548 RepositoryProblemFacet problem1 = createProblem( GROUP_ID, "artifactId", INTERNAL );
549 RepositoryProblemFacet problem2 = createProblem( GROUP_ID, "artifactId-2", SNAPSHOTS );
550 metadataRepositoryControl.expectAndReturn(
551 metadataRepository.getMetadataFacets( INTERNAL, RepositoryProblemFacet.FACET_ID ),
552 Arrays.asList( problem1.getName() ) );
553 metadataRepositoryControl.expectAndReturn(
554 metadataRepository.getMetadataFacets( SNAPSHOTS, RepositoryProblemFacet.FACET_ID ),
555 Arrays.asList( problem2.getName() ) );
556 metadataRepositoryControl.expectAndReturn(
557 metadataRepository.getMetadataFacet( INTERNAL, RepositoryProblemFacet.FACET_ID, problem1.getName() ),
559 metadataRepositoryControl.expectAndReturn(
560 metadataRepository.getMetadataFacet( SNAPSHOTS, RepositoryProblemFacet.FACET_ID, problem2.getName() ),
562 metadataRepositoryControl.replay();
564 action.setRepositoryId( GenerateReportAction.ALL_REPOSITORIES );
566 prepareAction( Collections.<String>emptyList(), Arrays.asList( SNAPSHOTS, INTERNAL ) );
568 String result = action.execute();
569 assertSuccessResult( result );
571 assertEquals( Arrays.asList( INTERNAL, SNAPSHOTS ),
572 new ArrayList<String>( action.getRepositoriesMap().keySet() ) );
573 assertEquals( Arrays.asList( problem1 ), action.getRepositoriesMap().get( INTERNAL ) );
574 assertEquals( Arrays.asList( problem2 ), action.getRepositoriesMap().get( SNAPSHOTS ) );
576 metadataRepositoryControl.verify();
579 public void testHealthReportSingleRepoByCorrectGroupId()
582 RepositoryProblemFacet problem1 = createProblem( GROUP_ID, "artifactId", INTERNAL );
583 RepositoryProblemFacet problem2 = createProblem( GROUP_ID, "artifactId-2", INTERNAL );
584 metadataRepositoryControl.expectAndReturn(
585 metadataRepository.getMetadataFacets( INTERNAL, RepositoryProblemFacet.FACET_ID ),
586 Arrays.asList( problem1.getName(), problem2.getName() ) );
587 metadataRepositoryControl.expectAndReturn(
588 metadataRepository.getMetadataFacet( INTERNAL, RepositoryProblemFacet.FACET_ID, problem1.getName() ),
590 metadataRepositoryControl.expectAndReturn(
591 metadataRepository.getMetadataFacet( INTERNAL, RepositoryProblemFacet.FACET_ID, problem2.getName() ),
593 metadataRepositoryControl.replay();
595 action.setGroupId( GROUP_ID );
596 action.setRepositoryId( INTERNAL );
598 prepareAction( Collections.<String>emptyList(), Arrays.asList( SNAPSHOTS, INTERNAL ) );
600 String result = action.execute();
601 assertSuccessResult( result );
603 assertEquals( Collections.singleton( INTERNAL ), action.getRepositoriesMap().keySet() );
604 assertEquals( Arrays.asList( problem1, problem2 ), action.getRepositoriesMap().get( INTERNAL ) );
606 metadataRepositoryControl.verify();
609 public void testHealthReportSingleRepoByCorrectGroupIdAllRepositories()
612 RepositoryProblemFacet problem1 = createProblem( GROUP_ID, "artifactId", INTERNAL );
613 RepositoryProblemFacet problem2 = createProblem( GROUP_ID, "artifactId-2", SNAPSHOTS );
614 metadataRepositoryControl.expectAndReturn(
615 metadataRepository.getMetadataFacets( INTERNAL, RepositoryProblemFacet.FACET_ID ),
616 Arrays.asList( problem1.getName() ) );
617 metadataRepositoryControl.expectAndReturn(
618 metadataRepository.getMetadataFacets( SNAPSHOTS, RepositoryProblemFacet.FACET_ID ),
619 Arrays.asList( problem2.getName() ) );
620 metadataRepositoryControl.expectAndReturn(
621 metadataRepository.getMetadataFacet( INTERNAL, RepositoryProblemFacet.FACET_ID, problem1.getName() ),
623 metadataRepositoryControl.expectAndReturn(
624 metadataRepository.getMetadataFacet( SNAPSHOTS, RepositoryProblemFacet.FACET_ID, problem2.getName() ),
626 metadataRepositoryControl.replay();
628 action.setGroupId( GROUP_ID );
629 action.setRepositoryId( GenerateReportAction.ALL_REPOSITORIES );
631 prepareAction( Collections.<String>emptyList(), Arrays.asList( SNAPSHOTS, INTERNAL ) );
633 String result = action.execute();
634 assertSuccessResult( result );
636 assertEquals( Arrays.asList( INTERNAL, SNAPSHOTS ),
637 new ArrayList<String>( action.getRepositoriesMap().keySet() ) );
638 assertEquals( Arrays.asList( problem1 ), action.getRepositoriesMap().get( INTERNAL ) );
639 assertEquals( Arrays.asList( problem2 ), action.getRepositoriesMap().get( SNAPSHOTS ) );
641 metadataRepositoryControl.verify();
644 public void testHealthReportSingleRepoByIncorrectGroupId()
647 metadataRepositoryControl.expectAndReturn(
648 metadataRepository.getMetadataFacets( INTERNAL, RepositoryProblemFacet.FACET_ID ),
649 Collections.<MetadataFacet>emptyList() );
650 metadataRepositoryControl.replay();
652 action.setGroupId( "not.it" );
653 action.setRepositoryId( INTERNAL );
655 prepareAction( Collections.<String>emptyList(), Arrays.asList( SNAPSHOTS, INTERNAL ) );
657 String result = action.execute();
658 assertEquals( GenerateReportAction.BLANK, result );
659 assertFalse( action.hasActionErrors() );
660 assertFalse( action.hasFieldErrors() );
662 metadataRepositoryControl.verify();
665 private void assertMultiRepoCsvResult()
669 "Repository,Total File Count,Total Size,Artifact Count,Group Count,Project Count,Plugins,Archetypes,Jars,Wars\n"
670 + "snapshots,0,0,0,0,0,0,0,0,0\n" + "internal,0,0,0,0,0,0,0,0,0\n",
671 IOUtils.toString( action.getInputStream() ) );
674 private RepositoryProblemFacet createProblem( String groupId, String artifactId, String repoId )
676 RepositoryProblemFacet problem = new RepositoryProblemFacet();
677 problem.setRepositoryId( repoId );
678 problem.setNamespace( groupId );
679 problem.setProject( artifactId );
680 problem.setProblem( PROBLEM );
684 public void testHealthReportNoRepositoryId()
687 prepareAction( Collections.<String>emptyList(), Arrays.asList( SNAPSHOTS, INTERNAL ) );
689 String result = action.execute();
690 assertEquals( Action.INPUT, result );
691 assertTrue( action.hasFieldErrors() );
694 private void assertSuccessResult( String result )
696 assertEquals( Action.SUCCESS, result );
697 assertFalse( action.hasActionErrors() );
698 assertFalse( action.hasFieldErrors() );
701 private RepositoryStatistics createDefaultStats()
703 return createStats( new Date() );
706 private RepositoryStatistics createStats( Date date )
708 RepositoryStatistics stats = new RepositoryStatistics();
709 stats.setScanStartTime( date );