use of com.faforever.api.data.domain.FeaturedMod in project faf-java-api by FAForever.
the class GitHubDeploymentServiceTest method deployEnvironmentMatch.
@Test
public void deployEnvironmentMatch() throws Exception {
apiProperties.getGitHub().setDeploymentEnvironment(ENVIRONMENT);
// Couldn't be mocked since calling ghDeployment.getId() threw an NPE
GHDeployment ghDeployment = new GHDeployment() {
@Override
public int getId() {
return 1;
}
@Override
public String getEnvironment() {
return ENVIRONMENT;
}
@Override
public String getPayload() {
return "faf";
}
};
Deployment deployment = mock(Deployment.class);
when(deployment.getDeployment()).thenReturn(ghDeployment);
GHRepository ghRepository = mock(GHRepository.class);
GHDeploymentStatusBuilder builder = mock(GHDeploymentStatusBuilder.class);
when(builder.description(any())).thenReturn(builder);
when(ghRepository.createDeployStatus(anyInt(), any())).thenReturn(builder);
when(deployment.getRepository()).thenReturn(ghRepository);
LegacyFeaturedModDeploymentTask task = mock(LegacyFeaturedModDeploymentTask.class);
when(task.setFeaturedMod(any())).thenReturn(task);
when(task.setStatusDescriptionListener(any())).thenReturn(task);
when(applicationContext.getBean(LegacyFeaturedModDeploymentTask.class)).thenReturn(task);
when(featuredModService.findModByTechnicalName("faf")).thenReturn(Optional.of(new FeaturedMod()));
instance.deploy(deployment);
verify(task).run();
verify(builder).create();
}
use of com.faforever.api.data.domain.FeaturedMod in project faf-java-api by FAForever.
the class LegacyFeaturedModDeploymentTaskTest method testRunNoFileIds.
@Test
public void testRunNoFileIds() throws Exception {
instance.setFeaturedMod(new FeaturedMod().setGitBranch("branch").setFileExtension("nx3").setTechnicalName("faf").setAllowOverride(true).setGitUrl("git@example.com/FAForever/faf"));
Mockito.doAnswer(invocation -> {
Path repoFolder = invocation.getArgument(0);
Files.createDirectories(repoFolder.resolve("someDir"));
Files.copy(LegacyFeaturedModDeploymentTaskTest.class.getResourceAsStream("/featured_mod/mod_info.lua"), repoFolder.resolve("mod_info.lua"));
return null;
}).when(gitWrapper).checkoutRef(any(), any());
when(featuredModService.getFeaturedMods()).thenReturn(Collections.singletonList(new FeaturedMod().setTechnicalName("faf")));
when(featuredModService.getFileIds("faf")).thenReturn(Collections.emptyMap());
Path dummyExe = repositoriesFolder.getRoot().toPath().resolve("TemplateForgedAlliance.exe");
createDummyExe(dummyExe);
properties.getDeployment().setForgedAllianceExePath(dummyExe.toAbsolutePath().toString());
instance.run();
verify(featuredModService, never()).save(anyString(), anyShort(), any());
}
use of com.faforever.api.data.domain.FeaturedMod in project faf-java-api by FAForever.
the class LegacyFeaturedModDeploymentTask method run.
@Override
@SneakyThrows
@Transactional(TxType.MANDATORY)
public void run() {
Assert.state(featuredMod != null, "Configuration must be set");
String modName = featuredMod.getTechnicalName();
Assert.state(featuredModService.getFeaturedMods().stream().anyMatch(featuredMod -> Objects.equals(featuredMod.getTechnicalName(), modName)), "Unknown mod: " + modName);
String repositoryUrl = featuredMod.getGitUrl();
String branch = featuredMod.getGitBranch();
boolean allowOverride = Optional.ofNullable(featuredMod.isAllowOverride()).orElse(false);
String modFilesExtension = featuredMod.getFileExtension();
Map<String, Short> fileIds = featuredModService.getFileIds(modName);
log.info("Starting deployment of '{}' from '{}', branch '{}', allowOverride '{}', modFilesExtension '{}'", modName, repositoryUrl, branch, allowOverride, modFilesExtension);
Path repositoryDirectory = buildRepositoryDirectoryPath(repositoryUrl);
checkoutCode(repositoryDirectory, repositoryUrl, branch);
short version = readModVersion(repositoryDirectory);
verifyVersion(version, allowOverride, modName);
Deployment deployment = apiProperties.getDeployment();
Path targetFolder = Paths.get(deployment.getFeaturedModsTargetDirectory(), String.format(deployment.getFilesDirectoryFormat(), modName));
List<StagedFile> files = packageDirectories(repositoryDirectory, version, fileIds, targetFolder);
createPatchedExe(version, fileIds, targetFolder).ifPresent(files::add);
if (files.isEmpty()) {
log.warn("Could not find any files to deploy. Is the configuration correct?");
return;
}
files.forEach(this::finalizeFile);
updateDatabase(files, version, modName);
log.info("Deployment of '{}' version '{}' was successful", modName, version);
}
use of com.faforever.api.data.domain.FeaturedMod in project faf-java-api by FAForever.
the class GitHubDeploymentServiceTest method createDeploymentIfEligible.
@Test
public void createDeploymentIfEligible() throws Exception {
Push push = mock(Push.class);
when(push.getRef()).thenReturn("refs/heads/junit");
when(featuredModService.findByGitUrlAndGitBranch(EXAMPLE_REPO_URL, "junit")).thenReturn(Optional.of(new FeaturedMod().setTechnicalName("faf")));
GHRepository repository = mock(GHRepository.class);
when(repository.gitHttpTransportUrl()).thenReturn(EXAMPLE_REPO_URL);
GHDeploymentBuilder deploymentBuilder = mock(GHDeploymentBuilder.class);
when(deploymentBuilder.autoMerge(false)).thenReturn(deploymentBuilder);
when(deploymentBuilder.environment(ENVIRONMENT)).thenReturn(deploymentBuilder);
when(deploymentBuilder.payload("faf")).thenReturn(deploymentBuilder);
when(deploymentBuilder.requiredContexts(Collections.emptyList())).thenReturn(deploymentBuilder);
when(repository.createDeployment("refs/heads/junit")).thenReturn(deploymentBuilder);
when(push.getRepository()).thenReturn(repository);
apiProperties.getGitHub().setDeploymentEnvironment(ENVIRONMENT);
instance.createDeploymentIfEligible(push);
verify(repository).createDeployment(any());
verify(deploymentBuilder).autoMerge(false);
verify(deploymentBuilder).environment(ENVIRONMENT);
verify(deploymentBuilder).create();
}
use of com.faforever.api.data.domain.FeaturedMod in project faf-java-api by FAForever.
the class LegacyFeaturedModDeploymentTaskTest method testRun.
@Test
@SuppressWarnings("unchecked")
public void testRun() throws Exception {
instance.setFeaturedMod(new FeaturedMod().setGitBranch("branch").setFileExtension("nx3").setTechnicalName("faf").setAllowOverride(true).setGitUrl("git@example.com/FAForever/faf"));
Mockito.doAnswer(invocation -> {
Path repoFolder = invocation.getArgument(0);
Files.createDirectories(repoFolder.resolve("someDir"));
Files.copy(LegacyFeaturedModDeploymentTaskTest.class.getResourceAsStream("/featured_mod/mod_info.lua"), repoFolder.resolve("mod_info.lua"));
Files.copy(LegacyFeaturedModDeploymentTaskTest.class.getResourceAsStream("/featured_mod/someDir/someFile"), repoFolder.resolve("someDir/someFile"));
return null;
}).when(gitWrapper).checkoutRef(any(), any());
when(featuredModService.getFeaturedMods()).thenReturn(Collections.singletonList(new FeaturedMod().setTechnicalName("faf")));
when(featuredModService.getFileIds("faf")).thenReturn(ImmutableMap.of("ForgedAlliance.exe", (short) 1, "someDir.nx3", (short) 2));
Path dummyExe = repositoriesFolder.getRoot().toPath().resolve("TemplateForgedAlliance.exe");
createDummyExe(dummyExe);
properties.getDeployment().setForgedAllianceExePath(dummyExe.toAbsolutePath().toString());
instance.run();
ArgumentCaptor<List<FeaturedModFile>> filesCaptor = ArgumentCaptor.forClass(List.class);
verify(featuredModService).save(eq("faf"), eq((short) 1337), filesCaptor.capture());
List<FeaturedModFile> files = filesCaptor.getValue();
files.sort(Comparator.comparing(FeaturedModFile::getFileId));
assertThat(files.get(0).getFileId(), is((short) 1));
assertThat(files.get(0).getMd5(), is("47df959058cb52fe966ea5936dbd8f4c"));
assertThat(files.get(0).getName(), is("ForgedAlliance.1337.exe"));
assertThat(files.get(0).getVersion(), is(1337));
assertThat(files.get(1).getFileId(), is((short) 2));
assertThat(files.get(1).getMd5(), is(notNullValue()));
assertThat(files.get(1).getName(), is("someDir.1337.nx3"));
assertThat(files.get(1).getVersion(), is(1337));
assertThat(Files.exists(targetFolder.getRoot().toPath().resolve("updates_faf_files/someDir.1337.nx3")), is(true));
assertThat(Files.exists(targetFolder.getRoot().toPath().resolve("updates_faf_files/ForgedAlliance.1337.exe")), is(true));
}
Aggregations