use of org.kie.workbench.common.screens.archetype.mgmt.shared.model.Archetype in project kie-wb-common by kiegroup.
the class ArchetypeServiceImplTest method validateWhenRepositoryIsNotAvailableTest.
@Test(expected = IllegalStateException.class)
public void validateWhenRepositoryIsNotAvailableTest() {
mockArchetypesOrgUnit();
final Archetype archetype = mock(Archetype.class);
doReturn(ArchetypeStatus.VALID).when(archetype).getStatus();
doReturn(archetype).when(archetypeConfigStorage).loadArchetype(Mockito.<String>any());
doReturn(null).when(repositoryService).getRepositoryFromSpace(Mockito.<Space>any(), Mockito.<String>any());
service.validate(COMMON_ARCHETYPE_ALIAS);
}
use of org.kie.workbench.common.screens.archetype.mgmt.shared.model.Archetype in project kie-wb-common by kiegroup.
the class ArchetypeServiceImplTest method validateWhenExecuteMavenThrowsExceptionTest.
@Test
public void validateWhenExecuteMavenThrowsExceptionTest() throws MavenEmbedderException {
mockArchetypesOrgUnit();
doReturn(mock(Repository.class)).when(repositoryService).getRepositoryFromSpace(Mockito.<Space>any(), eq(COMMON_ARCHETYPE_ALIAS));
doReturn(mock(Path.class)).when(service).unpackArchetype(Mockito.<Repository>any());
doThrow(MavenEmbedderException.class).when(service).executeMaven(Mockito.<BuildProjectCommand>any());
final Archetype archetype = createArchetypeWithStatus(ArchetypeStatus.INVALID);
doReturn(archetype).when(archetypeConfigStorage).loadArchetype(Mockito.<String>any());
doNothing().when(archetypeConfigStorage).saveArchetype(archetype);
service.validate(COMMON_ARCHETYPE_ALIAS);
verify(archetypePreferencesManager).enableArchetype(Mockito.<String>any(), eq(false), eq(true));
verify(archetypePreferencesManager).addArchetype(Mockito.<String>any());
verify(archetypeConfigStorage).loadArchetype(Mockito.<String>any());
verify(archetypeConfigStorage).saveArchetype(any(Archetype.class));
verify(archetypeListUpdatedEvent).fire(new ArchetypeListUpdatedEvent(ArchetypeListOperation.VALIDATE));
}
use of org.kie.workbench.common.screens.archetype.mgmt.shared.model.Archetype in project kie-wb-common by kiegroup.
the class ArchetypeServiceImplTest method listAllWithStatusPaginatedTest.
@Test
public void listAllWithStatusPaginatedTest() {
mockArchetypesOrgUnit();
final Archetype archetype1 = createArchetypeWithFields("findme", ArchetypeStatus.VALID);
final Archetype archetype2 = createArchetypeWithFields("tryfindme", ArchetypeStatus.INVALID);
final List<Archetype> archetypes = new ArrayList<>();
archetypes.addAll(Collections.nCopies(13, archetype1));
archetypes.addAll(Collections.nCopies(5, archetype2));
final List<Repository> repositories = new ArrayList<>();
archetypes.forEach(archetype -> {
doReturn(archetype).when(archetypeConfigStorage).loadArchetype(archetype.getAlias());
final Repository repository = mock(Repository.class);
doReturn(archetype.getAlias()).when(repository).getAlias();
repositories.add(repository);
});
doReturn(repositories).when(repositoryService).getAllRepositories(Mockito.<Space>any());
PaginatedArchetypeList result = service.list(0, 5, "", ArchetypeStatus.VALID);
assertThat(result.getTotal()).isEqualTo(13);
assertThat(result.getArchetypes()).hasSize(5);
assertThat(result.getPageNumber()).isEqualTo(0);
assertThat(result.getPageSize()).isEqualTo(5);
result = service.list(1, 5, "", ArchetypeStatus.VALID);
assertThat(result.getTotal()).isEqualTo(13);
assertThat(result.getArchetypes()).hasSize(5);
assertThat(result.getPageNumber()).isEqualTo(1);
assertThat(result.getPageSize()).isEqualTo(5);
result = service.list(2, 5, "", ArchetypeStatus.VALID);
assertThat(result.getTotal()).isEqualTo(13);
assertThat(result.getArchetypes()).hasSize(3);
assertThat(result.getPageNumber()).isEqualTo(2);
assertThat(result.getPageSize()).isEqualTo(5);
}
use of org.kie.workbench.common.screens.archetype.mgmt.shared.model.Archetype in project kie-wb-common by kiegroup.
the class ArchetypeServiceImplTest method getBaseKieTemplateRepositoryWhenInvalidTest.
@Test
public void getBaseKieTemplateRepositoryWhenInvalidTest() {
mockArchetypesOrgUnit();
final Archetype archetype = mock(Archetype.class);
doReturn(ArchetypeStatus.INVALID).when(archetype).getStatus();
doReturn(archetype).when(archetypeConfigStorage).loadArchetype(Mockito.<String>any());
final Optional<Repository> repository = service.getBaseKieTemplateRepository();
assertFalse(repository.isPresent());
}
use of org.kie.workbench.common.screens.archetype.mgmt.shared.model.Archetype in project kie-wb-common by kiegroup.
the class ArchetypeServiceImplTest method getBaseKieTemplateRepositoryTest.
@Test
public void getBaseKieTemplateRepositoryTest() {
mockArchetypesOrgUnit();
final Archetype archetype = mock(Archetype.class);
doReturn(ArchetypeStatus.VALID).when(archetype).getStatus();
doReturn(archetype).when(archetypeConfigStorage).loadArchetype(Mockito.<String>any());
final String repositoryAlias = service.makeRepositoryAlias(ArchetypeServiceImpl.BASE_KIE_PROJECT_TEMPLATE_GAV);
final Repository expectedRepository = mock(Repository.class);
doReturn(expectedRepository).when(repositoryService).getRepositoryFromSpace(Mockito.<Space>any(), eq(repositoryAlias));
final Optional<Repository> repository = service.getBaseKieTemplateRepository();
assertTrue(repository.isPresent());
assertThat(repository.get()).isSameAs(expectedRepository);
}
Aggregations