diff --git a/pom.xml b/pom.xml index 3b25a4f6835b189094a4cc9ac4ea27eaa7e1b7b3..8c59794942d9ccc7b1de11a833f7a612e55b6f2d 100644 --- a/pom.xml +++ b/pom.xml @@ -84,7 +84,6 @@ See the Licence for the specific language governing permissions and limitations <cxf.version>3.5.7</cxf.version> <ehcache.version>2.10.9.2</ehcache.version> <h2.version>2.2.224</h2.version> - <hamcrest-junit.version>2.0.0.0</hamcrest-junit.version> <hamcrest.version>2.2</hamcrest.version> <hibernate-jpa.version>1.0.2.Final</hibernate-jpa.version> <hibernate.validator.version>7.0.5.Final</hibernate.validator.version> @@ -98,7 +97,6 @@ See the Licence for the specific language governing permissions and limitations <org.glassfish.jaxb.jaxb-runtime.version>2.3.9</org.glassfish.jaxb.jaxb-runtime.version> <jakarta.xml.bind-api.version>2.3.3</jakarta.xml.bind-api.version> <jstl.version>1.2</jstl.version> - <junit.version>4.13.2</junit.version> <junit-jupiter.version>5.10.2</junit-jupiter.version> <junit-platform-surefire-provider.version>1.3.2</junit-platform-surefire-provider.version> <junitparams.version>1.1.1</junitparams.version> @@ -470,12 +468,6 @@ See the Licence for the specific language governing permissions and limitations <version>${mockito.version}</version> <scope>test</scope> </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>${junit.version}</version> - <scope>test</scope> - </dependency> <!-- Jackson--> <dependency> <groupId>com.fasterxml.jackson.core</groupId> @@ -566,12 +558,6 @@ See the Licence for the specific language governing permissions and limitations <version>${jakarta.servlet-api.version}</version> <scope>provided</scope> </dependency> - <dependency> - <groupId>pl.pragmatists</groupId> - <artifactId>JUnitParams</artifactId> - <version>${junitparams.version}</version> - <scope>test</scope> - </dependency> <dependency> <groupId>org.xmlunit</groupId> <artifactId>xmlunit-core</artifactId> @@ -590,12 +576,6 @@ See the Licence for the specific language governing permissions and limitations <version>${hamcrest.version}</version> <scope>test</scope> </dependency> - <dependency> - <groupId>org.hamcrest</groupId> - <artifactId>hamcrest-junit</artifactId> - <version>${hamcrest-junit.version}</version> - <scope>test</scope> - </dependency> <!-- Test dependencies --> <dependency> <groupId>org.springframework.boot</groupId> @@ -632,12 +612,6 @@ See the Licence for the specific language governing permissions and limitations <version>${junit-jupiter.version}</version> <scope>test</scope> </dependency> - <dependency> - <groupId>org.junit.vintage</groupId> - <artifactId>junit-vintage-engine</artifactId> - <version>${junit-jupiter.version}</version> - <scope>test</scope> - </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-params</artifactId> diff --git a/smp-examples/resource-spi-example/pom.xml b/smp-examples/resource-spi-example/pom.xml index 61b867b57d4cc78444e3761a6736b2bd443a2949..95d69ec40cfbd22c0de19ad2271cd8fe2601f720 100644 --- a/smp-examples/resource-spi-example/pom.xml +++ b/smp-examples/resource-spi-example/pom.xml @@ -61,11 +61,6 @@ <artifactId>mockito-core</artifactId> <scope>test</scope> </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-inline</artifactId> diff --git a/smp-examples/resource-spi-example/src/test/java/eu/europa/ec/smp/spi/examples/handler/AbstractHandlerTest.java b/smp-examples/resource-spi-example/src/test/java/eu/europa/ec/smp/spi/examples/handler/AbstractHandlerTest.java index d3414f365e3a55e91db62a12bd700a770eec1079..8303c04388368ca6f4174d8120f8aa9775ec80bd 100644 --- a/smp-examples/resource-spi-example/src/test/java/eu/europa/ec/smp/spi/examples/handler/AbstractHandlerTest.java +++ b/smp-examples/resource-spi-example/src/test/java/eu/europa/ec/smp/spi/examples/handler/AbstractHandlerTest.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -31,7 +31,7 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.util.Collections; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; abstract class AbstractHandlerTest { protected SmpDataServiceApi mockSmpDataApi = Mockito.mock(SmpDataServiceApi.class); @@ -77,7 +77,7 @@ abstract class AbstractHandlerTest { Mockito.when(mockSmpIdentifierServiceApi.normalizeSubresourceIdentifier(Mockito.anyString(), Mockito.anyString())).thenAnswer(i -> new ResourceIdentifier((String) i.getArguments()[0], (String) i.getArguments()[1])); } Mockito.when(mockSmpIdentifierServiceApi.normalizeResourceIdentifier(Mockito.anyString(), Mockito.anyString())).thenAnswer(i -> new ResourceIdentifier((String) i.getArguments()[0], (String) i.getArguments()[1])); - Mockito.doReturn(resourceIdentifier.getScheme()+"::"+resourceIdentifier.getValue()).when(mockSmpIdentifierServiceApi).formatResourceIdentifier(resourceIdentifier); + Mockito.doReturn(resourceIdentifier.getScheme() + "::" + resourceIdentifier.getValue()).when(mockSmpIdentifierServiceApi).formatResourceIdentifier(resourceIdentifier); getTestInstance().storeResource(requestData, responseData); } @@ -95,7 +95,7 @@ abstract class AbstractHandlerTest { Mockito.doReturn(AbstractHandlerTest.class.getResourceAsStream(resourceName)).when(requestData).getResourceInputStream(); Mockito.doReturn(resourceIdentifier).when(requestData).getResourceIdentifier(); Mockito.when(mockSmpIdentifierServiceApi.normalizeResourceIdentifier(Mockito.anyString(), Mockito.anyString())).thenAnswer(i -> new ResourceIdentifier((String) i.getArguments()[0], (String) i.getArguments()[1])); - Mockito.doReturn(resourceIdentifier.getScheme()+"::"+resourceIdentifier.getValue()).when(mockSmpIdentifierServiceApi).formatResourceIdentifier(resourceIdentifier); + Mockito.doReturn(resourceIdentifier.getScheme() + "::" + resourceIdentifier.getValue()).when(mockSmpIdentifierServiceApi).formatResourceIdentifier(resourceIdentifier); getTestInstance().validateResource(requestData); @@ -109,7 +109,7 @@ abstract class AbstractHandlerTest { void generateResourceAction(ResourceIdentifier resourceIdentifier, ResourceIdentifier subresourceIdentifier) throws ResourceException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); Mockito.doReturn(resourceIdentifier).when(requestData).getResourceIdentifier(); - Mockito.doReturn(resourceIdentifier.getScheme()+"::"+resourceIdentifier.getValue()).when(mockSmpIdentifierServiceApi).formatResourceIdentifier(resourceIdentifier); + Mockito.doReturn(resourceIdentifier.getScheme() + "::" + resourceIdentifier.getValue()).when(mockSmpIdentifierServiceApi).formatResourceIdentifier(resourceIdentifier); if (subresourceIdentifier != null) { Mockito.doReturn(subresourceIdentifier).when(requestData).getSubresourceIdentifier(); diff --git a/smp-examples/resource-spi-example/src/test/java/eu/europa/ec/smp/spi/examples/handler/DomiSMPJSONHandlerExampleTest.java b/smp-examples/resource-spi-example/src/test/java/eu/europa/ec/smp/spi/examples/handler/DomiSMPJSONHandlerExampleTest.java index ecb54157cb527f995631a82256685b6c5cf244c1..6224a4a63c407cacdde79c1f6016c4772a10c10a 100644 --- a/smp-examples/resource-spi-example/src/test/java/eu/europa/ec/smp/spi/examples/handler/DomiSMPJSONHandlerExampleTest.java +++ b/smp-examples/resource-spi-example/src/test/java/eu/europa/ec/smp/spi/examples/handler/DomiSMPJSONHandlerExampleTest.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -23,8 +23,7 @@ import eu.europa.ec.smp.spi.exceptions.ResourceException; import org.hamcrest.MatcherAssert; import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertThrows; - +import static org.junit.jupiter.api.Assertions.assertThrows; class DomiSMPJSONHandlerExampleTest extends AbstractHandlerTest { diff --git a/smp-examples/resource-spi-example/src/test/java/eu/europa/ec/smp/spi/examples/handler/DomiSMPPropertyHandlerExampleTest.java b/smp-examples/resource-spi-example/src/test/java/eu/europa/ec/smp/spi/examples/handler/DomiSMPPropertyHandlerExampleTest.java index fb0ac0df8f42c753634b4508a89d97c65ad857da..87f07c8db588dd197a464ee01ec3b26cf5bb655a 100644 --- a/smp-examples/resource-spi-example/src/test/java/eu/europa/ec/smp/spi/examples/handler/DomiSMPPropertyHandlerExampleTest.java +++ b/smp-examples/resource-spi-example/src/test/java/eu/europa/ec/smp/spi/examples/handler/DomiSMPPropertyHandlerExampleTest.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -23,7 +23,7 @@ import eu.europa.ec.smp.spi.exceptions.ResourceException; import org.hamcrest.MatcherAssert; import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; class DomiSMPPropertyHandlerExampleTest extends AbstractHandlerTest { diff --git a/smp-resource-extensions/oasis-cppa3-spi/pom.xml b/smp-resource-extensions/oasis-cppa3-spi/pom.xml index 8a4bceac566e2513830dccc64e2849ceae0a2b71..ad64358fcc62a66776f509198b27f619eac1d9fc 100644 --- a/smp-resource-extensions/oasis-cppa3-spi/pom.xml +++ b/smp-resource-extensions/oasis-cppa3-spi/pom.xml @@ -54,11 +54,6 @@ <artifactId>mockito-core</artifactId> <scope>test</scope> </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-inline</artifactId> diff --git a/smp-resource-extensions/oasis-cppa3-spi/src/test/java/eu/europa/ec/smp/spi/handler/AbstractHandlerTest.java b/smp-resource-extensions/oasis-cppa3-spi/src/test/java/eu/europa/ec/smp/spi/handler/AbstractHandlerTest.java index 0fcf42504bd50c3ed44f2b12206f751bf6712ebe..764815d9a98f790803443a4598dacd685198c7e9 100644 --- a/smp-resource-extensions/oasis-cppa3-spi/src/test/java/eu/europa/ec/smp/spi/handler/AbstractHandlerTest.java +++ b/smp-resource-extensions/oasis-cppa3-spi/src/test/java/eu/europa/ec/smp/spi/handler/AbstractHandlerTest.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -31,7 +31,7 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.util.Collections; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; abstract class AbstractHandlerTest { protected SmpDataServiceApi mockSmpDataApi = Mockito.mock(SmpDataServiceApi.class); @@ -96,7 +96,6 @@ abstract class AbstractHandlerTest { Mockito.when(mockSmpIdentifierServiceApi.normalizeResourceIdentifier(Mockito.anyString(), Mockito.anyString())).thenAnswer(i -> new ResourceIdentifier((String) i.getArguments()[0], (String) i.getArguments()[1])); - getTestInstance().validateResource(requestData); } diff --git a/smp-resource-extensions/oasis-cppa3-spi/src/test/java/eu/europa/ec/smp/spi/handler/OasisCppa3CppHandlerTest.java b/smp-resource-extensions/oasis-cppa3-spi/src/test/java/eu/europa/ec/smp/spi/handler/OasisCppa3CppHandlerTest.java index 23511fbcf1f38b7c38e27f4388880883388a8d44..7b6d1e79d759cf5fe09339ffad05951291ed4af8 100644 --- a/smp-resource-extensions/oasis-cppa3-spi/src/test/java/eu/europa/ec/smp/spi/handler/OasisCppa3CppHandlerTest.java +++ b/smp-resource-extensions/oasis-cppa3-spi/src/test/java/eu/europa/ec/smp/spi/handler/OasisCppa3CppHandlerTest.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -24,7 +24,7 @@ import eu.europa.ec.smp.spi.exceptions.ResourceException; import org.hamcrest.MatcherAssert; import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; public class OasisCppa3CppHandlerTest extends AbstractHandlerTest { diff --git a/smp-resource-extensions/oasis-smp-spi/pom.xml b/smp-resource-extensions/oasis-smp-spi/pom.xml index e04e24e48c14761807f9b5cfa2f81ad65c36eb45..c3f9ab3d5947ffaeefd7c87c86cba606d15c4717 100644 --- a/smp-resource-extensions/oasis-smp-spi/pom.xml +++ b/smp-resource-extensions/oasis-smp-spi/pom.xml @@ -56,11 +56,6 @@ <artifactId>mockito-core</artifactId> <scope>test</scope> </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-inline</artifactId> diff --git a/smp-resource-extensions/oasis-smp-spi/src/test/java/eu/europa/ec/smp/spi/handler/AbstractHandlerTest.java b/smp-resource-extensions/oasis-smp-spi/src/test/java/eu/europa/ec/smp/spi/handler/AbstractHandlerTest.java index d5231722231c780f93a2f5331b02c389b61f0373..5410843959f436a3d16f3e809470639f4dbb8cf1 100644 --- a/smp-resource-extensions/oasis-smp-spi/src/test/java/eu/europa/ec/smp/spi/handler/AbstractHandlerTest.java +++ b/smp-resource-extensions/oasis-smp-spi/src/test/java/eu/europa/ec/smp/spi/handler/AbstractHandlerTest.java @@ -32,7 +32,7 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.util.Collections; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; abstract class AbstractHandlerTest { protected SmpDataServiceApi mockSmpDataApi = Mockito.mock(SmpDataServiceApi.class); diff --git a/smp-resource-extensions/oasis-smp-spi/src/test/java/eu/europa/ec/smp/spi/handler/OasisSMPResource10HandlerTest.java b/smp-resource-extensions/oasis-smp-spi/src/test/java/eu/europa/ec/smp/spi/handler/OasisSMPResource10HandlerTest.java index 4baafd85b714abdd96a962e9457ef451a88d9d55..9f61819f30de2f263beba01eeaeebfbd1d4733dd 100644 --- a/smp-resource-extensions/oasis-smp-spi/src/test/java/eu/europa/ec/smp/spi/handler/OasisSMPResource10HandlerTest.java +++ b/smp-resource-extensions/oasis-smp-spi/src/test/java/eu/europa/ec/smp/spi/handler/OasisSMPResource10HandlerTest.java @@ -23,7 +23,8 @@ import eu.europa.ec.smp.spi.exceptions.ResourceException; import org.hamcrest.MatcherAssert; import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; + class OasisSMPResource10HandlerTest extends AbstractHandlerTest { @Override diff --git a/smp-resource-extensions/oasis-smp-spi/src/test/java/eu/europa/ec/smp/spi/handler/OasisSMPResource20HandlerTest.java b/smp-resource-extensions/oasis-smp-spi/src/test/java/eu/europa/ec/smp/spi/handler/OasisSMPResource20HandlerTest.java index 10c5d368accfeefd7f6b2c57e8cc860acec4e171..982f7bf3e6edf3f5d510fd6f54d9c8b953ea161d 100644 --- a/smp-resource-extensions/oasis-smp-spi/src/test/java/eu/europa/ec/smp/spi/handler/OasisSMPResource20HandlerTest.java +++ b/smp-resource-extensions/oasis-smp-spi/src/test/java/eu/europa/ec/smp/spi/handler/OasisSMPResource20HandlerTest.java @@ -23,7 +23,7 @@ import eu.europa.ec.smp.spi.exceptions.ResourceException; import org.hamcrest.MatcherAssert; import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; class OasisSMPResource20HandlerTest extends AbstractHandlerTest { @Override diff --git a/smp-resource-extensions/oasis-smp-spi/src/test/java/eu/europa/ec/smp/spi/handler/OasisSMPSubresource10HandlerTest.java b/smp-resource-extensions/oasis-smp-spi/src/test/java/eu/europa/ec/smp/spi/handler/OasisSMPSubresource10HandlerTest.java index 297a604bcc0ecf1198346d798af364055c7b7126..e7b0bf97b5dd08efd1229c35278905b223837f8a 100644 --- a/smp-resource-extensions/oasis-smp-spi/src/test/java/eu/europa/ec/smp/spi/handler/OasisSMPSubresource10HandlerTest.java +++ b/smp-resource-extensions/oasis-smp-spi/src/test/java/eu/europa/ec/smp/spi/handler/OasisSMPSubresource10HandlerTest.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -24,7 +24,7 @@ import eu.europa.ec.smp.spi.validation.Subresource10Validator; import org.hamcrest.MatcherAssert; import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; class OasisSMPSubresource10HandlerTest extends AbstractHandlerTest { diff --git a/smp-resource-extensions/oasis-smp-spi/src/test/java/eu/europa/ec/smp/spi/handler/OasisSMPSubresource20HandlerTest.java b/smp-resource-extensions/oasis-smp-spi/src/test/java/eu/europa/ec/smp/spi/handler/OasisSMPSubresource20HandlerTest.java index 7d44e700eaa279aa40f878e92666432c901ba1cf..8c43587af5885e8df0d6da25d8c7f01d861be661 100644 --- a/smp-resource-extensions/oasis-smp-spi/src/test/java/eu/europa/ec/smp/spi/handler/OasisSMPSubresource20HandlerTest.java +++ b/smp-resource-extensions/oasis-smp-spi/src/test/java/eu/europa/ec/smp/spi/handler/OasisSMPSubresource20HandlerTest.java @@ -24,7 +24,7 @@ import eu.europa.ec.smp.spi.validation.Subresource20Validator; import org.hamcrest.MatcherAssert; import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; class OasisSMPSubresource20HandlerTest extends AbstractHandlerTest { diff --git a/smp-server-library/pom.xml b/smp-server-library/pom.xml index a0702d784661dfc71322c4f920d6d062273b6cc3..ddfe59831ed3a14358db0f71dfd45f2c4e833c65 100644 --- a/smp-server-library/pom.xml +++ b/smp-server-library/pom.xml @@ -150,39 +150,16 @@ <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> </dependency> - - <!-- Test dependencies --> - <dependency> - <groupId>org.hamcrest</groupId> - <artifactId>hamcrest-junit</artifactId> - - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-engine</artifactId> <scope>test</scope> </dependency> - <dependency> - <groupId>org.junit.vintage</groupId> - <artifactId>junit-vintage-engine</artifactId> - <scope>test</scope> - </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-params</artifactId> <scope>test</scope> </dependency> - - <dependency> - <groupId>pl.pragmatists</groupId> - <artifactId>JUnitParams</artifactId> - <scope>test</scope> - </dependency> <dependency> <groupId>org.xmlunit</groupId> <artifactId>xmlunit-core</artifactId> diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/auth/SMPUserDetailsTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/auth/SMPUserDetailsTest.java index 5ebaf3f1b928c3ca7ef8af14a5cffec2de272db5..c1974d06108604d2e520d2ca4dfbb72b49129aea 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/auth/SMPUserDetailsTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/auth/SMPUserDetailsTest.java @@ -21,17 +21,17 @@ package eu.europa.ec.edelivery.smp.auth; import eu.europa.ec.edelivery.security.utils.SecurityUtils; import eu.europa.ec.edelivery.smp.data.model.user.DBUser; import eu.europa.ec.edelivery.smp.data.ui.auth.SMPAuthority; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Collections; import java.util.List; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -public class SMPUserDetailsTest { +class SMPUserDetailsTest { @Test - public void testInitSMPUserDetailsTest() { + void testInitSMPUserDetailsTest() { DBUser user = new DBUser(); SecurityUtils.Secret secret = SecurityUtils.generatePrivateSymmetricKey(true); List<SMPAuthority> authorityList = Collections.singletonList(SMPAuthority.S_AUTHORITY_USER); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/config/PropertyUpdateListenerTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/config/PropertyUpdateListenerTest.java index d4e68d7b20d2800008ea0a877ba57d9664d40b29..9f31cfbbd93a82bd412247fe95e488631a9a4568 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/config/PropertyUpdateListenerTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/config/PropertyUpdateListenerTest.java @@ -19,7 +19,7 @@ package eu.europa.ec.edelivery.smp.config; import eu.europa.ec.edelivery.smp.config.enums.SMPPropertyEnum; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; @@ -29,9 +29,9 @@ import java.util.Map; import static eu.europa.ec.edelivery.smp.config.enums.SMPPropertyEnum.ACCESS_TOKEN_FAIL_DELAY; import static eu.europa.ec.edelivery.smp.config.enums.SMPPropertyEnum.SMP_PROPERTY_REFRESH_CRON; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -public class PropertyUpdateListenerTest { +class PropertyUpdateListenerTest { PropertyUpdateListener testInstance = Mockito.spy(new PropertyUpdateListener() { @Override @@ -45,13 +45,13 @@ public class PropertyUpdateListenerTest { }); @Test - public void handlesProperty() { + void handlesProperty() { assertTrue(testInstance.handlesProperty(ACCESS_TOKEN_FAIL_DELAY)); assertFalse(testInstance.handlesProperty(SMP_PROPERTY_REFRESH_CRON)); } @Test - public void updateProperty() { + void updateProperty() { Mockito.doNothing().when(testInstance).updateProperties(Mockito.anyMap()); SMPPropertyEnum property = ACCESS_TOKEN_FAIL_DELAY; String testValue = "test"; diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/config/SMPDatabaseConfigTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/config/SMPDatabaseConfigTest.java index 784caf0efd93b45c4f84c561ed4e3080fd634a35..e579cb44ce914ab87c9efd0a1cec4c3cf2dec240 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/config/SMPDatabaseConfigTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/config/SMPDatabaseConfigTest.java @@ -23,9 +23,8 @@ import eu.europa.ec.edelivery.smp.config.init.DatabaseConnectionProperties; import eu.europa.ec.edelivery.smp.exceptions.SMPRuntimeException; import org.hamcrest.CoreMatchers; import org.hamcrest.MatcherAssert; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.jdbc.datasource.DriverManagerDataSource; import org.springframework.orm.jpa.JpaVendorAdapter; @@ -36,8 +35,7 @@ import org.springframework.transaction.PlatformTransactionManager; import javax.persistence.EntityManagerFactory; import javax.sql.DataSource; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.*; public class SMPDatabaseConfigTest { @@ -50,20 +48,20 @@ public class SMPDatabaseConfigTest { DatabaseConnectionProperties environmentProperties = Mockito.mock(DatabaseConnectionProperties.class); SMPDatabaseConfig testInstance = new SMPDatabaseConfig(); - @Before + @BeforeEach public void init(){ ReflectionTestUtils.setField(testInstance, "databaseConnectionBeanCreator", new DatabaseConnectionBeanCreator(environmentProperties)); } @Test - public void getDataSourceMissingConfiguration() { + void getDataSourceMissingConfiguration() { SMPRuntimeException result = assertThrows(SMPRuntimeException.class, () -> testInstance.getDataSource()); assertEquals("Configuration error: [Invalid datasource configuration. Both jndi or jdbc url are empty]!", result.getMessage()); } @Test - public void getJNDIForDataSourceMissing() { + void getJNDIForDataSourceMissing() { Mockito.doReturn("jdbc/eDeliverySmpDs").when(environmentProperties).getDatabaseJNDI(); SMPRuntimeException result = assertThrows(SMPRuntimeException.class, () -> testInstance.getDataSource()); @@ -72,40 +70,40 @@ public class SMPDatabaseConfigTest { } @Test - public void getDataSource() { + void getDataSource() { setJdbcProperties(); DataSource result = testInstance.getDataSource(); - Assert.assertNotNull(result); - Assert.assertEquals(DriverManagerDataSource.class, result.getClass()); + assertNotNull(result); + assertEquals(DriverManagerDataSource.class, result.getClass()); } @Test - public void jpaVendorAdapter() { + void jpaVendorAdapter() { setHibernateDatabaseDialect(); JpaVendorAdapter result = testInstance.jpaVendorAdapter(); - Assert.assertNotNull(result); + assertNotNull(result); } @Test - public void smpEntityManagerFactory() { + void smpEntityManagerFactory() { setJdbcProperties(); setHibernateDatabaseDialect(); LocalContainerEntityManagerFactoryBean result = testInstance.smpEntityManagerFactory(testInstance.getDataSource(), testInstance.jpaVendorAdapter()); - Assert.assertNotNull(result); + assertNotNull(result); } @Test - public void smpTransactionManager() { + void smpTransactionManager() { setJdbcProperties(); setHibernateDatabaseDialect(); EntityManagerFactory entityManagerFactory = testInstance.smpEntityManagerFactory(testInstance.getDataSource(), testInstance.jpaVendorAdapter()).getObject(); PlatformTransactionManager result = testInstance.smpTransactionManager(entityManagerFactory); - Assert.assertNotNull(result); + assertNotNull(result); } diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/config/SMPEnvironmentPropertiesTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/config/SMPEnvironmentPropertiesTest.java index 84333c9df97164c66fc392b958b7ff2e48920464..2fe65d4b31f90eb7c15a866b147bb795f00b2de1 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/config/SMPEnvironmentPropertiesTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/config/SMPEnvironmentPropertiesTest.java @@ -19,7 +19,7 @@ package eu.europa.ec.edelivery.smp.config; import eu.europa.ec.edelivery.smp.config.enums.SMPEnvPropertyEnum; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.nio.file.Files; @@ -31,12 +31,12 @@ import java.util.UUID; import static eu.europa.ec.edelivery.smp.config.enums.SMPPropertyEnum.CLIENT_CERT_HEADER_ENABLED_DEPRECATED; import static eu.europa.ec.edelivery.smp.config.enums.SMPPropertyEnum.EXTERNAL_TLS_AUTHENTICATION_CLIENT_CERT_HEADER_ENABLED; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -public class SMPEnvironmentPropertiesTest { +class SMPEnvironmentPropertiesTest { @Test - public void testUpdateDeprecatedValues() { + void testUpdateDeprecatedValues() { String testValue = "test"; Properties prop = new Properties(); prop.setProperty(CLIENT_CERT_HEADER_ENABLED_DEPRECATED.getProperty(), testValue); @@ -48,7 +48,7 @@ public class SMPEnvironmentPropertiesTest { } @Test - public void readPropertiesFromFile() throws IOException { + void readPropertiesFromFile() throws IOException { String value = UUID.randomUUID().toString(); Path propertyPath =Paths.get("target","testReadPropertiesFromFile.properties"); Files.write(propertyPath,("test="+value).getBytes(), StandardOpenOption.CREATE); @@ -61,7 +61,7 @@ public class SMPEnvironmentPropertiesTest { } @Test - public void readPropertiesFromClasspath() throws IOException { + void readPropertiesFromClasspath() { String classpath = "/test-smp.config.properties"; SMPEnvironmentProperties testInstance = SMPEnvironmentProperties.getInstance(); // when @@ -72,7 +72,7 @@ public class SMPEnvironmentPropertiesTest { } @Test - public void getEnvProperties() { + void getEnvProperties() { SMPEnvironmentProperties testInstance = SMPEnvironmentProperties.getInstance(); Properties properties = testInstance.getEnvProperties(); @@ -80,7 +80,7 @@ public class SMPEnvironmentPropertiesTest { } @Test - public void getEnvPropertiesForNull() { + void getEnvPropertiesForNull() { SMPEnvironmentProperties testInstance = SMPEnvironmentProperties.getInstance(); String value = testInstance.getEnvPropertyValue(SMPEnvPropertyEnum.LOG_CONFIGURATION_FILE); assertNull(value); @@ -92,14 +92,14 @@ public class SMPEnvironmentPropertiesTest { /* @Test - public void getFileProperties() { + void getFileProperties() { Properties result = SMPEnvironmentProperties.getFileProperties("/test-smp.config.properties"); assertNotNull(result); assertEquals("This property is from custom file",result.getProperty("test.read.property")); } @Test - public void getFilePropertiesLegacyFallback() { + void getFilePropertiesLegacyFallback() { Properties result = SMPEnvironmentProperties.getFileProperties("/prop-not-exists.properties"); assertNotNull(result); // in the legacy fallback file the property is defined as: ${jdbc.user} @@ -108,7 +108,7 @@ public class SMPEnvironmentPropertiesTest { @Test - public void updateLogConfigurationSetLogFolderProperty(){ + void updateLogConfigurationSetLogFolderProperty(){ String newFolderVal = "NewVal-"+ UUID.randomUUID().toString(); String currVal = System.getProperty(PROPERTY_LOG_FOLDER); SMPEnvironmentProperties.updateLogConfiguration(newFolderVal, null, null); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/config/init/SMPExtensionInitializerTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/config/init/SMPExtensionInitializerTest.java index 9035ad3f3665611e91c2121068990dfbdee0f0d4..85c6b7fa67472faa59c5f60e94cf08b05ee5f560 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/config/init/SMPExtensionInitializerTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/config/init/SMPExtensionInitializerTest.java @@ -32,7 +32,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; @ContextConfiguration( classes = {SMPExtensionInitializerTest.OasisSMPExtensionConfig.class} ) -public class SMPExtensionInitializerTest extends AbstractJunit5BaseDao { +class SMPExtensionInitializerTest extends AbstractJunit5BaseDao { @Configuration @ComponentScan({"eu.europa.ec.smp.spi"}) public static class OasisSMPExtensionConfig { @@ -47,7 +47,7 @@ public class SMPExtensionInitializerTest extends AbstractJunit5BaseDao { @Test @Transactional - public void testValidateExtensionData() { + void testValidateExtensionData() { int extensionCount = extensionDao.getAllExtensions().size(); testInstance.validateExtensionData(); // added OasisSMP extension diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/config/init/SMPKeystoreConfBuilderTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/config/init/SMPKeystoreConfBuilderTest.java index 30518d186ab149c2be2b52d332cc868a3884cc5b..2e01f80a94bf193729efa6a89fa0085dd9b496fb 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/config/init/SMPKeystoreConfBuilderTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/config/init/SMPKeystoreConfBuilderTest.java @@ -30,10 +30,10 @@ import java.security.KeyStore; import static eu.europa.ec.edelivery.smp.config.enums.SMPPropertyEnum.*; import static org.junit.jupiter.api.Assertions.assertNotNull; -public class SMPKeystoreConfBuilderTest { +class SMPKeystoreConfBuilderTest { @Test - public void testBuild(){ + void testBuild(){ File outputFolder = Paths.get("target").toFile(); SecurityUtils.Secret secret = SecurityUtils.generatePrivateSymmetricKey(true); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/conversion/DBUserToUserROConverterTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/conversion/DBUserToUserROConverterTest.java index d27da81a6605e249a1e23502c112d87c2f1e380f..9eb4a630c2eefc5353b7bb3cbb911211cd350234 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/conversion/DBUserToUserROConverterTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/conversion/DBUserToUserROConverterTest.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -26,12 +26,12 @@ import eu.europa.ec.edelivery.smp.data.model.user.DBCredential; import eu.europa.ec.edelivery.smp.data.model.user.DBUser; import eu.europa.ec.edelivery.smp.data.ui.UserRO; import eu.europa.ec.edelivery.smp.services.ConfigurationService; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.junit.platform.commons.util.StringUtils; -import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import java.time.OffsetDateTime; import java.util.List; @@ -44,8 +44,8 @@ import static org.assertj.core.api.Assertions.assertThat; * @since 4.1 */ -@RunWith(MockitoJUnitRunner.class) -public class DBUserToUserROConverterTest { +@ExtendWith(MockitoExtension.class) +class DBUserToUserROConverterTest { private DBUser source; @@ -58,7 +58,7 @@ public class DBUserToUserROConverterTest { private DBUserToUserROConverter converter = new DBUserToUserROConverter(credentialDao, configurationService); @Test - public void returnsThePasswordAsNotExpiredForCertificateOnlyUsers() { + void returnsThePasswordAsNotExpiredForCertificateOnlyUsers() { givenAnExistingCertificateOnlyUser(); whenConvertingTheExistingUser(); @@ -67,12 +67,12 @@ public class DBUserToUserROConverterTest { } @Test - public void returnsThePasswordAsExpiredWhenConvertingAnExistingUserThatHasAPasswordThatHasBeenRecentlyReset() { + void returnsThePasswordAsExpiredWhenConvertingAnExistingUserThatHasAPasswordThatHasBeenRecentlyReset() { givenAnExistingUserHavingAPasswordThatHasJustBeenReset(); List<DBCredential> credentialList = source.getUserCredentials(); Mockito.doReturn(credentialList).when(credentialDao).findUserCredentialForByUserIdTypeAndTarget(Mockito.any(), - Mockito.any(CredentialType.class), - Mockito.any(CredentialTargetType.class)); + Mockito.any(CredentialType.class), + Mockito.any(CredentialTargetType.class)); whenConvertingTheExistingUser(); @@ -81,7 +81,7 @@ public class DBUserToUserROConverterTest { } @Test - public void returnsThePasswordAsNotExpiredWhenConvertingAnExistingUserThatHasAPasswordChangedNoLongerThanThreeMonthsAgo() { + void returnsThePasswordAsNotExpiredWhenConvertingAnExistingUserThatHasAPasswordChangedNoLongerThanThreeMonthsAgo() { givenAnExistingUserHavingAPasswordThatChangedNoLongerThanThreeMonthsAgo(); whenConvertingTheExistingUser(); @@ -90,7 +90,7 @@ public class DBUserToUserROConverterTest { } @Test - public void returnsThePasswordAsExpiredWhenConvertingAnExistingUserThatHasAPasswordChangedMoreThanThreeMonthsAgo() { + void returnsThePasswordAsExpiredWhenConvertingAnExistingUserThatHasAPasswordChangedMoreThanThreeMonthsAgo() { givenAnExistingUserHavingAPasswordThatChangedMoreThanThreeMonthsAgo(); List<DBCredential> credentialList = source.getUserCredentials(); Mockito.doReturn(credentialList).when(credentialDao).findUserCredentialForByUserIdTypeAndTarget(Mockito.any(), @@ -125,8 +125,8 @@ public class DBUserToUserROConverterTest { Optional<DBCredential> optCertCred = source.getUserCredentials().stream().filter(credential -> credential.getCredentialType() == CredentialType.CERTIFICATE).findFirst(); if (StringUtils.isNotBlank(password)) { - DBCredential credential =optUserPassCred.orElse(new DBCredential()); - if (credential.getUser()==null){ + DBCredential credential = optUserPassCred.orElse(new DBCredential()); + if (credential.getUser() == null) { credential.setUser(source); credential.setCredentialType(CredentialType.USERNAME_PASSWORD); source.getUserCredentials().add(credential); @@ -138,9 +138,9 @@ public class DBUserToUserROConverterTest { source.getUserCredentials().remove(optUserPassCred.get()); } - if (certificate!=null) { - DBCredential credential =optCertCred.orElse(new DBCredential()); - if (credential.getUser()==null){ + if (certificate != null) { + DBCredential credential = optCertCred.orElse(new DBCredential()); + if (credential.getUser() == null) { credential.setUser(source); credential.setCredentialType(CredentialType.CERTIFICATE); source.getUserCredentials().add(credential); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/conversion/IdentifierServiceTests.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/conversion/IdentifierServiceTests.java index 7046d0f79455c572c9a61a0571ce2b1c74f3b739..fb97b54d2e5793ced905be7590eca47d76a0b66b 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/conversion/IdentifierServiceTests.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/conversion/IdentifierServiceTests.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -21,26 +21,23 @@ package eu.europa.ec.edelivery.smp.conversion; import eu.europa.ec.edelivery.smp.identifiers.Identifier; import eu.europa.ec.edelivery.smp.services.ConfigurationService; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.mockito.Mockito; import java.util.Arrays; import java.util.Collection; import static java.util.Arrays.asList; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotSame; /** * Created by gutowpa on 06/03/2017. */ -@RunWith(Parameterized.class) public class IdentifierServiceTests { - @Parameterized.Parameters(name = "{index}: {0}") public static Collection testCases() { return Arrays.asList(new Object[][]{ {"scheme", "value", "scheme", "value"}, @@ -53,27 +50,21 @@ public class IdentifierServiceTests { }); } - // input parameters - @Parameterized.Parameter - public String inputScheme; - @Parameterized.Parameter(1) - public String inputValue; - @Parameterized.Parameter(2) - public String expectedScheme; - @Parameterized.Parameter(3) - public String expectedValue; private final IdentifierService testInstance = new IdentifierService(Mockito.mock(ConfigurationService.class)); - @Before + @BeforeEach public void init() { testInstance.configureDocumentIdentifierFormatter(asList("case-SENSITIVE-scheme-1", "Case-SENSITIVE-Scheme-2")); testInstance.configureParticipantIdentifierFormatter(asList("case-sensitive-scheme-1", "Case-SENSITIVE-Scheme-2"), false, null); } - - @Test - public void testParticipantIdsCaseNormalization() { + @ParameterizedTest + @MethodSource("testCases") + void testParticipantIdsCaseNormalization(String inputScheme, + String inputValue, + String expectedScheme, + String expectedValue) { //given Identifier inputParticpantId = new Identifier(inputValue, inputScheme); @@ -90,8 +81,12 @@ public class IdentifierServiceTests { assertEquals(inputValue, inputParticpantId.getValue()); } - @Test - public void testDocumentIdsCaseNormalization() { + @ParameterizedTest + @MethodSource("testCases") + void testDocumentIdsCaseNormalization(String inputScheme, + String inputValue, + String expectedScheme, + String expectedValue) { //given Identifier inputDocId = new Identifier(inputValue, inputScheme); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/conversion/SmlIdentifierConverterTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/conversion/SmlIdentifierConverterTest.java index 0a6b0663031c65649c52cede9b2b4cee87acd548..b4b7811d5a4472abc510ed871206d1c3c956a35a 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/conversion/SmlIdentifierConverterTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/conversion/SmlIdentifierConverterTest.java @@ -23,15 +23,14 @@ import ec.services.wsdl.bdmsl.data._1.ParticipantsType; import ec.services.wsdl.bdmsl.data._1.SMPAdvancedServiceForParticipantType; import eu.europa.ec.edelivery.smp.identifiers.Identifier; import org.busdox.servicemetadata.locator._1.ServiceMetadataPublisherServiceForParticipantType; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.*; /** * Created by gutowpa on 08/01/2018. */ -public class SmlIdentifierConverterTest { +class SmlIdentifierConverterTest { private static final String SMP_ID = "SMP-ID"; private static final String ID_VALUE = "sample:value"; @@ -39,7 +38,7 @@ public class SmlIdentifierConverterTest { private static final String SERVICE_NAME = "naptrService"; @Test - public void toBusdoxParticipantId() { + void toBusdoxParticipantId() { //given Identifier participantId = new Identifier(ID_VALUE, ID_SCHEME); @@ -53,7 +52,7 @@ public class SmlIdentifierConverterTest { } @Test - public void toBusdoxParticipantId_NullScheme() { + void toBusdoxParticipantId_NullScheme() { //given Identifier participantId = new Identifier(ID_VALUE, null); @@ -66,7 +65,7 @@ public class SmlIdentifierConverterTest { } @Test - public void toBDMSLAdvancedParticipantId() { + void toBDMSLAdvancedParticipantId() { //given Identifier participantId = new Identifier(ID_VALUE, ID_SCHEME); @@ -80,7 +79,7 @@ public class SmlIdentifierConverterTest { } @Test - public void toBDMSLAdvancedParticipantId_NullScheme() { + void toBDMSLAdvancedParticipantId_NullScheme() { //given Identifier participantId = new Identifier(ID_VALUE, null); @@ -93,7 +92,7 @@ public class SmlIdentifierConverterTest { } @Test - public void toParticipantsType() { + void toParticipantsType() { //given Identifier participantId = new Identifier(ID_VALUE, ID_SCHEME); @@ -107,7 +106,7 @@ public class SmlIdentifierConverterTest { } @Test - public void toParticipantsType_NullScheme() { + void toParticipantsType_NullScheme() { //given Identifier participantId = new Identifier(ID_VALUE, null); @@ -119,21 +118,25 @@ public class SmlIdentifierConverterTest { assertEquals(ID_VALUE, result.getParticipantIdentifier().getValue()); } - @Test(expected = IllegalStateException.class) - public void validate_negativeCaseMissingSmpId() { + @Test + void validate_negativeCaseMissingSmpId() { //given Identifier participantId = new Identifier(ID_VALUE, ID_SCHEME); - //when - SmlIdentifierConverter.validate(participantId, null); + IllegalStateException result = assertThrows(IllegalStateException.class, + () -> SmlIdentifierConverter.validate(participantId, null)); + //then + assertEquals("SMP ID is null or empty", result.getMessage()); } - @Test(expected = IllegalStateException.class) - public void validate_negativeCaseMissingValue() { + @Test + void validate_negativeCaseMissingValue() { //given Identifier participantId = new Identifier(null, ID_SCHEME); - //when - SmlIdentifierConverter.validate(participantId, SMP_ID); + IllegalStateException result = assertThrows(IllegalStateException.class, + () -> SmlIdentifierConverter.validate(participantId, SMP_ID)); + //then + assertEquals("Participant Scheme or Id is null or empty", result.getMessage()); } } diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/conversion/UserROToDBUserConverterTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/conversion/UserROToDBUserConverterTest.java index 24ea1dfb84b8b9a02491b780fe6e5a67e5621bea..a5c6990b4ac0e3ce754dc9af114eae23ae5eb4dd 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/conversion/UserROToDBUserConverterTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/conversion/UserROToDBUserConverterTest.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -20,18 +20,18 @@ package eu.europa.ec.edelivery.smp.conversion; import eu.europa.ec.edelivery.smp.data.model.user.DBUser; import eu.europa.ec.edelivery.smp.data.ui.UserRO; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.core.convert.ConversionService; /** * @author Sebastian-Ion TINCU */ -@RunWith(MockitoJUnitRunner.class) -public class UserROToDBUserConverterTest { +@ExtendWith(MockitoExtension.class) +class UserROToDBUserConverterTest { private UserRO source; @@ -44,7 +44,7 @@ public class UserROToDBUserConverterTest { private UserROToDBUserConverter converter = new UserROToDBUserConverter(); @Test - public void doesNotSetPasswordChangedWhenConvertingUser() { + void doesNotSetPasswordChangedWhenConvertingUser() { givenUser(); whenConvertingTheUserRoSource(); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/conversion/X509CertificateToCertificateROConverterTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/conversion/X509CertificateToCertificateROConverterTest.java index 005fc336a2ac087a983aac5c044d2b16eab89b34..1eb7bd8860f3739097eb772668b55b15115f9bd1 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/conversion/X509CertificateToCertificateROConverterTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/conversion/X509CertificateToCertificateROConverterTest.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -19,10 +19,8 @@ package eu.europa.ec.edelivery.smp.conversion; import eu.europa.ec.edelivery.smp.data.ui.CertificateRO; -import junitparams.JUnitParamsRunner; -import junitparams.Parameters; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.io.InputStream; import java.security.Security; @@ -31,18 +29,16 @@ import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate; import java.time.ZoneOffset; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; -@RunWith(JUnitParamsRunner.class) -public class X509CertificateToCertificateROConverterTest { +class X509CertificateToCertificateROConverterTest { static { Security.insertProviderAt(new org.bouncycastle.jce.provider.BouncyCastleProvider(), 1); } - - private static final Object[] testCases() { + private static Object[] testCases() { return new Object[][]{ // filename, subject, issuer, serial number, clientCertHeader, certificateId, certKeyType { @@ -133,9 +129,9 @@ public class X509CertificateToCertificateROConverterTest { X509CertificateToCertificateROConverter testInstance = new X509CertificateToCertificateROConverter(); - @Test - @Parameters(method = "testCases") - public void testConvert(String filename, + @ParameterizedTest + @MethodSource("testCases") + void testConvert(String filename, String subject, String issuer, String serialNumber, @@ -160,11 +156,8 @@ public class X509CertificateToCertificateROConverterTest { assertEquals(certificate.getNotBefore().toInstant().atOffset(ZoneOffset.UTC), certRo.getValidFrom()); assertEquals(certificate.getNotAfter().toInstant().atOffset(ZoneOffset.UTC), certRo.getValidTo()); assertEquals(publicKeyType, certRo.getPublicKeyType()); - - } - X509Certificate getCertificate(String filename) throws CertificateException { CertificateFactory fact = CertificateFactory.getInstance("X.509"); InputStream is = X509CertificateToCertificateROConverterTest.class.getResourceAsStream("/certificates/" + filename); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/cron/SMPDynamicCronTriggerTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/cron/SMPDynamicCronTriggerTest.java index 6f4dfd23764599a7c832ff3224b571992c96770a..1efaab86ec1e4c0dfb66c0a994691ca6eee5b696 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/cron/SMPDynamicCronTriggerTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/cron/SMPDynamicCronTriggerTest.java @@ -19,19 +19,19 @@ package eu.europa.ec.edelivery.smp.cron; import eu.europa.ec.edelivery.smp.config.enums.SMPPropertyEnum; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.scheduling.TriggerContext; import org.springframework.scheduling.support.CronExpression; import java.time.Clock; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -public class SMPDynamicCronTriggerTest { +class SMPDynamicCronTriggerTest { @Test - public void nextExecutionTime() { + void nextExecutionTime() { SMPPropertyEnum propertyEnum = SMPPropertyEnum.SMP_ALERT_CREDENTIALS_CRON; SMPDynamicCronTrigger testInstance = new SMPDynamicCronTrigger(propertyEnum.getDefValue(), propertyEnum); // not yet triggered @@ -45,7 +45,7 @@ public class SMPDynamicCronTriggerTest { } @Test - public void getExpression() { + void getExpression() { SMPPropertyEnum propertyEnum = SMPPropertyEnum.SMP_ALERT_CREDENTIALS_CRON; SMPDynamicCronTrigger testInstance = new SMPDynamicCronTrigger(propertyEnum.getDefValue(), propertyEnum); @@ -53,7 +53,7 @@ public class SMPDynamicCronTriggerTest { } @Test - public void updateCronExpression() { + void updateCronExpression() { String newCronExpression = "0 */10 * * * *"; SMPPropertyEnum propertyEnum = SMPPropertyEnum.SMP_ALERT_CREDENTIALS_CRON; SMPDynamicCronTrigger testInstance = new SMPDynamicCronTrigger(propertyEnum.getDefValue(), propertyEnum); @@ -66,7 +66,7 @@ public class SMPDynamicCronTriggerTest { } @Test - public void getCronExpressionProperty() { + void getCronExpressionProperty() { SMPPropertyEnum propertyEnum = SMPPropertyEnum.SMP_ALERT_CREDENTIALS_CRON; SMPDynamicCronTrigger testInstance = new SMPDynamicCronTrigger(propertyEnum.getDefValue(), propertyEnum); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/AbstractBaseDao.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/AbstractBaseDao.java index 9e900f29a6e93747e15d0b517dacd8a873470fea..19bd89a4aa54bc3fa547110789c93e1062ab0890 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/AbstractBaseDao.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/AbstractBaseDao.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -20,12 +20,12 @@ package eu.europa.ec.edelivery.smp.data.dao; import eu.europa.ec.edelivery.smp.config.SMPDatabaseConfig; import org.apache.commons.io.FileUtils; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.jdbc.Sql; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import java.io.IOException; import java.nio.file.Path; @@ -37,7 +37,7 @@ import static eu.europa.ec.edelivery.smp.config.enums.SMPEnvPropertyEnum.*; * @author Joze Rihtarsic * @since 4.1 */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = {SMPDatabaseConfig.class, AlertDao.class, ResourceDao.class, @@ -56,7 +56,7 @@ public abstract class AbstractBaseDao { @Autowired protected TestUtilsDao testUtilsDao; public static final String BUILD_FOLDER = "target"; - public static final Path SECURITY_PATH= Paths.get(BUILD_FOLDER, "smp"); + public static final Path SECURITY_PATH = Paths.get(BUILD_FOLDER, "smp"); public static final String DATABASE_URL = "jdbc:h2:file:./target/DomiSmpTestDb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=TRUE;AUTO_SERVER=TRUE;"; public static final String DATABASE_USERNAME = "smp"; public static final String DATABASE_PASS = "smp"; diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/AbstractResourceDaoTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/AbstractResourceDaoTest.java index a11c96c8b7992ea44437cca460638c2b0860471c..8d4cf17031c6b69ed9c6e2f993401814891a3044 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/AbstractResourceDaoTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/AbstractResourceDaoTest.java @@ -26,7 +26,7 @@ import eu.europa.ec.edelivery.smp.data.model.user.DBResourceMember; import eu.europa.ec.edelivery.smp.data.model.user.DBUser; import eu.europa.ec.edelivery.smp.testutil.TestConstants; import eu.europa.ec.edelivery.smp.testutil.TestDBUtils; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; @@ -64,7 +64,7 @@ public abstract class AbstractResourceDaoTest extends AbstractBaseDao { ResourceMemberDao resourceMemberDao; - @Before + @BeforeEach public void prepareDatabase() { testUtilsDao.clearData(); // setup initial data! diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/AlertDaoIntegrationTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/AlertDaoIntegrationTest.java index 3717e314b850ac14e3deed5f7536c600280c213c..79af9c9289f50869975e1e401301d134d4880d9a 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/AlertDaoIntegrationTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/AlertDaoIntegrationTest.java @@ -20,18 +20,18 @@ package eu.europa.ec.edelivery.smp.data.dao; import eu.europa.ec.edelivery.smp.data.model.DBAlert; import eu.europa.ec.edelivery.smp.testutil.TestDBUtils; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -public class AlertDaoIntegrationTest extends AbstractBaseDao { +class AlertDaoIntegrationTest extends AbstractBaseDao { @Autowired AlertDao testInstance; @Test - public void persistAlert() { + void persistAlert() { // given long initCount = testInstance.getDataListCount(null); DBAlert entity = TestDBUtils.createDBAlert(); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/AuditIntegrationTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/AuditIntegrationTest.java index a9a88201f364f16f94cbae88b490f1805e3a249d..8490c31b6c24de34887d92555dc33e3918306fe4 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/AuditIntegrationTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/AuditIntegrationTest.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -32,8 +32,7 @@ import eu.europa.ec.edelivery.smp.data.ui.enums.AlertStatusEnum; import eu.europa.ec.edelivery.smp.data.ui.enums.AlertTypeEnum; import org.hibernate.envers.AuditReader; import org.hibernate.envers.AuditReaderFactory; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.test.util.ReflectionTestUtils; @@ -47,7 +46,8 @@ import java.util.Map; import java.util.UUID; import static eu.europa.ec.edelivery.smp.testutil.TestDBUtils.*; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Purpose of class is to test all Audit classes and methods with database. @@ -55,7 +55,7 @@ import static org.junit.Assert.assertTrue; * @author Joze Rihtarsic * @since 4.1 */ -public class AuditIntegrationTest extends AbstractBaseDao{ +class AuditIntegrationTest extends AbstractBaseDao { private static final Logger LOG = LoggerFactory.getLogger(AuditIntegrationTest.class); // because envers creates audit on commit we use PersistenceUnit to control commit... @@ -64,7 +64,7 @@ public class AuditIntegrationTest extends AbstractBaseDao{ EntityManagerFactory emf; @Test - public void testClassesForAudit() { + void testClassesForAudit() { AuditReader ar = AuditReaderFactory.get(emf.createEntityManager()); assertTrue(ar.isEntityClassAudited(DBResource.class)); assertTrue(ar.isEntityClassAudited(DBSubresource.class)); @@ -75,7 +75,7 @@ public class AuditIntegrationTest extends AbstractBaseDao{ } @Test - public void testAuditDBDomain() { + void testAuditDBDomain() { DBDomain domain = createDBDomain(); Map<String, Object> alterVal = new HashMap<>(); @@ -87,7 +87,7 @@ public class AuditIntegrationTest extends AbstractBaseDao{ } @Test - public void testAuditDBAlert() { + void testAuditDBAlert() { DBAlert dbAlert = createDBAlert(); Map<String, Object> alterVal = new HashMap<>(); @@ -97,7 +97,7 @@ public class AuditIntegrationTest extends AbstractBaseDao{ } @Test - public void testAuditDBUser() { + void testAuditDBUser() { DBUser dbuser = createDBUser(UUID.randomUUID().toString()); Map<String, Object> alterVal = new HashMap<>(); @@ -107,7 +107,7 @@ public class AuditIntegrationTest extends AbstractBaseDao{ } @Test - public void testAuditDBCredentials() { + void testAuditDBCredentials() { DBUser user = createDBUser("Credential-test"); persist(user); @@ -118,7 +118,6 @@ public class AuditIntegrationTest extends AbstractBaseDao{ alterVal.put("value", UUID.randomUUID().toString()); alterVal.put("credentialType", CredentialType.CAS); alterVal.put("credentialTarget", CredentialTargetType.REST_API); - alterVal.put("activeFrom", OffsetDateTime.now().plusMinutes(30)); alterVal.put("changedOn", OffsetDateTime.now().plusMinutes(30)); alterVal.put("expireAlertOn", OffsetDateTime.now().plusMinutes(30)); alterVal.put("activeFrom", OffsetDateTime.now().plusMinutes(30)); @@ -128,7 +127,7 @@ public class AuditIntegrationTest extends AbstractBaseDao{ } @Test - public void testAuditDBCredentialsWithCertificate() { + void testAuditDBCredentialsWithCertificate() { DBUser dbuser = createDBUser(UUID.randomUUID().toString()); persist(dbuser); @@ -146,7 +145,7 @@ public class AuditIntegrationTest extends AbstractBaseDao{ @Test - public void testAuditDBResource() { + void testAuditDBResource() { DBResource resource = createDBResource(); resource.setDocument(createDBDocument()); Map<String, Object> alterVal = new HashMap<>(); @@ -155,6 +154,7 @@ public class AuditIntegrationTest extends AbstractBaseDao{ testAuditEntity(resource, alterVal); } */ + /** * Method updates value in Map, then checks if revision increased. Last test in removing the entity. * @@ -187,11 +187,11 @@ public class AuditIntegrationTest extends AbstractBaseDao{ ReflectionTestUtils.setField(subEntity, prop, val, val.getClass()); }); update(em, entity); // master - Assert.assertEquals(++iRevSize, ar.getRevisions(subEntity.getClass(), dbId).size()); + assertEquals(++iRevSize, ar.getRevisions(subEntity.getClass(), dbId).size()); } // remove master remove(em, entity.getClass(), entity.getId()); - Assert.assertEquals(++iRevSize, ar.getRevisions(subEntity.getClass(), dbId).size()); + assertEquals(++iRevSize, ar.getRevisions(subEntity.getClass(), dbId).size()); em.close(); } diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/BaseDaoTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/BaseDaoTest.java index b9fbe6a173b355615da8f83c097e170e182614c8..e55213b6fa35b2b1c76ba571264463447930cec0 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/BaseDaoTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/BaseDaoTest.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -19,8 +19,7 @@ package eu.europa.ec.edelivery.smp.data.dao; import eu.europa.ec.edelivery.smp.data.model.DBDomain; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import javax.persistence.EntityManager; @@ -32,14 +31,16 @@ import javax.persistence.criteria.Root; import java.util.Collections; import java.util.List; +import static org.junit.jupiter.api.Assertions.*; + /** - * Purpose of class is to test implemented methods of BaseDao on DomainDao instance. + * Purpose of class is to test implemented methods of BaseDao on DomainDao instance. * * @author Joze Rihtarsic * @since 4.1 */ -public class BaseDaoTest extends AbstractBaseDao { +class BaseDaoTest extends AbstractBaseDao { @Autowired @@ -49,38 +50,38 @@ public class BaseDaoTest extends AbstractBaseDao { protected EntityManager memEManager; @Test - public void testSelectAndCountResult() { + void testSelectAndCountResult() { // given TestFilter filter = null; Class cls = DBDomain.class; // when CriteriaQuery res = testInstance.createSearchCriteria(filter, cls, false, null, null); //Then - Assert.assertNotNull(res); - Assert.assertNull(res.getSelection()); + assertNotNull(res); + assertNull(res.getSelection()); // when res = testInstance.createSearchCriteria(filter, cls, true, null, null); //Then - Assert.assertNotNull(res); - Assert.assertNotNull(res.getSelection()); - Assert.assertEquals(java.lang.Long.class, res.getSelection().getJavaType()); + assertNotNull(res); + assertNotNull(res.getSelection()); + assertEquals(java.lang.Long.class, res.getSelection().getJavaType()); } @Test - public void testFilterEmpty() { + void testFilterEmpty() { // given TestFilter filter = new TestFilter(); Class cls = DBDomain.class; // when CriteriaQuery res = testInstance.createSearchCriteria(filter, cls, false, null, null); //Then - Assert.assertNotNull(res); - Assert.assertEquals(0,res.getParameters().size() ); + assertNotNull(res); + assertEquals(0, res.getParameters().size()); } @Test - public void testPredicatesStringValue() { + void testPredicatesStringValue() { // given TestFilter filter = new TestFilter(); String filterValue = "TestValue"; @@ -92,18 +93,18 @@ public class BaseDaoTest extends AbstractBaseDao { Predicate expected = cb.equal(testInstance.getPath(om, "DomainCode"), filterValue); // when - List<Predicate> lst = testInstance.createPredicates(filter,om,cb ); + List<Predicate> lst = testInstance.createPredicates(filter, om, cb); //Then - Assert.assertNotNull(lst); - Assert.assertEquals(1,lst.size() ); + assertNotNull(lst); + assertEquals(1, lst.size()); } @Test - public void testPredicatesStringListValue() { + void testPredicatesStringListValue() { // given TestFilter filter = new TestFilter(); - List<String > filterValue = Collections.singletonList("TestValue"); + List<String> filterValue = Collections.singletonList("TestValue"); filter.setDomainCodeList(filterValue); CriteriaBuilder cb = memEManager.getCriteriaBuilder(); @@ -112,15 +113,15 @@ public class BaseDaoTest extends AbstractBaseDao { Predicate expected = cb.equal(testInstance.getPath(om, "DomainCodeList", "List"), filterValue); // when - List<Predicate> lst = testInstance.createPredicates(filter,om,cb ); + List<Predicate> lst = testInstance.createPredicates(filter, om, cb); //Then - Assert.assertNotNull(lst); - Assert.assertEquals(1,lst.size() ); + assertNotNull(lst); + assertEquals(1, lst.size()); } @Test - public void testPredicatesStringLikeValue() { + void testPredicatesStringLikeValue() { // given TestFilter filter = new TestFilter(); String filterValue = "TestValue"; @@ -132,18 +133,18 @@ public class BaseDaoTest extends AbstractBaseDao { Predicate expected = cb.equal(testInstance.getPath(om, "DomainCodeLike", "Like"), filterValue); // when - List<Predicate> lst = testInstance.createPredicates(filter,om,cb ); + List<Predicate> lst = testInstance.createPredicates(filter, om, cb); //Then - Assert.assertNotNull(lst); - Assert.assertEquals(1,lst.size() ); + assertNotNull(lst); + assertEquals(1, lst.size()); } @Test - public void testPredicatesLong() { + void testPredicatesLong() { // given TestFilter filter = new TestFilter(); - Long filterValue = (long)10; + Long filterValue = (long) 10; filter.setId(filterValue); CriteriaBuilder cb = memEManager.getCriteriaBuilder(); @@ -152,21 +153,20 @@ public class BaseDaoTest extends AbstractBaseDao { Predicate expected = cb.equal(testInstance.getPath(om, "Id"), filterValue); // when - List<Predicate> lst = testInstance.createPredicates(filter,om,cb ); + List<Predicate> lst = testInstance.createPredicates(filter, om, cb); //Then - Assert.assertNotNull(lst); - Assert.assertEquals(1,lst.size() ); + assertNotNull(lst); + assertEquals(1, lst.size()); } - - } + class TestFilter { String domainCode; String domainCodeLike; - Long id; + Long id; Long idFrom; Long idTo; List<String> domainCodeList; diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/ConfigurationDAOImplTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/ConfigurationDAOImplTest.java index 4ebfc46bcd6d8fe7d5465331558491358350b31e..3a3fd186035191fc571c45ebe6cc09019e79c85a 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/ConfigurationDAOImplTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/ConfigurationDAOImplTest.java @@ -44,8 +44,8 @@ import eu.europa.ec.edelivery.smp.exceptions.ErrorCode; import eu.europa.ec.edelivery.smp.exceptions.SMPRuntimeException; import org.hamcrest.CoreMatchers; import org.hamcrest.MatcherAssert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; @@ -59,7 +59,7 @@ import java.time.OffsetDateTime; import java.util.*; import static eu.europa.ec.edelivery.smp.config.enums.SMPPropertyEnum.*; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public class ConfigurationDAOImplTest extends AbstractBaseDao { @@ -67,7 +67,7 @@ public class ConfigurationDAOImplTest extends AbstractBaseDao { @Autowired private ConfigurationDao configurationDao; - @Before + @BeforeEach public void before() throws IOException { resetKeystore(); @@ -76,14 +76,14 @@ public class ConfigurationDAOImplTest extends AbstractBaseDao { } @Test - public void testGetSecurityFolder() { + void testGetSecurityFolder() { File folder = configurationDao.getSecurityFolder(); assertEquals("target/smp", folder.getPath()); } @Test - public void testFindConfigurationPropertyNotFound() { + void testFindConfigurationPropertyNotFound() { //GIVE - WHEN Optional<DBConfiguration> resultBO = configurationDao.findConfigurationProperty("NotFoundProperty"); @@ -92,7 +92,7 @@ public class ConfigurationDAOImplTest extends AbstractBaseDao { } @Test - public void testLastUpdateOK() { + void testLastUpdateOK() { //GIVE - WHEN OffsetDateTime lastUpdate = configurationDao.getLastUpdate(); @@ -102,7 +102,7 @@ public class ConfigurationDAOImplTest extends AbstractBaseDao { } @Test - public void testSetNewProperty() { + void testSetNewProperty() { // given OffsetDateTime lastUpdate = configurationDao.getLastUpdate(); String propertyValue = "TestUser"; @@ -120,7 +120,7 @@ public class ConfigurationDAOImplTest extends AbstractBaseDao { } @Test - public void testSetPropertyByStringOk() { + void testSetPropertyByStringOk() { // given OffsetDateTime lastUpdate = configurationDao.getLastUpdate(); String propertyValue = "localhost"; @@ -137,7 +137,7 @@ public class ConfigurationDAOImplTest extends AbstractBaseDao { } @Test - public void testSetPropertyByStringNotExists() { + void testSetPropertyByStringNotExists() { // given OffsetDateTime lastUpdate = configurationDao.getLastUpdate(); String propertyValue = "localhost"; @@ -150,7 +150,7 @@ public class ConfigurationDAOImplTest extends AbstractBaseDao { } @Test - public void testUpdatePropertyInvalid() { + void testUpdatePropertyInvalid() { //WHEN SMPRuntimeException result = assertThrows(SMPRuntimeException.class, () -> configurationDao.setPropertyToDatabase(SMPPropertyEnum.HTTP_FORWARDED_HEADERS_ENABLED, @@ -162,7 +162,7 @@ public class ConfigurationDAOImplTest extends AbstractBaseDao { } @Test - public void testUpdateProperty() { + void testUpdateProperty() { // given OffsetDateTime lastUpdate = configurationDao.getLastUpdate(); String propertyValue = "TestUser"; @@ -184,8 +184,7 @@ public class ConfigurationDAOImplTest extends AbstractBaseDao { } @Test - - public void testDeleteProperty() { + void testDeleteProperty() { // given String propertyValue = "TestUser"; String propertyDesc = "Test description"; @@ -204,14 +203,14 @@ public class ConfigurationDAOImplTest extends AbstractBaseDao { } @Test - public void testGetCachedProperty() { + void testGetCachedProperty() { String value = configurationDao.getCachedProperty(SMPPropertyEnum.ALERT_ACCESS_TOKEN_EXPIRED_PERIOD); assertEquals("30", value); } @Test - public void testGetCachedPropertyValue() { + void testGetCachedPropertyValue() { Object objPath = configurationDao.getCachedPropertyValue(SMPPropertyEnum.ALERT_ACCESS_TOKEN_EXPIRED_PERIOD); assertNotNull(objPath); @@ -219,7 +218,7 @@ public class ConfigurationDAOImplTest extends AbstractBaseDao { } @Test - public void testReloadPropertiesFromDatabase() { + void testReloadPropertiesFromDatabase() { // give configurationDao.setPropertyToDatabase(SMP_CLUSTER_ENABLED, "true", null); @@ -245,7 +244,7 @@ public class ConfigurationDAOImplTest extends AbstractBaseDao { @Test - public void testRefreshPropertiesWithReload() { + void testRefreshPropertiesWithReload() { // give String testValue = configurationDao.getCachedProperty(SMPPropertyEnum.UI_COOKIE_SESSION_IDLE_TIMEOUT_ADMIN); @@ -270,7 +269,7 @@ public class ConfigurationDAOImplTest extends AbstractBaseDao { } @Test - public void testRefreshEncryptProperties() { + void testRefreshEncryptProperties() { // give String newTestPassword = UUID.randomUUID().toString(); @@ -306,7 +305,7 @@ public class ConfigurationDAOImplTest extends AbstractBaseDao { } @Test - public void encryptDefault() throws IOException { + void encryptDefault() throws IOException { // given File f = generateRandomPrivateKey(); String password = "TEST11002password1@!." + System.currentTimeMillis(); @@ -319,7 +318,7 @@ public class ConfigurationDAOImplTest extends AbstractBaseDao { } @Test - public void encryptDefaultError() throws IOException { + void encryptDefaultError() throws IOException { // given File f = new File("no.key"); String password = "TEST11002password1@!." + System.currentTimeMillis(); @@ -332,7 +331,7 @@ public class ConfigurationDAOImplTest extends AbstractBaseDao { } @Test - public void decryptDefault() throws IOException { + void decryptDefault() throws IOException { // given File f = generateRandomPrivateKey(); String password = "TEST11002password1@!." + System.currentTimeMillis(); @@ -346,7 +345,7 @@ public class ConfigurationDAOImplTest extends AbstractBaseDao { } @Test - public void decryptDefaultError() throws IOException { + void decryptDefaultError() throws IOException { // given File f = generateRandomPrivateKey(); File fErr = new File("no.key"); @@ -362,7 +361,7 @@ public class ConfigurationDAOImplTest extends AbstractBaseDao { } @Test - public void encryptWithSetupKeyWithoutIV() { + void encryptWithSetupKeyWithoutIV() { // given File keyFile = resourceDirectory.resolve("encryptionKey.key").toFile(); String password = "test123"; @@ -377,7 +376,7 @@ public class ConfigurationDAOImplTest extends AbstractBaseDao { } @Test - public void encryptWithSetupKeyWitIV() { + void encryptWithSetupKeyWitIV() { // given File keyFile = resourceDirectory.resolve("masterKeyWithIV.key").toFile(); String password = "test123"; @@ -392,7 +391,7 @@ public class ConfigurationDAOImplTest extends AbstractBaseDao { } @Test - public void testRetrieveNonEncryptedPassword() { + void testRetrieveNonEncryptedPassword() { // given String newTestPassword = UUID.randomUUID().toString(); String newDBTestPassword = SecurityUtils.DECRYPTED_TOKEN_PREFIX + newTestPassword + "}"; @@ -412,7 +411,7 @@ public class ConfigurationDAOImplTest extends AbstractBaseDao { } @Test - public void testGetNonEncryptedValue() { + void testGetNonEncryptedValue() { // given String newTestPassword = UUID.randomUUID().toString(); String newDBTestPassword = SecurityUtils.DECRYPTED_TOKEN_PREFIX + newTestPassword + "}"; @@ -427,7 +426,7 @@ public class ConfigurationDAOImplTest extends AbstractBaseDao { @Test @Transactional - public void testUpdateEncryptedValues() { + void testUpdateEncryptedValues() { // given String newTestPassword = UUID.randomUUID().toString(); String newDBTestPassword = newTestPassword; @@ -465,7 +464,7 @@ public class ConfigurationDAOImplTest extends AbstractBaseDao { } @Test - public void testContextRefreshedEvent() { + void testContextRefreshedEvent() { configurationDao.setInitializedTime(null); assertFalse(configurationDao.isApplicationInitialized()); @@ -479,7 +478,7 @@ public class ConfigurationDAOImplTest extends AbstractBaseDao { @Test - public void testContextStopEvent() { + void testContextStopEvent() { configurationDao.setInitializedTime(OffsetDateTime.now()); // when configurationDao.contextStopEvent(); @@ -489,7 +488,7 @@ public class ConfigurationDAOImplTest extends AbstractBaseDao { } @Test - public void testGetPendingRestartProperties() { + void testGetPendingRestartProperties() { // set start "yesterday" - but all properties have update today! configurationDao.setInitializedTime(OffsetDateTime.now().minusDays(1)); // when @@ -499,7 +498,7 @@ public class ConfigurationDAOImplTest extends AbstractBaseDao { } @Test - public void testUpdateListener() { + void testUpdateListener() { configurationDao.contextRefreshedEvent(); PropertyUpdateListener listener = Mockito.mock(PropertyUpdateListener.class); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/CredentialDaoAlertsTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/CredentialDaoAlertsTest.java index 241818f56f8c57a16cc9736a0873daad49255846..86cf7a4c3517b04fc914d312f28ca6e454da4848 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/CredentialDaoAlertsTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/CredentialDaoAlertsTest.java @@ -21,8 +21,8 @@ package eu.europa.ec.edelivery.smp.data.dao; import eu.europa.ec.edelivery.smp.data.model.user.DBCredential; import eu.europa.ec.edelivery.smp.data.model.user.DBUser; import eu.europa.ec.edelivery.smp.testutil.TestDBUtils; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import java.time.OffsetDateTime; @@ -30,10 +30,10 @@ import java.util.List; import java.util.UUID; import java.util.stream.Collectors; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; -public class CredentialDaoAlertsTest extends AbstractBaseDao { + +class CredentialDaoAlertsTest extends AbstractBaseDao { DBUser okUser = TestDBUtils.createDBUserByUsername("okUser-" + UUID.randomUUID()); DBUser beforePasswordExpireNoAlertSend = TestDBUtils.createDBUserByUsername("befPassExpNoAlertSend-" + UUID.randomUUID()); @@ -69,7 +69,7 @@ public class CredentialDaoAlertsTest extends AbstractBaseDao { @Autowired UserDao userDao; - @Before + @BeforeEach public void setupData() { // persist users to database userDao.persistFlushDetach(okUser); @@ -173,7 +173,7 @@ public class CredentialDaoAlertsTest extends AbstractBaseDao { } @Test - public void getPasswordImminentExpireUsers() { + void getPasswordImminentExpireUsers() { List<DBCredential> dbUserList = testInstance.getBeforePasswordExpireUsersForAlerts(30, 5, 200); List<String> usernames = dbUserList.stream().map(DBCredential::getUser).map(DBUser::getUsername).collect(Collectors.toList()); assertTrue(usernames.contains(beforePasswordExpireNoAlertSend.getUsername())); @@ -181,7 +181,7 @@ public class CredentialDaoAlertsTest extends AbstractBaseDao { } @Test - public void getPasswordExpireUsers() { + void getPasswordExpireUsers() { List<DBCredential> dbUserList = testInstance.getPasswordExpiredUsersForAlerts(30, 5, 200); assertEquals(2, dbUserList.size()); List<String> usernames = dbUserList.stream().map(DBCredential::getUser).map(DBUser::getUsername).collect(Collectors.toList()); @@ -190,7 +190,7 @@ public class CredentialDaoAlertsTest extends AbstractBaseDao { } @Test - public void getAccessTokenImminentExpireUsers() { + void getAccessTokenImminentExpireUsers() { List<DBCredential> dbUserList = testInstance.getBeforeAccessTokenExpireUsersForAlerts(30, 5, 200); List<String> usernames = dbUserList.stream().map(DBCredential::getUser).map(DBUser::getUsername).collect(Collectors.toList()); System.out.println(usernames); @@ -200,7 +200,7 @@ public class CredentialDaoAlertsTest extends AbstractBaseDao { } @Test - public void getAccessTokenExpireUsers() { + void getAccessTokenExpireUsers() { List<DBCredential> dbUserList = testInstance.getAccessTokenExpiredUsersForAlerts(30, 5, 200); List<String> usernames = dbUserList.stream().map(DBCredential::getUser).map(DBUser::getUsername).collect(Collectors.toList()); System.out.println(usernames); @@ -210,7 +210,7 @@ public class CredentialDaoAlertsTest extends AbstractBaseDao { } @Test - public void getCertificateImminentExpireUsers() { + void getCertificateImminentExpireUsers() { List<DBCredential> dbUserList = testInstance.getBeforeCertificateExpireUsersForAlerts(30, 5, 200); List<String> usernames = dbUserList.stream().map(DBCredential::getUser).map(DBUser::getUsername).collect(Collectors.toList()); System.out.println(usernames); @@ -220,7 +220,7 @@ public class CredentialDaoAlertsTest extends AbstractBaseDao { } @Test - public void getCertificateExpireUsers() { + void getCertificateExpireUsers() { List<DBCredential> dbUserList = testInstance.getCertificateExpiredUsersForAlerts(30, 5, 200); List<String> usernames = dbUserList.stream().map(DBCredential::getUser).map(DBUser::getUsername).collect(Collectors.toList()); System.out.println(usernames); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/CredentialDaoIntegrationTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/CredentialDaoIntegrationTest.java index 6962cf9d3b9f758c917e957cf11c9d165670a92e..fce721f96f5233cc31328c251a84f45fb63d0f26 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/CredentialDaoIntegrationTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/CredentialDaoIntegrationTest.java @@ -25,20 +25,20 @@ import eu.europa.ec.edelivery.smp.data.model.user.DBCredential; import eu.europa.ec.edelivery.smp.data.model.user.DBUser; import eu.europa.ec.edelivery.smp.testutil.TestConstants; import eu.europa.ec.edelivery.smp.testutil.TestDBUtils; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import java.util.Optional; import static org.apache.commons.lang3.StringUtils.lowerCase; import static org.apache.commons.lang3.StringUtils.upperCase; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; /** * @author Joze Rihtarsic * @since 5.0 */ -public class CredentialDaoIntegrationTest extends AbstractBaseDao { +class CredentialDaoIntegrationTest extends AbstractBaseDao { @Autowired UserDao userDao; @@ -47,7 +47,7 @@ public class CredentialDaoIntegrationTest extends AbstractBaseDao { CredentialDao testInstance; @Test - public void findUsernameCredentialForUsername() { + void findUsernameCredentialForUsername() { DBCredential credential = TestDBUtils.createDBCredential(TestConstants.USERNAME_1, "TEST", CredentialType.USERNAME_PASSWORD, CredentialTargetType.UI); DBUser u = TestDBUtils.createDBUserByUsername(TestConstants.USERNAME_1); // execute @@ -69,7 +69,7 @@ public class CredentialDaoIntegrationTest extends AbstractBaseDao { } @Test - public void findUsernameCredentialForUsernameCaseInsensitive() { + void findUsernameCredentialForUsernameCaseInsensitive() { String username = lowerCase(TestConstants.USERNAME_1); DBCredential credential = TestDBUtils.createDBCredential(username, "TEST", CredentialType.USERNAME_PASSWORD, CredentialTargetType.UI); DBUser u = TestDBUtils.createDBUserByUsername(username); @@ -92,7 +92,7 @@ public class CredentialDaoIntegrationTest extends AbstractBaseDao { } @Test - public void findCertificateCredential() { + void findCertificateCredential() { String username = lowerCase(TestConstants.USERNAME_1); DBCredential credential = TestDBUtils.createDBCredential(username, "TEST", CredentialType.CERTIFICATE, CredentialTargetType.REST_API); DBCertificate certificate = TestDBUtils.createDBCertificate(); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/DocumentDaoTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/DocumentDaoTest.java index ebb4ba3bfea27198634169ba9e71b8367089268d..69d9c5d060f00ea26586475a32435402251d82a9 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/DocumentDaoTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/DocumentDaoTest.java @@ -20,28 +20,28 @@ package eu.europa.ec.edelivery.smp.data.dao; import eu.europa.ec.edelivery.smp.data.model.doc.DBDocument; import eu.europa.ec.edelivery.smp.data.model.doc.DBDocumentVersion; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import java.util.List; import java.util.Optional; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -public class DocumentDaoTest extends AbstractBaseDao { +class DocumentDaoTest extends AbstractBaseDao { @Autowired DocumentDao testInstance; - @Before + @BeforeEach public void prepareDatabase() { testUtilsDao.clearData(); testUtilsDao.createSubresources(); } @Test - public void testPersistDocument() { + void testPersistDocument() { DBDocument document = testUtilsDao.createAndPersistDocument(2, "value1", "schema1"); @@ -52,7 +52,7 @@ public class DocumentDaoTest extends AbstractBaseDao { @Test - public void getDocumentForResource() { + void getDocumentForResource() { Optional<DBDocument> result = testInstance.getDocumentForResource(testUtilsDao.getResourceD1G1RD1()); assertTrue(result.isPresent()); @@ -63,14 +63,14 @@ public class DocumentDaoTest extends AbstractBaseDao { @Test - public void getDocumentVersionsForResource() { + void getDocumentVersionsForResource() { List<DBDocumentVersion> result = testInstance.getDocumentVersionsForResource(testUtilsDao.getResourceD1G1RD1()); assertEquals(2, result.size()); } @Test - public void getCurrentDocumentVersionForResource() { + void getCurrentDocumentVersionForResource() { Optional<DBDocumentVersion> result = testInstance.getCurrentDocumentVersionForResource(testUtilsDao.getResourceD1G1RD1()); @@ -82,14 +82,14 @@ public class DocumentDaoTest extends AbstractBaseDao { @Test - public void getDocumentVersionsForSubresource() { + void getDocumentVersionsForSubresource() { List<DBDocumentVersion> result = testInstance.getDocumentVersionsForSubresource(testUtilsDao.getSubresourceD1G1RD1_S1()); assertEquals(2, result.size()); } @Test - public void getCurrentDocumentVersionForSubresource() { + void getCurrentDocumentVersionForSubresource() { Optional<DBDocumentVersion> result = testInstance.getCurrentDocumentVersionForSubresource(testUtilsDao.getSubresourceD1G1RD1_S1()); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/DomainDaoIntegrationTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/DomainDaoIntegrationTest.java index f61a6596018d435b01ff7f9e56ca690162854c0c..c4af53a9a2eedb054f361dc3fc55b6819b04d659 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/DomainDaoIntegrationTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/DomainDaoIntegrationTest.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -22,13 +22,15 @@ import eu.europa.ec.edelivery.smp.data.model.DBDomain; import eu.europa.ec.edelivery.smp.exceptions.ErrorCode; import eu.europa.ec.edelivery.smp.testutil.TestConstants; import eu.europa.ec.edelivery.smp.testutil.TestDBUtils; -import org.junit.Before; -import org.junit.Test; +import org.hamcrest.CoreMatchers; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import java.util.Optional; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.*; /** * Purpose of class is to test all resource methods with database. @@ -36,20 +38,19 @@ import static org.junit.Assert.*; * @author Joze Rihtarsic * @since 4.1 */ -public class DomainDaoIntegrationTest extends AbstractBaseDao { +class DomainDaoIntegrationTest extends AbstractBaseDao { @Autowired DomainDao testInstance; - - @Before + @BeforeEach public void prepareDatabase() { testUtilsDao.clearData(); } @Test - public void persistDomain() { + void persistDomain() { // set DBDomain d = new DBDomain(); d.setDomainCode(TestConstants.TEST_DOMAIN_CODE_1); @@ -63,8 +64,8 @@ public class DomainDaoIntegrationTest extends AbstractBaseDao { assertEquals(d, res.get()); // test equal method } - @Test(expected = Exception.class) - public void persistDuplicateDomain() { + @Test + void persistDuplicateDomain() { // set DBDomain d = new DBDomain(); d.setDomainCode(TestConstants.TEST_DOMAIN_CODE_1); @@ -73,11 +74,12 @@ public class DomainDaoIntegrationTest extends AbstractBaseDao { d2.setDomainCode(TestConstants.TEST_DOMAIN_CODE_1); // execute - testInstance.persistFlushDetach(d2); + Exception exception = assertThrows(Exception.class, () -> testInstance.persistFlushDetach(d2)); + assertThat(exception.getMessage(), CoreMatchers.containsString("ConstraintViolationException")); } @Test - public void getTheOnlyDomainNoDomain() { + void getTheOnlyDomainNoDomain() { // execute IllegalStateException exception = assertThrows(IllegalStateException.class, () -> testInstance.getTheOnlyDomain()); @@ -85,7 +87,7 @@ public class DomainDaoIntegrationTest extends AbstractBaseDao { } @Test - public void getTheOnlyDomainMultipleDomain() { + void getTheOnlyDomainMultipleDomain() { // set DBDomain d = new DBDomain(); d.setDomainCode(TestConstants.TEST_DOMAIN_CODE_1); @@ -102,7 +104,7 @@ public class DomainDaoIntegrationTest extends AbstractBaseDao { } @Test - public void getDomainByCodeExists() { + void getDomainByCodeExists() { // set DBDomain d = new DBDomain(); d.setDomainCode(TestConstants.TEST_DOMAIN_CODE_1); @@ -116,14 +118,14 @@ public class DomainDaoIntegrationTest extends AbstractBaseDao { } @Test - public void getDomainByCodeNotExists() { + void getDomainByCodeNotExists() { // test Optional<DBDomain> res = testInstance.getDomainByCode(TestConstants.TEST_DOMAIN_CODE_1); assertFalse(res.isPresent()); } @Test - public void removeByDomainCodeExists() { + void removeByDomainCodeExists() { // set DBDomain d = new DBDomain(); @@ -141,7 +143,7 @@ public class DomainDaoIntegrationTest extends AbstractBaseDao { } @Test - public void removeByDomainCodeNotExists() { + void removeByDomainCodeNotExists() { // set // test @@ -150,7 +152,7 @@ public class DomainDaoIntegrationTest extends AbstractBaseDao { } @Test - public void removeByDomainById() { + void removeByDomainById() { // set DBDomain d = new DBDomain(); d.setDomainCode(TestConstants.TEST_DOMAIN_CODE_1); @@ -168,7 +170,7 @@ public class DomainDaoIntegrationTest extends AbstractBaseDao { } @Test - public void testValidateDeleteOKScenario() { + void testValidateDeleteOKScenario() { // set DBDomain d = TestDBUtils.createDBDomain(); testInstance.persistFlushDetach(d); @@ -179,7 +181,7 @@ public class DomainDaoIntegrationTest extends AbstractBaseDao { } @Test - public void testValidateDeleteHasResources() { + void testValidateDeleteHasResources() { // set testUtilsDao.createSubresources(); DBDomain d = testUtilsDao.getD1(); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/DomainDaoTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/DomainDaoTest.java index d8b71579d675b927df00616c43db48ef406ca50a..bf14778e2e573b583ae7ae4b395452d6d0ea4d34 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/DomainDaoTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/DomainDaoTest.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -20,13 +20,14 @@ package eu.europa.ec.edelivery.smp.data.dao; import eu.europa.ec.edelivery.smp.data.enums.MembershipRoleType; import eu.europa.ec.edelivery.smp.data.model.DBDomain; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import java.util.List; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; + /** * The group of resources with shared resource management rights. The user with group admin has rights to create/delete @@ -35,12 +36,12 @@ import static org.junit.Assert.assertEquals; * @author Joze Rihtarsic * @since 5.0 */ -public class DomainDaoTest extends AbstractBaseDao { +class DomainDaoTest extends AbstractBaseDao { @Autowired DomainDao testInstance; - @Before + @BeforeEach public void prepareDatabase() { // setup initial data! testUtilsDao.clearData(); @@ -49,8 +50,9 @@ public class DomainDaoTest extends AbstractBaseDao { testUtilsDao.createResourceMemberships(); } + @Test - public void getDomainsByUserIdAndRolesCount() { + void getDomainsByUserIdAndRolesCount() { // one for domain 1 Long cnt = testInstance.getDomainsByUserIdAndDomainRolesCount(testUtilsDao.getUser1().getId(), MembershipRoleType.ADMIN); assertEquals(1, cnt.intValue()); @@ -64,12 +66,12 @@ public class DomainDaoTest extends AbstractBaseDao { assertEquals(2, cnt.intValue()); // all - cnt = testInstance.getDomainsByUserIdAndDomainRolesCount(testUtilsDao.getUser1().getId(), MembershipRoleType.VIEWER, MembershipRoleType.ADMIN); + cnt = testInstance.getDomainsByUserIdAndDomainRolesCount(testUtilsDao.getUser1().getId(), MembershipRoleType.VIEWER, MembershipRoleType.ADMIN); assertEquals(2, cnt.intValue()); } @Test - public void getDomainsByUserIdAndRoles() { + void getDomainsByUserIdAndRoles() { // one for domain 1 List<DBDomain> result = testInstance.getDomainsByUserIdAndDomainRoles(testUtilsDao.getUser1().getId(), MembershipRoleType.ADMIN); assertEquals(1, result.size()); @@ -86,12 +88,12 @@ public class DomainDaoTest extends AbstractBaseDao { result = testInstance.getDomainsByUserIdAndDomainRoles(testUtilsDao.getUser1().getId()); assertEquals(2, result.size()); - result = testInstance.getDomainsByUserIdAndDomainRoles(testUtilsDao.getUser1().getId(), MembershipRoleType.VIEWER, MembershipRoleType.ADMIN); + result = testInstance.getDomainsByUserIdAndDomainRoles(testUtilsDao.getUser1().getId(), MembershipRoleType.VIEWER, MembershipRoleType.ADMIN); assertEquals(2, result.size()); } @Test - public void getDomainsByUserIdAndGroupRolesCount() { + void getDomainsByUserIdAndGroupRolesCount() { // one for domain 1 Long cnt = testInstance.getDomainsByUserIdAndGroupRolesCount(testUtilsDao.getUser1().getId(), MembershipRoleType.ADMIN); assertEquals(1, cnt.intValue()); @@ -105,12 +107,12 @@ public class DomainDaoTest extends AbstractBaseDao { assertEquals(2, cnt.intValue()); // all - cnt = testInstance.getDomainsByUserIdAndGroupRolesCount(testUtilsDao.getUser1().getId(), MembershipRoleType.VIEWER, MembershipRoleType.ADMIN); + cnt = testInstance.getDomainsByUserIdAndGroupRolesCount(testUtilsDao.getUser1().getId(), MembershipRoleType.VIEWER, MembershipRoleType.ADMIN); assertEquals(2, cnt.intValue()); } @Test - public void getDomainsByUserIdAndGroupRoles() { + void getDomainsByUserIdAndGroupRoles() { // one for domain 1 List<DBDomain> result = testInstance.getDomainsByUserIdAndGroupRoles(testUtilsDao.getUser1().getId(), MembershipRoleType.ADMIN); assertEquals(1, result.size()); @@ -127,12 +129,12 @@ public class DomainDaoTest extends AbstractBaseDao { result = testInstance.getDomainsByUserIdAndGroupRoles(testUtilsDao.getUser1().getId()); assertEquals(2, result.size()); - result = testInstance.getDomainsByUserIdAndGroupRoles(testUtilsDao.getUser1().getId(), MembershipRoleType.VIEWER, MembershipRoleType.ADMIN); + result = testInstance.getDomainsByUserIdAndGroupRoles(testUtilsDao.getUser1().getId(), MembershipRoleType.VIEWER, MembershipRoleType.ADMIN); assertEquals(2, result.size()); } @Test - public void getDomainsByUserIdAndResourceRolesCount() { + void getDomainsByUserIdAndResourceRolesCount() { // one for domain 1 Long cnt = testInstance.getDomainsByUserIdAndResourceRolesCount(testUtilsDao.getUser1().getId(), MembershipRoleType.ADMIN); assertEquals(1, cnt.intValue()); @@ -146,11 +148,12 @@ public class DomainDaoTest extends AbstractBaseDao { assertEquals(2, cnt.intValue()); // all - cnt = testInstance.getDomainsByUserIdAndResourceRolesCount(testUtilsDao.getUser1().getId(), MembershipRoleType.VIEWER, MembershipRoleType.ADMIN); + cnt = testInstance.getDomainsByUserIdAndResourceRolesCount(testUtilsDao.getUser1().getId(), MembershipRoleType.VIEWER, MembershipRoleType.ADMIN); assertEquals(2, cnt.intValue()); } + @Test - public void getDomainsByUserIdAndResourceRoles() { + void getDomainsByUserIdAndResourceRoles() { // one for domain 1 List<DBDomain> result = testInstance.getDomainsByUserIdAndResourceRoles(testUtilsDao.getUser1().getId(), MembershipRoleType.ADMIN); assertEquals(1, result.size()); @@ -167,7 +170,7 @@ public class DomainDaoTest extends AbstractBaseDao { result = testInstance.getDomainsByUserIdAndResourceRoles(testUtilsDao.getUser1().getId()); assertEquals(2, result.size()); - result = testInstance.getDomainsByUserIdAndResourceRoles(testUtilsDao.getUser1().getId(), MembershipRoleType.VIEWER, MembershipRoleType.ADMIN); + result = testInstance.getDomainsByUserIdAndResourceRoles(testUtilsDao.getUser1().getId(), MembershipRoleType.VIEWER, MembershipRoleType.ADMIN); assertEquals(2, result.size()); } } diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/DomainMemberDaoTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/DomainMemberDaoTest.java index 761ff30d0bea8147a6aca8c26a4a10c4e8e3a455..289aaffaef75cd2fafbc94e13688b4258bed8e30 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/DomainMemberDaoTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/DomainMemberDaoTest.java @@ -23,20 +23,20 @@ import eu.europa.ec.edelivery.smp.data.model.DBDomain; import eu.europa.ec.edelivery.smp.data.model.user.DBDomainMember; import eu.europa.ec.edelivery.smp.data.model.user.DBUser; import org.apache.commons.lang3.StringUtils; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import java.util.Collections; import java.util.List; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; /** * @author Joze Rihtarsic * @since 5.0 */ -public class DomainMemberDaoTest extends AbstractBaseDao { +class DomainMemberDaoTest extends AbstractBaseDao { @Autowired UserDao userDao; @@ -45,7 +45,7 @@ public class DomainMemberDaoTest extends AbstractBaseDao { @Autowired DomainMemberDao testInstance; - @Before + @BeforeEach public void prepareDatabase() { testUtilsDao.clearData(); testUtilsDao.createUsers(); @@ -54,7 +54,7 @@ public class DomainMemberDaoTest extends AbstractBaseDao { @Test - public void testIsUserDomainsMember() { + void testIsUserDomainsMember() { DBDomain domain = testUtilsDao.getD1(); DBUser user = testUtilsDao.getUser1(); addMemberToDomain(user, domain, MembershipRoleType.ADMIN); @@ -65,7 +65,7 @@ public class DomainMemberDaoTest extends AbstractBaseDao { } @Test - public void testIsUserDomainsMemberFalse() { + void testIsUserDomainsMemberFalse() { // then boolean result = testInstance.isUserDomainsMember(testUtilsDao.getUser1(), Collections.singletonList(testUtilsDao.getD1())); @@ -74,7 +74,7 @@ public class DomainMemberDaoTest extends AbstractBaseDao { } @Test - public void testIsUserDomainsMemberWithRoleTrue() { + void testIsUserDomainsMemberWithRoleTrue() { DBDomain domain = testUtilsDao.getD1(); DBUser user = testUtilsDao.getUser1(); addMemberToDomain(user, domain, MembershipRoleType.ADMIN); @@ -86,7 +86,7 @@ public class DomainMemberDaoTest extends AbstractBaseDao { } @Test - public void testGetDomainMembersEmpty() { + void testGetDomainMembersEmpty() { DBDomain domain = testUtilsDao.getD1(); // then Long resultCount = testInstance.getDomainMemberCount(domain.getId(), null); @@ -96,7 +96,7 @@ public class DomainMemberDaoTest extends AbstractBaseDao { } @Test - public void testGetDomainMembersOne() { + void testGetDomainMembersOne() { DBDomain domain = testUtilsDao.getD1(); DBUser user = testUtilsDao.getUser1(); addMemberToDomain(user, domain, MembershipRoleType.ADMIN); @@ -108,7 +108,7 @@ public class DomainMemberDaoTest extends AbstractBaseDao { } @Test - public void testGetDomainMembersOneFilter() { + void testGetDomainMembersOneFilter() { DBDomain domain = testUtilsDao.getD1(); DBUser user = testUtilsDao.getUser1(); addMemberToDomain(user, domain, MembershipRoleType.ADMIN); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/DomainResourceDefDaoTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/DomainResourceDefDaoTest.java index c4833120a65eac156e3112aec57076e3f0712ceb..7898672b1eb7df4f9e384794168d2e7884ae4d50 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/DomainResourceDefDaoTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/DomainResourceDefDaoTest.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -19,27 +19,25 @@ package eu.europa.ec.edelivery.smp.data.dao; import eu.europa.ec.edelivery.smp.data.model.DBDomainResourceDef; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import java.util.List; import java.util.Optional; import static eu.europa.ec.edelivery.smp.testutil.TestConstants.*; -import static org.junit.Assert.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * @author Joze Rihtarsic * @since 5.0 */ -public class DomainResourceDefDaoTest extends AbstractBaseDao { +class DomainResourceDefDaoTest extends AbstractBaseDao { @Autowired DomainResourceDefDao testInstance; - @Before + @BeforeEach public void prepareDatabase() { // setup initial data! testUtilsDao.clearData(); @@ -48,18 +46,18 @@ public class DomainResourceDefDaoTest extends AbstractBaseDao { } @Test - public void getResourceDefConfigurationForDomain() { + void getResourceDefConfigurationForDomain() { // when List<DBDomainResourceDef> result = testInstance.getResourceDefConfigurationsForDomain(testUtilsDao.getD1()); - assertEquals(result.size(), 2); + assertEquals(2, result.size()); // definitions are sorted by id! assertEquals(testUtilsDao.getDomainResourceDefD1R1().getId(), result.get(0).getId()); assertEquals(testUtilsDao.getDomainResourceDefD1R2().getId(), result.get(1).getId()); } @Test - public void getResourceDefConfigurationForDomainAndResourceDef() { + void getResourceDefConfigurationForDomainAndResourceDef() { Optional<DBDomainResourceDef> result = testInstance.getResourceDefConfigurationForDomainCodeAndResourceDefCtx(TEST_DOMAIN_CODE_2, TEST_RESOURCE_DEF_SMP10_URL); @@ -68,7 +66,7 @@ public class DomainResourceDefDaoTest extends AbstractBaseDao { } @Test - public void getResourceDefConfigurationForDomainAndResourceDefNotExist() { + void getResourceDefConfigurationForDomainAndResourceDefNotExist() { Optional<DBDomainResourceDef> result = testInstance.getResourceDefConfigurationForDomainCodeAndResourceDefCtx(TEST_DOMAIN_CODE_2, TEST_RESOURCE_DEF_CPP); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/ExtensionDaoTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/ExtensionDaoTest.java index 963afc5017dd104c00aea76f98905341a0cbe119..0fdfbae75e60b59002194cad1bca20e7766cac6d 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/ExtensionDaoTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/ExtensionDaoTest.java @@ -20,27 +20,27 @@ package eu.europa.ec.edelivery.smp.data.dao; import eu.europa.ec.edelivery.smp.data.model.ext.DBExtension; import eu.europa.ec.edelivery.smp.testutil.TestDBUtils; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import javax.persistence.PersistenceException; import java.util.List; import java.util.Optional; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; /** * @author Joze Rihtarsic * @since 5.0 */ -public class ExtensionDaoTest extends AbstractBaseDao { +class ExtensionDaoTest extends AbstractBaseDao { @Autowired ExtensionDao testInstance; @Test - public void persistTest() { + void persistTest() { // set String testName = "TestClassName"; DBExtension testData = TestDBUtils.createDBExtension(testName); @@ -54,7 +54,7 @@ public class ExtensionDaoTest extends AbstractBaseDao { } @Test - public void persistDuplicate() { + void persistDuplicate() { // set String testName = "TestClassName"; DBExtension testData = TestDBUtils.createDBExtension(testName); @@ -66,7 +66,7 @@ public class ExtensionDaoTest extends AbstractBaseDao { } @Test - public void getDomainByIdentifier() { + void getDomainByIdentifier() { String testName = "TestClassNameIdentifier"; DBExtension testData = TestDBUtils.createDBExtension(testName); testInstance.persistFlushDetach(testData); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/GroupDaoTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/GroupDaoTest.java index 72288c78ed80946b07bf50cedaa25f7fad6899b8..101124bb8a91144f7db3b46a5bcc5d17f08b5cbd 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/GroupDaoTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/GroupDaoTest.java @@ -23,26 +23,26 @@ import eu.europa.ec.edelivery.smp.data.model.DBDomain; import eu.europa.ec.edelivery.smp.data.model.DBGroup; import eu.europa.ec.edelivery.smp.testutil.TestConstants; import eu.europa.ec.edelivery.smp.testutil.TestDBUtils; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import javax.persistence.PersistenceException; import java.util.List; import java.util.Optional; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; /** * @author Joze Rihtarsic * @since 5.0 */ -public class GroupDaoTest extends AbstractBaseDao { +class GroupDaoTest extends AbstractBaseDao { @Autowired GroupDao testInstance; - @Before + @BeforeEach public void prepareDatabase() { // setup initial data! testUtilsDao.clearData(); @@ -53,7 +53,7 @@ public class GroupDaoTest extends AbstractBaseDao { @Test - public void persistTest() { + void persistTest() { DBDomain domain = testUtilsDao.getD1(); int initSize = testInstance.getAllGroupsForDomain(domain).size(); @@ -68,7 +68,7 @@ public class GroupDaoTest extends AbstractBaseDao { } @Test - public void persistDuplicate() { + void persistDuplicate() { // set DBDomain domain = testUtilsDao.getD1(); @@ -81,7 +81,7 @@ public class GroupDaoTest extends AbstractBaseDao { } @Test - public void getDomainByCodeExists() { + void getDomainByCodeExists() { // set DBDomain domain = testUtilsDao.getD1(); @@ -92,7 +92,7 @@ public class GroupDaoTest extends AbstractBaseDao { } @Test - public void getDomainByCodeNotExists() { + void getDomainByCodeNotExists() { // set DBDomain domain = testUtilsDao.getD1(); // test @@ -101,7 +101,7 @@ public class GroupDaoTest extends AbstractBaseDao { } @Test - public void removeByDomainCodeExists() { + void removeByDomainCodeExists() { // set DBDomain domain = testUtilsDao.getD1(); @@ -116,7 +116,7 @@ public class GroupDaoTest extends AbstractBaseDao { } @Test - public void getGroupsByDomainUserIdAndGroupRolesExists() { + void getGroupsByDomainUserIdAndGroupRolesExists() { List<DBGroup> groups = testInstance.getGroupsByDomainUserIdAndGroupRoles( testUtilsDao.getD1().getId(), @@ -148,7 +148,7 @@ public class GroupDaoTest extends AbstractBaseDao { } @Test - public void getGroupsByDomainUserIdAndResourceRoles() { + void getGroupsByDomainUserIdAndResourceRoles() { List<DBGroup> groups = testInstance.getGroupsByDomainUserIdAndResourceRoles( testUtilsDao.getD1().getId(), diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/GroupMemberDaoTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/GroupMemberDaoTest.java index 5b4b7998b7d9feed2a4162c5b50b51007c728c6e..3bc81b2fd426dc503897ac76cadde8700cbefeaa 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/GroupMemberDaoTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/GroupMemberDaoTest.java @@ -23,25 +23,25 @@ import eu.europa.ec.edelivery.smp.data.model.DBGroup; import eu.europa.ec.edelivery.smp.data.model.user.DBGroupMember; import eu.europa.ec.edelivery.smp.data.model.user.DBUser; import org.apache.commons.lang3.StringUtils; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import java.util.Collections; import java.util.List; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; /** * @author Joze Rihtarsic * @since 5.0 */ -public class GroupMemberDaoTest extends AbstractBaseDao { +class GroupMemberDaoTest extends AbstractBaseDao { @Autowired GroupMemberDao testInstance; - @Before + @BeforeEach public void init() { testUtilsDao.clearData(); testUtilsDao.createUsers(); @@ -50,7 +50,7 @@ public class GroupMemberDaoTest extends AbstractBaseDao { } @Test - public void testIsUserGroupMember() { + void testIsUserGroupMember() { DBUser user = testUtilsDao.getUser1(); DBGroup group = testUtilsDao.getGroupD1G1(); @@ -66,7 +66,7 @@ public class GroupMemberDaoTest extends AbstractBaseDao { } @Test - public void testIsUserGroupMemberFalse() { + void testIsUserGroupMemberFalse() { DBUser user = testUtilsDao.getUser1(); DBGroup group = testUtilsDao.getGroupD1G1(); @@ -77,7 +77,7 @@ public class GroupMemberDaoTest extends AbstractBaseDao { } @Test - public void testIsUserGroupMemberWithRole() { + void testIsUserGroupMemberWithRole() { DBUser user = testUtilsDao.getUser1(); DBGroup group = testUtilsDao.getGroupD1G1(); @@ -94,7 +94,7 @@ public class GroupMemberDaoTest extends AbstractBaseDao { } @Test - public void isUserAnyDomainGroupResourceMember() { + void isUserAnyDomainGroupResourceMember() { DBUser user = testUtilsDao.getUser1(); DBGroup group = testUtilsDao.getGroupD1G1(); @@ -112,7 +112,7 @@ public class GroupMemberDaoTest extends AbstractBaseDao { } @Test - public void isUserAnyDomainGroupResourceMemberWithRole() { + void isUserAnyDomainGroupResourceMemberWithRole() { DBUser user = testUtilsDao.getUser1(); DBGroup group = testUtilsDao.getGroupD1G1(); @@ -129,7 +129,7 @@ public class GroupMemberDaoTest extends AbstractBaseDao { } @Test - public void testGetGroupMembersOne() { + void testGetGroupMembersOne() { DBGroup group = testUtilsDao.getGroupD1G1(); DBUser user = testUtilsDao.getUser1(); addMemberToGroup(user, group, MembershipRoleType.ADMIN); @@ -141,7 +141,7 @@ public class GroupMemberDaoTest extends AbstractBaseDao { } @Test - public void testGetDomainMembersOneFilter() { + void testGetDomainMembersOneFilter() { DBGroup group = testUtilsDao.getGroupD1G1(); DBUser user = testUtilsDao.getUser1(); addMemberToGroup(user, group, MembershipRoleType.ADMIN); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/ResourceDaoMembershipIntegrationTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/ResourceDaoMembershipIntegrationTest.java index f67588b21683ca90001e1c5ffd6db7b7180c6e81..05a100bfce028b7f9516f075746ba20781cf26b1 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/ResourceDaoMembershipIntegrationTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/ResourceDaoMembershipIntegrationTest.java @@ -23,12 +23,12 @@ import eu.europa.ec.edelivery.smp.data.model.doc.DBResource; import eu.europa.ec.edelivery.smp.data.model.user.DBResourceMember; import eu.europa.ec.edelivery.smp.data.model.user.DBUser; import eu.europa.ec.edelivery.smp.testutil.TestConstants; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.transaction.annotation.Transactional; import java.util.Optional; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; /** @@ -37,11 +37,11 @@ import static org.junit.Assert.*; * @author Joze Rihtarsic * @since 4.1 */ -public class ResourceDaoMembershipIntegrationTest extends AbstractResourceDaoTest { +class ResourceDaoMembershipIntegrationTest extends AbstractResourceDaoTest { @Test @Transactional - public void persistNewResourceWithMember() { + void persistNewResourceWithMember() { DBResource resource = createResourceWithMembers(TestConstants.USERNAME_1); Optional<DBResource> res = testInstance.findServiceGroup(resource.getIdentifierValue(), resource.getIdentifierScheme()); @@ -54,7 +54,7 @@ public class ResourceDaoMembershipIntegrationTest extends AbstractResourceDaoTes @Test @Transactional - public void addTwoMembersToServiceGroup() { + void addTwoMembersToServiceGroup() { DBResource resource = createResourceWithMembers(TestConstants.USERNAME_1, TestConstants.USERNAME_3); Optional<DBResource> res = testInstance.findServiceGroup(resource.getIdentifierValue(), resource.getIdentifierScheme()); @@ -64,7 +64,7 @@ public class ResourceDaoMembershipIntegrationTest extends AbstractResourceDaoTes @Test @Transactional - public void removeMemberFromResource() { + void removeMemberFromResource() { DBResource resource = createResourceWithMembers(TestConstants.USERNAME_1, TestConstants.USERNAME_3); assertEquals(2, resource.getMembers().size()); @@ -89,5 +89,4 @@ public class ResourceDaoMembershipIntegrationTest extends AbstractResourceDaoTes testInstance.clearPersistenceContext(); return resource; } - } diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/ResourceDaoSearchTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/ResourceDaoSearchTest.java index e81f9669c3bee440a32f613b84dd64280fea8260..b9c61a51f35f483aac9a4b812e25fde0661bc967 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/ResourceDaoSearchTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/ResourceDaoSearchTest.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -22,10 +22,8 @@ package eu.europa.ec.edelivery.smp.data.dao; import eu.europa.ec.edelivery.smp.data.model.doc.DBResource; import eu.europa.ec.edelivery.smp.data.model.doc.DBResourceFilter; import org.hamcrest.CoreMatchers; -import org.hamcrest.MatcherAssert; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -34,6 +32,9 @@ import org.springframework.transaction.annotation.Transactional; import java.util.List; import java.util.stream.Collectors; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.*; + /** * Purpose of class is to test all resource methods with database. * @@ -41,13 +42,13 @@ import java.util.stream.Collectors; * @since 5.0 */ -public class ResourceDaoSearchTest extends AbstractBaseDao { +class ResourceDaoSearchTest extends AbstractBaseDao { private static final Logger LOG = LoggerFactory.getLogger(ResourceDaoSearchTest.class); @Autowired ResourceDao testInstance; - @Before + @BeforeEach public void prepareDatabase() { // setup initial data! testUtilsDao.clearData(); @@ -56,89 +57,89 @@ public class ResourceDaoSearchTest extends AbstractBaseDao { @Test @Transactional - public void getAllPublicResources() { + void getAllPublicResources() { List<DBResource> allResources = testInstance.getResourcesForFilter(-1, -1, DBResourceFilter.createBuilder().build()); - Assert.assertEquals(8, allResources.size()); + assertEquals(8, allResources.size()); // only one group is public - - List<DBResource> result = testInstance.getPublicResourcesSearch(-1,-1,null, null, null); - Assert.assertEquals(1, result.size()); + List<DBResource> result = testInstance.getPublicResourcesSearch(-1, -1, null, null, null); + assertEquals(1, result.size()); assertResources(result, "1-1-1::pubPubPub"); // user1 (admin) and user2 (viewer) are members of all resources - result = testInstance.getPublicResourcesSearch(-1,-1,testUtilsDao.getUser2(), null, null); - Assert.assertEquals(8, result.size()); + result = testInstance.getPublicResourcesSearch(-1, -1, testUtilsDao.getUser2(), null, null); + assertEquals(8, result.size()); - result = testInstance.getPublicResourcesSearch(-1,-1,testUtilsDao.getUser1(), null, "pubPub"); - Assert.assertEquals(2, result.size()); - result.forEach(resource -> MatcherAssert.assertThat(resource.getIdentifierValue(), CoreMatchers.containsString("pubPub"))); + result = testInstance.getPublicResourcesSearch(-1, -1, testUtilsDao.getUser1(), null, "pubPub"); + assertEquals(2, result.size()); + result.forEach(resource -> assertThat(resource.getIdentifierValue(), CoreMatchers.containsString("pubPub"))); - result = testInstance.getPublicResourcesSearch(-1,-1,testUtilsDao.getUser1(), "1-1",null); - Assert.assertEquals(1, result.size()); - result.forEach(resource -> MatcherAssert.assertThat(resource.getIdentifierScheme(), CoreMatchers.containsString("1-1"))); + result = testInstance.getPublicResourcesSearch(-1, -1, testUtilsDao.getUser1(), "1-1", null); + assertEquals(1, result.size()); + result.forEach(resource -> assertThat(resource.getIdentifierScheme(), CoreMatchers.containsString("1-1"))); - result = testInstance.getPublicResourcesSearch(-1,-1,testUtilsDao.getUser1(), "1-1","priv"); - Assert.assertEquals(0, result.size()); + result = testInstance.getPublicResourcesSearch(-1, -1, testUtilsDao.getUser1(), "1-1", "priv"); + assertEquals(0, result.size()); - result = testInstance.getPublicResourcesSearch(-1,-1,testUtilsDao.getUser2(), null, null); - Assert.assertEquals(8, result.size()); + result = testInstance.getPublicResourcesSearch(-1, -1, testUtilsDao.getUser2(), null, null); + assertEquals(8, result.size()); // user3 is direct member of private domain - can see only public resource on public groups - result = testInstance.getPublicResourcesSearch(-1,-1,testUtilsDao.getUser3(), null, null); + result = testInstance.getPublicResourcesSearch(-1, -1, testUtilsDao.getUser3(), null, null); assertResources(result, "1-1-1::pubPubPub", "5-5-5::privPubPub"); // user4 is direct member of private group in private domain - result = testInstance.getPublicResourcesSearch(-1,-1,testUtilsDao.getUser4(), null, null); + result = testInstance.getPublicResourcesSearch(-1, -1, testUtilsDao.getUser4(), null, null); assertResources(result, "1-1-1::pubPubPub", "5-5-5::privPubPub", "7-7-7::privPrivPub"); // user5 is direct member of private resource in private group in private domain - result = testInstance.getPublicResourcesSearch(-1,-1,testUtilsDao.getUser5(), null, null); + result = testInstance.getPublicResourcesSearch(-1, -1, testUtilsDao.getUser5(), null, null); assertResources(result, "1-1-1::pubPubPub", "5-5-5::privPubPub", "7-7-7::privPrivPub", "8-8-8::privPrivPriv"); } - public void assertResources(List<DBResource> result, String ... resourceIdentifiers) { - List<String> resultIdentifiers = result.stream().map(val-> val.getIdentifierScheme()+"::"+val.getIdentifierValue() ).collect(Collectors.toList()); + public void assertResources(List<DBResource> result, String... resourceIdentifiers) { + List<String> resultIdentifiers = result.stream().map(val -> val.getIdentifierScheme() + "::" + val.getIdentifierValue()).collect(Collectors.toList()); System.out.println(resultIdentifiers); - Assert.assertArrayEquals(resourceIdentifiers, resultIdentifiers.stream().toArray()); + assertArrayEquals(resourceIdentifiers, resultIdentifiers.stream().toArray()); } @Test - public void getAllPublicResourcesCount() { + void getAllPublicResourcesCount() { List<DBResource> allResources = testInstance.getResourcesForFilter(-1, -1, DBResourceFilter.createBuilder().build()); - Assert.assertEquals(8, allResources.size()); + assertEquals(8, allResources.size()); // only one group is public - Long result = testInstance.getPublicResourcesSearchCount(null, null, null); - Assert.assertEquals(1, result.intValue()); + assertEquals(1, result.intValue()); // user1 (admin) and user2 (viewer) are members of all resources result = testInstance.getPublicResourcesSearchCount(testUtilsDao.getUser1(), null, null); - Assert.assertEquals(8, result.intValue()); + assertEquals(8, result.intValue()); result = testInstance.getPublicResourcesSearchCount(testUtilsDao.getUser1(), null, "pubPub"); - Assert.assertEquals(2, result.intValue()); + assertEquals(2, result.intValue()); - result = testInstance.getPublicResourcesSearchCount(testUtilsDao.getUser1(), "1-1",null); - Assert.assertEquals(1, result.intValue()); + result = testInstance.getPublicResourcesSearchCount(testUtilsDao.getUser1(), "1-1", null); + assertEquals(1, result.intValue()); - result = testInstance.getPublicResourcesSearchCount(testUtilsDao.getUser1(), "1-1","priv"); - Assert.assertEquals(0, result.intValue()); + result = testInstance.getPublicResourcesSearchCount(testUtilsDao.getUser1(), "1-1", "priv"); + assertEquals(0, result.intValue()); result = testInstance.getPublicResourcesSearchCount(testUtilsDao.getUser2(), null, null); - Assert.assertEquals(8, result.intValue()); + assertEquals(8, result.intValue()); // user3 is direct member of private domain - can see only public resource on public groups result = testInstance.getPublicResourcesSearchCount(testUtilsDao.getUser3(), null, null); - Assert.assertEquals(2, result.intValue()); + assertEquals(2, result.intValue()); // user4 is direct member of private group in private domain result = testInstance.getPublicResourcesSearchCount(testUtilsDao.getUser4(), null, null); - Assert.assertEquals(3, result.intValue()); + assertEquals(3, result.intValue()); // user5 is direct member of private resource in private group in private domain result = testInstance.getPublicResourcesSearchCount(testUtilsDao.getUser5(), null, null); - Assert.assertEquals(4, result.intValue()); + assertEquals(4, result.intValue()); } diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/ResourceDaoTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/ResourceDaoTest.java index 6540685bd399dbb95ee7ce03c7a6fcb45ce7883f..292c0b88bb1a4f53991bdb9c584cfadb00cf742b 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/ResourceDaoTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/ResourceDaoTest.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -28,9 +28,8 @@ import eu.europa.ec.edelivery.smp.data.model.doc.DBResourceFilter; import eu.europa.ec.edelivery.smp.data.model.ext.DBResourceDef; import eu.europa.ec.edelivery.smp.data.model.user.DBUser; import eu.europa.ec.edelivery.smp.testutil.TestDBUtils; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -40,6 +39,7 @@ import java.util.List; import java.util.Optional; import static eu.europa.ec.edelivery.smp.testutil.TestConstants.*; +import static org.junit.jupiter.api.Assertions.*; /** * Purpose of class is to test all resource methods with database. @@ -48,13 +48,13 @@ import static eu.europa.ec.edelivery.smp.testutil.TestConstants.*; * @since 5.0 */ -public class ResourceDaoTest extends AbstractBaseDao { +class ResourceDaoTest extends AbstractBaseDao { private static final Logger LOG = LoggerFactory.getLogger(ResourceDaoTest.class); @Autowired ResourceDao testInstance; - @Before + @BeforeEach public void prepareDatabase() { // setup initial data! testUtilsDao.clearData(); @@ -63,7 +63,7 @@ public class ResourceDaoTest extends AbstractBaseDao { @Test @Transactional - public void persistNewResourceWithDocument() { + void persistNewResourceWithDocument() { String testIdValue = "test-resource-id"; String testIdSchema = "test-resource-scheme"; DBResource testData = TestDBUtils.createDBResource(testIdValue, testIdSchema); @@ -78,21 +78,21 @@ public class ResourceDaoTest extends AbstractBaseDao { Optional<DBResource> optResult = testInstance.getResource(testIdValue, testIdSchema, testUtilsDao.getResourceDefSmp(), testUtilsDao.getD1()); - Assert.assertTrue(optResult.isPresent()); - Assert.assertNotNull(optResult.get().getDocument()); - Assert.assertNotNull(optResult.get().getDocument().getId()); - Assert.assertEquals(1, optResult.get().getDocument().getCurrentVersion()); - Assert.assertEquals(1, optResult.get().getDocument().getDocumentVersions().size()); - Assert.assertNotNull(optResult.get().getDocument().getDocumentVersions().get(0).getId()); - Assert.assertEquals(1, optResult.get().getDocument().getDocumentVersions().get(0).getVersion()); + assertTrue(optResult.isPresent()); + assertNotNull(optResult.get().getDocument()); + assertNotNull(optResult.get().getDocument().getId()); + assertEquals(1, optResult.get().getDocument().getCurrentVersion()); + assertEquals(1, optResult.get().getDocument().getDocumentVersions().size()); + assertNotNull(optResult.get().getDocument().getDocumentVersions().get(0).getId()); + assertEquals(1, optResult.get().getDocument().getDocumentVersions().get(0).getVersion()); } @Test @Transactional - public void persistNewVersionToResourceWithDocument() { + void persistNewVersionToResourceWithDocument() { Optional<DBResource> optResource = testInstance.getResource(TEST_SG_ID_1, TEST_SG_SCHEMA_1, testUtilsDao.getResourceDefSmp(), testUtilsDao.getD1()); - Assert.assertTrue(optResource.isPresent()); + assertTrue(optResource.isPresent()); DBResource resource = testInstance.find(optResource.get().getId()); int docCount = resource.getDocument().getDocumentVersions().size(); @@ -105,110 +105,110 @@ public class ResourceDaoTest extends AbstractBaseDao { Optional<DBResource> optResult = testInstance.getResource(TEST_SG_ID_1, TEST_SG_SCHEMA_1, testUtilsDao.getResourceDefSmp(), testUtilsDao.getD1()); - Assert.assertTrue(optResult.isPresent()); - Assert.assertNotNull(optResult.get().getDocument()); - Assert.assertEquals(docVersion + 1, optResult.get().getDocument().getCurrentVersion()); - Assert.assertEquals(docCount + 1, optResult.get().getDocument().getDocumentVersions().size()); + assertTrue(optResult.isPresent()); + assertNotNull(optResult.get().getDocument()); + assertEquals(docVersion + 1, optResult.get().getDocument().getCurrentVersion()); + assertEquals(docCount + 1, optResult.get().getDocument().getDocumentVersions().size()); } @Test - public void getResourceOK() { + void getResourceOK() { Optional<DBResource> optResource = testInstance.getResource(TEST_SG_ID_1, TEST_SG_SCHEMA_1, testUtilsDao.getResourceDefSmp(), testUtilsDao.getD1()); - Assert.assertTrue(optResource.isPresent()); - Assert.assertEquals(testUtilsDao.getResourceD1G1RD1().getId(), optResource.get().getId()); + assertTrue(optResource.isPresent()); + assertEquals(testUtilsDao.getResourceD1G1RD1().getId(), optResource.get().getId()); } @Test - public void getResourceOKNullSchema() { + void getResourceOKNullSchema() { Optional<DBResource> optResource = testInstance.getResource(TEST_SG_ID_2, null, testUtilsDao.getResourceDefSmp(), testUtilsDao.getD2()); - Assert.assertTrue(optResource.isPresent()); - Assert.assertEquals(testUtilsDao.getResourceD2G1RD1().getId(), optResource.get().getId()); + assertTrue(optResource.isPresent()); + assertEquals(testUtilsDao.getResourceD2G1RD1().getId(), optResource.get().getId()); } @Test - public void getResourceNotExists() { + void getResourceNotExists() { Optional<DBResource> optResource = testInstance.getResource(TEST_SG_ID_1, "WrongSchema", testUtilsDao.getResourceDefSmp(), testUtilsDao.getD1()); - Assert.assertFalse(optResource.isPresent()); + assertFalse(optResource.isPresent()); } @Test - public void getResourceWrongDomain() { + void getResourceWrongDomain() { Optional<DBResource> optResource = testInstance.getResource(TEST_SG_ID_1, TEST_SG_SCHEMA_1, testUtilsDao.getResourceDefSmp(), testUtilsDao.getD2()); - Assert.assertFalse(optResource.isPresent()); + assertFalse(optResource.isPresent()); } @Test - public void getResourceWrongResourceDef() { + void getResourceWrongResourceDef() { Optional<DBResource> optResource = testInstance.getResource(TEST_SG_ID_1, TEST_SG_SCHEMA_1, testUtilsDao.getResourceDefCpp(), testUtilsDao.getD1()); - Assert.assertFalse(optResource.isPresent()); + assertFalse(optResource.isPresent()); } @Test - public void deleteResourceSimpleOK() { + void deleteResourceSimpleOK() { Optional<DBResource> optResource = testInstance.getResource(TEST_SG_ID_1, TEST_SG_SCHEMA_1, testUtilsDao.getResourceDefSmp(), testUtilsDao.getD1()); - Assert.assertTrue(optResource.isPresent()); + assertTrue(optResource.isPresent()); // then testInstance.remove(optResource.get()); Optional<DBResource> optResult = testInstance.getResource(TEST_SG_ID_1, TEST_SG_SCHEMA_1, testUtilsDao.getResourceDefSmp(), testUtilsDao.getD1()); - Assert.assertFalse(optResult.isPresent()); + assertFalse(optResult.isPresent()); } @Test - public void deleteResourceJoinTableOK() { + void deleteResourceJoinTableOK() { testUtilsDao.createSubresources(); Optional<DBResource> optResource = testInstance.getResource(TEST_SG_ID_1, TEST_SG_SCHEMA_1, testUtilsDao.getResourceDefSmp(), testUtilsDao.getD1()); - Assert.assertTrue(optResource.isPresent()); + assertTrue(optResource.isPresent()); // then testInstance.remove(optResource.get()); Optional<DBResource> optResult = testInstance.getResource(TEST_SG_ID_1, TEST_SG_SCHEMA_1, testUtilsDao.getResourceDefSmp(), testUtilsDao.getD1()); - Assert.assertFalse(optResult.isPresent()); + assertFalse(optResult.isPresent()); } @Test - public void getAllPublicResources() { + void getAllPublicResources() { List<DBResource> result = testInstance.getResourcesForFilter(-1, -1, creatResourceFilter(null, null, null)); //System.out.println(result.get(0)); - Assert.assertEquals(2, result.size()); + assertEquals(2, result.size()); result = testInstance.getResourcesForFilter(-1, -1, DBResourceFilter.createBuilder().identifierFilter("test").build()); - Assert.assertEquals(2, result.size()); + assertEquals(2, result.size()); result = testInstance.getResourcesForFilter(-1, -1, DBResourceFilter.createBuilder().identifierFilter("actorid").build()); - Assert.assertEquals(1, result.size()); + assertEquals(1, result.size()); result = testInstance.getResourcesForFilter(0, 1, creatResourceFilter(null, null, null)); - Assert.assertEquals(1, result.size()); + assertEquals(1, result.size()); result = testInstance.getResourcesForFilter(-1, -1, creatResourceFilter(testUtilsDao.getGroupD1G1(), null, null)); - Assert.assertEquals(1, result.size()); + assertEquals(1, result.size()); - result = testInstance.getResourcesForFilter(-1, -1,creatResourceFilter( null, testUtilsDao.getD1(), null)); - Assert.assertEquals(1, result.size()); + result = testInstance.getResourcesForFilter(-1, -1, creatResourceFilter(null, testUtilsDao.getD1(), null)); + assertEquals(1, result.size()); result = testInstance.getResourcesForFilter(-1, -1, creatResourceFilter(null, null, testUtilsDao.getResourceDefSmp())); - Assert.assertEquals(2, result.size()); + assertEquals(2, result.size()); result = testInstance.getResourcesForFilter(-1, -1, creatResourceFilter(testUtilsDao.getGroupD1G1(), testUtilsDao.getD1(), testUtilsDao.getResourceDefSmp())); - Assert.assertEquals(1, result.size()); + assertEquals(1, result.size()); - result = testInstance.getResourcesForFilter(-1, -1,creatResourceFilter(testUtilsDao.getGroupD1G1(), + result = testInstance.getResourcesForFilter(-1, -1, creatResourceFilter(testUtilsDao.getGroupD1G1(), testUtilsDao.getD1(), testUtilsDao.getResourceDefSmp(), testUtilsDao.getUser1(), MembershipRoleType.ADMIN)); - Assert.assertEquals(1, result.size()); + assertEquals(1, result.size()); - result = testInstance.getResourcesForFilter(-1, -1,creatResourceFilter(testUtilsDao.getGroupD1G1(), + result = testInstance.getResourcesForFilter(-1, -1, creatResourceFilter(testUtilsDao.getGroupD1G1(), testUtilsDao.getD1(), testUtilsDao.getResourceDefSmp(), testUtilsDao.getUser1(), MembershipRoleType.ADMIN)); - Assert.assertEquals(1, result.size()); + assertEquals(1, result.size()); - result = testInstance.getResourcesForFilter(-1, -1,creatResourceFilter(testUtilsDao.getGroupD1G1(), + result = testInstance.getResourcesForFilter(-1, -1, creatResourceFilter(testUtilsDao.getGroupD1G1(), testUtilsDao.getD1(), testUtilsDao.getResourceDefSmp(), testUtilsDao.getUser2(), MembershipRoleType.ADMIN)); - Assert.assertEquals(0, result.size()); + assertEquals(0, result.size()); } @@ -216,53 +216,54 @@ public class ResourceDaoTest extends AbstractBaseDao { * test filter. - TODO when moving to JUNIT5 parametrize this method! */ @Test - public void getAllResourcesCount() { + void getAllResourcesCount() { Long result = testInstance.getResourcesForFilterCount(creatResourceFilter(null, null, null)); - Assert.assertEquals(2, result.intValue()); + assertEquals(2, result.intValue()); result = testInstance.getResourcesForFilterCount(creatResourceFilter(testUtilsDao.getGroupD1G1(), null, null)); - Assert.assertEquals(1, result.intValue()); + assertEquals(1, result.intValue()); - result = testInstance.getResourcesForFilterCount( DBResourceFilter.createBuilder().identifierFilter("test").build()); - Assert.assertEquals(2, result.intValue()); + result = testInstance.getResourcesForFilterCount(DBResourceFilter.createBuilder().identifierFilter("test").build()); + assertEquals(2, result.intValue()); - result = testInstance.getResourcesForFilterCount( DBResourceFilter.createBuilder().identifierFilter("actorid").build()); - Assert.assertEquals(1, result.intValue()); + result = testInstance.getResourcesForFilterCount(DBResourceFilter.createBuilder().identifierFilter("actorid").build()); + assertEquals(1, result.intValue()); result = testInstance.getResourcesForFilterCount(creatResourceFilter(null, testUtilsDao.getD1(), null)); - Assert.assertEquals(1, result.intValue()); + assertEquals(1, result.intValue()); result = testInstance.getResourcesForFilterCount(creatResourceFilter(null, null, testUtilsDao.getResourceDefSmp())); - Assert.assertEquals(2, result.intValue()); + assertEquals(2, result.intValue()); result = testInstance.getResourcesForFilterCount(creatResourceFilter(testUtilsDao.getGroupD1G1(), testUtilsDao.getD1(), testUtilsDao.getResourceDefSmp())); - Assert.assertEquals(1, result.intValue()); + assertEquals(1, result.intValue()); result = testInstance.getResourcesForFilterCount(creatResourceFilter(testUtilsDao.getGroupD1G1(), testUtilsDao.getD1(), testUtilsDao.getResourceDefSmp())); - Assert.assertEquals(1, result.intValue()); + assertEquals(1, result.intValue()); result = testInstance.getResourcesForFilterCount(creatResourceFilter(testUtilsDao.getGroupD1G1(), testUtilsDao.getD1(), testUtilsDao.getResourceDefSmp(), testUtilsDao.getUser1(), MembershipRoleType.ADMIN)); - Assert.assertEquals(1, result.intValue()); + assertEquals(1, result.intValue()); result = testInstance.getResourcesForFilterCount(creatResourceFilter(testUtilsDao.getGroupD1G1(), testUtilsDao.getD1(), testUtilsDao.getResourceDefSmp(), testUtilsDao.getUser1(), MembershipRoleType.ADMIN)); - Assert.assertEquals(1, result.intValue()); + assertEquals(1, result.intValue()); result = testInstance.getResourcesForFilterCount(creatResourceFilter(testUtilsDao.getGroupD1G1(), testUtilsDao.getD1(), testUtilsDao.getResourceDefSmp(), testUtilsDao.getUser2(), MembershipRoleType.ADMIN)); - Assert.assertEquals(0, result.intValue()); + assertEquals(0, result.intValue()); } protected static DBResourceFilter creatResourceFilter(DBGroup group, DBDomain domain, DBResourceDef resourceDef) { - return creatResourceFilter(group, domain, resourceDef, null, null); + return creatResourceFilter(group, domain, resourceDef, null, null); } + protected static DBResourceFilter creatResourceFilter(DBGroup group, DBDomain domain, DBResourceDef resourceDef, DBUser user, MembershipRoleType membershipRoleType) { return DBResourceFilter.createBuilder() .resourceDef(resourceDef) diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/ResourceDefDaoTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/ResourceDefDaoTest.java index d6a4bb52eda384a737f8ac2c7bbdd6f1e0fdd47f..219e89b92273b04c347c64a2c6c7aa4fba4ecdfb 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/ResourceDefDaoTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/ResourceDefDaoTest.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -20,26 +20,26 @@ package eu.europa.ec.edelivery.smp.data.dao; import eu.europa.ec.edelivery.smp.data.model.ext.DBResourceDef; import eu.europa.ec.edelivery.smp.testutil.TestDBUtils; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import javax.persistence.PersistenceException; import java.util.List; import java.util.Optional; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; /** * @author Joze Rihtarsic * @since 5.0 */ -public class ResourceDefDaoTest extends AbstractBaseDao { +class ResourceDefDaoTest extends AbstractBaseDao { @Autowired ResourceDefDao testInstance; - @Before + @BeforeEach public void init() { testUtilsDao.clearData(); testUtilsDao.createExtension(); @@ -47,7 +47,7 @@ public class ResourceDefDaoTest extends AbstractBaseDao { } @Test - public void persistTest() { + void persistTest() { // set String testName = "TestClassName"; DBResourceDef testData = TestDBUtils.createDBResourceDef(testName); @@ -62,7 +62,7 @@ public class ResourceDefDaoTest extends AbstractBaseDao { @Test - public void persistDuplicateUrlError() { + void persistDuplicateUrlError() { // set String testURL = "TestClassName"; DBResourceDef testData1 = TestDBUtils.createDBResourceDef("resourceDef1"); @@ -80,7 +80,7 @@ public class ResourceDefDaoTest extends AbstractBaseDao { } @Test - public void getExtensionByImplementationName() { + void getExtensionByImplementationName() { String testName = "TestClassName"; DBResourceDef testData = TestDBUtils.createDBResourceDef(testName); testData.setExtension(testUtilsDao.getExtension()); @@ -93,7 +93,7 @@ public class ResourceDefDaoTest extends AbstractBaseDao { } @Test - public void getResourceDefByURLSegment() { + void getResourceDefByURLSegment() { String testUrlSegment = "testUrlSegment"; DBResourceDef testData = TestDBUtils.createDBResourceDef("Code"); testData.setUrlSegment(testUrlSegment); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/ResourceMemberDaoTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/ResourceMemberDaoTest.java index a8010d8bf45b706d407e24582cf6fb7792743d5e..a3bf0647b3d1c387040a96862e663b4e641abf29 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/ResourceMemberDaoTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/ResourceMemberDaoTest.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -22,18 +22,19 @@ import eu.europa.ec.edelivery.smp.data.enums.MembershipRoleType; import eu.europa.ec.edelivery.smp.data.model.doc.DBResource; import eu.europa.ec.edelivery.smp.data.model.user.DBResourceMember; import eu.europa.ec.edelivery.smp.data.model.user.DBUser; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + /** * @author Joze Rihtarsic * @since 5.0 */ -public class ResourceMemberDaoTest extends AbstractBaseDao { +class ResourceMemberDaoTest extends AbstractBaseDao { @Autowired UserDao userDao; @@ -42,7 +43,7 @@ public class ResourceMemberDaoTest extends AbstractBaseDao { @Autowired ResourceMemberDao testInstance; - @Before + @BeforeEach public void prepareDatabase() { // setup initial data! testUtilsDao.clearData(); @@ -51,7 +52,7 @@ public class ResourceMemberDaoTest extends AbstractBaseDao { } @Test - public void testIsUserDomainsMember() { + void testIsUserDomainsMember() { DBUser user = testUtilsDao.getUser1(); DBResource resource = testUtilsDao.getResourceD2G1RD1(); @@ -67,7 +68,7 @@ public class ResourceMemberDaoTest extends AbstractBaseDao { } @Test - public void testIsUserDomainsMemberFalse() { + void testIsUserDomainsMemberFalse() { // user is not member to resource D2G1RD1 by default DBUser user = testUtilsDao.getUser1(); DBResource resource = testUtilsDao.getResourceD2G1RD1(); @@ -78,7 +79,7 @@ public class ResourceMemberDaoTest extends AbstractBaseDao { } @Test - public void testIsUserDomainsMemberWithRole() { + void testIsUserDomainsMemberWithRole() { DBUser user = testUtilsDao.getUser1(); DBResource resource = testUtilsDao.getResourceD2G1RD1(); DBResourceMember resourceMember = new DBResourceMember(); @@ -96,7 +97,7 @@ public class ResourceMemberDaoTest extends AbstractBaseDao { @Test - public void isUserAnyDomainResourceMember() { + void isUserAnyDomainResourceMember() { DBUser user = testUtilsDao.getUser1(); DBResource resource = testUtilsDao.getResourceD2G1RD1(); DBResourceMember resourceMember = new DBResourceMember(); @@ -116,7 +117,7 @@ public class ResourceMemberDaoTest extends AbstractBaseDao { } @Test - public void isUserAnyDomainResourceMemberWithRole() { + void isUserAnyDomainResourceMemberWithRole() { DBUser user = testUtilsDao.getUser1(); DBResource resource = testUtilsDao.getResourceD2G1RD1(); DBResourceMember resourceMember = new DBResourceMember(); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/SubresourceDaoTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/SubresourceDaoTest.java index 8549e7b8ba6d2e01eafd229a4cd9dce444d4e94e..bd0339fcda64e63e8b25c29bcb38dd80539b6d78 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/SubresourceDaoTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/SubresourceDaoTest.java @@ -20,21 +20,21 @@ package eu.europa.ec.edelivery.smp.data.dao; import eu.europa.ec.edelivery.smp.data.model.doc.DBSubresource; import eu.europa.ec.edelivery.smp.identifiers.Identifier; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import java.util.List; import java.util.Optional; import static eu.europa.ec.edelivery.smp.testutil.TestConstants.*; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -public class SubresourceDaoTest extends AbstractBaseDao { +class SubresourceDaoTest extends AbstractBaseDao { @Autowired SubresourceDao testInstance; - @Before + @BeforeEach public void prepareDatabase() { // setup initial data! testUtilsDao.clearData(); @@ -42,7 +42,7 @@ public class SubresourceDaoTest extends AbstractBaseDao { } @Test - public void getSubResource() { + void getSubResource() { Identifier suberesId = new Identifier(TEST_DOC_ID_1,TEST_DOC_SCHEMA_1 ); Optional<DBSubresource> subresource = testInstance.getSubResource(suberesId, testUtilsDao.getResourceD1G1RD1(), TEST_SUBRESOURCE_DEF_SMP10_URL); @@ -51,7 +51,7 @@ public class SubresourceDaoTest extends AbstractBaseDao { } @Test - public void getSubResourceWrongResource() { + void getSubResourceWrongResource() { Identifier suberesId = new Identifier(TEST_DOC_ID_1,TEST_DOC_SCHEMA_1 ); Optional<DBSubresource> subresource = testInstance.getSubResource(suberesId, testUtilsDao.getResourceD2G1RD1(), TEST_SUBRESOURCE_DEF_SMP10_URL); @@ -60,7 +60,7 @@ public class SubresourceDaoTest extends AbstractBaseDao { } @Test - public void getSubResourcesForResource() { + void getSubResourcesForResource() { Identifier identifier = new Identifier(TEST_SG_ID_1,TEST_SG_SCHEMA_1 ); List<DBSubresource> subresourceList = testInstance.getSubResourcesForResource(identifier, TEST_SUBRESOURCE_DEF_SMP10_ID); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/UserDaoIntegrationTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/UserDaoIntegrationTest.java index 05e72e37e671e4f824538094f8a0fe8441ca200e..988ea96bb5a417906d3445c749bc8916a88858a2 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/UserDaoIntegrationTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/UserDaoIntegrationTest.java @@ -25,14 +25,14 @@ import eu.europa.ec.edelivery.smp.testutil.TestConstants; import eu.europa.ec.edelivery.smp.testutil.TestDBUtils; import org.hamcrest.CoreMatchers; import org.hamcrest.MatcherAssert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; import java.util.Optional; import static eu.europa.ec.edelivery.smp.exceptions.ErrorCode.INVALID_USER_NO_IDENTIFIERS; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; /** @@ -41,7 +41,7 @@ import static org.junit.Assert.*; * @author Joze Rihtarsic * @since 4.1 */ -public class UserDaoIntegrationTest extends AbstractBaseDao { +class UserDaoIntegrationTest extends AbstractBaseDao { @Autowired UserDao testInstance; @@ -53,7 +53,7 @@ public class UserDaoIntegrationTest extends AbstractBaseDao { ResourceDao serviceGroupDao; @Test - public void persistUserWithoutIdentifier() { + void persistUserWithoutIdentifier() { // set DBUser u = new DBUser(); SMPRuntimeException result = assertThrows(SMPRuntimeException.class, () -> testInstance.persistFlushDetach(u)); @@ -62,7 +62,7 @@ public class UserDaoIntegrationTest extends AbstractBaseDao { } @Test - public void persistUserWithUsername() { + void persistUserWithUsername() { // set DBUser u = TestDBUtils.createDBUserByUsername(TestConstants.USERNAME_1); @@ -78,7 +78,7 @@ public class UserDaoIntegrationTest extends AbstractBaseDao { } @Test - public void persistUserWithoutCredentials() { + void persistUserWithoutCredentials() { DBUser u = TestDBUtils.createDBUserByUsername(TestConstants.USERNAME_1); assertTrue(u.getUserCredentials().isEmpty()); @@ -96,7 +96,7 @@ public class UserDaoIntegrationTest extends AbstractBaseDao { @Test @Transactional - public void persistUserWithUsernamePasswordCredential() { + void persistUserWithUsernamePasswordCredential() { // set DBUser u = TestDBUtils.createDBUserByUsername(TestConstants.USERNAME_2); DBCredential credential = TestDBUtils.createDBCredential(TestConstants.USERNAME_2); @@ -121,7 +121,7 @@ public class UserDaoIntegrationTest extends AbstractBaseDao { @Test @Transactional - public void persistUserWithCertificate() { + void persistUserWithCertificate() { // set DBUser u = TestDBUtils.createDBUserByCertificate(TestConstants.USER_CERT_1); DBCredential credential = u.getUserCredentials().get(0); @@ -149,7 +149,7 @@ public class UserDaoIntegrationTest extends AbstractBaseDao { } @Test - public void findCertUserByIdentifier() { + void findCertUserByIdentifier() { // set DBUser u = TestDBUtils.createDBUserByCertificate(TestConstants.USER_CERT_1); @@ -165,7 +165,7 @@ public class UserDaoIntegrationTest extends AbstractBaseDao { @Test @Transactional - public void findUsernameUserByIdentifier() { + void findUsernameUserByIdentifier() { // set DBUser u = TestDBUtils.createDBUserByUsername(TestConstants.USERNAME_1); DBCredential credential = TestDBUtils.createDBCredentialForUserAccessToken(u, null, null, null); @@ -182,7 +182,7 @@ public class UserDaoIntegrationTest extends AbstractBaseDao { } @Test - public void deleteUserWithCertificate() { + void deleteUserWithCertificate() { // given DBUser u = TestDBUtils.createDBUserByCertificate(TestConstants.USER_CERT_1); DBCredential credential = u.getUserCredentials().get(0); @@ -199,7 +199,7 @@ public class UserDaoIntegrationTest extends AbstractBaseDao { } @Test - public void findBlankUsernameUser() { + void findBlankUsernameUser() { // set DBUser u = TestDBUtils.createDBUserByUsername(TestConstants.USERNAME_1); @@ -218,7 +218,7 @@ public class UserDaoIntegrationTest extends AbstractBaseDao { } @Test - public void findNotExistsUsernameUser() { + void findNotExistsUsernameUser() { // set DBUser u = TestDBUtils.createDBUserByUsername(TestConstants.USERNAME_1); @@ -231,7 +231,7 @@ public class UserDaoIntegrationTest extends AbstractBaseDao { } @Test - public void findCaseInsensitiveUsernameUser() { + void findCaseInsensitiveUsernameUser() { // set DBUser u = TestDBUtils.createDBUserByUsername(TestConstants.USERNAME_1.toLowerCase()); @@ -243,6 +243,5 @@ public class UserDaoIntegrationTest extends AbstractBaseDao { assertTrue(ou.isPresent()); assertEquals(u, ou.get()); assertEquals(u.getEmailAddress(), ou.get().getEmailAddress()); - } } diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/utils/SMPMySQL5InnoDBDialectTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/utils/SMPMySQL5InnoDBDialectTest.java index ad1931854f7f0852b4cdc12390e5e22587c9d2d8..69e8e2fede9ae831a0feb926c159b9c23696a3eb 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/utils/SMPMySQL5InnoDBDialectTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/utils/SMPMySQL5InnoDBDialectTest.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -18,28 +18,30 @@ */ package eu.europa.ec.edelivery.smp.data.dao.utils; -import org.junit.Test; + +import org.junit.jupiter.api.Test; import java.sql.Types; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; + -public class SMPMySQL5InnoDBDialectTest { +class SMPMySQL5InnoDBDialectTest { SMPMySQL5InnoDBDialect testInstance = new SMPMySQL5InnoDBDialect(); @Test - public void getTableTypeString() { + void getTableTypeString() { assertEquals(" ENGINE=InnoDB DEFAULT CHARSET=utf8", testInstance.getTableTypeString()); } @Test - public void registerVarcharTypes() { + void registerVarcharTypes() { assertEquals("longtext", testInstance.getTypeName(Types.VARCHAR)); assertEquals("longtext", testInstance.getTypeName(Types.LONGVARCHAR)); - assertEquals("varchar(65535) CHARACTER SET utf8 COLLATE utf8_bin", testInstance.getTypeName(Types.VARCHAR, 65535,0,0)); + assertEquals("varchar(65535) CHARACTER SET utf8 COLLATE utf8_bin", testInstance.getTypeName(Types.VARCHAR, 65535, 0, 0)); } } diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/utils/SMPSchemaGeneratorTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/utils/SMPSchemaGeneratorTest.java index 4983a99e951aea6b8735b612c2db96af9986bdf7..55cdfb5bd15d7790d16fe02a98cdd059b5dbe3b2 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/utils/SMPSchemaGeneratorTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/utils/SMPSchemaGeneratorTest.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -18,22 +18,19 @@ */ package eu.europa.ec.edelivery.smp.data.dao.utils; -import junitparams.JUnitParamsRunner; -import junitparams.Parameters; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.io.File; import java.io.IOException; import java.util.Arrays; import java.util.List; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -@RunWith(JUnitParamsRunner.class) -public class SMPSchemaGeneratorTest { +class SMPSchemaGeneratorTest { private static final String DIALECT_ORACLE = "org.hibernate.dialect.Oracle10gDialect"; private static final String DIALECT_MYSQL_INNO5 = "org.hibernate.dialect.MySQL5InnoDBDialect"; @@ -41,7 +38,7 @@ public class SMPSchemaGeneratorTest { protected static String ENTITY_PACKAGES = "eu.europa.ec.edelivery.smp.data.model,eu.europa.ec.edelivery.smp.data.model.user,eu.europa.ec.edelivery.smp.data.model.doc,eu.europa.ec.edelivery.smp.data.model.ext"; - private static final Object[] dialectTestCases() { + private static Object[] dialectTestCases() { return new Object[][]{ {DIALECT_MYSQL_INNO5, "eu.europa.ec.edelivery.smp.data.dao.utils.SMPMySQL5InnoDBDialect"}, {DIALECT_ORACLE, DIALECT_ORACLE}, @@ -51,15 +48,12 @@ public class SMPSchemaGeneratorTest { }; } - @Rule - public ExpectedException expectedEx = ExpectedException.none(); - SMPSchemaGenerator testInstance = new SMPSchemaGenerator(); @Test - public void createDDLScript() throws ClassNotFoundException, IOException { + void createDDLScript() throws ClassNotFoundException, IOException { // given String folder = "target"; String dialect = DIALECT_ORACLE; @@ -82,7 +76,7 @@ public class SMPSchemaGeneratorTest { } @Test - public void createFileNameOracleDialect() { + void createFileNameOracleDialect() { String dialect = DIALECT_ORACLE; //when String filaName = testInstance.createFileName(dialect, SMPSchemaGenerator.filenameTemplate); @@ -91,7 +85,7 @@ public class SMPSchemaGeneratorTest { } @Test - public void createFileNameMySQLDialect() { + void createFileNameMySQLDialect() { // given String dialect = DIALECT_MYSQL_INNO5; //when @@ -101,7 +95,7 @@ public class SMPSchemaGeneratorTest { } @Test - public void createDropFileNameOracleDialect() { + void createDropFileNameOracleDialect() { String dialect = DIALECT_ORACLE; //when String fileName = testInstance.createFileName(dialect, SMPSchemaGenerator.filenameDropTemplate); @@ -110,7 +104,7 @@ public class SMPSchemaGeneratorTest { } @Test - public void createDropFileNameMySQLDialect() { + void createDropFileNameMySQLDialect() { // given String dialect = DIALECT_MYSQL_INNO5; //when @@ -119,9 +113,10 @@ public class SMPSchemaGeneratorTest { assertEquals("mysql5innodb-drop.ddl", fileName); } - @Test - @Parameters(method = "dialectTestCases") - public void getDialect(String input, String output) { + + @ParameterizedTest + @MethodSource("dialectTestCases") + void getDialect(String input, String output) { //when String result = testInstance.getDialect(input); @@ -130,15 +125,14 @@ public class SMPSchemaGeneratorTest { } @Test - public void getAllEntityClassesNotFound() throws ClassNotFoundException { + void getAllEntityClassesNotFound() { - expectedEx.expect(ClassNotFoundException.class); + assertThrows(ClassNotFoundException.class, () -> testInstance.getAllEntityClasses("eu.not.exists")); - testInstance.getAllEntityClasses("eu.not.exists"); } @Test - public void getAllEntityClasses() throws ClassNotFoundException { + void getAllEntityClasses() throws ClassNotFoundException { // given when List<Class> result = testInstance.getAllEntityClasses("eu.europa.ec.edelivery.smp.data.model"); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/ui/databind/SMPAuthorityDeserializerTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/ui/databind/SMPAuthorityDeserializerTest.java index 3103310285d35f55d7a775cb188920981cf29357..b2f114e4d4da598c0467c654ec57adea99ee2d7c 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/ui/databind/SMPAuthorityDeserializerTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/ui/databind/SMPAuthorityDeserializerTest.java @@ -21,12 +21,12 @@ package eu.europa.ec.edelivery.smp.data.ui.databind; import com.fasterxml.jackson.databind.ObjectMapper; import eu.europa.ec.edelivery.smp.data.ui.UserRO; import eu.europa.ec.edelivery.smp.data.ui.auth.SMPAuthority; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.*; + /** @@ -35,10 +35,10 @@ import static org.junit.Assert.assertNotNull; * @author Joze Rihtarsic * @since 4.2 */ -public class SMPAuthorityDeserializerTest { +class SMPAuthorityDeserializerTest { @Test - public void deserialize() throws IOException { + void deserialize() throws IOException { String value = "{\"status\":0,\"index\":0,\"actionMessage\":null,\"userId\":\"hsAkhiqJp1o89VZ4iBtmLnEM2vkb5FJTt0vWEUIxOw\",\"username\":\"user\",\"active\":true,\"role\":\"USER\",\"emailAddress\":\"user@mail-example.local\",\"fullName\":null,\"smpTheme\":null,\"smpLocale\":null,\"casAuthenticated\":false,\"casUserDataUrl\":null,\"passwordExpireOn\":null,\"sequentialLoginFailureCount\":0,\"lastFailedLoginAttempt\":null,\"suspendedUtil\":null,\"passwordUpdatedOn\":null,\"authorities\":[\"ROLE_USER\"],\"statusPassword\":0,\"passwordExpired\":true,\"showPasswordExpirationWarning\":false,\"forceChangeExpiredPassword\":false}"; ObjectMapper mapper = new ObjectMapper(); UserRO userRO = mapper.readValue(value, UserRO.class); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/identifiers/DocumentIdentifierFormatterTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/identifiers/DocumentIdentifierFormatterTest.java index 011f9c6d11e0f7b9e8691ff34811318389e6cef8..3b35a005564939c244cc0e62c098956f610ed6fd 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/identifiers/DocumentIdentifierFormatterTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/identifiers/DocumentIdentifierFormatterTest.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -18,22 +18,20 @@ */ package eu.europa.ec.edelivery.smp.identifiers; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.util.Arrays; import java.util.Collection; +import static org.junit.jupiter.api.Assertions.*; + /** * @author Joze Rihtarsic * @since 5.0 */ -@RunWith(Parameterized.class) public class DocumentIdentifierFormatterTest { - @Parameterized.Parameters(name = "{index}: {0}") public static Collection documentIdentifierCases() { return Arrays.asList(new Object[][]{ {"Basic example", @@ -49,7 +47,7 @@ public class DocumentIdentifierFormatterTest { "a::b::c", false}, {"Char : in scheme colon basic", - new Identifier("c","a:b"), + new Identifier("c", "a:b"), "a:b::c", "a%3Ab%3A%3Ac", "a:b::c", @@ -84,52 +82,52 @@ public class DocumentIdentifierFormatterTest { "ehealth-actorid-qns%3A%3Aurn%20ncpb%20test", "ehealth-actorid-qns::urn ncpb test", false}, - {"Example 01 (parse spaces)",new Identifier("urn:ehealth:pt:ncpb-idp","scheme"), + {"Example 01 (parse spaces)", new Identifier("urn:ehealth:pt:ncpb-idp", "scheme"), "scheme::urn:ehealth:pt:ncpb-idp", "scheme%3A%3Aurn%3Aehealth%3Apt%3Ancpb-idp", " scheme::urn:ehealth:pt:ncpb-idp", false}, - {"Example 02 (parse spaces)",new Identifier("urn:ehealth:be:ncpb-idp","otherscheme"), + {"Example 02 (parse spaces)", new Identifier("urn:ehealth:be:ncpb-idp", "otherscheme"), "otherscheme::urn:ehealth:be:ncpb-idp", - "otherscheme%3A%3Aurn%3Aehealth%3Abe%3Ancpb-idp" , + "otherscheme%3A%3Aurn%3Aehealth%3Abe%3Ancpb-idp", "otherscheme::urn:ehealth:be:ncpb-idp ", false}, - {"Example 03 (parse spaces in argument)",new Identifier("urn:ehealth:IdentityService::XCPD::CrossGatewayPatientDiscovery##ITI-55","ehealth-resid-qns"), + {"Example 03 (parse spaces in argument)", new Identifier("urn:ehealth:IdentityService::XCPD::CrossGatewayPatientDiscovery##ITI-55", "ehealth-resid-qns"), "ehealth-resid-qns::urn:ehealth:IdentityService::XCPD::CrossGatewayPatientDiscovery##ITI-55", "ehealth-resid-qns%3A%3Aurn%3Aehealth%3AIdentityService%3A%3AXCPD%3A%3ACrossGatewayPatientDiscovery%23%23ITI-55", "ehealth-resid-qns:: urn:ehealth:IdentityService::XCPD::CrossGatewayPatientDiscovery##ITI-55 ", false}, - {"Example 04",new Identifier( "urn:XCPD::CrossGatewayPatientDiscovery", "ehealth-resid-qns"), + {"Example 04", new Identifier("urn:XCPD::CrossGatewayPatientDiscovery", "ehealth-resid-qns"), "ehealth-resid-qns::urn:XCPD::CrossGatewayPatientDiscovery", "ehealth-resid-qns%3A%3Aurn%3AXCPD%3A%3ACrossGatewayPatientDiscovery", "ehealth-resid-qns::urn:XCPD::CrossGatewayPatientDiscovery", false}, - {"Example 05",new Identifier("urn:ehealth:PatientService::XCA::CrossGatewayQuery##ITI-38","ehealth-resid-qns"), + {"Example 05", new Identifier("urn:ehealth:PatientService::XCA::CrossGatewayQuery##ITI-38", "ehealth-resid-qns"), "ehealth-resid-qns::urn:ehealth:PatientService::XCA::CrossGatewayQuery##ITI-38", "ehealth-resid-qns%3A%3Aurn%3Aehealth%3APatientService%3A%3AXCA%3A%3ACrossGatewayQuery%23%23ITI-38", "ehealth-resid-qns::urn:ehealth:PatientService::XCA::CrossGatewayQuery##ITI-38", false}, - {"Example 06",new Identifier("urn:XCA::CrossGatewayQuery", "ehealth-resid-qns"), + {"Example 06", new Identifier("urn:XCA::CrossGatewayQuery", "ehealth-resid-qns"), "ehealth-resid-qns::urn:XCA::CrossGatewayQuery", "ehealth-resid-qns%3A%3Aurn%3AXCA%3A%3ACrossGatewayQuery", "ehealth-resid-qns::urn:XCA::CrossGatewayQuery", false}, - {"Example 07",new Identifier("urn:ehealth:OrderService::XCA::CrossGatewayQuery##ITI-38","ehealth-resid-qns"), + {"Example 07", new Identifier("urn:ehealth:OrderService::XCA::CrossGatewayQuery##ITI-38", "ehealth-resid-qns"), "ehealth-resid-qns::urn:ehealth:OrderService::XCA::CrossGatewayQuery##ITI-38", "ehealth-resid-qns%3A%3Aurn%3Aehealth%3AOrderService%3A%3AXCA%3A%3ACrossGatewayQuery%23%23ITI-38", "ehealth-resid-qns::urn:ehealth:OrderService::XCA::CrossGatewayQuery##ITI-38", false}, - {"Example 08",new Identifier("urn:ehealth:DispensationService:Initialize::XDR::ProvideandRegisterDocumentSet-b##ITI-41","ehealth-resid-qns"), + {"Example 08", new Identifier("urn:ehealth:DispensationService:Initialize::XDR::ProvideandRegisterDocumentSet-b##ITI-41", "ehealth-resid-qns"), "ehealth-resid-qns::urn:ehealth:DispensationService:Initialize::XDR::ProvideandRegisterDocumentSet-b##ITI-41", "ehealth-resid-qns%3A%3Aurn%3Aehealth%3ADispensationService%3AInitialize%3A%3AXDR%3A%3AProvideandRegisterDocumentSet-b%23%23ITI-41", "ehealth-resid-qns::urn:ehealth:DispensationService:Initialize::XDR::ProvideandRegisterDocumentSet-b##ITI-41", false}, - {"Example 09",new Identifier("urn:XDR::ProvideandRegisterDocumentSet-b","ehealth-resid-qns"), + {"Example 09", new Identifier("urn:XDR::ProvideandRegisterDocumentSet-b", "ehealth-resid-qns"), "ehealth-resid-qns::urn:XDR::ProvideandRegisterDocumentSet-b", "ehealth-resid-qns%3A%3Aurn%3AXDR%3A%3AProvideandRegisterDocumentSet-b", "ehealth-resid-qns::urn:XDR::ProvideandRegisterDocumentSet-b", false}, - {"Example 10",new Identifier("urn:ehealth:DispensationService:Discard::XDR::ProvideandRegisterDocumentSet-b##ITI-41","ehealth-resid-qns"), + {"Example 10", new Identifier("urn:ehealth:DispensationService:Discard::XDR::ProvideandRegisterDocumentSet-b##ITI-41", "ehealth-resid-qns"), "ehealth-resid-qns::urn:ehealth:DispensationService:Discard::XDR::ProvideandRegisterDocumentSet-b##ITI-41", "ehealth-resid-qns%3A%3Aurn%3Aehealth%3ADispensationService%3ADiscard%3A%3AXDR%3A%3AProvideandRegisterDocumentSet-b%23%23ITI-41", "ehealth-resid-qns::urn:ehealth:DispensationService:Discard::XDR::ProvideandRegisterDocumentSet-b##ITI-41", @@ -138,46 +136,44 @@ public class DocumentIdentifierFormatterTest { }); } - // input parameters - @Parameterized.Parameter - public String name; - @Parameterized.Parameter(1) - public Identifier identifierType; - @Parameterized.Parameter(2) - public String formattedIdentifier; - @Parameterized.Parameter(3) - public String uriFormattedIdentifier; - @Parameterized.Parameter(4) - public String identifierToParse; - @Parameterized.Parameter(5) - public boolean throwParseError; - IdentifierFormatter testInstance = IdentifierFormatter.Builder.create().build(); - @Test - public void testFormat() { + @ParameterizedTest + @MethodSource("documentIdentifierCases") + void testFormat(String name, + Identifier identifierType, + String formattedIdentifier, + String uriFormattedIdentifier, + String identifierToParse, + boolean throwParseError) { String result = testInstance.format(identifierType); String uriResult = testInstance.urlEncodedFormat(identifierType); - Assert.assertEquals(formattedIdentifier, result); - Assert.assertEquals(uriFormattedIdentifier, uriResult); + assertEquals(formattedIdentifier, result); + assertEquals(uriFormattedIdentifier, uriResult); } - @Test - public void testParse() { + @ParameterizedTest + @MethodSource("documentIdentifierCases") + void testParse(String name, + Identifier identifierType, + String formattedIdentifier, + String uriFormattedIdentifier, + String identifierToParse, + boolean throwParseError) { IllegalArgumentException exception = null; Identifier result = null; if (throwParseError) { - exception = Assert.assertThrows(IllegalArgumentException.class, () -> testInstance.parse(identifierToParse)); + exception = assertThrows(IllegalArgumentException.class, () -> testInstance.parse(identifierToParse)); } else { result = testInstance.parse(identifierToParse); } - Assert.assertNotNull(throwParseError ? exception : result); + assertNotNull(throwParseError ? exception : result); if (!throwParseError) { - Assert.assertEquals(identifierType.getScheme(), result.getScheme()); - Assert.assertEquals(identifierType.getValue(), result.getValue()); + assertEquals(identifierType.getScheme(), result.getScheme()); + assertEquals(identifierType.getValue(), result.getValue()); } } } diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/identifiers/ParticipantIdentifierFormatterFormatTests.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/identifiers/ParticipantIdentifierFormatterFormatTests.java index 22d07d59d08ed4cbfcaf5fad9f7cd5740d3e394d..2f5ca30bd69cf87db505e979c8a49a0abd041442 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/identifiers/ParticipantIdentifierFormatterFormatTests.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/identifiers/ParticipantIdentifierFormatterFormatTests.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -20,10 +20,9 @@ package eu.europa.ec.edelivery.smp.identifiers; import eu.europa.ec.dynamicdiscovery.model.identifiers.types.EBCorePartyIdFormatterType; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.util.Arrays; import java.util.Collection; @@ -32,10 +31,8 @@ import java.util.Collection; * @author Joze Rihtarsic * @since 5.0 */ -@RunWith(Parameterized.class) public class ParticipantIdentifierFormatterFormatTests { - @Parameterized.Parameters(name = "{index}: {0}") public static Collection participantIdentifierCases() { return Arrays.asList(new Object[][]{ {"ebCore unregistered", @@ -69,24 +66,20 @@ public class ParticipantIdentifierFormatterFormatTests { } // input parameters - @Parameterized.Parameter - public String name; - @Parameterized.Parameter(1) - public Identifier participantIdentifierType; - @Parameterized.Parameter(2) - public String formattedIdentifier; - @Parameterized.Parameter(3) - public String uriFormattedIdentifier; IdentifierFormatter testInstance = IdentifierFormatter.Builder.create().addFormatterTypes(new EBCorePartyIdFormatterType()).build(); - @Test - public void testFormat() { + @ParameterizedTest + @MethodSource("participantIdentifierCases") + void testFormat(String name, + Identifier participantIdentifierType, + String formattedIdentifier, + String uriFormattedIdentifier) { String result = testInstance.format(participantIdentifierType); String uriResult = testInstance.urlEncodedFormat(participantIdentifierType); - Assert.assertEquals(formattedIdentifier, result); - Assert.assertEquals(uriFormattedIdentifier, uriResult); + Assertions.assertEquals(formattedIdentifier, result); + Assertions.assertEquals(uriFormattedIdentifier, uriResult); } } diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/identifiers/ParticipantIdentifierFormatterParseTests.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/identifiers/ParticipantIdentifierFormatterParseTests.java index fde7d5a99cd7c17d1012989dd60cb1f2c44d3d65..d6684eaf9e7f4efc2ac8a857215426e2275e8f34 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/identifiers/ParticipantIdentifierFormatterParseTests.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/identifiers/ParticipantIdentifierFormatterParseTests.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -20,23 +20,20 @@ package eu.europa.ec.edelivery.smp.identifiers; import eu.europa.ec.dynamicdiscovery.model.identifiers.types.EBCorePartyIdFormatterType; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.util.Arrays; import java.util.Collection; +import static org.junit.jupiter.api.Assertions.*; + /** * @author Joze Rihtarsic * @since 5.0 */ -@RunWith(Parameterized.class) public class ParticipantIdentifierFormatterParseTests { - - @Parameterized.Parameters(name = "{index}: {0}") public static Collection participantIdentifierPositiveCases() { return Arrays.asList(new Object[][]{ {"ebCore unregistered", false, "urn:oasis:names:tc:ebcore:partyid-type:unregistered:domain:ec.europa.eu", "urn:oasis:names:tc:ebcore:partyid-type:unregistered:domain", "ec.europa.eu"}, @@ -66,34 +63,28 @@ public class ParticipantIdentifierFormatterParseTests { }); } - // input parameters - @Parameterized.Parameter - public String name; - @Parameterized.Parameter(1) - public boolean throwError; - @Parameterized.Parameter(2) - public String identifier; - @Parameterized.Parameter(3) - public String schemaPart; - @Parameterized.Parameter(4) - public String idPart; IdentifierFormatter testInstance = IdentifierFormatter.Builder.create().addFormatterTypes(new EBCorePartyIdFormatterType()).build(); - @Test - public void testPartyIdentifierParse() { + @ParameterizedTest + @MethodSource("participantIdentifierPositiveCases") + void testPartyIdentifierParse(String name, + boolean throwError, + String identifier, + String schemaPart, + String idPart) { IllegalArgumentException exception = null; Identifier result = null; if (throwError) { - exception = Assert.assertThrows(IllegalArgumentException.class, () -> testInstance.parse(identifier)); + exception = assertThrows(IllegalArgumentException.class, () -> testInstance.parse(identifier)); } else { result = testInstance.parse(identifier); } - Assert.assertNotNull(throwError ? exception : result); + assertNotNull(throwError ? exception : result); if (!throwError) { - Assert.assertEquals(schemaPart, result.getScheme()); - Assert.assertEquals(idPart, result.getValue()); + assertEquals(schemaPart, result.getScheme()); + assertEquals(idPart, result.getValue()); } } diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/identifiers/types/EBCorePartyIdFormatterTypeTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/identifiers/types/EBCorePartyIdFormatterTypeTest.java index 6346436ae93c046688a89a7775971f551f4ece20..bf0f65d4726999c0d2f34d81afd8be9976dfacf6 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/identifiers/types/EBCorePartyIdFormatterTypeTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/identifiers/types/EBCorePartyIdFormatterTypeTest.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -22,25 +22,21 @@ import eu.europa.ec.dynamicdiscovery.exception.MalformedIdentifierException; import eu.europa.ec.dynamicdiscovery.model.identifiers.types.EBCorePartyIdFormatterType; import org.hamcrest.CoreMatchers; import org.hamcrest.MatcherAssert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.util.Arrays; import java.util.Collection; import static org.apache.commons.lang3.StringUtils.trimToEmpty; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; /** * @author Joze Rihtarsic * @since 5.0 */ -@RunWith(Parameterized.class) public class EBCorePartyIdFormatterTypeTest { - - @Parameterized.Parameters(name = "{index}: {0}") public static Collection participantIdentifierPositiveCases() { return Arrays.asList(new Object[][]{ { @@ -124,39 +120,43 @@ public class EBCorePartyIdFormatterTypeTest { EBCorePartyIdFormatterType testInstance = new EBCorePartyIdFormatterType(); - // input parameters - @Parameterized.Parameter - public String testName; - @Parameterized.Parameter(1) - public boolean isEBCorePartyId; - @Parameterized.Parameter(2) - public String toParseIdentifier; - @Parameterized.Parameter(3) - public String schemaPart; - @Parameterized.Parameter(4) - public String idPart; - @Parameterized.Parameter(5) - public Class errorClass; - @Parameterized.Parameter(6) - public String containsErrorMessage; - - - @Test - public void isSchemeValid() { + @ParameterizedTest + @MethodSource("participantIdentifierPositiveCases") + void isSchemeValid(String testName, + boolean isEBCorePartyId, + String toParseIdentifier, + String schemaPart, + String idPart, + Class errorClass, + String containsErrorMessage) { boolean result = testInstance.isSchemeValid(schemaPart); assertEquals(isEBCorePartyId, result); } - @Test - public void isType() { + @ParameterizedTest + @MethodSource("participantIdentifierPositiveCases") + void isType(String testName, + boolean isEBCorePartyId, + String toParseIdentifier, + String schemaPart, + String idPart, + Class errorClass, + String containsErrorMessage) { boolean result = testInstance.isType(toParseIdentifier); assertEquals(isEBCorePartyId, result); } - @Test - public void format() { + @ParameterizedTest + @MethodSource("participantIdentifierPositiveCases") + void format(String testName, + boolean isEBCorePartyId, + String toParseIdentifier, + String schemaPart, + String idPart, + Class errorClass, + String containsErrorMessage) { // skip format for not ebcore party ids if (!isEBCorePartyId) { return; @@ -168,8 +168,15 @@ public class EBCorePartyIdFormatterTypeTest { assertEquals(schema + ":" + trimToEmpty(idPart), result); } - @Test - public void parse() { + @ParameterizedTest + @MethodSource("participantIdentifierPositiveCases") + void parse(String testName, + boolean isEBCorePartyId, + String toParseIdentifier, + String schemaPart, + String idPart, + Class errorClass, + String containsErrorMessage) { // skip parse not ebcore party ids if (!isEBCorePartyId) { IllegalArgumentException result = assertThrows(IllegalArgumentException.class, () -> testInstance.parse(toParseIdentifier)); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/identifiers/types/OasisSMPFormatterTypeTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/identifiers/types/OasisSMPFormatterTypeTest.java index 255d65de9f43260ff5dc8d8054af090333795461..0b1646352c8b5600877bf95719504d2b3b2cca18 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/identifiers/types/OasisSMPFormatterTypeTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/identifiers/types/OasisSMPFormatterTypeTest.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -21,25 +21,23 @@ package eu.europa.ec.edelivery.smp.identifiers.types; import eu.europa.ec.dynamicdiscovery.model.identifiers.types.OasisSMPFormatterType; import org.hamcrest.CoreMatchers; import org.hamcrest.MatcherAssert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.util.Arrays; import java.util.Collection; import static org.apache.commons.lang3.StringUtils.*; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; /** * @author Joze Rihtarsic * @since 5.0 */ -@RunWith(Parameterized.class) + public class OasisSMPFormatterTypeTest { - @Parameterized.Parameters(name = "{index}: {0}") public static Collection<Object> participantIdentifierPositiveCases() { return Arrays.asList(new Object[][]{ { @@ -71,39 +69,43 @@ public class OasisSMPFormatterTypeTest { OasisSMPFormatterType testInstance = new OasisSMPFormatterType(); - // input parameters - @Parameterized.Parameter - public String testName; - @Parameterized.Parameter(1) - public boolean isValidPartyId; - @Parameterized.Parameter(2) - public String toParseIdentifier; - @Parameterized.Parameter(3) - public String schemaPart; - @Parameterized.Parameter(4) - public String idPart; - @Parameterized.Parameter(5) - public Class errorClass; - @Parameterized.Parameter(6) - public String containsErrorMessage; - - - @Test - public void isSchemeValid() { + @ParameterizedTest + @MethodSource("participantIdentifierPositiveCases") + void isSchemeValid(String testName, + boolean isValidPartyId, + String toParseIdentifier, + String schemaPart, + String idPart, + Class errorClass, + String containsErrorMessage) { boolean result = testInstance.isSchemeValid(schemaPart); assertEquals(isValidPartyId, result); } - @Test - public void isType() { + @ParameterizedTest + @MethodSource("participantIdentifierPositiveCases") + void isType(String testName, + boolean isValidPartyId, + String toParseIdentifier, + String schemaPart, + String idPart, + Class errorClass, + String containsErrorMessage) { boolean result = testInstance.isType(toParseIdentifier); assertEquals(isValidPartyId, result); } - @Test - public void format() { + @ParameterizedTest + @MethodSource("participantIdentifierPositiveCases") + void format(String testName, + boolean isValidPartyId, + String toParseIdentifier, + String schemaPart, + String idPart, + Class errorClass, + String containsErrorMessage) { // skip format for not ebcore party ids if (!isValidPartyId) { return; @@ -115,11 +117,18 @@ public class OasisSMPFormatterTypeTest { String schema = trimToEmpty(schemaPart); assertEquals(schema + "::" + trim(idPart), result); - assertEquals((isEmpty(schema)?"":schema + "::") + trim(idPart), resultNoDelimiterForNullSchema); + assertEquals((isEmpty(schema) ? "" : schema + "::") + trim(idPart), resultNoDelimiterForNullSchema); } - @Test - public void parse() { + @ParameterizedTest + @MethodSource("participantIdentifierPositiveCases") + void parse(String testName, + boolean isValidPartyId, + String toParseIdentifier, + String schemaPart, + String idPart, + Class errorClass, + String containsErrorMessage) { // skip parse not ebcore party ids if (!isValidPartyId) { IllegalArgumentException result = assertThrows(IllegalArgumentException.class, () -> testInstance.parse(toParseIdentifier)); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/identifiers/types/TemplateFormatterTypeTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/identifiers/types/TemplateFormatterTypeTest.java index b71fb1acb88efa512cb918a655b49977d39cc8e6..b8c61e2c6c9ded5a01cf6627c44a507493588d3e 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/identifiers/types/TemplateFormatterTypeTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/identifiers/types/TemplateFormatterTypeTest.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -21,26 +21,23 @@ package eu.europa.ec.edelivery.smp.identifiers.types; import eu.europa.ec.dynamicdiscovery.model.identifiers.types.TemplateFormatterType; import org.hamcrest.CoreMatchers; import org.hamcrest.MatcherAssert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.util.Arrays; import java.util.Collection; import java.util.regex.Pattern; import static org.apache.commons.lang3.StringUtils.trim; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; /** * @author Joze Rihtarsic * @since 5.0 */ -@RunWith(Parameterized.class) public class TemplateFormatterTypeTest { - @Parameterized.Parameters(name = "{index}: {0}") public static Collection participantIdentifierPositiveCases() { return Arrays.asList(new Object[][]{ { @@ -77,38 +74,43 @@ public class TemplateFormatterTypeTest { // input parameters - @Parameterized.Parameter - public String testName; - @Parameterized.Parameter(1) - public boolean isValidPartyId; - @Parameterized.Parameter(2) - public String toParseIdentifier; - @Parameterized.Parameter(3) - public String schemaPart; - @Parameterized.Parameter(4) - public String idPart; - @Parameterized.Parameter(5) - public Class errorClass; - @Parameterized.Parameter(6) - public String containsErrorMessage; - - - @Test - public void isSchemeValid() { + @ParameterizedTest + @MethodSource("participantIdentifierPositiveCases") + void isSchemeValid(String testName, + boolean isValidPartyId, + String toParseIdentifier, + String schemaPart, + String idPart, + Class errorClass, + String containsErrorMessage) { boolean result = testInstance.isSchemeValid(schemaPart); assertEquals(isValidPartyId, result); } - @Test - public void isType() { + @ParameterizedTest + @MethodSource("participantIdentifierPositiveCases") + void isType(String testName, + boolean isValidPartyId, + String toParseIdentifier, + String schemaPart, + String idPart, + Class errorClass, + String containsErrorMessage) { boolean result = testInstance.isType(toParseIdentifier); assertEquals(isValidPartyId, result); } - @Test - public void format() { + @ParameterizedTest + @MethodSource("participantIdentifierPositiveCases") + void format(String testName, + boolean isValidPartyId, + String toParseIdentifier, + String schemaPart, + String idPart, + Class errorClass, + String containsErrorMessage) { // skip format for not ebcore party ids if (!isValidPartyId) { return; @@ -118,8 +120,15 @@ public class TemplateFormatterTypeTest { assertEquals(trim(idPart) + "::" + trim(schemaPart), result); } - @Test - public void parse() { + @ParameterizedTest + @MethodSource("participantIdentifierPositiveCases") + void parse(String testName, + boolean isValidPartyId, + String toParseIdentifier, + String schemaPart, + String idPart, + Class errorClass, + String containsErrorMessage) { // skip parse not ebcore party ids if (!isValidPartyId) { IllegalArgumentException result = assertThrows(IllegalArgumentException.class, () -> testInstance.parse(toParseIdentifier)); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/AbstractServiceIntegrationTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/AbstractServiceIntegrationTest.java index f10bcf068eafd3a58c6720c6615892a66a8993e6..c52857a2802c5fb44c21083d3a257d5cc5a32ac5 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/AbstractServiceIntegrationTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/AbstractServiceIntegrationTest.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -39,13 +39,13 @@ import eu.europa.ec.edelivery.smp.testutil.DBAssertion; import eu.europa.ec.edelivery.smp.testutil.TestConstants; import eu.europa.ec.edelivery.smp.testutil.TestDBUtils; import org.apache.commons.io.FileUtils; -import org.junit.Before; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.crypto.bcrypt.BCrypt; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.jdbc.Sql; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import java.io.IOException; import java.nio.file.Path; @@ -60,7 +60,7 @@ import static eu.europa.ec.edelivery.smp.testutil.TestConstants.*; * @since 4.1 */ -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = {IdentifierService.class, SmlConnector.class, SmpXmlSignatureService.class, MailService.class, DomainService.class, ResourceDao.class, SubresourceDao.class, DomainDao.class, UserDao.class, DBAssertion.class, ConfigurationDao.class, AlertDao.class, CredentialDao.class, @@ -106,7 +106,7 @@ public abstract class AbstractServiceIntegrationTest extends AbstractBaseDao { DBAssertion dbAssertion; - @Before + @BeforeEach public void before() throws IOException { resetKeystore(); } diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/AlertServiceTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/AlertServiceTest.java index fce94e65088329e9deb01e6df51ea998d493138b..6f2bb54847b7fc77d9530f1f855ec757c78d678a 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/AlertServiceTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/AlertServiceTest.java @@ -35,7 +35,7 @@ import eu.europa.ec.edelivery.smp.services.mail.prop.CredentialVerificationFaile import eu.europa.ec.edelivery.smp.services.mail.prop.CredentialsExpirationProperties; import eu.europa.ec.edelivery.smp.testutil.TestDBUtils; import eu.europa.ec.edelivery.smp.utils.SmpUrlBuilder; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; @@ -44,10 +44,10 @@ import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; -public class AlertServiceTest { +class AlertServiceTest { AlertDao alertDao = Mockito.mock(AlertDao.class); MailService mailService = Mockito.mock(MailService.class); @@ -67,7 +67,7 @@ public class AlertServiceTest { alertCronTrigger); @Test - public void testCreateAlert() { + void testCreateAlert() { String mailSubject = "mailSubject"; String mailTo = "mailTo"; String username = "username"; @@ -89,7 +89,7 @@ public class AlertServiceTest { } @Test - public void testSubmitAlertMailNoMail() { + void testSubmitAlertMailNoMail() { DBAlert alert = new DBAlert(); DBUser user = Mockito.mock(DBUser.class); @@ -100,7 +100,7 @@ public class AlertServiceTest { } @Test - public void alertBeforeUsernamePasswordExpire() { + void alertBeforeUsernamePasswordExpire() { // given DBUser user = TestDBUtils.createDBUser("alertBeforeUsernamePasswordExpire"); DBCredential credential = TestDBUtils.createDBCredentialForUser(user, null, OffsetDateTime.now().plusDays(1), null); @@ -127,7 +127,7 @@ public class AlertServiceTest { } @Test - public void alertUsernamePasswordExpired() { + void alertUsernamePasswordExpired() { // given DBUser user = TestDBUtils.createDBUser("alertUsernamePasswordExpired"); String mailSubject = "mail subject"; @@ -154,7 +154,7 @@ public class AlertServiceTest { } @Test - public void alertBeforeAccessTokenExpire() { + void alertBeforeAccessTokenExpire() { // given DBUser user = TestDBUtils.createDBUser("alertBeforeAccessTokenExpire"); DBCredential credential = TestDBUtils.createDBCredentialForUserAccessToken(user, null, OffsetDateTime.now().plusDays(1), null); @@ -182,7 +182,7 @@ public class AlertServiceTest { @Test - public void alertAccessTokenExpired() { + void alertAccessTokenExpired() { // given DBUser user = TestDBUtils.createDBUser("alertAccessTokenExpired"); DBCredential credential = TestDBUtils.createDBCredentialForUserAccessToken(user, null, OffsetDateTime.now().plusDays(-1), null); @@ -207,7 +207,7 @@ public class AlertServiceTest { } @Test - public void alertBeforeCertificateExpire() { + void alertBeforeCertificateExpire() { // given DBUser user = TestDBUtils.createDBUser("user", "alertBeforeCertificateExpire"); DBCredential credential = TestDBUtils.createDBCredentialForUserCertificate(user, null, OffsetDateTime.now().plusDays(1), null); @@ -232,7 +232,7 @@ public class AlertServiceTest { } @Test - public void alertCertificateExpired() { + void alertCertificateExpired() { // given DBUser user = TestDBUtils.createDBUser("user", "alertCertificateExpired"); DBCredential credential = TestDBUtils.createDBCredentialForUserCertificate(user, null, OffsetDateTime.now().plusDays(1), null); @@ -258,7 +258,7 @@ public class AlertServiceTest { } @Test - public void submitAlertMail() { + void submitAlertMail() { String mailTo = "test.mail@domain.eu"; String mailFrom = "test.mail@domain.eu"; String mailSubject = "mailSubject"; @@ -291,7 +291,7 @@ public class AlertServiceTest { } @Test - public void alertUsernameCredentialVerificationFailed() { + void alertUsernameCredentialVerificationFailed() { DBUser user = TestDBUtils.createDBUser("user"); DBCredential credential = TestDBUtils.createDBCredentialForUser(user, null, OffsetDateTime.now().plusDays(1), null); credential.setSequentialLoginFailureCount(5); @@ -324,7 +324,7 @@ public class AlertServiceTest { } @Test - public void alertTokenCredentialVerificationFailed() { + void alertTokenCredentialVerificationFailed() { DBUser user = TestDBUtils.createDBUser("user", "alertCertificateExpired"); DBCredential credential = TestDBUtils.createDBCredentialForUserAccessToken(user, null, OffsetDateTime.now().plusDays(1), null); credential.setSequentialLoginFailureCount(5); @@ -356,7 +356,7 @@ public class AlertServiceTest { } @Test - public void alertUsernameCredentialsSuspended() { + void alertUsernameCredentialsSuspended() { DBUser user = TestDBUtils.createDBUser("user", "alertUsernameCredentialsSuspended"); DBCredential credential = TestDBUtils.createDBCredentialForUser(user, null, OffsetDateTime.now().plusDays(1), null); credential.setSequentialLoginFailureCount(5); @@ -388,7 +388,7 @@ public class AlertServiceTest { } @Test - public void alertTokenCredentialsSuspended() { + void alertTokenCredentialsSuspended() { DBUser user = TestDBUtils.createDBUser("user", "alertCertificateExpired"); DBCredential credential = TestDBUtils.createDBCredentialForUserAccessToken(user, null, OffsetDateTime.now().plusDays(1), null); credential.setSequentialLoginFailureCount(5); @@ -446,7 +446,7 @@ public class AlertServiceTest { // test to contain all properties for (String prop : templateProperties) { - assertTrue(prop, model.getModel().containsKey(prop)); + assertTrue(model.getModel().containsKey(prop), prop); } // add two common properties: CURRENT_DATETIME, SMP_INSTANCE_NAME assertEquals(templateProperties.size() + 2, model.getModel().size()); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/CRLVerifierServiceTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/CRLVerifierServiceTest.java index 27cd6a4fb8b39f9a65db7b117424edf8e4751394..de0cc1036d6e9775b7e4ce0790a4a444fed64527 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/CRLVerifierServiceTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/CRLVerifierServiceTest.java @@ -39,7 +39,7 @@ import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; -public class CRLVerifierServiceTest { +class CRLVerifierServiceTest { ConfigurationService mockConfigurationService = Mockito.mock(ConfigurationService.class); @@ -54,7 +54,7 @@ public class CRLVerifierServiceTest { @Test - public void verifyCertificateCRLsTest() throws CertificateException, CRLException, IOException { + void verifyCertificateCRLsTest() throws CertificateException, CRLException, IOException { // given X509Certificate certificate = loadCertificate("smp-crl-test-all.pem"); @@ -69,7 +69,7 @@ public class CRLVerifierServiceTest { } @Test - public void verifyCertificateCRLRevokedTest() throws CertificateException, CRLException { + void verifyCertificateCRLRevokedTest() throws CertificateException, CRLException { // given X509Certificate certificate = loadCertificate("smp-crl-revoked.pem"); @@ -84,7 +84,7 @@ public class CRLVerifierServiceTest { } @Test - public void verifyCertificateCRLsX509FailsToConnectTest() throws CertificateException { + void verifyCertificateCRLsX509FailsToConnectTest() throws CertificateException { // given X509Certificate certificate = loadCertificate("smp-crl-test-all.pem"); // when @@ -96,7 +96,7 @@ public class CRLVerifierServiceTest { } @Test - public void downloadCRLWrongUrlSchemeTest() { + void downloadCRLWrongUrlSchemeTest() { X509CRL crl = testInstance.downloadCRL("wrong://localhost/crl", true); @@ -104,7 +104,7 @@ public class CRLVerifierServiceTest { } @Test - public void downloadCRLUrlSchemeLdapTest() { + void downloadCRLUrlSchemeLdapTest() { X509CRL crl = testInstance.downloadCRL("ldap://localhost/crl", true); @@ -112,7 +112,7 @@ public class CRLVerifierServiceTest { } @Test - public void verifyCertificateCRLsRevokedSerialTest() throws CertificateException, CRLException { + void verifyCertificateCRLsRevokedSerialTest() throws CertificateException, CRLException { CertificateFactory cf = CertificateFactory.getInstance("X.509"); X509CRL crl = (X509CRL) cf.generateCRL(getClass().getResourceAsStream("/certificates/smp-crl-test.crl")); @@ -124,7 +124,7 @@ public class CRLVerifierServiceTest { } @Test - public void verifyCertificateCRLsRevokedSerialTestThrowIOExceptionHttps() { + void verifyCertificateCRLsRevokedSerialTestThrowIOExceptionHttps() { String crlURL = "https://localhost/crl"; doThrow(new SMPRuntimeException(ErrorCode.CERTIFICATE_ERROR, "Can not download CRL '" + crlURL + "'", "IOException: Can not access URL")) @@ -144,7 +144,7 @@ public class CRLVerifierServiceTest { "' |test', false", "test| |test, false", }) - public void testIsValidParameter(String values, boolean expectedResult) { + void testIsValidParameter(String values, boolean expectedResult) { //given String[] parameters = StringUtils.split(values, '|'); //when @@ -154,7 +154,7 @@ public class CRLVerifierServiceTest { } @Test - public void testDownloadURLViaProxy() throws IOException { + void testDownloadURLViaProxy() throws IOException { //given String url = "https://localhost/crl"; String proxy = "localhost"; diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ConfigurationServiceAllGetMethodsTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ConfigurationServiceAllGetMethodsTest.java index b17d9df71b17261a0a5ccbaf4fe481f979468744..728ccc4bce9cf727a41ac7e1460a409765697daa 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ConfigurationServiceAllGetMethodsTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ConfigurationServiceAllGetMethodsTest.java @@ -23,9 +23,9 @@ import eu.europa.ec.edelivery.smp.data.dao.ConfigurationDao; import eu.europa.ec.edelivery.smp.data.ui.enums.AlertLevelEnum; import org.apache.commons.lang3.exception.ExceptionUtils; import org.apache.commons.lang3.reflect.MethodUtils; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.io.File; import java.lang.reflect.InvocationTargetException; @@ -34,12 +34,10 @@ import java.util.*; import java.util.regex.Pattern; import static eu.europa.ec.edelivery.smp.config.enums.SMPPropertyEnum.*; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; -@RunWith(Parameterized.class) public class ConfigurationServiceAllGetMethodsTest { private static final String TEST_STRING = "TestString"; private static final List<String> TEST_STRING_LIST = Arrays.asList("TestString1", "TestString2", "TestString3"); @@ -59,7 +57,6 @@ public class ConfigurationServiceAllGetMethodsTest { ConfigurationDao configurationDaoMock = mock(ConfigurationDao.class); ConfigurationService testInstance = new ConfigurationService(configurationDaoMock); - @Parameterized.Parameters(name = "{index}: {0}") public static Collection<Object[]> data() { // set property values for property, set value, method name, value or property, value (true) or property (false) return Arrays.asList(new Object[][]{ @@ -176,20 +173,10 @@ public class ConfigurationServiceAllGetMethodsTest { }); } - private final SMPPropertyEnum property; - private final Object value; - private final String methodName; - private final boolean fromValue; - public ConfigurationServiceAllGetMethodsTest(SMPPropertyEnum property, Object value, String methodName, boolean fromValue) { - this.property = property; - this.value = value; - this.methodName = methodName; - this.fromValue = fromValue; - } - - @Test - public void testProperty() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { + @ParameterizedTest + @MethodSource("data") + void testProperty(SMPPropertyEnum property, Object value, String methodName, boolean fromValue) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { if (fromValue) { doReturn(value instanceof AlertLevelEnum ? value.toString() : value).when(configurationDaoMock).getCachedPropertyValue(property); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ConfigurationServiceTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ConfigurationServiceTest.java index c290a70a15ff07662a192ad4ee32ba719be19dc6..94a421077b7f053a93a8cdea54a5588edf99dc0a 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ConfigurationServiceTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ConfigurationServiceTest.java @@ -19,25 +19,25 @@ package eu.europa.ec.edelivery.smp.services; import eu.europa.ec.edelivery.smp.data.dao.ConfigurationDao; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.net.MalformedURLException; import java.net.URL; import static eu.europa.ec.edelivery.smp.config.enums.SMPPropertyEnum.SSO_CAS_SMP_USER_DATA_URL_PATH; import static eu.europa.ec.edelivery.smp.config.enums.SMPPropertyEnum.SSO_CAS_URL; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.*; + import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; -public class ConfigurationServiceTest { +class ConfigurationServiceTest { ConfigurationDao configurationDaoMock = mock(ConfigurationDao.class); ConfigurationService testInstance = new ConfigurationService(configurationDaoMock); @Test - public void testGetCasUserDataURL() throws MalformedURLException { + void testGetCasUserDataURL() throws MalformedURLException { String casUrl = "http://test:123/path"; String casUserDataPath = "userdata/data.hsp"; doReturn(new URL(casUrl)).when(configurationDaoMock).getCachedPropertyValue(SSO_CAS_URL); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/CredentialServiceTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/CredentialServiceTest.java index 916950578cf7618f8dd13de46ec971d3b322ade4..620af6a07b718020ca24ab06761c377183953dc4 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/CredentialServiceTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/CredentialServiceTest.java @@ -49,7 +49,7 @@ import static eu.europa.ec.edelivery.smp.services.ui.UITruststoreServiceIntegrat import static org.junit.jupiter.api.Assertions.*; -public class CredentialServiceTest extends AbstractJunit5BaseDao { +class CredentialServiceTest extends AbstractJunit5BaseDao { @Autowired CredentialService testInstance; @@ -72,7 +72,7 @@ public class CredentialServiceTest extends AbstractJunit5BaseDao { } @Test - public void authenticateByUsernamePasswordTestBadUsername() { + void authenticateByUsernamePasswordTestBadUsername() { // given String username = "usernameNotExists"; String password = "password"; @@ -82,7 +82,7 @@ public class CredentialServiceTest extends AbstractJunit5BaseDao { } @Test - public void authenticateByUsernamePasswordTestOk() { + void authenticateByUsernamePasswordTestOk() { // given String username = TestConstants.USERNAME_1; String password = TestConstants.USERNAME_1_PASSWORD; @@ -96,7 +96,7 @@ public class CredentialServiceTest extends AbstractJunit5BaseDao { } @Test - public void authenticateByUsernamePasswordTestBadPassword() { + void authenticateByUsernamePasswordTestBadPassword() { // given String username = TestConstants.USERNAME_1; String password = "password"; @@ -106,7 +106,7 @@ public class CredentialServiceTest extends AbstractJunit5BaseDao { } @Test - public void authenticateByUsernamePasswordInactive() { + void authenticateByUsernamePasswordInactive() { testUtilsDao.deactivateUser(TestConstants.USERNAME_1); // given @@ -118,7 +118,7 @@ public class CredentialServiceTest extends AbstractJunit5BaseDao { } @Test - public void authenticateByUsernameCredentialsInactive() { + void authenticateByUsernameCredentialsInactive() { DBCredential credential = testUtilsDao.getUser1().getUserCredentials().get(0); credential.setActive(false); testUtilsDao.merge(credential); @@ -132,7 +132,7 @@ public class CredentialServiceTest extends AbstractJunit5BaseDao { } @Test - public void authenticateByUsernameCredentialsSuspended() { + void authenticateByUsernameCredentialsSuspended() { DBCredential credential = testUtilsDao.getUser1().getUserCredentials().get(0); credential.setLastFailedLoginAttempt(OffsetDateTime.now()); credential.setSequentialLoginFailureCount(100); @@ -147,7 +147,7 @@ public class CredentialServiceTest extends AbstractJunit5BaseDao { } @Test - public void authenticateByUsernameCredentialsNotSuspendedAnymore() { + void authenticateByUsernameCredentialsNotSuspendedAnymore() { DBCredential credential = testUtilsDao.getUser1().getUserCredentials().get(0); credential.setLastFailedLoginAttempt(OffsetDateTime.now().minusDays(100)); credential.setSequentialLoginFailureCount(100); @@ -165,7 +165,7 @@ public class CredentialServiceTest extends AbstractJunit5BaseDao { @Test - public void authenticateByAccessTokenBadUsername() { + void authenticateByAccessTokenBadUsername() { // given String accessTokenName = "usernameNotExists"; String accessTokenValue = "password"; @@ -175,7 +175,7 @@ public class CredentialServiceTest extends AbstractJunit5BaseDao { } @Test - public void authenticateByAccessTokenTestOk() { + void authenticateByAccessTokenTestOk() { // given String accessTokenName = TestConstants.USERNAME_3_AT; String accessTokenValue = TestConstants.USERNAME_3_AT_PASSWORD; @@ -189,7 +189,7 @@ public class CredentialServiceTest extends AbstractJunit5BaseDao { } @Test - public void authenticateByAccessTokenBadPassword() { + void authenticateByAccessTokenBadPassword() { // given String accessTokenName = TestConstants.USERNAME_3_AT; String accessTokenValue = "badPassword"; @@ -200,7 +200,7 @@ public class CredentialServiceTest extends AbstractJunit5BaseDao { } @Test - public void authenticateByAccessTokenInactive() { + void authenticateByAccessTokenInactive() { testUtilsDao.deactivateUser(TestConstants.USERNAME_3); String accessTokenName = TestConstants.USERNAME_3_AT; @@ -213,7 +213,7 @@ public class CredentialServiceTest extends AbstractJunit5BaseDao { } @Test - public void authenticateByAccessTokenCredentialsInactive() { + void authenticateByAccessTokenCredentialsInactive() { DBCredential credential = testUtilsDao.getUser3().getUserCredentials().get(0); credential.setActive(false); testUtilsDao.merge(credential); @@ -229,7 +229,7 @@ public class CredentialServiceTest extends AbstractJunit5BaseDao { } @Test - public void authenticateByAccessTokenSuspended() { + void authenticateByAccessTokenSuspended() { DBCredential credential = testUtilsDao.getUser3().getUserCredentials().get(0); credential.setLastFailedLoginAttempt(OffsetDateTime.now()); credential.setSequentialLoginFailureCount(100); @@ -245,7 +245,7 @@ public class CredentialServiceTest extends AbstractJunit5BaseDao { } @Test - public void authenticateByAccessTokenCredentialsNotSuspendedAnymore() { + void authenticateByAccessTokenCredentialsNotSuspendedAnymore() { DBCredential credential = testUtilsDao.getUser3().getUserCredentials().get(0); credential.setLastFailedLoginAttempt(OffsetDateTime.now().minusDays(100)); credential.setSequentialLoginFailureCount(100); @@ -262,7 +262,7 @@ public class CredentialServiceTest extends AbstractJunit5BaseDao { @Test - public void authenticateByCertificateTokenOkWithRole() throws Exception { + void authenticateByCertificateTokenOkWithRole() throws Exception { // given // must match the TestConstants.USER_CERT_3 @@ -281,7 +281,7 @@ public class CredentialServiceTest extends AbstractJunit5BaseDao { } @Test - public void authenticateByCertificateTokenNotTrusted() throws Exception { + void authenticateByCertificateTokenNotTrusted() throws Exception { // given X509Certificate cert = X509CertificateTestUtils.createX509CertificateForTest("CN=NotRegistered,O=European Commission,C=BE", new BigInteger("111111", 16), Collections.emptyList()); @@ -296,7 +296,7 @@ public class CredentialServiceTest extends AbstractJunit5BaseDao { @Test - public void testValidateCertificatePolicyLegacyMatchOk() { + void testValidateCertificatePolicyLegacyMatchOk() { String certID = "CN=SMP Test,OU=eDelivery,O=DIGITAL,C=BE:000111"; Mockito.doReturn(Arrays.asList(CERTIFICATE_POLICY_QCP_LEGAL, CERTIFICATE_POLICY_QCP_NATURAL)) .when(spyConfigurationService).getAllowedCertificatePolicies(); @@ -305,7 +305,7 @@ public class CredentialServiceTest extends AbstractJunit5BaseDao { } @Test - public void testValidateCertificatePolicyLegacyMatchMatchEmpty() { + void testValidateCertificatePolicyLegacyMatchMatchEmpty() { String certID = "CN=SMP Test,OU=eDelivery,O=DIGITAL,C=BE:000111"; Mockito.doReturn(Arrays.asList(CERTIFICATE_POLICY_QCP_LEGAL, CERTIFICATE_POLICY_QCP_NATURAL)) .when(spyConfigurationService).getAllowedCertificatePolicies(); @@ -317,7 +317,7 @@ public class CredentialServiceTest extends AbstractJunit5BaseDao { } @Test - public void testValidateCertificatePolicyLegacyMatchMismatch() { + void testValidateCertificatePolicyLegacyMatchMismatch() { String certID = "CN=SMP Test,OU=eDelivery,O=DIGITAL,C=BE:000111"; Mockito.doReturn(Arrays.asList(CERTIFICATE_POLICY_QCP_LEGAL, CERTIFICATE_POLICY_QCP_NATURAL)) .when(spyConfigurationService).getAllowedCertificatePolicies(); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/CredentialValidatorServiceTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/CredentialValidatorServiceTest.java index 48f8fbc7075c9a0d5f88596c3c67740aaa139914..13ef4af363bfc3c31289b5fe697f324901f179b6 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/CredentialValidatorServiceTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/CredentialValidatorServiceTest.java @@ -21,18 +21,18 @@ package eu.europa.ec.edelivery.smp.services; import eu.europa.ec.edelivery.smp.data.dao.CredentialDao; import eu.europa.ec.edelivery.smp.data.model.user.DBCredential; import eu.europa.ec.edelivery.smp.utils.HttpUtils; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; import java.util.Collections; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.verify; -public class CredentialValidatorServiceTest { +class CredentialValidatorServiceTest { ConfigurationService mockConfigService = Mockito.mock(ConfigurationService.class); CredentialsAlertService mockAlertService = Mockito.mock(CredentialsAlertService.class); @@ -41,14 +41,14 @@ public class CredentialValidatorServiceTest { CredentialValidatorService testInstance = new CredentialValidatorService(mockConfigService, mockAlertService, mockCredentialDao); @Test - public void testSkipCredentialValidationFalseNotCluster() { + void testSkipCredentialValidationFalseNotCluster() { doReturn(false).when(mockConfigService).isClusterEnabled(); boolean result = testInstance.skipCredentialValidation(); assertFalse(result); } @Test - public void testSkipCredentialValidationFalseClusterNotTargetServer() { + void testSkipCredentialValidationFalseClusterNotTargetServer() { doReturn(true).when(mockConfigService).isClusterEnabled(); doReturn("NotTargetServer").when(mockConfigService).getTargetServerForCredentialValidation(); boolean result = testInstance.skipCredentialValidation(); @@ -58,7 +58,7 @@ public class CredentialValidatorServiceTest { } @Test - public void testSkipCredentialValidationClusterNotTargetServer() { + void testSkipCredentialValidationClusterNotTargetServer() { String currentHostName = HttpUtils.getServerAddress(); doReturn(true).when(mockConfigService).isClusterEnabled(); doReturn(currentHostName).when(mockConfigService).getTargetServerForCredentialValidation(); @@ -69,7 +69,7 @@ public class CredentialValidatorServiceTest { } @Test - public void validateCredentialsForBeforeExpireUsernames() { + void validateCredentialsForBeforeExpireUsernames() { DBCredential userCredentials = Mockito.mock(DBCredential.class); Integer iPeriod = 10; Integer iInterval = 15; @@ -102,7 +102,7 @@ public class CredentialValidatorServiceTest { } @Test - public void validateCredentialsForExpiredUsernames() { + void validateCredentialsForExpiredUsernames() { DBCredential userCredentials = Mockito.mock(DBCredential.class); Integer iPeriod = 10; Integer iInterval = 15; @@ -135,7 +135,7 @@ public class CredentialValidatorServiceTest { } @Test - public void validateCredentialsForBeforeExpireAccessToken() { + void validateCredentialsForBeforeExpireAccessToken() { DBCredential userCredentials = Mockito.mock(DBCredential.class); Integer iPeriod = 10; Integer iInterval = 15; @@ -168,7 +168,7 @@ public class CredentialValidatorServiceTest { } @Test - public void validateCredentialsForExpiredAccessToken() { + void validateCredentialsForExpiredAccessToken() { DBCredential userCredentials = Mockito.mock(DBCredential.class); Integer iPeriod = 10; Integer iInterval = 15; @@ -201,7 +201,7 @@ public class CredentialValidatorServiceTest { } @Test - public void validateCredentialsForBeforeExpireCertificate() { + void validateCredentialsForBeforeExpireCertificate() { DBCredential userCredentials = Mockito.mock(DBCredential.class); Integer iPeriod = 10; Integer iInterval = 15; @@ -234,7 +234,7 @@ public class CredentialValidatorServiceTest { } @Test - public void validateCredentialsForExpiredCertificate() { + void validateCredentialsForExpiredCertificate() { DBCredential userCredentials = Mockito.mock(DBCredential.class); Integer iPeriod = 10; Integer iInterval = 15; diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/DomainServiceTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/DomainServiceTest.java index 80989dbefc02ce9d7460cbb181fc243f766c14c0..dd9fc1aafb586281f3513bc2b2a057eeb760f5c9 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/DomainServiceTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/DomainServiceTest.java @@ -48,7 +48,7 @@ import java.util.regex.Pattern; import static eu.europa.ec.edelivery.smp.testutil.TestConstants.TEST_DOMAIN_CODE_1; import static eu.europa.ec.edelivery.smp.testutil.TestConstants.TEST_DOMAIN_CODE_2; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; /** @@ -58,7 +58,7 @@ import static org.mockito.ArgumentMatchers.any; * @since 4.1 */ -public class DomainServiceTest extends AbstractJunit5BaseDao { +class DomainServiceTest extends AbstractJunit5BaseDao { @Autowired private IdentifierService identifierService; @@ -96,7 +96,7 @@ public class DomainServiceTest extends AbstractJunit5BaseDao { @ParameterizedTest @NullSource @ValueSource(strings = {"", " "}) - public void getDomainForBlankCodeForSingleDomain(String searchCode) { + void getDomainForBlankCodeForSingleDomain(String searchCode) { // given DBDomain testDomain01 = testUtilsDao.createDomain(TEST_DOMAIN_CODE_1); assertEquals(1, domainDao.getAllDomains().size()); @@ -107,7 +107,7 @@ public class DomainServiceTest extends AbstractJunit5BaseDao { } @Test - public void getDomainForBlankCodeForMultipleDomain() { + void getDomainForBlankCodeForMultipleDomain() { // given DBDomain testDomain01 = testUtilsDao.createDomain(TEST_DOMAIN_CODE_1); DBDomain testDomain02 = TestDBUtils.createDBDomain(TEST_DOMAIN_CODE_2); @@ -123,7 +123,7 @@ public class DomainServiceTest extends AbstractJunit5BaseDao { } @Test - public void getDomainForBlankCodeForMultipleDomainNotExists() { + void getDomainForBlankCodeForMultipleDomainNotExists() { // given DBDomain testDomain01 = testUtilsDao.createDomain(TEST_DOMAIN_CODE_1); DBDomain testDomain02 = TestDBUtils.createDBDomain(TEST_DOMAIN_CODE_2); @@ -139,7 +139,7 @@ public class DomainServiceTest extends AbstractJunit5BaseDao { } @Test - public void getDomainForInvalidCode() { + void getDomainForInvalidCode() { // given DBDomain testDomain01 = testUtilsDao.createDomain(TEST_DOMAIN_CODE_1); DBDomain testDomain02 = TestDBUtils.createDBDomain(TEST_DOMAIN_CODE_2); @@ -157,7 +157,7 @@ public class DomainServiceTest extends AbstractJunit5BaseDao { } @Test - public void testRegisterDomainAndParticipantsOK() { + void testRegisterDomainAndParticipantsOK() { // given testUtilsDao.clearData(); testUtilsDao.createResources(); @@ -178,7 +178,7 @@ public class DomainServiceTest extends AbstractJunit5BaseDao { } @Test - public void testUnRegisterDomainAndParticipantsOK() { + void testUnRegisterDomainAndParticipantsOK() { // given testUtilsDao.clearData(); testUtilsDao.createResources(); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/PayloadValidatorServiceTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/PayloadValidatorServiceTest.java index 2bc8e180d128340a41bbe06e59a34158b58acc17..05b508266e9d34e843e0d28fc16187d33185f42c 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/PayloadValidatorServiceTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/PayloadValidatorServiceTest.java @@ -22,7 +22,7 @@ import eu.europa.ec.edelivery.smp.exceptions.ErrorCode; import eu.europa.ec.edelivery.smp.exceptions.SMPRuntimeException; import eu.europa.ec.smp.spi.PayloadValidatorSpi; import eu.europa.ec.smp.spi.exceptions.PayloadValidatorSpiException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; import org.springframework.util.MimeTypeUtils; @@ -32,13 +32,12 @@ import java.util.Arrays; import java.util.Collections; import java.util.Optional; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.*; -public class PayloadValidatorServiceTest { +class PayloadValidatorServiceTest { @Test - public void validateUploadedContentNoValidatorsMostNotFail() { + void validateUploadedContentNoValidatorsMostNotFail() { PayloadValidatorService testInstance = new PayloadValidatorService(Optional.empty()); InputStream inputStream = Mockito.mock(InputStream.class); @@ -47,7 +46,7 @@ public class PayloadValidatorServiceTest { } @Test - public void validateUploadedContentNoValidatorsMostNotFailEmpty() { + void validateUploadedContentNoValidatorsMostNotFailEmpty() { PayloadValidatorService testInstance = new PayloadValidatorService(Optional.of(Collections.emptyList())); InputStream inputStream = Mockito.mock(InputStream.class); @@ -56,7 +55,7 @@ public class PayloadValidatorServiceTest { } @Test - public void validateUploadedContent() throws PayloadValidatorSpiException { + void validateUploadedContent() throws PayloadValidatorSpiException { PayloadValidatorSpi validatorSpi1 = Mockito.mock(PayloadValidatorSpi.class); PayloadValidatorSpi validatorSpi2 = Mockito.mock(PayloadValidatorSpi.class); PayloadValidatorService testInstance = new PayloadValidatorService(Optional.of(Arrays.asList(validatorSpi1, validatorSpi2))); @@ -80,7 +79,7 @@ public class PayloadValidatorServiceTest { } @Test - public void validateUploadedContentThrowException() throws PayloadValidatorSpiException { + void validateUploadedContentThrowException() throws PayloadValidatorSpiException { PayloadValidatorSpi validatorSpi1 = Mockito.mock(PayloadValidatorSpi.class); PayloadValidatorService testInstance = new PayloadValidatorService(Optional.of(Collections.singletonList(validatorSpi1))); InputStream inputStream = Mockito.mock(InputStream.class); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/SMLIntegrationServiceTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/SMLIntegrationServiceTest.java index d94d518a6b23ff456556142a91b849959a6ee5e3..7d0aabff69cebdbea5f652d6dd0005700609b26b 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/SMLIntegrationServiceTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/SMLIntegrationServiceTest.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -28,9 +28,8 @@ import eu.europa.ec.edelivery.smp.identifiers.Identifier; import eu.europa.ec.edelivery.smp.sml.SmlConnector; import org.busdox.servicemetadata.locator._1.ServiceMetadataPublisherServiceForParticipantType; import org.busdox.servicemetadata.locator._1.ServiceMetadataPublisherServiceType; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; @@ -40,8 +39,7 @@ import org.springframework.transaction.annotation.Transactional; import java.util.regex.Pattern; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -52,7 +50,7 @@ import static org.mockito.Mockito.verify; * @author Joze Rihtarsic * @since 4.1 */ -public class SMLIntegrationServiceTest extends AbstractServiceIntegrationTest { +class SMLIntegrationServiceTest extends AbstractServiceIntegrationTest { @Autowired IdentifierService identifierService; @@ -67,7 +65,7 @@ public class SMLIntegrationServiceTest extends AbstractServiceIntegrationTest { @SpyBean ConfigurationService configurationService; - @Before + @BeforeEach @Transactional public void prepareDatabase() { identifierService.configureParticipantIdentifierFormatter(null, false, Pattern.compile(".*")); @@ -85,7 +83,7 @@ public class SMLIntegrationServiceTest extends AbstractServiceIntegrationTest { } @Test - public void registerDomainToSml() throws UnauthorizedFault, InternalErrorFault, BadRequestFault { + void registerDomainToSml() throws UnauthorizedFault, InternalErrorFault, BadRequestFault { // given DBDomain testDomain01 = testUtilsDao.getD1(); testDomain01.setSmlRegistered(false); @@ -100,7 +98,7 @@ public class SMLIntegrationServiceTest extends AbstractServiceIntegrationTest { } @Test - public void unregisterDomainToSml() throws UnauthorizedFault, InternalErrorFault, BadRequestFault, NotFoundFault { + void unregisterDomainToSml() throws UnauthorizedFault, InternalErrorFault, BadRequestFault, NotFoundFault { // given DBDomain testDomain01 = testUtilsDao.getD1(); testDomain01.setSmlRegistered(true); @@ -115,7 +113,7 @@ public class SMLIntegrationServiceTest extends AbstractServiceIntegrationTest { } @Test - public void registerParticipant() throws Exception { + void registerParticipant() throws Exception { DBDomain testDomain01 = testUtilsDao.getD1(); testDomain01.setSmlRegistered(true); DBResource resource = testUtilsDao.getResourceD1G1RD1(); @@ -130,7 +128,7 @@ public class SMLIntegrationServiceTest extends AbstractServiceIntegrationTest { } @Test - public void participantExists() { + void participantExists() { // given DBDomain domain = testUtilsDao.getD1(); DBResource resource = testUtilsDao.getResourceD1G1RD1(); @@ -143,11 +141,11 @@ public class SMLIntegrationServiceTest extends AbstractServiceIntegrationTest { boolean participantExists = testInstance.participantExists(resource, domain); // then - Assert.assertTrue(participantExists); + assertTrue(participantExists); } @Test - public void registerOnlyDomainToSml_smlIntegrationDisabled() { + void registerOnlyDomainToSml_smlIntegrationDisabled() { // given DBDomain testDomain01 = testUtilsDao.getD1(); testDomain01.setSmlRegistered(false); @@ -155,12 +153,12 @@ public class SMLIntegrationServiceTest extends AbstractServiceIntegrationTest { givenSmlIntegrationEnabled(false); // when - SMPRuntimeException result = Assert.assertThrows(SMPRuntimeException.class, () -> testInstance.registerDomain(testDomain01)); - Assert.assertEquals("Configuration error: [SML integration is not enabled!]!", result.getMessage()); + SMPRuntimeException result = assertThrows(SMPRuntimeException.class, () -> testInstance.registerDomain(testDomain01)); + assertEquals("Configuration error: [SML integration is not enabled!]!", result.getMessage()); } @Test - public void unregisterOnlyDomainToSml_smlIntegrationDisabled() { + void unregisterOnlyDomainToSml_smlIntegrationDisabled() { // given DBDomain testDomain01 = testUtilsDao.getD1(); testDomain01.setSmlRegistered(true); @@ -168,12 +166,12 @@ public class SMLIntegrationServiceTest extends AbstractServiceIntegrationTest { givenSmlIntegrationEnabled(false); // when - SMPRuntimeException result = Assert.assertThrows(SMPRuntimeException.class, () -> testInstance.unRegisterDomain(testDomain01)); - Assert.assertEquals("Configuration error: [SML integration is not enabled!]!", result.getMessage()); + SMPRuntimeException result = assertThrows(SMPRuntimeException.class, () -> testInstance.unRegisterDomain(testDomain01)); + assertEquals("Configuration error: [SML integration is not enabled!]!", result.getMessage()); } @Test - public void registerParticipant_smlIntegrationDisabled() { + void registerParticipant_smlIntegrationDisabled() { DBDomain testDomain01 = testUtilsDao.getD1(); DBResource resource = testUtilsDao.getResourceD1G1RD1(); @@ -184,7 +182,7 @@ public class SMLIntegrationServiceTest extends AbstractServiceIntegrationTest { } @Test - public void unregisterParticipant_smlIntegrationDisabled() { + void unregisterParticipant_smlIntegrationDisabled() { DBDomain testDomain01 = testUtilsDao.getD1(); DBResource resource = testUtilsDao.getResourceD1G1RD1(); @@ -195,24 +193,24 @@ public class SMLIntegrationServiceTest extends AbstractServiceIntegrationTest { } @Test - public void participantExists_smlIntegrationDisabled() { + void participantExists_smlIntegrationDisabled() { DBDomain domain = testUtilsDao.getD1(); DBResource resource = testUtilsDao.getResourceD1G1RD1(); givenSmlIntegrationEnabled(false); - SMPRuntimeException result = Assert.assertThrows(SMPRuntimeException.class, () -> testInstance.participantExists(resource, domain)); - Assert.assertEquals("Configuration error: [SML integration is not enabled!]!", result.getMessage()); + SMPRuntimeException result = assertThrows(SMPRuntimeException.class, () -> testInstance.participantExists(resource, domain)); + assertEquals("Configuration error: [SML integration is not enabled!]!", result.getMessage()); } @Test - public void isDomainValid_smlIntegrationDisabled() { + void isDomainValid_smlIntegrationDisabled() { DBDomain domain = testUtilsDao.getD1(); givenSmlIntegrationEnabled(false); - SMPRuntimeException result = Assert.assertThrows(SMPRuntimeException.class, () -> testInstance.isDomainValid(domain)); - Assert.assertEquals("Configuration error: [SML integration is not enabled!]!", result.getMessage()); + SMPRuntimeException result = assertThrows(SMPRuntimeException.class, () -> testInstance.isDomainValid(domain)); + assertEquals("Configuration error: [SML integration is not enabled!]!", result.getMessage()); } private void givenSmlIntegrationEnabled(boolean enabled) { diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ServiceMetadataSignerTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ServiceMetadataSignerTest.java index c6221409ce06cb108b3b7b99e5ef30eaaa32f613..1cbd4a4f861cfefea0600676d618b2fe888f49d4 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ServiceMetadataSignerTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ServiceMetadataSignerTest.java @@ -48,7 +48,7 @@ import java.nio.file.Paths; */ @ContextConfiguration(classes = { SmpXmlSignatureService.class}) -public class ServiceMetadataSignerTest extends AbstractJunit5BaseDao{ +class ServiceMetadataSignerTest extends AbstractJunit5BaseDao{ Path resourceDirectory = Paths.get("src", "test", "resources", "keystores"); @@ -97,13 +97,13 @@ public class ServiceMetadataSignerTest extends AbstractJunit5BaseDao{ "smp_ecdsa_nist-b409", "smp_eddsa_25519", "smp_eddsa_448"}) - public void testSignatureAndDefaultAlgorithmeDefinitionOk(String alias) throws Exception { + void testSignatureAndDefaultAlgorithmeDefinitionOk(String alias) throws Exception { Document document = loadAndSignDocumentForDefault(alias); validateSignatureForDefault(document); } @Test - public void testAdminSignatureOk() throws Exception { + void testAdminSignatureOk() throws Exception { Element adminSignature = loadAndSignDocumentForAdmin("/expected_output/PUT_ServiceMetadata_request.xml"); SignatureUtil.validateSignature(adminSignature); } diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/mail/MailServiceTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/mail/MailServiceTest.java index 8257db2b815d7b425cfb133d33a3e4f3b92e91ca..699f305cf5c5a5f11b2f672a62d79550a7230b8e 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/mail/MailServiceTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/mail/MailServiceTest.java @@ -23,7 +23,7 @@ import eu.europa.ec.edelivery.smp.data.ui.enums.AlertTypeEnum; import eu.europa.ec.edelivery.smp.services.AbstractServiceIntegrationTest; import eu.europa.ec.edelivery.smp.services.mail.prop.TestMailProperties; import eu.europa.ec.edelivery.smp.testutil.MockAlertBeans; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.mail.javamail.JavaMailSenderImpl; @@ -34,7 +34,7 @@ import java.util.HashMap; import java.util.Map; @ContextConfiguration(classes = {MockAlertBeans.class, MailService.class}) -public class MailServiceTest extends AbstractServiceIntegrationTest { +class MailServiceTest extends AbstractServiceIntegrationTest { @Autowired @@ -44,7 +44,7 @@ public class MailServiceTest extends AbstractServiceIntegrationTest { MailService testInstance; @Test - public void testSendMail() { + void testSendMail() { Mockito.doNothing().when(mockJavaMailSender).send((MimeMessage) Mockito.any()); Map<String, Object> props = new HashMap<>(); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/resource/ResourceHandlerServiceTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/resource/ResourceHandlerServiceTest.java index edecf0cbd76a10174ba1717ec85c8aff7ef5f117..9ca3f68c3d50ef926a930d21f5798e936cbe4b10 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/resource/ResourceHandlerServiceTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/resource/ResourceHandlerServiceTest.java @@ -80,10 +80,6 @@ class ResourceHandlerServiceTest extends AbstractJunit5BaseDao { } - @Test - void createResource() { - } - @Test void testReadResource() { Mockito.doReturn(resolvedData).when(requestData).getResolvedData(); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/resource/ResourceResolverServiceTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/resource/ResourceResolverServiceTest.java index c493e6f981f34df7dfadc29c4869f3cd4e0ce48f..d5b793873c403cf67764670ce73b35019ed8f907 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/resource/ResourceResolverServiceTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/resource/ResourceResolverServiceTest.java @@ -31,8 +31,8 @@ import eu.europa.ec.edelivery.smp.servlet.ResourceRequest; import eu.europa.ec.edelivery.smp.testutil.TestDBUtils; import org.hamcrest.CoreMatchers; import org.hamcrest.MatcherAssert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.junit.platform.commons.util.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; @@ -43,7 +43,7 @@ import java.util.List; import java.util.UUID; import static eu.europa.ec.edelivery.smp.testutil.TestConstants.TEST_DOC_SCHEMA_2; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; @ContextConfiguration(classes = {ResourceResolverService.class, ConversionTestConfig.class}) @@ -53,7 +53,7 @@ public class ResourceResolverServiceTest extends AbstractServiceIntegrationTest @Autowired protected ResourceResolverService testInstance; - @Before + @BeforeEach public void prepareDatabase() { // setup initial data! testUtilsDao.clearData(); @@ -61,7 +61,7 @@ public class ResourceResolverServiceTest extends AbstractServiceIntegrationTest } @Test - public void tesValidateRequestDataInvalid() { + void tesValidateRequestDataInvalid() { List<Object[]> faileTestData = Arrays.asList( new Object[]{new ResourceRequest(null, null, null, null), "Resource Location vector coordinates must not be null"}, @@ -80,7 +80,7 @@ public class ResourceResolverServiceTest extends AbstractServiceIntegrationTest } @Test - public void testResolveAndAuthorizeRequestForResource() { + void testResolveAndAuthorizeRequestForResource() { // given SMPUserDetails user = new SMPUserDetails(null, null, null); DBResource resource = testUtilsDao.getResourceD1G1RD1(); @@ -96,7 +96,7 @@ public class ResourceResolverServiceTest extends AbstractServiceIntegrationTest } @Test - public void testResolveAndAuthorizeRequestForSubresource() { + void testResolveAndAuthorizeRequestForSubresource() { // given SMPUserDetails user = new SMPUserDetails(null, null, null); DBResource resource = testUtilsDao.getResourceD1G1RD1(); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIAlertServiceIntegrationTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIAlertServiceIntegrationTest.java index 95d3625814f99272b4ab492091600d9f852134c7..1770d8ef3b40df3b324f898406eb794ffba6f7b6 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIAlertServiceIntegrationTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIAlertServiceIntegrationTest.java @@ -24,15 +24,15 @@ import eu.europa.ec.edelivery.smp.data.ui.ServiceResult; import eu.europa.ec.edelivery.smp.services.AbstractServiceIntegrationTest; import eu.europa.ec.edelivery.smp.services.CredentialsAlertService; import eu.europa.ec.edelivery.smp.testutil.TestDBUtils; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.*; @ContextConfiguration(classes = UIAlertService.class) -public class UIAlertServiceIntegrationTest extends AbstractServiceIntegrationTest { +class UIAlertServiceIntegrationTest extends AbstractServiceIntegrationTest { @Autowired protected UIAlertService testInstance; @@ -52,7 +52,7 @@ public class UIAlertServiceIntegrationTest extends AbstractServiceIntegrationTes @Test - public void getTableList() { + void getTableList() { ServiceResult<AlertRO> before = testInstance.getTableList(-1, -1, null, null, null); int newAddedValuesCount = 10; insertDataObjects(newAddedValuesCount); @@ -64,7 +64,7 @@ public class UIAlertServiceIntegrationTest extends AbstractServiceIntegrationTes @Test - public void convertToRo() { + void convertToRo() { DBAlert alert = TestDBUtils.createDBAlert("test"); AlertRO alertRO = testInstance.convertToRo(alert); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIDocumentServiceTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIDocumentServiceTest.java index 977eae1f50126d6fc79bf858a5cd09006a0d87ba..7dc3d4ac41fcac0040a46a53c7d4172dc24084d4 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIDocumentServiceTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIDocumentServiceTest.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -32,13 +32,14 @@ import eu.europa.ec.smp.spi.handler.OasisSMPSubresource10Handler; import eu.europa.ec.smp.spi.validation.Subresource10Validator; import org.hamcrest.CoreMatchers; import org.hamcrest.MatcherAssert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; + @ContextConfiguration(classes = {UIDocumentService.class, ConversionTestConfig.class, ResourceHandlerService.class, OasisSMPResource10.class, OasisSMPResource10Handler.class, OasisSMPSubresource10.class, OasisSMPSubresource10Handler.class, Subresource10Validator.class,}) @@ -47,7 +48,7 @@ public class UIDocumentServiceTest extends AbstractServiceIntegrationTest { @Autowired protected UIDocumentService testInstance; - @Before + @BeforeEach public void prepareDatabase() { // setup initial data! testUtilsDao.clearData(); @@ -55,7 +56,7 @@ public class UIDocumentServiceTest extends AbstractServiceIntegrationTest { } @Test - public void testGenerateDocumentForResource(){ + void testGenerateDocumentForResource() { DocumentRo result = testInstance.generateDocumentForResource(testUtilsDao.getResourceD1G1RD1().getId(), null); assertNotNull(result); @@ -63,7 +64,7 @@ public class UIDocumentServiceTest extends AbstractServiceIntegrationTest { } @Test - public void testGenerateDocumentForSubResource(){ + void testGenerateDocumentForSubResource() { DBSubresource subresource = testUtilsDao.getSubresourceD1G1RD1_S1(); DocumentRo result = testInstance.generateDocumentForSubresource(subresource.getId(), @@ -74,7 +75,7 @@ public class UIDocumentServiceTest extends AbstractServiceIntegrationTest { } @Test - public void testValidateForResource() { + void testValidateForResource() { DBResource resource = testUtilsDao.getResourceD1G1RD1(); DocumentRo testDoc = testInstance.generateDocumentForResource(resource.getId(), null); assertNotNull(testDoc.getPayload()); @@ -83,21 +84,20 @@ public class UIDocumentServiceTest extends AbstractServiceIntegrationTest { } @Test - public void testValidateForResourceError() { + void testValidateForResourceError() { DBResource resource = testUtilsDao.getResourceD1G1RD1(); DocumentRo testDoc = new DocumentRo(); testDoc.setPayload("test"); - SMPRuntimeException result = assertThrows(SMPRuntimeException.class, () -> { - testInstance.validateDocumentForResource(resource.getId(), testDoc); - }); + SMPRuntimeException result = assertThrows(SMPRuntimeException.class, () -> + testInstance.validateDocumentForResource(resource.getId(), testDoc)); MatcherAssert.assertThat(result.getMessage(), CoreMatchers.containsString("Invalid request [ResourceValidation]")); } @Test - public void testValidateForSubresource() { + void testValidateForSubresource() { DBSubresource subresource = testUtilsDao.getSubresourceD1G1RD1_S1(); DocumentRo testDoc = testInstance.generateDocumentForSubresource(subresource.getId(), subresource.getResource().getId(), @@ -109,34 +109,33 @@ public class UIDocumentServiceTest extends AbstractServiceIntegrationTest { } @Test - public void testValidateForSubresourceError() { + void testValidateForSubresourceError() { DBSubresource subresource = testUtilsDao.getSubresourceD1G1RD1_S1(); DocumentRo testDoc = new DocumentRo(); testDoc.setPayload("test"); - SMPRuntimeException result = assertThrows(SMPRuntimeException.class, () -> { - testInstance.validateDocumentForSubresource(subresource.getId(), subresource.getResource().getId(), testDoc); - }); + SMPRuntimeException result = assertThrows(SMPRuntimeException.class, () -> + testInstance.validateDocumentForSubresource(subresource.getId(), subresource.getResource().getId(), testDoc)); MatcherAssert.assertThat(result.getMessage(), CoreMatchers.containsString("Invalid request [ResourceValidation]")); } @Test - public void testGetDocumentForResource(){ + void testGetDocumentForResource() { DBResource resource = testUtilsDao.getResourceD1G1RD1(); DocumentRo testDoc = testInstance.getDocumentForResource(resource.getId(), 1); assertNotNull(testDoc.getPayload()); } @Test - public void testGetDocumentForSubResource(){ + void testGetDocumentForSubResource() { DBSubresource subresource = testUtilsDao.getSubresourceD1G1RD1_S1(); DocumentRo testDoc = testInstance.getDocumentForSubResource(subresource.getId(), subresource.getResource().getId(), 1); assertNotNull(testDoc.getPayload()); } @Test - public void testSaveDocumentForResource(){ + void testSaveDocumentForResource() { DBResource resource = testUtilsDao.getResourceD1G1RD1(); DocumentRo testDoc = testInstance.generateDocumentForResource(resource.getId(), null); assertNotNull(testDoc.getPayload()); @@ -147,7 +146,7 @@ public class UIDocumentServiceTest extends AbstractServiceIntegrationTest { } @Test - public void testSaveSubresourceDocumentForResource(){ + void testSaveSubresourceDocumentForResource() { DBSubresource subresource = testUtilsDao.getSubresourceD1G1RD1_S1(); DocumentRo testDoc = testInstance.generateDocumentForSubresource(subresource.getId(), subresource.getResource().getId(), diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIDomainPublicServiceTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIDomainPublicServiceTest.java index f306e7cb55a33ec62199978c04f2e0a18fcba87e..474557f6d4da76d0d9a9fc8cb21b58a6a938ef5a 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIDomainPublicServiceTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIDomainPublicServiceTest.java @@ -48,62 +48,62 @@ class UIDomainPublicServiceTest extends AbstractJunit5BaseDao { } @Test - public void testGetTableList() { + void testGetTableList() { ServiceResult<DomainPublicRO> result = testInstance.getTableList(-1, -1, null, null, null); assertEquals(3, result.getCount().intValue()); } @Test - public void testGetAllDomainsForDomainAdminUser() { + void testGetAllDomainsForDomainAdminUser() { List<DomainRO> result = testInstance.getAllDomainsForDomainAdminUser(testUtilsDao.getUser1().getId()); assertEquals(1, result.size()); } @Test - public void testGetAllDomainsForDomainAdminUser3() { + void testGetAllDomainsForDomainAdminUser3() { List<DomainRO> result = testInstance.getAllDomainsForDomainAdminUser(testUtilsDao.getUser3().getId()); assertEquals(0, result.size()); } @Test - public void testGetAllDomainsForGroupAdminUser() { + void testGetAllDomainsForGroupAdminUser() { List<DomainRO> result = testInstance.getAllDomainsForGroupAdminUser(testUtilsDao.getUser1().getId()); assertEquals(1, result.size()); } @Test - public void testGetAllDomainsForGroupAdminUser3() { + void testGetAllDomainsForGroupAdminUser3() { List<DomainRO> result = testInstance.getAllDomainsForGroupAdminUser(testUtilsDao.getUser3().getId()); assertEquals(0, result.size()); } @Test - public void testGetAllDomainsForResourceAdminUser() { + void testGetAllDomainsForResourceAdminUser() { List<DomainRO> result = testInstance.getAllDomainsForResourceAdminUser(testUtilsDao.getUser1().getId()); assertEquals(1, result.size()); } @Test - public void testGetAllDomainsForResourceAdminUser3() { + void testGetAllDomainsForResourceAdminUser3() { List<DomainRO> result = testInstance.getAllDomainsForResourceAdminUser(testUtilsDao.getUser3().getId()); assertEquals(0, result.size()); } @Test - public void testGetDomainMembers() { + void testGetDomainMembers() { ServiceResult<MemberRO> result = testInstance.getDomainMembers(testUtilsDao.getD1().getId(), -1, -1, null); assertEquals(1, result.getCount().intValue()); assertEquals(1, result.getServiceEntities().size()); } @Test - public void testGetResourceDefDomainList() { + void testGetResourceDefDomainList() { List<ResourceDefinitionRO> result = testInstance.getResourceDefDomainList(testUtilsDao.getD1().getId()); assertEquals(2, result.size()); } @Test - public void testGetResourceDefDomainListFal() { + void testGetResourceDefDomainListFal() { BadRequestException result = assertThrows(BadRequestException.class, () -> testInstance.getResourceDefDomainList(-100L)); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIDomainServiceIntegrationTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIDomainServiceIntegrationTest.java index 525cc9d87dda4d8dcccc855903d6f130a202dcca..949a433c8ba2ffdc05de8ff5252f606004effd97 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIDomainServiceIntegrationTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIDomainServiceIntegrationTest.java @@ -24,11 +24,11 @@ import eu.europa.ec.edelivery.smp.data.ui.DomainRO; import eu.europa.ec.edelivery.smp.data.ui.ServiceResult; import eu.europa.ec.edelivery.smp.services.AbstractServiceIntegrationTest; import eu.europa.ec.edelivery.smp.testutil.TestDBUtils; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; /** @@ -38,7 +38,7 @@ import static org.junit.Assert.*; * @since 4.1 */ @ContextConfiguration(classes = UIDomainService.class) -public class UIDomainServiceIntegrationTest extends AbstractServiceIntegrationTest { +class UIDomainServiceIntegrationTest extends AbstractServiceIntegrationTest { @Autowired protected UIDomainService testInstance; @@ -51,7 +51,7 @@ public class UIDomainServiceIntegrationTest extends AbstractServiceIntegrationTe } @Test - public void testGetTableListEmpty() { + void testGetTableListEmpty() { // given when ServiceResult<DomainRO> res = testInstance.getTableList(-1, -1, null, null, null); // then @@ -64,7 +64,7 @@ public class UIDomainServiceIntegrationTest extends AbstractServiceIntegrationTe } @Test - public void testGetTableList15() { + void testGetTableList15() { // given insertDataObjects(15); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIDomainServiceTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIDomainServiceTest.java index 9d6eed1ced0ecba72f8becac03238c7cd3c0c343..ebf7532c662c1f26a2d316e9bd47b321595b1dbf 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIDomainServiceTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIDomainServiceTest.java @@ -26,9 +26,8 @@ import eu.europa.ec.edelivery.smp.exceptions.BadRequestException; import eu.europa.ec.edelivery.smp.services.AbstractServiceTest; import eu.europa.ec.edelivery.smp.services.SMLIntegrationService; import org.apache.commons.lang3.StringUtils; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.SpyBean; @@ -37,9 +36,9 @@ import org.springframework.test.util.ReflectionTestUtils; import java.util.Collections; import java.util.List; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -public class UIDomainServiceTest extends AbstractServiceTest { +class UIDomainServiceTest extends AbstractServiceTest { @Autowired private UIDomainService testInstance; @@ -49,7 +48,7 @@ public class UIDomainServiceTest extends AbstractServiceTest { @SpyBean private SMLIntegrationService smlIntegrationService; - @Before + @BeforeEach public void prepareDatabase() { testUtilsDao.clearData(); testUtilsDao.createResourceDefinitionsForDomains(); @@ -59,13 +58,13 @@ public class UIDomainServiceTest extends AbstractServiceTest { } @Test - public void getAllDomains() { + void getAllDomains() { List<DomainRO> domainROS = testInstance.getAllDomains(); assertEquals(3, domainROS.size()); } @Test - public void updateDomainData() { + void updateDomainData() { DomainRO domainRO = new DomainRO(); domainRO.setDomainCode("NewCode"); domainRO.setVisibility(VisibilityType.INTERNAL); @@ -82,7 +81,7 @@ public class UIDomainServiceTest extends AbstractServiceTest { } @Test - public void updateSMLDomainData() { + void updateSMLDomainData() { DomainRO domainRO = new DomainRO(); domainRO.setSmlSubdomain("New SmlSubdomain"); domainRO.setSmlSmpId("NewSmlSmpId"); @@ -100,26 +99,26 @@ public class UIDomainServiceTest extends AbstractServiceTest { } @Test - public void updateSMLDomainData_domainNotFound() { - BadRequestException result = Assert.assertThrows(BadRequestException.class, () -> + void updateSMLDomainData_domainNotFound() { + BadRequestException result = assertThrows(BadRequestException.class, () -> testInstance.updateDomainSmlIntegrationData(-1l, new DomainRO())); - Assert.assertEquals("Domain does not exist in database!", result.getMessage()); + assertEquals("Domain does not exist in database!", result.getMessage()); } @Test - public void updateSMLDomainData_registeredDomainSmpIdChangeNotAllowed() { + void updateSMLDomainData_registeredDomainSmpIdChangeNotAllowed() { DBDomain domain = testUtilsDao.getD3(); DomainRO domainRO = new DomainRO(); domainRO.setSmlSmpId("utestRegistered03"); - BadRequestException result = Assert.assertThrows(BadRequestException.class, () -> + BadRequestException result = assertThrows(BadRequestException.class, () -> testInstance.updateDomainSmlIntegrationData(domain.getId(), domainRO)); - Assert.assertEquals("SMP-SML identifier must not change for registered domain [utestRegistered03]!", result.getMessage()); + assertEquals("SMP-SML identifier must not change for registered domain [utestRegistered03]!", result.getMessage()); } @Test - public void updateSMLDomainData_invalidSmlIntegrationCertificate() { + void updateSMLDomainData_invalidSmlIntegrationCertificate() { DBDomain domain = testUtilsDao.getD3(); // Ensure domain DTO doesn't update domain existing values or #isDomainValid(domain) below won't match @@ -132,13 +131,13 @@ public class UIDomainServiceTest extends AbstractServiceTest { Mockito.doReturn(false).when(smlIntegrationService).isDomainValid(domain); - BadRequestException result = Assert.assertThrows(BadRequestException.class, () -> + BadRequestException result = assertThrows(BadRequestException.class, () -> testInstance.updateDomainSmlIntegrationData(domain.getId(), domainRO)); - Assert.assertEquals("The SML-SMP certificate for domain [utestRegistered03] is not valid!", result.getMessage()); + assertEquals("The SML-SMP certificate for domain [utestRegistered03] is not valid!", result.getMessage()); } @Test - public void updateDomainResourceListClear() { + void updateDomainResourceListClear() { DBDomain testDomain = testUtilsDao.getD1(); DomainRO domainRO = testInstance.getDomainData(testDomain.getId()); assertFalse(domainRO.getResourceDefinitions().isEmpty()); @@ -149,7 +148,7 @@ public class UIDomainServiceTest extends AbstractServiceTest { } @Test - public void updateDomainResourceListAddNew() { + void updateDomainResourceListAddNew() { DBDomain testDomain = testUtilsDao.getD2(); DomainRO domainRO = testInstance.getDomainData(testDomain.getId()); String restDef2 = testUtilsDao.getResourceDefCpp().getIdentifier(); @@ -164,7 +163,7 @@ public class UIDomainServiceTest extends AbstractServiceTest { } @Test - public void deleteDomain() { + void deleteDomain() { DBDomain domain = testUtilsDao.getD1(); DBDomain test = domainDao.find(domain.getId()); assertNotNull(test); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIGroupPublicServiceTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIGroupPublicServiceTest.java index cc67fb0116b783700a443dca056cf92a5495d471..57f6e8722d1579eee4c314dae5579cb9d0cda6e6 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIGroupPublicServiceTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIGroupPublicServiceTest.java @@ -37,11 +37,11 @@ import org.springframework.core.convert.ConversionService; import java.util.List; import java.util.UUID; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.*; + import static org.junit.jupiter.api.Assertions.assertNotEquals; -public class UIGroupPublicServiceTest extends AbstractJunit5BaseDao { +class UIGroupPublicServiceTest extends AbstractJunit5BaseDao { @Autowired @@ -59,49 +59,49 @@ public class UIGroupPublicServiceTest extends AbstractJunit5BaseDao { } @Test - public void testGetAllGroupsForDomainD1() { + void testGetAllGroupsForDomainD1() { List<GroupRO> groups = testInstance.getAllGroupsForDomain(testUtilsDao.getD1().getId()); assertEquals(2, groups.size()); } @Test - public void testGetAllGroupsForDomainD2() { + void testGetAllGroupsForDomainD2() { List<GroupRO> groups = testInstance.getAllGroupsForDomain(testUtilsDao.getD2().getId()); assertEquals(1, groups.size()); } @Test - public void testGetAllGroupsForDomainAndUserAndGroupRoleExpectedOneGroup() { + void testGetAllGroupsForDomainAndUserAndGroupRoleExpectedOneGroup() { List<GroupRO> groups = testInstance.getAllGroupsForDomainAndUserAndGroupRole(testUtilsDao.getD1().getId(), testUtilsDao.getUser1().getId(), MembershipRoleType.ADMIN); assertEquals(1, groups.size()); } @Test - public void testGetAllGroupsForDomainAndUserAndGroupRoleExpectedNullGroup() { + void testGetAllGroupsForDomainAndUserAndGroupRoleExpectedNullGroup() { List<GroupRO> groups = testInstance.getAllGroupsForDomainAndUserAndGroupRole(testUtilsDao.getD1().getId(), testUtilsDao.getUser1().getId(), MembershipRoleType.VIEWER); assertEquals(0, groups.size()); } @Test - public void testGetAllGroupsForDomainAndUserAndResourceRoleExpectedOneGroup() { + void testGetAllGroupsForDomainAndUserAndResourceRoleExpectedOneGroup() { List<GroupRO> groups = testInstance.getAllGroupsForDomainAndUserAndGroupRole(testUtilsDao.getD1().getId(), testUtilsDao.getUser1().getId(), MembershipRoleType.ADMIN); assertEquals(1, groups.size()); } @Test - public void testGetAllGroupsForDomainAndUserAndResourceRoleExpectedNullGroup() { + void testGetAllGroupsForDomainAndUserAndResourceRoleExpectedNullGroup() { List<GroupRO> groups = testInstance.getAllGroupsForDomainAndUserAndGroupRole(testUtilsDao.getD1().getId(), testUtilsDao.getUser1().getId(), MembershipRoleType.VIEWER); assertEquals(0, groups.size()); } @Test - public void testCreateGroupForDomain() { + void testCreateGroupForDomain() { // given GroupRO groupRO = TestROUtils.createGroup(UUID.randomUUID().toString(), VisibilityType.PUBLIC); DBDomain domain = testUtilsDao.getD1(); @@ -117,7 +117,7 @@ public class UIGroupPublicServiceTest extends AbstractJunit5BaseDao { } @Test - public void testSaveGroupForDomain() { + void testSaveGroupForDomain() { // given DBDomain domain = testUtilsDao.getD1(); DBGroup group = testUtilsDao.getGroupD1G1(); @@ -137,7 +137,7 @@ public class UIGroupPublicServiceTest extends AbstractJunit5BaseDao { } @Test - public void testDeleteGroupForDomain() { + void testDeleteGroupForDomain() { // given GroupRO groupRO = TestROUtils.createGroup(UUID.randomUUID().toString(), VisibilityType.PUBLIC); DBDomain domain = testUtilsDao.getD1(); @@ -152,7 +152,7 @@ public class UIGroupPublicServiceTest extends AbstractJunit5BaseDao { } @Test - public void testGetGroupMembers() { + void testGetGroupMembers() { // given // see the data in testUtilsDao.createGroupMemberships() // when @@ -166,7 +166,7 @@ public class UIGroupPublicServiceTest extends AbstractJunit5BaseDao { @Test - public void testAddUpdateMemberToGroupUpdate() { + void testAddUpdateMemberToGroupUpdate() { // given // see the data in testUtilsDao.createGroupMemberships() DBGroupMember dbMember = testUtilsDao.getGroupMemberU1D1G1Admin(); @@ -182,7 +182,7 @@ public class UIGroupPublicServiceTest extends AbstractJunit5BaseDao { } @Test - public void testAddUpdateMemberToGroupAdd() { + void testAddUpdateMemberToGroupAdd() { // given ServiceResult<MemberRO> members = testInstance.getGroupMembers(testUtilsDao.getGroupD1G1().getId(),testUtilsDao.getD1().getId(), -1, -1, null); int memberCount = members.getCount().intValue(); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIKeystoreServiceTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIKeystoreServiceTest.java index 6a95ca0aa77d453148cfea77bcfb7bf59b4d196c..07a02b4f86a234d4288f5aac17e52bbf0972e59a 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIKeystoreServiceTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIKeystoreServiceTest.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -23,16 +23,14 @@ import eu.europa.ec.edelivery.smp.data.ui.CertificateRO; import eu.europa.ec.edelivery.smp.exceptions.SMPRuntimeException; import eu.europa.ec.edelivery.smp.services.AbstractServiceIntegrationTest; import eu.europa.ec.edelivery.smp.services.ConfigurationService; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; +import org.hamcrest.CoreMatchers; +import org.hamcrest.MatcherAssert; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.util.ReflectionTestUtils; import javax.net.ssl.KeyManager; @@ -46,9 +44,8 @@ import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.util.List; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = {UIKeystoreService.class, ConversionTestConfig.class, ConfigurationService.class}) public class UIKeystoreServiceTest extends AbstractServiceIntegrationTest { @@ -58,16 +55,13 @@ public class UIKeystoreServiceTest extends AbstractServiceIntegrationTest { public static final X500Principal CERT_SUBJECT_X500PRINCIPAL = new X500Principal("CN=SMP Mock Services, OU=DIGIT, O=European Commision, C=BE"); - @Rule - public ExpectedException expectedEx = ExpectedException.none(); - @Autowired protected UIKeystoreService testInstance; ConfigurationService configurationService = Mockito.mock(ConfigurationService.class); - @Before + @BeforeEach public void setup() throws IOException { // restore keystore resetKeystore(); @@ -84,14 +78,14 @@ public class UIKeystoreServiceTest extends AbstractServiceIntegrationTest { } @Test - public void testGetKeystoreEntriesList() { + void testGetKeystoreEntriesList() { List<CertificateRO> lst = testInstance.getKeystoreEntriesList(); assertEquals(1, lst.size()); assertEquals(S_ALIAS, lst.get(0).getAlias()); } @Test - public void testGetSingleKey() { + void testGetSingleKey() { // given when assertEquals(1, testInstance.getKeystoreEntriesList().size()); Key key = testInstance.getKey(S_ALIAS); @@ -101,7 +95,7 @@ public class UIKeystoreServiceTest extends AbstractServiceIntegrationTest { } @Test - public void testGetSingleCertificate() { + void testGetSingleCertificate() { // given when assertEquals(1, testInstance.getKeystoreEntriesList().size()); X509Certificate certificate = testInstance.getCert(S_ALIAS); @@ -111,7 +105,7 @@ public class UIKeystoreServiceTest extends AbstractServiceIntegrationTest { } @Test - public void testGetSingleKeyNullAlias() { + void testGetSingleKeyNullAlias() { // given when assertEquals(1, testInstance.getKeystoreEntriesList().size()); Key key = testInstance.getKey(null); @@ -121,7 +115,7 @@ public class UIKeystoreServiceTest extends AbstractServiceIntegrationTest { } @Test - public void testGetSingleCertificateNullAlias() { + void testGetSingleCertificateNullAlias() { // given when assertEquals(1, testInstance.getKeystoreEntriesList().size()); X509Certificate certificate = testInstance.getCert(null); @@ -132,7 +126,7 @@ public class UIKeystoreServiceTest extends AbstractServiceIntegrationTest { } @Test - public void testGetKey() throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, UnrecoverableKeyException { + void testGetKey() throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, UnrecoverableKeyException { // given when testInstance.importKeys(loadKeystore("test-import.jks", "NewPassword1234", "JKS"), "NewPassword1234"); assertEquals(3, testInstance.getKeystoreEntriesList().size()); @@ -143,7 +137,7 @@ public class UIKeystoreServiceTest extends AbstractServiceIntegrationTest { } @Test - public void testGetCertificate() throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, UnrecoverableKeyException { + void testGetCertificate() throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, UnrecoverableKeyException { // given when testInstance.importKeys(loadKeystore("test-import.jks", "NewPassword1234", "JKS"), "NewPassword1234"); assertEquals(3, testInstance.getKeystoreEntriesList().size()); @@ -154,7 +148,7 @@ public class UIKeystoreServiceTest extends AbstractServiceIntegrationTest { } @Test - public void testImportPCKSKeystore() throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, UnrecoverableKeyException { + void testImportPCKSKeystore() throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, UnrecoverableKeyException { // given KeyStore keystore = loadKeystore("test-import.p12", "NewPassword1234", "PKCS12"); assertEquals(1, testInstance.getKeystoreEntriesList().size()); @@ -165,8 +159,8 @@ public class UIKeystoreServiceTest extends AbstractServiceIntegrationTest { } @Test - @Ignore("This test is not working on gitlab") - public void testImportKeystoreTwice() throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, UnrecoverableKeyException { + @Disabled("This test is not working on gitlab") + void testImportKeystoreTwice() throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, UnrecoverableKeyException { // given testInstance.importKeys(loadKeystore("test-import.jks", "NewPassword1234", "JKS"), "NewPassword1234"); assertEquals(3, testInstance.getKeystoreEntriesList().size()); @@ -177,7 +171,7 @@ public class UIKeystoreServiceTest extends AbstractServiceIntegrationTest { } @Test - public void testImportJKSKeystore() throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, UnrecoverableKeyException { + void testImportJKSKeystore() throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, UnrecoverableKeyException { // given KeyStore keystore = loadKeystore("test-import.jks", "NewPassword1234", "JKS"); assertEquals(1, testInstance.getKeystoreEntriesList().size()); @@ -189,42 +183,39 @@ public class UIKeystoreServiceTest extends AbstractServiceIntegrationTest { @Test - public void testDeleteKeyTestCertificate() throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, UnrecoverableKeyException { + void testDeleteKeyTestCertificate() throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, UnrecoverableKeyException { // given testInstance.importKeys(loadKeystore("test-import.jks", "NewPassword1234", "JKS"), "NewPassword1234"); assertEquals(3, testInstance.getKeystoreEntriesList().size()); assertNotNull(testInstance.getCert(S_ALIAS)); assertNotNull(testInstance.getKey(S_ALIAS)); - - expectedEx.expect(SMPRuntimeException.class); - expectedEx.expectMessage("Wrong configuration, missing key pair from keystore or wrong alias: " + S_ALIAS); - //when testInstance.deleteKey(S_ALIAS); + //when + SMPRuntimeException result = assertThrows(SMPRuntimeException.class, () -> { + testInstance.getCert(S_ALIAS); + }); - // then - assertEquals(2, testInstance.getKeystoreEntriesList().size()); - assertNull(testInstance.getCert(S_ALIAS)); + MatcherAssert.assertThat(result.getMessage(), + CoreMatchers.containsString("Wrong configuration, missing key pair from keystore or wrong alias: " + S_ALIAS)); } @Test - public void testDeleteKeyTestKey() throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, UnrecoverableKeyException { + void testDeleteKeyTestKey() throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, UnrecoverableKeyException { // given testInstance.importKeys(loadKeystore("test-import.jks", "NewPassword1234", "JKS"), "NewPassword1234"); assertEquals(3, testInstance.getKeystoreEntriesList().size()); assertNotNull(testInstance.getCert(S_ALIAS)); assertNotNull(testInstance.getKey(S_ALIAS)); - - expectedEx.expect(SMPRuntimeException.class); - expectedEx.expectMessage("Wrong configuration, missing key pair from keystore or wrong alias: " + S_ALIAS); - //when testInstance.deleteKey(S_ALIAS); + //when + SMPRuntimeException result = assertThrows(SMPRuntimeException.class, () -> { + testInstance.getKey(S_ALIAS); + }); - // then - assertEquals(2, testInstance.getKeystoreEntriesList().size()); - assertNull(testInstance.getKey(S_ALIAS)); + MatcherAssert.assertThat(result.getMessage(), + CoreMatchers.containsString("Wrong configuration, missing key pair from keystore or wrong alias: " + S_ALIAS)); } - private KeyStore loadKeystore(String keystoreName, String password, String type) throws KeyStoreException, CertificateException, NoSuchAlgorithmException, IOException { // Load the KeyStore and get the signing key and certificate. File keystoreFilePath = new File(resourceDirectory.toFile(), keystoreName); @@ -238,7 +229,7 @@ public class UIKeystoreServiceTest extends AbstractServiceIntegrationTest { } @Test - public void testDetectKeystoreChangeForEntryList() throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, UnrecoverableKeyException { + void testDetectKeystoreChangeForEntryList() throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, UnrecoverableKeyException { // given testInstance.importKeys(loadKeystore("test-import.jks", "NewPassword1234", "JKS"), "NewPassword1234"); assertEquals(3, testInstance.getKeystoreEntriesList().size()); @@ -251,7 +242,7 @@ public class UIKeystoreServiceTest extends AbstractServiceIntegrationTest { } @Test - public void testDetectKeystoreChangeForKeyManagers() throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, UnrecoverableKeyException { + void testDetectKeystoreChangeForKeyManagers() throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, UnrecoverableKeyException { // given KeyManager km = testInstance.getKeyManagers()[0]; testInstance.importKeys(loadKeystore("test-import.jks", "NewPassword1234", "JKS"), "NewPassword1234"); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIPropertyServiceIntegrationTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIPropertyServiceIntegrationTest.java index b7b6b078eadba1840db940f8ab436a010933b09a..f10c119086e10014ce316724ed6aa06bfd8b94f8 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIPropertyServiceIntegrationTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIPropertyServiceIntegrationTest.java @@ -28,7 +28,7 @@ import eu.europa.ec.edelivery.smp.services.AbstractServiceIntegrationTest; import org.apache.commons.lang3.StringUtils; import org.hamcrest.CoreMatchers; import org.hamcrest.MatcherAssert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.test.context.ContextConfiguration; @@ -39,11 +39,11 @@ import java.util.Map; import static eu.europa.ec.edelivery.smp.config.enums.SMPPropertyEnum.SMP_CLUSTER_ENABLED; import static eu.europa.ec.edelivery.smp.config.enums.SMPPropertyEnum.SMP_PROPERTY_REFRESH_CRON; import static eu.europa.ec.edelivery.smp.cron.CronTriggerConfig.TRIGGER_BEAN_PROPERTY_REFRESH; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; @ContextConfiguration(classes = {UIPropertyService.class}) -public class UIPropertyServiceIntegrationTest extends AbstractServiceIntegrationTest { +class UIPropertyServiceIntegrationTest extends AbstractServiceIntegrationTest { @Autowired protected UIPropertyService testInstance; @@ -53,7 +53,7 @@ public class UIPropertyServiceIntegrationTest extends AbstractServiceIntegration @Test - public void getTableListAll() { + void getTableListAll() { //when ServiceResultProperties res = testInstance.getTableList(-1, -1, null, null, null); @@ -67,7 +67,7 @@ public class UIPropertyServiceIntegrationTest extends AbstractServiceIntegration } @Test - public void getTableListFilterByCas() { + void getTableListFilterByCas() { //when String filter = ".cas"; @@ -84,7 +84,7 @@ public class UIPropertyServiceIntegrationTest extends AbstractServiceIntegration } @Test - public void createPropertyPendingToUpdate() { + void createPropertyPendingToUpdate() { SMPPropertyEnum propertyType = SMP_PROPERTY_REFRESH_CRON; DBConfiguration dbConfiguration = new DBConfiguration(); dbConfiguration.setProperty(propertyType.getProperty()); @@ -106,7 +106,7 @@ public class UIPropertyServiceIntegrationTest extends AbstractServiceIntegration } @Test - public void updatePropertyList() { + void updatePropertyList() { configurationDao.setPropertyToDatabase(SMP_PROPERTY_REFRESH_CRON.getProperty(), SMP_PROPERTY_REFRESH_CRON.getDefValue()); // set non cluster - to enable instant refresh configurationDao.setPropertyToDatabase(SMP_CLUSTER_ENABLED.getProperty(), "false"); @@ -122,7 +122,7 @@ public class UIPropertyServiceIntegrationTest extends AbstractServiceIntegration } @Test - public void validatePropertyNotExists() { + void validatePropertyNotExists() { String propertyName = "DoesNotExist"; String propertyValue = "DoesNotExistValue"; PropertyRO property = new PropertyRO(propertyName, propertyValue); @@ -136,7 +136,7 @@ public class UIPropertyServiceIntegrationTest extends AbstractServiceIntegration } @Test - public void validatePropertyInvalidValue() { + void validatePropertyInvalidValue() { String propertyName = SMPPropertyEnum.ACCESS_TOKEN_FAIL_DELAY.getProperty(); String propertyValue = "NotANumber"; PropertyRO property = new PropertyRO(propertyName, propertyValue); @@ -150,7 +150,7 @@ public class UIPropertyServiceIntegrationTest extends AbstractServiceIntegration } @Test - public void validatePropertyOK() { + void validatePropertyOK() { String propertyName = SMPPropertyEnum.ACCESS_TOKEN_FAIL_DELAY.getProperty(); String propertyValue = "1223232"; PropertyRO property = new PropertyRO(propertyName, propertyValue); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIResourceSearchServiceTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIResourceSearchServiceTest.java index c54c11ff6fd0c2a1c2ff9796235a02c17a9308fc..14b3af0d1007d9121f9d18193e64b329ed11293e 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIResourceSearchServiceTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIResourceSearchServiceTest.java @@ -30,7 +30,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -public class UIResourceSearchServiceTest extends AbstractJunit5BaseDao { +class UIResourceSearchServiceTest extends AbstractJunit5BaseDao { @Autowired @@ -44,7 +44,7 @@ public class UIResourceSearchServiceTest extends AbstractJunit5BaseDao { } @Test - public void testGetTableList() { + void testGetTableList() { ResourceFilter filter = new ResourceFilter(); ServiceResult<ServiceGroupSearchRO> result = testInstance.getTableList(-1, -1, null, null, filter); assertNotNull(result); @@ -52,7 +52,7 @@ public class UIResourceSearchServiceTest extends AbstractJunit5BaseDao { } @Test - public void testGetTableListWithFilter() { + void testGetTableListWithFilter() { ResourceFilter filter = new ResourceFilter(); filter.setIdentifierValueLike(testUtilsDao.getResourceD1G1RD1().getIdentifierValue()); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIResourceServiceTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIResourceServiceTest.java index 7e62f31fdbe4716c2573d61ad8af34c65086a783..7ec8d231ce37395d8f658e82d87a6e8971ae71ea 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIResourceServiceTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIResourceServiceTest.java @@ -46,7 +46,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.*; @ContextConfiguration(classes = {UIResourceService.class, ConversionTestConfig.class}) -public class UIResourceServiceTest extends AbstractJunit5BaseDao { +class UIResourceServiceTest extends AbstractJunit5BaseDao { @Autowired protected UIResourceService testInstance; @@ -65,7 +65,7 @@ public class UIResourceServiceTest extends AbstractJunit5BaseDao { } @Test - public void testGetGroupResources() { + void testGetGroupResources() { ServiceResult<ResourceRO> result = testInstance.getGroupResources(testUtilsDao.getGroupD1G1().getId(), -1, -1, null); // one resource is expected - see the data in testUtilsDao.createResources() assertNotNull(result); @@ -73,7 +73,7 @@ public class UIResourceServiceTest extends AbstractJunit5BaseDao { } @Test - public void testGetResourcesForUserAndGroup() { + void testGetResourcesForUserAndGroup() { ServiceResult<ResourceRO> resultAdmin = testInstance.getResourcesForUserAndGroup(testUtilsDao.getUser1().getId(), MembershipRoleType.ADMIN, testUtilsDao.getGroupD1G1().getId(), -1, -1, null); @@ -85,7 +85,7 @@ public class UIResourceServiceTest extends AbstractJunit5BaseDao { } @Test - public void testCreateResourceForGroup() { + void testCreateResourceForGroup() { // given ResourceRO testResource = TestROUtils.createResource(UUID.randomUUID().toString(), TEST_SG_SCHEMA_1, testUtilsDao.getDomainResourceDefD1R1().getResourceDef().getIdentifier()); @@ -100,7 +100,7 @@ public class UIResourceServiceTest extends AbstractJunit5BaseDao { } @Test - public void testCreateResourceForGroupFailsGroupNotExists() { + void testCreateResourceForGroupFailsGroupNotExists() { // given ResourceRO testResource = TestROUtils.createResource(UUID.randomUUID().toString(), TEST_SG_SCHEMA_1, testUtilsDao.getDomainResourceDefD1R1().getResourceDef().getIdentifier()); @@ -116,7 +116,7 @@ public class UIResourceServiceTest extends AbstractJunit5BaseDao { } @Test - public void testCreateResourceForGroupFailsGroupNotForDomain() { + void testCreateResourceForGroupFailsGroupNotForDomain() { // given ResourceRO testResource = TestROUtils.createResource(UUID.randomUUID().toString(), TEST_SG_SCHEMA_1, testUtilsDao.getDomainResourceDefD1R1().getResourceDef().getIdentifier()); @@ -132,7 +132,7 @@ public class UIResourceServiceTest extends AbstractJunit5BaseDao { } @Test - public void testCreateResourceForGroupFailInvalidResourceDef() { + void testCreateResourceForGroupFailInvalidResourceDef() { // given ResourceRO testResource = TestROUtils.createResource(UUID.randomUUID().toString(), TEST_SG_SCHEMA_1, UUID.randomUUID().toString()); @@ -148,7 +148,7 @@ public class UIResourceServiceTest extends AbstractJunit5BaseDao { } @Test - public void testCreateResourceForGroupFailAlreadyExists() { + void testCreateResourceForGroupFailAlreadyExists() { // given DBResource dbResource = testUtilsDao.getResourceD1G1RD1(); ResourceRO testResource = TestROUtils.createResource(dbResource.getIdentifierValue(), dbResource.getIdentifierScheme(), @@ -165,7 +165,7 @@ public class UIResourceServiceTest extends AbstractJunit5BaseDao { } @Test - public void testUpdateResourceForGroup() { + void testUpdateResourceForGroup() { // given DBResource dbResource = testUtilsDao.getResourceD1G1RD1(); ResourceRO testResource = TestROUtils.createResource(dbResource.getIdentifierValue(), dbResource.getIdentifierScheme(), dbResource.getDomainResourceDef().getResourceDef().getIdentifier()); @@ -184,7 +184,7 @@ public class UIResourceServiceTest extends AbstractJunit5BaseDao { @Test - public void testUpdateResourceForGroupGroupNotFound() { + void testUpdateResourceForGroupGroupNotFound() { // given DBResource dbResource = testUtilsDao.getResourceD1G1RD1(); ResourceRO testResource = TestROUtils.createResource(dbResource.getIdentifierValue(), dbResource.getIdentifierScheme(), dbResource.getDomainResourceDef().getResourceDef().getIdentifier()); @@ -201,7 +201,7 @@ public class UIResourceServiceTest extends AbstractJunit5BaseDao { } @Test - public void testUpdateResourceForGroupNotBelongToDomain() { + void testUpdateResourceForGroupNotBelongToDomain() { // given DBResource dbResource = testUtilsDao.getResourceD1G1RD1(); ResourceRO testResource = TestROUtils.createResource(dbResource.getIdentifierValue(), dbResource.getIdentifierScheme(), dbResource.getDomainResourceDef().getResourceDef().getIdentifier()); @@ -219,7 +219,7 @@ public class UIResourceServiceTest extends AbstractJunit5BaseDao { @Test - public void testUpdateResourceForGroupResourceDefNotFound() { + void testUpdateResourceForGroupResourceDefNotFound() { // given String defIdNotExist = UUID.randomUUID().toString(); DBResource dbResource = testUtilsDao.getResourceD1G1RD1(); @@ -237,7 +237,7 @@ public class UIResourceServiceTest extends AbstractJunit5BaseDao { } @Test - public void testDeleteResourceFromGroupOK() { + void testDeleteResourceFromGroupOK() { // given ResourceRO testResource = TestROUtils.createResource(UUID.randomUUID().toString(), TEST_SG_SCHEMA_1, testUtilsDao.getDomainResourceDefD1R1().getResourceDef().getIdentifier()); @@ -253,7 +253,7 @@ public class UIResourceServiceTest extends AbstractJunit5BaseDao { @Test - public void testDeleteResourceFromGroupResourceNotExists() { + void testDeleteResourceFromGroupResourceNotExists() { // given // when SMPRuntimeException result = assertThrows(SMPRuntimeException.class, @@ -265,7 +265,7 @@ public class UIResourceServiceTest extends AbstractJunit5BaseDao { @Test - public void testDeleteResourceFromGroupResourceNotBelongToGroup() { + void testDeleteResourceFromGroupResourceNotBelongToGroup() { // given // when SMPRuntimeException result = assertThrows(SMPRuntimeException.class, @@ -276,7 +276,7 @@ public class UIResourceServiceTest extends AbstractJunit5BaseDao { } @Test - public void testDeleteResourceFromGroup() { + void testDeleteResourceFromGroup() { // given ResourceRO testResource = TestROUtils.createResource(UUID.randomUUID().toString(), TEST_SG_SCHEMA_1, testUtilsDao.getDomainResourceDefD1R1().getResourceDef().getIdentifier()); @@ -293,7 +293,7 @@ public class UIResourceServiceTest extends AbstractJunit5BaseDao { } @Test - public void testGetResourceMembers() { + void testGetResourceMembers() { // given // see the data in testUtilsDao.createResourceMemberships() // when @@ -305,7 +305,7 @@ public class UIResourceServiceTest extends AbstractJunit5BaseDao { } @Test - public void testAddUpdateMemberToResourceUpdate() { + void testAddUpdateMemberToResourceUpdate() { // given // see the data in testUtilsDao.createResourceMemberships() DBResourceMember resourceMember = testUtilsDao.getResourceMemberU1R1_D2G1RD1_Admin(); @@ -320,7 +320,7 @@ public class UIResourceServiceTest extends AbstractJunit5BaseDao { } @Test - public void testAddUpdateMemberToResourceUAdd() { + void testAddUpdateMemberToResourceUAdd() { // given int memberCount = testInstance.getResourceMembers(testUtilsDao.getResourceD1G1RD1().getId(), testUtilsDao.getGroupD1G1().getId(), -1, -1, null).getCount().intValue(); DBResourceMember dbMember = new DBResourceMember(); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UITruststoreServiceIntegrationTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UITruststoreServiceIntegrationTest.java index 6698ba5ab06066002ffc10abc9b807eb8375311f..f1192ae84ac2188e09fe93e8cd750a4c7cac9a3c 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UITruststoreServiceIntegrationTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UITruststoreServiceIntegrationTest.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -29,14 +29,11 @@ import eu.europa.ec.edelivery.smp.testutil.X509CertificateTestUtils; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.hamcrest.CoreMatchers; -import org.hamcrest.MatcherAssert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.util.ReflectionTestUtils; import javax.security.auth.x500.X500Principal; @@ -50,9 +47,9 @@ import java.time.OffsetDateTime; import java.util.*; import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.*; -@RunWith(SpringJUnit4ClassRunner.class) public class UITruststoreServiceIntegrationTest extends AbstractServiceIntegrationTest { public static final String CERTIFICATE_POLICY_ANY = "2.5.29.32.0"; @@ -80,7 +77,7 @@ public class UITruststoreServiceIntegrationTest extends AbstractServiceIntegrati @Autowired protected CRLVerifierService crlVerifierService; - @Before + @BeforeEach public void setup() throws IOException { configurationService = Mockito.spy(configurationService); crlVerifierService = Mockito.spy(crlVerifierService); @@ -107,7 +104,7 @@ public class UITruststoreServiceIntegrationTest extends AbstractServiceIntegrati } @Test - public void testGetKeystoreEntriesList() { + void testGetKeystoreEntriesList() { List<String> lst = testInstance.getNormalizedTrustedList(); assertEquals(2, lst.size()); assertEquals(S_SUBJECT_PEPPOL, lst.get(0)); @@ -115,28 +112,28 @@ public class UITruststoreServiceIntegrationTest extends AbstractServiceIntegrati } @Test - public void testSubjectValid() { + void testSubjectValid() { // given when // then assertTrue(testInstance.isSubjectOnTrustedList(S_SUBJECT_PEPPOL)); } @Test - public void testSubjectValidExpanded() { + void testSubjectValidExpanded() { // given when // then assertTrue(testInstance.isSubjectOnTrustedList(S_SUBJECT_PEPPOL_EXPANDED)); } @Test - public void testSubjectNotTrusted() { + void testSubjectNotTrusted() { // given when // then assertFalse(testInstance.isSubjectOnTrustedList(S_SUBJECT_PEPPOL_NOT_TRUSTED)); } @Test - public void testAddCertificate() throws Exception { + void testAddCertificate() throws Exception { // given String certSubject = "CN=SMP Test,OU=eDelivery,O=DIGITAL,C=BE"; String alias = UUID.randomUUID().toString(); @@ -152,7 +149,7 @@ public class UITruststoreServiceIntegrationTest extends AbstractServiceIntegrati } @Test - public void testAddCertificateRDN() throws Exception { + void testAddCertificateRDN() throws Exception { // given String certSubject = "GIVENNAME=John+SERIALNUMBER=1+CN=SMP Test,OU=eDelivery,O=DIGITAL,C=BE"; String alias = UUID.randomUUID().toString(); @@ -169,7 +166,7 @@ public class UITruststoreServiceIntegrationTest extends AbstractServiceIntegrati } @Test - public void testDeleteCertificate() throws Exception { + void testDeleteCertificate() throws Exception { // given List<CertificateRO> list = testInstance.getCertificateROEntriesList(); int iSize = list.size(); @@ -185,7 +182,7 @@ public class UITruststoreServiceIntegrationTest extends AbstractServiceIntegrati } @Test - public void testDeleteCertificateNotExists() throws Exception { + void testDeleteCertificateNotExists() throws Exception { // given // when X509Certificate cert = testInstance.deleteCertificate("alias-not-exists"); @@ -194,7 +191,7 @@ public class UITruststoreServiceIntegrationTest extends AbstractServiceIntegrati } @Test - public void testIsTruststoreChanged() throws Exception { + void testIsTruststoreChanged() throws Exception { // given String certSubject = "CN=SMP Test,OU=eDelivery,O=DIGITAL,C=BE"; String alias = UUID.randomUUID().toString(); @@ -209,7 +206,7 @@ public class UITruststoreServiceIntegrationTest extends AbstractServiceIntegrati @Test - public void testGetCertificateDataPEMAndFullValidationExpired() throws IOException { + void testGetCertificateDataPEMAndFullValidationExpired() throws IOException { // given byte[] buff = IOUtils.toByteArray(UIUserServiceIntegrationTest.class.getResourceAsStream("/truststore/SMPtest.crt")); @@ -229,7 +226,7 @@ public class UITruststoreServiceIntegrationTest extends AbstractServiceIntegrati } @Test - public void validateCertificateWithTruststoreNullCertificate() { + void validateCertificateWithTruststoreNullCertificate() { CertificateException result = assertThrows(CertificateException.class, () -> testInstance.validateCertificateWithTruststore(null)); @@ -238,7 +235,7 @@ public class UITruststoreServiceIntegrationTest extends AbstractServiceIntegrati } @Test - public void validateCertificateWithTruststoreNullTruststore() throws Exception { + void validateCertificateWithTruststoreNullTruststore() throws Exception { String certSubject = "CN=SMP Test,OU=eDelivery,O=DIGITAL,C=BE"; X509Certificate certificate = X509CertificateTestUtils.createX509CertificateForTest(certSubject); Mockito.doReturn(null).when(testInstance).getTrustStore(); @@ -249,7 +246,7 @@ public class UITruststoreServiceIntegrationTest extends AbstractServiceIntegrati } @Test - public void testGetCertificateDataError() throws IOException, CertificateException { + void testGetCertificateDataError() throws IOException, CertificateException { // given byte[] buff = IOUtils.toByteArray(UIUserServiceIntegrationTest.class.getResourceAsStream("/certificates/cert-not-parsable.pem")); @@ -263,7 +260,7 @@ public class UITruststoreServiceIntegrationTest extends AbstractServiceIntegrati } @Test - public void testGetCertificateDataPEMWithHeader() throws IOException, CertificateException { + void testGetCertificateDataPEMWithHeader() throws IOException, CertificateException { // given byte[] buff = IOUtils.toByteArray(UIUserServiceIntegrationTest.class.getResourceAsStream("/truststore/pem-with-header.crt")); @@ -281,7 +278,7 @@ public class UITruststoreServiceIntegrationTest extends AbstractServiceIntegrati } @Test - public void testGetCertificateDataSMime() throws IOException, CertificateException { + void testGetCertificateDataSMime() throws IOException, CertificateException { // given byte[] buff = IOUtils.toByteArray(UIUserServiceIntegrationTest.class.getResourceAsStream("/certificates/cert-smime.pem")); @@ -299,7 +296,7 @@ public class UITruststoreServiceIntegrationTest extends AbstractServiceIntegrati } @Test - public void testGetCertificateDataDER() throws IOException, CertificateException { + void testGetCertificateDataDER() throws IOException, CertificateException { // given byte[] buff = IOUtils.toByteArray(UIUserServiceIntegrationTest.class.getResourceAsStream("/truststore/NewPeppolAP.crt")); @@ -317,7 +314,7 @@ public class UITruststoreServiceIntegrationTest extends AbstractServiceIntegrati } @Test - public void testCheckFullCertificateValidityNotYetValid() throws Exception { + void testCheckFullCertificateValidityNotYetValid() throws Exception { // given String certSubject = "CN=SMP Test,OU=eDelivery,O=DIGITAL,C=BE"; X509Certificate certificate = X509CertificateTestUtils.createX509CertificateForTest("10af", certSubject, certSubject, @@ -331,7 +328,7 @@ public class UITruststoreServiceIntegrationTest extends AbstractServiceIntegrati } @Test - public void testCheckFullCertificateValidityExpired() throws Exception { + void testCheckFullCertificateValidityExpired() throws Exception { // given String certSubject = "CN=SMP Test,OU=eDelivery,O=DIGITAL,C=BE"; @@ -348,7 +345,7 @@ public class UITruststoreServiceIntegrationTest extends AbstractServiceIntegrati } @Test - public void testCheckFullCertificateNotTrusted() throws Exception { + void testCheckFullCertificateNotTrusted() throws Exception { // given String crlUrl = "https://localhost/crl"; String revokedSerialFromList = "0011"; @@ -371,12 +368,12 @@ public class UITruststoreServiceIntegrationTest extends AbstractServiceIntegrati CertificateNotTrustedException result = assertThrows(CertificateNotTrustedException.class, () -> testInstance.checkFullCertificateValidity(certificate)); //then - MatcherAssert.assertThat(result.getMessage(), CoreMatchers.containsString("Certificate is not trusted!")); + assertThat(result.getMessage(), CoreMatchers.containsString("Certificate is not trusted!")); } @Test - public void testCheckFullCertificateValidityRevoked() throws Exception { + void testCheckFullCertificateValidityRevoked() throws Exception { // given String crlUrl = "https://localhost/crl"; String revokedSerialFromList = "0011"; @@ -398,11 +395,11 @@ public class UITruststoreServiceIntegrationTest extends AbstractServiceIntegrati CertificateRevokedException result = assertThrows(CertificateRevokedException.class, () -> testInstance.checkFullCertificateValidity(certificate)); //then - MatcherAssert.assertThat(result.getMessage(), CoreMatchers.containsString("Certificate has been revoked")); + assertThat(result.getMessage(), CoreMatchers.containsString("Certificate has been revoked")); } @Test - public void testCheckFullCertificateValidityInvalidKey() throws Exception { + void testCheckFullCertificateValidityInvalidKey() throws Exception { // given String certSubject = "CN=SMP Test,OU=eDelivery,O=DIGITAL,C=BE"; X509Certificate certificate = X509CertificateTestUtils.createX509CertificateForTest( @@ -419,11 +416,11 @@ public class UITruststoreServiceIntegrationTest extends AbstractServiceIntegrati testInstance.checkFullCertificateValidity(certificate)); //then - MatcherAssert.assertThat(result.getMessage(), CoreMatchers.containsString("Certificate does not have allowed key algorithm type!")); + assertThat(result.getMessage(), CoreMatchers.containsString("Certificate does not have allowed key algorithm type!")); } @Test - public void testCheckFullCertificateValidityNotForceCRL() throws Exception { + void testCheckFullCertificateValidityNotForceCRL() throws Exception { // given String crlUrl = "https://localhost/crl"; String revokedSerialFromList = "0011"; @@ -448,7 +445,7 @@ public class UITruststoreServiceIntegrationTest extends AbstractServiceIntegrati } @Test - public void testCheckFullCertificateValidityOK() throws Exception { + void testCheckFullCertificateValidityOK() throws Exception { // given String crlUrl = "https://localhost/crl"; CertificateFactory cf = CertificateFactory.getInstance("X.509"); @@ -469,7 +466,7 @@ public class UITruststoreServiceIntegrationTest extends AbstractServiceIntegrati } @Test - public void testCreateAliasForCert() throws Exception { + void testCreateAliasForCert() throws Exception { // given String certSubject = "CN=SMP Test,OU=eDelivery,O=DIGITAL,C=BE"; X509Certificate certificate = X509CertificateTestUtils.createX509CertificateForTest(certSubject); @@ -482,7 +479,7 @@ public class UITruststoreServiceIntegrationTest extends AbstractServiceIntegrati @Test - public void testCreateAliasFoMultiValuerCert() throws Exception { + void testCreateAliasFoMultiValuerCert() throws Exception { // given String certSubject = "GIVENNAME=John+SERIALNUMBER=1+CN=SMP Test,OU=eDelivery,O=DIGITAL,C=BE"; X509Certificate certificate = X509CertificateTestUtils.createX509CertificateForTest(certSubject); @@ -494,7 +491,7 @@ public class UITruststoreServiceIntegrationTest extends AbstractServiceIntegrati } @Test - public void testValidateCertificatePolicyLegacyMatchOk() throws Exception { + void testValidateCertificatePolicyLegacyMatchOk() throws Exception { String certSubject = "CN=SMP Test,OU=eDelivery,O=DIGITAL,C=BE"; X509Certificate certificate = X509CertificateTestUtils.createX509CertificateForTest(certSubject, BigInteger.TEN, Collections.singletonList(CERTIFICATE_POLICY_QCP_NATURAL)); Mockito.doReturn(Arrays.asList(CERTIFICATE_POLICY_QCP_LEGAL, CERTIFICATE_POLICY_QCP_NATURAL)).when(configurationService).getAllowedCertificatePolicies(); @@ -502,29 +499,29 @@ public class UITruststoreServiceIntegrationTest extends AbstractServiceIntegrati } @Test - public void testValidateCertificatePolicyLegacyMatchEmpty() throws Exception { + void testValidateCertificatePolicyLegacyMatchEmpty() throws Exception { String certSubject = "CN=SMP Test,OU=eDelivery,O=DIGITAL,C=BE"; X509Certificate certificate = X509CertificateTestUtils.createX509CertificateForTest(certSubject, BigInteger.TEN, null); Mockito.doReturn(Arrays.asList(CERTIFICATE_POLICY_QCP_LEGAL, CERTIFICATE_POLICY_QCP_NATURAL)).when(configurationService).getAllowedCertificatePolicies(); CertificateException result = assertThrows(CertificateException.class, () -> testInstance.validateCertificatePolicyMatchLegacy(certificate)); - MatcherAssert.assertThat(result.getMessage(), CoreMatchers.startsWith("Certificate has empty CertificatePolicy extension. Certificate:")); + assertThat(result.getMessage(), CoreMatchers.startsWith("Certificate has empty CertificatePolicy extension. Certificate:")); } @Test - public void testValidateCertificatePolicyLegacyMatchMismatch() throws Exception { + void testValidateCertificatePolicyLegacyMatchMismatch() throws Exception { String certSubject = "CN=SMP Test,OU=eDelivery,O=DIGITAL,C=BE"; X509Certificate certificate = X509CertificateTestUtils.createX509CertificateForTest(certSubject, BigInteger.TEN, Collections.singletonList(CERTIFICATE_POLICY_QCP_LEGAL_QSCD)); Mockito.doReturn(Arrays.asList(CERTIFICATE_POLICY_QCP_LEGAL, CERTIFICATE_POLICY_QCP_NATURAL)).when(configurationService).getAllowedCertificatePolicies(); CertificateException result = assertThrows(CertificateException.class, () -> testInstance.validateCertificatePolicyMatchLegacy(certificate)); - MatcherAssert.assertThat(result.getMessage(), CoreMatchers.startsWith("Certificate policy verification failed.")); + assertThat(result.getMessage(), CoreMatchers.startsWith("Certificate policy verification failed.")); } @Test - public void validateCertificateNotUsed() throws CertificateException { + void validateCertificateNotUsed() throws CertificateException { String certId = "cn=test" + UUID.randomUUID() + ",o=test,c=eu:123456"; CertificateRO certificateRO = new CertificateRO(); certificateRO.setCertificateId(certId); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UITruststoreServiceTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UITruststoreServiceTest.java index 356a7dc3222d6efd56d0b60e154732ca82a6cc23..48439490ee90592ae7dcab26a37835e2375c81d8 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UITruststoreServiceTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UITruststoreServiceTest.java @@ -51,7 +51,7 @@ import java.util.regex.Pattern; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; -public class UITruststoreServiceTest { +class UITruststoreServiceTest { // test data protected Path resourceDirectory = Paths.get("src", "test", "resources", "truststore"); protected Path targetDirectory = Paths.get("target", "test-uitruststoreservice"); @@ -73,7 +73,7 @@ public class UITruststoreServiceTest { } @Test - public void validateCertificateNotUsedOk() throws CertificateException { + void validateCertificateNotUsedOk() throws CertificateException { String certId = "cn=test" + UUID.randomUUID() + ",o=test,c=eu:123456"; CertificateRO certificateRO = new CertificateRO(); certificateRO.setCertificateId(certId); @@ -88,7 +88,7 @@ public class UITruststoreServiceTest { } @Test - public void validateCertificateNotUsedIsUsed() { + void validateCertificateNotUsedIsUsed() { String certId = "cn=test" + UUID.randomUUID() + ",o=test,c=eu:123456"; CertificateRO certificateRO = new CertificateRO(); certificateRO.setCertificateId(certId); @@ -99,7 +99,7 @@ public class UITruststoreServiceTest { } @Test - public void validateNewCertificateOk() throws CertificateException { + void validateNewCertificateOk() throws CertificateException { X509Certificate cert = Mockito.mock(X509Certificate.class); CertificateRO certData = new CertificateRO(); doNothing().when(testInstance).checkFullCertificateValidity(cert); @@ -112,7 +112,7 @@ public class UITruststoreServiceTest { } @Test - public void validateNewCertificateCertificateExpiredException() throws CertificateException { + void validateNewCertificateCertificateExpiredException() throws CertificateException { X509Certificate cert = Mockito.mock(X509Certificate.class); CertificateRO certData = new CertificateRO(); doThrow(new CertificateExpiredException("Expired")).when(testInstance).checkFullCertificateValidity(cert); @@ -124,7 +124,7 @@ public class UITruststoreServiceTest { } @Test - public void validateNewCertificateCertificateCertificateNotYetValidException() throws CertificateException { + void validateNewCertificateCertificateCertificateNotYetValidException() throws CertificateException { X509Certificate cert = Mockito.mock(X509Certificate.class); CertificateRO certData = new CertificateRO(); doThrow(new CertificateNotYetValidException("Error")).when(testInstance).checkFullCertificateValidity(cert); @@ -136,7 +136,7 @@ public class UITruststoreServiceTest { } @Test - public void validateNewCertificateCertificateCertificateRevokedException() throws CertificateException { + void validateNewCertificateCertificateCertificateRevokedException() throws CertificateException { X509Certificate cert = Mockito.mock(X509Certificate.class); CertificateRO certData = new CertificateRO(); doThrow(Mockito.mock(CertificateRevokedException.class)).when(testInstance).checkFullCertificateValidity(cert); @@ -148,7 +148,7 @@ public class UITruststoreServiceTest { } @Test - public void validateNewCertificateCertificateCertificateNotTrustedException() throws CertificateException { + void validateNewCertificateCertificateCertificateNotTrustedException() throws CertificateException { X509Certificate cert = Mockito.mock(X509Certificate.class); CertificateRO certData = new CertificateRO(); doThrow(Mockito.mock(CertificateNotTrustedException.class)).when(testInstance).checkFullCertificateValidity(cert); @@ -160,7 +160,7 @@ public class UITruststoreServiceTest { } @Test - public void validateNewCertificateCertPathValidatorException() throws CertificateException { + void validateNewCertificateCertPathValidatorException() throws CertificateException { X509Certificate cert = Mockito.mock(X509Certificate.class); CertificateRO certData = new CertificateRO(); doThrow(new CertificateException(Mockito.mock(CertPathValidatorException.class))).when(testInstance).checkFullCertificateValidity(cert); @@ -172,7 +172,7 @@ public class UITruststoreServiceTest { } @Test - public void validateNewCertificateCertificateException() throws CertificateException { + void validateNewCertificateCertificateException() throws CertificateException { String errorMessage = "Error Message"; X509Certificate cert = Mockito.mock(X509Certificate.class); CertificateRO certData = new CertificateRO(); @@ -185,14 +185,14 @@ public class UITruststoreServiceTest { } @Test - public void validateCertificateSubjectExpressionLegacyIfNullSkip() throws CertificateException { + void validateCertificateSubjectExpressionLegacyIfNullSkip() throws CertificateException { X509Certificate cert = Mockito.mock(X509Certificate.class); doReturn(null).when(configurationService).getCertificateSubjectRegularExpression(); testInstance.validateCertificateSubjectExpressionLegacy(cert); } @Test - public void validateCertificateSubjectExpressionLegacyValidatedNotMatch() throws Exception { + void validateCertificateSubjectExpressionLegacyValidatedNotMatch() throws Exception { String regularExpression = ".*CN=SomethingNotExists.*"; String subject = "CN=Something,O=test,C=EU"; X509Certificate certificate = X509CertificateTestUtils.createX509CertificateForTest(subject); @@ -207,7 +207,7 @@ public class UITruststoreServiceTest { @Test - public void validateCertificateSubjectExpressionLegacyValidatedMatch() throws Exception { + void validateCertificateSubjectExpressionLegacyValidatedMatch() throws Exception { String regularExpression = ".*CN=Something.*"; String subject = "CN=Something,O=test,C=EU"; X509Certificate certificate = X509CertificateTestUtils.createX509CertificateForTest(subject); @@ -218,7 +218,7 @@ public class UITruststoreServiceTest { } @Test - public void loadTruststoreDoNotThrowError() { + void loadTruststoreDoNotThrowError() { // test for null file KeyStore result = testInstance.loadTruststore(null); assertNull(result); @@ -234,14 +234,14 @@ public class UITruststoreServiceTest { } @Test - public void testTruststoreNotConfiguredNotConfigured() { + void testTruststoreNotConfiguredNotConfigured() { doReturn(null).when(configurationService).getTruststoreFile(); boolean result = testInstance.truststoreNotConfigured(); assertTrue(result); } @Test - public void testTruststoreNotConfiguredConfigured() { + void testTruststoreNotConfiguredConfigured() { doReturn(targetTruststore.toFile()).when(configurationService).getTruststoreFile(); boolean result = testInstance.truststoreNotConfigured(); @@ -249,7 +249,7 @@ public class UITruststoreServiceTest { } @Test - public void testRefreshDataNoConfiguration() { + void testRefreshDataNoConfiguration() { doReturn(null).when(configurationService).getTruststoreFile(); // must not throw error @@ -261,7 +261,7 @@ public class UITruststoreServiceTest { } @Test - public void testRefreshDataOk() { + void testRefreshDataOk() { doReturn(targetTruststore.toFile()).when(configurationService).getTruststoreFile(); doReturn(truststorePassword).when(configurationService).getTruststoreCredentialToken(); @@ -274,7 +274,7 @@ public class UITruststoreServiceTest { } @Test - public void getCertificateDataNullEmpty() { + void getCertificateDataNullEmpty() { // must not throw error CertificateRO certificateRO = testInstance.getCertificateData(null); @@ -286,7 +286,7 @@ public class UITruststoreServiceTest { } @Test - public void getCertificateDataInvalidCertificate() { + void getCertificateDataInvalidCertificate() { // must not throw error CertificateRO certificateRO = testInstance.getCertificateData("notACertificate".getBytes()); @@ -298,7 +298,7 @@ public class UITruststoreServiceTest { } @Test - public void getCertificateDataNoValidationOK() throws Exception { + void getCertificateDataNoValidationOK() throws Exception { String subject = "CN=Something,O=test,C=EU"; X509Certificate certificate = X509CertificateTestUtils.createX509CertificateForTest(subject); CertificateRO convertedCert = Mockito.mock(CertificateRO.class); @@ -311,7 +311,7 @@ public class UITruststoreServiceTest { } @Test - public void getCertificateDataNoValidationBase64OK() throws Exception { + void getCertificateDataNoValidationBase64OK() throws Exception { String subject = "CN=Something,O=test,C=EU"; X509Certificate certificate = X509CertificateTestUtils.createX509CertificateForTest(subject); String base64Cert = Base64.getEncoder().encodeToString(certificate.getEncoded()); @@ -326,7 +326,7 @@ public class UITruststoreServiceTest { } @Test - public void getCertificateDataValidateOK() throws Exception { + void getCertificateDataValidateOK() throws Exception { String subject = "CN=Something,O=test,C=EU"; X509Certificate certificate = X509CertificateTestUtils.createX509CertificateForTest(subject); CertificateRO convertedCert = Mockito.mock(CertificateRO.class); @@ -339,7 +339,7 @@ public class UITruststoreServiceTest { } @Test - public void testValidateCertificateWithTruststoreNull() { + void testValidateCertificateWithTruststoreNull() { // when CertificateException result = assertThrows(CertificateException.class, () -> testInstance.validateCertificateWithTruststore(null)); // then @@ -347,7 +347,7 @@ public class UITruststoreServiceTest { } @Test - public void testValidateCertificateWithTruststoreNoTruststoreConfigured() throws Exception { + void testValidateCertificateWithTruststoreNoTruststoreConfigured() throws Exception { String subject = "CN=Something,O=test,C=EU"; X509Certificate certificate = X509CertificateTestUtils.createX509CertificateForTest(subject); doReturn(null).when(configurationService).getTruststoreFile(); @@ -360,7 +360,7 @@ public class UITruststoreServiceTest { } @Test - public void testValidateCertificateWithTruststoreNotTrusted() throws Exception { + void testValidateCertificateWithTruststoreNotTrusted() throws Exception { String subject = "CN=Something,O=test,C=EU"; X509Certificate certificate = X509CertificateTestUtils.createX509CertificateForTest(subject); doReturn(targetTruststore.toFile()).when(configurationService).getTruststoreFile(); @@ -374,7 +374,7 @@ public class UITruststoreServiceTest { } @Test - public void testValidateAllowedCertificateKeyTypes() throws Exception { + void testValidateAllowedCertificateKeyTypes() throws Exception { String subject = "CN=Something,O=test,C=EU"; X509Certificate certificate = X509CertificateTestUtils.createX509CertificateForTest(subject); doReturn(Collections.singletonList("FutureKeyAlgorithm")).when(configurationService).getAllowedCertificateKeyTypes(); @@ -387,7 +387,7 @@ public class UITruststoreServiceTest { @Test - public void testAddCertificate() throws Exception { + void testAddCertificate() throws Exception { String subject = "CN=Something,O=test,C=EU"; X509Certificate certificate = X509CertificateTestUtils.createX509CertificateForTest(subject); @@ -402,7 +402,7 @@ public class UITruststoreServiceTest { } @Test - public void testDeleteCertificate() throws Exception { + void testDeleteCertificate() throws Exception { String subject = "CN=Something,O=test,C=EU"; X509Certificate certificate = X509CertificateTestUtils.createX509CertificateForTest(subject); doReturn(targetTruststore.toFile()).when(configurationService).getTruststoreFile(); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIUserServiceIntegrationTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIUserServiceIntegrationTest.java index e9d3f2888b0b90850fba6a2c3a9205f256f19830..c1d6056c33cfd98a3da602dfe1e52aabd57a8aa0 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIUserServiceIntegrationTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIUserServiceIntegrationTest.java @@ -64,7 +64,7 @@ import static org.mockito.Mockito.when; * @since 4.1 */ @ContextConfiguration(classes = {UIUserService.class, ConversionTestConfig.class}) -public class UIUserServiceIntegrationTest extends AbstractJunit5BaseDao { +class UIUserServiceIntegrationTest extends AbstractJunit5BaseDao { @Autowired protected UIUserService testInstance; @@ -84,7 +84,7 @@ public class UIUserServiceIntegrationTest extends AbstractJunit5BaseDao { } @Test - public void testGetTableListEmpty() { + void testGetTableListEmpty() { // given //when @@ -100,7 +100,7 @@ public class UIUserServiceIntegrationTest extends AbstractJunit5BaseDao { } @Test - public void testGetTableList15() { + void testGetTableList15() { // given insertDataObjects(15); @@ -124,7 +124,7 @@ public class UIUserServiceIntegrationTest extends AbstractJunit5BaseDao { } @Test - public void testAddUser() { + void testAddUser() { // given insertDataObjects(15); long iCnt = userDao.getDataListCount(null); @@ -149,7 +149,7 @@ public class UIUserServiceIntegrationTest extends AbstractJunit5BaseDao { } @Test - public void testDeleteUser() { + void testDeleteUser() { // given insertDataObjects(15); ServiceResult<UserRO> urTest = testInstance.getTableList(-1, -1, null, null, null); @@ -170,7 +170,7 @@ public class UIUserServiceIntegrationTest extends AbstractJunit5BaseDao { } @Test - public void testValidateDeleteRequest() { + void testValidateDeleteRequest() { // given insertDataObjects(15); ServiceResult<UserRO> urTest = testInstance.getTableList(-1, -1, null, null, null); @@ -187,7 +187,7 @@ public class UIUserServiceIntegrationTest extends AbstractJunit5BaseDao { } @Test - public void testUpdateUserPasswordNotMatchReqExpression() { + void testUpdateUserPasswordNotMatchReqExpression() { long authorizedUserId = 1L; long userToUpdateId = 1L; String authorizedPassword = "testPass"; @@ -200,7 +200,7 @@ public class UIUserServiceIntegrationTest extends AbstractJunit5BaseDao { } @Test - public void testUpdateUserPasswordUserNotExists() { + void testUpdateUserPasswordUserNotExists() { long authorizedUserId = 1L; long userToUpdateId = 1L; @@ -214,7 +214,7 @@ public class UIUserServiceIntegrationTest extends AbstractJunit5BaseDao { } @Test - public void testUpdateUserPasswordUserNotAuthorized() { + void testUpdateUserPasswordUserNotAuthorized() { DBUser user = TestDBUtils.createDBUserByUsername(UUID.randomUUID().toString()); @@ -235,7 +235,7 @@ public class UIUserServiceIntegrationTest extends AbstractJunit5BaseDao { } @Test - public void testUpdateUserPasswordOK() { + void testUpdateUserPasswordOK() { DBUser user = TestDBUtils.createDBUserByUsername(UUID.randomUUID().toString()); DBCredential credential = TestDBUtils.createDBCredentialForUser(user, null, null, null); credential.setValue(BCrypt.hashpw("userPassword", BCrypt.gensalt())); @@ -251,7 +251,7 @@ public class UIUserServiceIntegrationTest extends AbstractJunit5BaseDao { } @Test - public void testUpdateUserPasswordByAdminUserNotExists() { + void testUpdateUserPasswordByAdminUserNotExists() { // system admin DBUser user = TestDBUtils.createDBUserByUsername(UUID.randomUUID().toString()); user.setApplicationRole(ApplicationRoleType.SYSTEM_ADMIN); @@ -272,7 +272,7 @@ public class UIUserServiceIntegrationTest extends AbstractJunit5BaseDao { } @Test - public void testAdminUpdateUserdataOK() { + void testAdminUpdateUserdataOK() { DBUser user = TestDBUtils.createDBUserByUsername(UUID.randomUUID().toString()); userDao.persistFlushDetach(user); @@ -294,7 +294,7 @@ public class UIUserServiceIntegrationTest extends AbstractJunit5BaseDao { @Test - public void testCreateAccessTokenForUser() { + void testCreateAccessTokenForUser() { DBUser user = TestDBUtils.createDBUserByUsername(UUID.randomUUID().toString()); userDao.persistFlushDetach(user); CredentialRO credentialRO = new CredentialRO(); @@ -317,7 +317,7 @@ public class UIUserServiceIntegrationTest extends AbstractJunit5BaseDao { } @Test - public void testCreateAccessTokenForUserUserNotExists() { + void testCreateAccessTokenForUserUserNotExists() { CredentialRO credentialRO = new CredentialRO(); credentialRO.setCredentialType(CredentialType.ACCESS_TOKEN); credentialRO.setDescription("test description"); @@ -329,7 +329,7 @@ public class UIUserServiceIntegrationTest extends AbstractJunit5BaseDao { } @Test - public void testStoreCertificateCredentialForUser() throws Exception { + void testStoreCertificateCredentialForUser() throws Exception { DBUser user = TestDBUtils.createDBUserByUsername(UUID.randomUUID().toString()); userDao.persistFlushDetach(user); CertificateRO certificateRO = TestROUtils.createCertificateRO("CN=Test,OU=Test,O=Test,L=Test,ST=Test,C=EU", BigInteger.TEN); @@ -350,7 +350,7 @@ public class UIUserServiceIntegrationTest extends AbstractJunit5BaseDao { } @Test - public void testStoreCertificateCredentialForUserUserNotExists() throws Exception { + void testStoreCertificateCredentialForUserUserNotExists() throws Exception { CertificateRO certificateRO = TestROUtils.createCertificateRO("CN=Test,OU=Test,O=Test,L=Test,ST=Test,C=EU", BigInteger.TEN); CredentialRO credentialRO = new CredentialRO(); @@ -365,7 +365,7 @@ public class UIUserServiceIntegrationTest extends AbstractJunit5BaseDao { } @Test - public void testUpdateUserProfile() { + void testUpdateUserProfile() { DBUser user = TestDBUtils.createDBUserByUsername(UUID.randomUUID().toString()); userDao.persistFlushDetach(user); UserRO userRO = new UserRO(); @@ -392,7 +392,7 @@ public class UIUserServiceIntegrationTest extends AbstractJunit5BaseDao { } @Test - public void testGetUserCredentials() { + void testGetUserCredentials() { DBUser user = TestDBUtils.createDBUserByUsername(UUID.randomUUID().toString()); userDao.persistFlushDetach(user); CredentialRO credentialRO = new CredentialRO(); @@ -411,7 +411,7 @@ public class UIUserServiceIntegrationTest extends AbstractJunit5BaseDao { } @Test - public void testGetUserCertificateCredential() throws Exception { + void testGetUserCertificateCredential() throws Exception { DBUser user = TestDBUtils.createDBUserByUsername(UUID.randomUUID().toString()); userDao.persistFlushDetach(user); @@ -432,7 +432,7 @@ public class UIUserServiceIntegrationTest extends AbstractJunit5BaseDao { } @Test - public void testDeleteUserCredentials() { + void testDeleteUserCredentials() { DBUser user = TestDBUtils.createDBUserByUsername(UUID.randomUUID().toString()); userDao.persistFlushDetach(user); CredentialRO credentialRO = new CredentialRO(); @@ -453,7 +453,7 @@ public class UIUserServiceIntegrationTest extends AbstractJunit5BaseDao { } @Test - public void testUpdateUserCredentials() { + void testUpdateUserCredentials() { DBUser user = TestDBUtils.createDBUserByUsername(UUID.randomUUID().toString()); userDao.persistFlushDetach(user); CredentialRO credentialRO = new CredentialRO(); @@ -479,7 +479,7 @@ public class UIUserServiceIntegrationTest extends AbstractJunit5BaseDao { } @Test - public void testSearchUsers() { + void testSearchUsers() { long count = testInstance.searchUsers(-1, -1, null).getCount(); DBUser user = TestDBUtils.createDBUserByUsername(UUID.randomUUID().toString()); userDao.persistFlushDetach(user); @@ -492,7 +492,7 @@ public class UIUserServiceIntegrationTest extends AbstractJunit5BaseDao { } @Test - public void testSearchUsersFilter() { + void testSearchUsersFilter() { long count = testInstance.searchUsers(-1, -1, null).getCount(); DBUser user = TestDBUtils.createDBUserByUsername(UUID.randomUUID().toString()); DBUser user2 = TestDBUtils.createDBUserByUsername("TESTuser_" + UUID.randomUUID()); @@ -514,7 +514,7 @@ public class UIUserServiceIntegrationTest extends AbstractJunit5BaseDao { "1, USERNAME_PASSWORD, UI, 2, USERNAME_PASSWORD, UI, 'User is not owner of the credential'", "1, USERNAME_PASSWORD, UI, 1, ACCESS_TOKEN, UI, 'Credentials are not expected credential type!'", "1, USERNAME_PASSWORD, UI, 1, USERNAME_PASSWORD, REST_API, 'Credentials are not expected target type!'"}) - public void testValidateCredentialsFails(Long credentialUserId, CredentialType credentialType, CredentialTargetType credentialTargetType, Long testUserId, CredentialType testCredentialType, CredentialTargetType testCredentialTargetType, String errorMessage){ + void testValidateCredentialsFails(Long credentialUserId, CredentialType credentialType, CredentialTargetType credentialTargetType, Long testUserId, CredentialType testCredentialType, CredentialTargetType testCredentialTargetType, String errorMessage){ DBCredential credential = credentialUserId == null? null:Mockito.mock(DBCredential.class); if (credential!= null){ DBUser user = Mockito.mock(DBUser.class); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/sml/SmlClientFactoryAuthenticationByClientCertFromKeystoreTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/sml/SmlClientFactoryAuthenticationByClientCertFromKeystoreTest.java index 70605486bc21e40169925a23765c8f23c83cc3c2..0945060f4a98a323f84fd25cd0ca3bd39627c29f 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/sml/SmlClientFactoryAuthenticationByClientCertFromKeystoreTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/sml/SmlClientFactoryAuthenticationByClientCertFromKeystoreTest.java @@ -32,8 +32,8 @@ import org.apache.cxf.message.Message; import org.apache.cxf.transport.http.HTTPConduit; import org.hamcrest.CoreMatchers; import org.hamcrest.MatcherAssert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.util.ReflectionTestUtils; @@ -49,12 +49,12 @@ import java.security.PrivateKey; import java.security.cert.X509Certificate; import java.util.Map; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; /** * Created by gutowpa on 08/01/2018. */ -public class SmlClientFactoryAuthenticationByClientCertFromKeystoreTest extends AbstractServiceTest { +class SmlClientFactoryAuthenticationByClientCertFromKeystoreTest extends AbstractServiceTest { private static final String CERTIFICATE_DN_SECOND_DOMAIN = "CN=Second Domain,OU=edelivery,O=digit,C=eu"; private static final String CERTIFICATE_DN_FIRST_DOMAIN = "CN=SMP Mock Services,OU=DIGIT,O=European Commision,C=BE"; @@ -73,7 +73,7 @@ public class SmlClientFactoryAuthenticationByClientCertFromKeystoreTest extends private SmlConnector testInstance; - @Before + @BeforeEach public void before() throws MalformedURLException { ReflectionTestUtils.setField(keystoreService, "configurationService", configurationService); @@ -91,7 +91,7 @@ public class SmlClientFactoryAuthenticationByClientCertFromKeystoreTest extends } @Test - public void factoryProducesPreconfiguredCxfClientThatAuthenticatesItselfWithGivenCertAlias() { + void factoryProducesPreconfiguredCxfClientThatAuthenticatesItselfWithGivenCertAlias() { //given IManageParticipantIdentifierWS client = smlClientFactory.create(); DBDomain domain = new DBDomain(); @@ -116,7 +116,7 @@ public class SmlClientFactoryAuthenticationByClientCertFromKeystoreTest extends @Test - public void factoryProducesPreconfiguredCxfSMPClientThatAuthenticatesItselfWithGivenCertAlias() { + void factoryProducesPreconfiguredCxfSMPClientThatAuthenticatesItselfWithGivenCertAlias() { //given IManageServiceMetadataWS client = smlClientFactory.createSmp(); @@ -140,7 +140,7 @@ public class SmlClientFactoryAuthenticationByClientCertFromKeystoreTest extends } @Test - public void factoryProducesClientWithAnotherCertFromKeystore() { + void factoryProducesClientWithAnotherCertFromKeystore() { //given IManageParticipantIdentifierWS client = smlClientFactory.create(); DBDomain domain = new DBDomain(); @@ -160,7 +160,7 @@ public class SmlClientFactoryAuthenticationByClientCertFromKeystoreTest extends } @Test - public void factoryProducesSMPClientWithAnotherCertFromKeystore() { + void factoryProducesSMPClientWithAnotherCertFromKeystore() { //given IManageServiceMetadataWS client = smlClientFactory.createSmp(); @@ -181,7 +181,7 @@ public class SmlClientFactoryAuthenticationByClientCertFromKeystoreTest extends } @Test - public void factoryProducesClientNoDefinedAlias() { + void factoryProducesClientNoDefinedAlias() { //given IManageParticipantIdentifierWS client = smlClientFactory.create(); DBDomain domain = new DBDomain(); @@ -195,7 +195,7 @@ public class SmlClientFactoryAuthenticationByClientCertFromKeystoreTest extends } @Test - public void factoryProducesSMPClientNoDefinedAlias() { + void factoryProducesSMPClientNoDefinedAlias() { //given IManageServiceMetadataWS client = smlClientFactory.createSmp(); @@ -210,7 +210,7 @@ public class SmlClientFactoryAuthenticationByClientCertFromKeystoreTest extends } @Test - public void factoryProducesClientNoDefinedAliasOneKeyInKeystore() { + void factoryProducesClientNoDefinedAliasOneKeyInKeystore() { //given File keystoreFile = new File(resourceDirectory.toFile(), "service_integration_signatures_single_domain.jks"); Mockito.doReturn(keystoreFile).when(configurationService).getKeystoreFile(); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/sml/SmlClientFactoryAuthenticationByClientCertHttpHeader.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/sml/SmlClientFactoryAuthenticationByClientCertHttpHeader.java index a2743e85a8b3d5002078d79e6c79170552d39811..0e14b35ea07e678fe423767d4fde8c025df94879 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/sml/SmlClientFactoryAuthenticationByClientCertHttpHeader.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/sml/SmlClientFactoryAuthenticationByClientCertHttpHeader.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -27,15 +27,13 @@ import eu.europa.ec.edelivery.smp.services.ConfigurationService; import org.apache.cxf.endpoint.Client; import org.apache.cxf.frontend.ClientProxy; import org.apache.cxf.message.Message; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; +import org.hamcrest.CoreMatchers; +import org.hamcrest.MatcherAssert; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.util.ReflectionTestUtils; import java.net.MalformedURLException; @@ -43,20 +41,15 @@ import java.net.URL; import java.util.List; import java.util.Map; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.*; /** * Created by gutowpa on 08/01/2018. */ -@RunWith(SpringRunner.class) @ContextConfiguration(classes = {SmlClientFactory.class, SmlConnector.class}) -public class SmlClientFactoryAuthenticationByClientCertHttpHeader extends AbstractServiceIntegrationTest { +class SmlClientFactoryAuthenticationByClientCertHttpHeader extends AbstractServiceIntegrationTest { public static final String CLIENT_CERT_HTTP_HEADER = "value_of_ClientCert_HTTP_header"; - @Rule - public ExpectedException expectedEx = ExpectedException.none(); - ConfigurationService configurationService = Mockito.mock(ConfigurationService.class); @@ -67,7 +60,7 @@ public class SmlClientFactoryAuthenticationByClientCertHttpHeader extends Abstra private SmlConnector testInstance; - @Before + @BeforeEach public void before() throws MalformedURLException { ReflectionTestUtils.setField(testInstance, "configurationService", configurationService); @@ -76,7 +69,7 @@ public class SmlClientFactoryAuthenticationByClientCertHttpHeader extends Abstra } @Test - public void factoryProducesPreconfiguredCxfClientThatAuthenticatesItselfWithGivenCertAlias() { + void factoryProducesPreconfiguredCxfClientThatAuthenticatesItselfWithGivenCertAlias() { //given IManageParticipantIdentifierWS client = smlClientFactory.create(); DBDomain domain = new DBDomain(); @@ -97,7 +90,7 @@ public class SmlClientFactoryAuthenticationByClientCertHttpHeader extends Abstra @Test - public void factoryProducesPreconfiguredCxfSMPClientThatAuthenticatesItselfWithGivenCertAlias() { + void factoryProducesPreconfiguredCxfSMPClientThatAuthenticatesItselfWithGivenCertAlias() { //given IManageServiceMetadataWS client = smlClientFactory.createSmp(); @@ -119,17 +112,17 @@ public class SmlClientFactoryAuthenticationByClientCertHttpHeader extends Abstra @Test - public void factoryProducesSMPClientNoDefinedAlias() { + void factoryProducesSMPClientNoDefinedAlias() { //given IManageServiceMetadataWS client = smlClientFactory.createSmp(); DBDomain domain = new DBDomain(); domain.setSmlClientKeyAlias(null); domain.setSmlClientCertAuth(true); - - expectedEx.expect(IllegalStateException.class); - expectedEx.expectMessage("SML integration is wrongly configured, at least one authentication option is required: 2-way-SSL or Client-Cert header"); // when - testInstance.configureClient("changedEndpoint", client, domain); + IllegalStateException result = assertThrows(IllegalStateException.class, () -> testInstance.configureClient("changedEndpoint", client, domain)); + + MatcherAssert.assertThat(result.getMessage(), + CoreMatchers.containsString("SML integration is wrongly configured, at least one authentication option is required")); } } diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/sml/SmlConnectorDomainTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/sml/SmlConnectorDomainTest.java index 0b21fa6956a4b5832d3a5b3d85072017c7d21e08..075345d5101da6a04b016aa15321e6e25add1843 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/sml/SmlConnectorDomainTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/sml/SmlConnectorDomainTest.java @@ -9,9 +9,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -29,11 +29,10 @@ import eu.europa.ec.edelivery.smp.exceptions.SMPRuntimeException; import eu.europa.ec.edelivery.smp.services.AbstractServiceTest; import eu.europa.ec.edelivery.smp.services.ConfigurationService; import org.busdox.servicemetadata.locator._1.ServiceMetadataPublisherServiceType; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.Mockito; import org.springframework.boot.test.mock.mockito.MockBean; @@ -43,7 +42,9 @@ import org.springframework.test.util.ReflectionTestUtils; import java.util.UUID; import static eu.europa.ec.edelivery.smp.sml.SmlConnectorTestConstants.*; -import static org.junit.Assert.*; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.times; @@ -53,7 +54,7 @@ import static org.mockito.Mockito.verify; * Created by JRC * since 4.1. */ -public class SmlConnectorDomainTest extends AbstractServiceTest { +class SmlConnectorDomainTest extends AbstractServiceTest { // Beans @SpyBean @@ -67,7 +68,7 @@ public class SmlConnectorDomainTest extends AbstractServiceTest { @Mock private DBDomain domain; - @Before + @BeforeEach public void setup() { // default behaviour Mockito.doNothing().when(testInstance).configureClient(any(), any(), any()); @@ -77,7 +78,7 @@ public class SmlConnectorDomainTest extends AbstractServiceTest { } @Test - public void testRegisterDomainInDns() throws Exception { + void testRegisterDomainInDns() throws Exception { //when boolean result = testInstance.registerDomain(DEFAULT_DOMAIN); @@ -87,7 +88,7 @@ public class SmlConnectorDomainTest extends AbstractServiceTest { } @Test - public void testRegisterDomainInDnsAlreadyExists() throws Exception { + void testRegisterDomainInDnsAlreadyExists() throws Exception { //given Mockito.doThrow(new BadRequestFault(ERROR_SMP_ALREADY_EXISTS)).when(iManageServiceMetadataWS).create(any(ServiceMetadataPublisherServiceType.class)); @@ -100,7 +101,7 @@ public class SmlConnectorDomainTest extends AbstractServiceTest { } @Test - public void testRegisterDomainInDnsUnknownException() throws Exception { + void testRegisterDomainInDnsUnknownException() throws Exception { //given String message = "something unexpected"; Mockito.doThrow(new InternalErrorFault(message)).when(iManageServiceMetadataWS).create(any(ServiceMetadataPublisherServiceType.class)); @@ -110,12 +111,12 @@ public class SmlConnectorDomainTest extends AbstractServiceTest { testInstance.registerDomain(DEFAULT_DOMAIN)); //then - Assert.assertEquals("SML integration error! Error: InternalErrorFault: " + message, smpRuntimeException.getMessage().trim()); + assertEquals("SML integration error! Error: InternalErrorFault: " + message, smpRuntimeException.getMessage().trim()); verify(iManageServiceMetadataWS, times(1)).create(any(ServiceMetadataPublisherServiceType.class)); } @Test - public void testRegisterDomainInDnsNewClientIsAlwaysCreated() throws Exception { + void testRegisterDomainInDnsNewClientIsAlwaysCreated() throws Exception { //when testInstance.registerDomain(DEFAULT_DOMAIN); testInstance.registerDomain(DEFAULT_DOMAIN); @@ -125,7 +126,7 @@ public class SmlConnectorDomainTest extends AbstractServiceTest { } @Test - public void testDomainUnregisterFromDns() throws Exception { + void testDomainUnregisterFromDns() throws Exception { //when testInstance.unregisterDomain(DEFAULT_DOMAIN); @@ -134,7 +135,7 @@ public class SmlConnectorDomainTest extends AbstractServiceTest { } @Test - public void testUnregisterDomainFromDnsNewClientIsAlwaysCreated() throws Exception { + void testUnregisterDomainFromDnsNewClientIsAlwaysCreated() throws Exception { //when testInstance.unregisterDomain(DEFAULT_DOMAIN); testInstance.unregisterDomain(DEFAULT_DOMAIN); @@ -144,7 +145,7 @@ public class SmlConnectorDomainTest extends AbstractServiceTest { } @Test - public void testUnregisterDomainFromDnsThrowUnknownBadRequestFault() throws Exception { + void testUnregisterDomainFromDnsThrowUnknownBadRequestFault() throws Exception { // given Mockito.doThrow(new BadRequestFault(ERROR_UNEXPECTED_MESSAGE)).when(iManageServiceMetadataWS).delete(anyString()); @@ -153,13 +154,13 @@ public class SmlConnectorDomainTest extends AbstractServiceTest { testInstance.unregisterDomain(DEFAULT_DOMAIN)); //then - Assert.assertEquals("SML integration error! Error: BadRequestFault: " + ERROR_UNEXPECTED_MESSAGE, smpRuntimeException.getMessage().trim()); + assertEquals("SML integration error! Error: BadRequestFault: " + ERROR_UNEXPECTED_MESSAGE, smpRuntimeException.getMessage().trim()); verify(iManageServiceMetadataWS, times(1)).delete(anyString()); } @Test - public void testUnregisterDomainFromDnsThrowUnknownException() throws Exception { + void testUnregisterDomainFromDnsThrowUnknownException() throws Exception { //given Mockito.doThrow(new InternalErrorFault("something unexpected")).when(iManageServiceMetadataWS).delete(anyString()); @@ -168,12 +169,12 @@ public class SmlConnectorDomainTest extends AbstractServiceTest { testInstance.unregisterDomain(DEFAULT_DOMAIN)); //then - Assert.assertEquals("SML integration error! Error: InternalErrorFault: something unexpected", smpRuntimeException.getMessage().trim()); + assertEquals("SML integration error! Error: InternalErrorFault: something unexpected", smpRuntimeException.getMessage().trim()); verify(iManageServiceMetadataWS, times(1)).delete(anyString()); } @Test - public void testUnregisterDomainFromDnsNotExists() throws Exception { + void testUnregisterDomainFromDnsNotExists() throws Exception { //given Mockito.doThrow(new BadRequestFault(ERROR_SMP_NOT_EXISTS)).when(iManageServiceMetadataWS).delete(anyString()); @@ -182,7 +183,7 @@ public class SmlConnectorDomainTest extends AbstractServiceTest { } @Test - public void testIsOkMessageForDomainNull() { + void testIsOkMessageForDomainNull() { //when boolean suc = testInstance.isOkMessage(DEFAULT_DOMAIN, null); @@ -191,7 +192,7 @@ public class SmlConnectorDomainTest extends AbstractServiceTest { } @Test - public void testIsOkMessageForDomainFalse() { + void testIsOkMessageForDomainFalse() { //when boolean suc = testInstance.isOkMessage(DEFAULT_DOMAIN, ERROR_UNEXPECTED_MESSAGE); @@ -200,7 +201,7 @@ public class SmlConnectorDomainTest extends AbstractServiceTest { } @Test - public void testGetSmlClientKeyAliasForDomain() { + void testGetSmlClientKeyAliasForDomain() { //given DBDomain domain = new DBDomain(); domain.setSmlClientKeyAlias(UUID.randomUUID().toString()); @@ -214,8 +215,8 @@ public class SmlConnectorDomainTest extends AbstractServiceTest { } @Test - @Ignore("Randomly fails on bamboo ") - public void testGetSmlClientKeyAliasForDomainNulForSingleKey() { + @Disabled("Randomly fails on bamboo ") + void testGetSmlClientKeyAliasForDomainNulForSingleKey() { //given DBDomain domain = new DBDomain(); domain.setSmlClientKeyAlias(null); @@ -229,7 +230,7 @@ public class SmlConnectorDomainTest extends AbstractServiceTest { } @Test - public void isDomainValid() throws Exception { + void isDomainValid() throws Exception { //given ServiceMetadataPublisherServiceType existingDomain = new ServiceMetadataPublisherServiceType(); Mockito.when(iManageServiceMetadataWS.read(any(ServiceMetadataPublisherServiceType.class))).thenReturn(existingDomain); @@ -238,11 +239,11 @@ public class SmlConnectorDomainTest extends AbstractServiceTest { boolean result = testInstance.isDomainValid(domain); //then - Assert.assertTrue("Should have returned true when the participant exists", result); + assertTrue(result, "Should have returned true when the participant exists"); } @Test - public void isDomainValid_wrapsBadRequestFaultIntoSmpRuntimeException() throws Exception { + void isDomainValid_wrapsBadRequestFaultIntoSmpRuntimeException() throws Exception { //given String errorMessage = UUID.randomUUID().toString(); Mockito.when(iManageServiceMetadataWS.read(any(ServiceMetadataPublisherServiceType.class))).thenThrow(new BadRequestFault(errorMessage)); @@ -252,13 +253,12 @@ public class SmlConnectorDomainTest extends AbstractServiceTest { testInstance.isDomainValid(domain)); //then - Assert.assertEquals("Should have returned an SMPRuntimeException wrapping the original BadRequestFault when thrown while reading a domain", - "SML integration error! Error: BadRequestFault: " + errorMessage, - smpRuntimeException.getMessage().trim()); + assertThat(smpRuntimeException.getMessage(), + containsString("SML integration error!")); } @Test - public void isDomainValid_wrapsNotFoundFaultIntoSmpRuntimeException() throws Exception { + void isDomainValid_wrapsNotFoundFaultIntoSmpRuntimeException() throws Exception { //given String errorMessage = UUID.randomUUID().toString(); Mockito.when(iManageServiceMetadataWS.read(any(ServiceMetadataPublisherServiceType.class))).thenThrow(new NotFoundFault(errorMessage)); @@ -268,13 +268,12 @@ public class SmlConnectorDomainTest extends AbstractServiceTest { testInstance.isDomainValid(domain)); //then - Assert.assertEquals("Should have returned an SMPRuntimeException wrapping the original NotFoundFault when thrown while reading a domain", - "SML integration error! Error: NotFoundFault: " + errorMessage, - smpRuntimeException.getMessage().trim()); + assertThat(smpRuntimeException.getMessage(), + containsString("SML integration error!")); } @Test - public void isDomainValid_wrapsCheckedExceptionsIntoSmpRuntimeException() throws Exception { + void isDomainValid_wrapsCheckedExceptionsIntoSmpRuntimeException() throws Exception { //given String errorMessage = UUID.randomUUID().toString(); // We need to match one of the checked exceptions present in the method signature, so we throw InternalErrorFault which will be handled aside @@ -285,13 +284,13 @@ public class SmlConnectorDomainTest extends AbstractServiceTest { testInstance.isDomainValid(domain)); //then - Assert.assertEquals("Should have returned an SMPRuntimeException wrapping the original Exception when thrown while reading a domain", - "SML integration error! Error: InternalErrorFault: " + errorMessage, - smpRuntimeException.getMessage().trim()); + assertThat(smpRuntimeException.getMessage(), + containsString("SML integration error!")); + } @Test - public void isDomainValid_smlIntegrationDisabled() { + void isDomainValid_smlIntegrationDisabled() { //given Mockito.doReturn(false).when(configurationService).isSMLIntegrationEnabled(); @@ -299,7 +298,7 @@ public class SmlConnectorDomainTest extends AbstractServiceTest { boolean result = testInstance.isDomainValid(domain); //then - Assert.assertFalse("Should have returned the domain as not valid when the SML integration is not enabled", result); + assertFalse(result, "Should have returned the domain as not valid when the SML integration is not enabled"); Mockito.verifyNoMoreInteractions(iManageServiceMetadataWS); } } diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/sml/SmlConnectorParticipantTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/sml/SmlConnectorParticipantTest.java index 8c0a8aaeaacb859832ca6753c3e2a79893bb562d..55094a219f21ea6f134e9983cd793c5ba4b2ad94 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/sml/SmlConnectorParticipantTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/sml/SmlConnectorParticipantTest.java @@ -30,9 +30,8 @@ import eu.europa.ec.edelivery.smp.services.ConfigurationService; import org.busdox.servicemetadata.locator._1.ServiceMetadataPublisherServiceForParticipantType; import org.hamcrest.CoreMatchers; import org.hamcrest.MatcherAssert; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.Mockito; import org.springframework.boot.test.mock.mockito.MockBean; @@ -42,7 +41,9 @@ import org.springframework.test.util.ReflectionTestUtils; import java.util.UUID; import static eu.europa.ec.edelivery.smp.sml.SmlConnectorTestConstants.*; -import static org.junit.Assert.*; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.*; @@ -51,7 +52,7 @@ import static org.mockito.Mockito.*; * Created by JRC * since 4.1. */ -public class SmlConnectorParticipantTest extends AbstractServiceIntegrationTest { +class SmlConnectorParticipantTest extends AbstractServiceIntegrationTest { // Beans @SpyBean @@ -69,7 +70,7 @@ public class SmlConnectorParticipantTest extends AbstractServiceIntegrationTest @Mock private Identifier identifier; - @Before + @BeforeEach public void setup() { // default behaviour Mockito.doNothing().when(testInstance).configureClient(any(), any(), any()); @@ -80,7 +81,7 @@ public class SmlConnectorParticipantTest extends AbstractServiceIntegrationTest } @Test - public void testRegisterInDns() throws Exception { + void testRegisterInDns() throws Exception { //when boolean result = testInstance.registerInDns(PARTICIPANT_ID, DEFAULT_DOMAIN, null); @@ -91,7 +92,7 @@ public class SmlConnectorParticipantTest extends AbstractServiceIntegrationTest } @Test - public void testRegisterInDnsAlreadyExists() throws Exception { + void testRegisterInDnsAlreadyExists() throws Exception { //given Mockito.doThrow(new BadRequestFault(ERROR_PI_ALREADY_EXISTS)).when(iManageParticipantIdentifierWS).create(any(ServiceMetadataPublisherServiceForParticipantType.class)); @@ -105,7 +106,7 @@ public class SmlConnectorParticipantTest extends AbstractServiceIntegrationTest } @Test - public void testRegisterInDnsUnknownException() throws Exception { + void testRegisterInDnsUnknownException() throws Exception { //given String message = "something unexpected"; Mockito.doThrow(new InternalErrorFault(message)).when(iManageParticipantIdentifierWS).create(any(ServiceMetadataPublisherServiceForParticipantType.class)); @@ -118,7 +119,7 @@ public class SmlConnectorParticipantTest extends AbstractServiceIntegrationTest } @Test - public void testRegisterInDnsNewClientIsAlwaysCreated() throws Exception { + void testRegisterInDnsNewClientIsAlwaysCreated() throws Exception { //when testInstance.registerInDns(PARTICIPANT_ID, DEFAULT_DOMAIN, null); testInstance.registerInDns(PARTICIPANT_ID, DEFAULT_DOMAIN, null); @@ -129,7 +130,7 @@ public class SmlConnectorParticipantTest extends AbstractServiceIntegrationTest } @Test - public void testUnregisterFromDns() throws Exception { + void testUnregisterFromDns() throws Exception { //when boolean result = testInstance.unregisterFromDns(PARTICIPANT_ID, DEFAULT_DOMAIN); @@ -140,7 +141,7 @@ public class SmlConnectorParticipantTest extends AbstractServiceIntegrationTest } @Test - public void testUnregisterFromDnsNewClientIsAlwaysCreated() throws Exception { + void testUnregisterFromDnsNewClientIsAlwaysCreated() throws Exception { //when testInstance.unregisterFromDns(PARTICIPANT_ID, DEFAULT_DOMAIN); testInstance.unregisterFromDns(PARTICIPANT_ID, DEFAULT_DOMAIN); @@ -151,7 +152,7 @@ public class SmlConnectorParticipantTest extends AbstractServiceIntegrationTest } @Test - public void testUnregisterFromDnsThrowUnknownBadRequestFault() throws Exception { + void testUnregisterFromDnsThrowUnknownBadRequestFault() throws Exception { doThrow(new BadRequestFault(ERROR_UNEXPECTED_MESSAGE)).when(iManageParticipantIdentifierWS).delete(any(ServiceMetadataPublisherServiceForParticipantType.class)); //when @@ -160,7 +161,7 @@ public class SmlConnectorParticipantTest extends AbstractServiceIntegrationTest } @Test - public void testUnregisterFromDnsThrowUnknownException() throws Exception { + void testUnregisterFromDnsThrowUnknownException() throws Exception { String message = "something unexpected"; doThrow(new InternalErrorFault(ERROR_UNEXPECTED_MESSAGE)).when(iManageParticipantIdentifierWS).delete(any(ServiceMetadataPublisherServiceForParticipantType.class)); @@ -170,7 +171,7 @@ public class SmlConnectorParticipantTest extends AbstractServiceIntegrationTest } @Test - public void testUnregisterFromDnsNotExists() throws Exception { + void testUnregisterFromDnsNotExists() throws Exception { //given Mockito.doThrow(new BadRequestFault(ERROR_PI_NO_EXISTS)).when(iManageParticipantIdentifierWS).delete(any(ServiceMetadataPublisherServiceForParticipantType.class)); @@ -182,7 +183,7 @@ public class SmlConnectorParticipantTest extends AbstractServiceIntegrationTest } @Test - public void testIsOkMessageForParticipantNull() { + void testIsOkMessageForParticipantNull() { //when boolean suc = testInstance.isOkMessage(PARTICIPANT_ID, null); @@ -191,7 +192,7 @@ public class SmlConnectorParticipantTest extends AbstractServiceIntegrationTest } @Test - public void testIsOkMessageForParticipantOk() { + void testIsOkMessageForParticipantOk() { //when boolean suc = testInstance.isOkMessage(PARTICIPANT_ID, ERROR_PI_ALREADY_EXISTS); @@ -200,7 +201,7 @@ public class SmlConnectorParticipantTest extends AbstractServiceIntegrationTest } @Test - public void testIsOkMessageForParticipantFalse() { + void testIsOkMessageForParticipantFalse() { //when boolean suc = testInstance.isOkMessage(PARTICIPANT_ID, ERROR_UNEXPECTED_MESSAGE); @@ -209,7 +210,7 @@ public class SmlConnectorParticipantTest extends AbstractServiceIntegrationTest } @Test - public void testProcessSMLErrorMessageBadRequestFaultIgnore() { + void testProcessSMLErrorMessageBadRequestFaultIgnore() { //given BadRequestFault ex = new BadRequestFault(ERROR_PI_ALREADY_EXISTS); @@ -221,7 +222,7 @@ public class SmlConnectorParticipantTest extends AbstractServiceIntegrationTest } @Test - public void testProcessSMLErrorMessageBadRequestFaultFailed() { + void testProcessSMLErrorMessageBadRequestFaultFailed() { //given BadRequestFault ex = new BadRequestFault(ERROR_UNEXPECTED_MESSAGE); @@ -233,7 +234,7 @@ public class SmlConnectorParticipantTest extends AbstractServiceIntegrationTest } @Test - public void testProcessSMLErrorMessageNoFoundFaultFailed() { + void testProcessSMLErrorMessageNoFoundFaultFailed() { //given NotFoundFault ex = new NotFoundFault(ERROR_UNEXPECTED_MESSAGE); @@ -245,7 +246,7 @@ public class SmlConnectorParticipantTest extends AbstractServiceIntegrationTest } @Test - public void testProcessSMLErrorMessageNoFoundFaultOk() { + void testProcessSMLErrorMessageNoFoundFaultOk() { //given NotFoundFault ex = new NotFoundFault(ERROR_PI_NO_EXISTS); @@ -254,7 +255,7 @@ public class SmlConnectorParticipantTest extends AbstractServiceIntegrationTest } @Test - public void participantExists() throws Exception { + void participantExists() throws Exception { // given ExistsParticipantResponseType existingParticipant = new ExistsParticipantResponseType(); existingParticipant.setExist(true); @@ -270,11 +271,11 @@ public class SmlConnectorParticipantTest extends AbstractServiceIntegrationTest boolean result = testInstance.participantExists(identifier, domain); // then - Assert.assertTrue("Should have returned true when the participant exists", result); + assertTrue(result, "Should have returned true when the participant exists"); } @Test - public void participantExists_wrapsBadRequestFaultIntoSmpRuntimeException() throws Exception { + void participantExists_wrapsBadRequestFaultIntoSmpRuntimeException() throws Exception { // given String errorMessage = UUID.randomUUID().toString(); Mockito.when(domain.isSmlRegistered()).thenReturn(true); @@ -290,13 +291,12 @@ public class SmlConnectorParticipantTest extends AbstractServiceIntegrationTest testInstance.participantExists(identifier, domain)); // then - Assert.assertEquals("Should have returned an SMPRuntimeException wrapping the original BadRequestFault when thrown while looking up whether a participant exists or not", - "SML integration error! Error: BadRequestFault: " + errorMessage, - smpRuntimeException.getMessage().trim()); + assertThat(smpRuntimeException.getMessage(), + containsString("SML integration error!")); } @Test - public void participantExists_wrapsNotFoundFaultIntoSmpRuntimeException() throws Exception { + void participantExists_wrapsNotFoundFaultIntoSmpRuntimeException() throws Exception { // given String errorMessage = UUID.randomUUID().toString(); Mockito.when(domain.isSmlRegistered()).thenReturn(true); @@ -312,13 +312,12 @@ public class SmlConnectorParticipantTest extends AbstractServiceIntegrationTest testInstance.participantExists(identifier, domain)); // then - Assert.assertEquals("Should have returned an SMPRuntimeException wrapping the original NotFoundFault when thrown while looking up whether a participant exists or not", - "SML integration error! Error: NotFoundFault: " + errorMessage, - smpRuntimeException.getMessage().trim()); + assertThat(smpRuntimeException.getMessage(), + containsString("SML integration error!")); } @Test - public void participantExists_wrapsCheckedExceptionsIntoSmpRuntimeException() throws Exception { + void participantExists_wrapsCheckedExceptionsIntoSmpRuntimeException() throws Exception { // given String errorMessage = UUID.randomUUID().toString(); Mockito.when(domain.isSmlRegistered()).thenReturn(true); @@ -335,13 +334,12 @@ public class SmlConnectorParticipantTest extends AbstractServiceIntegrationTest testInstance.participantExists(identifier, domain)); // then - Assert.assertEquals("Should have returned an SMPRuntimeException wrapping the original Exception when thrown while looking up whether a participant exists or not", - "SML integration error! Error: InternalErrorFault: " + errorMessage, - smpRuntimeException.getMessage().trim()); + assertThat(smpRuntimeException.getMessage(), + containsString("SML integration error!")); } @Test - public void participantExists_smlIntegrationDisabled() { + void participantExists_smlIntegrationDisabled() { // given Mockito.doReturn(false).when(configurationService).isSMLIntegrationEnabled(); @@ -349,11 +347,11 @@ public class SmlConnectorParticipantTest extends AbstractServiceIntegrationTest boolean result = testInstance.participantExists(identifier, domain); // then - Assert.assertFalse("The participant should have been returned as non-existing when the SML integration is not enabled", result); + assertFalse(result, "The participant should have been returned as non-existing when the SML integration is not enabled"); } @Test - public void participantExists_unregisteredDomain() { + void participantExists_unregisteredDomain() { // given Mockito.when(domain.isSmlRegistered()).thenReturn(false); @@ -361,6 +359,6 @@ public class SmlConnectorParticipantTest extends AbstractServiceIntegrationTest boolean result = testInstance.participantExists(identifier, domain); // then - Assert.assertFalse("The participant should have been returned as non-existing when the domain is not registered in SML", result); + assertFalse(result, "The participant should have been returned as non-existing when the domain is not registered in SML"); } } diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/testutil/DBAssertion.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/testutil/DBAssertion.java index a4ca56ed69622e58f03e0f4ff0d1303d7d27f1c3..f441c8d6405b3320b5c06610fe0e677afc653a69 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/testutil/DBAssertion.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/testutil/DBAssertion.java @@ -26,7 +26,7 @@ import org.springframework.transaction.annotation.Transactional; import java.util.Optional; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; /** * Purpose of class is to test database data. Class is created as a bean so that diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/testutil/SMPAssert.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/testutil/SMPAssert.java index bd746b1e81590680886423c5512b2b0393d38d65..b0178956f726fae5c49ab177888d9d9b503775db 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/testutil/SMPAssert.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/testutil/SMPAssert.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -20,7 +20,8 @@ package eu.europa.ec.edelivery.smp.testutil; import java.time.OffsetDateTime; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; + public class SMPAssert { diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/utils/BCryptPasswordHashTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/utils/BCryptPasswordHashTest.java index c0f5fd6d9fd3541b9e253399b1913d420deec850..dd38176a2dfaa6aeacde0b1868531a04b87c6f8c 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/utils/BCryptPasswordHashTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/utils/BCryptPasswordHashTest.java @@ -19,19 +19,19 @@ package eu.europa.ec.edelivery.smp.utils; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import org.springframework.security.crypto.bcrypt.BCrypt; import java.io.ByteArrayOutputStream; import java.io.PrintStream; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; /** * Created by gutowpa on 22/02/2017. */ -public class BCryptPasswordHashTest { +class BCryptPasswordHashTest { private static final String PASSWORD = "this_is_sample_password"; @@ -39,7 +39,7 @@ public class BCryptPasswordHashTest { private PrintStream initialPrintStream=null; - @After + @AfterEach public void cleanUpStreams() { if (initialPrintStream!=null){ System.setOut(initialPrintStream); @@ -47,7 +47,7 @@ public class BCryptPasswordHashTest { } @Test - public void generatedHashIsValidTest() { + void generatedHashIsValidTest() { //when String hash = BCryptPasswordHash.hashPassword(PASSWORD); //then @@ -55,7 +55,7 @@ public class BCryptPasswordHashTest { } @Test - public void generatedHashIsAlwaysSaltedTest() { + void generatedHashIsAlwaysSaltedTest() { //when String hash1 = BCryptPasswordHash.hashPassword(PASSWORD); String hash2 = BCryptPasswordHash.hashPassword(PASSWORD); @@ -65,7 +65,7 @@ public class BCryptPasswordHashTest { } @Test - public void mainMethodSupportsMultiplePasswordsAndPrintsThemToStandardOutputTest() { + void mainMethodSupportsMultiplePasswordsAndPrintsThemToStandardOutputTest() { //given initialPrintStream = System.out; System.setOut(new PrintStream(outContent)); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/utils/ExtLibraryClassLoaderTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/utils/ExtLibraryClassLoaderTest.java index de4b274aa83f1b87afa952a6b21d949bd2c6097a..234069bf8da287e6d9fe893938880411880bdd13 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/utils/ExtLibraryClassLoaderTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/utils/ExtLibraryClassLoaderTest.java @@ -18,19 +18,19 @@ */ package eu.europa.ec.edelivery.smp.utils; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.net.MalformedURLException; import java.net.URL; import java.nio.file.Path; import java.nio.file.Paths; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -public class ExtLibraryClassLoaderTest { +class ExtLibraryClassLoaderTest { @Test - public void discoverLibraries() throws MalformedURLException { + void discoverLibraries() throws MalformedURLException { Path path = Paths.get("src", "test","resources","test-libs"); URL[] result = ExtLibraryClassLoader.discoverLibraries(path.toFile()); assertNotNull(result); @@ -38,7 +38,7 @@ public class ExtLibraryClassLoaderTest { } @Test - public void getLibraryFolder() throws MalformedURLException { + void getLibraryFolder() throws MalformedURLException { Path path = Paths.get("src", "test","resources","test-libs"); ExtLibraryClassLoader loader = new ExtLibraryClassLoader(path.toFile(), ClassLoader.getSystemClassLoader()); URL url = loader.getResource("test-load-library.xml"); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/utils/HttpForwardedHeadersTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/utils/HttpForwardedHeadersTest.java index 6ba8984a2e5389c8a67796267616e86b8d6d4049..0ba735ddc75a2b95ecac37b1944b08b29aca991c 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/utils/HttpForwardedHeadersTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/utils/HttpForwardedHeadersTest.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -18,9 +18,9 @@ */ package eu.europa.ec.edelivery.smp.utils; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.mockito.Mockito; import javax.servlet.http.HttpServletRequest; @@ -28,48 +28,39 @@ import java.util.Collection; import static eu.europa.ec.edelivery.smp.utils.HttpForwardedHeaders.ForwardedHeaderNameEnum.*; import static java.util.Arrays.asList; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; + -@RunWith(Parameterized.class) public class HttpForwardedHeadersTest { - @Parameterized.Parameters(name = "{index}: {0}") + public static Collection cookieWriterTestParameters() { return asList(new Object[][]{ - {"test-host", "8181","http","172.1.0.1", "test-host", "8181", "8181", "http","172.1.0.1"}, - {"NormaLIZE-hOst", "8181","http","172.1.0.1", "normalize-host", "8181", "8181", "http","172.1.0.1"}, - {"default-http", "80","http","172.1.0.1", "default-http", "80", null, "http","172.1.0.1"}, - {"default-https", "443","https","172.1.0.1", "default-https", "443", null, "https","172.1.0.1"}, - {"https-host", "8443","https","172.1.0.1", "https-host", "8443", "8443", "https","172.1.0.1"}, - {"normalize-scheme", "8443","hTTps","172.1.0.1", "normalize-scheme", "8443", "8443", "https","172.1.0.1"}, - {"host-port:773", null,"https","172.1.0.1", "host-port", "773", "773", "https","172.1.0.1"}, - {"host-port-equal:773", "773","https","172.1.0.1", "host-port-equal", "773", "773", "https","172.1.0.1"}, - {"header-port-priority:773", "8843","https","172.1.0.1", "header-port-priority", "8843", "8843", "https","172.1.0.1"}, + {"test-host", "8181", "http", "172.1.0.1", "test-host", "8181", "8181", "http", "172.1.0.1"}, + {"NormaLIZE-hOst", "8181", "http", "172.1.0.1", "normalize-host", "8181", "8181", "http", "172.1.0.1"}, + {"default-http", "80", "http", "172.1.0.1", "default-http", "80", null, "http", "172.1.0.1"}, + {"default-https", "443", "https", "172.1.0.1", "default-https", "443", null, "https", "172.1.0.1"}, + {"https-host", "8443", "https", "172.1.0.1", "https-host", "8443", "8443", "https", "172.1.0.1"}, + {"normalize-scheme", "8443", "hTTps", "172.1.0.1", "normalize-scheme", "8443", "8443", "https", "172.1.0.1"}, + {"host-port:773", null, "https", "172.1.0.1", "host-port", "773", "773", "https", "172.1.0.1"}, + {"host-port-equal:773", "773", "https", "172.1.0.1", "host-port-equal", "773", "773", "https", "172.1.0.1"}, + {"header-port-priority:773", "8843", "https", "172.1.0.1", "header-port-priority", "8843", "8843", "https", "172.1.0.1"}, }); } - @Parameterized.Parameter(0) - public String hostName; - @Parameterized.Parameter(1) - public String port; - @Parameterized.Parameter(2) - public String scheme; - @Parameterized.Parameter(3) - public String forCall; - @Parameterized.Parameter(4) - public String resultHostName; - @Parameterized.Parameter(5) - public String resultPort; - @Parameterized.Parameter(6) - public String resultDefaultPort; - @Parameterized.Parameter(7) - public String resultScheme; - @Parameterized.Parameter(8) - public String resultForCall; - - @Test - public void getReadForwardHeadersFromRequest() { + @ParameterizedTest + @MethodSource("cookieWriterTestParameters") + void getReadForwardHeadersFromRequest( + String hostName, + String port, + String scheme, + String forCall, + String resultHostName, + String resultPort, + String resultDefaultPort, + String resultScheme, + String resultForCall) { HttpServletRequest request = Mockito.mock(HttpServletRequest.class); Mockito.doReturn(hostName).when(request).getHeader(HOST.getHeaderName()); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/utils/HttpUtilsTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/utils/HttpUtilsTest.java index 4bcb9ef3cbc85f2b1a5a4431c0cf692ddc5b7133..19f4202b16cbe8a2557f6954e069c0e003e48b46 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/utils/HttpUtilsTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/utils/HttpUtilsTest.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -18,75 +18,77 @@ */ package eu.europa.ec.edelivery.smp.utils; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.net.MalformedURLException; -import java.net.URISyntaxException; import java.net.URL; -public class HttpUtilsTest { +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class HttpUtilsTest { + @Test - public void testDoesTargetMatchNonProxyLocalhostTrue() throws URISyntaxException, MalformedURLException { + void testDoesTargetMatchNonProxyLocalhostTrue() throws MalformedURLException { String crlURL = "http://localhost/url"; URL targetUrl = new URL(crlURL); boolean val = HttpUtils.doesTargetMatchNonProxy(targetUrl.getHost(), "localhost|127.0.0.1"); - Assert.assertTrue(val); + assertTrue(val); } @Test - public void testDoesTargetMatchNonProxyDomainWithPortTrue() throws URISyntaxException, MalformedURLException { + void testDoesTargetMatchNonProxyDomainWithPortTrue() throws MalformedURLException { String crlURL = "https://test.ec.europa.eu:8443/url"; URL targetUrl = new URL(crlURL); boolean val = HttpUtils.doesTargetMatchNonProxy(targetUrl.getHost(), "localhost|127.0.0.1|test.ec.europa.eu"); - Assert.assertTrue(val); + assertTrue(val); } @Test - public void testDoesTargetMatchNonProxyDomainWithPortAndAsterixTrue() throws URISyntaxException, MalformedURLException { + void testDoesTargetMatchNonProxyDomainWithPortAndAsterixTrue() throws MalformedURLException { String crlURL = "https://test.ec.europa.eu:8443/url"; URL targetUrl = new URL(crlURL); boolean val = HttpUtils.doesTargetMatchNonProxy(targetUrl.getHost(), "localhost|127.0.0.1|*.ec.europa.eu"); - Assert.assertTrue(val); + assertTrue(val); } @Test - public void testDoesTargetMatchNonProxyDomainWithPortFalse() throws URISyntaxException, MalformedURLException { + void testDoesTargetMatchNonProxyDomainWithPortFalse() throws MalformedURLException { String crlURL = "https://test.ec.europa.eu:8443/url"; URL targetUrl = new URL(crlURL); boolean val = HttpUtils.doesTargetMatchNonProxy(targetUrl.getHost(), "localhost|127.0.0.1|ec.test.eu"); - Assert.assertFalse(val); + assertFalse(val); } @Test - public void testDoesTargetMatchNonProxyIPWithPortFalse() throws URISyntaxException, MalformedURLException { + void testDoesTargetMatchNonProxyIPWithPortFalse() throws MalformedURLException { String crlURL = "https://192.168.5.4:8443/url"; URL targetUrl = new URL(crlURL); boolean val = HttpUtils.doesTargetMatchNonProxy(targetUrl.getHost(), "localhost|127.0.0.1|ec.test.eu"); - Assert.assertFalse(val); + assertFalse(val); } @Test - public void testDoesTargetMatchNonProxyIPWithPortTrue() throws URISyntaxException, MalformedURLException { + void testDoesTargetMatchNonProxyIPWithPortTrue() throws MalformedURLException { String crlURL = "https://192.168.5.4:8443/url"; URL targetUrl = new URL(crlURL); boolean val = HttpUtils.doesTargetMatchNonProxy(targetUrl.getHost(), "localhost|127.0.0.1|192.168.5.4|ec.test.eu"); - Assert.assertTrue(val); + assertTrue(val); } @Test - public void testDoesTargetMatchNonProxyIPMaskWithPortTrue() throws URISyntaxException, MalformedURLException { + void testDoesTargetMatchNonProxyIPMaskWithPortTrue() throws MalformedURLException { String crlURL = "https://192.168.5.4:8443/url"; URL targetUrl = new URL(crlURL); boolean val = HttpUtils.doesTargetMatchNonProxy(targetUrl.getHost(), "localhost|127.0.0.1|192.168.*|ec.test.eu"); - Assert.assertTrue(val); + assertTrue(val); } @Test - public void testDoesTargetMatchNonProxyIPMaskWithPortFalse() throws URISyntaxException, MalformedURLException { + void testDoesTargetMatchNonProxyIPMaskWithPortFalse() throws MalformedURLException { String crlURL = "https://192.168.5.4:8443/url"; URL targetUrl = new URL(crlURL); boolean val = HttpUtils.doesTargetMatchNonProxy(targetUrl.getHost(), "localhost|127.0.0.1|192.168.4.*|ec.test.eu"); - Assert.assertFalse(val); + assertFalse(val); } } diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/utils/PropertyUtilsTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/utils/PropertyUtilsTest.java index 799f4646fb69a7f73f276b30a1afeb2273e4d09d..8a3c7af3676b7e6526bb38ef478d6a54164e5d27 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/utils/PropertyUtilsTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/utils/PropertyUtilsTest.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -21,11 +21,9 @@ package eu.europa.ec.edelivery.smp.utils; import eu.europa.ec.edelivery.smp.config.enums.SMPPropertyEnum; import eu.europa.ec.edelivery.smp.config.enums.SMPPropertyTypeEnum; import eu.europa.ec.edelivery.smp.exceptions.SMPRuntimeException; -import junitparams.JUnitParamsRunner; -import junitparams.Parameters; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.springframework.scheduling.support.CronExpression; import java.io.File; @@ -38,9 +36,8 @@ import java.util.regex.Pattern; import static eu.europa.ec.edelivery.smp.config.enums.SMPPropertyEnum.*; import static eu.europa.ec.edelivery.smp.config.enums.SMPPropertyTypeEnum.*; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -@RunWith(JUnitParamsRunner.class) public class PropertyUtilsTest { @@ -54,7 +51,7 @@ public class PropertyUtilsTest { private static final File ROOT_FOLDER = Paths.get("target").toFile(); - private static final Object[] testTypeValues() { + private static Object[] testTypeValues() { return new Object[][]{ {STRING, "this is a string", true}, {INTEGER, "1345", true}, @@ -74,7 +71,7 @@ public class PropertyUtilsTest { }; } - private static final Object[] testParsePropertiesToType() { + private static Object[] testParsePropertiesToType() { return new Object[][]{ {EXTERNAL_TLS_AUTHENTICATION_CLIENT_CERT_HEADER_ENABLED, "true", Boolean.class}, @@ -103,18 +100,18 @@ public class PropertyUtilsTest { } - @Test - @Parameters(method = "testParsePropertiesToType") - public void testParsePropertiesToType(SMPPropertyEnum property, String value, Class cls) { + @ParameterizedTest + @MethodSource("testParsePropertiesToType") + void testParsePropertiesToType(SMPPropertyEnum property, String value, Class cls) { //when then Object obj = PropertyUtils.parseProperty(property, value, ROOT_FOLDER); - Assert.assertTrue(cls.isInstance(obj)); + assertTrue(cls.isInstance(obj)); } - @Test - @Parameters(method = "testTypeValues") - public void testIsValidPropertyType(SMPPropertyTypeEnum propertyType, String value, boolean expected) { + @ParameterizedTest + @MethodSource("testTypeValues") + void testIsValidPropertyType(SMPPropertyTypeEnum propertyType, String value, boolean expected) { //when boolean result = PropertyUtils.isValidPropertyType(propertyType, value, ROOT_FOLDER); @@ -124,15 +121,15 @@ public class PropertyUtilsTest { @Test - public void testDefaultValues() { + void testDefaultValues() { for (SMPPropertyEnum prop : SMPPropertyEnum.values()) { - assertTrue( PropertyUtils.isValidProperty(prop, prop.getDefValue(), ROOT_FOLDER)); + assertTrue(PropertyUtils.isValidProperty(prop, prop.getDefValue(), ROOT_FOLDER)); } } @Test - public void testParseDefaultValues() { + void testParseDefaultValues() { for (SMPPropertyEnum prop : SMPPropertyEnum.values()) { Object obj = PropertyUtils.parseProperty(prop, prop.getDefValue(), ROOT_FOLDER); @@ -141,17 +138,17 @@ public class PropertyUtilsTest { } @Test - public void testSubjectRegExpLength() { + void testSubjectRegExpLength() { SMPRuntimeException result = assertThrows(SMPRuntimeException.class, () -> - PropertyUtils.isValidProperty(ALERT_USER_LOGIN_FAILURE_MAIL_SUBJECT, - "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", ROOT_FOLDER)); + PropertyUtils.isValidProperty(ALERT_USER_LOGIN_FAILURE_MAIL_SUBJECT, + "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", ROOT_FOLDER)); assertEquals("Configuration error: [Subject must have less than 256 character]!", result.getMessage()); } @Test - public void testSubjectRegExpValue() { + void testSubjectRegExpValue() { SMPRuntimeException result = assertThrows(SMPRuntimeException.class, () -> PropertyUtils.isValidProperty(ALERT_USER_SUSPENDED_LEVEL, "value", ROOT_FOLDER)); @@ -161,13 +158,13 @@ public class PropertyUtilsTest { @Test - public void testParseMapPropertiesToType() { + void testParseMapPropertiesToType() { //when then - String value= "test1:val1|test2:val2|test3:val:with:colon|test4: val-no-spaces"; + String value = "test1:val1|test2:val2|test3:val:with:colon|test4: val-no-spaces"; Object obj = PropertyUtils.parseProperty(SML_CUSTOM_NAPTR_SERVICE_PARAMS, value, ROOT_FOLDER); assertEquals(HashMap.class, obj.getClass()); - Map<String, String> maRes= (Map<String, String>)obj; + Map<String, String> maRes = (Map<String, String>) obj; assertTrue(maRes.containsKey("test1")); assertEquals("val1", maRes.get("test1")); @@ -180,51 +177,51 @@ public class PropertyUtilsTest { } - @Test - @Parameters(method = "testTypeValues") - public void testParsePropertyType(SMPPropertyTypeEnum propertyType, String value, boolean expectParseOk) { + @ParameterizedTest + @MethodSource("testTypeValues") + void testParsePropertyType(SMPPropertyTypeEnum propertyType, String value, boolean expectParseOk) { if (expectParseOk) { Object result = PropertyUtils.parsePropertyType(propertyType, value, ROOT_FOLDER); assertNotNull(result); assertType(propertyType, result); - } - else { - SMPRuntimeException exception = assertThrows(SMPRuntimeException.class, ()->PropertyUtils.parsePropertyType(propertyType, value, ROOT_FOLDER)); + } else { + SMPRuntimeException exception = assertThrows(SMPRuntimeException.class, () -> PropertyUtils.parsePropertyType(propertyType, value, ROOT_FOLDER)); assertNotNull(exception.getErrorCode()); } } + public static void assertType(SMPPropertyTypeEnum prop, Object value) { switch (prop) { case BOOLEAN: - Assert.assertEquals(Boolean.class, value.getClass()); + assertEquals(Boolean.class, value.getClass()); break; case EMAIL: - Assert.assertEquals(String.class, value.getClass()); + assertEquals(String.class, value.getClass()); break; case REGEXP: - Assert.assertEquals(Pattern.class, value.getClass()); + assertEquals(Pattern.class, value.getClass()); break; case INTEGER: - Assert.assertEquals(Integer.class, value.getClass()); + assertEquals(Integer.class, value.getClass()); break; case LIST_STRING: - Assert.assertTrue(value instanceof List); + assertTrue(value instanceof List); break; case MAP_STRING: - Assert.assertTrue(value instanceof Map); + assertTrue(value instanceof Map); break; case PATH: case FILENAME: - Assert.assertEquals(File.class, value.getClass()); + assertEquals(File.class, value.getClass()); break; case URL: - Assert.assertEquals(java.net.URL.class, value.getClass()); + assertEquals(java.net.URL.class, value.getClass()); break; case STRING: - Assert.assertEquals(String.class, value.getClass()); + assertEquals(String.class, value.getClass()); break; case CRON_EXPRESSION: - Assert.assertEquals(CronExpression.class, value.getClass()); + assertEquals(CronExpression.class, value.getClass()); break; default: fail("Unknown property type"); @@ -234,7 +231,7 @@ public class PropertyUtilsTest { public static void assertType(SMPPropertyEnum prop, Object value) { if (value == null) { if (prop.isMandatory()) { - Assert.fail("Default value for property: " + prop.getProperty() + " must not be empty!"); + fail("Default value for property: " + prop.getProperty() + " must not be empty!"); } return; } @@ -242,23 +239,23 @@ public class PropertyUtilsTest { } @Test - public void testIsSensitiveData() { - for (SMPPropertyEnum smpPropertyEnum: SMPPropertyEnum.values()){ - Assert.assertEquals(SENSITIVE_PROPERTIES.contains(smpPropertyEnum), PropertyUtils.isSensitiveData(smpPropertyEnum.getProperty())); + void testIsSensitiveData() { + for (SMPPropertyEnum smpPropertyEnum : SMPPropertyEnum.values()) { + assertEquals(SENSITIVE_PROPERTIES.contains(smpPropertyEnum), PropertyUtils.isSensitiveData(smpPropertyEnum.getProperty())); } } @Test - public void getMaskedData() { + void getMaskedData() { String testValue = "TestValue"; - for (SMPPropertyEnum smpPropertyEnum: SMPPropertyEnum.values()){ - String expectedValue = SENSITIVE_PROPERTIES.contains(smpPropertyEnum)?"*******":testValue; - Assert.assertEquals(expectedValue, PropertyUtils.getMaskedData(smpPropertyEnum.getProperty(),testValue)); + for (SMPPropertyEnum smpPropertyEnum : SMPPropertyEnum.values()) { + String expectedValue = SENSITIVE_PROPERTIES.contains(smpPropertyEnum) ? "*******" : testValue; + assertEquals(expectedValue, PropertyUtils.getMaskedData(smpPropertyEnum.getProperty(), testValue)); } } /* @Test - public void matchAllValues(){ + void matchAllValues(){ System.out.println("Contains in values"); List<String> enumList = Arrays.stream(SMPPropertyEnum.values()).map(val-> val.getProperty()).collect(Collectors.toList()); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/utils/SMPCookieWriterGenerateHeaderTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/utils/SMPCookieWriterGenerateHeaderTest.java index 48dddb4024d008ca3b0c5929631fe028cc283dc8..2649b86c02400dcb6d33cf03f95ad8a547d5a431 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/utils/SMPCookieWriterGenerateHeaderTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/utils/SMPCookieWriterGenerateHeaderTest.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -20,9 +20,8 @@ package eu.europa.ec.edelivery.smp.utils; import org.apache.commons.lang3.StringUtils; import org.hamcrest.core.IsNot; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.mockito.Mockito; import org.springframework.mock.web.MockHttpSession; @@ -31,65 +30,50 @@ import java.util.Arrays; import java.util.Collection; import java.util.UUID; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.startsWith; import static org.hamcrest.core.StringContains.containsString; -import static org.junit.Assert.assertThat; import static org.mockito.Mockito.doReturn; -@RunWith(Parameterized.class) public class SMPCookieWriterGenerateHeaderTest { - // parameters - String description; - boolean isSecure; - Integer maxAge; - String path; - String sameSite; - String expectedResultContains; - String expectedResultNotContains; - @Parameterized.Parameters(name = "{index}: {0}") public static Collection cookieWriterTestParameters() { return Arrays.asList(new Object[][]{ - {"Contains HttpOnly", false, 36000, "/path", "Strict", "; HttpOnly", null}, - {"Test with secure off", false, 36000, "/path", "Strict", null, "; secure"}, - {"Test with secure on", true, 36000, "/path", "Strict", "; secure", null}, - {"MaxAge given", true, 123456, "/path", "Strict", "; Max-Age=123456; Expires=", null}, - {"MaxAge not given", true, null, "/path", "Strict", null, "; Max-Age="}, - {"SameSite: off", false, 36000, "/path", null, null, "; SameSite="}, - {"SameSite: Strict", true, 36000, "/path", "Strict", "; SameSite=Strict", null}, - {"SameSite: Lax", true, 36000, "/path", "Lax", "; SameSite=Lax", null}, - {"SameSite: None", true, 36000, "/path", "None", "; SameSite=None", null}, - {"Path: Null - set request context by default", true, 36000, null, "None", "; Path=/request-context;", null}, - {"Path: user-defined-path", true, 36000, "/user-defined-path", "None", "; Path=/user-defined-path", null}, + {"Contains HttpOnly", false, 36000, "/path", "Strict", "; HttpOnly", null}, + {"Test with secure off", false, 36000, "/path", "Strict", null, "; secure"}, + {"Test with secure on", true, 36000, "/path", "Strict", "; secure", null}, + {"MaxAge given", true, 123456, "/path", "Strict", "; Max-Age=123456; Expires=", null}, + {"MaxAge not given", true, null, "/path", "Strict", null, "; Max-Age="}, + {"SameSite: off", false, 36000, "/path", null, null, "; SameSite="}, + {"SameSite: Strict", true, 36000, "/path", "Strict", "; SameSite=Strict", null}, + {"SameSite: Lax", true, 36000, "/path", "Lax", "; SameSite=Lax", null}, + {"SameSite: None", true, 36000, "/path", "None", "; SameSite=None", null}, + {"Path: Null - set request context by default", true, 36000, null, "None", "; Path=/request-context;", null}, + {"Path: user-defined-path", true, 36000, "/user-defined-path", "None", "; Path=/user-defined-path", null}, }); } - public SMPCookieWriterGenerateHeaderTest(String description, boolean isSecure, Integer maxAge, String path, String sameSite,String expectedResultContains, String expectedResultNotContains) { - this.description = description; - this.isSecure = isSecure; - this.maxAge = maxAge; - this.path = path; - this.sameSite = sameSite; - this.expectedResultContains = expectedResultContains; - this.expectedResultNotContains = expectedResultNotContains; - } // test instance SMPCookieWriter testInstance = new SMPCookieWriter(); - @Test - public void generateSetCookieHeader() { + @ParameterizedTest + @MethodSource("cookieWriterTestParameters") + void generateSetCookieHeader(String description, boolean isSecure, + Integer maxAge, String path, + String sameSite, String expectedResultContains, + String expectedResultNotContains) { // given String sessionID = UUID.randomUUID().toString(); HttpServletRequest request = Mockito.mock(HttpServletRequest.class); doReturn("/request-context").when(request).getContextPath(); // when - String result = testInstance.generateSetCookieHeader(MockHttpSession.SESSION_COOKIE_NAME, sessionID, isSecure, maxAge, path, sameSite, request); + String result = testInstance.generateSetCookieHeader(MockHttpSession.SESSION_COOKIE_NAME, sessionID, isSecure, maxAge, path, sameSite, request); // then - assertThat(result, startsWith(MockHttpSession.SESSION_COOKIE_NAME+"="+sessionID)); + assertThat(result, startsWith(MockHttpSession.SESSION_COOKIE_NAME + "=" + sessionID)); if (StringUtils.isNotEmpty(expectedResultContains)) { assertThat(result, containsString(expectedResultContains)); } diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/utils/SMPCookieWriterTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/utils/SMPCookieWriterTest.java index 133ed1af226863de6381bd7d257d94d9ac197f13..fd5ca27c0a4484e6e942572d034e235192148a3c 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/utils/SMPCookieWriterTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/utils/SMPCookieWriterTest.java @@ -18,7 +18,7 @@ */ package eu.europa.ec.edelivery.smp.utils; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.http.HttpHeaders; @@ -29,11 +29,11 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.*; -public class SMPCookieWriterTest { +class SMPCookieWriterTest { SMPCookieWriter testInstance = spy(new SMPCookieWriter()); @Test - public void generateSetCookieHeaderForName() { + void generateSetCookieHeaderForName() { // given String generatedHeader = "JSESSION=this-is-test-example; HttpOnly; Max-Age=36000; Expires=Thu, 16 Sep 2021 19:41:30 +0200; Path=/path; SameSite=Strict"; String sessionValue = "SessionValue"; diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/utils/SessionSecurityUtilsTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/utils/SessionSecurityUtilsTest.java index 8b3d093aaedb298aac2de3f0f922146d1621db64..518c217cb698b7a46add6dfb8efe764ef812f305 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/utils/SessionSecurityUtilsTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/utils/SessionSecurityUtilsTest.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -23,9 +23,8 @@ import eu.europa.ec.edelivery.smp.auth.SMPAuthenticationToken; import eu.europa.ec.edelivery.smp.auth.SMPUserDetails; import eu.europa.ec.edelivery.smp.data.ui.auth.SMPAuthority; import org.jasig.cas.client.validation.Assertion; -import org.junit.After; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.cas.authentication.CasAuthenticationToken; @@ -35,35 +34,35 @@ import org.springframework.security.core.context.SecurityContextHolder; import java.util.Collections; import java.util.List; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; /** * @author Joze Rihtarsic - * @since 4.2 + * @since 4.2q */ -public class SessionSecurityUtilsTest { +class SessionSecurityUtilsTest { - @After + @AfterEach public void afterUnitTest() { // clear authentication SecurityContextHolder.getContext().setAuthentication(null); } @Test - public void encryptedEntityId() { + void encryptedEntityId() { SMPAuthenticationToken token = setTestSMPAuthenticationToken(); - Long value = Long.valueOf(12332L); + Long value = 12332L; String result = SessionSecurityUtils.encryptedEntityId(value); assertNotNull(result); String decResult = SecurityUtils.decryptUrlSafe(token.getSecret(), result); - assertEquals(value, Long.valueOf(decResult.substring(0, decResult.indexOf('#')) )); + assertEquals(value, Long.valueOf(decResult.substring(0, decResult.indexOf('#')))); } @Test - public void decryptEntityId() { + void decryptEntityId() { SMPAuthenticationToken token = setTestSMPAuthenticationToken(); - Long value = Long.valueOf(12332L); + Long value = 12332L; String encValue = SecurityUtils.encryptURLSafe(token.getSecret(), value.toString()); Long result = SessionSecurityUtils.decryptEntityId(encValue); @@ -73,7 +72,7 @@ public class SessionSecurityUtilsTest { } @Test - public void getAuthenticationSecretFromSMPAuthenticationToken() { + void getAuthenticationSecretFromSMPAuthenticationToken() { // given SMPAuthenticationToken token = setTestSMPAuthenticationToken(); @@ -83,7 +82,7 @@ public class SessionSecurityUtilsTest { } @Test - public void getAuthenticationSecretFromCasAuthenticationToken() { + void getAuthenticationSecretFromCasAuthenticationToken() { // given CasAuthenticationToken token = setTestCasAuthenticationToken(); @@ -94,7 +93,7 @@ public class SessionSecurityUtilsTest { } @Test - public void getAuthenticationSecretNotSupported() { + void getAuthenticationSecretNotSupported() { // given UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(null, null); SecurityContextHolder.getContext().setAuthentication(token); @@ -105,7 +104,7 @@ public class SessionSecurityUtilsTest { } @Test - public void getAuthenticationName() { + void getAuthenticationName() { Authentication authentication = Mockito.mock(Authentication.class); SecurityContextHolder.getContext().setAuthentication(authentication); String testName = "testName"; @@ -113,16 +112,16 @@ public class SessionSecurityUtilsTest { String result = SessionSecurityUtils.getAuthenticationName(); - Assert.assertNotNull(result); - Assert.assertEquals(testName, result); + assertNotNull(result); + assertEquals(testName, result); } @Test - public void getSessionAuthenticationClasses() { + void getSessionAuthenticationClasses() { List<Class> list = SessionSecurityUtils.getSessionAuthenticationClasses(); - Assert.assertEquals(4, list.size()); - Assert.assertTrue(list.contains(SMPAuthenticationToken.class)); - Assert.assertTrue(list.contains(CasAuthenticationToken.class)); + assertEquals(4, list.size()); + assertTrue(list.contains(SMPAuthenticationToken.class)); + assertTrue(list.contains(CasAuthenticationToken.class)); } public SMPAuthenticationToken setTestSMPAuthenticationToken() { diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/utils/X509CertificateUtilsTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/utils/X509CertificateUtilsTest.java index 6a4ac794ac96519e6a13b1cd829ee31903c5453a..498026b6ee0a7f1802324cfdba49e1b727e69d6b 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/utils/X509CertificateUtilsTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/utils/X509CertificateUtilsTest.java @@ -35,12 +35,11 @@ package eu.europa.ec.edelivery.smp.utils; import eu.europa.ec.edelivery.security.utils.X509CertificateUtils; -import junitparams.JUnitParamsRunner; -import junitparams.Parameters; import org.apache.commons.io.IOUtils; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + import java.io.IOException; import java.security.Security; @@ -51,18 +50,18 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.*; + /** * @author Joze Rihtarsic * @since 4.1 */ -@RunWith(JUnitParamsRunner.class) + public class X509CertificateUtilsTest { - @BeforeClass + @BeforeAll public static void beforeClass() { Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()); } @@ -95,9 +94,9 @@ public class X509CertificateUtilsTest { }; } - @Test - @Parameters(method = "parseTestCases") - public void parseCertificateTest(String certificateFileName) throws CertificateException, IOException { + @ParameterizedTest + @MethodSource("parseTestCases") + void parseCertificateTest(String certificateFileName) throws CertificateException, IOException { //given byte[] buff = getBytes(certificateFileName); @@ -107,10 +106,9 @@ public class X509CertificateUtilsTest { } - - @Test - @Parameters(method = "crlTestListCases") - public void getCrlDistributionPointsTest(String certificatFileName, String clrLists) throws CertificateException { + @ParameterizedTest + @MethodSource("crlTestListCases") + void getCrlDistributionPointsTest(String certificatFileName, String clrLists) throws CertificateException { //given X509Certificate certificate = loadCertificate(certificatFileName); List<String> lstExpected = clrLists == null ? Collections.emptyList() : Arrays.asList(clrLists.split(",")); @@ -123,10 +121,9 @@ public class X509CertificateUtilsTest { }); } - - @Test - @Parameters(method = "crlExtractHTTPSTestListCases") - public void extractHttpCrlDistributionPoints(String clrLists, String value) { + @ParameterizedTest + @MethodSource("crlExtractHTTPSTestListCases") + void extractHttpCrlDistributionPoints(String clrLists, String value) { //given List<String> urlList = clrLists == null ? Collections.emptyList() : Arrays.asList(clrLists.split(",")); // when @@ -135,7 +132,6 @@ public class X509CertificateUtilsTest { assertEquals(value, url); } - public static X509Certificate loadCertificate(String filename) throws CertificateException { CertificateFactory fact = CertificateFactory.getInstance("X.509"); @@ -147,6 +143,4 @@ public class X509CertificateUtilsTest { public static byte[] getBytes(String filename) throws CertificateException, IOException { return IOUtils.toByteArray(X509CertificateUtilsTest.class.getResourceAsStream("/certificates/" + filename)); } - - } diff --git a/smp-webapp/pom.xml b/smp-webapp/pom.xml index a89c39ba03282dc2a3812fff7cefd7d04a58ca36..9ba3041c5426f75da36f50e7efb57519fe4588c8 100644 --- a/smp-webapp/pom.xml +++ b/smp-webapp/pom.xml @@ -99,21 +99,11 @@ <artifactId>spring-test</artifactId> <scope>test</scope> </dependency> - <dependency> - <groupId>org.hamcrest</groupId> - <artifactId>hamcrest-junit</artifactId> - <scope>test</scope> - </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-engine</artifactId> <scope>test</scope> </dependency> - <dependency> - <groupId>org.junit.vintage</groupId> - <artifactId>junit-vintage-engine</artifactId> - <scope>test</scope> - </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-params</artifactId> diff --git a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/AbstractTest.java b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/AbstractTest.java index f5423b93ef87906584661b83ee15dccdae9fc06a..fc42e9b9f3211bbccbd0dd18f8b7c73dc932ddd5 100644 --- a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/AbstractTest.java +++ b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/AbstractTest.java @@ -19,7 +19,7 @@ package eu.europa.ec.edelivery.smp; import eu.europa.ec.edelivery.smp.test.testutils.X509CertificateTestUtils; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; import java.io.IOException; @@ -29,10 +29,8 @@ import java.io.IOException; */ public abstract class AbstractTest { - @Before + @BeforeEach public void setup() throws IOException { X509CertificateTestUtils.reloadKeystores(); } - - } diff --git a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/auth/SMPAuthenticationEventListenerTest.java b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/auth/SMPAuthenticationEventListenerTest.java index af90c87f355d6915334f9d1536e253d09ba0d08f..46e7dec51a0738b18276699af1340888ac5509c6 100644 --- a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/auth/SMPAuthenticationEventListenerTest.java +++ b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/auth/SMPAuthenticationEventListenerTest.java @@ -20,7 +20,7 @@ package eu.europa.ec.edelivery.smp.auth; import eu.europa.ec.edelivery.smp.data.ui.auth.SMPAuthority; import eu.europa.ec.edelivery.smp.services.ConfigurationService; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.security.core.GrantedAuthority; @@ -28,9 +28,9 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.*; -public class SMPAuthenticationEventListenerTest { +class SMPAuthenticationEventListenerTest { ConfigurationService configurationService = Mockito.mock(ConfigurationService.class); // test instance @@ -38,7 +38,7 @@ public class SMPAuthenticationEventListenerTest { @Test - public void getSessionTimeoutForRolesSMPAdmin() { + void getSessionTimeoutForRolesSMPAdmin() { // Given Collection<? extends GrantedAuthority> authorities = Collections.singletonList(SMPAuthority.S_AUTHORITY_USER); // when then @@ -46,7 +46,7 @@ public class SMPAuthenticationEventListenerTest { } @Test - public void getSessionTimeoutForRolesSystemAdmin() { + void getSessionTimeoutForRolesSystemAdmin() { // Given Collection<? extends GrantedAuthority> authorities = Collections.singletonList(SMPAuthority.S_AUTHORITY_SYSTEM_ADMIN); // when then @@ -54,7 +54,7 @@ public class SMPAuthenticationEventListenerTest { } @Test - public void getSessionTimeoutForRolesUser() { + void getSessionTimeoutForRolesUser() { // Given Collection<? extends GrantedAuthority> authorities = Collections.singletonList(SMPAuthority.S_AUTHORITY_USER); // when then @@ -62,7 +62,7 @@ public class SMPAuthenticationEventListenerTest { } @Test - public void getSessionTimeoutForRolesUserAndSystem() { + void getSessionTimeoutForRolesUserAndSystem() { // Given Collection<? extends GrantedAuthority> authorities = Arrays.asList(SMPAuthority.S_AUTHORITY_USER, SMPAuthority.S_AUTHORITY_SYSTEM_ADMIN); // when then @@ -70,7 +70,7 @@ public class SMPAuthenticationEventListenerTest { } @Test - public void getSessionTimeoutForRolesUserAndSMP() { + void getSessionTimeoutForRolesUserAndSMP() { // Given Collection<? extends GrantedAuthority> authorities = Collections.singletonList(SMPAuthority.S_AUTHORITY_USER); // when then diff --git a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/auth/SMPAuthenticationProviderTest.java b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/auth/SMPAuthenticationProviderTest.java index 06db88dfee2b2c33739b73953b8663f02f2dbf5c..4f2668693622c363881e9bdea385588dbb34bbf4 100644 --- a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/auth/SMPAuthenticationProviderTest.java +++ b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/auth/SMPAuthenticationProviderTest.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -25,14 +25,13 @@ import eu.europa.ec.edelivery.smp.data.enums.CredentialTargetType; import eu.europa.ec.edelivery.smp.data.enums.CredentialType; import eu.europa.ec.edelivery.smp.data.model.user.DBCredential; import eu.europa.ec.edelivery.smp.data.model.user.DBUser; -import eu.europa.ec.edelivery.smp.services.CredentialService; -import eu.europa.ec.edelivery.smp.services.CredentialsAlertService; import eu.europa.ec.edelivery.smp.services.CRLVerifierService; import eu.europa.ec.edelivery.smp.services.ConfigurationService; +import eu.europa.ec.edelivery.smp.services.CredentialService; +import eu.europa.ec.edelivery.smp.services.CredentialsAlertService; import eu.europa.ec.edelivery.smp.services.ui.UITruststoreService; import org.hamcrest.Matchers; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.core.convert.ConversionService; import org.springframework.security.authentication.AuthenticationServiceException; @@ -40,19 +39,18 @@ import org.springframework.security.authentication.BadCredentialsException; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.crypto.bcrypt.BCrypt; -import java.time.OffsetDateTime; import java.util.Calendar; import java.util.Optional; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.doReturn; /** * @author Joze Rihtarsic * @since 4.2 */ -public class SMPAuthenticationProviderTest { +class SMPAuthenticationProviderTest { CredentialDao mockCredentialDao = Mockito.mock(CredentialDao.class); @@ -64,13 +62,13 @@ public class SMPAuthenticationProviderTest { UserDao mockUserDao = Mockito.mock(UserDao.class); - CredentialService mockCredentialService = new CredentialService(mockUserDao, mockCredentialDao, mockConversionService, mockCrlVerifierService, mockTruststoreService, mockConfigurationService, mocAlertService); + CredentialService mockCredentialService = new CredentialService(mockUserDao, mockCredentialDao, mockConversionService, mockCrlVerifierService, mockTruststoreService, mockConfigurationService, mocAlertService); SMPAuthenticationProvider testInstance = new SMPAuthenticationProvider(mockCredentialService); // response time for existing and nonexistent user should be "approx. equal" @Test - public void authenticateByAccessTokenResponseTime() { + void authenticateByAccessTokenResponseTime() { UsernamePasswordAuthenticationToken userToken = new UsernamePasswordAuthenticationToken("User", "User"); int count = 10; @@ -85,7 +83,7 @@ public class SMPAuthenticationProviderTest { credential.setCredentialTarget(CredentialTargetType.REST_API); doReturn(1000).when(mockConfigurationService).getAccessTokenLoginFailDelayInMilliSeconds(); - doReturn(count+5).when(mockConfigurationService).getAccessTokenLoginMaxAttempts(); + doReturn(count + 5).when(mockConfigurationService).getAccessTokenLoginMaxAttempts(); doReturn(Optional.of(credential)).when(mockCredentialDao).findAccessTokenCredentialForAPI(any()); diff --git a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/auth/SMPAuthorizationServiceTest.java b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/auth/SMPAuthorizationServiceTest.java index f8de0d06868d2dac4bbeb2d52a0230cdb11bd88b..363a48a4608d7ecea2c1c12d9db40b6603d73c04 100644 --- a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/auth/SMPAuthorizationServiceTest.java +++ b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/auth/SMPAuthorizationServiceTest.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -27,9 +27,8 @@ import eu.europa.ec.edelivery.smp.data.ui.UserRO; import eu.europa.ec.edelivery.smp.data.ui.auth.SMPAuthority; import eu.europa.ec.edelivery.smp.services.ConfigurationService; import eu.europa.ec.edelivery.smp.utils.SessionSecurityUtils; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.core.convert.ConversionService; import org.springframework.security.authentication.BadCredentialsException; @@ -40,10 +39,12 @@ import org.springframework.security.core.context.SecurityContextHolder; import java.time.OffsetDateTime; import java.util.Collections; -import static org.junit.Assert.assertTrue; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.junit.jupiter.api.Assertions.*; -public class SMPAuthorizationServiceTest { +class SMPAuthorizationServiceTest { UserRO user = null; SecurityContext mockSecurityContextSystemAdmin = null; @@ -59,7 +60,7 @@ public class SMPAuthorizationServiceTest { configurationService); - @Before + @BeforeEach public void setup() { user = new UserRO(); @@ -99,7 +100,7 @@ public class SMPAuthorizationServiceTest { } @Test - public void isSystemAdministratorLoggedIn() { + void isSystemAdministratorLoggedIn() { // given SecurityContextHolder.setContext(mockSecurityContextSystemAdmin); // when then @@ -107,16 +108,18 @@ public class SMPAuthorizationServiceTest { assertTrue(bVal); } - @Test(expected = BadCredentialsException.class) - public void isCurrentlyLoggedInNotLoggedIn() { + @Test + void isCurrentlyLoggedInNotLoggedIn() { // given SecurityContextHolder.setContext(mockSecurityContextSystemAdmin); - testInstance.isCurrentlyLoggedIn("Invalid or Expired session! Please login again."); + BadCredentialsException result = assertThrows(BadCredentialsException.class, + () -> testInstance.isCurrentlyLoggedIn("InvalidUserId.")); + assertThat(result.getMessage(), containsString("Invalid user id")); } @Test - public void isCurrentlyLoggedIn() throws Exception { + void isCurrentlyLoggedIn() { // given SecurityContextHolder.setContext(mockSecurityContextSystemAdmin); // when then @@ -125,7 +128,7 @@ public class SMPAuthorizationServiceTest { } @Test - public void testGetUpdatedUserData() { + void testGetUpdatedUserData() { UserRO user = new UserRO(); user.setPasswordExpireOn(OffsetDateTime.now().minusDays(1)); Mockito.doReturn(10).when(configurationService).getPasswordPolicyUIWarningDaysBeforeExpire(); @@ -133,13 +136,13 @@ public class SMPAuthorizationServiceTest { user = testInstance.getUpdatedUserData(user); - Assert.assertTrue(user.isShowPasswordExpirationWarning()); - Assert.assertFalse(user.isForceChangeExpiredPassword()); - Assert.assertFalse(user.isPasswordExpired()); + assertTrue(user.isShowPasswordExpirationWarning()); + assertFalse(user.isForceChangeExpiredPassword()); + assertFalse(user.isPasswordExpired()); } @Test - public void testGetUpdatedUserDataAboutToExpireNoWarning() { + void testGetUpdatedUserDataAboutToExpireNoWarning() { UserRO user = new UserRO(); // password will expire in 11 days. But the warning is 10 days before expire user.setPasswordExpireOn(OffsetDateTime.now().plusDays(11)); @@ -148,13 +151,13 @@ public class SMPAuthorizationServiceTest { user = testInstance.getUpdatedUserData(user); - Assert.assertFalse(user.isShowPasswordExpirationWarning()); - Assert.assertFalse(user.isForceChangeExpiredPassword()); - Assert.assertFalse(user.isPasswordExpired()); + assertFalse(user.isShowPasswordExpirationWarning()); + assertFalse(user.isForceChangeExpiredPassword()); + assertFalse(user.isPasswordExpired()); } @Test - public void testGetUpdatedUserDataAboutToExpireShowWarning() { + void testGetUpdatedUserDataAboutToExpireShowWarning() { UserRO user = new UserRO(); // password will expire in 9 days. Warning is 10 days before expire user.setPasswordExpireOn(OffsetDateTime.now().plusDays(9)); @@ -163,13 +166,13 @@ public class SMPAuthorizationServiceTest { user = testInstance.getUpdatedUserData(user); - Assert.assertTrue(user.isShowPasswordExpirationWarning()); - Assert.assertFalse(user.isForceChangeExpiredPassword()); - Assert.assertFalse(user.isPasswordExpired()); + assertTrue(user.isShowPasswordExpirationWarning()); + assertFalse(user.isForceChangeExpiredPassword()); + assertFalse(user.isPasswordExpired()); } @Test - public void testGetUpdatedUserDataForceChange() { + void testGetUpdatedUserDataForceChange() { UserRO user = new UserRO(); user.setPasswordExpireOn(OffsetDateTime.now().plusDays(1)); user.setPasswordExpired(true); @@ -178,12 +181,12 @@ public class SMPAuthorizationServiceTest { user = testInstance.getUpdatedUserData(user); - Assert.assertTrue(user.isForceChangeExpiredPassword()); - Assert.assertTrue(user.isPasswordExpired()); + assertTrue(user.isForceChangeExpiredPassword()); + assertTrue(user.isPasswordExpired()); } @Test - public void testGetUpdatedUserDataForceChangeFalse() { + void testGetUpdatedUserDataForceChangeFalse() { UserRO user = new UserRO(); user.setPasswordExpireOn(OffsetDateTime.now().plusDays(1)); user.setPasswordExpired(true); @@ -192,8 +195,8 @@ public class SMPAuthorizationServiceTest { user = testInstance.getUpdatedUserData(user); - Assert.assertFalse(user.isForceChangeExpiredPassword()); - Assert.assertTrue(user.isPasswordExpired()); + assertFalse(user.isForceChangeExpiredPassword()); + assertTrue(user.isPasswordExpired()); } } diff --git a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/auth/URLCsrfMatcherTest.java b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/auth/URLCsrfMatcherTest.java index 4a46c80a4e427833e780930598a5573970049d64..5bc51f231dea190becdd159722180eef5cabb421 100644 --- a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/auth/URLCsrfMatcherTest.java +++ b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/auth/URLCsrfMatcherTest.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -18,9 +18,8 @@ */ package eu.europa.ec.edelivery.smp.auth; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.mockito.Mockito; import org.springframework.http.HttpMethod; @@ -30,12 +29,11 @@ import java.util.Collections; import java.util.List; import static java.util.Arrays.asList; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; + -@RunWith(Parameterized.class) public class URLCsrfMatcherTest { - @Parameterized.Parameters(name = "{index}: {0}") public static Collection cookieWriterTestParameters() { return asList(new Object[][]{ {"/test/", false, Collections.singletonList("/.*"), null}, @@ -46,21 +44,12 @@ public class URLCsrfMatcherTest { }); } - @Parameterized.Parameter(0) - public String patInfo; - - @Parameterized.Parameter(1) - public boolean notMatchResult; - - @Parameterized.Parameter(2) - public List<String> regExp; - - @Parameterized.Parameter(3) - public List<HttpMethod> httpMethods; - - - @Test - public void matches() { + @ParameterizedTest + @MethodSource("cookieWriterTestParameters") + void matches(String patInfo, + boolean notMatchResult, + List<String> regExp, + List<HttpMethod> httpMethods) { URLCsrfIgnoreMatcher testInstance = new URLCsrfIgnoreMatcher(regExp, httpMethods); HttpServletRequest request = Mockito.mock(HttpServletRequest.class); diff --git a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/auth/cas/SMPCasConfigurerTest.java b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/auth/cas/SMPCasConfigurerTest.java index cc35dcc67dfc9e38a38a54fc0d1070f916b69567..7cd8a714c5bc907264c60ab179b271cf574ffeed 100644 --- a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/auth/cas/SMPCasConfigurerTest.java +++ b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/auth/cas/SMPCasConfigurerTest.java @@ -20,7 +20,7 @@ package eu.europa.ec.edelivery.smp.auth.cas; import eu.europa.ec.edelivery.smp.services.ConfigurationService; import eu.europa.ec.edelivery.smp.utils.SmpUrlBuilder; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.security.cas.ServiceProperties; import org.springframework.security.cas.authentication.CasAuthenticationProvider; @@ -33,18 +33,18 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; -public class SMPCasConfigurerTest { +class SMPCasConfigurerTest { ConfigurationService mockConfigService = Mockito.mock(ConfigurationService.class); SmpUrlBuilder mockSmpUrlBuilder = Mockito.mock(SmpUrlBuilder.class); SMPCasConfigurer testInstance = new SMPCasConfigurer(mockSmpUrlBuilder, mockConfigService); @Test - public void serviceProperties() throws MalformedURLException { + void serviceProperties() throws MalformedURLException { String callbackString = "http://callback.local/smp"; URL callBackURL = new URL(callbackString); doReturn(callBackURL).when(mockConfigService).getCasCallbackUrl(); @@ -57,7 +57,7 @@ public class SMPCasConfigurerTest { } @Test - public void casAuthenticationEntryPoint() throws MalformedURLException { + void casAuthenticationEntryPoint() throws MalformedURLException { String casUrl = "http://cas-server.local/cas"; String casLoginPath = "login"; doReturn(true).when(mockConfigService).isSSOEnabledForUserAuthentication(); @@ -72,7 +72,7 @@ public class SMPCasConfigurerTest { } @Test - public void ecasServiceTicketValidator() throws MalformedURLException { + void ecasServiceTicketValidator() throws MalformedURLException { String casUrl = "http://cas-server.local/cas"; String tokenValidator = "laxValidate"; @@ -86,7 +86,7 @@ public class SMPCasConfigurerTest { } @Test - public void getCustomParameters() { + void getCustomParameters() { Map<String, String> testMap = new HashMap<>(); testMap.put("key1","val1"); testMap.put("key2","val2"); @@ -104,7 +104,7 @@ public class SMPCasConfigurerTest { } @Test - public void casAuthenticationProvider() { + void casAuthenticationProvider() { ServiceProperties serviceProperties = mock(ServiceProperties.class); SMPCas20ServiceTicketValidator smpCas20ServiceTicketValidator = mock(SMPCas20ServiceTicketValidator.class); SMPCasUserService smpCasUserService = mock(SMPCasUserService.class); diff --git a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/config/SMPMailPropertyUpdateListenerTest.java b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/config/SMPMailPropertyUpdateListenerTest.java index 5c669ed713c31886ee90199b8d8235042ca65594..364801ef51b01ae779849f1042a98475a022a6e5 100644 --- a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/config/SMPMailPropertyUpdateListenerTest.java +++ b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/config/SMPMailPropertyUpdateListenerTest.java @@ -20,7 +20,7 @@ package eu.europa.ec.edelivery.smp.config; import eu.europa.ec.edelivery.smp.config.enums.SMPPropertyEnum; import eu.europa.ec.edelivery.smp.config.properties.SMPMailPropertyUpdateListener; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.springframework.mail.javamail.JavaMailSenderImpl; @@ -31,16 +31,16 @@ import java.util.Map; import java.util.Optional; import static eu.europa.ec.edelivery.smp.config.enums.SMPPropertyEnum.*; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -public class SMPMailPropertyUpdateListenerTest { +class SMPMailPropertyUpdateListenerTest { JavaMailSenderImpl javaMailSender = Mockito.mock(JavaMailSenderImpl.class); SMPMailPropertyUpdateListener testInstance = new SMPMailPropertyUpdateListener(Optional.of(javaMailSender)); @Test - public void testUpdatePropertiesHost() { + void testUpdatePropertiesHost() { String testStringValue = "TestValue"; Map<SMPPropertyEnum, Object> prop = new HashMap(); prop.put(MAIL_SERVER_HOST, testStringValue); @@ -49,7 +49,7 @@ public class SMPMailPropertyUpdateListenerTest { } @Test - public void testUpdatePropertiesPort() { + void testUpdatePropertiesPort() { Integer portValue = 1122; Map<SMPPropertyEnum, Object> prop = new HashMap(); prop.put(MAIL_SERVER_PORT, portValue); @@ -58,7 +58,7 @@ public class SMPMailPropertyUpdateListenerTest { } @Test - public void testUpdatePropertiesProtocol() { + void testUpdatePropertiesProtocol() { String testStringValue = "TestValue"; Map<SMPPropertyEnum, Object> prop = new HashMap(); prop.put(MAIL_SERVER_PROTOCOL, testStringValue); @@ -67,7 +67,7 @@ public class SMPMailPropertyUpdateListenerTest { } @Test - public void testUpdatePropertiesUsername() { + void testUpdatePropertiesUsername() { String testStringValue = "TestValue"; Map<SMPPropertyEnum, Object> prop = new HashMap(); prop.put(MAIL_SERVER_USERNAME, testStringValue); @@ -76,7 +76,7 @@ public class SMPMailPropertyUpdateListenerTest { } @Test - public void testUpdatePropertiesPassword() { + void testUpdatePropertiesPassword() { String testStringValue = "TestValue"; Map<SMPPropertyEnum, Object> prop = new HashMap(); prop.put(MAIL_SERVER_PASSWORD, testStringValue); @@ -85,7 +85,7 @@ public class SMPMailPropertyUpdateListenerTest { } @Test - public void testUpdatePropertiesProperties() { + void testUpdatePropertiesProperties() { Map<String, String> properties = new HashMap(); properties.put("testkey", "testValue"); Map<SMPPropertyEnum, Object> prop = new HashMap(); @@ -95,7 +95,7 @@ public class SMPMailPropertyUpdateListenerTest { } @Test - public void testHandledProperties() { + void testHandledProperties() { Map<SMPPropertyEnum, Object> prop = new HashMap(); List<SMPPropertyEnum> result = testInstance.handledProperties(); assertEquals(6, result.size()); @@ -108,7 +108,7 @@ public class SMPMailPropertyUpdateListenerTest { } @Test - public void testHandleProperty() { + void testHandleProperty() { boolean resultTrue = testInstance.handlesProperty(MAIL_SERVER_HOST); assertTrue(resultTrue); boolean resultFalse = testInstance.handlesProperty(HTTP_PROXY_HOST); diff --git a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/config/SMPSecurityPropertyUpdateListenerTest.java b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/config/SMPSecurityPropertyUpdateListenerTest.java index e89e4eb91cd97957cca6199407b4e767e2b19c84..d97c261e8cd233253fc251e83d7e496fcf381cb6 100644 --- a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/config/SMPSecurityPropertyUpdateListenerTest.java +++ b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/config/SMPSecurityPropertyUpdateListenerTest.java @@ -20,7 +20,7 @@ package eu.europa.ec.edelivery.smp.config; import eu.europa.ec.edelivery.smp.config.enums.SMPPropertyEnum; import eu.europa.ec.edelivery.smp.config.properties.SMPSecurityPropertyUpdateListener; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.web.server.adapter.ForwardedHeaderTransformer; @@ -31,17 +31,16 @@ import java.util.Map; import static eu.europa.ec.edelivery.smp.config.enums.SMPPropertyEnum.*; import static java.lang.Boolean.FALSE; import static java.lang.Boolean.TRUE; -import static org.junit.Assert.*; - -public class SMPSecurityPropertyUpdateListenerTest { +import static org.junit.jupiter.api.Assertions.*; +class SMPSecurityPropertyUpdateListenerTest { WSSecurityConfigurerAdapter wsSecurityConfigurerAdapter = Mockito.mock(WSSecurityConfigurerAdapter.class); ForwardedHeaderTransformer forwardedHeaderTransformer = Mockito.mock(ForwardedHeaderTransformer.class); SMPSecurityPropertyUpdateListener testInstance = new SMPSecurityPropertyUpdateListener(wsSecurityConfigurerAdapter, forwardedHeaderTransformer); @Test - public void testPropertiesUpdateClientCertTrue() { + void testPropertiesUpdateClientCertTrue() { Map<SMPPropertyEnum, Object> prop = new HashMap(); prop.put(EXTERNAL_TLS_AUTHENTICATION_CLIENT_CERT_HEADER_ENABLED, TRUE); testInstance.updateProperties(prop); @@ -51,7 +50,7 @@ public class SMPSecurityPropertyUpdateListenerTest { } @Test - public void testPropertiesUpdateSSLClientCertTrue() { + void testPropertiesUpdateSSLClientCertTrue() { Map<SMPPropertyEnum, Object> prop = new HashMap(); prop.put(EXTERNAL_TLS_AUTHENTICATION_CERTIFICATE_HEADER_ENABLED, TRUE); testInstance.updateProperties(prop); @@ -61,7 +60,7 @@ public class SMPSecurityPropertyUpdateListenerTest { } @Test - public void testPropertiesUpdateForwardedHeadersTrue() { + void testPropertiesUpdateForwardedHeadersTrue() { Map<SMPPropertyEnum, Object> prop = new HashMap(); prop.put(HTTP_FORWARDED_HEADERS_ENABLED, FALSE); testInstance.updateProperties(prop); @@ -71,7 +70,7 @@ public class SMPSecurityPropertyUpdateListenerTest { } @Test - public void testPropertiesUpdateFalse() { + void testPropertiesUpdateFalse() { Map<SMPPropertyEnum, Object> prop = new HashMap(); prop.put(EXTERNAL_TLS_AUTHENTICATION_CLIENT_CERT_HEADER_ENABLED, FALSE); prop.put(EXTERNAL_TLS_AUTHENTICATION_CERTIFICATE_HEADER_ENABLED, FALSE); @@ -83,7 +82,7 @@ public class SMPSecurityPropertyUpdateListenerTest { } @Test - public void testHandledProperties() { + void testHandledProperties() { Map<SMPPropertyEnum, Object> prop = new HashMap(); List<SMPPropertyEnum> result = testInstance.handledProperties(); assertEquals(3, result.size()); @@ -93,7 +92,7 @@ public class SMPSecurityPropertyUpdateListenerTest { } @Test - public void testHandleProperty() { + void testHandleProperty() { boolean resultTrue = testInstance.handlesProperty(HTTP_FORWARDED_HEADERS_ENABLED); assertTrue(resultTrue); boolean resultFalse = testInstance.handlesProperty(HTTP_PROXY_HOST); diff --git a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/config/SMPWebApplicationInitializerTest.java b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/config/SMPWebApplicationInitializerTest.java index fd9cac8c8a5bdf5e8f4416beda8aeeef7935863e..4ba599ada45a361dfa9a3e488975337f2bccc3b2 100644 --- a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/config/SMPWebApplicationInitializerTest.java +++ b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/config/SMPWebApplicationInitializerTest.java @@ -19,7 +19,7 @@ package eu.europa.ec.edelivery.smp.config; import eu.europa.ec.edelivery.smp.utils.ExtLibraryClassLoader; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; import org.slf4j.Logger; @@ -28,14 +28,14 @@ import java.io.File; import java.nio.file.Path; import java.nio.file.Paths; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -public class SMPWebApplicationInitializerTest { +class SMPWebApplicationInitializerTest { SMPWebApplicationInitializer testInstance = new SMPWebApplicationInitializer(); @Test - public void logBuildProperties() { + void logBuildProperties() { Logger log = Mockito.mock(Logger.class); testInstance.logBuildProperties(log, "/test-application.properties"); @@ -57,19 +57,19 @@ public class SMPWebApplicationInitializerTest { } @Test - public void createLibraryClassLoaderNotExists() { + void createLibraryClassLoaderNotExists() { ExtLibraryClassLoader loader= testInstance.createLibraryClassLoader(new File("FileNotExists")); assertNull(loader); } @Test - public void createLibraryClassLoaderIsNotFolder() { + void createLibraryClassLoaderIsNotFolder() { ExtLibraryClassLoader loader= testInstance.createLibraryClassLoader(new File("./pom.xml")); assertNull(loader); } @Test - public void createLibraryClassLoader() { + void createLibraryClassLoader() { // folder contains one library jar simple-extension.jar with the resource logback-test.xml Path path = Paths.get("src","test","resources", "test-libs"); ExtLibraryClassLoader loader= testInstance.createLibraryClassLoader(path.toFile()); diff --git a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/controllers/ResourceControllerTest.java b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/controllers/ResourceControllerTest.java index 2bd01f5c19f45a81f6ec2ab44c062ea25f3fbc92..c1be5049846b3605fb35d31973a308a6aad39c46 100644 --- a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/controllers/ResourceControllerTest.java +++ b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/controllers/ResourceControllerTest.java @@ -73,13 +73,13 @@ public class ResourceControllerTest extends AbstractControllerTest { } @Test - public void notFoundIsReturnedWhenServiceGroupDoesNotExist() throws Exception { + void notFoundIsReturnedWhenServiceGroupDoesNotExist() throws Exception { mvc.perform(get(format("/%s::%s", IDENTIFIER_SCHEME, UUID.randomUUID()))) .andExpect(status().isNotFound()); } @Test - public void adminCanCreateServiceGroup() throws Exception { + void adminCanCreateServiceGroup() throws Exception { String participantId = UUID.randomUUID().toString(); String resourceExample = getSampleServiceGroupBody(IDENTIFIER_SCHEME, participantId); String urPath = format("/%s::%s", IDENTIFIER_SCHEME, participantId); @@ -93,7 +93,7 @@ public class ResourceControllerTest extends AbstractControllerTest { } @Test - public void adminCanUpdateServiceGroup() throws Exception { + void adminCanUpdateServiceGroup() throws Exception { String participantId = UUID.randomUUID().toString(); String resourceExample = getSampleServiceGroupBody(IDENTIFIER_SCHEME, participantId); String urPath = format("/%s::%s", IDENTIFIER_SCHEME, participantId); @@ -115,7 +115,7 @@ public class ResourceControllerTest extends AbstractControllerTest { } @Test - public void existingServiceGroupCanBeRetrievedByEverybody() throws Exception { + void existingServiceGroupCanBeRetrievedByEverybody() throws Exception { String participantId = UUID.randomUUID().toString(); String resourceExample = getSampleServiceGroupBody(IDENTIFIER_SCHEME, participantId); String urPath = format("/%s::%s", IDENTIFIER_SCHEME, participantId); @@ -138,7 +138,7 @@ public class ResourceControllerTest extends AbstractControllerTest { "/" + HTTP_DOMAIN_VALUE, // as domain value "/" + HTTP_DOMAIN_VALUE + "/" + DOCUMENT_TYPE_URL // as domain value }) - public void existingServiceGroupCanBeRetrievedByEverybodyWithSubContext(String context) throws Exception { + void existingServiceGroupCanBeRetrievedByEverybodyWithSubContext(String context) throws Exception { String participantId = UUID.randomUUID().toString(); String resourceExample = getSampleServiceGroupBody(IDENTIFIER_SCHEME, participantId); String urPath = format("%s/%s::%s", context, IDENTIFIER_SCHEME, participantId); @@ -160,7 +160,7 @@ public class ResourceControllerTest extends AbstractControllerTest { "/" + HTTP_DOMAIN_VALUE, // as domain value "/" + HTTP_DOMAIN_VALUE + "/" + DOCUMENT_TYPE_URL // as domain value }) - public void existingServiceMetadataCanBeRetrievedByEverybody(String context) throws Exception { + void existingServiceMetadataCanBeRetrievedByEverybody(String context) throws Exception { String participantId = UUID.randomUUID().toString(); String documentId = UUID.randomUUID().toString(); @@ -193,7 +193,7 @@ public class ResourceControllerTest extends AbstractControllerTest { } @Test - public void getExistingServiceMetadataWithReverseProxyHost() throws Exception { + void getExistingServiceMetadataWithReverseProxyHost() throws Exception { //given String participantId = UUID.randomUUID().toString(); String documentId = UUID.randomUUID().toString(); @@ -210,7 +210,7 @@ public class ResourceControllerTest extends AbstractControllerTest { } @Test - public void getExistingServiceMetadataWithReverseNoProxyHost() throws Exception { + void getExistingServiceMetadataWithReverseNoProxyHost() throws Exception { //given String participantId = UUID.randomUUID().toString(); String documentId = UUID.randomUUID().toString(); @@ -227,7 +227,7 @@ public class ResourceControllerTest extends AbstractControllerTest { } @Test - public void getExistingServiceMetadataWithReverseProxyPort() throws Exception { + void getExistingServiceMetadataWithReverseProxyPort() throws Exception { //given String participantId = UUID.randomUUID().toString(); String documentId = UUID.randomUUID().toString(); @@ -243,7 +243,7 @@ public class ResourceControllerTest extends AbstractControllerTest { } @Test - public void getExistingServiceMetadataWithReverseProxySchema() throws Exception { + void getExistingServiceMetadataWithReverseProxySchema() throws Exception { //given String participantId = UUID.randomUUID().toString(); String documentId = UUID.randomUUID().toString(); @@ -260,7 +260,7 @@ public class ResourceControllerTest extends AbstractControllerTest { } @Test - public void getExistingServiceMetadataWithReverseProxySkipDefaultPortHttps() throws Exception { + void getExistingServiceMetadataWithReverseProxySkipDefaultPortHttps() throws Exception { //given String participantId = UUID.randomUUID().toString(); String documentId = UUID.randomUUID().toString(); @@ -279,7 +279,7 @@ public class ResourceControllerTest extends AbstractControllerTest { } @Test - public void getExistingServiceMetadataWithReverseProxySkipDefaultPortHttp() throws Exception { + void getExistingServiceMetadataWithReverseProxySkipDefaultPortHttp() throws Exception { //given String participantId = UUID.randomUUID().toString(); String documentId = UUID.randomUUID().toString(); @@ -296,7 +296,7 @@ public class ResourceControllerTest extends AbstractControllerTest { } @Test - public void getExistingServiceMetadataWithReverseProxyPortInHost() throws Exception { + void getExistingServiceMetadataWithReverseProxyPortInHost() throws Exception { //given String participantId = UUID.randomUUID().toString(); String documentId = UUID.randomUUID().toString(); @@ -326,7 +326,7 @@ public class ResourceControllerTest extends AbstractControllerTest { } @Test - public void anonymousUserCannotCreateServiceGroup() throws Exception { + void anonymousUserCannotCreateServiceGroup() throws Exception { String participantId = UUID.randomUUID().toString(); String resourceExample = getSampleServiceGroupBody(IDENTIFIER_SCHEME, participantId); @@ -343,7 +343,7 @@ public class ResourceControllerTest extends AbstractControllerTest { } @Test - public void adminCanDeleteServiceGroup() throws Exception { + void adminCanDeleteServiceGroup() throws Exception { String participantId = UUID.randomUUID().toString(); String resourceExample = getSampleServiceGroupBody(IDENTIFIER_SCHEME, participantId); String urlPath = format("/%s::%s", IDENTIFIER_SCHEME, participantId); @@ -363,7 +363,7 @@ public class ResourceControllerTest extends AbstractControllerTest { } @Test - public void malformedInputReturnsBadRequest() throws Exception { + void malformedInputReturnsBadRequest() throws Exception { String participantId = UUID.randomUUID().toString(); String urlPath = format("/%s::%s", IDENTIFIER_SCHEME, participantId); @@ -377,7 +377,7 @@ public class ResourceControllerTest extends AbstractControllerTest { } @Test - public void invalidParticipantSchemeReturnsBadRequest() throws Exception { + void invalidParticipantSchemeReturnsBadRequest() throws Exception { String participantId = UUID.randomUUID().toString(); String scheme = "length-exceeeeeeds-25chars"; @@ -394,7 +394,7 @@ public class ResourceControllerTest extends AbstractControllerTest { } @Test - public void creatingServiceGroupUnderBadFormatedDomainReturnsBadRequest() throws Exception { + void creatingServiceGroupUnderBadFormatedDomainReturnsBadRequest() throws Exception { String participantId = UUID.randomUUID().toString(); String resourceExample = getSampleServiceGroupBody(IDENTIFIER_SCHEME, participantId); String urlPath = format("/%s::%s", IDENTIFIER_SCHEME, participantId); @@ -410,7 +410,7 @@ public class ResourceControllerTest extends AbstractControllerTest { } @Test - public void creatingServiceGroupUnderNotExistingDomainReturnsBadRequest() throws Exception { + void creatingServiceGroupUnderNotExistingDomainReturnsBadRequest() throws Exception { String participantId = UUID.randomUUID().toString(); String resourceExample = getSampleServiceGroupBody(IDENTIFIER_SCHEME, participantId); @@ -426,7 +426,7 @@ public class ResourceControllerTest extends AbstractControllerTest { } @Test - public void adminCanAssignNewServiceGroupToOtherOwner() throws Exception { + void adminCanAssignNewServiceGroupToOtherOwner() throws Exception { String participantId = UUID.randomUUID().toString(); String resourceExample = getSampleServiceGroupBody(IDENTIFIER_SCHEME, participantId); String urlPath = format("/%s::%s", IDENTIFIER_SCHEME, participantId); @@ -442,7 +442,7 @@ public class ResourceControllerTest extends AbstractControllerTest { } @Test - public void adminCannotAssignNewServiceGroupToNotExistingOwner() throws Exception { + void adminCannotAssignNewServiceGroupToNotExistingOwner() throws Exception { String participantId = UUID.randomUUID().toString(); String resourceExample = getSampleServiceGroupBody(IDENTIFIER_SCHEME, participantId); String urlPath = format("/%s::%s", IDENTIFIER_SCHEME, participantId); diff --git a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/error/ErrorResponseBuilderTest.java b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/error/ErrorResponseBuilderTest.java index a307ce132e43db7520218960d695f89386dbe6bb..5cc175af7f0fb7b29c8f32333fff57651bbbbbb5 100644 --- a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/error/ErrorResponseBuilderTest.java +++ b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/error/ErrorResponseBuilderTest.java @@ -21,7 +21,7 @@ package eu.europa.ec.edelivery.smp.error; import eu.europa.ec.edelivery.smp.error.xml.ErrorResponse; import eu.europa.ec.edelivery.smp.exceptions.ErrorBusinessCode; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.http.ResponseEntity; import org.xml.sax.SAXException; @@ -31,14 +31,14 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import static eu.europa.ec.edelivery.smp.exceptions.ErrorBusinessCode.*; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.springframework.http.HttpStatus.BAD_REQUEST; import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR; /** * Created by migueti on 06/01/2017. */ -public class ErrorResponseBuilderTest { +class ErrorResponseBuilderTest { private final Pattern PATTERN = Pattern.compile(".*?(:).*?(:).*?(:)([A-Z0-9]{8}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{12})", Pattern.CASE_INSENSITIVE | Pattern.DOTALL); @@ -47,7 +47,7 @@ public class ErrorResponseBuilderTest { private final String DEFAULT_ERROR_DESCRIPTION = "Unexpected technical error occurred."; @Test - public void testDifferentErrorIds() throws ParserConfigurationException, IOException, SAXException { + void testDifferentErrorIds() throws ParserConfigurationException, IOException, SAXException { ResponseEntity result1 = ErrorResponseBuilder.status(INTERNAL_SERVER_ERROR).build(); ResponseEntity result2 = ErrorResponseBuilder.status(INTERNAL_SERVER_ERROR).build(); @@ -67,7 +67,7 @@ public class ErrorResponseBuilderTest { } @Test - public void testDifferentErrorIdsWithBusinessCodeAndErrorDescription() throws ParserConfigurationException, IOException, SAXException { + void testDifferentErrorIdsWithBusinessCodeAndErrorDescription() throws ParserConfigurationException, IOException, SAXException { ResponseEntity result1 = ErrorResponseBuilder.status(INTERNAL_SERVER_ERROR).businessCode(OTHER_ERROR).errorDescription("Business Error Description").build(); ResponseEntity result2 = ErrorResponseBuilder.status(INTERNAL_SERVER_ERROR).businessCode(OTHER_ERROR).errorDescription("Business Error Description").build(); @@ -89,7 +89,7 @@ public class ErrorResponseBuilderTest { } @Test - public void testBusinessCode() throws ParserConfigurationException, IOException, SAXException { + void testBusinessCode() throws ParserConfigurationException, IOException, SAXException { final ErrorBusinessCode BC_BUSINESS_CODE = MISSING_FIELD; ResponseEntity result = ErrorResponseBuilder.status(INTERNAL_SERVER_ERROR).businessCode(BC_BUSINESS_CODE).build(); @@ -101,7 +101,7 @@ public class ErrorResponseBuilderTest { } @Test - public void testErrorDescription() throws ParserConfigurationException, IOException, SAXException { + void testErrorDescription() throws ParserConfigurationException, IOException, SAXException { final String STR_ERROR_DESCRIPTION = "Business Error Description"; ResponseEntity result = ErrorResponseBuilder.status(INTERNAL_SERVER_ERROR).errorDescription(STR_ERROR_DESCRIPTION).build(); @@ -113,7 +113,7 @@ public class ErrorResponseBuilderTest { } @Test - public void testBuildWithStatus() throws IOException, SAXException, ParserConfigurationException { + void testBuildWithStatus() throws IOException, SAXException, ParserConfigurationException { ResponseEntity result = ErrorResponseBuilder.status(BAD_REQUEST).build(); assertNotNull(result); @@ -124,7 +124,7 @@ public class ErrorResponseBuilderTest { } @Test - public void testBuildTwoInstancesWithStatus() throws IOException, SAXException, ParserConfigurationException { + void testBuildTwoInstancesWithStatus() throws IOException, SAXException, ParserConfigurationException { ResponseEntity result1 = ErrorResponseBuilder.status(BAD_REQUEST).build(); ResponseEntity result2 = ErrorResponseBuilder.status(INTERNAL_SERVER_ERROR).build(); @@ -141,7 +141,7 @@ public class ErrorResponseBuilderTest { assertEquals(INTERNAL_SERVER_ERROR.value(), result2.getStatusCodeValue()); } - private String checkXmlError(ErrorResponse errorResponse, ErrorBusinessCode errorBusinessCode, String errorDescription) throws ParserConfigurationException, IOException, SAXException { + private String checkXmlError(ErrorResponse errorResponse, ErrorBusinessCode errorBusinessCode, String errorDescription) { assertNotNull(errorResponse); assertEquals(errorBusinessCode.toString(), errorResponse.getBusinessCode()); diff --git a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/error/SMPSecurityExceptionHandlerTest.java b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/error/SMPSecurityExceptionHandlerTest.java index 9f8d0e96477cce6603a7f590a41c3fdaf55ab097..e8aed031301602a9a13247b25693d64ae43c7699 100644 --- a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/error/SMPSecurityExceptionHandlerTest.java +++ b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/error/SMPSecurityExceptionHandlerTest.java @@ -23,7 +23,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import eu.europa.ec.edelivery.smp.error.xml.ErrorResponse; import eu.europa.ec.edelivery.smp.exceptions.ErrorBusinessCode; import eu.europa.ec.edelivery.smp.ui.ResourceConstants; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import javax.servlet.http.HttpServletRequest; @@ -32,16 +32,16 @@ import javax.xml.bind.JAXBException; import java.io.IOException; import java.io.StringReader; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.mock; import static org.springframework.http.HttpStatus.UNAUTHORIZED; -public class SMPSecurityExceptionHandlerTest { +class SMPSecurityExceptionHandlerTest { SMPSecurityExceptionHandler testInstance = new SMPSecurityExceptionHandler(); @Test - public void isUITRestRequestPublic() { + void isUITRestRequestPublic() { // given HttpServletRequest request = mock(HttpServletRequest.class); Mockito.doReturn(ResourceConstants.CONTEXT_PATH_PUBLIC_SEARCH_PARTICIPANT).when(request).getRequestURI(); @@ -52,7 +52,7 @@ public class SMPSecurityExceptionHandlerTest { } @Test - public void isUITRestRequestInternal() { + void isUITRestRequestInternal() { // given HttpServletRequest request = mock(HttpServletRequest.class); Mockito.doReturn("smp" + ResourceConstants.CONTEXT_PATH_INTERNAL_APPLICATION).when(request).getRequestURI(); @@ -63,7 +63,7 @@ public class SMPSecurityExceptionHandlerTest { } @Test - public void isUITRestRequestSMPServiceEndpoint() { + void isUITRestRequestSMPServiceEndpoint() { // given HttpServletRequest request = mock(HttpServletRequest.class); Mockito.doReturn("/smp").when(request).getContextPath(); @@ -75,7 +75,7 @@ public class SMPSecurityExceptionHandlerTest { @Test - public void marshallToXML() throws JAXBException { + void marshallToXML() throws JAXBException { ErrorResponse error = ErrorResponseBuilder.status(UNAUTHORIZED) .businessCode(ErrorBusinessCode.UNAUTHORIZED) .errorDescription("Test error Message") @@ -95,7 +95,7 @@ public class SMPSecurityExceptionHandlerTest { } @Test - public void marshallToJSon() throws IOException { + void marshallToJSon() throws IOException { ErrorResponse error = ErrorResponseBuilder.status(UNAUTHORIZED) .businessCode(ErrorBusinessCode.UNAUTHORIZED) .errorDescription("Test json error Message") @@ -112,7 +112,7 @@ public class SMPSecurityExceptionHandlerTest { assertEquals(error.getErrorUniqueId(), result.getErrorUniqueId()); } @Test - public void marshallUIError() throws JsonProcessingException { + void marshallUIError() throws JsonProcessingException { HttpServletRequest request = mock(HttpServletRequest.class); Mockito.doReturn(ResourceConstants.CONTEXT_PATH_PUBLIC_SEARCH_PARTICIPANT).when(request).getRequestURI(); ErrorResponse error = ErrorResponseBuilder.status(UNAUTHORIZED) @@ -132,7 +132,7 @@ public class SMPSecurityExceptionHandlerTest { } @Test - public void marshallXMLError() throws JAXBException { + void marshallXMLError() throws JAXBException { HttpServletRequest request = mock(HttpServletRequest.class); Mockito.doReturn("/smp/test-test-test::0001:test").when(request).getRequestURI(); ErrorResponse error = ErrorResponseBuilder.status(UNAUTHORIZED) diff --git a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/error/ServiceErrorControllerAdviceTest.java b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/error/ServiceErrorControllerAdviceTest.java index e33e86be89431362a13fc600df366168955f476d..8376f2bea6c9c10f791c0541803b1f6dffdff74d 100644 --- a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/error/ServiceErrorControllerAdviceTest.java +++ b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/error/ServiceErrorControllerAdviceTest.java @@ -22,20 +22,20 @@ import eu.europa.ec.dynamicdiscovery.exception.MalformedIdentifierException; import eu.europa.ec.edelivery.smp.error.xml.ErrorResponse; import eu.europa.ec.edelivery.smp.exceptions.BadRequestException; import eu.europa.ec.edelivery.smp.exceptions.ErrorBusinessCode; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.http.ResponseEntity; import org.springframework.security.access.AccessDeniedException; import org.springframework.security.core.AuthenticationException; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.*; import static org.springframework.http.HttpStatus.*; -public class ServiceErrorControllerAdviceTest { +class ServiceErrorControllerAdviceTest { ServiceErrorControllerAdvice testIntance = new ServiceErrorControllerAdvice(); @Test - public void handleRuntimeException() { + void handleRuntimeException() { ResponseEntity re = testIntance.handleRuntimeException(new RuntimeException("RuntimeExceptionMessage")); assertEquals(INTERNAL_SERVER_ERROR, re.getStatusCode()); @@ -45,7 +45,7 @@ public class ServiceErrorControllerAdviceTest { } @Test - public void handleBadRequestException() { + void handleBadRequestException() { ResponseEntity re = testIntance.handleBadRequestException(new BadRequestException(ErrorBusinessCode.WRONG_FIELD, "BadRequestExceptionMessage")); @@ -55,7 +55,7 @@ public class ServiceErrorControllerAdviceTest { @Test - public void handleMalformedIdentifierException() { + void handleMalformedIdentifierException() { ResponseEntity re = testIntance.handleMalformedIdentifierException(new MalformedIdentifierException("MalformedIdentifierExceptionMessage", null)); assertEquals(BAD_REQUEST, re.getStatusCode()); @@ -63,7 +63,7 @@ public class ServiceErrorControllerAdviceTest { } @Test - public void handleAuthenticationException() { + void handleAuthenticationException() { ResponseEntity re = testIntance.handleRuntimeException(new AuthenticationException("AuthenticationException") { @Override @@ -77,7 +77,7 @@ public class ServiceErrorControllerAdviceTest { } @Test - public void handleAccessDeniedException() { + void handleAccessDeniedException() { ResponseEntity re = testIntance.handleAccessDeniedException(new AccessDeniedException("AccessDeniedExceptionMessage")); assertEquals(UNAUTHORIZED, re.getStatusCode()); @@ -86,7 +86,7 @@ public class ServiceErrorControllerAdviceTest { /* @Test - public void handleXmlInvalidAgainstSchemaException() { + void handleXmlInvalidAgainstSchemaException() { ResponseEntity re = testIntance.handleXmlInvalidAgainstSchemaException( new XmlInvalidAgainstSchemaException("XmlInvalidAgainstSchemaExceptionMessage", null)); diff --git a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/monitor/MonitorControllerIT.java b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/monitor/MonitorControllerIT.java index bd018b536508aeabf20064af5604bbbf94cb9258..03620a1038c26ef71926ff421c1ea685c3b4f2bc 100644 --- a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/monitor/MonitorControllerIT.java +++ b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/monitor/MonitorControllerIT.java @@ -36,7 +36,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. * @author Joze Rihtarsic * @since 4.1 */ -public class MonitorControllerIT extends AbstractControllerTest { +class MonitorControllerIT extends AbstractControllerTest { private static final String URL = "/monitor/is-alive"; private static final RequestPostProcessor ADMIN_CREDENTIALS = httpBasic("pat_smp_admin", "123456"); @@ -50,13 +50,13 @@ public class MonitorControllerIT extends AbstractControllerTest { } @Test - public void isAliveNotAuthorized() throws Exception { + void isAliveNotAuthorized() throws Exception { mvc.perform(get(URL)) .andExpect(status().isUnauthorized()); } @Test - public void isAlive() throws Exception { + void isAlive() throws Exception { mvc.perform(get(URL) .with(ADMIN_CREDENTIALS)) .andExpect(status() @@ -64,7 +64,7 @@ public class MonitorControllerIT extends AbstractControllerTest { } @Test - public void testDatabase() { + void testDatabase() { // when boolean result = testInstance.testDatabase(); diff --git a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/server/security/SecurityConfigurationClientCertTest.java b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/server/security/SecurityConfigurationClientCertTest.java index bee3fa88390526498d22dacc8455863b547a18f0..f8a35ab2e8fb0268b8e31468d8a9fa6d4700676d 100644 --- a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/server/security/SecurityConfigurationClientCertTest.java +++ b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/server/security/SecurityConfigurationClientCertTest.java @@ -27,7 +27,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; -import org.junit.runners.Parameterized; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -76,7 +75,6 @@ public class SecurityConfigurationClientCertTest { public static final String RETURN_LOGGED_USER_PATH = "/getLoggedUsername"; - @Parameterized.Parameters public static Iterable<Object[]> data() { return Arrays.asList(new Object[][]{ { @@ -162,7 +160,7 @@ public class SecurityConfigurationClientCertTest { @ParameterizedTest @MethodSource("data") - public void validClientCertHeaderAuthorizedForPutTest( + void validClientCertHeaderAuthorizedForPutTest( String testName, String expectedCertificateId, String certificateDn, diff --git a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/server/security/SecurityConfigurationTest.java b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/server/security/SecurityConfigurationTest.java index 9cc7160b804fe3930b52704d86dd816adb08ae09..4a2b86dfda199232b76dd44adf9fba6614179cfe 100644 --- a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/server/security/SecurityConfigurationTest.java +++ b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/server/security/SecurityConfigurationTest.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -25,16 +25,15 @@ import eu.europa.ec.edelivery.smp.data.dao.ConfigurationDao; import eu.europa.ec.edelivery.smp.test.SmpTestWebAppConfig; import eu.europa.ec.edelivery.smp.test.testutils.MockMvcUtils; import eu.europa.ec.edelivery.smp.test.testutils.X509CertificateTestUtils; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpHeaders; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.jdbc.Sql; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; @@ -43,6 +42,8 @@ import org.springframework.web.context.WebApplicationContext; import java.io.IOException; import static org.hamcrest.Matchers.containsString; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.httpBasic; import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.BEFORE_TEST_METHOD; @@ -52,7 +53,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. /** * Created by gutowpa on 20/02/2017. */ -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @WebAppConfiguration @ContextConfiguration(classes = {SmpTestWebAppConfig.class}) @Sql(scripts = { @@ -80,149 +81,147 @@ public class SecurityConfigurationTest { MockMvc mvc; - @Before + @BeforeEach public void setup() throws IOException { X509CertificateTestUtils.reloadKeystores(); - configurationDao.setPropertyToDatabase(SMPPropertyEnum.EXTERNAL_TLS_AUTHENTICATION_CLIENT_CERT_HEADER_ENABLED,"true", null); + configurationDao.setPropertyToDatabase(SMPPropertyEnum.EXTERNAL_TLS_AUTHENTICATION_CLIENT_CERT_HEADER_ENABLED, "true", null); configurationDao.reloadPropertiesFromDatabase(); mvc = MockMvcUtils.initializeMockMvc(context); configurationDao.contextRefreshedEvent(); } @Test - public void getMethodAccessiblePubliclyTest() throws Exception { + void getMethodAccessiblePubliclyTest() throws Exception { mvc.perform(MockMvcRequestBuilders.get(RETURN_LOGGED_USER_PATH) - .with(csrf())) + .with(csrf())) .andExpect(status().isOk()) .andExpect(content().string(containsString("anonymousUser"))); } @Test - public void notAuthenticatedUserCannotCallPutTest() throws Exception { + void notAuthenticatedUserCannotCallPutTest() throws Exception { mvc.perform(MockMvcRequestBuilders.put(RETURN_LOGGED_USER_PATH) - .with(csrf())) + .with(csrf())) .andExpect(status().isUnauthorized()); } @Test - public void notAuthenticatedUserCannotCallDeleteTest() throws Exception { + void notAuthenticatedUserCannotCallDeleteTest() throws Exception { mvc.perform(MockMvcRequestBuilders.delete(RETURN_LOGGED_USER_PATH) - .with(csrf())) + .with(csrf())) .andExpect(status().isUnauthorized()); } @Test - public void userStoredWithHashedPassIsAuthorizedForPutTest() throws Exception { + void userStoredWithHashedPassIsAuthorizedForPutTest() throws Exception { mvc.perform(MockMvcRequestBuilders.put(RETURN_LOGGED_USER_PATH) - .with(httpBasic(TEST_USERNAME_DB_HASHED_PASS, PASSWORD)) - .with(csrf())) + .with(httpBasic(TEST_USERNAME_DB_HASHED_PASS, PASSWORD)) + .with(csrf())) .andExpect(status().isOk()) .andExpect(content().string(containsString(TEST_USERNAME_DB_HASHED_PASS))); } @Test - public void userStoredWithUpperCaseUsernameIsAuthorizedForPutTestIdCaseSensitive() throws Exception { + void userStoredWithUpperCaseUsernameIsAuthorizedForPutTestIdCaseSensitive() throws Exception { String upperCaseUsername = TEST_USERNAME_DB_HASHED_PASS.toUpperCase(); // test that is not the same - Assert.assertNotEquals(upperCaseUsername, TEST_USERNAME_DB_HASHED_PASS); + assertNotEquals(upperCaseUsername, TEST_USERNAME_DB_HASHED_PASS); mvc.perform(MockMvcRequestBuilders.put(RETURN_LOGGED_USER_PATH) - .with(httpBasic(upperCaseUsername, PASSWORD)) - .with(csrf())) + .with(httpBasic(upperCaseUsername, PASSWORD)) + .with(csrf())) .andExpect(status().isUnauthorized()); } @Test - public void userStoredWithClearPassIsNotAuthorizedForPutTest() throws Exception { + void userStoredWithClearPassIsNotAuthorizedForPutTest() throws Exception { mvc.perform(MockMvcRequestBuilders.put(RETURN_LOGGED_USER_PATH) - .with(httpBasic(TEST_USERNAME_DB_CLEAR_PASS, PASSWORD)).with(csrf())) + .with(httpBasic(TEST_USERNAME_DB_CLEAR_PASS, PASSWORD)).with(csrf())) .andExpect(status().isUnauthorized()); } - @Test(expected = ClientCertParseException.class) - public void malformedClientCertHeaderNotAuthorizedTest() throws Exception { + @Test + void malformedClientCertHeaderNotAuthorizedTest() { HttpHeaders headers = new HttpHeaders(); headers.add("Client-Cert", "malformed header value"); - mvc.perform(MockMvcRequestBuilders.put(RETURN_LOGGED_USER_PATH) - .headers(headers).with(csrf())) - .andExpect(status().isUnauthorized()); + assertThrows(ClientCertParseException.class, () -> mvc.perform(MockMvcRequestBuilders.put(RETURN_LOGGED_USER_PATH) + .headers(headers).with(csrf())) + .andExpect(status().isUnauthorized())); } @Test - public void validClientCertHeaderAuthorizedForPutTest() throws Exception { + void validClientCertHeaderAuthorizedForPutTest() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.add("Client-Cert", CLIENT_CERT_VALID_HEADER); String result = mvc.perform(MockMvcRequestBuilders.put(RETURN_LOGGED_USER_PATH) - .headers(headers) - .with(csrf())) + .headers(headers) + .with(csrf())) .andExpect(status().isOk()) .andExpect(content().string(containsString(TEST_USERNAME_CLIENT_CERT))) .andReturn().getResponse().getContentAsString(); } @Test - public void ClientCertHeaderNotAuthorizedForPutTest() throws Exception { + void ClientCertHeaderNotAuthorizedForPutTest() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.add("Client-Cert", CLIENT_CERT_NOT_AUTHORIZED_HEADER); mvc.perform(MockMvcRequestBuilders.put(RETURN_LOGGED_USER_PATH) - .headers(headers).with(csrf())) + .headers(headers).with(csrf())) .andExpect(status().isUnauthorized()); } @Test - @Ignore - public void validClientCertHeaderAuthorizedBeforeValidBasicAuthTest() throws Exception { + @Disabled + void validClientCertHeaderAuthorizedBeforeValidBasicAuthTest() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.add("Client-Cert", CLIENT_CERT_VALID_HEADER); mvc.perform(MockMvcRequestBuilders.put(RETURN_LOGGED_USER_PATH) - .headers(headers) - .with(httpBasic(TEST_USERNAME_DB_HASHED_PASS, PASSWORD)) - .with(csrf())) + .headers(headers) + .with(httpBasic(TEST_USERNAME_DB_HASHED_PASS, PASSWORD)) + .with(csrf())) .andExpect(status().isOk()) .andExpect(content().string(containsString(TEST_USERNAME_CLIENT_CERT))); } @Test - @Ignore - public void validClientCertHeaderAuthorizedBeforeValidBasicAuthTestUpper() throws Exception { + @Disabled + void validClientCertHeaderAuthorizedBeforeValidBasicAuthTestUpper() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.add("Client-Cert", CLIENT_CERT_VALID_HEADER_UPPER_SN); mvc.perform(MockMvcRequestBuilders.put(RETURN_LOGGED_USER_PATH) - .headers(headers) - .with(httpBasic(TEST_USERNAME_DB_HASHED_PASS, PASSWORD)) - .with(csrf())) + .headers(headers) + .with(httpBasic(TEST_USERNAME_DB_HASHED_PASS, PASSWORD)) + .with(csrf())) .andExpect(status().isOk()) .andExpect(content().string(containsString(TEST_USERNAME_CLIENT_CERT))); } @Test - @Ignore - public void validClientCertHeaderAuthorizedBeforeValidBasicAuthTestDBUpperSN() throws Exception { + @Disabled + void validClientCertHeaderAuthorizedBeforeValidBasicAuthTestDBUpperSN() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.add("Client-Cert", CLIENT_CERT_VALID_HEADER_DB_UPPER_SN); mvc.perform(MockMvcRequestBuilders.put(RETURN_LOGGED_USER_PATH) - .headers(headers) - .with(httpBasic(TEST_USERNAME_DB_HASHED_PASS, PASSWORD)) - .with(csrf())) + .headers(headers) + .with(httpBasic(TEST_USERNAME_DB_HASHED_PASS, PASSWORD)) + .with(csrf())) .andExpect(status().isOk()) .andExpect(content().string(containsString(TEST_USERNAME_CLIENT_CERT_DB_UPPER_SN))).toString(); } @Test - @Ignore - public void validClientCertHeaderAuthorizedBeforeValidBasicAuthTestUpperDBUpperSN() throws Exception { + @Disabled + void validClientCertHeaderAuthorizedBeforeValidBasicAuthTestUpperDBUpperSN() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.add("Client-Cert", CLIENT_CERT_VALID_HEADER_DB_UPPER_SN); mvc.perform(MockMvcRequestBuilders.put(RETURN_LOGGED_USER_PATH) - .headers(headers) - .with(httpBasic(TEST_USERNAME_DB_HASHED_PASS, PASSWORD)) - .with(csrf())) + .headers(headers) + .with(httpBasic(TEST_USERNAME_DB_HASHED_PASS, PASSWORD)) + .with(csrf())) .andExpect(status().isOk()) .andExpect(content().string(containsString(TEST_USERNAME_CLIENT_CERT_DB_UPPER_SN))); } - - } diff --git a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/server/security/SignatureValidatorTest.java b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/server/security/SignatureValidatorTest.java index 0d5053881bcc61e9e7d535a4e0ca7893d511c45e..d9220d5ef45ab84c830f5e414cd81a4832d98f63 100644 --- a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/server/security/SignatureValidatorTest.java +++ b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/server/security/SignatureValidatorTest.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -24,9 +24,9 @@ import eu.europa.ec.edelivery.security.PreAuthenticatedCertificatePrincipal; import eu.europa.ec.edelivery.smp.test.SmpTestWebAppConfig; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.time.DateUtils; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.mock.web.MockServletContext; import org.springframework.security.core.context.SecurityContextHolder; @@ -34,7 +34,7 @@ import org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfig import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.jdbc.Sql; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.request.RequestPostProcessor; @@ -70,7 +70,7 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @WebAppConfiguration @ContextConfiguration(classes = {SmpTestWebAppConfig.class}) @Sql(scripts = { @@ -91,7 +91,7 @@ public class SignatureValidatorTest { private MockMvc mvc; - @Before + @BeforeEach public void setup() throws IOException { FileUtils.deleteDirectory(targetDirectory.toFile()); FileUtils.copyDirectory(resourceDirectory.toFile(), targetDirectory.toFile()); @@ -112,7 +112,7 @@ public class SignatureValidatorTest { } @Test - public void validateSignature() throws Throwable { + void validateSignature() throws Throwable { String serviceGroupId = "ehealth-actorid-qns::urn:australia:ncpb"; Principal principal = generateMockValidPrincipal(); @@ -124,7 +124,7 @@ public class SignatureValidatorTest { } @Test - public void validateLinearizedSignature() throws Throwable { + void validateLinearizedSignature() throws Throwable { String serviceGroupId = "ehealth-actorid-qns::urn:brazil:ncpb"; Principal principal = generateMockValidPrincipal(); String filePathToLoad = "/input/ServiceMetadata_linarized.xml"; @@ -159,9 +159,9 @@ public class SignatureValidatorTest { //When //Save ServiceMetadata mvc.perform(put(uri).header("Domain", "domain") - .with(ADMIN_CREDENTIALS) - .contentType(APPLICATION_XML_VALUE) - .content(signedByCustomizedSignature)) + .with(ADMIN_CREDENTIALS) + .contentType(APPLICATION_XML_VALUE) + .content(signedByCustomizedSignature)) .andExpect(status().is2xxSuccessful()); //Retrieve saved ServiceMetadata diff --git a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/test/testutils/MockMvcUtils.java b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/test/testutils/MockMvcUtils.java index 0c70be0e36f014f1f461107222fb835a3a2977e0..4e0412ceecc533c9c1db2a7a04054a1c0bf10d81 100644 --- a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/test/testutils/MockMvcUtils.java +++ b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/test/testutils/MockMvcUtils.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -46,7 +46,7 @@ import java.io.UnsupportedEncodingException; import java.util.List; import static eu.europa.ec.edelivery.smp.ui.ResourceConstants.*; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.httpBasic; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; diff --git a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/AuthenticationResourceIT.java b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/AuthenticationResourceIT.java index 4648f568ba76991f544ce647742a9cd11f6cb8f7..bc84916dc98d76b08fb1e18ff139a2cdc6239580 100644 --- a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/AuthenticationResourceIT.java +++ b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/AuthenticationResourceIT.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -24,15 +24,15 @@ import eu.europa.ec.edelivery.smp.services.ui.UIKeystoreService; import eu.europa.ec.edelivery.smp.test.SmpTestWebAppConfig; import eu.europa.ec.edelivery.smp.test.testutils.MockMvcUtils; import eu.europa.ec.edelivery.smp.test.testutils.X509CertificateTestUtils; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.jdbc.Sql; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.web.context.WebApplicationContext; @@ -40,20 +40,20 @@ import org.springframework.web.context.WebApplicationContext; import javax.servlet.http.HttpSession; import java.io.IOException; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.BEFORE_TEST_METHOD; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @WebAppConfiguration @ContextConfiguration(classes = {SmpTestWebAppConfig.class}) @Sql(scripts = { "classpath:/cleanup-database.sql", "classpath:/webapp_integration_test_data.sql"}, executionPhase = BEFORE_TEST_METHOD) -public class AuthenticationResourceIT { +class AuthenticationResourceIT { private static final Logger LOG = LoggerFactory.getLogger(AuthenticationResourceIT.class); @@ -72,7 +72,7 @@ public class AuthenticationResourceIT { private MockMvc mvc; - @Before + @BeforeEach public void setup() throws IOException { X509CertificateTestUtils.reloadKeystores(); mvc = MockMvcUtils.initializeMockMvc(webAppContext); @@ -81,7 +81,7 @@ public class AuthenticationResourceIT { } @Test - public void authenticateSuccessTest() throws Exception { + void authenticateSuccessTest() throws Exception { // given when HttpSession session = mvc.perform(post(PATH) .header("Content-Type", "application/json") @@ -95,7 +95,7 @@ public class AuthenticationResourceIT { @Test - public void authenticateInvalidPasswordTest() throws Exception { + void authenticateInvalidPasswordTest() throws Exception { // given when then mvc.perform(post(PATH) .header("Content-Type", "application/json") @@ -106,7 +106,7 @@ public class AuthenticationResourceIT { } @Test - public void authenticateInvalidUsernameTest() throws Exception { + void authenticateInvalidUsernameTest() throws Exception { // given when mvc.perform(post(PATH) diff --git a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/AuthenticationResourceTest.java b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/AuthenticationResourceTest.java index 32705e9daa1ef7804c1936a551ed5b444c1bfd01..438326fbb19c7146a46c3eb93798abe2773051c7 100644 --- a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/AuthenticationResourceTest.java +++ b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/AuthenticationResourceTest.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -24,8 +24,7 @@ import eu.europa.ec.edelivery.smp.data.ui.UserRO; import eu.europa.ec.edelivery.smp.services.ConfigurationService; import eu.europa.ec.edelivery.smp.services.ui.UIUserService; import eu.europa.ec.edelivery.smp.utils.SMPCookieWriter; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.security.web.csrf.CsrfTokenRepository; import org.springframework.web.servlet.view.RedirectView; @@ -35,8 +34,10 @@ import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import static eu.europa.ec.edelivery.smp.utils.SMPCookieWriter.SESSION_COOKIE_NAME; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; -public class AuthenticationResourceTest { +class AuthenticationResourceTest { SMPAuthenticationService authenticationService = Mockito.mock(SMPAuthenticationService.class); SMPAuthorizationService authorizationService = Mockito.mock(SMPAuthorizationService.class); @@ -53,7 +54,7 @@ public class AuthenticationResourceTest { uiUserService); @Test - public void logout() { + void logout() { HttpServletRequest request = Mockito.mock(HttpServletRequest.class); HttpServletResponse response = Mockito.mock(HttpServletResponse.class); Mockito.doNothing().when(authenticationService).logout(Mockito.any(), Mockito.any()); @@ -63,23 +64,23 @@ public class AuthenticationResourceTest { } @Test - public void authenticateCAS() { + void authenticateCAS() { RedirectView result = testInstance.authenticateCAS(); - Assert.assertNotNull(result); - Assert.assertEquals("../../../#/", result.getUrl()); + assertNotNull(result); + assertEquals("../../../#/", result.getUrl()); } @Test - public void getUser() { + void getUser() { UserRO user = new UserRO(); Mockito.doReturn(user).when(authorizationService).getLoggedUserData(); UserRO result = testInstance.getUser(); - Assert.assertEquals(user, result); + assertEquals(user, result); } @Test - public void recreatedSessionCookie() { + void recreatedSessionCookie() { String cookieName = SESSION_COOKIE_NAME; String cookieValue = "CookieValue"; boolean sessionCookieSecure = true; diff --git a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/edit/DocumentEditControllerIT.java b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/edit/DocumentEditControllerIT.java index c292ad005efe36d51d2f731d2f4983929080d54c..6dd9b2cf45d118e126888d39ec5d83945232b6f6 100644 --- a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/edit/DocumentEditControllerIT.java +++ b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/edit/DocumentEditControllerIT.java @@ -56,7 +56,7 @@ class DocumentEditControllerIT extends AbstractControllerTest { } @Test - public void testGetDocumentForNewResource() throws Exception { + void testGetDocumentForNewResource() throws Exception { // given when MockHttpSession session = loginWithSystemAdmin(mvc); UserRO userRO = getLoggedUserData(mvc, session); @@ -83,7 +83,7 @@ class DocumentEditControllerIT extends AbstractControllerTest { } @Test - public void testGetDocumentForResource() throws Exception { + void testGetDocumentForResource() throws Exception { // given when MockHttpSession session = loginWithSystemAdmin(mvc); UserRO userRO = getLoggedUserData(mvc, session); @@ -113,7 +113,7 @@ class DocumentEditControllerIT extends AbstractControllerTest { } @Test - public void testValidateDocumentOk() throws Exception { + void testValidateDocumentOk() throws Exception { // given when MockHttpSession session = loginWithSystemAdmin(mvc); UserRO userRO = getLoggedUserData(mvc, session); @@ -144,7 +144,7 @@ class DocumentEditControllerIT extends AbstractControllerTest { } @Test - public void testValidateDocumentInvalid() throws Exception { + void testValidateDocumentInvalid() throws Exception { // given when MockHttpSession session = loginWithSystemAdmin(mvc); UserRO userRO = getLoggedUserData(mvc, session); @@ -180,7 +180,7 @@ class DocumentEditControllerIT extends AbstractControllerTest { } @Test - public void testGenerateDocument() throws Exception { + void testGenerateDocument() throws Exception { // given when MockHttpSession session = loginWithSystemAdmin(mvc); UserRO userRO = getLoggedUserData(mvc, session); diff --git a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/edit/DomainEditControllerIT.java b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/edit/DomainEditControllerIT.java index 35228130ffce25d704d880be397eae48809b9835..ebb49801a21df07576cd9a7bdf893567f44d5367 100644 --- a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/edit/DomainEditControllerIT.java +++ b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/edit/DomainEditControllerIT.java @@ -46,7 +46,7 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -public class DomainEditControllerIT extends AbstractControllerTest { +class DomainEditControllerIT extends AbstractControllerTest { private static final String PATH = CONTEXT_PATH_EDIT_DOMAIN; @Autowired @@ -65,7 +65,7 @@ public class DomainEditControllerIT extends AbstractControllerTest { "group-admin, 1", "resource-admin, 1", }) - public void testGetDomains(String roleType, int values) throws Exception { + void testGetDomains(String roleType, int values) throws Exception { // given when MockHttpSession session = loginWithSystemAdmin(mvc); UserRO userRO = getLoggedUserData(mvc, session); @@ -87,7 +87,7 @@ public class DomainEditControllerIT extends AbstractControllerTest { @Test - public void testGetDomainMembers() throws Exception { + void testGetDomainMembers() throws Exception { // given MockHttpSession session = loginWithSystemAdmin(mvc); UserRO userRO = getLoggedUserData(mvc, session); @@ -112,7 +112,7 @@ public class DomainEditControllerIT extends AbstractControllerTest { } @Test - public void testAddDomainMember() throws Exception { + void testAddDomainMember() throws Exception { // given MockHttpSession session = loginWithSystemAdmin(mvc); UserRO userRO = getLoggedUserData(mvc, session); @@ -128,7 +128,7 @@ public class DomainEditControllerIT extends AbstractControllerTest { } @Test - public void testDeleteDomainMember() throws Exception { + void testDeleteDomainMember() throws Exception { // given MockHttpSession session = loginWithSystemAdmin(mvc); UserRO userRO = getLoggedUserData(mvc, session); @@ -150,7 +150,7 @@ public class DomainEditControllerIT extends AbstractControllerTest { } @Test - public void testUpdateDomainMember() throws Exception { + void testUpdateDomainMember() throws Exception { // given MockHttpSession session = loginWithSystemAdmin(mvc); UserRO userRO = getLoggedUserData(mvc, session); diff --git a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/edit/DomainEditControllerTest.java b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/edit/DomainEditControllerTest.java index 2e7ad61d90c90ccc9e9006c64e7bcabfd1072c30..b56a7b81fad7bdc40de60930e84da30b70ca3194 100644 --- a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/edit/DomainEditControllerTest.java +++ b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/edit/DomainEditControllerTest.java @@ -46,7 +46,7 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -public class DomainEditControllerTest extends AbstractControllerTest { +class DomainEditControllerTest extends AbstractControllerTest { private static final String PATH = CONTEXT_PATH_EDIT_DOMAIN; @Autowired @@ -65,7 +65,7 @@ public class DomainEditControllerTest extends AbstractControllerTest { "group-admin, 1", "resource-admin, 1", }) - public void testGetDomains(String roleType, int values) throws Exception { + void testGetDomains(String roleType, int values) throws Exception { // given when MockHttpSession session = loginWithSystemAdmin(mvc); UserRO userRO = getLoggedUserData(mvc, session); @@ -87,7 +87,7 @@ public class DomainEditControllerTest extends AbstractControllerTest { @Test - public void testGetDomainMembers() throws Exception { + void testGetDomainMembers() throws Exception { // given MockHttpSession session = loginWithSystemAdmin(mvc); UserRO userRO = getLoggedUserData(mvc, session); @@ -112,7 +112,7 @@ public class DomainEditControllerTest extends AbstractControllerTest { } @Test - public void testAddDomainMember() throws Exception { + void testAddDomainMember() throws Exception { // given MockHttpSession session = loginWithSystemAdmin(mvc); UserRO userRO = getLoggedUserData(mvc, session); @@ -128,7 +128,7 @@ public class DomainEditControllerTest extends AbstractControllerTest { } @Test - public void testDeleteDomainMember() throws Exception { + void testDeleteDomainMember() throws Exception { // given MockHttpSession session = loginWithSystemAdmin(mvc); UserRO userRO = getLoggedUserData(mvc, session); @@ -150,7 +150,7 @@ public class DomainEditControllerTest extends AbstractControllerTest { } @Test - public void testUpdateDomainMember() throws Exception { + void testUpdateDomainMember() throws Exception { // given MockHttpSession session = loginWithSystemAdmin(mvc); UserRO userRO = getLoggedUserData(mvc, session); diff --git a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/edit/GroupEditControllerIT.java b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/edit/GroupEditControllerIT.java index 9a9924eb513e58f8d174b71672e49f17cf1ca56e..f017d1d9c101fcad1c2517cbdec5fb68d5149930 100644 --- a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/edit/GroupEditControllerIT.java +++ b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/edit/GroupEditControllerIT.java @@ -49,7 +49,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. * For the test configuration see the webapp_integration_test_data.sql file. * The system admin user is admin member of domain '1' and group '1'. */ -public class GroupEditControllerIT extends AbstractControllerTest { +class GroupEditControllerIT extends AbstractControllerTest { private static final String PATH = CONTEXT_PATH_EDIT_GROUP; @Autowired @@ -69,7 +69,7 @@ public class GroupEditControllerIT extends AbstractControllerTest { "group-viewer, 0", "all-roles, 1" }) - public void testGetGroup(String roleType, int values) throws Exception { + void testGetGroup(String roleType, int values) throws Exception { // given when MockHttpSession session = loginWithSystemAdmin(mvc); UserRO userRO = getLoggedUserData(mvc, session); @@ -90,7 +90,7 @@ public class GroupEditControllerIT extends AbstractControllerTest { } @Test - public void testPutGroup() throws Exception { + void testPutGroup() throws Exception { // given MockHttpSession session = loginWithSystemAdmin(mvc); UserRO userRO = getLoggedUserData(mvc, session); @@ -121,7 +121,7 @@ public class GroupEditControllerIT extends AbstractControllerTest { } @Test - public void testDeleteGroup() throws Exception { + void testDeleteGroup() throws Exception { // given MockHttpSession session = loginWithSystemAdmin(mvc); UserRO userRO = getLoggedUserData(mvc, session); @@ -148,7 +148,7 @@ public class GroupEditControllerIT extends AbstractControllerTest { } @Test - public void testUpdateGroup() throws Exception { + void testUpdateGroup() throws Exception { // given MockHttpSession session = loginWithSystemAdmin(mvc); UserRO userRO = getLoggedUserData(mvc, session); @@ -179,7 +179,7 @@ public class GroupEditControllerIT extends AbstractControllerTest { @Test - public void testGetGroupMembers() throws Exception { + void testGetGroupMembers() throws Exception { // given MockHttpSession session = loginWithSystemAdmin(mvc); UserRO userRO = getLoggedUserData(mvc, session); @@ -206,7 +206,7 @@ public class GroupEditControllerIT extends AbstractControllerTest { @Test - public void testAddGroupMember() throws Exception { + void testAddGroupMember() throws Exception { // given MockHttpSession session = loginWithSystemAdmin(mvc); UserRO userRO = getLoggedUserData(mvc, session); @@ -223,7 +223,7 @@ public class GroupEditControllerIT extends AbstractControllerTest { } @Test - public void testDeleteGroupMember() throws Exception { + void testDeleteGroupMember() throws Exception { // given MockHttpSession session = loginWithSystemAdmin(mvc); UserRO userRO = getLoggedUserData(mvc, session); @@ -245,7 +245,7 @@ public class GroupEditControllerIT extends AbstractControllerTest { } @Test - public void testUpdateGroupMember() throws Exception { + void testUpdateGroupMember() throws Exception { // given MockHttpSession session = loginWithSystemAdmin(mvc); UserRO userRO = getLoggedUserData(mvc, session); diff --git a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/edit/ResourceEditControllerIT.java b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/edit/ResourceEditControllerIT.java index 0f614c20da475890fd73cfa4d85859e8741fd3db..29d08e8d516f344479d1b5eb964095dde1cd38ec 100644 --- a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/edit/ResourceEditControllerIT.java +++ b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/edit/ResourceEditControllerIT.java @@ -53,7 +53,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. * For the test configuration see the webapp_integration_test_data.sql file. * The system admin user is admin member of domain '1' and group '1'. */ -public class ResourceEditControllerIT extends AbstractControllerTest { +class ResourceEditControllerIT extends AbstractControllerTest { private static final String PATH = CONTEXT_PATH_EDIT_RESOURCE; @Autowired @@ -81,7 +81,7 @@ public class ResourceEditControllerIT extends AbstractControllerTest { "'No match at all','', 0", "australia,'', 1", // filter by value match }) - public void testGetResourcesForGroup(String filter, String roleType, int expectedResults) throws Exception { + void testGetResourcesForGroup(String filter, String roleType, int expectedResults) throws Exception { // given when MockHttpSession session = loginWithSystemAdmin(mvc); UserRO userRO = getLoggedUserData(mvc, session); @@ -107,7 +107,7 @@ public class ResourceEditControllerIT extends AbstractControllerTest { } @Test - public void testPutResource() throws Exception { + void testPutResource() throws Exception { // given MockHttpSession session = loginWithSystemAdmin(mvc); UserRO userRO = getLoggedUserData(mvc, session); @@ -145,7 +145,7 @@ public class ResourceEditControllerIT extends AbstractControllerTest { } @Test - public void testDeleteResource() throws Exception { + void testDeleteResource() throws Exception { // given MockHttpSession session = loginWithSystemAdmin(mvc); UserRO userRO = getLoggedUserData(mvc, session); @@ -171,7 +171,7 @@ public class ResourceEditControllerIT extends AbstractControllerTest { } @Test - public void testUpdateResource() throws Exception { + void testUpdateResource() throws Exception { // given MockHttpSession session = loginWithSystemAdmin(mvc); UserRO userRO = getLoggedUserData(mvc, session); @@ -200,7 +200,7 @@ public class ResourceEditControllerIT extends AbstractControllerTest { } @Test - public void testGetGroupMembers() throws Exception { + void testGetGroupMembers() throws Exception { // given MockHttpSession session = loginWithSystemAdmin(mvc); UserRO userRO = getLoggedUserData(mvc, session); @@ -230,7 +230,7 @@ public class ResourceEditControllerIT extends AbstractControllerTest { @Test - public void testAddGroupMember() throws Exception { + void testAddGroupMember() throws Exception { // given MockHttpSession session = loginWithSystemAdmin(mvc); UserRO userRO = getLoggedUserData(mvc, session); @@ -249,7 +249,7 @@ public class ResourceEditControllerIT extends AbstractControllerTest { } @Test - public void testDeleteGroupMember() throws Exception { + void testDeleteGroupMember() throws Exception { // given MockHttpSession session = loginWithSystemAdmin(mvc); UserRO userRO = getLoggedUserData(mvc, session); @@ -274,7 +274,7 @@ public class ResourceEditControllerIT extends AbstractControllerTest { } @Test - public void testUpdateGroupMember() throws Exception { + void testUpdateGroupMember() throws Exception { // given MockHttpSession session = loginWithSystemAdmin(mvc); UserRO userRO = getLoggedUserData(mvc, session); diff --git a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/external/ApplicationResourceIT.java b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/external/ApplicationResourceIT.java index 3ca96a6a7c2074b14e754f6793850ee0f0e77b90..20c309a268be10e54790826aa6b6d4c9099c1024 100644 --- a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/external/ApplicationResourceIT.java +++ b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/external/ApplicationResourceIT.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -25,9 +25,9 @@ import eu.europa.ec.edelivery.smp.data.ui.SmpInfoRO; import eu.europa.ec.edelivery.smp.test.SmpTestWebAppConfig; import eu.europa.ec.edelivery.smp.ui.ResourceConstants; import org.hamcrest.MatcherAssert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.mock.web.MockHttpSession; import org.springframework.mock.web.MockServletContext; @@ -35,7 +35,7 @@ import org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfig import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.jdbc.Sql; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; @@ -48,14 +48,14 @@ import javax.servlet.ServletContextListener; import static eu.europa.ec.edelivery.smp.test.testutils.MockMvcUtils.loginWithSystemAdmin; import static eu.europa.ec.edelivery.smp.test.testutils.MockMvcUtils.loginWithUserGroupAdmin; import static org.hamcrest.CoreMatchers.startsWith; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.BEFORE_TEST_METHOD; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @WebAppConfiguration @ContextConfiguration(classes = {SmpTestWebAppConfig.class}) @Sql(scripts = { @@ -67,7 +67,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. "smp.artifact.version=TestApplicationVersion", "smp.artifact.build.time=2018-11-27 00:00:00", }) -public class ApplicationResourceIT { +class ApplicationResourceIT { private static final String PATH = ResourceConstants.CONTEXT_PATH_PUBLIC_APPLICATION; @Autowired @@ -78,7 +78,7 @@ public class ApplicationResourceIT { private MockMvc mvc; - @Before + @BeforeEach public void setup() { mvc = MockMvcBuilders.webAppContextSetup(webAppContext) .apply(SecurityMockMvcConfigurers.springSecurity()) @@ -93,7 +93,7 @@ public class ApplicationResourceIT { } @Test - public void testGetName() throws Exception { + void testGetName() throws Exception { String value = mvc.perform(get(PATH + "/name")) .andExpect(status().isOk()) .andReturn() @@ -104,13 +104,13 @@ public class ApplicationResourceIT { } @Test - public void getDisplayName() throws Exception { + void getDisplayName() throws Exception { String value = applicationResource.getDisplayVersion(); MatcherAssert.assertThat(value, startsWith("TestApplicationSmpName Version [TestApplicationVersion] Build-Time [2018-11-27 00:00:00")); } @Test - public void getApplicationInfoTest() throws Exception { + void getApplicationInfoTest() throws Exception { String value = mvc.perform(get(PATH + "/info")) .andExpect(status().isOk()) .andReturn() @@ -124,23 +124,23 @@ public class ApplicationResourceIT { } @Test - public void testGetApplicationConfigNotAuthorized() throws Exception { + void testGetApplicationConfigNotAuthorized() throws Exception { // when mvc.perform(get(PATH + "/config") - .with(csrf())) + .with(csrf())) .andExpect(status().isUnauthorized()) .andReturn() .getResponse(); } @Test - public void testGetApplicationConfigAuthorized() throws Exception { + void testGetApplicationConfigAuthorized() throws Exception { // User MockHttpSession sessionUser = loginWithUserGroupAdmin(mvc); String val = mvc.perform(get(PATH + "/config") - .session(sessionUser) - .with(csrf())) + .session(sessionUser) + .with(csrf())) .andExpect(status().isOk()) .andReturn() .getResponse() @@ -149,8 +149,8 @@ public class ApplicationResourceIT { // system admin MockHttpSession sessionSystem = loginWithSystemAdmin(mvc); val = mvc.perform(get(PATH + "/config") - .session(sessionSystem) - .with(csrf())) + .session(sessionSystem) + .with(csrf())) .andExpect(status().isOk()) .andReturn() .getResponse() @@ -159,12 +159,12 @@ public class ApplicationResourceIT { } @Test - public void testGetApplicationConfigUser() throws Exception { + void testGetApplicationConfigUser() throws Exception { // when MockHttpSession session = loginWithUserGroupAdmin(mvc); String value = mvc.perform(get(PATH + "/config") - .session(session) - .with(csrf())) + .session(session) + .with(csrf())) .andExpect(status().isOk()) .andReturn() .getResponse() diff --git a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/external/DomainResourceIT.java b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/external/DomainResourceIT.java index 67d81bf52be31e56817ffb06cb7cdd80d4717a68..f99b019b7f8d133952e18495b7c2d681e3d1a7d1 100644 --- a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/external/DomainResourceIT.java +++ b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/external/DomainResourceIT.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -28,13 +28,13 @@ import eu.europa.ec.edelivery.smp.test.SmpTestWebAppConfig; import eu.europa.ec.edelivery.smp.test.testutils.MockMvcUtils; import eu.europa.ec.edelivery.smp.test.testutils.X509CertificateTestUtils; import eu.europa.ec.edelivery.smp.ui.ResourceConstants; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.jdbc.Sql; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; @@ -42,19 +42,19 @@ import org.springframework.web.context.WebApplicationContext; import java.io.IOException; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @WebAppConfiguration @ContextConfiguration(classes = {SmpTestWebAppConfig.class}) @Sql(scripts = { "/cleanup-database.sql", "/webapp_integration_test_data.sql"}) -public class DomainResourceIT { +class DomainResourceIT { private static final String PATH = ResourceConstants.CONTEXT_PATH_PUBLIC_DOMAIN; @Autowired @@ -67,7 +67,7 @@ public class DomainResourceIT { private MockMvc mvc; - @Before + @BeforeEach public void setup() throws IOException { X509CertificateTestUtils.reloadKeystores(); configurationDao.setPropertyToDatabase(SMPPropertyEnum.EXTERNAL_TLS_AUTHENTICATION_CLIENT_CERT_HEADER_ENABLED, "true", null); @@ -77,7 +77,7 @@ public class DomainResourceIT { } @Test - public void geDomainPublicList() throws Exception { + void geDomainPublicList() throws Exception { // given when MvcResult result = mvc.perform(get(PATH) diff --git a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/external/SearchResourceIT.java b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/external/SearchResourceIT.java index cd349cfcaf15d7529b42bc299a25bbb980938dd0..ff219471c0201416028296c63248558c817f77a9 100644 --- a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/external/SearchResourceIT.java +++ b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/external/SearchResourceIT.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -21,15 +21,15 @@ package eu.europa.ec.edelivery.smp.ui.external; import com.fasterxml.jackson.databind.ObjectMapper; import eu.europa.ec.edelivery.smp.data.ui.ServiceResult; import eu.europa.ec.edelivery.smp.test.SmpTestWebAppConfig; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.mock.web.MockServletContext; import org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.jdbc.Sql; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; @@ -41,8 +41,8 @@ import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; import static eu.europa.ec.edelivery.smp.ui.ResourceConstants.CONTEXT_PATH_PUBLIC_SEARCH_PARTICIPANT; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.BEFORE_TEST_METHOD; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -52,21 +52,21 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. * @author Joze Rihtarsic * @since 4.1 */ -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @WebAppConfiguration @ContextConfiguration(classes = {SmpTestWebAppConfig.class}) @Sql(scripts = { "classpath:/cleanup-database.sql", "classpath:/webapp_integration_test_data.sql"}, executionPhase = BEFORE_TEST_METHOD) -public class SearchResourceIT { +class SearchResourceIT { @Autowired private WebApplicationContext webAppContext; private MockMvc mvc; - @Before + @BeforeEach public void setup() { mvc = MockMvcBuilders.webAppContextSetup(webAppContext) .apply(SecurityMockMvcConfigurers.springSecurity()) @@ -82,7 +82,7 @@ public class SearchResourceIT { } @Test - public void testSearchByAnonymous() throws Exception { + void testSearchByAnonymous() throws Exception { // given when MvcResult result = mvc.perform(get(CONTEXT_PATH_PUBLIC_SEARCH_PARTICIPANT)).andExpect(status().isOk()).andReturn(); diff --git a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/external/UserControllerIT.java b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/external/UserControllerIT.java index 05d2b012d3a09b47e756eb9aad3a6ac360fab7f6..a5d3b3d81129837f2d887b7b30694fd46961a5a3 100644 --- a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/external/UserControllerIT.java +++ b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/external/UserControllerIT.java @@ -44,7 +44,7 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -public class UserControllerIT extends AbstractControllerTest { +class UserControllerIT extends AbstractControllerTest { private static final String PATH = CONTEXT_PATH_PUBLIC_USER; @Autowired @@ -56,7 +56,7 @@ public class UserControllerIT extends AbstractControllerTest { } @Test - public void testGetUserNavigationTreeForSystemAdmin() throws Exception { + void testGetUserNavigationTreeForSystemAdmin() throws Exception { MockHttpSession session = loginWithSystemAdmin(mvc); UserRO userRO = getLoggedUserData(mvc, session); @@ -74,7 +74,7 @@ public class UserControllerIT extends AbstractControllerTest { } @Test - public void testGetUserNavigationTreeForUser() throws Exception { + void testGetUserNavigationTreeForUser() throws Exception { MockHttpSession session = loginWithUser2(mvc); UserRO userRO = getLoggedUserData(mvc, session); @@ -92,7 +92,7 @@ public class UserControllerIT extends AbstractControllerTest { } @Test - public void testLookupUsers() throws Exception { + void testLookupUsers() throws Exception { MockHttpSession session = loginWithUser2(mvc); UserRO userRO = getLoggedUserData(mvc, session); MvcResult response = mvc.perform(get(PATH + "/{user-id}/search", userRO.getUserId()) @@ -107,7 +107,7 @@ public class UserControllerIT extends AbstractControllerTest { } @Test - public void testLookupUsersFilter() throws Exception { + void testLookupUsersFilter() throws Exception { MockHttpSession session = loginWithUser2(mvc); UserRO userRO = getLoggedUserData(mvc, session); MvcResult response = mvc.perform(get(PATH + "/{user-id}/search", userRO.getUserId()).param("filter", userRO.getUsername()) @@ -123,7 +123,7 @@ public class UserControllerIT extends AbstractControllerTest { } @Test - public void testGetUserCredentialStatus() throws Exception { + void testGetUserCredentialStatus() throws Exception { MockHttpSession session = loginWithUser2(mvc); UserRO userRO = getLoggedUserData(mvc, session); MvcResult response = mvc.perform(get(PATH + "/{user-id}/username-credential-status", userRO.getUserId()) @@ -142,7 +142,7 @@ public class UserControllerIT extends AbstractControllerTest { @Test - public void testGetAccessTokenCredentials() throws Exception { + void testGetAccessTokenCredentials() throws Exception { MockHttpSession session = loginWithUser2(mvc); UserRO userRO = getLoggedUserData(mvc, session); MvcResult response = mvc.perform(get(PATH + "/{user-id}/access-token-credentials", userRO.getUserId()) diff --git a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/external/UserResourceIT.java b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/external/UserResourceIT.java index e438f56c818e35f4b23ef78b70fbd74abdfdc609..967dde44df7d554f3bd339d43846d30a45d7fb3d 100644 --- a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/external/UserResourceIT.java +++ b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/external/UserResourceIT.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -25,15 +25,15 @@ import eu.europa.ec.edelivery.smp.data.ui.PasswordChangeRO; import eu.europa.ec.edelivery.smp.data.ui.UserRO; import eu.europa.ec.edelivery.smp.test.SmpTestWebAppConfig; import eu.europa.ec.edelivery.smp.ui.ResourceConstants; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.mock.web.MockHttpSession; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.jdbc.Sql; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; @@ -43,8 +43,8 @@ import javax.ws.rs.core.MediaType; import static eu.europa.ec.edelivery.smp.test.testutils.MockMvcUtils.*; import static eu.europa.ec.edelivery.smp.ui.ResourceConstants.CONTEXT_PATH_PUBLIC_SECURITY_USER; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.BEFORE_TEST_METHOD; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; @@ -54,14 +54,14 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. * @author Joze Rihtarsic * @since 4.1 */ -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @WebAppConfiguration @ContextConfiguration(classes = {SmpTestWebAppConfig.class}) @Sql(scripts = { "classpath:/cleanup-database.sql", "classpath:/webapp_integration_test_data.sql"}, executionPhase = BEFORE_TEST_METHOD) -public class UserResourceIT { +class UserResourceIT { private static final String PATH_PUBLIC = ResourceConstants.CONTEXT_PATH_PUBLIC_USER; @@ -74,14 +74,14 @@ public class UserResourceIT { .findAndAddModules() .build(); - @Before + @BeforeEach public void setup() { mvc = initializeMockMvc(webAppContext); } @Test - public void testUpdateCurrentUserOK() throws Exception { + void testUpdateCurrentUserOK() throws Exception { // login MockHttpSession session = loginWithSystemAdmin(mvc); // when update data @@ -98,7 +98,7 @@ public class UserResourceIT { } @Test - public void testUpdateCurrentUserNotAuthenticatedUser() throws Exception { + void testUpdateCurrentUserNotAuthenticatedUser() throws Exception { // given when - log as SMP admin // then change values and list uses for changed value @@ -119,8 +119,8 @@ public class UserResourceIT { } @Test - @Ignore - public void generateAccessTokenForUser() throws Exception { + @Disabled + void generateAccessTokenForUser() throws Exception { MockHttpSession session = loginWithUser2(mvc); UserRO userRO = getLoggedUserData(mvc, session); assertNotNull(userRO); @@ -144,7 +144,7 @@ public class UserResourceIT { } @Test - public void changePassword() throws Exception { + void changePassword() throws Exception { String newPassword = "TESTtest1234!@#$"; MockHttpSession session = loginWithUser2(mvc); @@ -167,5 +167,4 @@ public class UserResourceIT { MockHttpSession sessionNew = loginWithCredentials(mvc, SG_USER2_USERNAME, newPassword); assertNotNull(sessionNew); } - } diff --git a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/internal/DomainAdminControllerIT.java b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/internal/DomainAdminControllerIT.java index 3e516f0a909e22f84fb90db1c3d71ac4e1442f99..a298efe04d2b1344fb02b09cb6a81e9109d7c4f5 100644 --- a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/internal/DomainAdminControllerIT.java +++ b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/internal/DomainAdminControllerIT.java @@ -50,7 +50,7 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -public class DomainAdminControllerIT extends AbstractControllerTest { +class DomainAdminControllerIT extends AbstractControllerTest { private static final String PATH = ResourceConstants.CONTEXT_PATH_INTERNAL_DOMAIN; @Autowired @@ -62,7 +62,7 @@ public class DomainAdminControllerIT extends AbstractControllerTest { } @Test - public void testGetAllDomains() throws Exception { + void testGetAllDomains() throws Exception { List<DBDomain> domain = domainDao.getAllDomains(); MockHttpSession session = loginWithSystemAdmin(mvc); @@ -79,7 +79,7 @@ public class DomainAdminControllerIT extends AbstractControllerTest { } @Test - public void testCreateBasicDomainData() throws Exception { + void testCreateBasicDomainData() throws Exception { DomainRO testDomain = TestROUtils.createDomain(); MockHttpSession session = loginWithSystemAdmin(mvc); @@ -99,7 +99,7 @@ public class DomainAdminControllerIT extends AbstractControllerTest { } @Test - public void testCreateDomainWithEmptyCode() throws Exception { + void testCreateDomainWithEmptyCode() throws Exception { DomainRO testDomain = TestROUtils.createDomain(""); MockHttpSession session = loginWithSystemAdmin(mvc); @@ -119,7 +119,7 @@ public class DomainAdminControllerIT extends AbstractControllerTest { } @Test - public void testUpdateResourceDefDomainList() throws Exception { + void testUpdateResourceDefDomainList() throws Exception { String domainCode = "domainTwo"; String documentType = "edelivery-oasis-cppa"; MockHttpSession session = loginWithSystemAdmin(mvc); @@ -142,7 +142,7 @@ public class DomainAdminControllerIT extends AbstractControllerTest { } @Test - public void testDeleteDomainOK() throws Exception { + void testDeleteDomainOK() throws Exception { // given - delete domain two :) String domainCode = "domainTwo"; MockHttpSession session = loginWithSystemAdmin(mvc); @@ -163,7 +163,7 @@ public class DomainAdminControllerIT extends AbstractControllerTest { } @Test - public void updateDomainData() throws Exception { + void updateDomainData() throws Exception { String domainCode = "domainTwo"; MockHttpSession session = loginWithSystemAdmin(mvc); UserRO userRO = MockMvcUtils.getLoggedUserData(mvc, session); @@ -185,7 +185,7 @@ public class DomainAdminControllerIT extends AbstractControllerTest { } @Test - public void updateDomainSmlIntegrationData() throws Exception { + void updateDomainSmlIntegrationData() throws Exception { String domainCode = "domainTwo"; MockHttpSession session = loginWithSystemAdmin(mvc); UserRO userRO = (UserRO) session.getAttribute(MOCK_LOGGED_USER); @@ -208,7 +208,7 @@ public class DomainAdminControllerIT extends AbstractControllerTest { } @Test - public void updateDomainDataAddNewResourceDef() throws Exception { + void updateDomainDataAddNewResourceDef() throws Exception { // set the webapp_integration_test_data.sql for resourceDefID String resourceDefID = "edelivery-oasis-cppa"; String domainCode = "domainTwo"; diff --git a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/internal/KeystoreAdminControllerIT.java b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/internal/KeystoreAdminControllerIT.java index f75e67d1a1bd30878336b22928bf52d3d1e9bf64..30742c1cff1ff5781e856a5c4292eeaf0cb2c61b 100644 --- a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/internal/KeystoreAdminControllerIT.java +++ b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/internal/KeystoreAdminControllerIT.java @@ -45,7 +45,7 @@ import static org.springframework.security.test.web.servlet.request.SecurityMock import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -public class KeystoreAdminControllerIT extends AbstractControllerTest { +class KeystoreAdminControllerIT extends AbstractControllerTest { private static final String PATH = CONTEXT_PATH_INTERNAL_KEYSTORE; Path keystore = Paths.get("src", "test", "resources", "keystores", "smp-keystore.jks"); @@ -59,7 +59,7 @@ public class KeystoreAdminControllerIT extends AbstractControllerTest { } @Test - public void getKeyCertificateList() throws Exception { + void getKeyCertificateList() throws Exception { // given when int countStart = uiKeystoreService.getKeystoreEntriesList().size(); MockHttpSession session = loginWithSystemAdmin(mvc); @@ -86,7 +86,7 @@ public class KeystoreAdminControllerIT extends AbstractControllerTest { } @Test - public void uploadKeystoreFailed() throws Exception { + void uploadKeystoreFailed() throws Exception { // given when // login MockHttpSession session = loginWithSystemAdmin(mvc); @@ -105,7 +105,7 @@ public class KeystoreAdminControllerIT extends AbstractControllerTest { } @Test - public void uploadKeystoreInvalidPassword() throws Exception { + void uploadKeystoreInvalidPassword() throws Exception { // login MockHttpSession session = loginWithSystemAdmin(mvc); UserRO userRO = (UserRO) session.getAttribute(MOCK_LOGGED_USER); @@ -123,7 +123,7 @@ public class KeystoreAdminControllerIT extends AbstractControllerTest { } @Test - public void uploadKeystoreOK() throws Exception { + void uploadKeystoreOK() throws Exception { MockHttpSession session = loginWithSystemAdmin(mvc); UserRO userRO = getLoggedUserData(mvc, session); @@ -144,7 +144,7 @@ public class KeystoreAdminControllerIT extends AbstractControllerTest { } @Test - public void deleteCertificateOK() throws Exception { + void deleteCertificateOK() throws Exception { MockHttpSession session = loginWithSystemAdmin(mvc); UserRO userRO = getLoggedUserData(mvc, session); String alias = "second_domain_alias"; @@ -166,7 +166,7 @@ public class KeystoreAdminControllerIT extends AbstractControllerTest { } @Test - public void deleteCertificateNotExists() throws Exception { + void deleteCertificateNotExists() throws Exception { MockHttpSession session = loginWithSystemAdmin(mvc); UserRO userRO = getLoggedUserData(mvc, session); String alias = "alias-not-exists"; diff --git a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/internal/TruststoreAdminControllerIT.java b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/internal/TruststoreAdminControllerIT.java index 4773bce5fe55255b46e293bedfa4d2e905044490..f8a80d85d5363cbd5fe70351d7e4af8c4782cd85 100644 --- a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/internal/TruststoreAdminControllerIT.java +++ b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/internal/TruststoreAdminControllerIT.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -27,11 +27,10 @@ import eu.europa.ec.edelivery.smp.services.ui.UITruststoreService; import eu.europa.ec.edelivery.smp.test.SmpTestWebAppConfig; import eu.europa.ec.edelivery.smp.test.testutils.X509CertificateTestUtils; import eu.europa.ec.edelivery.smp.ui.AbstractControllerTest; -import eu.europa.ec.edelivery.smp.ui.external.UserResourceIT; import org.apache.commons.io.IOUtils; import org.hamcrest.CoreMatchers; -import org.junit.Ignore; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.mock.web.MockHttpSession; @@ -47,14 +46,14 @@ import java.util.List; import static eu.europa.ec.edelivery.smp.test.testutils.MockMvcUtils.*; import static eu.europa.ec.edelivery.smp.ui.ResourceConstants.CONTEXT_PATH_INTERNAL_TRUSTSTORE; import static eu.europa.ec.edelivery.smp.ui.ResourceConstants.CONTEXT_PATH_PUBLIC_TRUSTSTORE; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @ContextConfiguration(classes = {SmpTestWebAppConfig.class, UITruststoreService.class}) -public class TruststoreAdminControllerIT extends AbstractControllerTest { +class TruststoreAdminControllerIT extends AbstractControllerTest { private static final String PATH_INTERNAL = CONTEXT_PATH_INTERNAL_TRUSTSTORE; private static final String PATH_PUBLIC = CONTEXT_PATH_PUBLIC_TRUSTSTORE; @@ -76,7 +75,7 @@ public class TruststoreAdminControllerIT extends AbstractControllerTest { @Test - public void validateInvalidCertificate() throws Exception { + void validateInvalidCertificate() throws Exception { byte[] buff = "Not a certificate :) ".getBytes(); // login @@ -94,8 +93,8 @@ public class TruststoreAdminControllerIT extends AbstractControllerTest { } @Test - public void validateCertificateSystemAdmin() throws Exception { - byte[] buff = IOUtils.toByteArray(UserResourceIT.class.getResourceAsStream("/SMPtest.crt")); + void validateCertificateSystemAdmin() throws Exception { + byte[] buff = IOUtils.toByteArray(TruststoreAdminControllerIT.class.getResourceAsStream("/SMPtest.crt")); // login MockHttpSession session = loginWithSystemAdmin(mvc); // when update data @@ -121,7 +120,7 @@ public class TruststoreAdminControllerIT extends AbstractControllerTest { } @Test - public void validateCertificateIdWithEmailSerialNumberInSubjectCertIdTest() throws Exception { + void validateCertificateIdWithEmailSerialNumberInSubjectCertIdTest() throws Exception { // login MockHttpSession session = loginWithSystemAdmin(mvc); // when update data @@ -146,8 +145,8 @@ public class TruststoreAdminControllerIT extends AbstractControllerTest { } @Test - public void uploadCertificateInvalidUser() throws Exception { - byte[] buff = IOUtils.toByteArray(UserResourceIT.class.getResourceAsStream("/SMPtest.crt")); + void uploadCertificateInvalidUser() throws Exception { + byte[] buff = IOUtils.toByteArray(TruststoreAdminControllerIT.class.getResourceAsStream("/SMPtest.crt")); // id and logged user not match // given when mvc.perform(post(PATH_PUBLIC + "/34556655/validate-certificate") @@ -158,7 +157,7 @@ public class TruststoreAdminControllerIT extends AbstractControllerTest { } @Test - public void getCertificateList() throws Exception { + void getCertificateList() throws Exception { // given when // login MockHttpSession session = loginWithSystemAdmin(mvc); @@ -188,13 +187,13 @@ public class TruststoreAdminControllerIT extends AbstractControllerTest { } @Test - @Ignore("Fails on CITNET bamboo") - public void deleteCertificateSystemAdmin() throws Exception { + @Disabled("Fails on CITNET bamboo") + void deleteCertificateSystemAdmin() throws Exception { MockHttpSession session = loginWithSystemAdmin(mvc); UserRO userRO = getLoggedUserData(mvc, session); - byte[] buff = IOUtils.toByteArray(UserResourceIT.class.getResourceAsStream("/SMPtest.crt")); + byte[] buff = IOUtils.toByteArray(TruststoreAdminControllerIT.class.getResourceAsStream("/SMPtest.crt")); int countStart = uiTruststoreService.getNormalizedTrustedList().size(); MvcResult prepRes = mvc.perform(post(PATH_INTERNAL + "/" + userRO.getUserId() + "/upload-certificate") diff --git a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/internal/TruststoreAdminControllerTest.java b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/internal/TruststoreAdminControllerTest.java index 196a8de6f1163228864768bde95aa6593b78ba5d..ca7e8a6055440ae055bc752b15ebeee4b7db57dd 100644 --- a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/internal/TruststoreAdminControllerTest.java +++ b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/internal/TruststoreAdminControllerTest.java @@ -46,7 +46,7 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -public class TruststoreAdminControllerTest extends AbstractControllerTest { +class TruststoreAdminControllerTest extends AbstractControllerTest { private static final String PATH = CONTEXT_PATH_INTERNAL_TRUSTSTORE; @Autowired @@ -59,7 +59,7 @@ public class TruststoreAdminControllerTest extends AbstractControllerTest { } @Test - public void testGetSystemTruststoreCertificates() throws Exception { + void testGetSystemTruststoreCertificates() throws Exception { // given when int countStart = uiTruststoreService.getCertificateROEntriesList().size(); MockHttpSession session = loginWithSystemAdmin(mvc); @@ -86,7 +86,7 @@ public class TruststoreAdminControllerTest extends AbstractControllerTest { } @Test - public void testUploadCertificateFailed() throws Exception { + void testUploadCertificateFailed() throws Exception { // given when // login MockHttpSession session = loginWithSystemAdmin(mvc); @@ -107,7 +107,7 @@ public class TruststoreAdminControllerTest extends AbstractControllerTest { } @Test - public void testUploadCertificateOK() throws Exception { + void testUploadCertificateOK() throws Exception { X509Certificate cert = X509CertificateTestUtils.createX509CertificateForTest("123456", "cn=test,o=test,c=eu"); MockHttpSession session = loginWithSystemAdmin(mvc); @@ -128,7 +128,7 @@ public class TruststoreAdminControllerTest extends AbstractControllerTest { } @Test - public void testDeleteCertificateFailed() throws Exception { + void testDeleteCertificateFailed() throws Exception { String alias = UUID.randomUUID().toString(); @@ -152,7 +152,7 @@ public class TruststoreAdminControllerTest extends AbstractControllerTest { } @Test - public void testDeleteCertificateOK() throws Exception { + void testDeleteCertificateOK() throws Exception { X509Certificate cert = X509CertificateTestUtils.createX509CertificateForTest("123456", "cn=test,o=test,c=eu"); String alias = UUID.randomUUID().toString(); diff --git a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/internal/UserAdminControllerIT.java b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/internal/UserAdminControllerIT.java index bf582b06a3d2d0f2ea14c3021e407c602fe18ea2..b4f70cd64a4529ca6f81b55dd356a6606c681cc5 100644 --- a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/internal/UserAdminControllerIT.java +++ b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/ui/internal/UserAdminControllerIT.java @@ -43,7 +43,7 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -public class UserAdminControllerIT extends AbstractControllerTest { +class UserAdminControllerIT extends AbstractControllerTest { private static final String PATH_INTERNAL = ResourceConstants.CONTEXT_PATH_INTERNAL_USER; @@ -53,7 +53,7 @@ public class UserAdminControllerIT extends AbstractControllerTest { } @Test - public void getUsers() throws Exception { + void getUsers() throws Exception { MockHttpSession session = loginWithSystemAdmin(mvc); MvcResult result = mvc.perform(get(PATH_INTERNAL) .session(session) @@ -71,7 +71,7 @@ public class UserAdminControllerIT extends AbstractControllerTest { } @Test - public void testSearch() throws Exception { + void testSearch() throws Exception { MockHttpSession session = loginWithSystemAdmin(mvc); UserRO userROAdmin = getLoggedUserData(mvc, session); MvcResult result = mvc.perform(get(PATH_INTERNAL + "/{user-id}/search", userROAdmin.getUserId()) @@ -90,7 +90,7 @@ public class UserAdminControllerIT extends AbstractControllerTest { } @Test - public void testSearchFilterNoMatch() throws Exception { + void testSearchFilterNoMatch() throws Exception { MockHttpSession session = loginWithSystemAdmin(mvc); UserRO userROAdmin = getLoggedUserData(mvc, session); MvcResult result = mvc.perform(get(PATH_INTERNAL + "/{user-id}/search", userROAdmin.getUserId()) @@ -105,7 +105,7 @@ public class UserAdminControllerIT extends AbstractControllerTest { } @Test - public void testValidateDeleteUserOK() throws Exception { + void testValidateDeleteUserOK() throws Exception { // login MockHttpSession session = loginWithSystemAdmin(mvc); @@ -133,7 +133,7 @@ public class UserAdminControllerIT extends AbstractControllerTest { } @Test - public void testValidateDeleteLoggedUserNotOK() throws Exception { + void testValidateDeleteLoggedUserNotOK() throws Exception { // login MockHttpSession session = loginWithSystemAdmin(mvc); @@ -160,7 +160,7 @@ public class UserAdminControllerIT extends AbstractControllerTest { } @Test - public void changePasswordForUser() throws Exception { + void changePasswordForUser() throws Exception { MockHttpSession sessionAdmin = loginWithSystemAdmin(mvc); UserRO userROAdmin = getLoggedUserData(mvc, sessionAdmin); @@ -178,7 +178,7 @@ public class UserAdminControllerIT extends AbstractControllerTest { newPass.setUsername(SG_USER2_USERNAME); newPass.setCurrentPassword(SYS_ADMIN_PASSWD); newPass.setNewPassword(newPassword); - assertNotEquals(newPassword, SG_USER2_PASSWD); + assertNotEquals(SG_USER2_PASSWD, newPassword); mvc.perform(put(PATH_INTERNAL + "/" + userROAdmin.getUserId() + "/change-password-for/" + userROToUpdate.get("userId")) .with(csrf()) @@ -193,7 +193,7 @@ public class UserAdminControllerIT extends AbstractControllerTest { } @Test - public void testGetUserData() throws Exception { + void testGetUserData() throws Exception { MockHttpSession sessionAdmin = loginWithSystemAdmin(mvc); UserRO userROAdmin = getLoggedUserData(mvc, sessionAdmin); @@ -218,7 +218,7 @@ public class UserAdminControllerIT extends AbstractControllerTest { } @Test - public void testUpdateUserData() throws Exception { + void testUpdateUserData() throws Exception { MockHttpSession sessionAdmin = loginWithSystemAdmin(mvc); UserRO userROAdmin = getLoggedUserData(mvc, sessionAdmin); @@ -250,7 +250,7 @@ public class UserAdminControllerIT extends AbstractControllerTest { } @Test - public void testUDeleteUserData() throws Exception { + void testUDeleteUserData() throws Exception { MockHttpSession sessionAdmin = loginWithSystemAdmin(mvc); UserRO userROAdmin = getLoggedUserData(mvc, sessionAdmin);