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.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 =
97 applicationContext.getBean( "repositorySessionFactory#test", TestRepositorySessionFactory.class );
98 factory.setRepositorySession( repositorySession );
102 public void tearDown()
105 UserRepositoriesStub stub = applicationContext.getBean( "userRepositories", UserRepositoriesStub.class );
106 stub.setRepoIds( Lists.<String>newArrayList( "test-repo" ) );
111 private void prepareAction( List<String> selectedRepositories, List<String> availableRepositories )
113 action.setSelectedRepositories( selectedRepositories );
116 assertEquals( Arrays.asList( GenerateReportAction.ALL_REPOSITORIES, INTERNAL, SNAPSHOTS ),
117 action.getRepositoryIds() );
118 assertEquals( availableRepositories, action.getAvailableRepositories() );
121 public void testGenerateStatisticsInvalidRowCount()
123 repositoryStatisticsManagerControl.replay();
124 prepareAction( Collections.singletonList( INTERNAL ), Collections.singletonList( SNAPSHOTS ) );
126 action.setRowCount( 0 );
127 String result = action.generateStatistics();
128 assertEquals( Action.INPUT, result );
129 assertTrue( action.hasFieldErrors() );
130 repositoryStatisticsManagerControl.verify();
133 public void testGenerateStatisticsInvalidEndDate()
135 repositoryStatisticsManagerControl.replay();
136 prepareAction( Collections.singletonList( INTERNAL ), Collections.singletonList( SNAPSHOTS ) );
138 action.setStartDate( "2009/12/12" );
139 action.setEndDate( "2008/11/11" );
140 String result = action.generateStatistics();
141 assertEquals( Action.INPUT, result );
142 assertTrue( action.hasFieldErrors() );
143 repositoryStatisticsManagerControl.verify();
146 public void testGenerateStatisticsMalformedEndDate()
148 repositoryStatisticsManagerControl.replay();
149 prepareAction( Collections.singletonList( INTERNAL ), Collections.singletonList( SNAPSHOTS ) );
151 action.setEndDate( "This is not a date" );
152 String result = action.generateStatistics();
154 // TODO: should be an input error
155 assertEquals( Action.ERROR, result );
156 assertTrue( action.hasActionErrors() );
157 repositoryStatisticsManagerControl.verify();
160 public void testGenerateStatisticsInvalidEndDateMultiRepo()
162 repositoryStatisticsManagerControl.replay();
163 prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() );
165 action.setStartDate( "2009/12/12" );
166 action.setEndDate( "2008/11/11" );
167 String result = action.generateStatistics();
168 assertEquals( Action.INPUT, result );
169 assertTrue( action.hasFieldErrors() );
170 repositoryStatisticsManagerControl.verify();
173 public void testGenerateStatisticsMalformedEndDateMultiRepo()
175 repositoryStatisticsManagerControl.replay();
176 prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() );
178 action.setEndDate( "This is not a date" );
179 String result = action.generateStatistics();
181 // TODO: should be an input error
182 assertEquals( Action.ERROR, result );
183 assertTrue( action.hasActionErrors() );
184 repositoryStatisticsManagerControl.verify();
187 public void testGenerateStatisticsNoRepos()
189 repositoryStatisticsManagerControl.replay();
190 prepareAction( Collections.<String>emptyList(), Arrays.asList( SNAPSHOTS, INTERNAL ) );
192 String result = action.generateStatistics();
193 assertEquals( Action.INPUT, result );
194 assertTrue( action.hasFieldErrors() );
195 repositoryStatisticsManagerControl.verify();
198 public void testGenerateStatisticsSingleRepo()
201 repositoryStatisticsManagerControl.expectAndReturn(
202 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, INTERNAL, null, null ),
203 Collections.singletonList( createDefaultStats() ) );
205 repositoryStatisticsManagerControl.replay();
206 prepareAction( Collections.singletonList( INTERNAL ), Collections.singletonList( SNAPSHOTS ) );
208 String result = action.generateStatistics();
209 assertSuccessResult( result );
210 repositoryStatisticsManagerControl.verify();
213 public void testGenerateStatisticsSingleRepoNoStats()
217 repositoryStatisticsManagerControl.expectAndReturn(
218 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, INTERNAL, null, null ),
219 Collections.<Object>emptyList() );
220 repositoryStatisticsManagerControl.replay();
221 prepareAction( Collections.singletonList( INTERNAL ), Collections.singletonList( SNAPSHOTS ) );
223 String result = action.generateStatistics();
224 assertEquals( Action.ERROR, result );
225 assertTrue( action.hasActionErrors() );
227 repositoryStatisticsManagerControl.verify();
230 public void testGenerateStatisticsOvershotPages()
234 repositoryStatisticsManagerControl.expectAndReturn(
235 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, INTERNAL, null, null ),
236 Collections.singletonList( createDefaultStats() ) );
237 repositoryStatisticsManagerControl.replay();
239 prepareAction( Collections.singletonList( INTERNAL ), Collections.singletonList( SNAPSHOTS ) );
241 String result = action.generateStatistics();
242 assertEquals( Action.ERROR, result );
243 assertTrue( action.hasActionErrors() );
244 repositoryStatisticsManagerControl.verify();
247 public void testGenerateStatisticsMultipleRepoNoResults()
251 repositoryStatisticsManagerControl.expectAndReturn(
252 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, SNAPSHOTS, null, null ),
253 Collections.<Object>emptyList() );
254 repositoryStatisticsManagerControl.expectAndReturn(
255 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, INTERNAL, null, null ),
256 Collections.<Object>emptyList() );
257 repositoryStatisticsManagerControl.replay();
258 prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() );
260 String result = action.generateStatistics();
261 assertEquals( GenerateReportAction.BLANK, result );
262 assertFalse( action.hasActionErrors() );
263 assertFalse( action.hasActionMessages() );
264 assertFalse( action.hasFieldErrors() );
266 repositoryStatisticsManagerControl.verify();
269 public void testGenerateStatisticsMultipleRepo()
273 repositoryStatisticsManagerControl.expectAndReturn(
274 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, SNAPSHOTS, null, null ),
275 Collections.singletonList( createDefaultStats() ) );
276 repositoryStatisticsManagerControl.expectAndReturn(
277 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, INTERNAL, null, null ),
278 Collections.singletonList( createDefaultStats() ) );
280 repositoryStatisticsManagerControl.replay();
281 prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() );
283 String result = action.generateStatistics();
284 assertSuccessResult( result );
285 repositoryStatisticsManagerControl.verify();
288 public void testDownloadStatisticsSingleRepo()
291 Date date = new Date();
292 repositoryStatisticsManagerControl.expectAndReturn(
293 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, SNAPSHOTS, null, null ),
294 Collections.singletonList( createStats( date ) ) );
295 repositoryStatisticsManagerControl.replay();
297 prepareAction( Arrays.asList( SNAPSHOTS ), Arrays.asList( INTERNAL ) );
299 String result = action.downloadStatisticsReport();
300 assertEquals( GenerateReportAction.SEND_FILE, result );
301 assertFalse( action.hasActionErrors() );
302 assertFalse( action.hasFieldErrors() );
305 "Date of Scan,Total File Count,Total Size,Artifact Count,Group Count,Project Count,Plugins,Archetypes,Jars,Wars\n"
306 + date + ",0,0,0,0,0,0,0,0,0\n", IOUtils.toString( action.getInputStream() ) );
307 repositoryStatisticsManagerControl.verify();
310 public void testDownloadStatisticsMultipleRepos()
313 repositoryStatisticsManagerControl.expectAndReturn(
314 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, SNAPSHOTS, null, null ),
315 Collections.singletonList( createDefaultStats() ) );
316 repositoryStatisticsManagerControl.expectAndReturn(
317 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, INTERNAL, null, null ),
318 Collections.singletonList( createDefaultStats() ) );
319 repositoryStatisticsManagerControl.replay();
320 prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() );
322 String result = action.downloadStatisticsReport();
323 assertEquals( GenerateReportAction.SEND_FILE, result );
324 assertFalse( action.hasActionErrors() );
325 assertFalse( action.hasFieldErrors() );
327 assertMultiRepoCsvResult();
328 repositoryStatisticsManagerControl.verify();
331 public void testDownloadStatisticsMalformedEndDateMultiRepo()
333 repositoryStatisticsManagerControl.replay();
334 prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() );
336 action.setEndDate( "This is not a date" );
337 String result = action.downloadStatisticsReport();
339 // TODO: should be an input error
340 assertEquals( Action.ERROR, result );
341 assertTrue( action.hasActionErrors() );
342 repositoryStatisticsManagerControl.verify();
345 public void testDownloadStatisticsMalformedEndDateSingleRepo()
347 repositoryStatisticsManagerControl.replay();
348 prepareAction( Arrays.asList( SNAPSHOTS ), Arrays.asList( INTERNAL ) );
350 action.setEndDate( "This is not a date" );
351 String result = action.downloadStatisticsReport();
353 // TODO: should be an input error
354 assertEquals( Action.ERROR, result );
355 assertTrue( action.hasActionErrors() );
356 repositoryStatisticsManagerControl.verify();
359 public void testDownloadStatisticsInvalidEndDateMultiRepo()
361 repositoryStatisticsManagerControl.replay();
362 prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() );
364 action.setStartDate( "2009/12/12" );
365 action.setEndDate( "2008/11/11" );
366 String result = action.downloadStatisticsReport();
367 assertEquals( Action.INPUT, result );
368 assertTrue( action.hasFieldErrors() );
369 repositoryStatisticsManagerControl.verify();
372 public void testDownloadStatisticsInvalidEndDateSingleRepo()
374 repositoryStatisticsManagerControl.replay();
375 prepareAction( Arrays.asList( SNAPSHOTS ), Arrays.asList( INTERNAL ) );
377 action.setStartDate( "2009/12/12" );
378 action.setEndDate( "2008/11/11" );
379 String result = action.downloadStatisticsReport();
380 assertEquals( Action.INPUT, result );
381 assertTrue( action.hasFieldErrors() );
382 repositoryStatisticsManagerControl.verify();
385 public void testDownloadStatisticsSingleRepoNoStats()
389 repositoryStatisticsManagerControl.expectAndReturn(
390 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, INTERNAL, null, null ),
391 Collections.<Object>emptyList() );
392 repositoryStatisticsManagerControl.replay();
393 prepareAction( Collections.singletonList( INTERNAL ), Collections.singletonList( SNAPSHOTS ) );
395 String result = action.downloadStatisticsReport();
396 assertEquals( Action.ERROR, result );
397 assertTrue( action.hasActionErrors() );
398 repositoryStatisticsManagerControl.verify();
401 public void testDownloadStatisticsNoRepos()
403 repositoryStatisticsManagerControl.replay();
404 prepareAction( Collections.<String>emptyList(), Arrays.asList( SNAPSHOTS, INTERNAL ) );
406 String result = action.downloadStatisticsReport();
407 assertEquals( Action.INPUT, result );
408 assertTrue( action.hasFieldErrors() );
409 repositoryStatisticsManagerControl.verify();
412 public void testDownloadStatisticsMultipleRepoNoResults()
416 repositoryStatisticsManagerControl.expectAndReturn(
417 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, SNAPSHOTS, null, null ),
418 Collections.<Object>emptyList() );
419 repositoryStatisticsManagerControl.expectAndReturn(
420 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, INTERNAL, null, null ),
421 Collections.<Object>emptyList() );
422 repositoryStatisticsManagerControl.replay();
423 prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() );
425 String result = action.downloadStatisticsReport();
426 assertEquals( GenerateReportAction.BLANK, result );
427 assertFalse( action.hasActionErrors() );
428 assertFalse( action.hasActionMessages() );
429 assertFalse( action.hasFieldErrors() );
430 repositoryStatisticsManagerControl.verify();
433 public void testDownloadStatisticsMultipleRepoInStrutsFormat()
436 repositoryStatisticsManagerControl.expectAndReturn(
437 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, SNAPSHOTS, null, null ),
438 Collections.singletonList( createDefaultStats() ) );
439 repositoryStatisticsManagerControl.expectAndReturn(
440 repositoryStatisticsManager.getStatisticsInRange( metadataRepository, INTERNAL, null, null ),
441 Collections.singletonList( createDefaultStats() ) );
442 repositoryStatisticsManagerControl.replay();
443 prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() );
445 action.setSelectedRepositories( Collections.singletonList( "[" + SNAPSHOTS + "],[" + INTERNAL + "]" ) );
446 String result = action.downloadStatisticsReport();
447 assertEquals( GenerateReportAction.SEND_FILE, result );
448 assertFalse( action.hasActionErrors() );
449 assertFalse( action.hasFieldErrors() );
451 assertMultiRepoCsvResult();
452 repositoryStatisticsManagerControl.verify();
455 public void testHealthReportSingleRepo()
458 RepositoryProblemFacet problem1 = createProblem( GROUP_ID, "artifactId", INTERNAL );
459 RepositoryProblemFacet problem2 = createProblem( GROUP_ID, "artifactId-2", INTERNAL );
461 metadataRepositoryControl.expectAndReturn(
462 metadataRepository.getMetadataFacets( INTERNAL, RepositoryProblemFacet.FACET_ID ),
463 Arrays.asList( problem1.getName(), problem2.getName() ) );
464 metadataRepositoryControl.expectAndReturn(
465 metadataRepository.getMetadataFacet( INTERNAL, RepositoryProblemFacet.FACET_ID, problem1.getName() ),
467 metadataRepositoryControl.expectAndReturn(
468 metadataRepository.getMetadataFacet( INTERNAL, RepositoryProblemFacet.FACET_ID, problem2.getName() ),
470 metadataRepositoryControl.replay();
472 action.setRepositoryId( INTERNAL );
474 prepareAction( Collections.<String>emptyList(), Arrays.asList( SNAPSHOTS, INTERNAL ) );
476 String result = action.execute();
477 assertSuccessResult( result );
479 assertEquals( Collections.singleton( INTERNAL ), action.getRepositoriesMap().keySet() );
480 assertEquals( Arrays.asList( problem1, problem2 ), action.getRepositoriesMap().get( INTERNAL ) );
482 metadataRepositoryControl.verify();
485 public void testHealthReportInvalidRowCount()
488 metadataRepositoryControl.replay();
490 action.setRowCount( 0 );
491 action.setRepositoryId( INTERNAL );
493 prepareAction( Collections.<String>emptyList(), Arrays.asList( SNAPSHOTS, INTERNAL ) );
495 String result = action.execute();
496 assertEquals( Action.INPUT, result );
497 assertFalse( action.hasActionErrors() );
498 assertTrue( action.hasFieldErrors() );
500 metadataRepositoryControl.verify();
503 public void testHealthReportAllRepos()
506 RepositoryProblemFacet problem1 = createProblem( GROUP_ID, "artifactId", INTERNAL );
507 RepositoryProblemFacet problem2 = createProblem( GROUP_ID, "artifactId-2", SNAPSHOTS );
508 metadataRepositoryControl.expectAndReturn(
509 metadataRepository.getMetadataFacets( INTERNAL, RepositoryProblemFacet.FACET_ID ),
510 Arrays.asList( problem1.getName() ) );
511 metadataRepositoryControl.expectAndReturn(
512 metadataRepository.getMetadataFacets( SNAPSHOTS, RepositoryProblemFacet.FACET_ID ),
513 Arrays.asList( problem2.getName() ) );
514 metadataRepositoryControl.expectAndReturn(
515 metadataRepository.getMetadataFacet( INTERNAL, RepositoryProblemFacet.FACET_ID, problem1.getName() ),
517 metadataRepositoryControl.expectAndReturn(
518 metadataRepository.getMetadataFacet( SNAPSHOTS, RepositoryProblemFacet.FACET_ID, problem2.getName() ),
520 metadataRepositoryControl.replay();
522 action.setRepositoryId( GenerateReportAction.ALL_REPOSITORIES );
524 prepareAction( Collections.<String>emptyList(), Arrays.asList( SNAPSHOTS, INTERNAL ) );
526 String result = action.execute();
527 assertSuccessResult( result );
529 assertEquals( Arrays.asList( INTERNAL, SNAPSHOTS ),
530 new ArrayList<String>( action.getRepositoriesMap().keySet() ) );
531 assertEquals( Arrays.asList( problem1 ), action.getRepositoriesMap().get( INTERNAL ) );
532 assertEquals( Arrays.asList( problem2 ), action.getRepositoriesMap().get( SNAPSHOTS ) );
534 metadataRepositoryControl.verify();
537 public void testHealthReportSingleRepoByCorrectGroupId()
540 RepositoryProblemFacet problem1 = createProblem( GROUP_ID, "artifactId", INTERNAL );
541 RepositoryProblemFacet problem2 = createProblem( GROUP_ID, "artifactId-2", INTERNAL );
542 metadataRepositoryControl.expectAndReturn(
543 metadataRepository.getMetadataFacets( INTERNAL, RepositoryProblemFacet.FACET_ID ),
544 Arrays.asList( problem1.getName(), problem2.getName() ) );
545 metadataRepositoryControl.expectAndReturn(
546 metadataRepository.getMetadataFacet( INTERNAL, RepositoryProblemFacet.FACET_ID, problem1.getName() ),
548 metadataRepositoryControl.expectAndReturn(
549 metadataRepository.getMetadataFacet( INTERNAL, RepositoryProblemFacet.FACET_ID, problem2.getName() ),
551 metadataRepositoryControl.replay();
553 action.setGroupId( GROUP_ID );
554 action.setRepositoryId( INTERNAL );
556 prepareAction( Collections.<String>emptyList(), Arrays.asList( SNAPSHOTS, INTERNAL ) );
558 String result = action.execute();
559 assertSuccessResult( result );
561 assertEquals( Collections.singleton( INTERNAL ), action.getRepositoriesMap().keySet() );
562 assertEquals( Arrays.asList( problem1, problem2 ), action.getRepositoriesMap().get( INTERNAL ) );
564 metadataRepositoryControl.verify();
567 public void testHealthReportSingleRepoByCorrectGroupIdAllRepositories()
570 RepositoryProblemFacet problem1 = createProblem( GROUP_ID, "artifactId", INTERNAL );
571 RepositoryProblemFacet problem2 = createProblem( GROUP_ID, "artifactId-2", SNAPSHOTS );
572 metadataRepositoryControl.expectAndReturn(
573 metadataRepository.getMetadataFacets( INTERNAL, RepositoryProblemFacet.FACET_ID ),
574 Arrays.asList( problem1.getName() ) );
575 metadataRepositoryControl.expectAndReturn(
576 metadataRepository.getMetadataFacets( SNAPSHOTS, RepositoryProblemFacet.FACET_ID ),
577 Arrays.asList( problem2.getName() ) );
578 metadataRepositoryControl.expectAndReturn(
579 metadataRepository.getMetadataFacet( INTERNAL, RepositoryProblemFacet.FACET_ID, problem1.getName() ),
581 metadataRepositoryControl.expectAndReturn(
582 metadataRepository.getMetadataFacet( SNAPSHOTS, RepositoryProblemFacet.FACET_ID, problem2.getName() ),
584 metadataRepositoryControl.replay();
586 action.setGroupId( GROUP_ID );
587 action.setRepositoryId( GenerateReportAction.ALL_REPOSITORIES );
589 prepareAction( Collections.<String>emptyList(), Arrays.asList( SNAPSHOTS, INTERNAL ) );
591 String result = action.execute();
592 assertSuccessResult( result );
594 assertEquals( Arrays.asList( INTERNAL, SNAPSHOTS ),
595 new ArrayList<String>( action.getRepositoriesMap().keySet() ) );
596 assertEquals( Arrays.asList( problem1 ), action.getRepositoriesMap().get( INTERNAL ) );
597 assertEquals( Arrays.asList( problem2 ), action.getRepositoriesMap().get( SNAPSHOTS ) );
599 metadataRepositoryControl.verify();
602 public void testHealthReportSingleRepoByIncorrectGroupId()
605 metadataRepositoryControl.expectAndReturn(
606 metadataRepository.getMetadataFacets( INTERNAL, RepositoryProblemFacet.FACET_ID ),
607 Collections.<MetadataFacet>emptyList() );
608 metadataRepositoryControl.replay();
610 action.setGroupId( "not.it" );
611 action.setRepositoryId( INTERNAL );
613 prepareAction( Collections.<String>emptyList(), Arrays.asList( SNAPSHOTS, INTERNAL ) );
615 String result = action.execute();
616 assertEquals( GenerateReportAction.BLANK, result );
617 assertFalse( action.hasActionErrors() );
618 assertFalse( action.hasFieldErrors() );
620 metadataRepositoryControl.verify();
623 private void assertMultiRepoCsvResult()
627 "Repository,Total File Count,Total Size,Artifact Count,Group Count,Project Count,Plugins,Archetypes,Jars,Wars\n"
628 + "snapshots,0,0,0,0,0,0,0,0,0\n" + "internal,0,0,0,0,0,0,0,0,0\n",
629 IOUtils.toString( action.getInputStream() ) );
632 private RepositoryProblemFacet createProblem( String groupId, String artifactId, String repoId )
634 RepositoryProblemFacet problem = new RepositoryProblemFacet();
635 problem.setRepositoryId( repoId );
636 problem.setNamespace( groupId );
637 problem.setProject( artifactId );
638 problem.setProblem( PROBLEM );
642 public void testHealthReportNoRepositoryId()
645 prepareAction( Collections.<String>emptyList(), Arrays.asList( SNAPSHOTS, INTERNAL ) );
647 String result = action.execute();
648 assertEquals( Action.INPUT, result );
649 assertTrue( action.hasFieldErrors() );
652 private void assertSuccessResult( String result )
654 assertEquals( Action.SUCCESS, result );
655 assertFalse( action.hasActionErrors() );
656 assertFalse( action.hasFieldErrors() );
659 private RepositoryStatistics createDefaultStats()
661 return createStats( new Date() );
664 private RepositoryStatistics createStats( Date date )
666 RepositoryStatistics stats = new RepositoryStatistics();
667 stats.setScanStartTime( date );