Search in sources :

Example 1 with AccessibleSettings

use of org.fakekoji.core.AccessibleSettings in project jenkins-scm-koji-plugin by judovana.

the class BumperApiTest method addVariantWithMissingName.

@Test
public void addVariantWithMissingName() throws IOException {
    final DataGenerator.FolderHolder folderHolder = DataGenerator.initFolders(temporaryFolder);
    final AccessibleSettings settings = DataGenerator.getSettings(folderHolder);
    final BumperAPI bumperApi = new BumperAPI(settings);
    DataGenerator.createProjectJobs(settings);
    final Result<BumpResult, OToolError> result = bumperApi.addTaskVariant(createParamsMap(new String[][] { { "type", Task.Type.BUILD.getValue() }, { "defaultValue", defaultValue }, { "values", defaultValue + ",ijklmnopq,rstuvwxyz" } }));
    Assert.assertTrue(result.isError());
}
Also used : BumpResult(org.fakekoji.jobmanager.bumpers.BumpResult) DataGenerator(org.fakekoji.DataGenerator) AccessibleSettings(org.fakekoji.core.AccessibleSettings) Test(org.junit.Test)

Example 2 with AccessibleSettings

use of org.fakekoji.core.AccessibleSettings in project jenkins-scm-koji-plugin by judovana.

the class BumperApiTest method addVariantWithExistingName.

@Test
public void addVariantWithExistingName() throws IOException {
    final DataGenerator.FolderHolder folderHolder = DataGenerator.initFolders(temporaryFolder);
    final AccessibleSettings settings = DataGenerator.getSettings(folderHolder);
    final BumperAPI bumperApi = new BumperAPI(settings);
    DataGenerator.createProjectJobs(settings);
    final Result<BumpResult, OToolError> result = bumperApi.addTaskVariant(createParamsMap(new String[][] { { "name", DataGenerator.JVM }, { "type", Task.Type.BUILD.getValue() }, { "defaultValue", defaultValue }, { "values", defaultValue + ",ijklmnopq,rstuvwxyz" } }));
    Assert.assertTrue(result.isError());
}
Also used : BumpResult(org.fakekoji.jobmanager.bumpers.BumpResult) DataGenerator(org.fakekoji.DataGenerator) AccessibleSettings(org.fakekoji.core.AccessibleSettings) Test(org.junit.Test)

Example 3 with AccessibleSettings

use of org.fakekoji.core.AccessibleSettings in project jenkins-scm-koji-plugin by judovana.

the class BumperApiTest method addVariantWithMissingDefaultValue.

@Test
public void addVariantWithMissingDefaultValue() throws IOException {
    final DataGenerator.FolderHolder folderHolder = DataGenerator.initFolders(temporaryFolder);
    final AccessibleSettings settings = DataGenerator.getSettings(folderHolder);
    final BumperAPI bumperApi = new BumperAPI(settings);
    DataGenerator.createProjectJobs(settings);
    final Result<BumpResult, OToolError> result = bumperApi.addTaskVariant(createParamsMap(new String[][] { { "name", taskVariantId }, { "type", Task.Type.BUILD.getValue() }, { "values", defaultValue + ",ijklmnopq,rstuvwxyz" } }));
    Assert.assertTrue(result.isError());
}
Also used : BumpResult(org.fakekoji.jobmanager.bumpers.BumpResult) DataGenerator(org.fakekoji.DataGenerator) AccessibleSettings(org.fakekoji.core.AccessibleSettings) Test(org.junit.Test)

Example 4 with AccessibleSettings

use of org.fakekoji.core.AccessibleSettings in project jenkins-scm-koji-plugin by judovana.

the class BumperApiTest method removeBuildVariant.

@Test
public void removeBuildVariant() throws IOException {
    final String taskVariantId = JRE_SDK;
    final DataGenerator.FolderHolder folderHolder = DataGenerator.initFolders(temporaryFolder);
    final AccessibleSettings settings = DataGenerator.getSettings(folderHolder);
    DataGenerator.initBuildsRoot(settings.getDbFileRoot());
    final File jobsRoot = settings.getJenkinsJobsRoot();
    DataGenerator.createProjectJobs(settings);
    final BumperAPI bumperApi = new BumperAPI(settings);
    final Map<String, List<String>> params = Stream.of(new String[][] { { "name", taskVariantId }, { EXECUTE, "true" } }).collect(Collectors.toMap(data -> data[0], data -> Collections.singletonList(data[1])));
    final Set<String> taskIds = DataGenerator.getTasks().stream().map(Task::getId).collect(Collectors.toSet());
    final Result<BumpResult, OToolError> result = bumperApi.removeTaskVariant(params);
    Assert.assertFalse(result.isError());
    Assert.assertFalse(settings.getConfigManager().taskVariantManager.contains(taskVariantId));
    final JobUpdateResults results = result.getValue().getJobResults();
    Assert.assertEquals(47, results.jobsCreated.size());
    Assert.assertTrue(results.jobsArchived.isEmpty());
    Assert.assertTrue(results.jobsRevived.isEmpty());
    Assert.assertTrue(results.jobsRewritten.isEmpty());
    for (final JobUpdateResult jobResult : results.jobsCreated) {
        final String[] parts = jobResult.message.split(" ");
        final String prevJobName = parts[2];
        final String currJobName = parts[4];
        final String prevJobTaskId = prevJobName.split("-")[0];
        final String currJobTaskId = currJobName.split("-")[0];
        Assert.assertTrue(jobResult.success);
        Assert.assertEquals(prevJobTaskId, currJobTaskId);
        Assert.assertTrue(taskIds.contains(prevJobTaskId));
        Assert.assertEquals(prevJobName.replace("." + SDK, ""), currJobName);
        Assert.assertTrue(new File(jobsRoot, currJobName).exists());
        Assert.assertFalse(new File(jobsRoot, prevJobName).exists());
    }
    Assert.assertEquals(Utils.readResource("org/fakekoji/api/http/rest/post-remove-variant-builds-tree"), toTree(settings.getDbFileRoot()));
}
Also used : JenkinsCliWrapper(org.fakekoji.jobmanager.JenkinsCliWrapper) Arrays(java.util.Arrays) BeforeClass(org.junit.BeforeClass) Task(org.fakekoji.model.Task) JobUpdateResults(org.fakekoji.jobmanager.model.JobUpdateResults) Utils(org.fakekoji.Utils) Map(java.util.Map) JRE_SDK(org.fakekoji.DataGenerator.JRE_SDK) JobUpdateResult(org.fakekoji.jobmanager.model.JobUpdateResult) StorageException(org.fakekoji.storage.StorageException) DataGenerator(org.fakekoji.DataGenerator) SDK(org.fakekoji.DataGenerator.SDK) BumpResult(org.fakekoji.jobmanager.bumpers.BumpResult) ManagementException(org.fakekoji.jobmanager.ManagementException) Set(java.util.Set) Test(org.junit.Test) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) File(java.io.File) Objects(java.util.Objects) EXECUTE(org.fakekoji.api.http.rest.BumperAPI.EXECUTE) List(java.util.List) Rule(org.junit.Rule) Stream(java.util.stream.Stream) Result(org.fakekoji.functional.Result) TaskVariant(org.fakekoji.model.TaskVariant) Assert(org.junit.Assert) Collections(java.util.Collections) TemporaryFolder(org.junit.rules.TemporaryFolder) AccessibleSettings(org.fakekoji.core.AccessibleSettings) JobUpdateResults(org.fakekoji.jobmanager.model.JobUpdateResults) AccessibleSettings(org.fakekoji.core.AccessibleSettings) BumpResult(org.fakekoji.jobmanager.bumpers.BumpResult) DataGenerator(org.fakekoji.DataGenerator) List(java.util.List) JobUpdateResult(org.fakekoji.jobmanager.model.JobUpdateResult) File(java.io.File) Test(org.junit.Test)

Example 5 with AccessibleSettings

use of org.fakekoji.core.AccessibleSettings in project jenkins-scm-koji-plugin by judovana.

the class TestSshApi method startSshdServer.

@BeforeClass
public static void startSshdServer() throws IOException, GeneralSecurityException {
    final FolderHolder folderHolder = DataGenerator.initFolders(temporaryFolder);
    final AccessibleSettings settings = DataGenerator.getSettings(folderHolder);
    ServerSocket s = new ServerSocket(settings.getSshPort());
    port = s.getLocalPort();
    final File keys = File.createTempFile("ssh-fake-koji.", ".TestKeys");
    keys.delete();
    keys.mkdir();
    priv = new File(keys, "id_rsa");
    pub = new File(keys, "id_rsa.pub");
    createFile(priv, IDS_RSA);
    createFile(pub, IDS_RSA_PUB);
    Set<PosixFilePermission> perms = new HashSet<>();
    Files.setPosixFilePermissions(pub.toPath(), perms);
    Files.setPosixFilePermissions(priv.toPath(), perms);
    perms.add(PosixFilePermission.OWNER_READ);
    perms.add(PosixFilePermission.OWNER_WRITE);
    Files.setPosixFilePermissions(pub.toPath(), perms);
    Files.setPosixFilePermissions(priv.toPath(), perms);
    Runtime.getRuntime().addShutdownHook(new Thread() {

        @Override
        public void run() {
            priv.delete();
            pub.delete();
            keys.delete();
        }
    });
    s.close();
    kojiDb = settings.getDbFileRoot();
    server = new ScpService(settings, "tester=" + pub.getAbsolutePath());
    server.start();
    sources = File.createTempFile("ssh-fake-koji.", ".sources");
    sources.delete();
    sources.mkdir();
    sources.deleteOnExit();
    secondDir = File.createTempFile("ssh-fake-koji.", ".secondDir");
    secondDir.delete();
    secondDir.mkdir();
    secondDir.deleteOnExit();
}
Also used : FolderHolder(org.fakekoji.DataGenerator.FolderHolder) ServerSocket(java.net.ServerSocket) PosixFilePermission(java.nio.file.attribute.PosixFilePermission) AccessibleSettings(org.fakekoji.core.AccessibleSettings) File(java.io.File) HashSet(java.util.HashSet) BeforeClass(org.junit.BeforeClass)

Aggregations

AccessibleSettings (org.fakekoji.core.AccessibleSettings)17 DataGenerator (org.fakekoji.DataGenerator)14 BumpResult (org.fakekoji.jobmanager.bumpers.BumpResult)12 Test (org.junit.Test)12 File (java.io.File)6 BeforeClass (org.junit.BeforeClass)6 IOException (java.io.IOException)3 Arrays (java.util.Arrays)3 Collections (java.util.Collections)3 List (java.util.List)3 Map (java.util.Map)3 Objects (java.util.Objects)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 Stream (java.util.stream.Stream)3 JRE_SDK (org.fakekoji.DataGenerator.JRE_SDK)3 SDK (org.fakekoji.DataGenerator.SDK)3 Utils (org.fakekoji.Utils)3 EXECUTE (org.fakekoji.api.http.rest.BumperAPI.EXECUTE)3 Result (org.fakekoji.functional.Result)3