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.webtest.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;
47 import org.junit.Test;
49 import static org.mockito.Mockito.mock;
50 import static org.mockito.Mockito.when;
53 * Test the GenerationReportAction. Note that we are testing for <i>current</i> behaviour, however there are several
54 * instances below where other behaviour may actually be more appropriate (eg the error handling, download stats should
55 * never forward to HTML page, etc). This is also missing tests for various combinations of paging at this point.
57 public class GenerateReportActionTest
58 extends AbstractActionTestCase
60 private GenerateReportAction action;
62 private static final String SNAPSHOTS = "snapshots";
64 private static final String INTERNAL = "internal";
66 private static final String GROUP_ID = "groupId";
68 private RepositoryStatisticsManager repositoryStatisticsManager;
70 private MockControl repositoryStatisticsManagerControl;
72 private MockControl metadataRepositoryControl;
74 private MetadataRepository metadataRepository;
76 private static final String PROBLEM = "problem";
85 UserRepositoriesStub stub = applicationContext.getBean( "userRepositories", UserRepositoriesStub.class );
86 stub.setRepoIds( Lists.<String>newArrayList( "internal", "snapshots" ) );
88 action = (GenerateReportAction) getActionProxy( "/report/generateReport.action" ).getAction();
90 repositoryStatisticsManagerControl = MockControl.createControl( RepositoryStatisticsManager.class );
91 repositoryStatisticsManager = (RepositoryStatisticsManager) repositoryStatisticsManagerControl.getMock();
92 action.setRepositoryStatisticsManager( repositoryStatisticsManager );
94 metadataRepositoryControl = MockControl.createControl( MetadataRepository.class );
95 metadataRepository = (MetadataRepository) metadataRepositoryControl.getMock();
97 RepositorySession repositorySession = mock( RepositorySession.class );
98 when( repositorySession.getRepository() ).thenReturn( metadataRepository );
100 TestRepositorySessionFactory factory =
101 applicationContext.getBean( "repositorySessionFactory#test", TestRepositorySessionFactory.class );
102 factory.setRepositorySession( repositorySession );
108 public void tearDown()
111 UserRepositoriesStub stub = applicationContext.getBean( "userRepositories", UserRepositoriesStub.class );
112 stub.setRepoIds( Lists.<String>newArrayList( "test-repo" ) );
118 private void prepareAction( List<String> selectedRepositories, List<String> availableRepositories )
121 MockControl managedRepositoryControl = MockControl.createControl( ManagedRepositoryAdmin.class );
122 ManagedRepositoryAdmin managedRepositoryAdmin = (ManagedRepositoryAdmin) managedRepositoryControl.getMock();
124 Map<String, ManagedRepository> map = new HashMap<String, ManagedRepository>( availableRepositories.size() );
125 for ( String repoId : availableRepositories )
127 map.put( repoId, new ManagedRepository() );
130 managedRepositoryControl.expectAndReturn( managedRepositoryAdmin.getManagedRepositoriesAsMap(), map, 1, 10 );
132 managedRepositoryControl.replay();
133 action.setManagedRepositoryAdmin( managedRepositoryAdmin );
136 action.setSelectedRepositories( selectedRepositories );
139 List<String> repos = Arrays.asList( GenerateReportAction.ALL_REPOSITORIES, INTERNAL, SNAPSHOTS );
141 Collections.sort( repos );
143 Collections.sort( action.getRepositoryIds() );
145 assertEquals( repos, action.getRepositoryIds() );
146 Collections.sort( action.getAvailableRepositories() );
148 availableRepositories = new ArrayList<String>( availableRepositories );
149 Collections.sort( availableRepositories );
152 assertEquals( availableRepositories, action.getAvailableRepositories() );
156 public void testGenerateStatisticsInvalidRowCount()
159 repositoryStatisticsManagerControl.replay();
160 prepareAction( Collections.singletonList( INTERNAL ), Collections.singletonList( SNAPSHOTS ) );
162 action.setRowCount( 0 );
163 String result = action.generateStatistics();
164 assertEquals( Action.INPUT, result );
165 assertTrue( action.hasFieldErrors() );
166 repositoryStatisticsManagerControl.verify();
170 public void testGenerateStatisticsInvalidEndDate()
173 repositoryStatisticsManagerControl.replay();
174 prepareAction( Collections.singletonList( INTERNAL ), Collections.singletonList( SNAPSHOTS ) );
176 action.setStartDate( "2009/12/12" );
177 action.setEndDate( "2008/11/11" );
178 String result = action.generateStatistics();
179 assertEquals( Action.INPUT, result );
180 assertTrue( action.hasFieldErrors() );
181 repositoryStatisticsManagerControl.verify();
185 public void testGenerateStatisticsMalformedEndDate()
188 repositoryStatisticsManagerControl.replay();
189 prepareAction( Collections.singletonList( INTERNAL ), Collections.singletonList( SNAPSHOTS ) );
191 action.setEndDate( "This is not a date" );
192 String result = action.generateStatistics();
194 // TODO: should be an input error
195 assertEquals( Action.ERROR, result );
196 assertTrue( action.hasActionErrors() );
197 repositoryStatisticsManagerControl.verify();
201 public void testGenerateStatisticsInvalidEndDateMultiRepo()
204 repositoryStatisticsManagerControl.replay();
205 prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() );
207 action.setStartDate( "2009/12/12" );
208 action.setEndDate( "2008/11/11" );
209 String result = action.generateStatistics();
210 assertEquals( Action.INPUT, result );
211 assertTrue( action.hasFieldErrors() );
212 repositoryStatisticsManagerControl.verify();
216 public void testGenerateStatisticsMalformedEndDateMultiRepo()
219 repositoryStatisticsManagerControl.replay();
220 prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() );
222 action.setEndDate( "This is not a date" );
223 String result = action.generateStatistics();
225 // TODO: should be an input error
226 assertEquals( Action.ERROR, result );
227 assertTrue( action.hasActionErrors() );
228 repositoryStatisticsManagerControl.verify();
232 public void testGenerateStatisticsNoRepos()
235 repositoryStatisticsManagerControl.replay();
236 prepareAction( Collections.<String>emptyList(), Arrays.asList( SNAPSHOTS, INTERNAL ) );
238 String result = action.generateStatistics();
239 assertEquals( Action.INPUT, result );
240 assertTrue( action.hasFieldErrors() );
241 repositoryStatisticsManagerControl.verify();
245 public void testGenerateStatisticsSingleRepo()
248 repositoryStatisticsManagerControl.expectAndReturn(
249 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, INTERNAL, null, null ),
250 Collections.singletonList( createDefaultStats() ) );
252 repositoryStatisticsManagerControl.replay();
253 prepareAction( Collections.singletonList( INTERNAL ), Collections.singletonList( SNAPSHOTS ) );
255 String result = action.generateStatistics();
256 assertSuccessResult( result );
257 repositoryStatisticsManagerControl.verify();
261 public void testGenerateStatisticsSingleRepoNoStats()
265 repositoryStatisticsManagerControl.expectAndReturn(
266 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, INTERNAL, null, null ),
267 Collections.<Object>emptyList() );
268 repositoryStatisticsManagerControl.replay();
269 prepareAction( Collections.singletonList( INTERNAL ), Collections.singletonList( SNAPSHOTS ) );
271 String result = action.generateStatistics();
272 assertEquals( Action.ERROR, result );
273 assertTrue( action.hasActionErrors() );
275 repositoryStatisticsManagerControl.verify();
279 public void testGenerateStatisticsOvershotPages()
283 repositoryStatisticsManagerControl.expectAndReturn(
284 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, INTERNAL, null, null ),
285 Collections.singletonList( createDefaultStats() ) );
286 repositoryStatisticsManagerControl.replay();
288 prepareAction( Collections.singletonList( INTERNAL ), Collections.singletonList( SNAPSHOTS ) );
290 String result = action.generateStatistics();
291 assertEquals( Action.ERROR, result );
292 assertTrue( action.hasActionErrors() );
293 repositoryStatisticsManagerControl.verify();
297 public void testGenerateStatisticsMultipleRepoNoResults()
301 repositoryStatisticsManagerControl.expectAndReturn(
302 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, SNAPSHOTS, null, null ),
303 Collections.<Object>emptyList() );
304 repositoryStatisticsManagerControl.expectAndReturn(
305 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, INTERNAL, null, null ),
306 Collections.<Object>emptyList() );
307 repositoryStatisticsManagerControl.replay();
308 prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() );
310 String result = action.generateStatistics();
311 assertEquals( GenerateReportAction.BLANK, result );
312 assertFalse( action.hasActionErrors() );
313 assertFalse( action.hasActionMessages() );
314 assertFalse( action.hasFieldErrors() );
316 repositoryStatisticsManagerControl.verify();
320 public void testGenerateStatisticsMultipleRepo()
324 repositoryStatisticsManagerControl.expectAndReturn(
325 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, SNAPSHOTS, null, null ),
326 Collections.singletonList( createDefaultStats() ) );
327 repositoryStatisticsManagerControl.expectAndReturn(
328 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, INTERNAL, null, null ),
329 Collections.singletonList( createDefaultStats() ) );
331 repositoryStatisticsManagerControl.replay();
332 prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() );
334 String result = action.generateStatistics();
335 assertSuccessResult( result );
336 repositoryStatisticsManagerControl.verify();
340 public void testDownloadStatisticsSingleRepo()
343 Date date = new Date();
344 repositoryStatisticsManagerControl.expectAndReturn(
345 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, SNAPSHOTS, null, null ),
346 Collections.singletonList( createStats( date ) ) );
347 repositoryStatisticsManagerControl.replay();
349 prepareAction( Arrays.asList( SNAPSHOTS ), Arrays.asList( INTERNAL ) );
351 String result = action.downloadStatisticsReport();
352 assertEquals( GenerateReportAction.SEND_FILE, result );
353 assertFalse( action.hasActionErrors() );
354 assertFalse( action.hasFieldErrors() );
357 "Date of Scan,Total File Count,Total Size,Artifact Count,Group Count,Project Count,Plugins,Archetypes,Jars,Wars\n"
358 + date + ",0,0,0,0,0,0,0,0,0\n", IOUtils.toString( action.getInputStream() ) );
359 repositoryStatisticsManagerControl.verify();
363 public void testDownloadStatisticsMultipleRepos()
366 repositoryStatisticsManagerControl.expectAndReturn(
367 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, SNAPSHOTS, null, null ),
368 Collections.singletonList( createDefaultStats() ) );
369 repositoryStatisticsManagerControl.expectAndReturn(
370 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, INTERNAL, null, null ),
371 Collections.singletonList( createDefaultStats() ) );
372 repositoryStatisticsManagerControl.replay();
373 prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() );
375 String result = action.downloadStatisticsReport();
376 assertEquals( GenerateReportAction.SEND_FILE, result );
377 assertFalse( action.hasActionErrors() );
378 assertFalse( action.hasFieldErrors() );
380 assertMultiRepoCsvResult();
381 repositoryStatisticsManagerControl.verify();
385 public void testDownloadStatisticsMalformedEndDateMultiRepo()
388 repositoryStatisticsManagerControl.replay();
389 prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() );
391 action.setEndDate( "This is not a date" );
392 String result = action.downloadStatisticsReport();
394 // TODO: should be an input error
395 assertEquals( Action.ERROR, result );
396 assertTrue( action.hasActionErrors() );
397 repositoryStatisticsManagerControl.verify();
401 public void testDownloadStatisticsMalformedEndDateSingleRepo()
404 repositoryStatisticsManagerControl.replay();
405 prepareAction( Arrays.asList( SNAPSHOTS ), Arrays.asList( INTERNAL ) );
407 action.setEndDate( "This is not a date" );
408 String result = action.downloadStatisticsReport();
410 // TODO: should be an input error
411 assertEquals( Action.ERROR, result );
412 assertTrue( action.hasActionErrors() );
413 repositoryStatisticsManagerControl.verify();
417 public void testDownloadStatisticsInvalidEndDateMultiRepo()
420 repositoryStatisticsManagerControl.replay();
421 prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() );
423 action.setStartDate( "2009/12/12" );
424 action.setEndDate( "2008/11/11" );
425 String result = action.downloadStatisticsReport();
426 assertEquals( Action.INPUT, result );
427 assertTrue( action.hasFieldErrors() );
428 repositoryStatisticsManagerControl.verify();
432 public void testDownloadStatisticsInvalidEndDateSingleRepo()
435 repositoryStatisticsManagerControl.replay();
436 prepareAction( Arrays.asList( SNAPSHOTS ), Arrays.asList( INTERNAL ) );
438 action.setStartDate( "2009/12/12" );
439 action.setEndDate( "2008/11/11" );
440 String result = action.downloadStatisticsReport();
441 assertEquals( Action.INPUT, result );
442 assertTrue( action.hasFieldErrors() );
443 repositoryStatisticsManagerControl.verify();
447 public void testDownloadStatisticsSingleRepoNoStats()
451 repositoryStatisticsManagerControl.expectAndReturn(
452 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, INTERNAL, null, null ),
453 Collections.<Object>emptyList() );
454 repositoryStatisticsManagerControl.replay();
455 prepareAction( Collections.singletonList( INTERNAL ), Collections.singletonList( SNAPSHOTS ) );
457 String result = action.downloadStatisticsReport();
458 assertEquals( Action.ERROR, result );
459 assertTrue( action.hasActionErrors() );
460 repositoryStatisticsManagerControl.verify();
464 public void testDownloadStatisticsNoRepos()
467 repositoryStatisticsManagerControl.replay();
468 prepareAction( Collections.<String>emptyList(), Arrays.asList( SNAPSHOTS, INTERNAL ) );
470 String result = action.downloadStatisticsReport();
471 assertEquals( Action.INPUT, result );
472 assertTrue( action.hasFieldErrors() );
473 repositoryStatisticsManagerControl.verify();
477 public void testDownloadStatisticsMultipleRepoNoResults()
481 repositoryStatisticsManagerControl.expectAndReturn(
482 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, SNAPSHOTS, null, null ),
483 Collections.<Object>emptyList() );
484 repositoryStatisticsManagerControl.expectAndReturn(
485 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, INTERNAL, null, null ),
486 Collections.<Object>emptyList() );
487 repositoryStatisticsManagerControl.replay();
488 prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() );
490 String result = action.downloadStatisticsReport();
491 assertEquals( GenerateReportAction.BLANK, result );
492 assertFalse( action.hasActionErrors() );
493 assertFalse( action.hasActionMessages() );
494 assertFalse( action.hasFieldErrors() );
495 repositoryStatisticsManagerControl.verify();
499 public void testDownloadStatisticsMultipleRepoInStrutsFormat()
502 repositoryStatisticsManagerControl.expectAndReturn(
503 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, SNAPSHOTS, null, null ),
504 Collections.singletonList( createDefaultStats() ) );
505 repositoryStatisticsManagerControl.expectAndReturn(
506 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, INTERNAL, null, null ),
507 Collections.singletonList( createDefaultStats() ) );
508 repositoryStatisticsManagerControl.replay();
509 prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() );
511 action.setSelectedRepositories( Collections.singletonList( "[" + SNAPSHOTS + "],[" + INTERNAL + "]" ) );
512 String result = action.downloadStatisticsReport();
513 assertEquals( GenerateReportAction.SEND_FILE, result );
514 assertFalse( action.hasActionErrors() );
515 assertFalse( action.hasFieldErrors() );
517 assertMultiRepoCsvResult();
518 repositoryStatisticsManagerControl.verify();
522 public void testHealthReportSingleRepo()
525 RepositoryProblemFacet problem1 = createProblem( GROUP_ID, "artifactId", INTERNAL );
526 RepositoryProblemFacet problem2 = createProblem( GROUP_ID, "artifactId-2", INTERNAL );
528 metadataRepositoryControl.expectAndReturn(
529 metadataRepository.getMetadataFacets( INTERNAL, RepositoryProblemFacet.FACET_ID ),
530 Arrays.asList( problem1.getName(), problem2.getName() ) );
531 metadataRepositoryControl.expectAndReturn(
532 metadataRepository.getMetadataFacet( INTERNAL, RepositoryProblemFacet.FACET_ID, problem1.getName() ),
534 metadataRepositoryControl.expectAndReturn(
535 metadataRepository.getMetadataFacet( INTERNAL, RepositoryProblemFacet.FACET_ID, problem2.getName() ),
537 metadataRepositoryControl.replay();
539 action.setRepositoryId( INTERNAL );
541 prepareAction( Collections.<String>emptyList(), Arrays.asList( SNAPSHOTS, INTERNAL ) );
543 String result = action.execute();
544 assertSuccessResult( result );
546 assertEquals( Collections.singleton( INTERNAL ), action.getRepositoriesMap().keySet() );
547 assertEquals( Arrays.asList( problem1, problem2 ), action.getRepositoriesMap().get( INTERNAL ) );
549 metadataRepositoryControl.verify();
553 public void testHealthReportInvalidRowCount()
556 metadataRepositoryControl.replay();
558 action.setRowCount( 0 );
559 action.setRepositoryId( INTERNAL );
561 prepareAction( Collections.<String>emptyList(), Arrays.asList( SNAPSHOTS, INTERNAL ) );
563 String result = action.execute();
564 assertEquals( Action.INPUT, result );
565 assertFalse( action.hasActionErrors() );
566 assertTrue( action.hasFieldErrors() );
568 metadataRepositoryControl.verify();
572 public void testHealthReportAllRepos()
575 RepositoryProblemFacet problem1 = createProblem( GROUP_ID, "artifactId", INTERNAL );
576 RepositoryProblemFacet problem2 = createProblem( GROUP_ID, "artifactId-2", SNAPSHOTS );
577 metadataRepositoryControl.expectAndReturn(
578 metadataRepository.getMetadataFacets( INTERNAL, RepositoryProblemFacet.FACET_ID ),
579 Arrays.asList( problem1.getName() ) );
580 metadataRepositoryControl.expectAndReturn(
581 metadataRepository.getMetadataFacets( SNAPSHOTS, RepositoryProblemFacet.FACET_ID ),
582 Arrays.asList( problem2.getName() ) );
583 metadataRepositoryControl.expectAndReturn(
584 metadataRepository.getMetadataFacet( INTERNAL, RepositoryProblemFacet.FACET_ID, problem1.getName() ),
586 metadataRepositoryControl.expectAndReturn(
587 metadataRepository.getMetadataFacet( SNAPSHOTS, RepositoryProblemFacet.FACET_ID, problem2.getName() ),
589 metadataRepositoryControl.replay();
591 action.setRepositoryId( GenerateReportAction.ALL_REPOSITORIES );
593 prepareAction( Collections.<String>emptyList(), Arrays.asList( SNAPSHOTS, INTERNAL ) );
595 String result = action.execute();
596 assertSuccessResult( result );
598 assertEquals( Arrays.asList( INTERNAL, SNAPSHOTS ),
599 new ArrayList<String>( action.getRepositoriesMap().keySet() ) );
600 assertEquals( Arrays.asList( problem1 ), action.getRepositoriesMap().get( INTERNAL ) );
601 assertEquals( Arrays.asList( problem2 ), action.getRepositoriesMap().get( SNAPSHOTS ) );
603 metadataRepositoryControl.verify();
607 public void testHealthReportSingleRepoByCorrectGroupId()
610 RepositoryProblemFacet problem1 = createProblem( GROUP_ID, "artifactId", INTERNAL );
611 RepositoryProblemFacet problem2 = createProblem( GROUP_ID, "artifactId-2", INTERNAL );
612 metadataRepositoryControl.expectAndReturn(
613 metadataRepository.getMetadataFacets( INTERNAL, RepositoryProblemFacet.FACET_ID ),
614 Arrays.asList( problem1.getName(), problem2.getName() ) );
615 metadataRepositoryControl.expectAndReturn(
616 metadataRepository.getMetadataFacet( INTERNAL, RepositoryProblemFacet.FACET_ID, problem1.getName() ),
618 metadataRepositoryControl.expectAndReturn(
619 metadataRepository.getMetadataFacet( INTERNAL, RepositoryProblemFacet.FACET_ID, problem2.getName() ),
621 metadataRepositoryControl.replay();
623 action.setGroupId( GROUP_ID );
624 action.setRepositoryId( INTERNAL );
626 prepareAction( Collections.<String>emptyList(), Arrays.asList( SNAPSHOTS, INTERNAL ) );
628 String result = action.execute();
629 assertSuccessResult( result );
631 assertEquals( Collections.singleton( INTERNAL ), action.getRepositoriesMap().keySet() );
632 assertEquals( Arrays.asList( problem1, problem2 ), action.getRepositoriesMap().get( INTERNAL ) );
634 metadataRepositoryControl.verify();
638 public void testHealthReportSingleRepoByCorrectGroupIdAllRepositories()
641 RepositoryProblemFacet problem1 = createProblem( GROUP_ID, "artifactId", INTERNAL );
642 RepositoryProblemFacet problem2 = createProblem( GROUP_ID, "artifactId-2", SNAPSHOTS );
643 metadataRepositoryControl.expectAndReturn(
644 metadataRepository.getMetadataFacets( INTERNAL, RepositoryProblemFacet.FACET_ID ),
645 Arrays.asList( problem1.getName() ) );
646 metadataRepositoryControl.expectAndReturn(
647 metadataRepository.getMetadataFacets( SNAPSHOTS, RepositoryProblemFacet.FACET_ID ),
648 Arrays.asList( problem2.getName() ) );
649 metadataRepositoryControl.expectAndReturn(
650 metadataRepository.getMetadataFacet( INTERNAL, RepositoryProblemFacet.FACET_ID, problem1.getName() ),
652 metadataRepositoryControl.expectAndReturn(
653 metadataRepository.getMetadataFacet( SNAPSHOTS, RepositoryProblemFacet.FACET_ID, problem2.getName() ),
655 metadataRepositoryControl.replay();
657 action.setGroupId( GROUP_ID );
658 action.setRepositoryId( GenerateReportAction.ALL_REPOSITORIES );
660 prepareAction( Collections.<String>emptyList(), Arrays.asList( SNAPSHOTS, INTERNAL ) );
662 String result = action.execute();
663 assertSuccessResult( result );
665 assertEquals( Arrays.asList( INTERNAL, SNAPSHOTS ),
666 new ArrayList<String>( action.getRepositoriesMap().keySet() ) );
667 assertEquals( Arrays.asList( problem1 ), action.getRepositoriesMap().get( INTERNAL ) );
668 assertEquals( Arrays.asList( problem2 ), action.getRepositoriesMap().get( SNAPSHOTS ) );
670 metadataRepositoryControl.verify();
674 public void testHealthReportSingleRepoByIncorrectGroupId()
677 metadataRepositoryControl.expectAndReturn(
678 metadataRepository.getMetadataFacets( INTERNAL, RepositoryProblemFacet.FACET_ID ),
679 Collections.<MetadataFacet>emptyList() );
680 metadataRepositoryControl.replay();
682 action.setGroupId( "not.it" );
683 action.setRepositoryId( INTERNAL );
685 prepareAction( Collections.<String>emptyList(), Arrays.asList( SNAPSHOTS, INTERNAL ) );
687 String result = action.execute();
688 assertEquals( GenerateReportAction.BLANK, result );
689 assertFalse( action.hasActionErrors() );
690 assertFalse( action.hasFieldErrors() );
692 metadataRepositoryControl.verify();
695 private void assertMultiRepoCsvResult()
699 "Repository,Total File Count,Total Size,Artifact Count,Group Count,Project Count,Plugins,Archetypes,Jars,Wars\n"
700 + "snapshots,0,0,0,0,0,0,0,0,0\n" + "internal,0,0,0,0,0,0,0,0,0\n",
701 IOUtils.toString( action.getInputStream() ) );
704 private RepositoryProblemFacet createProblem( String groupId, String artifactId, String repoId )
706 RepositoryProblemFacet problem = new RepositoryProblemFacet();
707 problem.setRepositoryId( repoId );
708 problem.setNamespace( groupId );
709 problem.setProject( artifactId );
710 problem.setProblem( PROBLEM );
715 public void testHealthReportNoRepositoryId()
718 prepareAction( Collections.<String>emptyList(), Arrays.asList( SNAPSHOTS, INTERNAL ) );
720 String result = action.execute();
721 assertEquals( Action.INPUT, result );
722 assertTrue( action.hasFieldErrors() );
725 private void assertSuccessResult( String result )
727 assertEquals( Action.SUCCESS, result );
728 assertFalse( action.hasActionErrors() );
729 assertFalse( action.hasFieldErrors() );
732 private RepositoryStatistics createDefaultStats()
734 return createStats( new Date() );
737 private RepositoryStatistics createStats( Date date )
739 RepositoryStatistics stats = new RepositoryStatistics();
740 stats.setScanStartTime( date );