diff --git a/pom.xml b/pom.xml index 4d4383a2ee0ec5546031aad4089bd6cb622f2561..67153d124879f59044451ad7c2929548658c5d4b 100644 --- a/pom.xml +++ b/pom.xml @@ -22,9 +22,9 @@ <version>4.2-SNAPSHOT</version> <modules> + <module>smp-angular</module> <module>smp-api</module> <module>smp-server-library</module> - <module>smp-angular</module> <module>smp-webapp</module> <module>smp-soapui-tests</module> </modules> @@ -81,41 +81,20 @@ <spring.version>5.3.18</spring.version> <xmlunit.version>2.5.1</xmlunit.version> - <!-- jacoco, sonar code coverage settings start --> - <!-- JaCoCo Properties --> - <jacoco.version>0.8.6</jacoco.version> - <sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin> - <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis> - <sonar.jacoco.reportPaths>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPaths> - <jacoco.destFile>${sonar.jacoco.reportPaths}</jacoco.destFile> - <sonar.language>java</sonar.language> - - <!--sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin> - <sonar.jacoco.codeCoveragePath>${basedir}/target/code-coverage</sonar.jacoco.codeCoveragePath> - <sonar.jacoco.reportPaths>${sonar.jacoco.codeCoveragePath}/jacoco-ut.exec</sonar.jacoco.reportPaths> - <sonar.language>java</sonar.language--> <sonar.jacoco.remotePort>${jacocoRemotePort}</sonar.jacoco.remotePort> <sonar.jacoco.remoteAddress>${jacocoRemoteAddress}</sonar.jacoco.remoteAddress> <sonar.host.url>http://localhost:9000/sonar/</sonar.host.url> - <sonar.exclusions>**/smp/data/model/*, - **/smp/data/ui/*, - **/smp/ui/exception/*, - **/smp/services/ui/filters/*, - **/smp/exceptions/*, - **/smp/data/ui/enums/*, - **/to_be_removed/* - </sonar.exclusions> - - - <jacoco.maven.plugin.version>0.8.2</jacoco.maven.plugin.version> - <surefire.maven.plugin.version>2.22.1</surefire.maven.plugin.version> + <sonar.language>java</sonar.language> + <jacoco.maven.plugin.version>0.8.6</jacoco.maven.plugin.version> + <surefire.maven.plugin.version>2.22.2</surefire.maven.plugin.version> <!-- latest version compatible with SonarQube 5.6 is: 3.3.0.603--> <sonar.maven.plugin.version>3.5.0.1254</sonar.maven.plugin.version> </properties> <scm> - <developerConnection>scm:git:https://ec.europa.eu/digital-building-blocks/code/scm/edelivery/smp.git</developerConnection> + <developerConnection>scm:git:https://ec.europa.eu/digital-building-blocks/code/scm/edelivery/smp.git + </developerConnection> <tag>HEAD</tag> </scm> @@ -542,6 +521,7 @@ <pluginManagement> <plugins> <plugin> + <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>${surefire.maven.plugin.version}</version> </plugin> @@ -549,21 +529,6 @@ <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>${jacoco.maven.plugin.version}</version> - <executions> - <execution> - <id>jacoco-initialize</id> - <goals> - <goal>prepare-agent</goal> - </goals> - </execution> - <execution> - <id>jacoco-site</id> - <phase>package</phase> - <goals> - <goal>report</goal> - </goals> - </execution> - </executions> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> @@ -590,6 +555,11 @@ <artifactId>maven-antrun-plugin</artifactId> <version>1.8</version> </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-dependency-plugin</artifactId> + <version>3.3.0</version> + </plugin> <plugin> <groupId>com.smartbear.soapui</groupId> <artifactId>soapui-pro-maven-plugin</artifactId> @@ -621,28 +591,19 @@ <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> - <configuration> - <reportsDirectory>${sonar.jacoco.reportPaths}</reportsDirectory> - </configuration> - <executions> - <execution> - <id>default-test</id> - <configuration> - <argLine>-server -ea -Duser.language=en -Xms512m -Xmx1024m ${surefire.argline} - </argLine> - <includes> - <include>**/*Test.java</include> - </includes> - <excludes> - <exclude>**/*IntegrationTest.java</exclude> - </excludes> - </configuration> - </execution> - </executions> + <dependencies> + <!-- Force using the latest JUnit 47 provider --> + <dependency> + <groupId>org.apache.maven.surefire</groupId> + <artifactId>surefire-junit47</artifactId> + <version>${surefire.maven.plugin.version}</version> + </dependency> + </dependencies> + </plugin> <!-- integration tests, failsafe plugin --> - <plugin> + <!-- plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-failsafe-plugin</artifactId> <version>2.19.1</version> @@ -666,38 +627,26 @@ <version>2.19.1</version> </dependency> </dependencies> - </plugin> + </plugin --> <!-- jacoco start --> <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> - <version>${jacoco.maven.plugin.version}</version> <executions> <execution> - <id>pre-unit-test</id> + <id>prepare-agent</id> <goals> <goal>prepare-agent</goal> </goals> - <configuration> - <propertyName>surefire.argline</propertyName> - <append>true</append> - </configuration> </execution> - - <!--execution> - <id>pre-integration-test</id> - <phase>pre-integration-test</phase> + <execution> + <id>report</id> + <phase>verify</phase> <goals> - <goal>prepare-agent-integration</goal> + <goal>report</goal> </goals> - <configuration> - <! - - Sets the path to the file which contains the execution data. - - > - <destFile>${sonar.jacoco.itReportPath}</destFile> - <propertyName>failsafe.argline</propertyName> - <append>true</append> - </configuration> - </execution --> + </execution> </executions> </plugin> <plugin> diff --git a/smp-docker/images/tomcat-mysql-smp-sml/entrypoint.sh b/smp-docker/images/tomcat-mysql-smp-sml/entrypoint.sh index 99c90316c9fe9b93a913b42d68bb6d6ff89c2005..22fb94713c7713510eb03ded008ab0e37aeb030b 100755 --- a/smp-docker/images/tomcat-mysql-smp-sml/entrypoint.sh +++ b/smp-docker/images/tomcat-mysql-smp-sml/entrypoint.sh @@ -26,7 +26,7 @@ fi init_tomcat() { # add java code coverage angent to image if [ -e /opt/jacoco/jacoco-agent.jar ]; then - JAVA_OPTS="-javaagent:/opt/jacoco/jacoco-agent.jar=output=tcpserver,address=*,port=6901 $JAVA_OPTS" + JAVA_OPTS="-javaagent:/opt/jacoco/jacoco-agent.jar=output=tcpserver,address=*,port=6901,includes=eu.europa.ec.edelivery.smp.* $JAVA_OPTS" fi # add allow encoded slashes and disable scheme for proxy JAVA_OPTS="$JAVA_OPTS -Dorg.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true -Djdk.http.auth.tunneling.disabledSchemes=" diff --git a/smp-server-library/pom.xml b/smp-server-library/pom.xml index 9dfc5513ab2f836e43183c740f9d34fe1ad415aa..56cfff178f25db27c8ea46843700193c22a414ba 100644 --- a/smp-server-library/pom.xml +++ b/smp-server-library/pom.xml @@ -22,24 +22,6 @@ <artifactId>smp-server-library</artifactId> <name>smp-server-library</name> - <!-- Default values for local compilation. The properties can be overriden for continuous integration servers --> - <properties> - - <jdbc.driver>com.mysql.jdbc.Driver</jdbc.driver> - <jdbc.url>jdbc:mysql://localhost/smp</jdbc.url> - <jdbc.user>smp</jdbc.user> - <jdbc.password>****</jdbc.password> - <target-database>MySQL</target-database> - <jdbc.read-connections.max>10</jdbc.read-connections.max> - - <!-- jdbc.driver>oracle.jdbc.OracleDriver</jdbc.driver> - <jdbc.url>jdbc:oracle:thin:@192.168.56.102:1521/xe</jdbc.url> - <jdbc.user>smp</jdbc.user> - <jdbc.password>****</jdbc.password> - <target-database>Oracle</target-database> - <jdbc.read-connections.max>10</jdbc.read-connections.max --> - </properties> - <dependencies> <dependency> <groupId>eu.europa.ec.edelivery</groupId> diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBServiceGroup.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBServiceGroup.java index 8cdcea23ff745b8839e1c1a0b04e555f462b97a9..dc26ab63862f5abac2c50a51dba49b9ac5f10e7f 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBServiceGroup.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBServiceGroup.java @@ -1,3 +1,4 @@ +package eu.europa.ec.edelivery.smp.data.model; /* * Copyright 2017 European Commission | CEF eDelivery * @@ -11,8 +12,6 @@ * See the Licence for the specific language governing permissions and limitations under the Licence. */ -package eu.europa.ec.edelivery.smp.data.model; - import eu.europa.ec.edelivery.smp.data.dao.utils.ColumnDescription; import org.apache.commons.lang3.StringUtils; import org.hibernate.envers.Audited; @@ -44,7 +43,7 @@ public class DBServiceGroup extends BaseEntity { @Id @SequenceGenerator(name = "sg_generator", sequenceName = "SMP_SERVICE_GROUP_SEQ", allocationSize = 1) - @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sg_generator" ) + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sg_generator") @Column(name = "ID") @ColumnDescription(comment = "Unique Servicegroup id") Long id; @@ -55,7 +54,7 @@ public class DBServiceGroup extends BaseEntity { cascade = CascadeType.ALL, orphanRemoval = true ) - List<DBServiceGroupDomain> serviceGroupDomains= new ArrayList<>(); + List<DBServiceGroupDomain> serviceGroupDomains; // fetch in on demand - reduce performance issue on big SG table (set it better option) @@ -78,15 +77,11 @@ public class DBServiceGroup extends BaseEntity { @OneToOne(mappedBy = "dbServiceGroup", cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true) private DBServiceGroupExtension serviceGroupExtension; - @Column(name = "CREATED_ON" , nullable = false) + @Column(name = "CREATED_ON", nullable = false) LocalDateTime createdOn; @Column(name = "LAST_UPDATED_ON", nullable = false) LocalDateTime lastUpdatedOn; - - public DBServiceGroup() { - } - @Override public Long getId() { return id; @@ -141,37 +136,36 @@ public class DBServiceGroup extends BaseEntity { } public List<DBServiceGroupDomain> getServiceGroupDomains() { + if (serviceGroupDomains == null) { + serviceGroupDomains = new ArrayList<>(); + } return serviceGroupDomains; } - public void setServiceGroupDomains(List<DBServiceGroupDomain> serviceGroupDomains) { - this.serviceGroupDomains = serviceGroupDomains; - } - public DBServiceGroupDomain addDomain(DBDomain domain) { DBServiceGroupDomain sgd = new DBServiceGroupDomain(this, domain); - serviceGroupDomains.add(sgd); + getServiceGroupDomains().add(sgd); return sgd; } public void removeDomain(String domainCode) { // find connecting object - Optional<DBServiceGroupDomain> osgd = serviceGroupDomains.stream() + Optional<DBServiceGroupDomain> osgd = getServiceGroupDomains().stream() .filter(psgd -> domainCode.equals(psgd.getDomain().getDomainCode())).findFirst(); - if (osgd.isPresent()){ + if (osgd.isPresent()) { DBServiceGroupDomain dsg = osgd.get(); - serviceGroupDomains.remove(dsg); + getServiceGroupDomains().remove(dsg); dsg.setDomain(null); dsg.setServiceGroup(null); } } - public Optional<DBServiceGroupDomain> findServiceGroupDomainForMetadata(String docId, String docSch){ - for (DBServiceGroupDomain serviceGroupDomain : serviceGroupDomains) { + public Optional<DBServiceGroupDomain> findServiceGroupDomainForMetadata(String docId, String docSch) { + for (DBServiceGroupDomain serviceGroupDomain : getServiceGroupDomains()) { for (DBServiceMetadata dbServiceMetadata : serviceGroupDomain.getServiceMetadata()) { if (Objects.equals(docId, dbServiceMetadata.getDocumentIdentifier()) - && Objects.equals(docId, dbServiceMetadata.getDocumentIdentifier()) ) { + && Objects.equals(docSch, dbServiceMetadata.getDocumentIdentifierScheme())) { return Optional.of(serviceGroupDomain); } } @@ -180,11 +174,10 @@ public class DBServiceGroup extends BaseEntity { } - @Transient public Optional<DBServiceGroupDomain> getServiceGroupForDomain(String domainCode) { // find connecting object - return StringUtils.isBlank(domainCode)?Optional.empty():serviceGroupDomains.stream() + return StringUtils.isBlank(domainCode) ? Optional.empty() : getServiceGroupDomains().stream() .filter(psgd -> domainCode.equals(psgd.getDomain().getDomainCode())).findFirst(); } @@ -209,8 +202,6 @@ public class DBServiceGroup extends BaseEntity { } - - /** * Id is database suragete id + natural key! * @@ -236,7 +227,7 @@ public class DBServiceGroup extends BaseEntity { @PrePersist public void prePersist() { - if(createdOn == null) { + if (createdOn == null) { createdOn = LocalDateTime.now(); } lastUpdatedOn = LocalDateTime.now(); diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ui/UIServiceMetadataService.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ui/UIServiceMetadataService.java index ba201c62ad048184f4f13e5f730be0f884b30397..6c6989f88bd939dff94cbf080abf077d8fbb7afd 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ui/UIServiceMetadataService.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ui/UIServiceMetadataService.java @@ -25,10 +25,14 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.io.UnsupportedEncodingException; +import java.nio.charset.IllegalCharsetNameException; import java.util.Optional; import static eu.europa.ec.edelivery.smp.exceptions.ErrorCode.INVALID_REQUEST; +/** + * Serives for managing the Service metadata + */ @Service public class UIServiceMetadataService extends UIServiceBase<DBServiceMetadata, ServiceMetadataRO> { private static final SMPLogger LOG = SMPLoggerFactory.getLogger(UIServiceMetadataService.class); @@ -69,8 +73,8 @@ public class UIServiceMetadataService extends UIServiceBase<DBServiceMetadata, S try { return new String(extension, "UTF-8"); } catch (UnsupportedEncodingException e) { - LOG.error("Error converting the servicemetadata to utf-8 String for id:" + id, e); - return null; + LOG.error("Can not convert ServiceMetadata bytearray to 'UTF-8'", e); + throw new IllegalCharsetNameException("UTF-8"); } } 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 207b6efb626058b08b2fa0cc08ba90e9047fe24b..4100280de9134ceb69e2ad6c82419068cb9a1535 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,7 +21,7 @@ public class SMPAuthorityDeserializerTest { @Test public void deserialize() throws IOException { - String value = "{\"username\":\"smp\",\"password\":null,\"emailAddress\":null,\"authorities\":[\"ROLE_SMP_ADMIN\"],\"active\":true,\"role\":\"SMP_ADMIN\",\"id\":8,\"certificate\":null,\"statusPassword\":0,\"passwordExpired\":true}"; + String value = "{\"username\":\"smp\",\"password\":null,\"emailAddress\":null,\"authorities\":[\"ROLE_SMP_ADMIN\"],\"active\":true,\"role\":\"SMP_ADMIN\",\"certificate\":null,\"statusPassword\":0,\"passwordExpired\":true}"; ObjectMapper mapper = new ObjectMapper(); UserRO userRO = mapper.readValue(value, UserRO.class); diff --git a/smp-soapui-tests/pom.xml b/smp-soapui-tests/pom.xml index e6d704ab2d6946cfa5e976c2e9a4f90a26bef0a6..f85a1dbf5774dceb2abb755c755e8919a0c39327 100644 --- a/smp-soapui-tests/pom.xml +++ b/smp-soapui-tests/pom.xml @@ -32,7 +32,7 @@ <artifactId>soapui-pro-maven-plugin</artifactId> <version>5.1.2</version> <configuration> - <outputFolder>${build.directory}/soapui</outputFolder> + <outputFolder>${build.directory}/soapui-reports/</outputFolder> <junitReport>true</junitReport> <printReport>true</printReport> <settingsFile>${basedir}/soapui/soapui-settings.xml</settingsFile> @@ -70,26 +70,78 @@ </goals> </execution> </executions> - </plugin> - + <!-- extract classes so that JACOCO plugin can find the classes + to generate a report (use this option to get Code coverage report for SOAPUI project) + --> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-dependency-plugin</artifactId> + <executions> + <execution> + <id>unpack</id> + <phase>package</phase> + <goals> + <goal>unpack</goal> + </goals> + <configuration> + <artifactItems> + <artifactItem> + <groupId>${project.groupId}</groupId> + <artifactId>smp-api</artifactId> + <version>${project.version}</version> + <type>jar</type> + </artifactItem> + <artifactItem> + <groupId>${project.groupId}</groupId> + <artifactId>smp-server-library</artifactId> + <version>${project.version}</version> + <type>jar</type> + </artifactItem> + <artifactItem> + <groupId>${project.groupId}</groupId> + <artifactId>smp</artifactId> + <version>${project.version}</version> + <type>war</type> + </artifactItem> + </artifactItems> + <includes>eu/europa/ec/edelivery/smp/**/*.class</includes> + <outputDirectory>${project.build.directory}/classes</outputDirectory> + </configuration> + </execution> + </executions> + </plugin> + <!-- dump jacoco.exec from remote agent and generate report --> <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>${jacoco.maven.plugin.version}</version> + <configuration> + <classDumpDir>${project.build.outputDirectory}</classDumpDir> + </configuration> <executions> + <!-- execution> + <id>jacoco-agent</id> + <phase>pre-integration-test</phase> + <goals> + <goal>prepare-agent</goal> + </goals> + <configuration> + <destFile>${jacoco.reportPath}</destFile> + <propertyName>jacoco.agent.itArgLine</propertyName> + </configuration> + </execution --> + <execution> <phase>post-integration-test</phase> - <goals> <goal>dump</goal> + <goal>report</goal> </goals> <configuration> - <destFile>${sonar.jacoco.reportPaths}</destFile> + <!-- dataFile>${project.build.directory}/jacoco.exec</dataFile --> <address>${sonar.jacoco.remoteAddress}</address> <port>${sonar.jacoco.remotePort}</port> - <reset>false</reset> - <append>true</append> </configuration> </execution> </executions>