Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ProActive
scheduling
Commits
697de0d9
Unverified
Commit
697de0d9
authored
Jun 08, 2020
by
TAO Xinxiu (Isabelle)
Committed by
GitHub
Jun 08, 2020
Browse files
Add OPTIONAL variables: URL, URI, GLOBAL_FILE, USER_FILE (#3767)
parent
5216be16
Changes
25
Hide whitespace changes
Inline
Side-by-side
scheduler/scheduler-api/src/main/java/org/ow2/proactive/scheduler/common/job/factories/spi/model/factory/GlobalFileParserValidator.java
View file @
697de0d9
...
...
@@ -38,6 +38,10 @@ public class GlobalFileParserValidator extends BaseParserValidator<String> {
super
(
model
,
ModelType
.
GLOBAL_FILE
);
}
public
GlobalFileParserValidator
(
String
model
,
ModelType
type
)
throws
ModelSyntaxException
{
super
(
model
,
type
);
}
@Override
protected
Converter
<
String
>
createConverter
(
String
model
)
throws
ModelSyntaxException
{
return
new
IdentityConverter
();
...
...
scheduler/scheduler-api/src/main/java/org/ow2/proactive/scheduler/common/job/factories/spi/model/factory/ModelType.java
View file @
697de0d9
...
...
@@ -25,8 +25,6 @@
*/
package
org.ow2.proactive.scheduler.common.job.factories.spi.model.factory
;
import
java.net.URI
;
import
java.net.URL
;
import
java.util.Date
;
...
...
@@ -50,12 +48,16 @@ public enum ModelType {
REGEXP
(
RegexpParserValidator
.
class
,
String
.
class
),
SHORT
(
ShortParserValidator
.
class
,
Short
.
class
),
SPEL
(
SPELParserValidator
.
class
,
String
.
class
),
URI
(
URIParserValidator
.
class
,
URI
.
class
),
URL
(
URLParserValidator
.
class
,
URL
.
class
),
URI
(
URIParserValidator
.
class
,
String
.
class
),
OPTIONAL_URI
(
OptionalURIParserValidator
.
class
,
String
.
class
),
URL
(
URLParserValidator
.
class
,
String
.
class
),
OPTIONAL_URL
(
OptionalURLParserValidator
.
class
,
String
.
class
),
HIDDEN
(
HiddenParserValidator
.
class
,
String
.
class
),
CREDENTIAL
(
CredentialParserValidator
.
class
,
String
.
class
),
USER_FILE
(
UserFileParserValidator
.
class
,
URI
.
class
),
GLOBAL_FILE
(
GlobalFileParserValidator
.
class
,
URI
.
class
);
USER_FILE
(
UserFileParserValidator
.
class
,
String
.
class
),
OPTIONAL_USER_FILE
(
OptionalUserFileParserValidator
.
class
,
String
.
class
),
GLOBAL_FILE
(
GlobalFileParserValidator
.
class
,
String
.
class
),
OPTIONAL_GLOBAL_FILE
(
OptionalGlobalFileParserValidator
.
class
,
String
.
class
);
// The parser validator of the model type
private
Class
typeParserValidator
;
...
...
scheduler/scheduler-api/src/main/java/org/ow2/proactive/scheduler/common/job/factories/spi/model/factory/OptionalGlobalFileParserValidator.java
0 → 100644
View file @
697de0d9
/*
* ProActive Parallel Suite(TM):
* The Open Source library for parallel and distributed
* Workflows & Scheduling, Orchestration, Cloud Automation
* and Big Data Analysis on Enterprise Grids & Clouds.
*
* Copyright (c) 2007 - 2017 ActiveEon
* Contact: contact@activeeon.com
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation: version 3 of
* the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* If needed, contact us to obtain a release under GPL Version 2 or 3
* or a different license than the AGPL.
*/
package
org.ow2.proactive.scheduler.common.job.factories.spi.model.factory
;
import
org.ow2.proactive.scheduler.common.job.factories.spi.model.converter.Converter
;
import
org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ModelSyntaxException
;
import
org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.GlobalFileValidator
;
import
org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.OptionalValidator
;
import
org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.Validator
;
public
class
OptionalGlobalFileParserValidator
extends
GlobalFileParserValidator
{
public
OptionalGlobalFileParserValidator
(
String
model
)
throws
ModelSyntaxException
{
super
(
model
,
ModelType
.
OPTIONAL_GLOBAL_FILE
);
}
@Override
protected
Validator
<
String
>
createValidator
(
String
model
,
Converter
<
String
>
converter
)
{
return
new
OptionalValidator
<>(
new
GlobalFileValidator
());
}
}
scheduler/scheduler-api/src/main/java/org/ow2/proactive/scheduler/common/job/factories/spi/model/factory/OptionalURIParserValidator.java
0 → 100644
View file @
697de0d9
/*
* ProActive Parallel Suite(TM):
* The Open Source library for parallel and distributed
* Workflows & Scheduling, Orchestration, Cloud Automation
* and Big Data Analysis on Enterprise Grids & Clouds.
*
* Copyright (c) 2007 - 2017 ActiveEon
* Contact: contact@activeeon.com
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation: version 3 of
* the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* If needed, contact us to obtain a release under GPL Version 2 or 3
* or a different license than the AGPL.
*/
package
org.ow2.proactive.scheduler.common.job.factories.spi.model.factory
;
import
org.ow2.proactive.scheduler.common.job.factories.spi.model.converter.Converter
;
import
org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ModelSyntaxException
;
import
org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.OptionalValidator
;
import
org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.URIValidator
;
import
org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.Validator
;
public
class
OptionalURIParserValidator
extends
URIParserValidator
{
public
OptionalURIParserValidator
(
String
model
)
throws
ModelSyntaxException
{
super
(
model
,
ModelType
.
OPTIONAL_URI
);
}
@Override
protected
Validator
<
String
>
createValidator
(
String
model
,
Converter
<
String
>
converter
)
{
return
new
OptionalValidator
<>(
new
URIValidator
());
}
}
scheduler/scheduler-api/src/main/java/org/ow2/proactive/scheduler/common/job/factories/spi/model/factory/OptionalURLParserValidator.java
0 → 100644
View file @
697de0d9
/*
* ProActive Parallel Suite(TM):
* The Open Source library for parallel and distributed
* Workflows & Scheduling, Orchestration, Cloud Automation
* and Big Data Analysis on Enterprise Grids & Clouds.
*
* Copyright (c) 2007 - 2017 ActiveEon
* Contact: contact@activeeon.com
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation: version 3 of
* the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* If needed, contact us to obtain a release under GPL Version 2 or 3
* or a different license than the AGPL.
*/
package
org.ow2.proactive.scheduler.common.job.factories.spi.model.factory
;
import
org.ow2.proactive.scheduler.common.job.factories.spi.model.converter.Converter
;
import
org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ModelSyntaxException
;
import
org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.OptionalValidator
;
import
org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.URLValidator
;
import
org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.Validator
;
public
class
OptionalURLParserValidator
extends
URLParserValidator
{
public
OptionalURLParserValidator
(
String
model
)
throws
ModelSyntaxException
{
super
(
model
,
ModelType
.
OPTIONAL_URL
);
}
@Override
protected
Validator
<
String
>
createValidator
(
String
model
,
Converter
<
String
>
converter
)
{
return
new
OptionalValidator
<>(
new
URLValidator
());
}
}
scheduler/scheduler-api/src/main/java/org/ow2/proactive/scheduler/common/job/factories/spi/model/factory/OptionalUserFileParserValidator.java
0 → 100644
View file @
697de0d9
/*
* ProActive Parallel Suite(TM):
* The Open Source library for parallel and distributed
* Workflows & Scheduling, Orchestration, Cloud Automation
* and Big Data Analysis on Enterprise Grids & Clouds.
*
* Copyright (c) 2007 - 2017 ActiveEon
* Contact: contact@activeeon.com
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation: version 3 of
* the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* If needed, contact us to obtain a release under GPL Version 2 or 3
* or a different license than the AGPL.
*/
package
org.ow2.proactive.scheduler.common.job.factories.spi.model.factory
;
import
org.ow2.proactive.scheduler.common.job.factories.spi.model.converter.Converter
;
import
org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ModelSyntaxException
;
import
org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.OptionalValidator
;
import
org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.UserFileValidator
;
import
org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.Validator
;
public
class
OptionalUserFileParserValidator
extends
UserFileParserValidator
{
public
OptionalUserFileParserValidator
(
String
model
)
throws
ModelSyntaxException
{
super
(
model
,
ModelType
.
OPTIONAL_USER_FILE
);
}
@Override
protected
Validator
<
String
>
createValidator
(
String
model
,
Converter
<
String
>
converter
)
{
return
new
OptionalValidator
<>(
new
UserFileValidator
());
}
}
scheduler/scheduler-api/src/main/java/org/ow2/proactive/scheduler/common/job/factories/spi/model/factory/URIParserValidator.java
View file @
697de0d9
...
...
@@ -25,28 +25,30 @@
*/
package
org.ow2.proactive.scheduler.common.job.factories.spi.model.factory
;
import
java.net.URI
;
import
org.ow2.proactive.scheduler.common.job.factories.spi.model.converter.Converter
;
import
org.ow2.proactive.scheduler.common.job.factories.spi.model.converter.
URI
Converter
;
import
org.ow2.proactive.scheduler.common.job.factories.spi.model.converter.
Identity
Converter
;
import
org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ModelSyntaxException
;
import
org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.
AcceptAll
Validator
;
import
org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.
URI
Validator
;
import
org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.Validator
;
public
class
URIParserValidator
extends
BaseParserValidator
<
URI
>
{
public
class
URIParserValidator
extends
BaseParserValidator
<
String
>
{
public
URIParserValidator
(
String
model
)
throws
ModelSyntaxException
{
super
(
model
,
ModelType
.
URI
);
}
public
URIParserValidator
(
String
model
,
ModelType
type
)
throws
ModelSyntaxException
{
super
(
model
,
type
);
}
@Override
protected
Converter
<
URI
>
createConverter
(
String
model
)
throws
ModelSyntaxException
{
return
new
URI
Converter
();
protected
Converter
<
String
>
createConverter
(
String
model
)
throws
ModelSyntaxException
{
return
new
Identity
Converter
();
}
@Override
protected
Validator
<
URI
>
createValidator
(
String
model
,
Converter
<
URI
>
converter
)
throws
ModelSyntaxException
{
return
new
AcceptAll
Validator
<>
();
protected
Validator
<
String
>
createValidator
(
String
model
,
Converter
<
String
>
converter
)
{
return
new
URI
Validator
();
}
}
scheduler/scheduler-api/src/main/java/org/ow2/proactive/scheduler/common/job/factories/spi/model/factory/URLParserValidator.java
View file @
697de0d9
...
...
@@ -25,28 +25,30 @@
*/
package
org.ow2.proactive.scheduler.common.job.factories.spi.model.factory
;
import
java.net.URL
;
import
org.ow2.proactive.scheduler.common.job.factories.spi.model.converter.Converter
;
import
org.ow2.proactive.scheduler.common.job.factories.spi.model.converter.
URL
Converter
;
import
org.ow2.proactive.scheduler.common.job.factories.spi.model.converter.
Identity
Converter
;
import
org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ModelSyntaxException
;
import
org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.
AcceptAll
Validator
;
import
org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.
URL
Validator
;
import
org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.Validator
;
public
class
URLParserValidator
extends
BaseParserValidator
<
URL
>
{
public
class
URLParserValidator
extends
BaseParserValidator
<
String
>
{
public
URLParserValidator
(
String
model
)
throws
ModelSyntaxException
{
super
(
model
,
ModelType
.
URL
);
}
public
URLParserValidator
(
String
model
,
ModelType
type
)
throws
ModelSyntaxException
{
super
(
model
,
type
);
}
@Override
protected
Converter
<
URL
>
createConverter
(
String
model
)
throws
ModelSyntaxException
{
return
new
URL
Converter
();
protected
Converter
<
String
>
createConverter
(
String
model
)
throws
ModelSyntaxException
{
return
new
Identity
Converter
();
}
@Override
protected
Validator
<
URL
>
createValidator
(
String
model
,
Converter
<
URL
>
converter
)
throws
ModelSyntaxException
{
return
new
AcceptAll
Validator
<>
();
protected
Validator
<
String
>
createValidator
(
String
model
,
Converter
<
String
>
converter
)
{
return
new
URL
Validator
();
}
}
scheduler/scheduler-api/src/main/java/org/ow2/proactive/scheduler/common/job/factories/spi/model/factory/UserFileParserValidator.java
View file @
697de0d9
...
...
@@ -38,6 +38,10 @@ public class UserFileParserValidator extends BaseParserValidator<String> {
super
(
model
,
ModelType
.
USER_FILE
);
}
public
UserFileParserValidator
(
String
model
,
ModelType
type
)
throws
ModelSyntaxException
{
super
(
model
,
type
);
}
@Override
protected
Converter
<
String
>
createConverter
(
String
model
)
throws
ModelSyntaxException
{
return
new
IdentityConverter
();
...
...
scheduler/scheduler-api/src/main/java/org/ow2/proactive/scheduler/common/job/factories/spi/model/validator/OptionalValidator.java
0 → 100644
View file @
697de0d9
/*
* ProActive Parallel Suite(TM):
* The Open Source library for parallel and distributed
* Workflows & Scheduling, Orchestration, Cloud Automation
* and Big Data Analysis on Enterprise Grids & Clouds.
*
* Copyright (c) 2007 - 2017 ActiveEon
* Contact: contact@activeeon.com
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation: version 3 of
* the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* If needed, contact us to obtain a release under GPL Version 2 or 3
* or a different license than the AGPL.
*/
package
org.ow2.proactive.scheduler.common.job.factories.spi.model.validator
;
import
org.apache.commons.lang3.StringUtils
;
import
org.ow2.proactive.scheduler.common.job.factories.spi.model.ModelValidatorContext
;
import
org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ValidationException
;
/**
* Validate all the blank parameter value. When the value is not blank, use its specific validator to check the value validity.
* @param <T>
*/
public
class
OptionalValidator
<
T
>
implements
Validator
<
T
>
{
Validator
<
T
>
validator
;
public
OptionalValidator
(
Validator
<
T
>
validator
)
{
this
.
validator
=
validator
;
}
@Override
public
T
validate
(
T
parameterValue
,
ModelValidatorContext
context
)
throws
ValidationException
{
// When the parameter value is not provided, it's validated. Otherwise, use its proper validator
if
(
StringUtils
.
isBlank
(
parameterValue
.
toString
()))
{
return
parameterValue
;
}
else
{
return
validator
.
validate
(
parameterValue
,
context
);
}
}
}
scheduler/scheduler-api/src/main/java/org/ow2/proactive/scheduler/common/job/factories/spi/model/
converter/URIConverte
r.java
→
scheduler/scheduler-api/src/main/java/org/ow2/proactive/scheduler/common/job/factories/spi/model/
validator/URIValidato
r.java
View file @
697de0d9
...
...
@@ -23,21 +23,27 @@
* If needed, contact us to obtain a release under GPL Version 2 or 3
* or a different license than the AGPL.
*/
package
org.ow2.proactive.scheduler.common.job.factories.spi.model.
converte
r
;
package
org.ow2.proactive.scheduler.common.job.factories.spi.model.
validato
r
;
import
java.net.URI
;
import
java.net.URISyntaxException
;
import
org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ConversionException
;
import
org.ow2.proactive.scheduler.common.job.factories.spi.model.ModelValidatorContext
;
import
org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ValidationException
;
public
class
URIConverter
implements
Converter
<
URI
>
{
/**
* @author ActiveEon Team
* @since 19/08/19s
*/
public
class
URIValidator
implements
Validator
<
String
>
{
@Override
public
URI
convert
(
String
parameterValue
)
throws
Convers
ionException
{
public
String
validate
(
String
parameterValue
,
ModelValidatorContext
context
)
throws
Validat
ionException
{
try
{
return
new
URI
(
parameterValue
);
return
new
URI
(
parameterValue
)
.
toString
()
;
}
catch
(
URISyntaxException
e
)
{
throw
new
Convers
ionException
(
parameterValue
,
URI
.
class
,
e
.
getMessage
()
,
e
);
throw
new
Validat
ionException
(
parameterValue
+
" is not a valid URI."
,
e
);
}
}
}
scheduler/scheduler-api/src/main/java/org/ow2/proactive/scheduler/common/job/factories/spi/model/
converter/URLConverte
r.java
→
scheduler/scheduler-api/src/main/java/org/ow2/proactive/scheduler/common/job/factories/spi/model/
validator/URLValidato
r.java
View file @
697de0d9
...
...
@@ -23,21 +23,27 @@
* If needed, contact us to obtain a release under GPL Version 2 or 3
* or a different license than the AGPL.
*/
package
org.ow2.proactive.scheduler.common.job.factories.spi.model.
converte
r
;
package
org.ow2.proactive.scheduler.common.job.factories.spi.model.
validato
r
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ConversionException
;
import
org.ow2.proactive.scheduler.common.job.factories.spi.model.ModelValidatorContext
;
import
org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ValidationException
;
public
class
URLConverter
implements
Converter
<
URL
>
{
/**
* @author ActiveEon Team
* @since 19/08/19s
*/
public
class
URLValidator
implements
Validator
<
String
>
{
@Override
public
URL
convert
(
String
parameterValue
)
throws
Convers
ionException
{
public
String
validate
(
String
parameterValue
,
ModelValidatorContext
context
)
throws
Validat
ionException
{
try
{
return
new
URL
(
parameterValue
);
return
new
URL
(
parameterValue
)
.
toString
()
;
}
catch
(
MalformedURLException
e
)
{
throw
new
Convers
ionException
(
parameterValue
,
URL
.
class
,
e
.
getMessage
()
,
e
);
throw
new
Validat
ionException
(
parameterValue
+
" is not a valid URL."
,
e
);
}
}
}
scheduler/scheduler-api/src/test/java/org/ow2/proactive/scheduler/common/job/factories/spi/model/factory/GlobalFileParserValidatorTest.java
0 → 100644
View file @
697de0d9
/*
* ProActive Parallel Suite(TM):
* The Open Source library for parallel and distributed
* Workflows & Scheduling, Orchestration, Cloud Automation
* and Big Data Analysis on Enterprise Grids & Clouds.
*
* Copyright (c) 2007 - 2017 ActiveEon
* Contact: contact@activeeon.com
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation: version 3 of
* the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* If needed, contact us to obtain a release under GPL Version 2 or 3
* or a different license than the AGPL.
*/
package
org.ow2.proactive.scheduler.common.job.factories.spi.model.factory
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
static
org
.
ow2
.
proactive
.
scheduler
.
common
.
SchedulerConstants
.
GLOBALSPACE_NAME
;
import
org.junit.Assert
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.mockito.Mock
;
import
org.mockito.MockitoAnnotations
;
import
org.ow2.proactive.scheduler.common.SchedulerSpaceInterface
;
import
org.ow2.proactive.scheduler.common.exception.NotConnectedException
;
import
org.ow2.proactive.scheduler.common.exception.PermissionException
;
import
org.ow2.proactive.scheduler.common.job.factories.spi.model.ModelValidatorContext
;
import
org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ConversionException
;
import
org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ModelSyntaxException
;
import
org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ValidationException
;
public
class
GlobalFileParserValidatorTest
{
final
String
existGlobalFilePath
=
"global folder/exist-file.txt"
;
final
String
notExistGlobalFilePath
=
"not-exist-file.png"
;
@Mock
private
ModelValidatorContext
context
;
@Mock
private
SchedulerSpaceInterface
schedulerSpaceInterface
;
@Before
public
void
init
()
throws
NotConnectedException
,
PermissionException
{
MockitoAnnotations
.
initMocks
(
this
);
when
(
context
.
getSpace
()).
thenReturn
(
schedulerSpaceInterface
);
when
(
schedulerSpaceInterface
.
checkFileExists
(
GLOBALSPACE_NAME
,
existGlobalFilePath
)).
thenReturn
(
true
);
when
(
schedulerSpaceInterface
.
checkFileExists
(
GLOBALSPACE_NAME
,
notExistGlobalFilePath
)).
thenReturn
(
false
);
}
@Test
public
void
testThatValidGlobalFileIsOk
()
throws
ModelSyntaxException
,
ValidationException
,
ConversionException
{
String
value
=
existGlobalFilePath
;
GlobalFileParserValidator
parserValidator
=
new
GlobalFileParserValidator
(
ModelType
.
GLOBAL_FILE
.
name
());
Assert
.
assertEquals
(
value
,
parserValidator
.
parseAndValidate
(
value
,
context
));
}
@Test
(
expected
=
ValidationException
.
class
)
public
void
testThatInvalidGlobalFileThrowException
()
throws
ModelSyntaxException
,
ValidationException
,
ConversionException
{
GlobalFileParserValidator
parserValidator
=
new
GlobalFileParserValidator
(
ModelType
.
GLOBAL_FILE
.
name
());
parserValidator
.
parseAndValidate
(
notExistGlobalFilePath
,
context
);
}
@Test
(
expected
=
ValidationException
.
class
)
public
void
testThatEmptyGlobalFileThrowException
()
throws
ModelSyntaxException
,
ValidationException
,
ConversionException
{
String
value
=
""
;
GlobalFileParserValidator
parserValidator
=
new
GlobalFileParserValidator
(
ModelType
.
GLOBAL_FILE
.
name
());
parserValidator
.
parseAndValidate
(
value
,
context
);
}
// when context is not specified, the parserValidator is expected to not check global file existence.
@Test
public
void
testThatGivenNoContextEmptyGlobalFileIsOK
()
throws
ModelSyntaxException
,
ValidationException
,
ConversionException
{
String
value
=
""
;
GlobalFileParserValidator
parserValidator
=
new
GlobalFileParserValidator
(
ModelType
.
GLOBAL_FILE
.
name
());
Assert
.
assertEquals
(
value
,
parserValidator
.
parseAndValidate
(
value
,
null
));