-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #231: CAS not reset if validation fails in managed CASes
- Fix issue that CAS is not reset if validation fails - Added unit tests
- Loading branch information
Showing
7 changed files
with
192 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
uimafit-junit/src/test/java/org/apache/uima/fit/testing/junit/ManagedCasTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.uima.fit.testing.junit; | ||
|
||
import static java.util.Arrays.asList; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType; | ||
|
||
import org.apache.uima.cas.CAS; | ||
import org.apache.uima.fit.validation.ValidationResult; | ||
import org.apache.uima.fit.validation.Validator; | ||
import org.junit.jupiter.api.Test; | ||
import org.opentest4j.AssertionFailedError; | ||
|
||
class ManagedCasTest { | ||
|
||
private ManagedCas sut = new ManagedCas(); | ||
|
||
@Test | ||
void thatValidatorIsResetBeforeNextTest() throws Exception { | ||
Validator defaultValidator = sut.getValidator(); | ||
Validator transientValidator = new Validator.Builder().build(); | ||
sut.withValidator(transientValidator); | ||
assertThat(sut.getValidator()).isSameAs(transientValidator); | ||
sut.afterTestExecution(null); | ||
assertThat(sut.getValidator()).isSameAs(defaultValidator); | ||
} | ||
|
||
@Test | ||
void thatCasIsResetBeforeNextTest() throws Exception { | ||
CAS cas = sut.get(); | ||
cas.setDocumentText("test"); | ||
sut.afterTestExecution(null); | ||
assertThat(cas.getDocumentText()).isNull(); | ||
} | ||
|
||
@Test | ||
void thatCasIsResetBeforeNextTestIfValidationFails() throws Exception { | ||
sut.withValidator(new Validator.Builder() | ||
.withCheck(cas -> asList(ValidationResult.error(this, "fail"))).build()); | ||
CAS cas = sut.get(); | ||
cas.setDocumentText("test"); | ||
assertThatExceptionOfType(AssertionFailedError.class) // | ||
.as("Validation should fail") // | ||
.isThrownBy(() -> sut.afterTestExecution(null)); | ||
assertThat(cas.getDocumentText()) // | ||
.as("Despite failed validation, CAS should have been reset") // | ||
.isNull(); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
uimafit-junit/src/test/java/org/apache/uima/fit/testing/junit/ManagedJCasTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.uima.fit.testing.junit; | ||
|
||
import static java.util.Arrays.asList; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType; | ||
|
||
import org.apache.uima.fit.validation.ValidationResult; | ||
import org.apache.uima.fit.validation.Validator; | ||
import org.apache.uima.jcas.JCas; | ||
import org.junit.jupiter.api.Test; | ||
import org.opentest4j.AssertionFailedError; | ||
|
||
class ManagedJCasTest { | ||
|
||
private ManagedJCas sut = new ManagedJCas(); | ||
|
||
@Test | ||
void thatValidatorIsResetBeforeNextTest() throws Exception { | ||
Validator defaultValidator = sut.getValidator(); | ||
Validator transientValidator = new Validator.Builder().build(); | ||
sut.withValidator(transientValidator); | ||
assertThat(sut.getValidator()).isSameAs(transientValidator); | ||
sut.afterTestExecution(null); | ||
assertThat(sut.getValidator()).isSameAs(defaultValidator); | ||
} | ||
|
||
@Test | ||
void thatCasIsResetBeforeNextTest() throws Exception { | ||
JCas cas = sut.get(); | ||
cas.setDocumentText("test"); | ||
sut.afterTestExecution(null); | ||
assertThat(cas.getDocumentText()).isNull(); | ||
} | ||
|
||
@Test | ||
void thatCasIsResetBeforeNextTestIfValidationFails() throws Exception { | ||
sut.withValidator(new Validator.Builder() | ||
.withCheck(cas -> asList(ValidationResult.error(this, "fail"))).build()); | ||
JCas cas = sut.get(); | ||
cas.setDocumentText("test"); | ||
assertThatExceptionOfType(AssertionFailedError.class) // | ||
.as("Validation should fail") // | ||
.isThrownBy(() -> sut.afterTestExecution(null)); | ||
assertThat(cas.getDocumentText()) // | ||
.as("Despite failed validation, JCAS should have been reset") // | ||
.isNull(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters