Skip to content

Commit

Permalink
Merge pull request #52 from msiebeneicher/enhancement/add_a_unique_jo…
Browse files Browse the repository at this point in the history
…b_name_validation

add a unique job name validation
  • Loading branch information
msiebeneicher committed Apr 22, 2016
2 parents c6a8371 + d71c590 commit 9bd5df7
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
@@ -1,4 +1,7 @@
# dev-master (v0.7.x)
2016-04-21 msiebeneicher <marc.siebeneicher@trivago.com>
* [issue#50] - Added a unique job name validation

2016-04-21 msiebeneicher <marc.siebeneicher@trivago.com>
* Updating dependencies (including require-dev)
- Updating mikey179/vfsstream (v1.6.2 => v1.6.3)
Expand Down
1 change: 1 addition & 0 deletions src/Exception/JobLoadException.php
Expand Up @@ -12,4 +12,5 @@
class JobLoadException extends \Exception
{
const ERROR_CODE_NO_VALID_JSON = 1;
const ERROR_CODE_DUPLICATE_JOB_ID = 2;
}
10 changes: 10 additions & 0 deletions src/Service/JobRepository/BridgeFileSystem.php
Expand Up @@ -159,10 +159,19 @@ private function getJobFilesFromFileSystem($sPath, array &$aJobFiles = [])
/**
* @param string $sJobName
* @param string $sJobFile
* @throws JobLoadException
*/
private function setJobFileToMap($sJobName, $sJobFile)
{
// set path to job file map
if (isset($this->aJobFileMap[$sJobName]))
{
throw new JobLoadException(
sprintf('The jobname "%s" already exists. Jobnames have to be unique - Please check your local jobfiles for duplicate entries.', $sJobName),
JobLoadException::ERROR_CODE_DUPLICATE_JOB_ID
);
}

$this->aJobFileMap[$sJobName] = $sJobFile;
}

Expand Down Expand Up @@ -204,6 +213,7 @@ private function hasUnsetJobFileFromMap($sJobName, $sJobFile = '')
* @param array $aJobFiles
* @param bool $bSetToFileMap
* @return JobEntity[]
* @throws JobLoadException
*/
private function loadJobsFromFileContent(array $aJobFiles, $bSetToFileMap)
{
Expand Down
24 changes: 24 additions & 0 deletions test/unit/Service/JobRepository/BridgeFileSystemTest.php
Expand Up @@ -174,4 +174,28 @@ public function testJobLoadException()
$_aJobs = $_oFileSystemRepository->getJobs();
$this->assertNull($_aJobs);
}

/**
* @expectedException \Chapi\Exception\JobLoadException
*/
public function testJobLoadExceptionForDuplicateJobNames()
{
$_aStructure = array(
'directory' => array(
'jobA.json' => json_encode($this->getValidScheduledJobEntity('JobA')),
),
'jobB.json' => json_encode($this->getValidScheduledJobEntity('JobA')),
);

$this->oVfsRoot = vfsStream::setup($this->sRepositoryDir, null, $_aStructure);

$_oFileSystemRepository = new BridgeFileSystem(
$this->oFileSystemService->reveal(),
$this->oCache->reveal(),
vfsStream::url($this->sRepositoryDir)
);

$_aJobs = $_oFileSystemRepository->getJobs();
$this->assertNull($_aJobs);
}
}

0 comments on commit 9bd5df7

Please sign in to comment.